Lego SYSCALL Facts¶
This document is about the general concepts of Lego syscall implementation. If you are developing syscall, please read this document first.
Interrupts Enabled¶
Each syscall is invoked with interrupts enabled. Also, it must return with interrupts enabled as well. Any buggy syscall implementation will be catched by syscall_return_slowpath()
:
```c
void syscall_return_slowpath(struct pt_regs *regs)
{
if (WARN(irqs_disabled(), “syscall %ld left IRQs disabled”, regs->orig_ax))
local_irq_enable();
1 2 |
|
}
void do_syscall_64(struct pt_regs *regs) { .. local_irq_enable();
1 2 3 4 5 6 7 8 |
|
} ```
Get User Entry pt_regs¶
The macro task_pt_regs()
always return the pt_regs
, that saves the user context when it issued the syscall, no matter how many levels interrupts are nested when you call task_pt_regs()
. This is based on the fact that kernel stack is empty at syscall entry, thus this user pt_regs
was saved at the top
of kernel stack:
```c
define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1)¶
asm
ENTRY(entry_SYSCALL_64)
SWAPGS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
```
–
Yizhou Shan
Created: Feb 22, 2018
Last Updated: Feb 22, 2018