Move status codes into a separate header
All checks were successful
Build documentation / build-and-deploy (push) Successful in 36s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 36s
This commit is contained in:
13
include/m/status.h
Normal file
13
include/m/status.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _M_STATUS_H
|
||||
#define _M_STATUS_H
|
||||
|
||||
#define ST_OK 0
|
||||
#define ST_SYSCALL_NOT_FOUND 1
|
||||
#define ST_UNALIGNED 2
|
||||
#define ST_OOM_ERROR 3
|
||||
#define ST_NOT_FOUND 4
|
||||
#define ST_BAD_ADDRESS_SPACE 5
|
||||
#define ST_PERMISSION_ERROR 6
|
||||
#define ST_BAD_RESOURCE 7
|
||||
|
||||
#endif // _M_STATUS_H
|
||||
@@ -13,13 +13,4 @@
|
||||
#define SYS_PROC_SPAWN_THREAD 10
|
||||
#define SYS_PROC_SCHED 11
|
||||
|
||||
#define SR_OK 0
|
||||
#define SR_SYSCALL_NOT_FOUND 1
|
||||
#define SR_UNALIGNED 2
|
||||
#define SR_OOM_ERROR 3
|
||||
#define SR_NOT_FOUND 4
|
||||
#define SR_BAD_ADDRESS_SPACE 5
|
||||
#define SR_PERMISSION_ERROR 6
|
||||
#define SR_BAD_RESOURCE 7
|
||||
|
||||
#endif // _M_SYSCALL_DEFS_H
|
||||
|
||||
@@ -22,7 +22,7 @@ int make_thread (void (*fn) (void)) {
|
||||
size_t stack_size = 256 * PAGE_SIZE;
|
||||
void* stack = malloc (stack_size);
|
||||
if (stack == NULL)
|
||||
return -SR_OOM_ERROR;
|
||||
return -ST_OOM_ERROR;
|
||||
|
||||
uintptr_t stack_top = (uintptr_t)stack + stack_size;
|
||||
return proc_spawn_thread (stack_top, stack_size, (void*)fn);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <amd64/mm.h>
|
||||
#include <amd64/msr-index.h>
|
||||
#include <amd64/msr.h>
|
||||
#include <m/status.h>
|
||||
#include <m/syscall_defs.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sys/debug.h>
|
||||
@@ -20,7 +21,7 @@ int amd64_syscall_dispatch (void* stack_ptr) {
|
||||
syscall_handler_func_t func = syscall_find_handler (syscall_num);
|
||||
|
||||
if (func == NULL)
|
||||
return -SR_SYSCALL_NOT_FOUND;
|
||||
return -ST_SYSCALL_NOT_FOUND;
|
||||
|
||||
struct proc* caller = thiscpu->proc_current;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <aux/compiler.h>
|
||||
#include <libk/std.h>
|
||||
#include <limine/requests.h>
|
||||
#include <m/status.h>
|
||||
#include <m/syscall_defs.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <proc/mutex.h>
|
||||
@@ -19,14 +20,14 @@
|
||||
/* int proc_quit (void) */
|
||||
DEFINE_SYSCALL (sys_proc_quit) {
|
||||
proc_kill (proc, regs);
|
||||
return SR_OK;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
/* int proc_test (void) */
|
||||
DEFINE_SYSCALL (sys_proc_test) {
|
||||
char c = (char)a1;
|
||||
DEBUG ("test syscall from %d! %c\n", proc->pid, c);
|
||||
return SR_OK;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
/* int proc_map (uintptr_t paddr, uintptr_t vaddr, size_t pages, uint32_t flags) */
|
||||
@@ -37,13 +38,13 @@ DEFINE_SYSCALL (sys_proc_map) {
|
||||
uint32_t flags = (uint32_t)a4;
|
||||
|
||||
if (vaddr % PAGE_SIZE != 0)
|
||||
return -SR_UNALIGNED;
|
||||
return -ST_UNALIGNED;
|
||||
|
||||
if (paddr % PAGE_SIZE != 0)
|
||||
return -SR_UNALIGNED;
|
||||
return -ST_UNALIGNED;
|
||||
|
||||
bool ok = proc_map (proc, paddr, vaddr, pages, flags);
|
||||
return ok ? SR_OK : -SR_OOM_ERROR;
|
||||
return ok ? ST_OK : -ST_OOM_ERROR;
|
||||
}
|
||||
|
||||
/* int proc_unmap (uintptr_t vaddr, size_t pages) */
|
||||
@@ -52,10 +53,10 @@ DEFINE_SYSCALL (sys_proc_unmap) {
|
||||
size_t pages = (size_t)a2;
|
||||
|
||||
if (vaddr % PAGE_SIZE != 0)
|
||||
return -SR_UNALIGNED;
|
||||
return -ST_UNALIGNED;
|
||||
|
||||
bool ok = proc_unmap (proc, vaddr, pages);
|
||||
return ok ? SR_OK : -SR_OOM_ERROR;
|
||||
return ok ? ST_OK : -ST_OOM_ERROR;
|
||||
}
|
||||
|
||||
/* int proc_create_resource_mem (int rid, size_t pages, int vis, uintptr_t* out_paddr) */
|
||||
@@ -69,7 +70,7 @@ DEFINE_SYSCALL (sys_proc_create_resource_mem) {
|
||||
uintptr_t* out_paddr_buf = (uintptr_t*)a4;
|
||||
|
||||
if (rid < 0)
|
||||
return -SR_BAD_RESOURCE;
|
||||
return -ST_BAD_RESOURCE;
|
||||
|
||||
spin_lock (&proc->pd->lock, &ctxprpd);
|
||||
|
||||
@@ -77,7 +78,7 @@ DEFINE_SYSCALL (sys_proc_create_resource_mem) {
|
||||
|
||||
if (!mm_validate_buffer (proc->pd, (uintptr_t)out_paddr_buf, sizeof (uintptr_t), 0)) {
|
||||
spin_unlock (&proc->pd->lock, &ctxprpd);
|
||||
return -SR_BAD_ADDRESS_SPACE;
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
}
|
||||
|
||||
spin_unlock (&proc->pd->lock, &ctxprpd);
|
||||
@@ -91,7 +92,7 @@ DEFINE_SYSCALL (sys_proc_create_resource_mem) {
|
||||
*out_paddr_buf_vaddr = r->u.mem.paddr;
|
||||
return r->rid;
|
||||
} else {
|
||||
return -SR_OOM_ERROR;
|
||||
return -ST_OOM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,13 +102,13 @@ DEFINE_SYSCALL (sys_proc_create_resource_mutex) {
|
||||
int vis = (int)a2;
|
||||
|
||||
if (rid < 0)
|
||||
return -SR_BAD_RESOURCE;
|
||||
return -ST_BAD_RESOURCE;
|
||||
|
||||
struct proc_resource* r = proc_create_resource (proc, rid, PR_MUTEX, vis, NULL);
|
||||
if (r != NULL)
|
||||
return r->rid;
|
||||
else
|
||||
return -SR_OOM_ERROR;
|
||||
return -ST_OOM_ERROR;
|
||||
}
|
||||
|
||||
/* int proc_mutex_lock (int mutex_rid) */
|
||||
@@ -122,11 +123,11 @@ DEFINE_SYSCALL (sys_proc_mutex_lock) {
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
|
||||
if (resource == NULL)
|
||||
return -SR_NOT_FOUND;
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
proc_mutex_lock (proc, &resource->u.mutex);
|
||||
|
||||
return SR_OK;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
DEFINE_SYSCALL (sys_proc_mutex_unlock) {
|
||||
@@ -140,15 +141,15 @@ DEFINE_SYSCALL (sys_proc_mutex_unlock) {
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
|
||||
if (resource == NULL)
|
||||
return -SR_NOT_FOUND;
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
int result = proc_mutex_unlock (proc, &resource->u.mutex) ? SR_OK : -SR_PERMISSION_ERROR;
|
||||
int result = proc_mutex_unlock (proc, &resource->u.mutex) ? ST_OK : -ST_PERMISSION_ERROR;
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
proc_sched (regs);
|
||||
|
||||
return SR_OK;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
/* int proc_drop_resource (int rid) */
|
||||
@@ -163,11 +164,11 @@ DEFINE_SYSCALL (sys_proc_drop_resource) {
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
|
||||
if (resource == NULL)
|
||||
return -SR_NOT_FOUND;
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
proc_drop_resource (proc, resource);
|
||||
|
||||
return SR_OK;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
/* int proc_spawn_thread (uintptr_t vstack_top, size_t stack_size, void* entry) */
|
||||
@@ -183,7 +184,7 @@ DEFINE_SYSCALL (sys_proc_spawn_thread) {
|
||||
DEBUG ("new=%p\n", new);
|
||||
|
||||
if (new == NULL) {
|
||||
return -SR_OOM_ERROR;
|
||||
return -ST_OOM_ERROR;
|
||||
}
|
||||
|
||||
int pid = new->pid;
|
||||
@@ -196,7 +197,7 @@ DEFINE_SYSCALL (sys_proc_spawn_thread) {
|
||||
/* int proc_sched (void) */
|
||||
DEFINE_SYSCALL (sys_proc_sched) {
|
||||
proc_sched (regs);
|
||||
return SR_OK;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef _LIBMSL_M_STATUS_H
|
||||
#define _LIBMSL_M_STATUS_H
|
||||
|
||||
#include <m/syscall.h>
|
||||
|
||||
#endif // _LIBMSL_M_STATUS_H
|
||||
Reference in New Issue
Block a user