feature (libnx): implemented syscall functions

This commit is contained in:
antifallobst 2023-05-29 18:17:23 +02:00
parent 5dfffaa811
commit 60445162a5
2 changed files with 132 additions and 37 deletions

View File

@ -6,25 +6,29 @@
#include "public/nox/stdtypes.h"
#include "public/nox/string.h"
uint64_t nx_fs_open (string_t path, uint64_t len, uint64_t* fd);
uint64_t nx_fs_close (uint64_t fd);
uint64_t nx_fs_read (uint64_t fd, uint64_t offset, void* mem, uint64_t n);
uint64_t nx_fs_write (uint64_t fd, uint64_t offset, void* mem, uint64_t n);
uint64_t nx_fs_delete (string_t path, uint64_t len);
uint64_t nx_fs_list (string_t path, uint64_t len, void* mem, uint64_t* needed_mem);
uint64_t nx_fs_info (uint64_t fd, uint64_t attr, void* mem);
uint64_t nx_fs_open (string_t path, uint64_t len, uint64_t* fd);
uint64_t nx_fs_close (uint64_t fd);
uint64_t nx_fs_read (uint64_t fd, uint64_t offset, void* mem, uint64_t n);
uint64_t nx_fs_write (uint64_t fd, uint64_t offset, void* mem, uint64_t n);
uint64_t nx_fs_delete (string_t path, uint64_t len);
uint64_t nx_fs_list (string_t path, uint64_t len, void* mem, uint64_t* needed_mem);
uint64_t nx_fs_info (uint64_t fd, uint64_t attr, void* mem);
uint64_t nx_mem_alloc (void* addr, uint64_t n, uint64_t flags);
uint64_t nx_mem_free (void* addr, uint64_t n);
uint64_t nx_mem_label (void* addr, uint64_t len, uint64_t* fd);
uint64_t nx_mem_unlabel (uint64_t* fd);
uint64_t nx_mem_alloc (void* addr, uint64_t n, uint64_t flags);
uint64_t nx_mem_free (void* addr, uint64_t n);
uint64_t nx_mem_label (void* addr, uint64_t len, uint64_t* fd);
uint64_t nx_mem_unlabel (uint64_t* fd);
uint64_t nx_proc_create (void* conf, uint64_t* pid);
uint64_t nx_proc_signal_send (uint64_t pid, uint64_t signal);
uint64_t nx_proc_signal_set_handler (uint64_t signal, void* handler);
uint64_t nx_thread_create (void* addr, uint64_t* tid);
uint64_t nx_thread_start (uint64_t tid);
uint64_t nx_thread_stop (uint64_t tid);
uint64_t nx_thread_kill (uint64_t tid);
uint64_t nx_proc_create (void* conf, uint64_t* pid);
uint64_t nx_proc_signal_send (uint64_t pid, uint64_t signal);
uint64_t nx_proc_signal_set_handler (uint64_t signal, void* handler);
uint64_t nx_proc_thread_create (void* addr, uint64_t* tid);
uint64_t nx_proc_thread_start (uint64_t tid);
uint64_t nx_proc_thread_pause (uint64_t tid);
uint64_t nx_proc_thread_kill (uint64_t tid);
uint64_t nx_drv_register (uint64_t fd, void* conf);
uint64_t nx_drv_create_command_buffer (void* addr, uint64_t len);
uint64_t nx_drv_flush_command_buffer (void* addr);
#endif //LIBC_SYSCALL_H

View File

@ -5,24 +5,115 @@
extern uint64_t syscall_perform(uint64_t id, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
typedef enum {
NX_FS_OPEN = 0x0001,
NX_FS_CLOSE = 0x0002,
NX_FS_READ = 0x0003,
NX_FS_WRITE = 0x0004,
NX_FS_DELETE = 0x0005,
NX_FS_LIST = 0x0006,
NX_FS_INFO = 0x0007,
NX_FS_OPEN = 0x0001,
NX_FS_CLOSE = 0x0002,
NX_FS_READ = 0x0003,
NX_FS_WRITE = 0x0004,
NX_FS_DELETE = 0x0005,
NX_FS_LIST = 0x0006,
NX_FS_INFO = 0x0007,
NX_MEM_ALLOC = 0x0101,
NX_MEM_FREE = 0x0102,
NX_MEM_LABEL = 0x0103,
NX_MEM_UNLABEL = 0x0104,
NX_MEM_ALLOC = 0x0101,
NX_MEM_FREE = 0x0102,
NX_MEM_LABEL = 0x0103,
NX_MEM_UNLABEL = 0x0104,
NX_PROC_CREATE = 0x0201,
NX_PROC_SIGNAL_SEND = 0x0202,
NX_PROC_SIGNAL_SET_HANDLER = 0x0203,
NX_PROC_THREAD_CREATE = 0x0204,
NX_PROC_THREAD_START = 0x0205,
NX_PROC_THREAD_PAUSE = 0x0206,
NX_PROC_THREAD_KILL = 0x0207,
NX_PROC_CREATE = 0x0201,
NX_PROC_SIGNAL_SEND = 0x0202,
NX_PROC_SIGNAL_SET_HANDLER = 0x0203,
NX_PROC_THREAD_CREATE = 0x0204,
NX_PROC_THREAD_START = 0x0205,
NX_PROC_THREAD_PAUSE = 0x0206,
NX_PROC_THREAD_KILL = 0x0207,
NX_DRV_REGISTER = 0x0301,
NX_DRV_CREATE_COMMAND_BUFFER = 0x0302,
NX_DRV_FLUSH_COMMAND_BUFFER = 0x0303,
} syscall_E;
uint64_t nx_fs_open(string_t path, uint64_t len, uint64_t* fd) {
return syscall_perform(NX_FS_OPEN, (uint64_t)path, len, (uint64_t)fd, 0);
}
uint64_t nx_fs_close(uint64_t fd) {
return syscall_perform(NX_FS_CLOSE, fd, 0, 0, 0);
}
uint64_t nx_fs_read(uint64_t fd, uint64_t offset, void* mem, uint64_t n) {
return syscall_perform(NX_FS_READ, fd, offset, (uint64_t)mem, n);
}
uint64_t nx_fs_write(uint64_t fd, uint64_t offset, void* mem, uint64_t n) {
return syscall_perform(NX_FS_WRITE, fd, offset, (uint64_t)mem, n);
}
uint64_t nx_fs_delete(string_t path, uint64_t len) {
return syscall_perform(NX_FS_DELETE, (uint64_t)path, len, 0, 0);
}
uint64_t nx_fs_list(string_t path, uint64_t len, void* mem, uint64_t* needed_mem) {
return syscall_perform(NX_FS_LIST, (uint64_t)path, len, (uint64_t)mem, (uint64_t)needed_mem);
}
uint64_t nx_fs_info(uint64_t fd, uint64_t attr, void* mem) {
return syscall_perform(NX_FS_INFO, fd, attr, (uint64_t)mem, 0);
}
uint64_t nx_mem_alloc(void* addr, uint64_t n, uint64_t flags) {
return syscall_perform(NX_MEM_ALLOC, (uint64_t)addr, n, flags, 0);
}
uint64_t nx_mem_free(void* addr, uint64_t n) {
return syscall_perform(NX_MEM_FREE, (uint64_t)addr, n, 0, 0);
}
uint64_t nx_mem_label(void* addr, uint64_t len, uint64_t* fd) {
return syscall_perform(NX_MEM_LABEL, (uint64_t)addr, len, (uint64_t)fd, 0);
}
uint64_t nx_mem_unlabel(uint64_t* fd) {
return syscall_perform(NX_MEM_UNLABEL, (uint64_t) fd, 0, 0, 0);
}
uint64_t nx_proc_create(void* conf, uint64_t* pid) {
return syscall_perform(NX_PROC_CREATE, (uint64_t)conf, (uint64_t)pid, 0, 0);
}
uint64_t nx_proc_signal_send(uint64_t pid, uint64_t signal) {
return syscall_perform(NX_PROC_SIGNAL_SEND, pid, signal, 0, 0);
}
uint64_t nx_proc_signal_set_handler(uint64_t signal, void* handler) {
return syscall_perform(NX_PROC_SIGNAL_SET_HANDLER, signal, (uint64_t)handler, 0, 0);
}
uint64_t nx_proc_thread_create(void* addr, uint64_t* tid) {
return syscall_perform(NX_PROC_THREAD_CREATE, (uint64_t)addr, (uint64_t)tid, 0, 0);
}
uint64_t nx_proc_thread_start(uint64_t tid) {
return syscall_perform(NX_PROC_THREAD_START, tid, 0, 0, 0);
}
uint64_t nx_proc_thread_pause(uint64_t tid) {
return syscall_perform(NX_PROC_THREAD_PAUSE, tid, 0, 0, 0);
}
uint64_t nx_proc_thread_kill(uint64_t tid) {
return syscall_perform(NX_PROC_THREAD_KILL, tid, 0, 0, 0);
}
uint64_t nx_drv_register(uint64_t fd, void* conf) {
return syscall_perform(NX_DRV_REGISTER, fd, (uint64_t)conf, 0, 0);
}
uint64_t nx_drv_create_command_buffer(void* addr, uint64_t len) {
return syscall_perform(NX_DRV_CREATE_COMMAND_BUFFER, (uint64_t)addr, len, 0, 0);
}
uint64_t nx_drv_flush_command_buffer(void* addr) {
return syscall_perform(NX_DRV_FLUSH_COMMAND_BUFFER, (uint64_t)addr, 0, 0, 0);
}