PatchworkOS
Loading...
Searching...
No Matches
syscalls.h
Go to the documentation of this file.
1#pragma once
2
6#include <kernel/mem/space.h>
7
22#define SYS_PROCESS_EXIT 0
23#define SYS_THREAD_EXIT 1
24#define SYS_SPAWN 2
25#define SYS_NANOSLEEP 3
26#define SYS_ERRNO 4
27#define SYS_GETPID 5
28#define SYS_GETTID 6
29#define SYS_UPTIME 7
30#define SYS_UNIX_EPOCH 8
31#define SYS_OPEN 9
32#define SYS_OPEN2 10
33#define SYS_CLOSE 11
34#define SYS_READ 12
35#define SYS_WRITE 13
36#define SYS_SEEK 14
37#define SYS_IOCTL 15
38#define SYS_CHDIR 16
39#define SYS_POLL 17
40#define SYS_STAT 18
41#define SYS_MMAP 19
42#define SYS_MUNMAP 20
43#define SYS_MPROTECT 21
44#define SYS_GETDENTS 22
45#define SYS_THREAD_CREATE 23
46#define SYS_YIELD 24
47#define SYS_DUP 25
48#define SYS_DUP2 26
49#define SYS_FUTEX 27
50#define SYS_REMOVE 28
51#define SYS_LINK 29
52#define SYS_SHARE 30
53#define SYS_CLAIM 31
54#define SYS_BIND 32
55
56#define SYS_TOTAL_AMOUNT 33
57
67
74typedef struct
75{
77 void* handler;
79
84
89
100#define SYSCALL_DEFINE(num, returnType, ...) \
101 returnType syscall_handler_##num(__VA_ARGS__); \
102 const syscall_descriptor_t __syscall_##num __attribute__((used, section(".syscall_table"))) = { \
103 .number = (num), \
104 .handler = (void*)syscall_handler_##num, \
105 }; \
106 returnType syscall_handler_##num(__VA_ARGS__)
107
113extern void syscall_entry(void);
114
121void syscall_ctx_init(syscall_ctx_t* ctx, stack_pointer_t* kernelStack);
122
127
133void syscall_table_init(void);
134
140void syscalls_cpu_init(void);
141
157 uint64_t number);
158
syscall_descriptor_t _syscallTableEnd[]
Linker defined end of the syscall table.
void syscall_table_init(void)
Initialize the syscall table.
Definition syscalls.c:23
syscall_descriptor_t _syscallTableStart[]
Linker defined start of the syscall table.
void syscalls_cpu_init(void)
Initalize syscalls on the current CPU.
Definition syscalls.c:39
void syscall_ctx_init(syscall_ctx_t *ctx, stack_pointer_t *kernelStack)
Initialize a per-thread syscall context.
Definition syscalls.c:50
void syscall_ctx_load(syscall_ctx_t *ctx)
Load a syscall context into the CPU.
Definition syscalls.c:56
void syscall_entry(void)
Assembly entry point for syscalls.
uint64_t syscall_handler(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9, uint64_t number)
C syscall handler.
Definition syscalls.c:72
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
Structure to define a stack in memory.
Per thread syscall context.
Definition syscalls.h:63
uintptr_t userRsp
Definition syscalls.h:65
uintptr_t kernelRsp
Definition syscalls.h:64
A syscall descriptor.
Definition syscalls.h:75