|
PatchworkOS
|
System Calls. More...
Data Structures | |
| struct | syscall_ctx_t |
| Per thread syscall context. More... | |
| struct | syscall_descriptor_t |
| A syscall descriptor. More... | |
Macros | |
| #define | SYS_PROCESS_EXIT 0 |
| #define | SYS_THREAD_EXIT 1 |
| #define | SYS_SPAWN 2 |
| #define | SYS_NANOSLEEP 3 |
| #define | SYS_ERRNO 4 |
| #define | SYS_GETPID 5 |
| #define | SYS_GETTID 6 |
| #define | SYS_UPTIME 7 |
| #define | SYS_UNIX_EPOCH 8 |
| #define | SYS_OPEN 9 |
| #define | SYS_OPEN2 10 |
| #define | SYS_CLOSE 11 |
| #define | SYS_READ 12 |
| #define | SYS_WRITE 13 |
| #define | SYS_SEEK 14 |
| #define | SYS_IOCTL 15 |
| #define | SYS_CHDIR 16 |
| #define | SYS_POLL 17 |
| #define | SYS_STAT 18 |
| #define | SYS_MMAP 19 |
| #define | SYS_MUNMAP 20 |
| #define | SYS_MPROTECT 21 |
| #define | SYS_GETDENTS 22 |
| #define | SYS_THREAD_CREATE 23 |
| #define | SYS_YIELD 24 |
| #define | SYS_DUP 25 |
| #define | SYS_DUP2 26 |
| #define | SYS_FUTEX 27 |
| #define | SYS_REMOVE 28 |
| #define | SYS_LINK 29 |
| #define | SYS_SHARE 30 |
| #define | SYS_CLAIM 31 |
| #define | SYS_BIND 32 |
| #define | SYS_TOTAL_AMOUNT 33 |
| #define | SYSCALL_DEFINE(num, returnType, ...) |
| Macro to define a syscall. | |
Functions | |
| void | syscall_entry (void) |
| Assembly entry point for syscalls. | |
| void | syscall_ctx_init (syscall_ctx_t *ctx, stack_pointer_t *kernelStack) |
| Initialize a per-thread syscall context. | |
| void | syscall_ctx_load (syscall_ctx_t *ctx) |
| Load a syscall context into the CPU. | |
| void | syscall_table_init (void) |
| Initialize the syscall table. | |
| void | syscalls_cpu_init (void) |
| Initalize syscalls on the current CPU. | |
| 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. | |
Variables | |
| syscall_descriptor_t | _syscallTableStart [] |
| Linker defined start of the syscall table. | |
| syscall_descriptor_t | _syscallTableEnd [] |
| Linker defined end of the syscall table. | |
System Calls.
System calls provide a controlled interface for user-space applications to request services from the kernel, such as file operations, process management, and inter-process communication.
| #define SYS_BIND 32 |
Definition at line 54 of file syscalls.h.
| #define SYS_CHDIR 16 |
Definition at line 38 of file syscalls.h.
| #define SYS_CLAIM 31 |
Definition at line 53 of file syscalls.h.
| #define SYS_CLOSE 11 |
Definition at line 33 of file syscalls.h.
| #define SYS_DUP 25 |
Definition at line 47 of file syscalls.h.
| #define SYS_DUP2 26 |
Definition at line 48 of file syscalls.h.
| #define SYS_ERRNO 4 |
Definition at line 26 of file syscalls.h.
| #define SYS_FUTEX 27 |
Definition at line 49 of file syscalls.h.
| #define SYS_GETDENTS 22 |
Definition at line 44 of file syscalls.h.
| #define SYS_GETPID 5 |
Definition at line 27 of file syscalls.h.
| #define SYS_GETTID 6 |
Definition at line 28 of file syscalls.h.
| #define SYS_IOCTL 15 |
Definition at line 37 of file syscalls.h.
| #define SYS_LINK 29 |
Definition at line 51 of file syscalls.h.
| #define SYS_MMAP 19 |
Definition at line 41 of file syscalls.h.
| #define SYS_MPROTECT 21 |
Definition at line 43 of file syscalls.h.
| #define SYS_MUNMAP 20 |
Definition at line 42 of file syscalls.h.
| #define SYS_NANOSLEEP 3 |
Definition at line 25 of file syscalls.h.
| #define SYS_OPEN 9 |
Definition at line 31 of file syscalls.h.
| #define SYS_OPEN2 10 |
Definition at line 32 of file syscalls.h.
| #define SYS_POLL 17 |
Definition at line 39 of file syscalls.h.
| #define SYS_PROCESS_EXIT 0 |
Definition at line 22 of file syscalls.h.
| #define SYS_READ 12 |
Definition at line 34 of file syscalls.h.
| #define SYS_REMOVE 28 |
Definition at line 50 of file syscalls.h.
| #define SYS_SEEK 14 |
Definition at line 36 of file syscalls.h.
| #define SYS_SHARE 30 |
Definition at line 52 of file syscalls.h.
| #define SYS_SPAWN 2 |
Definition at line 24 of file syscalls.h.
| #define SYS_STAT 18 |
Definition at line 40 of file syscalls.h.
| #define SYS_THREAD_CREATE 23 |
Definition at line 45 of file syscalls.h.
| #define SYS_THREAD_EXIT 1 |
Definition at line 23 of file syscalls.h.
| #define SYS_TOTAL_AMOUNT 33 |
Definition at line 56 of file syscalls.h.
| #define SYS_UNIX_EPOCH 8 |
Definition at line 30 of file syscalls.h.
| #define SYS_UPTIME 7 |
Definition at line 29 of file syscalls.h.
| #define SYS_WRITE 13 |
Definition at line 35 of file syscalls.h.
| #define SYS_YIELD 24 |
Definition at line 46 of file syscalls.h.
| #define SYSCALL_DEFINE | ( | num, | |
| returnType, | |||
| ... | |||
| ) |
Macro to define a syscall.
Uses the linker section to define a system call in the syscall table.
| num | The syscall number, must be unique, check include/kernel/syscalls.h for existing numbers. |
| returnType | The return type of the syscall handler. |
| ... | The arguments of the syscall handler, can be no more then 6 arguments. To avoid using the stack to pass arguments to a syscall. |
Definition at line 100 of file syscalls.h.
| void syscall_ctx_init | ( | syscall_ctx_t * | ctx, |
| stack_pointer_t * | kernelStack | ||
| ) |
Initialize a per-thread syscall context.
| ctx | The syscall context to initialize. |
| kernelStack | The kernel stack of the thread. |
Definition at line 50 of file syscalls.c.
References syscall_ctx_t::kernelRsp, stack_pointer_t::top, and syscall_ctx_t::userRsp.
Referenced by thread_init().
| void syscall_ctx_load | ( | syscall_ctx_t * | ctx | ) |
Load a syscall context into the CPU.
Definition at line 56 of file syscalls.c.
References MSR_GS_BASE, MSR_KERNEL_GS_BASE, and msr_write().
Referenced by thread_load().
|
extern |
Assembly entry point for syscalls.
Responsible for switching stacks.
Referenced by syscalls_cpu_init().
| 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.
This is called from the assembly syscall_entry() function.
| rdi | First argument. |
| rsi | Second argument. |
| rdx | Third argument. |
| rcx | Fourth argument. |
| r8 | Fifth argument. |
| r9 | Sixth argument. |
| number | The syscall number. |
Definition at line 72 of file syscalls.c.
References ENOSYS, ERR, errno, syscall_descriptor_t::handler, INTERRUPT_NOTE, lapic_self_id(), lapic_send_ipi(), LOG_DEBUG, note_queue_length(), NULL, sched_thread_unsafe(), and syscall_get_descriptor().
| void syscall_table_init | ( | void | ) |
Initialize the syscall table.
This will sort the syscall table and verify that all syscalls are present.
Definition at line 23 of file syscalls.c.
References _syscallTableEnd, _syscallTableStart, assert, LOG_INFO, qsort(), SYS_TOTAL_AMOUNT, and syscall_descriptor_cmp().
Referenced by init_finalize().
| void syscalls_cpu_init | ( | void | ) |
Initalize syscalls on the current CPU.
This will setup the MSR registers required for syscalls.
Definition at line 39 of file syscalls.c.
References EFER_SYSCALL_ENABLE, GDT_KERNEL_CODE, GDT_RING3, GDT_USER_CODE, MSR_EFER, MSR_LSTAR, msr_read(), MSR_STAR, MSR_SYSCALL_FLAG_MASK, msr_write(), RFLAGS_AUX_CARRY, RFLAGS_DIRECTION, RFLAGS_INTERRUPT_ENABLE, RFLAGS_IOPL, RFLAGS_NESTED_TASK, RFLAGS_TRAP, and syscall_entry().
Referenced by cpu_init().
|
extern |
Linker defined end of the syscall table.
Referenced by syscall_table_init().
|
extern |
Linker defined start of the syscall table.
Referenced by syscall_get_descriptor(), and syscall_table_init().