AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
syscall.c
Go to the documentation of this file.
1
7
8
#include <
core/system.h
>
9
#include <
core/arch.h
>
10
#include <
sys/proc.h
>
11
#include <
sys/sched.h
>
12
#include <
sys/syscall.h
>
13
#include <
sys/signal.h
>
14
#include <aquila/syscall.h>
15
#include <aquila/errno.h>
16
17
/*
18
* Runs a system call: the interrupt handler calls it for `int $0x80`. It
19
* returns to user mode when the call is done, delivering the signals that
20
* came meanwhile.
21
*/
22
void
arch_syscall
(
struct
x86_regs
*r)
23
{
24
#if ARCH_BITS==32
25
syscall_dispatch
(r->eax, r->ebx, r->ecx, r->edx, r->esi, r->edi);
26
#else
27
/* the arguments in Linux's registers (r10 instead of rcx, which the
28
* syscall instruction overwrites) */
29
syscall_dispatch
(r->
rax
, r->
rdi
, r->
rsi
, r->
rdx
, r->
r10
, r->
r8
);
30
#endif
31
32
/* if the call woke up an urgent thread (the network's, for a packet
33
* sent to ourselves), it runs before we return to user mode */
34
if
(
sched_urgent
) {
35
extern
void
x86_preempt(
void
);
36
x86_preempt();
37
}
38
39
/* deliver the pending signals, and restart the call if one
40
* interrupted it (not sigreturn, whose registers are the frame's) */
41
x86_return_to_user
(r,
curthread
->syscall_nr != SYS_sigreturn);
42
}
43
44
/*
45
* Sets the result of a thread's system call: eax (rax) when it returns to
46
* user mode. That's in its saved registers (for a child of `fork()`, its
47
* copy of its parent's), or, for a thread that has never run, where it
48
* will start from.
49
*/
50
void
arch_syscall_return
(
struct
thread
*
thread
,
uintptr_t
val)
51
{
52
struct
x86_thread
*arch =
thread
->
arch
;
53
54
#if ARCH_BITS==32
55
if
(
thread
->
spawned
) arch->
regs
->eax = val;
56
else
arch->eax = val;
57
#else
58
if
(
thread
->
spawned
) arch->
regs
->
rax
= val;
59
else
arch->
rax
= val;
60
#endif
61
}
arch_syscall
void arch_syscall(struct aarch64_regs *r)
Definition
syscall.c:23
arch_syscall_return
void arch_syscall_return(struct thread *thread, uintptr_t val)
Sets the result of a thread's system call, in the register that returns it to user mode.
Definition
syscall.c:43
x86_return_to_user
void x86_return_to_user(struct x86_regs *r, int syscall)
Delivers the current process's pending signals on the way back to user mode: stops and default action...
Definition
signal.c:246
arch.h
system.h
proc.h
sched.h
sched_urgent
int sched_urgent
Definition
sched.c:306
curthread
#define curthread
Definition
sched.h:12
signal.h
uintptr_t
__SIZE_TYPE__ uintptr_t
Definition
stddef.h:12
thread
A thread.
Definition
thread.h:23
thread::spawned
int spawned
whether it has run yet
Definition
thread.h:87
thread::arch
void * arch
the architecture's own data: its registers, its kernel stack
Definition
thread.h:84
x86_regs
The registers an interrupt or exception saved, on the kernel stack, as cpu.S's stubs push them: the g...
Definition
cpu.h:12
x86_regs::rsi
uint64_t rsi
Definition
cpu.h:22
x86_regs::r10
uint64_t r10
Definition
cpu.h:21
x86_regs::rdx
uint64_t rdx
Definition
cpu.h:22
x86_regs::rax
uint64_t rax
Definition
cpu.h:22
x86_regs::rdi
uint64_t rdi
Definition
cpu.h:22
x86_regs::r8
uint64_t r8
Definition
cpu.h:21
x86_thread
A thread's x86 state: its kernel stack, and where it resumes.
Definition
arch.h:16
x86_thread::rax
uintptr_t rax
Definition
arch.h:31
x86_thread::regs
struct x86_regs * regs
Definition
arch.h:34
syscall.h
syscall_dispatch
void syscall_dispatch(unsigned long nr, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
Runs a system call that the current thread made from user mode.
Definition
syscall.c:313
kernel
arch
i386
sys
syscall.c
Generated by
1.18.0