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
6
7
#include <
core/system.h
>
8
#include <
core/arch.h
>
9
#include <
sys/proc.h
>
10
#include <
sys/sched.h
>
11
#include <
sys/syscall.h
>
12
#include <
sys/signal.h
>
13
#include <aquila/syscall.h>
14
#include <aquila/errno.h>
15
16
void
aarch64_preempt
(
void
);
17
18
/*
19
* Runs a system call: the exception handler calls it for an `svc`
20
* instruction from user mode. It returns to user mode when the call is
21
* done, delivering the signals that came meanwhile.
22
*/
23
void
arch_syscall
(
struct
aarch64_regs
*r)
24
{
25
/* the number in x8, the arguments in x0 to x4 (as on Linux) */
26
syscall_dispatch
(r->
x
[8], r->
x
[0], r->
x
[1], r->
x
[2], r->
x
[3], r->
x
[4]);
27
28
/* if the call woke up an urgent thread (the network's, for a packet
29
* sent to ourselves), it runs before we return to user mode */
30
if
(
sched_urgent
)
31
aarch64_preempt
();
32
33
/* deliver the pending signals, and restart the call if one
34
* interrupted it (not sigreturn, whose registers are the frame's) */
35
aarch64_return_to_user
(r,
curthread
->syscall_nr != SYS_sigreturn);
36
}
37
38
/*
39
* Sets the result of a thread's system call: x0 when it returns to user
40
* mode. That's in its saved registers, or, for a thread that has never
41
* run (a child of `fork()`), where it will start from.
42
*/
43
void
arch_syscall_return
(
struct
thread
*
thread
,
uintptr_t
val)
44
{
45
struct
aarch64_thread
*arch =
thread
->
arch
;
46
47
if
(
thread
->
spawned
)
48
arch->
regs
->
x
[0] = val;
49
else
50
arch->
x0
= val;
51
}
aarch64_return_to_user
void aarch64_return_to_user(struct aarch64_regs *r, int syscall)
Takes the current thread's signals on its way back to user mode, and restarts or fails the system cal...
Definition
signal.c:201
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
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
aarch64_regs
What an exception saves on the kernel stack (cpu/vectors.S): the context it interrupted.
Definition
cpu.h:12
aarch64_regs::x
uint64_t x[31]
Definition
cpu.h:13
aarch64_thread
A thread's aarch64 state (thread->arch).
Definition
arch.h:25
aarch64_thread::x0
uint64_t x0
Definition
arch.h:37
aarch64_thread::regs
struct aarch64_regs * regs
Definition
arch.h:33
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
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
aarch64_preempt
void aarch64_preempt(void)
Switches away from this CPU's running thread, which stays ready, to the next ready thread.
Definition
trap.c:188
kernel
arch
aarch64
sys
syscall.c
Generated by
1.18.0