#pragma once // syscall_nr.h - system call numbers // Shared between kernel (ke_syscall.c) and user mode (syscall.dll). // Keep in sync with gSyscallTable in ke_syscall.c and SYS_MAX below. // // Calling convention (INT 0x40, MS x64): // RAX = syscall number // RCX, RDX, R8, R9 = args 0-3 // R10, R11 = args 4-5 (loaded by SYSCALL_STUB6 in syscall_stubs.asm) // Return value in RAX (KSTATUS or data). // // Handle semantics: // Every kernel object (file, mutex, semaphore, event, queue) is reference- // counted. SYS_CLOSE_HANDLE is the ONE way to close any handle regardless // of the object type behind it. KeCloseHandle calls ObDereferenceObject, // which fires the type-specific Destroy callback (e.g. FileDestroy) // automatically when the refcount reaches zero. There is no separate // SYS_CLOSE_FILE - that was redundant. // --------------------------------------------------------------------------- // Process & Thread // --------------------------------------------------------------------------- #define SYS_EXIT_PROCESS 0 // (int exitCode) -> void #define SYS_EXIT_THREAD 1 // (int exitCode) -> void #define SYS_CREATE_THREAD 2 // (uint64_t entry, uint64_t arg, uint32_t priority, uint32_t* tidOut) -> KSTATUS #define SYS_GET_CURRENT_TID 3 // () -> uint32_t #define SYS_GET_CURRENT_PID 4 // () -> uint32_t #define SYS_YIELD 5 // () -> void #define SYS_SLEEP 6 // (uint32_t ms) -> void #define SYS_SET_THREAD_PRIORITY 7 // (uint32_t priority) -> KSTATUS // --------------------------------------------------------------------------- // Memory // --------------------------------------------------------------------------- #define SYS_ALLOC 8 // (size_t size) -> void* (NULL on failure) #define SYS_FREE 9 // (void* ptr, size_t size) -> void #define SYS_REALLOC 10 // (void* ptr, size_t newSize) -> void* // --------------------------------------------------------------------------- // Synchronisation Objects // --------------------------------------------------------------------------- #define SYS_MUTEX_CREATE 11 // (uint32_t* handleOut) -> KSTATUS #define SYS_MUTEX_ACQUIRE 12 // (uint32_t handle) -> KSTATUS #define SYS_MUTEX_TRY_ACQUIRE 13 // (uint32_t handle) -> KSTATUS #define SYS_MUTEX_RELEASE 14 // (uint32_t handle) -> KSTATUS #define SYS_SEM_CREATE 15 // (int32_t initial, int32_t max, uint32_t* handleOut) -> KSTATUS #define SYS_SEM_WAIT 16 // (uint32_t handle) -> KSTATUS #define SYS_SEM_TRY_WAIT 17 // (uint32_t handle) -> KSTATUS #define SYS_SEM_SIGNAL 18 // (uint32_t handle) -> KSTATUS #define SYS_EVENT_CREATE 19 // (uint32_t* handleOut) -> KSTATUS #define SYS_EVENT_SIGNAL 20 // (uint32_t handle) -> KSTATUS #define SYS_EVENT_CLEAR 21 // (uint32_t handle) -> KSTATUS #define SYS_EVENT_WAIT 22 // (uint32_t handle) -> KSTATUS // --------------------------------------------------------------------------- // Queue // --------------------------------------------------------------------------- #define SYS_QUEUE_CREATE 23 // (uint32_t* handleOut) -> KSTATUS #define SYS_QUEUE_SEND 24 // (uint32_t handle, void* msg, int blocking) -> KSTATUS #define SYS_QUEUE_RECV 25 // (uint32_t handle, void* msg, int blocking) -> KSTATUS // --------------------------------------------------------------------------- // Handle (unified close for all object types) // --------------------------------------------------------------------------- #define SYS_CLOSE_HANDLE 26 // (uint32_t handle) -> KSTATUS // --------------------------------------------------------------------------- // File I/O // (Close a file handle via SYS_CLOSE_HANDLE, same as any other object.) // --------------------------------------------------------------------------- #define SYS_OPEN_FILE 27 // (const char* path, uint32_t* handleOut) -> KSTATUS #define SYS_READ_FILE 28 // (uint32_t handle, void* buf, size_t size, size_t* bytesReadOut) -> KSTATUS #define SYS_WRITE_FILE 29 // (uint32_t handle, const void* buf, size_t size, size_t* bytesWrittenOut) -> KSTATUS #define SYS_CREATE_FILE 30 // (const char* path, uint32_t* handleOut) -> KSTATUS #define SYS_DELETE_FILE 31 // (const char* path) -> KSTATUS #define SYS_TRUNCATE_FILE 32 // (uint32_t handle, uint64_t newSize) -> KSTATUS #define SYS_GET_FILE_POS 33 // (uint32_t handle) -> uint64_t #define SYS_SEEK_FILE 34 // (uint32_t handle, uint64_t offset) -> KSTATUS #define SYS_GET_FILE_SIZE 35 // (uint32_t handle) -> uint64_t // --------------------------------------------------------------------------- // Screen / Graphics // --------------------------------------------------------------------------- #define SYS_SCREEN_BLIT 36 // (int x, int y, int w, int h, const uint32_t* pixels) -> void #define SYS_SCREEN_CLEAR 37 // (uint32_t color) -> void #define SYS_SCREEN_GET_SIZE 38 // (int* widthOut, int* heightOut) -> void #define SYS_SCREEN_PUT_CHAR 39 // (char c, int x, int y, uint32_t fg, uint32_t bg) -> void // --------------------------------------------------------------------------- // Keyboard // --------------------------------------------------------------------------- #define SYS_KB_POLL 40 // () -> uint32_t (1 if key available, 0 otherwise) #define SYS_KB_IS_KEY_DOWN 41 // (int scancode) -> uint32_t (1 if down, 0 otherwise) #define SYS_KB_READ_CHAR 42 // () -> char (blocks, yields while waiting) #define SYS_KB_READ_SCANCODE 43 // () -> uint8_t (blocks, yields while waiting) #define SYS_KB_GET_MODIFIERS 44 // () -> uint32_t (current modifier bitmask) // --------------------------------------------------------------------------- // Mouse // --------------------------------------------------------------------------- #define SYS_MOUSE_POLL 45 // () -> uint32_t (1 if packet waiting, 0 otherwise) #define SYS_MOUSE_READ 46 // (int* dx, int* dy, uint8_t* buttons) -> uint32_t (1=ok, 0=empty) #define SYS_MOUSE_GET_POS 47 // (int* x, int* y) -> void // --------------------------------------------------------------------------- // Timer // --------------------------------------------------------------------------- #define SYS_GET_TICK 48 // () -> uint64_t (milliseconds since boot) // --------------------------------------------------------------------------- // Debug // --------------------------------------------------------------------------- #define SYS_DEBUG_PRINT 49 // (const char* str) -> void // --------------------------------------------------------------------------- // Process launch & lifecycle // --------------------------------------------------------------------------- #define SYS_CREATE_PROCESS 50 // (const char* path, const char* args, uint32_t* pidOut) -> KSTATUS #define SYS_WAIT_FOR_PROCESS 51 // (uint32_t pid) -> KSTATUS #define SYS_GET_PROCESS_EXIT_CODE 52 // (uint32_t pid, int* exitCodeOut) -> KSTATUS // --------------------------------------------------------------------------- // Console output (white text, for user programs) // --------------------------------------------------------------------------- #define SYS_WRITE_CONSOLE 53 // (const char* str, size_t len) -> void // --------------------------------------------------------------------------- // Directory enumeration // --------------------------------------------------------------------------- #define SYS_OPEN_DIR 54 // (const char* path, uint32_t* handleOut) -> KSTATUS #define SYS_READ_DIR 55 // (uint32_t handle, DirEntry* entryOut) -> KSTATUS // --------------------------------------------------------------------------- // Current Working Directory // --------------------------------------------------------------------------- #define SYS_SET_CWD 56 // (const char* path) -> KSTATUS #define SYS_GET_CWD 57 // (char* buf, size_t buflen) -> KSTATUS // --------------------------------------------------------------------------- // Thread join (used by pthread_join in posix.dll) // --------------------------------------------------------------------------- #define SYS_WAIT_THREAD 58 // (uint32_t tid) -> KSTATUS // --------------------------------------------------------------------------- // Process PID query (used by posix_spawn -> waitpid in posix.dll) // --------------------------------------------------------------------------- #define SYS_GET_PROCESS_PID 59 // (uint32_t pid) -> KSTATUS // --------------------------------------------------------------------------- // Named Queue Registry // SysPublishQueue - register a queue under a name (call once at startup) // SysOpenNamedQueue - resolve a name to a handle (retry until SUCCESS) // --------------------------------------------------------------------------- #define SYS_PUBLISH_QUEUE 60 // (const char* name, uint32_t queueHandle) -> KSTATUS #define SYS_OPEN_NAMED_QUEUE 61 // (const char* name, uint32_t* handleOut) -> KSTATUS // --------------------------------------------------------------------------- // Handle duplication // --------------------------------------------------------------------------- #define SYS_QUEUE_DUPLICATE 62 // (uint32_t handle, uint32_t targetPid, uint32_t* handleOut) -> KSTATUS #define SYS_NAMED_QUEUE_OWNER_PID 63 // (const char* name, uint32_t* pidOut) -> KSTATUS // --------------------------------------------------------------------------- // Process utilities // --------------------------------------------------------------------------- #define SYS_KILL_PROCESS 64 // (uint32_t pid, int exitCode) -> KSTATUS #define SYS_GET_PROCESS_LIST 65 // (uint32_t* pidsOut, size_t maxCount, size_t* countOut) -> KSTATUS // --------------------------------------------------------------------------- // Filesystem mutations // --------------------------------------------------------------------------- #define SYS_RENAME_FILE 66 // (const char* oldPath, const char* newPath) -> KSTATUS #define SYS_CREATE_DIR 67 // (const char* path) -> KSTATUS #define SYS_REMOVE_DIR 68 // (const char* path) -> KSTATUS #define SYS_MAX 69