AquilaOS documentation
How it works, and its code
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
16void 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 */
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)
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 */
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}
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
void arch_syscall(struct aarch64_regs *r)
Definition syscall.c:23
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
int sched_urgent
Definition sched.c:306
#define curthread
Definition sched.h:12
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
What an exception saves on the kernel stack (cpu/vectors.S): the context it interrupted.
Definition cpu.h:12
uint64_t x[31]
Definition cpu.h:13
A thread's aarch64 state (thread->arch).
Definition arch.h:25
uint64_t x0
Definition arch.h:37
struct aarch64_regs * regs
Definition arch.h:33
A thread.
Definition thread.h:23
int spawned
whether it has run yet
Definition thread.h:87
void * arch
the architecture's own data: its registers, its kernel stack
Definition thread.h:84
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
void aarch64_preempt(void)
Switches away from this CPU's running thread, which stays ready, to the next ready thread.
Definition trap.c:188