Browse Source

Move system calls to the SDK and normalize their names

coderain 6 years ago
parent
commit
549ee9217b

+ 2 - 2
kernel/include/clock.h

@@ -48,8 +48,8 @@
 #define CMOS_RTC_STC_REG 0x0C
 
 void clock_init();
-dword_t clock_get_time(clock_time_t *time);
+sysret_t syscall_clock_get_time(clock_time_t *time);
 bool_t clock_check_time(clock_time_t *time);
-dword_t clock_set_time(clock_time_t *time);
+sysret_t syscall_clock_set_time(clock_time_t *time);
 
 #endif

+ 1 - 0
kernel/include/cpu.h

@@ -21,6 +21,7 @@
 #define _CPU_H_
 
 #include <common.h>
+#include <sdk/cpu.h>
 
 #define CPU_FEATURE_FPU   (1 << 0)
 #define CPU_FEATURE_VME   (1 << 1)

+ 0 - 1
kernel/include/device.h

@@ -120,7 +120,6 @@ dword_t unregister_char_device(device_t *device);
 dword_t device_read(device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
 dword_t device_write(device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
 dword_t device_ioctl_internal(device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
-dword_t device_ioctl(handle_t device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
 void device_init(void);
 
 #endif

+ 3 - 40
kernel/include/exception.h

@@ -20,58 +20,21 @@
 #ifndef _EXCEPTION_H_
 #define _EXCEPTION_H_
 
+#define __MONOLITIHUM_KERNEL_MODE__
+
 #include <common.h>
 #include <interrupt.h>
-
-typedef registers_t exception_handler_t;
-
-typedef struct
-{
-    dword_t number;
-    dword_t parameters[15];
-} exception_info_t;
-
+#include <sdk/exception.h>
 #include <thread.h>
 
 #define KERNEL_CRASH(message) kernel_crash((message), NULL, __FILE__, __LINE__)
 #define KERNEL_CRASH_WITH_REGS(message, regs) kernel_crash((message), (regs), __FILE__, __LINE__)
 #define ASSERT(test) (test) ? 0 : KERNEL_CRASH("Assertion \"" #test "\" failed");
 
-#define EH_TRY if (get_current_thread() != NULL) { exception_handler_t ___handler; if (save_kernel_handler(&___handler) == 0)
-#define EH_CATCH else
-#define EH_DONE syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); }
-#define EH_ESCAPE(x) do { syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); x; } while (FALSE)
-
-enum
-{
-    EXCEPTION_DIVISION_BY_ZERO,
-    EXCEPTION_DEBUG_INT,
-    EXCEPTION_NMI,
-    EXCEPTION_BREAKPOINT,
-    EXCEPTION_OVERFLOW,
-    EXCEPTION_BOUND_RANGE,
-    EXCEPTION_INVALID_OPCODE,
-    EXCEPTION_NO_FPU,
-    EXCEPTION_DOUBLE_FAULT,
-    EXCEPTION_FPU_SEGMENT,
-    EXCEPTION_BAD_TSS,
-    EXCEPTION_NO_SEGMENT,
-    EXCEPTION_STACK_OVERFLOW,
-    EXCEPTION_GPF,
-    EXCEPTION_PAGE_FAULT,
-    EXCEPTION_ALIGNMENT,
-    EXCEPTION_HARDWARE,
-    NUM_EXCEPTIONS
-};
-
 extern void __attribute__((noreturn)) exception_return(registers_t regs);
 extern int __attribute__((returns_twice)) save_kernel_handler(exception_handler_t *old_handler);
 
-dword_t get_exception_info(exception_info_t *info);
-dword_t raise_exception(exception_info_t *info);
 void __attribute__((noreturn)) kernel_crash(const char *message, registers_t *regs, const char *filename, int line);
-int save_exception_handler(exception_handler_t *old_handler);
-dword_t restore_exception_handler(exception_handler_t *old_handler);
 void exceptions_init();
 
 #endif

+ 0 - 10
kernel/include/filesystem.h

@@ -118,16 +118,6 @@ dword_t register_mounted_volume(mounted_volume_t *volume);
 dword_t unregister_mounted_volume(mounted_volume_t *volume);
 dword_t normalize_path(const char *path, char *normalized_path);
 dword_t open_file_internal(const char *path, file_instance_t **instance, dword_t mode, dword_t attributes);
-dword_t open_file(const char *path, handle_t *handle, dword_t mode, dword_t attributes);
-dword_t delete_file(const char *path);
-dword_t query_file(handle_t handle, file_info_type_t info_type, void *buffer, size_t size);
-dword_t set_file(handle_t handle, file_info_type_t set_type, void *buffer, size_t size);
-dword_t list_directory(handle_t handle, char *filename, bool_t continue_scan);
-dword_t read_file(handle_t handle, void *buffer, qword_t offset, size_t size, size_t *bytes_read);
-dword_t write_file(handle_t handle, const void *buffer, qword_t offset, size_t size, size_t *bytes_written);
-dword_t mount(const char *device, const char *mountpoint, const char *filesystem, dword_t flags);
-dword_t unmount(const char *device);
-dword_t wait_directory_event(handle_t handle, dword_t event_mask, file_event_t *buffer, size_t size, dword_t timeout);
 void report_filesystem_event(const char *path, dword_t type);
 
 #endif

+ 1 - 24
kernel/include/interrupt.h

@@ -21,6 +21,7 @@
 #define _INTERRUPT_H_
 
 #include <common.h>
+#include <sdk/cpu.h>
 #include <sdk/list.h>
 
 #define IDT_NUM_INTERRUPTS 256
@@ -41,30 +42,6 @@ typedef struct
 } idt_entry_t;
 #pragma pack(pop)
 
-typedef struct
-{
-    dword_t data_selector;
-    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
-    dword_t error_code;
-    dword_t eip, cs, eflags;
-} registers_t;
-
-typedef struct
-{
-    dword_t data_selector;
-    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
-    dword_t error_code;
-    dword_t eip, cs, eflags, esp3, ss;
-} registers_ext_t;
-
-typedef struct
-{
-    dword_t data_selector;
-    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
-    dword_t error_code;
-    dword_t eip, cs, eflags, esp3, ss, es, ds, fs, gs;
-} registers_ext_vm86_t;
-
 typedef void (*isr_proc_t)(registers_t *regs, byte_t interrupt_num);
 
 typedef struct

+ 1 - 38
kernel/include/memory.h

@@ -26,14 +26,7 @@
 #include <avl_tree.h>
 #include <object.h>
 #include <filesystem.h>
-
-#define MEMORY_BLOCK_ACCESSIBLE    (1 << 0)
-#define MEMORY_BLOCK_WRITABLE      (1 << 1)
-#define MEMORY_BLOCK_EXECUTABLE    (1 << 2)
-#define MEMORY_BLOCK_USERMODE      (1 << 3)
-#define MEMORY_BLOCK_EVICTABLE     (1 << 29)
-#define MEMORY_BLOCK_COPY_ON_WRITE (1 << 30)
-#define MEMORY_BLOCK_FREE          (1 << 31)
+#include <sdk/memory.h>
 
 #define PAGE_SIZE      4096
 #define PAGE_PRESENT   (1 << 0)
@@ -84,9 +77,6 @@
 #define INVALID_STORE_NUMBER        ((dword_t)-1)
 #define PAGE_STORE_ENTRY_PRESENT    (1 << 31)
 
-#define MEMORY_SECTION_WRITABLE     (1 << 0)
-#define MEMORY_SECTION_DIRECT_WRITE (1 << 1)
-
 typedef struct memory_block memory_block_t;
 
 typedef struct
@@ -95,14 +85,6 @@ typedef struct
     uintptr_t ref_count;
 } page_t;
 
-typedef struct
-{
-    uintptr_t used_virtual;
-    uintptr_t committed;
-    uintptr_t evicted;
-    uintptr_t shared;
-} memory_stats_t;
-
 typedef struct
 {
     list_entry_t link;
@@ -145,13 +127,6 @@ struct memory_block
     qword_t section_offset;
 };
 
-typedef struct
-{
-    qword_t address;
-    qword_t size;
-    dword_t flags;
-} memory_block_info_t;
-
 typedef struct
 {
     list_entry_t link;
@@ -204,14 +179,6 @@ dword_t alloc_memory_in_address_space(
 dword_t free_memory_in_address_space(memory_address_space_t *address_space, void *address);
 dword_t commit_pages(void *address, size_t size);
 dword_t uncommit_pages(void *address, size_t size);
-dword_t alloc_memory(handle_t process, void **address, size_t size, dword_t block_flags);
-dword_t free_memory(handle_t process, void *address);
-dword_t commit_memory(handle_t process, void *address, dword_t size);
-dword_t uncommit_memory(handle_t process, void *address, dword_t size);
-dword_t set_memory_flags(handle_t process, void *address, dword_t flags);
-dword_t query_memory(handle_t process, void *address, memory_block_info_t *info);
-dword_t read_memory(handle_t process, void *address, void *buffer, dword_t size);
-dword_t write_memory(handle_t process, void *address, void *buffer, dword_t size);
 void *alloc_pool(void *address, size_t size, dword_t block_flags);
 void free_pool(void *address);
 dword_t create_address_space(void *base_address, dword_t page_count, memory_address_space_t *mem_space);
@@ -220,10 +187,6 @@ void bump_address_space(memory_address_space_t *mem_space);
 void delete_address_space(memory_address_space_t *mem_space);
 bool_t memory_fault_handler(void *address, registers_t *regs);
 void memory_init(multiboot_mmap_t *mmap_addr, dword_t mmap_length);
-dword_t create_memory_section(const char *name, handle_t file, size_t size, dword_t flags, handle_t *handle);
-dword_t open_memory_section(const char *name, handle_t *handle);
-dword_t map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags);
-dword_t flush_memory_section(handle_t process, void *address);
 void memory_cleanup(object_t *obj);
 
 #endif

+ 0 - 3
kernel/include/object.h

@@ -51,9 +51,6 @@ bool_t reference_by_handle(handle_t handle, object_type_t type, object_t **objec
 dword_t open_object(object_t *obj, access_flags_t access_flags, handle_t *handle);
 dword_t open_object_by_name(const char *name, object_type_t type, access_flags_t access_flags, handle_t *handle);
 void close_object_internal(object_t *obj);
-dword_t close_object(handle_t handle);
-dword_t query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size);
-dword_t duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate);
 dword_t enum_objects_by_type(object_type_t type, object_t **object);
 
 #endif

+ 4 - 4
kernel/include/pipe.h

@@ -41,9 +41,9 @@ typedef struct
     list_entry_t fifo;
 } pipe_t;
 
-dword_t create_pipe(const char *name, handle_t *handle);
-dword_t open_pipe(const char *name, handle_t *handle);
-dword_t read_pipe(handle_t handle, void *buffer, dword_t size, dword_t timeout);
-dword_t write_pipe(handle_t handle, void *buffer, dword_t size);
+sysret_t syscall_create_pipe(const char *name, handle_t *handle);
+sysret_t syscall_open_pipe(const char *name, handle_t *handle);
+sysret_t syscall_read_pipe(handle_t handle, void *buffer, dword_t size, dword_t timeout);
+sysret_t syscall_write_pipe(handle_t handle, void *buffer, dword_t size);
 
 #endif

+ 1 - 9
kernel/include/power.h

@@ -20,16 +20,8 @@
 #ifndef _POWER_H_
 #define _POWER_H_
 
-#include <common.h>
-
-typedef enum
-{
-    POWER_COMMAND_HALT,
-    POWER_COMMAND_REBOOT,
-    POWER_COMMAND_SHUTDOWN
-} power_command_t;
+#include <sdk/power.h>
 
 dword_t power_init(void);
-dword_t power_control(power_command_t command);
 
 #endif

+ 7 - 7
kernel/include/process.h

@@ -74,16 +74,16 @@ typedef struct process process_t;
 extern process_t *kernel_process;
 
 process_t *get_current_process();
-dword_t open_process(dword_t pid, handle_t *handle);
+sysret_t syscall_open_process(dword_t pid, handle_t *handle);
 void init_user_stack(uintptr_t *stack_pointer, process_params_t *parameters);
-dword_t create_process(const char *path, dword_t flags, process_params_t *parameters, handle_t *process_handle, handle_t *thread_handle);
+sysret_t syscall_create_process(const char *path, dword_t flags, process_params_t *parameters, handle_t *process_handle, handle_t *thread_handle);
 void process_cleanup(object_t *proc);
 void destroy_process(process_t *process);
-dword_t terminate(handle_t handle, dword_t exit_code);
-dword_t get_process_id();
-dword_t query_process(handle_t handle, process_info_t info_type, void *buffer, dword_t size);
-dword_t enum_processes(dword_t *pid_array, dword_t *count);
-dword_t wait_process(handle_t handle, dword_t timeout);
+sysret_t syscall_terminate(handle_t handle, dword_t exit_code);
+sysret_t syscall_get_process_id();
+sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *buffer, dword_t size);
+sysret_t syscall_enum_processes(dword_t *pid_array, dword_t *count);
+sysret_t syscall_wait_process(handle_t handle, dword_t timeout);
 process_t *switch_process(process_t *new_process);
 void process_init();
 

+ 4 - 4
kernel/include/sync.h

@@ -48,11 +48,11 @@ void acquire_resource_shared(resource_t *res);
 void acquire_resource_exclusive(resource_t *res);
 void release_resource(resource_t *res);
 void init_semaphore(semaphore_t *semaphore, dword_t init_count, dword_t max_count);
-dword_t create_semaphore(const char *name, dword_t init_count, dword_t max_count, handle_t *handle);
-dword_t open_semaphore(const char *name, handle_t *handle);
+sysret_t syscall_create_semaphore(const char *name, dword_t init_count, dword_t max_count, handle_t *handle);
+sysret_t syscall_open_semaphore(const char *name, handle_t *handle);
 dword_t wait_semaphore(semaphore_t *semaphore, dword_t count, dword_t timeout);
 dword_t release_semaphore(semaphore_t *semaphore, dword_t count);
-dword_t wait_semaphore_by_handle(handle_t semaphore, dword_t count, dword_t timeout);
-dword_t release_semaphore_by_handle(handle_t semaphore, dword_t count);
+sysret_t syscall_wait_semaphore(handle_t semaphore, dword_t count, dword_t timeout);
+sysret_t syscall_release_semaphore(handle_t semaphore, dword_t count);
 
 #endif

+ 1 - 40
kernel/include/thread.h

@@ -27,27 +27,15 @@
 #include <sync.h>
 #include <interrupt.h>
 #include <syscalls.h>
+#include <sdk/thread.h>
 
 #define QUANTUM 30
 #define MAX_THREADS 2097152
 #define KERNEL_STACK_SIZE 262144
 
-#define THREAD_CREATE_FROZEN (1 << 0)
-
 #define SAFE_EFLAGS_MASK 0x00000CD5
 
 typedef dword_t (*thread_procedure_t)(void*);
-typedef dword_t priority_t;
-typedef qword_t affinity_t;
-
-typedef enum
-{
-    THREAD_TID_INFO,
-    THREAD_FROZEN_INFO,
-    THREAD_CPU_STATE_INFO,
-    THREAD_PRIORITY_INFO,
-    THREAD_AFFINITY_INFO,
-} thread_info_t;
 
 typedef enum
 {
@@ -68,22 +56,6 @@ typedef enum
     WAIT_CANCELED
 } wait_result_t;
 
-enum
-{
-    THREAD_PRIORITY_HIGH,
-    THREAD_PRIORITY_MID,
-    THREAD_PRIORITY_LOW,
-    THREAD_PRIORITY_IDLE,
-
-    THREAD_PRIORITY_MAX
-};
-
-typedef struct
-{
-    registers_t regs;
-    byte_t fpu_state[512];
-} thread_state_t;
-
 #ifndef PROCESS_TYPEDEF
 #define PROCESS_TYPEDEF
 typedef struct process process_t;
@@ -134,21 +106,10 @@ typedef struct thread thread_t;
 extern bool_t scheduler_enabled;
 
 thread_t *get_current_thread();
-dword_t get_thread_id();
-dword_t open_thread(dword_t tid, handle_t *handle);
 dword_t create_thread_internal(process_t *proc, thread_state_t *initial_state, dword_t flags, priority_t priority, void *kernel_stack, thread_t **new_thread);
-dword_t create_thread(handle_t process, thread_state_t *initial_state, dword_t flags, priority_t priority, handle_t *new_thread);
 dword_t terminate_thread_internal(thread_t *thread, dword_t return_value);
-dword_t terminate_thread(handle_t thread, dword_t return_value);
-dword_t freeze_thread(handle_t handle);
-dword_t thaw_thread(handle_t handle);
 void scheduler(registers_t *regs);
 wait_result_t scheduler_wait(wait_condition_t condition, dword_t timeout, uintptr_t *pointer, uintptr_t value);
-void sleep(qword_t milliseconds);
-void yield_quantum();
-dword_t query_thread(handle_t handle, thread_info_t info_type, void *buffer, size_t size);
-dword_t set_thread(handle_t handle, thread_info_t info_type, const void *buffer, size_t size);
-dword_t wait_thread(handle_t handle, dword_t timeout);
 dword_t create_system_thread(thread_procedure_t routine, dword_t flags, priority_t priority, dword_t stack_size, void *param, thread_t **new_thread);
 void thread_init(void);
 

+ 2 - 2
kernel/include/timer.h

@@ -31,8 +31,8 @@
 #define TIMER_RATE_GENERATOR(x) (((x) << 6) | 0x34)
 #define TIMER_SQUARE_WAVE(x) (((x) << 6) | 0x36)
 
-qword_t get_milliseconds(void);
-qword_t get_nanoseconds(void);
+sysret_t syscall_get_milliseconds(void);
+sysret_t syscall_get_nanoseconds(void);
 void timer_init(void);
 
 #endif

+ 1 - 82
kernel/include/user.h

@@ -22,77 +22,10 @@
 
 #include <common.h>
 #include <object.h>
+#include <sdk/user.h>
 
-#define MAX_USERNAME_LENGTH 32
 #define LOGIN_ATTEMPT_TIMEOUT 3000
 
-#define PRIVILEGE_LOGON_USER       (1ULL << 0)
-#define PRIVILEGE_NETWORK_ACCESS   (1ULL << 1)
-#define PRIVILEGE_MOUNT_UNMOUNT    (1ULL << 2)
-#define PRIVILEGE_UNNAMED3         (1ULL << 3)
-#define PRIVILEGE_UNNAMED4         (1ULL << 4)
-#define PRIVILEGE_UNNAMED5         (1ULL << 5)
-#define PRIVILEGE_UNNAMED6         (1ULL << 6)
-#define PRIVILEGE_UNNAMED7         (1ULL << 7)
-#define PRIVILEGE_UNNAMED8         (1ULL << 8)
-#define PRIVILEGE_UNNAMED9         (1ULL << 9)
-#define PRIVILEGE_UNNAMED10        (1ULL << 10)
-#define PRIVILEGE_UNNAMED11        (1ULL << 11)
-#define PRIVILEGE_UNNAMED12        (1ULL << 12)
-#define PRIVILEGE_UNNAMED13        (1ULL << 13)
-#define PRIVILEGE_UNNAMED14        (1ULL << 14)
-#define PRIVILEGE_UNNAMED15        (1ULL << 15)
-#define PRIVILEGE_UNNAMED16        (1ULL << 16)
-#define PRIVILEGE_UNNAMED17        (1ULL << 17)
-#define PRIVILEGE_UNNAMED18        (1ULL << 18)
-#define PRIVILEGE_UNNAMED19        (1ULL << 19)
-#define PRIVILEGE_UNNAMED20        (1ULL << 20)
-#define PRIVILEGE_UNNAMED21        (1ULL << 21)
-#define PRIVILEGE_UNNAMED22        (1ULL << 22)
-#define PRIVILEGE_UNNAMED23        (1ULL << 23)
-#define PRIVILEGE_UNNAMED24        (1ULL << 24)
-#define PRIVILEGE_UNNAMED25        (1ULL << 25)
-#define PRIVILEGE_UNNAMED26        (1ULL << 26)
-#define PRIVILEGE_UNNAMED27        (1ULL << 27)
-#define PRIVILEGE_UNNAMED28        (1ULL << 28)
-#define PRIVILEGE_UNNAMED29        (1ULL << 29)
-#define PRIVILEGE_UNNAMED30        (1ULL << 30)
-#define PRIVILEGE_SET_TIME         (1ULL << 31)
-#define PRIVILEGE_ACCESS_ALL       (1ULL << 32)
-#define PRIVILEGE_CHARACTER_DEVICE (1ULL << 33)
-#define PRIVILEGE_BLOCK_DEVICE     (1ULL << 34)
-#define PRIVILEGE_UNNAMED35        (1ULL << 35)
-#define PRIVILEGE_UNNAMED36        (1ULL << 36)
-#define PRIVILEGE_UNNAMED37        (1ULL << 37)
-#define PRIVILEGE_UNNAMED38        (1ULL << 38)
-#define PRIVILEGE_UNNAMED39        (1ULL << 39)
-#define PRIVILEGE_UNNAMED40        (1ULL << 40)
-#define PRIVILEGE_UNNAMED41        (1ULL << 41)
-#define PRIVILEGE_UNNAMED42        (1ULL << 42)
-#define PRIVILEGE_UNNAMED43        (1ULL << 43)
-#define PRIVILEGE_UNNAMED44        (1ULL << 44)
-#define PRIVILEGE_UNNAMED45        (1ULL << 45)
-#define PRIVILEGE_UNNAMED46        (1ULL << 46)
-#define PRIVILEGE_UNNAMED47        (1ULL << 47)
-#define PRIVILEGE_UNNAMED48        (1ULL << 48)
-#define PRIVILEGE_UNNAMED49        (1ULL << 49)
-#define PRIVILEGE_UNNAMED50        (1ULL << 50)
-#define PRIVILEGE_UNNAMED51        (1ULL << 51)
-#define PRIVILEGE_UNNAMED52        (1ULL << 52)
-#define PRIVILEGE_UNNAMED53        (1ULL << 53)
-#define PRIVILEGE_UNNAMED54        (1ULL << 54)
-#define PRIVILEGE_UNNAMED55        (1ULL << 55)
-#define PRIVILEGE_UNNAMED56        (1ULL << 56)
-#define PRIVILEGE_UNNAMED57        (1ULL << 57)
-#define PRIVILEGE_UNNAMED58        (1ULL << 58)
-#define PRIVILEGE_MANAGE_USERS     (1ULL << 59)
-#define PRIVILEGE_PROCESS_CONTROL  (1ULL << 60)
-#define PRIVILEGE_SET_PAGE_FILE    (1ULL << 61)
-#define PRIVILEGE_POWER_CONTROL    (1ULL << 62)
-#define PRIVILEGE_CHANGE_UID       (1ULL << 63)
-
-#define ALL_PRIVILEGES 0xFFFFFFFFFFFFFFFFULL
-
 typedef struct
 {
     object_t header;
@@ -103,21 +36,7 @@ typedef struct
     qword_t last_login_attempt;
 } user_t;
 
-typedef enum
-{
-    USER_NAME_INFO,
-    USER_PRIVILEGE_INFO,
-} user_info_t;
-
 bool_t check_privileges(qword_t privilege_mask);
-dword_t create_user(dword_t uid, const char *name, dword_t *password_hash, qword_t privileges);
-dword_t delete_user(dword_t uid);
-dword_t get_user_id(void);
-dword_t set_user_id(dword_t uid);
-dword_t revert_user(void);
-dword_t logon_user(dword_t uid, const char *password);
-dword_t logoff_user(dword_t uid);
-dword_t query_user(dword_t uid, user_info_t, void *buffer, dword_t size);
 void user_init(void);
 
 #endif

+ 5 - 5
kernel/src/acpica/osmlxf.c

@@ -236,23 +236,23 @@ ACPI_STATUS AcpiOsSignalSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units)
 
 UINT64 AcpiOsGetTimer(void)
 {
-    return get_nanoseconds() / 100ULL;
+    return syscall_get_nanoseconds() / 100ULL;
 }
 
 void AcpiOsSleep(UINT64 Milliseconds)
 {
-    sleep(Milliseconds);
+    syscall_sleep(Milliseconds);
 }
 
 void AcpiOsStall(UINT32 Microseconds)
 {
-    qword_t end_time = get_nanoseconds() + (qword_t)Microseconds * 1000ULL;
-    while (get_nanoseconds() < end_time) continue;
+    qword_t end_time = syscall_get_nanoseconds() + (qword_t)Microseconds * 1000ULL;
+    while (syscall_get_nanoseconds() < end_time) continue;
 }
 
 ACPI_THREAD_ID AcpiOsGetThreadId(void)
 {
-    return get_thread_id() + 1;
+    return syscall_get_thread_id() + 1;
 }
 
 ACPI_STATUS AcpiOsInstallInterruptHandler(UINT32 InterruptLevel, ACPI_OSD_HANDLER Handler, void *Context)

+ 2 - 2
kernel/src/clock.c

@@ -87,7 +87,7 @@ bool_t clock_check_time(clock_time_t *time)
     return TRUE;
 }
 
-dword_t clock_get_time(clock_time_t *time)
+sysret_t syscall_clock_get_time(clock_time_t *time)
 {
     if (get_previous_mode() != KERNEL_MODE && !check_usermode(time, sizeof(clock_time_t)))
     {
@@ -112,7 +112,7 @@ dword_t clock_get_time(clock_time_t *time)
     return ERR_SUCCESS;
 }
 
-dword_t clock_set_time(clock_time_t *time)
+sysret_t syscall_clock_set_time(clock_time_t *time)
 {
     clock_time_t safe_time = {0};
 

+ 1 - 1
kernel/src/device.c

@@ -465,7 +465,7 @@ dword_t device_ioctl_internal(device_t *device, dword_t control_code, const void
     return ret;
 }
 
-dword_t device_ioctl(handle_t device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
+sysret_t syscall_device_ioctl(handle_t device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
 {
     dword_t ret = ERR_SUCCESS;
     byte_t *safe_in_buffer = NULL;

+ 4 - 4
kernel/src/drivers/floppy.c

@@ -72,7 +72,7 @@ static bool_t floppy_fifo_write(byte_t byte)
     {
         byte_t msr = inportb(FLOPPY_MSR);
         if (msr & 0x80) break;
-        sleep(1);
+        syscall_sleep(1);
     }
 
     if (timeout != 0) outportb(FLOPPY_FIFO, byte);
@@ -89,7 +89,7 @@ static bool_t floppy_fifo_read(byte_t *byte)
     {
         byte_t msr = inportb(FLOPPY_MSR);
         if (msr & 0x80) break;
-        sleep(1);
+        syscall_sleep(1);
     }
 
     if (timeout != 0) *byte = inportb(FLOPPY_FIFO);
@@ -165,7 +165,7 @@ static dword_t floppy_motor_thread(void *param)
         }
 
         release_lock(&floppy_motor_lock);
-        sleep(3000);
+        syscall_sleep(3000);
     }
 
     return 0;
@@ -181,7 +181,7 @@ static void floppy_motor_on(dword_t drive)
         dor |= 1 << (4 + (drive & 1));
         outportb(FLOPPY_DOR, dor);
 
-        sleep(300);
+        syscall_sleep(300);
     }
 
     floppy_motor_status[drive & 1] = FLOPPY_MOTOR_RUNNING;

+ 4 - 4
kernel/src/drivers/fs/fat.c

@@ -651,7 +651,7 @@ static dword_t fatfs_mount(const char *device, const char *mountpoint, dword_t f
     volume->sectors_per_fat = sectors_per_fat;
     volume->total_clusters = total_clusters;
     volume->last_free_cluster = volume->root_dir_cluster + 1;
-    volume->owner_uid = get_user_id();
+    volume->owner_uid = syscall_get_user_id();
 
     ret = register_mounted_volume(&volume->header);
     if (ret != ERR_SUCCESS) free(volume);
@@ -771,7 +771,7 @@ static dword_t fatfs_load_file(file_t **_file)
         if (ret != ERR_SUCCESS) return ret;
 
         clock_time_t current_time;
-        clock_get_time(&current_time);
+        syscall(SYSCALL_CLOCK_GET_TIME, &current_time);
 
         dirent.attributes = 0;
         if (!(file->header.attributes & FILE_ATTR_OWNER_WRITABLE)) dirent.attributes |= FATFS_ATTR_READONLY;
@@ -846,7 +846,7 @@ static dword_t fatfs_open_file(file_instance_t **_instance)
     fatfs_file_t *file = CONTAINER_OF((*_instance)->global, fatfs_file_t, header);
 
     fatfs_volume_t *volume = CONTAINER_OF(file->header.volume, fatfs_volume_t, header);
-    if (get_user_id() != volume->owner_uid) return ERR_FORBIDDEN;
+    if (syscall_get_user_id() != volume->owner_uid) return ERR_FORBIDDEN;
 
     fatfs_file_instance_t *instance = (fatfs_file_instance_t*)realloc(*_instance, sizeof(fatfs_file_instance_t));
     if (instance == NULL) return ERR_NOMEMORY;
@@ -865,7 +865,7 @@ static dword_t fatfs_close_file(file_instance_t *_instance)
 static dword_t fatfs_delete_file(mounted_volume_t *_volume, const char *path, bool_t purge)
 {
     fatfs_volume_t *volume = CONTAINER_OF(volume, fatfs_volume_t, header);
-    if (get_user_id() != volume->owner_uid) return ERR_FORBIDDEN;
+    if (syscall_get_user_id() != volume->owner_uid) return ERR_FORBIDDEN;
 
     fatfs_dirent_t dirent;
     dword_t cluster_num;

+ 4 - 4
kernel/src/drivers/ps2.c

@@ -42,11 +42,11 @@ static ps2_device_t *ps2_devices[2] = { NULL };
 
 static inline bool_t poll_and_read(byte_t *byte)
 {
-    qword_t end_time = get_milliseconds() + (qword_t)PS2_TIMEOUT;
+    qword_t end_time = syscall_get_milliseconds() + (qword_t)PS2_TIMEOUT;
 
     while (!(inportb(PS2_STATUS_PORT) & PS2_OUTPUT_BUFFER_FULL))
     {
-        if (get_milliseconds() >= end_time) return FALSE;
+        if (syscall_get_milliseconds() >= end_time) return FALSE;
     }
 
     *byte = inportb(PS2_DATA_PORT);
@@ -55,11 +55,11 @@ static inline bool_t poll_and_read(byte_t *byte)
 
 static inline bool_t poll_and_write(byte_t byte)
 {
-    qword_t end_time = get_milliseconds() + (qword_t)PS2_TIMEOUT;
+    qword_t end_time = syscall_get_milliseconds() + (qword_t)PS2_TIMEOUT;
 
     while (inportb(PS2_STATUS_PORT) & PS2_INPUT_BUFFER_FULL)
     {
-        if (get_milliseconds() >= end_time) return FALSE;
+        if (syscall_get_milliseconds() >= end_time) return FALSE;
     }
 
     outportb(PS2_DATA_PORT, byte);

+ 5 - 5
kernel/src/exception.c

@@ -81,7 +81,7 @@ static void raise_exception_internal(registers_t *regs, processor_mode_t mode, e
         else
         {
             enable_ints();
-            terminate(INVALID_HANDLE, 1);
+            syscall_terminate(INVALID_HANDLE, 1);
             ASSERT(FALSE);
         }
     }
@@ -119,7 +119,7 @@ static void exception_handler(registers_t *regs, byte_t int_num)
     raise_exception_internal(regs, SEGMENT_RPL(regs->cs) == 0 ? KERNEL_MODE : USER_MODE, &info);
 }
 
-dword_t raise_exception(exception_info_t *info)
+sysret_t syscall_raise_exception(exception_info_t *info)
 {
     exception_info_t safe_info;
 
@@ -141,7 +141,7 @@ dword_t raise_exception(exception_info_t *info)
     return ERR_SUCCESS;
 }
 
-dword_t get_exception_info(exception_info_t *info)
+sysret_t syscall_get_exception_info(exception_info_t *info)
 {
     thread_t *thread = get_current_thread();
 
@@ -183,13 +183,13 @@ void set_exception_handler(registers_t *regs, processor_mode_t mode, exception_h
     }
 }
 
-int save_exception_handler(exception_handler_t *old_handler)
+sysret_t syscall_save_exception_handler(exception_handler_t *old_handler)
 {
     set_exception_handler(old_handler, USER_MODE, get_current_thread()->syscall_regs);
     return 0;
 }
 
-dword_t restore_exception_handler(exception_handler_t *old_handler)
+sysret_t syscall_restore_exception_handler(exception_handler_t *old_handler)
 {
     thread_t *thread = get_current_thread();
 

+ 11 - 11
kernel/src/filesystem.c

@@ -253,7 +253,7 @@ dword_t normalize_path(const char *path, char *normalized_path)
     return ret;
 }
 
-dword_t mount(const char *device, const char *mountpoint, const char *filesystem, dword_t flags)
+sysret_t syscall_mount(const char *device, const char *mountpoint, const char *filesystem, dword_t flags)
 {
     dword_t ret = ERR_NOTFOUND;
     list_entry_t *i;
@@ -299,7 +299,7 @@ dword_t mount(const char *device, const char *mountpoint, const char *filesystem
     return ret;
 }
 
-dword_t unmount(const char *mountpoint)
+sysret_t syscall_unmount(const char *mountpoint)
 {
     acquire_resource_exclusive(&volume_list_res);
     list_entry_t *ptr;
@@ -421,7 +421,7 @@ dword_t open_file_internal(const char *path, file_instance_t **file_instance, dw
     return ret;
 }
 
-dword_t open_file(const char *path, handle_t *handle, dword_t mode, dword_t attributes)
+sysret_t syscall_open_file(const char *path, handle_t *handle, dword_t mode, dword_t attributes)
 {
     dword_t ret = ERR_SUCCESS;
     file_instance_t *file;
@@ -456,7 +456,7 @@ dword_t open_file(const char *path, handle_t *handle, dword_t mode, dword_t attr
     }
     EH_CATCH
     {
-        close_object(safe_handle);
+        syscall_close_object(safe_handle);
         ret = ERR_BADPTR;
     }
     EH_DONE;
@@ -466,7 +466,7 @@ cleanup:
     return ret;
 }
 
-dword_t delete_file(const char *path)
+sysret_t syscall_delete_file(const char *path)
 {
     dword_t ret = ERR_SUCCESS;
     char normalized_path[MAX_PATH];
@@ -510,7 +510,7 @@ cleanup:
     return ret;
 }
 
-dword_t query_file(handle_t handle, file_info_type_t type, void *buffer, size_t size)
+sysret_t syscall_query_file(handle_t handle, file_info_type_t type, void *buffer, size_t size)
 {
     dword_t ret = ERR_SUCCESS;
     void *safe_buffer;
@@ -577,7 +577,7 @@ dword_t query_file(handle_t handle, file_info_type_t type, void *buffer, size_t
     return ret;
 }
 
-dword_t set_file(handle_t handle, file_info_type_t set_type, void *buffer, size_t size)
+sysret_t syscall_set_file(handle_t handle, file_info_type_t set_type, void *buffer, size_t size)
 {
     void *safe_buffer;
     file_instance_t *file = NULL;
@@ -606,7 +606,7 @@ dword_t set_file(handle_t handle, file_info_type_t set_type, void *buffer, size_
     return ret;
 }
 
-dword_t list_directory(handle_t handle, char *filename, bool_t continue_scan)
+sysret_t syscall_list_directory(handle_t handle, char *filename, bool_t continue_scan)
 {
     file_instance_t *directory;
     char safe_filename[MAX_PATH];
@@ -631,7 +631,7 @@ dword_t list_directory(handle_t handle, char *filename, bool_t continue_scan)
     return ret;
 }
 
-dword_t read_file(handle_t handle, void *buffer, qword_t offset, size_t size, size_t *bytes_read)
+sysret_t syscall_read_file(handle_t handle, void *buffer, qword_t offset, size_t size, size_t *bytes_read)
 {
     dword_t ret;
     file_instance_t *file;
@@ -673,7 +673,7 @@ cleanup:
     return ret;
 }
 
-dword_t write_file(handle_t handle, const void *buffer, qword_t offset, size_t size, dword_t *bytes_written)
+sysret_t syscall_write_file(handle_t handle, const void *buffer, qword_t offset, size_t size, dword_t *bytes_written)
 {
     dword_t ret;
     file_instance_t *file;
@@ -720,7 +720,7 @@ cleanup:
     return ret;
 }
 
-dword_t wait_directory_event(handle_t handle, dword_t event_mask, file_event_t *buffer, size_t size, dword_t timeout)
+sysret_t syscall_wait_directory_event(handle_t handle, dword_t event_mask, file_event_t *buffer, size_t size, dword_t timeout)
 {
     file_instance_t *directory;
 

+ 19 - 19
kernel/src/memory/memory.c

@@ -410,7 +410,7 @@ next:
         entry->number = i;
 
         dword_t bytes_written;
-        ret = write_file(store->file_handle, buffer, (qword_t)entry->number * (qword_t)PAGE_SIZE, PAGE_SIZE, &bytes_written);
+        ret = syscall_write_file(store->file_handle, buffer, (qword_t)entry->number * (qword_t)PAGE_SIZE, PAGE_SIZE, &bytes_written);
         if (ret != ERR_SUCCESS)
         {
             reference_page(physical);
@@ -1300,7 +1300,7 @@ dword_t write_physical(void *physical, void *buffer, dword_t size)
     return ret;
 }
 
-dword_t alloc_memory(handle_t process, void **address, dword_t size, dword_t flags)
+sysret_t syscall_alloc_memory(handle_t process, void **address, dword_t size, dword_t flags)
 {
     process_t *proc;
     dword_t ret = ERR_SUCCESS;
@@ -1348,7 +1348,7 @@ dword_t alloc_memory(handle_t process, void **address, dword_t size, dword_t fla
     return ret;
 }
 
-dword_t free_memory(handle_t process, void *address)
+sysret_t syscall_free_memory(handle_t process, void *address)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -1369,7 +1369,7 @@ dword_t free_memory(handle_t process, void *address)
     return ret;
 }
 
-dword_t commit_memory(handle_t process, void *address, dword_t size)
+sysret_t syscall_commit_memory(handle_t process, void *address, dword_t size)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -1398,7 +1398,7 @@ dword_t commit_memory(handle_t process, void *address, dword_t size)
     return ret;
 }
 
-dword_t uncommit_memory(handle_t process, void *address, dword_t size)
+sysret_t syscall_uncommit_memory(handle_t process, void *address, dword_t size)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -1427,7 +1427,7 @@ dword_t uncommit_memory(handle_t process, void *address, dword_t size)
     return ret;
 }
 
-dword_t set_memory_flags(handle_t process, void *address, dword_t flags)
+sysret_t syscall_set_memory_flags(handle_t process, void *address, dword_t flags)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -1505,7 +1505,7 @@ cleanup:
     return ret;
 }
 
-dword_t query_memory(handle_t process, void *address, memory_block_info_t *info)
+sysret_t syscall_query_memory(handle_t process, void *address, memory_block_info_t *info)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -1552,7 +1552,7 @@ cleanup:
     return ret;
 }
 
-dword_t read_memory(handle_t process, void *address, void *buffer, dword_t size)
+sysret_t syscall_read_memory(handle_t process, void *address, void *buffer, dword_t size)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -1611,7 +1611,7 @@ dword_t read_memory(handle_t process, void *address, void *buffer, dword_t size)
     return ret;
 }
 
-dword_t write_memory(handle_t process, void *address, void *buffer, dword_t size)
+sysret_t syscall_write_memory(handle_t process, void *address, void *buffer, dword_t size)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -1695,7 +1695,7 @@ void free_pool(void *address)
     free_memory_in_address_space(&kernel_address_space, address);
 }
 
-dword_t create_memory_section(const char *name, handle_t file, size_t max_size, dword_t flags, handle_t *handle)
+sysret_t syscall_create_memory_section(const char *name, handle_t file, size_t max_size, dword_t flags, handle_t *handle)
 {
     dword_t ret = ERR_SUCCESS;
     handle_t safe_handle;
@@ -1767,7 +1767,7 @@ dword_t create_memory_section(const char *name, handle_t file, size_t max_size,
         }
         EH_CATCH
         {
-            close_object(safe_handle);
+            syscall_close_object(safe_handle);
             ret = ERR_BADPTR;
         }
         EH_DONE;
@@ -1780,7 +1780,7 @@ cleanup:
     return ret;
 }
 
-dword_t open_memory_section(const char *name, handle_t *handle)
+sysret_t syscall_open_memory_section(const char *name, handle_t *handle)
 {
     handle_t safe_handle;
     char *safe_name = NULL;
@@ -1809,7 +1809,7 @@ dword_t open_memory_section(const char *name, handle_t *handle)
     }
     EH_CATCH
     {
-        close_object(safe_handle);
+        syscall_close_object(safe_handle);
         ret = ERR_BADPTR;
     }
     EH_DONE;
@@ -1818,7 +1818,7 @@ dword_t open_memory_section(const char *name, handle_t *handle)
     return ret;
 }
 
-dword_t map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags)
+sysret_t syscall_map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc = NULL;
@@ -1882,7 +1882,7 @@ cleanup:
     return ret;
 }
 
-dword_t flush_memory_section(handle_t process, void *address)
+sysret_t syscall_flush_memory_section(handle_t process, void *address)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc = NULL;
@@ -1936,7 +1936,7 @@ cleanup:
     return ret;
 }
 
-dword_t add_page_file(const char *path, dword_t max_entries)
+sysret_t syscall_add_page_file(const char *path, dword_t max_entries)
 {
     dword_t ret;
     char *safe_path = NULL;
@@ -2008,7 +2008,7 @@ cleanup:
     return ret;
 }
 
-dword_t remove_page_file(const char *path)
+sysret_t syscall_remove_page_file(const char *path)
 {
     dword_t ret = ERR_SUCCESS;
     char *safe_path = NULL;
@@ -2083,7 +2083,7 @@ dword_t remove_page_file(const char *path)
         dword_t page_flags = 0;
         page_store_entry_t *entry = CONTAINER_OF(ptr, page_store_entry_t, link);
 
-        ret = read_file(store->file_handle, buffer, (qword_t)entry->number * (qword_t)PAGE_SIZE, PAGE_SIZE, &bytes_read);
+        ret = syscall_read_file(store->file_handle, buffer, (qword_t)entry->number * (qword_t)PAGE_SIZE, PAGE_SIZE, &bytes_read);
         if (ret != ERR_SUCCESS) break;
 
         acquire_resource_exclusive(&entry->address_space->resource);
@@ -2432,7 +2432,7 @@ done:
         if (entry->number != INVALID_STORE_NUMBER)
         {
             enable_ints();
-            dword_t ret = read_file(store->file_handle, buffer, (qword_t)entry->number * (qword_t)PAGE_SIZE, PAGE_SIZE, &bytes_read);
+            dword_t ret = syscall_read_file(store->file_handle, buffer, (qword_t)entry->number * (qword_t)PAGE_SIZE, PAGE_SIZE, &bytes_read);
             disable_ints();
 
             if ((page_directory[pd_index] & PAGE_PRESENT) && (page_table[pt_index] & PAGE_PRESENT))

+ 4 - 4
kernel/src/object.c

@@ -88,7 +88,7 @@ static bool_t access_check(object_t *obj, access_flags_t access_flags)
     if (check_privileges(PRIVILEGE_ACCESS_ALL)) return TRUE;
 
     list_entry_t *ptr;
-    dword_t uid = get_user_id();
+    dword_t uid = syscall_get_user_id();
 
     for (ptr = obj->acl.next; ptr != &obj->acl; ptr = ptr->next)
     {
@@ -277,7 +277,7 @@ void close_object_internal(object_t *obj)
     }
 }
 
-dword_t close_object(handle_t handle)
+sysret_t syscall_close_object(handle_t handle)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc = get_previous_mode() == USER_MODE ? get_current_process() : kernel_process;
@@ -312,7 +312,7 @@ dword_t close_object(handle_t handle)
     return ret;
 }
 
-dword_t query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size)
+sysret_t syscall_query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size)
 {
     dword_t ret = ERR_SUCCESS;
     process_t *proc;
@@ -374,7 +374,7 @@ cleanup:
     return ret;
 }
 
-dword_t duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate)
+sysret_t syscall_duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate)
 {
     process_t *proc;
     handle_t safe_handle;

+ 4 - 4
kernel/src/pipe.c

@@ -24,7 +24,7 @@
 #include <syscalls.h>
 #include <heap.h>
 
-dword_t create_pipe(const char *name, handle_t *handle)
+sysret_t syscall_create_pipe(const char *name, handle_t *handle)
 {
     dword_t ret;
     handle_t safe_handle;
@@ -91,7 +91,7 @@ cleanup:
     return ret;
 }
 
-dword_t open_pipe(const char *name, handle_t *handle)
+sysret_t syscall_open_pipe(const char *name, handle_t *handle)
 {
     handle_t safe_handle;
     char *safe_name = NULL;
@@ -133,7 +133,7 @@ cleanup:
     return ret;
 }
 
-dword_t read_pipe(handle_t handle, void *buffer, dword_t size, dword_t timeout)
+sysret_t syscall_read_pipe(handle_t handle, void *buffer, dword_t size, dword_t timeout)
 {
     pipe_t *pipe;
     byte_t *safe_buffer = NULL;
@@ -199,7 +199,7 @@ dword_t read_pipe(handle_t handle, void *buffer, dword_t size, dword_t timeout)
     return ret;
 }
 
-dword_t write_pipe(handle_t handle, void *buffer, dword_t size)
+sysret_t syscall_write_pipe(handle_t handle, void *buffer, dword_t size)
 {
     pipe_t *pipe;
     byte_t *safe_buffer = NULL;

+ 1 - 1
kernel/src/power.c

@@ -37,7 +37,7 @@ dword_t power_init(void)
     return ERR_SUCCESS;
 }
 
-dword_t power_control(power_command_t command)
+sysret_t syscall_power_control(power_command_t command)
 {
     if (get_previous_mode() == USER_MODE && !check_privileges(PRIVILEGE_POWER_CONTROL))
     {

+ 13 - 13
kernel/src/process.c

@@ -104,7 +104,7 @@ process_t *get_current_process()
     return thread->owner_process;
 }
 
-dword_t open_process(dword_t pid, handle_t *handle)
+sysret_t syscall_open_process(dword_t pid, handle_t *handle)
 {
     dword_t ret;
     process_t *proc = NULL;
@@ -123,7 +123,7 @@ dword_t open_process(dword_t pid, handle_t *handle)
 
     if (ret == ERR_SUCCESS)
     {
-        if (proc->current_user->uid == get_user_id() || check_privileges(PRIVILEGE_PROCESS_CONTROL))
+        if (proc->current_user->uid == syscall_get_user_id() || check_privileges(PRIVILEGE_PROCESS_CONTROL))
         {
             ret = open_object(&proc->header, 0, handle);
         }
@@ -198,7 +198,7 @@ void init_user_stack(uintptr_t *stack_pointer, process_params_t *parameters)
     push_to_stack(stack_pointer, end_code_addr);
 }
 
-dword_t create_process(const char *path, dword_t flags, process_params_t *parameters, handle_t *process_handle, handle_t *thread_handle)
+sysret_t syscall_create_process(const char *path, dword_t flags, process_params_t *parameters, handle_t *process_handle, handle_t *thread_handle)
 {
     dword_t ret;
     handle_t file = INVALID_HANDLE;
@@ -306,7 +306,7 @@ dword_t create_process(const char *path, dword_t flags, process_params_t *parame
         if (ret != ERR_SUCCESS) goto cleanup;
     }
 
-    clock_get_time(&proc->start_time);
+    syscall_clock_get_time(&proc->start_time);
 
     ret = create_object(&proc->header);
     if (ret != ERR_SUCCESS) goto cleanup;
@@ -386,8 +386,8 @@ cleanup:
         if (ret != ERR_SUCCESS)
         {
             syscall(SYSCALL_TERMINATE, proc->pid, 1);
-            if (safe_process_handle != INVALID_HANDLE) close_object(safe_process_handle);
-            if (safe_thread_handle != INVALID_HANDLE) close_object(safe_thread_handle);
+            if (safe_process_handle != INVALID_HANDLE) syscall_close_object(safe_process_handle);
+            if (safe_thread_handle != INVALID_HANDLE) syscall_close_object(safe_thread_handle);
         }
 
         dereference(&proc->header);
@@ -411,7 +411,7 @@ cleanup:
     return ret;
 }
 
-dword_t terminate(handle_t handle, dword_t exit_code)
+sysret_t syscall_terminate(handle_t handle, dword_t exit_code)
 {
     process_t *proc;
     thread_t *current_thread = get_current_thread();
@@ -428,7 +428,7 @@ dword_t terminate(handle_t handle, dword_t exit_code)
 
     proc->terminating = TRUE;
     proc->exit_code = exit_code;
-    clock_get_time(&proc->end_time);
+    syscall_clock_get_time(&proc->end_time);
 
     acquire_resource_shared(&proc->thread_list_res);
 
@@ -464,13 +464,13 @@ dword_t terminate(handle_t handle, dword_t exit_code)
     else return terminate_thread_internal(current_thread, exit_code);
 }
 
-dword_t get_process_id()
+sysret_t syscall_get_process_id()
 {
     process_t *proc = get_current_process();
     return proc->pid;
 }
 
-dword_t query_process(handle_t handle, process_info_t info_type, void *buffer, dword_t size)
+sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *buffer, dword_t size)
 {
     dword_t ret = ERR_SUCCESS;
     void *safe_buffer;
@@ -630,7 +630,7 @@ dword_t query_process(handle_t handle, process_info_t info_type, void *buffer, d
     return ret;
 }
 
-dword_t enum_processes(dword_t *pid_array, dword_t *count)
+sysret_t syscall_enum_processes(dword_t *pid_array, dword_t *count)
 {
     dword_t ret = ERR_SUCCESS;
     dword_t safe_count;
@@ -698,7 +698,7 @@ cleanup:
     return ret;
 }
 
-dword_t wait_process(handle_t handle, dword_t timeout)
+sysret_t syscall_wait_process(handle_t handle, dword_t timeout)
 {
     dword_t ret;
     process_t *proc;
@@ -757,7 +757,7 @@ void process_init(char *root_directory)
     kernel_process->terminating = FALSE;
     kernel_process->terminated = FALSE;
 
-    clock_get_time(&kernel_process->start_time);
+    syscall_clock_get_time(&kernel_process->start_time);
 
     list_init(&kernel_process->threads);
     kernel_process->thread_list_res = 0;

+ 5 - 5
kernel/src/start.c

@@ -69,7 +69,7 @@ dword_t system_idle_thread(void *param)
 
     while (TRUE)
     {
-        yield_quantum();
+        syscall_yield_quantum();
         halt();
     }
 }
@@ -206,7 +206,7 @@ void kernel_main(multiboot_header_t *mboot, dword_t stack)
     strcat(message, "...");
     printf("%-70s", message);
 
-    dword_t ret = mount(root_disk, root_disk, NULL, MOUNT_FLAG_READONLY);
+    dword_t ret = syscall_mount(root_disk, root_disk, NULL, MOUNT_FLAG_READONLY);
     if (ret != ERR_SUCCESS) KERNEL_CRASH("Cannot mount root disk");
 
     free(root_disk);
@@ -227,11 +227,11 @@ void kernel_main(multiboot_header_t *mboot, dword_t stack)
     parameters.standard_output = INVALID_HANDLE;
     parameters.standard_error = INVALID_HANDLE;
 
-    ret = create_process(manager_path, 0, &parameters, &manager_process, &main_thread);
+    ret = syscall_create_process(manager_path, 0, &parameters, &manager_process, &main_thread);
     if (ret != ERR_SUCCESS) KERNEL_CRASH("Cannot start system manager");
 
-    close_object(main_thread);
-    wait_process(manager_process, NO_TIMEOUT);
+    syscall_close_object(main_thread);
+    syscall_wait_process(manager_process, NO_TIMEOUT);
 
     KERNEL_CRASH("The system manager has stopped working");
     ASSERT(FALSE);

+ 8 - 8
kernel/src/sync.c

@@ -55,7 +55,7 @@ void acquire_lock(lock_t *lock)
 void release_lock(lock_t *lock)
 {
     __sync_lock_release(lock);
-    if (scheduler_enabled) yield_quantum();
+    if (scheduler_enabled) syscall_yield_quantum();
 }
 
 void acquire_resource_shared(resource_t *res)
@@ -91,7 +91,7 @@ void acquire_resource_exclusive(resource_t *res)
 void release_resource(resource_t *res)
 {
     __sync_lock_release(res);
-    if (scheduler_enabled) yield_quantum();
+    if (scheduler_enabled) syscall_yield_quantum();
 }
 
 void init_semaphore(semaphore_t *semaphore, dword_t init_count, dword_t max_count)
@@ -102,7 +102,7 @@ void init_semaphore(semaphore_t *semaphore, dword_t init_count, dword_t max_coun
     semaphore->max_count = max_count;
 }
 
-dword_t create_semaphore(const char *name, dword_t init_count, dword_t max_count, handle_t *handle)
+sysret_t syscall_create_semaphore(const char *name, dword_t init_count, dword_t max_count, handle_t *handle)
 {
     handle_t safe_handle;
     char *safe_name = NULL;
@@ -143,7 +143,7 @@ dword_t create_semaphore(const char *name, dword_t init_count, dword_t max_count
     return ret;
 }
 
-dword_t open_semaphore(const char *name, handle_t *handle)
+sysret_t syscall_open_semaphore(const char *name, handle_t *handle)
 {
     handle_t safe_handle;
     char *safe_name = NULL;
@@ -169,7 +169,7 @@ dword_t open_semaphore(const char *name, handle_t *handle)
     EH_TRY *handle = safe_handle;
     EH_CATCH
     {
-        close_object(safe_handle);
+        syscall_close_object(safe_handle);
         ret = ERR_BADPTR;
     }
     EH_DONE;
@@ -199,7 +199,7 @@ dword_t release_semaphore(semaphore_t *semaphore, dword_t count)
     if ((semaphore->count + count) <= semaphore->max_count)
     {
         semaphore->count += count;
-        if (scheduler_enabled) yield_quantum();
+        if (scheduler_enabled) syscall_yield_quantum();
         return ERR_SUCCESS;
     }
     else
@@ -208,7 +208,7 @@ dword_t release_semaphore(semaphore_t *semaphore, dword_t count)
     }
 }
 
-dword_t wait_semaphore_by_handle(handle_t semaphore, dword_t count, dword_t timeout)
+sysret_t syscall_wait_semaphore(handle_t semaphore, dword_t count, dword_t timeout)
 {
     semaphore_t *obj;
 
@@ -219,7 +219,7 @@ dword_t wait_semaphore_by_handle(handle_t semaphore, dword_t count, dword_t time
     return ret;
 }
 
-dword_t release_semaphore_by_handle(handle_t semaphore, dword_t count)
+sysret_t syscall_release_semaphore(handle_t semaphore, dword_t count)
 {
     semaphore_t *obj;
 

+ 72 - 65
kernel/src/syscalls.c

@@ -32,67 +32,74 @@ extern qword_t syscall_function(const void*, dword_t*, dword_t);
 
 const void *service_table[] =
 {
-    &alloc_memory,
-    &clock_get_time,
-    &clock_set_time,
-    &close_object,
-    &commit_memory,
-    &create_memory_section,
-    &create_process,
-    &create_semaphore,
-    &create_thread,
-    &create_user,
-    &delete_file,
-    &delete_user,
-    &device_ioctl,
-    &duplicate_handle,
-    &enum_processes,
-    &flush_memory_section,
-    &free_memory,
-    &get_exception_info,
-    &get_milliseconds,
-    &get_nanoseconds,
-    &get_process_id,
-    &get_thread_id,
-    &get_user_id,
-    &list_directory,
-    &logon_user,
-    &map_memory_section,
-    &mount,
-    &open_file,
-    &open_memory_section,
-    &open_pipe,
-    &open_process,
-    &open_thread,
-    &power_control,
-    &query_file,
-    &query_handle,
-    &query_process,
-    &query_thread,
-    &query_user,
-    &raise_exception,
-    &read_file,
-    &read_memory,
-    &read_pipe,
-    &release_semaphore_by_handle,
-    &restore_exception_handler,
-    &revert_user,
-    &save_exception_handler,
-    &set_memory_flags,
-    &set_user_id,
-    &sleep,
-    &terminate,
-    &terminate_thread,
-    &uncommit_memory,
-    &unmount,
-    &wait_directory_event,
-    &wait_process,
-    &wait_semaphore_by_handle,
-    &wait_thread,
-    &write_file,
-    &write_memory,
-    &write_pipe,
-    &yield_quantum,
+    &syscall_alloc_memory,
+    &syscall_clock_get_time,
+    &syscall_clock_set_time,
+    &syscall_close_object,
+    &syscall_commit_memory,
+    &syscall_create_memory_section,
+    &syscall_create_pipe,
+    &syscall_create_process,
+    &syscall_create_semaphore,
+    &syscall_create_thread,
+    &syscall_create_user,
+    &syscall_delete_file,
+    &syscall_delete_user,
+    &syscall_device_ioctl,
+    &syscall_duplicate_handle,
+    &syscall_enum_processes,
+    &syscall_flush_memory_section,
+    &syscall_free_memory,
+    &syscall_freeze_thread,
+    &syscall_get_exception_info,
+    &syscall_get_milliseconds,
+    &syscall_get_nanoseconds,
+    &syscall_get_process_id,
+    &syscall_get_thread_id,
+    &syscall_get_user_id,
+    &syscall_list_directory,
+    &syscall_logon_user,
+    &syscall_map_memory_section,
+    &syscall_mount,
+    &syscall_open_file,
+    &syscall_open_memory_section,
+    &syscall_open_pipe,
+    &syscall_open_process,
+    &syscall_open_semaphore,
+    &syscall_open_thread,
+    &syscall_power_control,
+    &syscall_query_file,
+    &syscall_query_handle,
+    &syscall_query_memory,
+    &syscall_query_process,
+    &syscall_query_thread,
+    &syscall_query_user,
+    &syscall_raise_exception,
+    &syscall_read_file,
+    &syscall_read_memory,
+    &syscall_read_pipe,
+    &syscall_release_semaphore,
+    &syscall_restore_exception_handler,
+    &syscall_revert_user,
+    &syscall_save_exception_handler,
+    &syscall_set_file,
+    &syscall_set_memory_flags,
+    &syscall_set_thread,
+    &syscall_set_user_id,
+    &syscall_sleep,
+    &syscall_terminate,
+    &syscall_terminate_thread,
+    &syscall_thaw_thread,
+    &syscall_uncommit_memory,
+    &syscall_unmount,
+    &syscall_wait_directory_event,
+    &syscall_wait_process,
+    &syscall_wait_semaphore,
+    &syscall_wait_thread,
+    &syscall_write_file,
+    &syscall_write_memory,
+    &syscall_write_pipe,
+    &syscall_yield_quantum,
 };
 
 static void system_service_handler(registers_t *regs, byte_t int_num)
@@ -133,15 +140,15 @@ static void system_service_handler(registers_t *regs, byte_t int_num)
         memcpy(parameters, (dword_t*)regs->edx, sizeof(parameters));
     }
 
-    qword_t result = syscall_function(service_table[regs->eax], parameters, sizeof(parameters));
+    sysret_t result = syscall_function(service_table[regs->eax], parameters, sizeof(parameters));
     regs->eax = (dword_t)result;
     regs->edx = (dword_t)(result >> 32);
 
 cleanup:
     thread->syscall_regs = NULL;
     release_lock(&thread->syscall_lock);
-    if (thread->cancel_io) while (TRUE) yield_quantum();
-    else if (thread->frozen) yield_quantum();
+    if (thread->cancel_io) while (TRUE) syscall_yield_quantum();
+    else if (thread->frozen) syscall_yield_quantum();
 }
 
 processor_mode_t get_previous_mode()
@@ -179,7 +186,7 @@ char *copy_user_string(const char *string)
     return result;
 }
 
-qword_t syscall(syscall_number_t num, ...)
+sysret_t syscall(syscall_number_t num, ...)
 {
     int i;
     qword_t ret = 0ULL;

+ 19 - 17
kernel/src/thread.c

@@ -103,7 +103,7 @@ static inline bool_t test_condition(wait_condition_t condition, dword_t *pointer
 
 static inline bool_t is_thread_ready(thread_t *thread)
 {
-    qword_t current_time = get_milliseconds();
+    qword_t current_time = syscall_get_milliseconds();
 
     if (thread->terminated) return FALSE;
     if (thread->frozen > 0 && !thread->syscall_lock) return FALSE;
@@ -248,7 +248,7 @@ thread_t *get_current_thread()
     return current_thread;
 }
 
-dword_t get_thread_id()
+sysret_t syscall_get_thread_id()
 {
     return current_thread->tid;
 }
@@ -351,7 +351,7 @@ wait_result_t scheduler_wait(wait_condition_t condition, dword_t timeout, uintpt
 
     if (timeout != NO_TIMEOUT)
     {
-        current_thread->wait_timestamp = get_milliseconds();
+        current_thread->wait_timestamp = syscall_get_milliseconds();
         current_thread->wait_timeout = timeout;
     }
     else
@@ -365,20 +365,22 @@ wait_result_t scheduler_wait(wait_condition_t condition, dword_t timeout, uintpt
     current_thread->wait_condition = condition;
 
     leave_critical(&critical);
-    yield_quantum();
+    syscall_yield_quantum();
 
     return current_thread->wait_result;
 }
 
-void sleep(qword_t milliseconds)
+sysret_t syscall_sleep(qword_t milliseconds)
 {
     scheduler_wait(WAIT_ALWAYS, milliseconds, NULL, 0);
+    return ERR_SUCCESS;
 }
 
-void yield_quantum()
+sysret_t syscall_yield_quantum()
 {
     current_thread->quantum = 0;
     reschedule();
+    return ERR_SUCCESS;
 }
 
 dword_t create_system_thread(thread_procedure_t routine, dword_t flags, priority_t priority, dword_t stack_size, void *param, thread_t **new_thread)
@@ -406,7 +408,7 @@ dword_t create_system_thread(thread_procedure_t routine, dword_t flags, priority
     return create_thread_internal(kernel_process, &initial_state, flags, priority, kernel_stack, new_thread);
 }
 
-dword_t create_thread(handle_t process, thread_state_t *initial_state, dword_t flags, priority_t priority, handle_t *new_thread)
+sysret_t syscall_create_thread(handle_t process, thread_state_t *initial_state, dword_t flags, priority_t priority, handle_t *new_thread)
 {
     dword_t ret;
     thread_state_t safe_state;
@@ -464,7 +466,7 @@ dword_t create_thread(handle_t process, thread_state_t *initial_state, dword_t f
     ret = open_object(&thread->header, 0, &thread_handle);
 
     EH_TRY *new_thread = thread_handle;
-    EH_CATCH close_object(thread_handle);
+    EH_CATCH syscall_close_object(thread_handle);
     EH_DONE;
 
 cleanup:
@@ -472,7 +474,7 @@ cleanup:
     return ret;
 }
 
-dword_t open_thread(dword_t tid, handle_t *handle)
+sysret_t syscall_open_thread(dword_t tid, handle_t *handle)
 {
     int i;
     thread_t *thread = NULL;
@@ -480,7 +482,7 @@ dword_t open_thread(dword_t tid, handle_t *handle)
     critical_t critical;
     enter_critical(&critical);
 
-    if (get_thread_id() == tid)
+    if (syscall_get_thread_id() == tid)
     {
         thread = current_thread;
     }
@@ -525,11 +527,11 @@ dword_t terminate_thread_internal(thread_t *thread, dword_t exit_code)
 
     leave_critical(&critical);
 
-    if (thread == current_thread) yield_quantum();
+    if (thread == current_thread) syscall_yield_quantum();
     return ERR_SUCCESS;
 }
 
-dword_t terminate_thread(handle_t handle, dword_t exit_code)
+sysret_t syscall_terminate_thread(handle_t handle, dword_t exit_code)
 {
     thread_t *thread;
 
@@ -546,7 +548,7 @@ dword_t terminate_thread(handle_t handle, dword_t exit_code)
     return terminate_thread_internal(thread, exit_code);
 }
 
-dword_t query_thread(handle_t handle, thread_info_t info_type, void *buffer, size_t size)
+sysret_t syscall_query_thread(handle_t handle, thread_info_t info_type, void *buffer, size_t size)
 {
     dword_t ret = ERR_SUCCESS;
     thread_t *thread;
@@ -633,7 +635,7 @@ dword_t query_thread(handle_t handle, thread_info_t info_type, void *buffer, siz
     return ret;
 }
 
-dword_t set_thread(handle_t handle, thread_info_t info_type, const void *buffer, size_t size)
+sysret_t syscall_set_thread(handle_t handle, thread_info_t info_type, const void *buffer, size_t size)
 {
     dword_t ret;
     thread_t *thread;
@@ -744,7 +746,7 @@ dword_t set_thread(handle_t handle, thread_info_t info_type, const void *buffer,
     return ret;
 }
 
-dword_t wait_thread(handle_t handle, dword_t timeout)
+sysret_t syscall_wait_thread(handle_t handle, dword_t timeout)
 {
     dword_t ret;
     thread_t *thread;
@@ -765,7 +767,7 @@ dword_t wait_thread(handle_t handle, dword_t timeout)
     return ret;
 }
 
-dword_t freeze_thread(handle_t handle)
+sysret_t syscall_freeze_thread(handle_t handle)
 {
     dword_t ret = ERR_SUCCESS;
     thread_t *thread;
@@ -786,7 +788,7 @@ dword_t freeze_thread(handle_t handle)
     return ret;
 }
 
-dword_t thaw_thread(handle_t handle)
+sysret_t syscall_thaw_thread(handle_t handle)
 {
     dword_t ret = ERR_SUCCESS;
     thread_t *thread;

+ 2 - 2
kernel/src/timer.c

@@ -33,12 +33,12 @@ void timer_irq(registers_t *regs, byte_t irq_num)
     }
 }
 
-qword_t get_milliseconds(void)
+sysret_t syscall_get_milliseconds(void)
 {
     return total_ticks;
 }
 
-qword_t get_nanoseconds(void)
+sysret_t syscall_get_nanoseconds(void)
 {
     critical_t critical;
     enter_critical(&critical);

+ 10 - 10
kernel/src/user.c

@@ -163,13 +163,13 @@ bool_t check_privileges(qword_t privilege_mask)
     return ((privileges & privilege_mask) == privilege_mask);
 }
 
-dword_t get_user_id()
+sysret_t syscall_get_user_id()
 {
     process_t *proc = get_current_process();
     return proc->current_user->uid;
 }
 
-dword_t set_user_id(dword_t uid)
+sysret_t syscall_set_user_id(dword_t uid)
 {
     process_t *proc = get_current_process();
     user_t *user = reference_user_by_id(uid);
@@ -187,7 +187,7 @@ dword_t set_user_id(dword_t uid)
     return ERR_SUCCESS;
 }
 
-dword_t revert_user()
+sysret_t syscall_revert_user()
 {
     process_t *proc = get_current_process();
 
@@ -204,7 +204,7 @@ dword_t revert_user()
     }
 }
 
-dword_t create_user(dword_t uid, const char *name, dword_t *password_hash, qword_t privileges)
+sysret_t syscall_create_user(dword_t uid, const char *name, dword_t *password_hash, qword_t privileges)
 {
     dword_t safe_password_hash[64];
 
@@ -228,7 +228,7 @@ dword_t create_user(dword_t uid, const char *name, dword_t *password_hash, qword
     return add_user(uid, name, password_hash, privileges);
 }
 
-dword_t delete_user(dword_t uid)
+sysret_t syscall_delete_user(dword_t uid)
 {
     if (get_previous_mode() == USER_MODE && !check_privileges(PRIVILEGE_MANAGE_USERS))
     {
@@ -261,7 +261,7 @@ dword_t delete_user(dword_t uid)
     return ERR_SUCCESS;
 }
 
-dword_t logon_user(dword_t uid, const char *password)
+sysret_t syscall_logon_user(dword_t uid, const char *password)
 {
     dword_t ret;
     process_t *proc = get_current_process();
@@ -270,7 +270,7 @@ dword_t logon_user(dword_t uid, const char *password)
     char *safe_password;
 
     if (user == NULL) return ERR_NOTFOUND;
-    if ((get_milliseconds() - current_user->last_login_attempt) < LOGIN_ATTEMPT_TIMEOUT) return ERR_BUSY;
+    if ((syscall_get_milliseconds() - current_user->last_login_attempt) < LOGIN_ATTEMPT_TIMEOUT) return ERR_BUSY;
 
     if (get_previous_mode() == USER_MODE)
     {
@@ -283,7 +283,7 @@ dword_t logon_user(dword_t uid, const char *password)
 
     if (uid == 0)
     {
-        current_user->last_login_attempt = get_milliseconds();
+        current_user->last_login_attempt = syscall_get_milliseconds();
         ret = ERR_INVALID;
         goto cleanup;
     }
@@ -306,7 +306,7 @@ dword_t logon_user(dword_t uid, const char *password)
     }
     else
     {
-        user->last_login_attempt = get_milliseconds();
+        user->last_login_attempt = syscall_get_milliseconds();
         ret = ERR_INVALID;
     }
 
@@ -316,7 +316,7 @@ cleanup:
     return ret;
 }
 
-dword_t query_user(dword_t uid, user_info_t info_type, void *buffer, dword_t size)
+sysret_t syscall_query_user(dword_t uid, user_info_t info_type, void *buffer, dword_t size)
 {
     dword_t ret = ERR_SUCCESS;
     void *safe_buffer;

+ 3 - 3
kernel/src/video.c

@@ -385,11 +385,11 @@ void video_init()
 
     ASSERT(get_previous_mode() == KERNEL_MODE);
 
-    ret = open_file("CharDevices/Video0", &handle, 0, 0);
+    ret = syscall_open_file("CharDevices/Video0", &handle, 0, 0);
     ASSERT(ret == ERR_SUCCESS);
 
-    ret = device_ioctl(handle, IOCTL_VIDEO_MAP_FRAMEBUFFER, &params, sizeof(params), &address, sizeof(address));
+    ret = syscall_device_ioctl(handle, IOCTL_VIDEO_MAP_FRAMEBUFFER, &params, sizeof(params), &address, sizeof(address));
     ASSERT(ret == ERR_SUCCESS);
 
-    close_object(handle);
+    syscall_close_object(handle);
 }

+ 1 - 1
library/Makefile

@@ -31,7 +31,7 @@ OBJDIR = obj
 DEPDIR = dep
 
 # Flags
-CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fPIC
+CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fPIC -I ..
 ASMFLAGS = -felf
 LDFLAGS = -shared
 

+ 361 - 0
library/src/wrappers.c

@@ -0,0 +1,361 @@
+/*
+ * wrappers.c
+ *
+ * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sdk/monolithium.h>
+
+sysret_t syscall_alloc_memory(handle_t process, void **address, size_t size, dword_t block_flags)
+{
+    return syscall(SYSCALL_ALLOC_MEMORY, process, address, size, block_flags);
+}
+
+sysret_t syscall_clock_get_time(clock_time_t *time)
+{
+    return syscall(SYSCALL_CLOCK_GET_TIME, time);
+}
+
+sysret_t syscall_clock_set_time(clock_time_t *time)
+{
+    return syscall(SYSCALL_CLOCK_SET_TIME, time);
+}
+
+sysret_t syscall_close_object(handle_t handle)
+{
+    return syscall(SYSCALL_CLOSE_OBJECT, handle);
+}
+
+sysret_t syscall_commit_memory(handle_t process, void *address, dword_t size)
+{
+    return syscall(SYSCALL_COMMIT_MEMORY, process, address, size);
+}
+
+sysret_t syscall_create_memory_section(const char *name, handle_t file, size_t size, dword_t flags, handle_t *handle)
+{
+    return syscall(SYSCALL_CREATE_MEMORY_SECTION, name, file, size, flags, handle);
+}
+
+sysret_t syscall_create_pipe(const char *name, handle_t *handle)
+{
+    return syscall(SYSCALL_CREATE_PIPE, name, handle);
+}
+
+sysret_t syscall_create_process(const char *path, dword_t flags, process_params_t *parameters, handle_t *process_handle, handle_t *thread_handle)
+{
+    return syscall(SYSCALL_CREATE_PROCESS, path, flags, parameters, process_handle, thread_handle);
+}
+
+sysret_t syscall_create_semaphore(const char *name, dword_t init_count, dword_t max_count, handle_t *handle)
+{
+    return syscall(SYSCALL_CREATE_SEMAPHORE, name, init_count, max_count, handle);
+}
+
+sysret_t syscall_create_thread(handle_t process, thread_state_t *initial_state, dword_t flags, priority_t priority, handle_t *new_thread)
+{
+    return syscall(SYSCALL_CREATE_THREAD, process, initial_state, flags, priority, new_thread);
+}
+
+sysret_t syscall_create_user(dword_t uid, const char *name, dword_t *password_hash, qword_t privileges)
+{
+    return syscall(SYSCALL_CREATE_USER, uid, name, password_hash, privileges);
+}
+
+sysret_t syscall_delete_file(const char *path)
+{
+    return syscall(SYSCALL_DELETE_FILE, path);
+}
+
+sysret_t syscall_delete_user(dword_t uid)
+{
+    return syscall(SYSCALL_DELETE_USER, uid);
+}
+
+sysret_t syscall_device_ioctl(handle_t device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
+{
+    return syscall(SYSCALL_DEVICE_IOCTL, device, control_code, in_buffer, in_length, out_buffer, out_length);
+}
+
+sysret_t syscall_duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate)
+{
+    return syscall(SYSCALL_DUPLICATE_HANDLE, source_process, handle, dest_process, duplicate);
+}
+
+sysret_t syscall_enum_processes(dword_t *pid_array, dword_t *count)
+{
+    return syscall(SYSCALL_ENUM_PROCESSES, pid_array, count);
+}
+
+sysret_t syscall_flush_memory_section(handle_t process, void *address)
+{
+    return syscall(SYSCALL_FLUSH_MEMORY_SECTION, process, address);
+}
+
+sysret_t syscall_free_memory(handle_t process, void *address)
+{
+    return syscall(SYSCALL_FREE_MEMORY, process, address);
+}
+
+sysret_t syscall_freeze_thread(handle_t handle)
+{
+    return syscall(SYSCALL_FREEZE_THREAD, handle);
+}
+
+sysret_t syscall_get_exception_info(exception_info_t *info)
+{
+    return syscall(SYSCALL_GET_EXCEPTION_INFO, info);
+}
+
+sysret_t syscall_get_milliseconds(void)
+{
+    return syscall(SYSCALL_GET_MILLISECONDS);
+}
+
+sysret_t syscall_get_nanoseconds(void)
+{
+    return syscall(SYSCALL_GET_NANOSECONDS);
+}
+
+sysret_t syscall_get_process_id(void)
+{
+    return syscall(SYSCALL_GET_PROCESS_ID);
+}
+
+sysret_t syscall_get_thread_id(void)
+{
+    return syscall(SYSCALL_GET_THREAD_ID);
+}
+
+sysret_t syscall_get_user_id(void)
+{
+    return syscall(SYSCALL_GET_USER_ID);
+}
+
+sysret_t syscall_list_directory(handle_t handle, char *filename, bool_t continue_scan)
+{
+    return syscall(SYSCALL_LIST_DIRECTORY, handle, filename, continue_scan);
+}
+
+sysret_t syscall_logon_user(dword_t uid, const char *password)
+{
+    return syscall(SYSCALL_LOGON_USER, uid, password);
+}
+
+sysret_t syscall_map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags)
+{
+    return syscall(SYSCALL_MAP_MEMORY_SECTION, process, section, address, offset, size, flags);
+}
+
+sysret_t syscall_mount(const char *device, const char *mountpoint, const char *filesystem, dword_t flags)
+{
+    return syscall(SYSCALL_MOUNT, device, mountpoint, filesystem, flags);
+}
+
+sysret_t syscall_open_file(const char *path, handle_t *handle, dword_t mode, dword_t attributes)
+{
+    return syscall(SYSCALL_OPEN_FILE, path, handle, mode, attributes);
+}
+
+sysret_t syscall_open_memory_section(const char *name, handle_t *handle)
+{
+    return syscall(SYSCALL_OPEN_MEMORY_SECTION, name, handle);
+}
+
+sysret_t syscall_open_pipe(const char *name, handle_t *handle)
+{
+    return syscall(SYSCALL_OPEN_PIPE, name, handle);
+}
+
+sysret_t syscall_open_process(dword_t pid, handle_t *handle)
+{
+    return syscall(SYSCALL_OPEN_PROCESS, pid, handle);
+}
+
+sysret_t syscall_open_semaphore(const char *name, handle_t *handle)
+{
+    return syscall(SYSCALL_OPEN_SEMAPHORE, name, handle);
+}
+
+sysret_t syscall_open_thread(dword_t tid, handle_t *handle)
+{
+    return syscall(SYSCALL_OPEN_THREAD, tid, handle);
+}
+
+sysret_t syscall_power_control(power_command_t command)
+{
+    return syscall(SYSCALL_POWER_CONTROL, command);
+}
+
+sysret_t syscall_query_file(handle_t handle, file_info_type_t info_type, void *buffer, size_t size)
+{
+    return syscall(SYSCALL_QUERY_FILE, handle, info_type, buffer, size);
+}
+
+sysret_t syscall_query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size)
+{
+    return syscall(SYSCALL_QUERY_HANDLE, handle, type, buffer, size);
+}
+
+sysret_t syscall_query_memory(handle_t process, void *address, memory_block_info_t *info)
+{
+    return syscall(SYSCALL_QUERY_MEMORY, process, address, info);
+}
+
+sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *buffer, dword_t size)
+{
+    return syscall(SYSCALL_QUERY_PROCESS, handle, info_type, buffer, size);
+}
+
+sysret_t syscall_query_thread(handle_t handle, thread_info_t info_type, void *buffer, size_t size)
+{
+    return syscall(SYSCALL_QUERY_THREAD, handle, info_type, buffer, size);
+}
+
+sysret_t syscall_query_user(dword_t uid, user_info_t info_type, void *buffer, dword_t size)
+{
+    return syscall(SYSCALL_QUERY_USER, uid, info_type, buffer, size);
+}
+
+sysret_t syscall_raise_exception(exception_info_t *info)
+{
+    return syscall(SYSCALL_RAISE_EXCEPTION, info);
+}
+
+sysret_t syscall_read_file(handle_t handle, void *buffer, qword_t offset, size_t size, size_t *bytes_read)
+{
+    return syscall(SYSCALL_READ_FILE, handle, buffer, offset, size, bytes_read);
+}
+
+sysret_t syscall_read_memory(handle_t process, void *address, void *buffer, dword_t size)
+{
+    return syscall(SYSCALL_READ_MEMORY, process, address, buffer, size);
+}
+
+sysret_t syscall_read_pipe(handle_t handle, void *buffer, dword_t size, dword_t timeout)
+{
+    return syscall(SYSCALL_READ_PIPE, handle, buffer, size, timeout);
+}
+
+sysret_t syscall_release_semaphore(handle_t semaphore, dword_t count)
+{
+    return syscall(SYSCALL_RELEASE_SEMAPHORE, semaphore, count);
+}
+
+sysret_t syscall_restore_exception_handler(exception_handler_t *old_handler)
+{
+    return syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, old_handler);
+}
+
+sysret_t syscall_revert_user(void)
+{
+    return syscall(SYSCALL_REVERT_USER);
+}
+
+sysret_t syscall_save_exception_handler(exception_handler_t *old_handler)
+{
+    return syscall(SYSCALL_SAVE_EXCEPTION_HANDLER, old_handler);
+}
+
+sysret_t syscall_set_file(handle_t handle, file_info_type_t set_type, void *buffer, size_t size)
+{
+    return syscall(SYSCALL_SET_FILE, handle, set_type, buffer, size);
+}
+
+sysret_t syscall_set_memory_flags(handle_t process, void *address, dword_t flags)
+{
+    return syscall(SYSCALL_SET_MEMORY_FLAGS, process, address, flags);
+}
+
+sysret_t syscall_set_thread(handle_t handle, thread_info_t info_type, const void *buffer, size_t size)
+{
+    return syscall(SYSCALL_SET_THREAD, handle, info_type, buffer, size);
+}
+
+sysret_t syscall_set_user_id(dword_t uid)
+{
+    return syscall(SYSCALL_SET_USER_ID, uid);
+}
+
+sysret_t syscall_sleep(qword_t milliseconds)
+{
+    return syscall(SYSCALL_SLEEP, milliseconds);
+}
+
+sysret_t syscall_terminate(handle_t handle, dword_t exit_code)
+{
+    return syscall(SYSCALL_TERMINATE, handle, exit_code);
+}
+
+sysret_t syscall_terminate_thread(handle_t thread, dword_t return_value)
+{
+    return syscall(SYSCALL_TERMINATE_THREAD, thread, return_value);
+}
+
+sysret_t syscall_thaw_thread(handle_t handle)
+{
+    return syscall(SYSCALL_THAW_THREAD, handle);
+}
+
+sysret_t syscall_uncommit_memory(handle_t process, void *address, dword_t size)
+{
+    return syscall(SYSCALL_UNCOMMIT_MEMORY, process, address, size);
+}
+
+sysret_t syscall_unmount(const char *device)
+{
+    return syscall(SYSCALL_UNMOUNT, device);
+}
+
+sysret_t syscall_wait_directory_event(handle_t handle, dword_t event_mask, file_event_t *buffer, size_t size, dword_t timeout)
+{
+    return syscall(SYSCALL_WAIT_DIRECTORY_EVENT, handle, event_mask, buffer, size, timeout);
+}
+
+sysret_t syscall_wait_process(handle_t handle, dword_t timeout)
+{
+    return syscall(SYSCALL_WAIT_PROCESS, handle, timeout);
+}
+
+sysret_t syscall_wait_semaphore(handle_t semaphore, dword_t count, dword_t timeout)
+{
+    return syscall(SYSCALL_WAIT_SEMAPHORE, semaphore, count, timeout);
+}
+
+sysret_t syscall_wait_thread(handle_t handle, dword_t timeout)
+{
+    return syscall(SYSCALL_WAIT_THREAD, handle, timeout);
+}
+
+sysret_t syscall_write_file(handle_t handle, const void *buffer, qword_t offset, size_t size, size_t *bytes_written)
+{
+    return syscall(SYSCALL_WRITE_FILE, handle, buffer, offset, size, bytes_written);
+}
+
+sysret_t syscall_write_memory(handle_t process, void *address, void *buffer, dword_t size)
+{
+    return syscall(SYSCALL_WRITE_MEMORY, process, address, buffer, size);
+}
+
+sysret_t syscall_write_pipe(handle_t handle, void *buffer, dword_t size)
+{
+    return syscall(SYSCALL_WRITE_PIPE, handle, buffer, size);
+}
+
+sysret_t syscall_yield_quantum(void)
+{
+    return syscall(SYSCALL_YIELD_QUANTUM);
+}
+

+ 47 - 0
sdk/cpu.h

@@ -0,0 +1,47 @@
+/*
+ * cpu.h
+ *
+ * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MONOLITHIUM_CPU_H__
+#define __MONOLITHIUM_CPU_H__
+
+typedef struct
+{
+    dword_t data_selector;
+    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
+    dword_t error_code;
+    dword_t eip, cs, eflags;
+} registers_t;
+
+typedef struct
+{
+    dword_t data_selector;
+    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
+    dword_t error_code;
+    dword_t eip, cs, eflags, esp3, ss;
+} registers_ext_t;
+
+typedef struct
+{
+    dword_t data_selector;
+    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
+    dword_t error_code;
+    dword_t eip, cs, eflags, esp3, ss, es, ds, fs, gs;
+} registers_ext_vm86_t;
+
+#endif

+ 3 - 0
sdk/defs.h

@@ -73,4 +73,7 @@ typedef uint16_t word_t;
 typedef uint32_t dword_t;
 typedef uint64_t qword_t;
 
+/* System call return value */
+typedef qword_t sysret_t;
+
 #endif

+ 4 - 0
sdk/device.h

@@ -20,6 +20,8 @@
 #ifndef __MONOLITHIUM_DEVICE_H__
 #define __MONOLITHIUM_DEVICE_H__
 
+#include "object.h"
+
 #define MAX_DEVICE_NAME 32
 
 #define BLOCK_DEVICE_REMOVABLE_MEDIA  (1 << 0)
@@ -38,4 +40,6 @@ typedef enum
     CHAR_DEVICE
 } device_type_t;
 
+sysret_t syscall_device_ioctl(handle_t device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
+
 #endif

+ 71 - 0
sdk/exception.h

@@ -0,0 +1,71 @@
+/*
+ * exception.h
+ *
+ * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MONOLITHIUM_EXCEPTION_H__
+#define __MONOLITHIUM_EXCEPTION_H__
+
+#include "defs.h"
+#include "cpu.h"
+
+#ifdef __MONOLITIHUM_KERNEL_MODE__
+#define EH_TRY if (get_current_thread() != NULL) { exception_handler_t ___handler; if (save_kernel_handler(&___handler) == 0)
+#else
+#define EH_TRY if (TRUE) { exception_handler_t ___handler; if (syscall(SYSCALL_SAVE_EXCEPTION_HANDLER, &__handler) == 0)
+#endif
+
+#define EH_CATCH else
+#define EH_DONE syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); }
+#define EH_ESCAPE(x) do { syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); x; } while (FALSE)
+
+typedef registers_t exception_handler_t;
+
+typedef enum
+{
+    EXCEPTION_DIVISION_BY_ZERO,
+    EXCEPTION_DEBUG_INT,
+    EXCEPTION_NMI,
+    EXCEPTION_BREAKPOINT,
+    EXCEPTION_OVERFLOW,
+    EXCEPTION_BOUND_RANGE,
+    EXCEPTION_INVALID_OPCODE,
+    EXCEPTION_NO_FPU,
+    EXCEPTION_DOUBLE_FAULT,
+    EXCEPTION_FPU_SEGMENT,
+    EXCEPTION_BAD_TSS,
+    EXCEPTION_NO_SEGMENT,
+    EXCEPTION_STACK_OVERFLOW,
+    EXCEPTION_GPF,
+    EXCEPTION_PAGE_FAULT,
+    EXCEPTION_ALIGNMENT,
+    EXCEPTION_HARDWARE,
+    NUM_EXCEPTIONS
+} exception_t;
+
+typedef struct
+{
+    exception_t number;
+    dword_t parameters[15];
+} exception_info_t;
+
+sysret_t syscall_get_exception_info(exception_info_t *info);
+sysret_t syscall_raise_exception(exception_info_t *info);
+sysret_t syscall_save_exception_handler(exception_handler_t *old_handler);
+sysret_t syscall_restore_exception_handler(exception_handler_t *old_handler);
+
+#endif

+ 12 - 0
sdk/filesystem.h

@@ -22,6 +22,7 @@
 
 #include "defs.h"
 #include "clock.h"
+#include "object.h"
 
 #define PATH_DELIMITER_STRING "/"
 #define PATH_DELIMITER_CHAR   (*PATH_DELIMITER_STRING)
@@ -66,4 +67,15 @@ typedef struct
     char filename[VARIABLE_SIZE];
 } file_event_t;
 
+sysret_t syscall_open_file(const char *path, handle_t *handle, dword_t mode, dword_t attributes);
+sysret_t syscall_delete_file(const char *path);
+sysret_t syscall_query_file(handle_t handle, file_info_type_t info_type, void *buffer, size_t size);
+sysret_t syscall_set_file(handle_t handle, file_info_type_t set_type, void *buffer, size_t size);
+sysret_t syscall_list_directory(handle_t handle, char *filename, bool_t continue_scan);
+sysret_t syscall_read_file(handle_t handle, void *buffer, qword_t offset, size_t size, size_t *bytes_read);
+sysret_t syscall_write_file(handle_t handle, const void *buffer, qword_t offset, size_t size, size_t *bytes_written);
+sysret_t syscall_mount(const char *device, const char *mountpoint, const char *filesystem, dword_t flags);
+sysret_t syscall_unmount(const char *device);
+sysret_t syscall_wait_directory_event(handle_t handle, dword_t event_mask, file_event_t *buffer, size_t size, dword_t timeout);
+
 #endif

+ 64 - 0
sdk/memory.h

@@ -0,0 +1,64 @@
+/*
+ * memory.h
+ *
+ * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MONOLITIHUM_MEMORY_H__
+#define __MONOLITIHUM_MEMORY_H__
+
+#include "defs.h"
+
+#define MEMORY_BLOCK_ACCESSIBLE    (1 << 0)
+#define MEMORY_BLOCK_WRITABLE      (1 << 1)
+#define MEMORY_BLOCK_EXECUTABLE    (1 << 2)
+#define MEMORY_BLOCK_USERMODE      (1 << 3)
+#define MEMORY_BLOCK_EVICTABLE     (1 << 29)
+#define MEMORY_BLOCK_COPY_ON_WRITE (1 << 30)
+#define MEMORY_BLOCK_FREE          (1 << 31)
+
+#define MEMORY_SECTION_WRITABLE     (1 << 0)
+#define MEMORY_SECTION_DIRECT_WRITE (1 << 1)
+
+typedef struct
+{
+    uintptr_t used_virtual;
+    uintptr_t committed;
+    uintptr_t evicted;
+    uintptr_t shared;
+} memory_stats_t;
+
+typedef struct
+{
+    qword_t address;
+    qword_t size;
+    dword_t flags;
+} memory_block_info_t;
+
+sysret_t syscall_alloc_memory(handle_t process, void **address, size_t size, dword_t block_flags);
+sysret_t syscall_free_memory(handle_t process, void *address);
+sysret_t syscall_commit_memory(handle_t process, void *address, dword_t size);
+sysret_t syscall_uncommit_memory(handle_t process, void *address, dword_t size);
+sysret_t syscall_set_memory_flags(handle_t process, void *address, dword_t flags);
+sysret_t syscall_query_memory(handle_t process, void *address, memory_block_info_t *info);
+sysret_t syscall_read_memory(handle_t process, void *address, void *buffer, dword_t size);
+sysret_t syscall_write_memory(handle_t process, void *address, void *buffer, dword_t size);
+sysret_t syscall_create_memory_section(const char *name, handle_t file, size_t size, dword_t flags, handle_t *handle);
+sysret_t syscall_open_memory_section(const char *name, handle_t *handle);
+sysret_t syscall_map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags);
+sysret_t syscall_flush_memory_section(handle_t process, void *address);
+
+#endif

+ 5 - 0
sdk/monolithium.h

@@ -20,8 +20,13 @@
 #include "clock.h"
 #include "defs.h"
 #include "device.h"
+#include "exception.h"
 #include "filesystem.h"
 #include "list.h"
+#include "memory.h"
 #include "object.h"
+#include "power.h"
 #include "process.h"
 #include "syscalls.h"
+#include "thread.h"
+#include "user.h"

+ 4 - 0
sdk/object.h

@@ -53,4 +53,8 @@ typedef enum
     ACCESS_DEFAULT_DENY,
 } access_control_policy_t;
 
+sysret_t syscall_close_object(handle_t handle);
+sysret_t syscall_query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size);
+sysret_t syscall_duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate);
+
 #endif

+ 34 - 0
sdk/power.h

@@ -0,0 +1,34 @@
+/*
+ * power.h
+ *
+ * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MONOLITHIUM_POWER_H__
+#define __MONOLITHIUM_POWER_H__
+
+#include "defs.h"
+
+typedef enum
+{
+    POWER_COMMAND_HALT,
+    POWER_COMMAND_REBOOT,
+    POWER_COMMAND_SHUTDOWN
+} power_command_t;
+
+sysret_t syscall_power_control(power_command_t command);
+
+#endif

+ 8 - 1
sdk/syscalls.h

@@ -33,6 +33,7 @@ typedef enum
     SYSCALL_CLOSE_OBJECT,
     SYSCALL_COMMIT_MEMORY,
     SYSCALL_CREATE_MEMORY_SECTION,
+    SYSCALL_CREATE_PIPE,
     SYSCALL_CREATE_PROCESS,
     SYSCALL_CREATE_SEMAPHORE,
     SYSCALL_CREATE_THREAD,
@@ -44,6 +45,7 @@ typedef enum
     SYSCALL_ENUM_PROCESSES,
     SYSCALL_FLUSH_MEMORY_SECTION,
     SYSCALL_FREE_MEMORY,
+    SYSCALL_FREEZE_THREAD,
     SYSCALL_GET_EXCEPTION_INFO,
     SYSCALL_GET_MILLISECONDS,
     SYSCALL_GET_NANOSECONDS,
@@ -58,10 +60,12 @@ typedef enum
     SYSCALL_OPEN_MEMORY_SECTION,
     SYSCALL_OPEN_PIPE,
     SYSCALL_OPEN_PROCESS,
+    SYSCALL_OPEN_SEMAPHORE,
     SYSCALL_OPEN_THREAD,
     SYSCALL_POWER_CONTROL,
     SYSCALL_QUERY_FILE,
     SYSCALL_QUERY_HANDLE,
+    SYSCALL_QUERY_MEMORY,
     SYSCALL_QUERY_PROCESS,
     SYSCALL_QUERY_THREAD,
     SYSCALL_QUERY_USER,
@@ -73,11 +77,14 @@ typedef enum
     SYSCALL_RESTORE_EXCEPTION_HANDLER,
     SYSCALL_REVERT_USER,
     SYSCALL_SAVE_EXCEPTION_HANDLER,
+    SYSCALL_SET_FILE,
     SYSCALL_SET_MEMORY_FLAGS,
+    SYSCALL_SET_THREAD,
     SYSCALL_SET_USER_ID,
     SYSCALL_SLEEP,
     SYSCALL_TERMINATE,
     SYSCALL_TERMINATE_THREAD,
+    SYSCALL_THAW_THREAD,
     SYSCALL_UNCOMMIT_MEMORY,
     SYSCALL_UNMOUNT,
     SYSCALL_WAIT_DIRECTORY_EVENT,
@@ -92,6 +99,6 @@ typedef enum
     SERVICE_COUNT
 } syscall_number_t;
 
-qword_t syscall(syscall_number_t num, ...);
+sysret_t syscall(syscall_number_t num, ...);
 
 #endif

+ 66 - 0
sdk/thread.h

@@ -0,0 +1,66 @@
+/*
+ * thread.h
+ *
+ * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MONOLITHIUM_THREAD_H__
+#define __MONOLITHIUM_THREAD_H__
+
+#define THREAD_CREATE_FROZEN (1 << 0)
+
+#include "defs.h"
+
+typedef qword_t affinity_t;
+
+typedef enum
+{
+    THREAD_TID_INFO,
+    THREAD_FROZEN_INFO,
+    THREAD_CPU_STATE_INFO,
+    THREAD_PRIORITY_INFO,
+    THREAD_AFFINITY_INFO,
+} thread_info_t;
+
+typedef enum
+{
+    THREAD_PRIORITY_HIGH,
+    THREAD_PRIORITY_MID,
+    THREAD_PRIORITY_LOW,
+    THREAD_PRIORITY_IDLE,
+
+    THREAD_PRIORITY_MAX
+} priority_t;
+
+typedef struct
+{
+    registers_t regs;
+    byte_t fpu_state[512];
+} thread_state_t;
+
+sysret_t syscall_get_thread_id(void);
+sysret_t syscall_open_thread(dword_t tid, handle_t *handle);
+sysret_t syscall_create_thread(handle_t process, thread_state_t *initial_state, dword_t flags, priority_t priority, handle_t *new_thread);
+sysret_t syscall_terminate_thread(handle_t thread, dword_t return_value);
+sysret_t syscall_freeze_thread(handle_t handle);
+sysret_t syscall_thaw_thread(handle_t handle);
+sysret_t syscall_sleep(qword_t milliseconds);
+sysret_t syscall_yield_quantum(void);
+sysret_t syscall_query_thread(handle_t handle, thread_info_t info_type, void *buffer, size_t size);
+sysret_t syscall_set_thread(handle_t handle, thread_info_t info_type, const void *buffer, size_t size);
+sysret_t syscall_wait_thread(handle_t handle, dword_t timeout);
+
+#endif

+ 108 - 0
sdk/user.h

@@ -0,0 +1,108 @@
+/*
+ * user.h
+ *
+ * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MONOLITHIUM_USER_H__
+#define __MONOLITHIUM_USER_H__
+
+#include "defs.h"
+
+#define MAX_USERNAME_LENGTH 32
+
+#define PRIVILEGE_LOGON_USER       (1ULL << 0)
+#define PRIVILEGE_NETWORK_ACCESS   (1ULL << 1)
+#define PRIVILEGE_MOUNT_UNMOUNT    (1ULL << 2)
+#define PRIVILEGE_UNNAMED3         (1ULL << 3)
+#define PRIVILEGE_UNNAMED4         (1ULL << 4)
+#define PRIVILEGE_UNNAMED5         (1ULL << 5)
+#define PRIVILEGE_UNNAMED6         (1ULL << 6)
+#define PRIVILEGE_UNNAMED7         (1ULL << 7)
+#define PRIVILEGE_UNNAMED8         (1ULL << 8)
+#define PRIVILEGE_UNNAMED9         (1ULL << 9)
+#define PRIVILEGE_UNNAMED10        (1ULL << 10)
+#define PRIVILEGE_UNNAMED11        (1ULL << 11)
+#define PRIVILEGE_UNNAMED12        (1ULL << 12)
+#define PRIVILEGE_UNNAMED13        (1ULL << 13)
+#define PRIVILEGE_UNNAMED14        (1ULL << 14)
+#define PRIVILEGE_UNNAMED15        (1ULL << 15)
+#define PRIVILEGE_UNNAMED16        (1ULL << 16)
+#define PRIVILEGE_UNNAMED17        (1ULL << 17)
+#define PRIVILEGE_UNNAMED18        (1ULL << 18)
+#define PRIVILEGE_UNNAMED19        (1ULL << 19)
+#define PRIVILEGE_UNNAMED20        (1ULL << 20)
+#define PRIVILEGE_UNNAMED21        (1ULL << 21)
+#define PRIVILEGE_UNNAMED22        (1ULL << 22)
+#define PRIVILEGE_UNNAMED23        (1ULL << 23)
+#define PRIVILEGE_UNNAMED24        (1ULL << 24)
+#define PRIVILEGE_UNNAMED25        (1ULL << 25)
+#define PRIVILEGE_UNNAMED26        (1ULL << 26)
+#define PRIVILEGE_UNNAMED27        (1ULL << 27)
+#define PRIVILEGE_UNNAMED28        (1ULL << 28)
+#define PRIVILEGE_UNNAMED29        (1ULL << 29)
+#define PRIVILEGE_UNNAMED30        (1ULL << 30)
+#define PRIVILEGE_SET_TIME         (1ULL << 31)
+#define PRIVILEGE_ACCESS_ALL       (1ULL << 32)
+#define PRIVILEGE_CHARACTER_DEVICE (1ULL << 33)
+#define PRIVILEGE_BLOCK_DEVICE     (1ULL << 34)
+#define PRIVILEGE_UNNAMED35        (1ULL << 35)
+#define PRIVILEGE_UNNAMED36        (1ULL << 36)
+#define PRIVILEGE_UNNAMED37        (1ULL << 37)
+#define PRIVILEGE_UNNAMED38        (1ULL << 38)
+#define PRIVILEGE_UNNAMED39        (1ULL << 39)
+#define PRIVILEGE_UNNAMED40        (1ULL << 40)
+#define PRIVILEGE_UNNAMED41        (1ULL << 41)
+#define PRIVILEGE_UNNAMED42        (1ULL << 42)
+#define PRIVILEGE_UNNAMED43        (1ULL << 43)
+#define PRIVILEGE_UNNAMED44        (1ULL << 44)
+#define PRIVILEGE_UNNAMED45        (1ULL << 45)
+#define PRIVILEGE_UNNAMED46        (1ULL << 46)
+#define PRIVILEGE_UNNAMED47        (1ULL << 47)
+#define PRIVILEGE_UNNAMED48        (1ULL << 48)
+#define PRIVILEGE_UNNAMED49        (1ULL << 49)
+#define PRIVILEGE_UNNAMED50        (1ULL << 50)
+#define PRIVILEGE_UNNAMED51        (1ULL << 51)
+#define PRIVILEGE_UNNAMED52        (1ULL << 52)
+#define PRIVILEGE_UNNAMED53        (1ULL << 53)
+#define PRIVILEGE_UNNAMED54        (1ULL << 54)
+#define PRIVILEGE_UNNAMED55        (1ULL << 55)
+#define PRIVILEGE_UNNAMED56        (1ULL << 56)
+#define PRIVILEGE_UNNAMED57        (1ULL << 57)
+#define PRIVILEGE_UNNAMED58        (1ULL << 58)
+#define PRIVILEGE_MANAGE_USERS     (1ULL << 59)
+#define PRIVILEGE_PROCESS_CONTROL  (1ULL << 60)
+#define PRIVILEGE_SET_PAGE_FILE    (1ULL << 61)
+#define PRIVILEGE_POWER_CONTROL    (1ULL << 62)
+#define PRIVILEGE_CHANGE_UID       (1ULL << 63)
+
+#define ALL_PRIVILEGES 0xFFFFFFFFFFFFFFFFULL
+
+typedef enum
+{
+    USER_NAME_INFO,
+    USER_PRIVILEGE_INFO,
+} user_info_t;
+
+sysret_t syscall_create_user(dword_t uid, const char *name, dword_t *password_hash, qword_t privileges);
+sysret_t syscall_delete_user(dword_t uid);
+sysret_t syscall_get_user_id(void);
+sysret_t syscall_set_user_id(dword_t uid);
+sysret_t syscall_revert_user(void);
+sysret_t syscall_logon_user(dword_t uid, const char *password);
+sysret_t syscall_query_user(dword_t uid, user_info_t, void *buffer, dword_t size);
+
+#endif