aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-11-21 17:38:57 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2022-11-21 17:38:57 +0200
commite1599d8ab33f3f7d09c6a8a05f954209c969c8c1 (patch)
tree6a7a74578dae2e7e0063474ac6aca674db9d8ea3
parent6f5065da917a911c5e810a058d16d147c31d5fbe (diff)
downloadkmi-e1599d8ab33f3f7d09c6a8a05f954209c969c8c1.tar.gz
kmi-e1599d8ab33f3f7d09c6a8a05f954209c969c8c1.zip
make syscall handlers void
-rw-r--r--Makefile2
-rw-r--r--arch/riscv64/kernel/entry.S43
-rw-r--r--common/dispatch.c15
-rw-r--r--common/uapi/cap.c21
-rw-r--r--common/uapi/conf.c25
-rw-r--r--common/uapi/dispatch.c124
-rw-r--r--common/uapi/ipc.c50
-rw-r--r--common/uapi/mem.c30
-rw-r--r--common/uapi/proc.c43
-rw-r--r--common/uapi/timers.c31
-rw-r--r--include/apos/tcb.h4
-rw-r--r--include/apos/uapi.h342
12 files changed, 381 insertions, 349 deletions
diff --git a/Makefile b/Makefile
index 5e3dc50..3c29758 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ DO != echo -n > deps.mk
# this could be done better
DEBUGFLAGS != [ $(RELEASE) ] \
- && echo "-flto -O2 -g -DDEBUG" \
+ && echo "-flto -O2 -g -DNDEBUG" \
|| echo "-O0 -g -DDEBUG"
CFLAGS = -ffreestanding -nostdlib -static -fno-pie -std=c17 -Wall -Wextra -Wvla -D$(ARCH)
diff --git a/arch/riscv64/kernel/entry.S b/arch/riscv64/kernel/entry.S
index f099065..b4308b4 100644
--- a/arch/riscv64/kernel/entry.S
+++ b/arch/riscv64/kernel/entry.S
@@ -72,39 +72,21 @@ _save_context:
/* interrupts fall through, exceptions jump */
bge s4, zero, handle_exception
/* TODO: handle interrupts */
- j restore_all
+ j _load_context
handle_exception:
li t0, EXC_SYSCALL
/* system exceptions fall through, syscalls and ipis jump */
/* temp, at some point we want to handle system exceptions as well */
beq s4, t0, handle_dispatch
- j restore_all
+ j _load_context
handle_dispatch:
/* store execution continuation point */
csrr s0, CSR_SEPC
sr s0, offsetof_exec(tp)
- /* allocate space for sys_ret structure on stack and shift argument
- * registers down one to make room for the pointer to this structure */
- addi sp, sp, -sizeof_sys_ret
- mv a6, a5
- mv a5, a4
- mv a4, a3
- mv a3, a2
- mv a2, a1
- mv a1, a0
- mv a0, sp
/* jump to C */
jal dispatch
- /* move structure from stack into registers. */
- lr a0, offsetof_s(sp)
- lr a1, offsetof_ar0(sp)
- lr a2, offsetof_ar1(sp)
- lr a3, offsetof_ar2(sp)
- lr a4, offsetof_ar3(sp)
- lr a5, offsetof_ar4(sp)
- addi sp, sp, sizeof_sys_ret
/* if we had a thread switch, load kernel stack of current thread and
* restore its context */
/* get associated kernel stack */
@@ -113,18 +95,8 @@ handle_dispatch:
/* set execution continuation */
lr s0, offsetof_exec(tp)
csrw CSR_SEPC, s0
- /* restore system call result */
- j restore_noreturn
-restore_all:
- lr a0, offsetof_a0(sp)
- lr a1, offsetof_a1(sp)
- lr a2, offsetof_a2(sp)
- lr a3, offsetof_a3(sp)
- lr a4, offsetof_a4(sp)
- lr a5, offsetof_a5(sp)
-
-restore_noreturn:
+_load_context:
/* restore registers besides possible return value, assume instruction
* to return to has already been set (CSR_EPC) */
csrw CSR_SSCRATCH, tp
@@ -135,8 +107,14 @@ restore_noreturn:
lr t0, offsetof_t0(sp)
lr t1, offsetof_t1(sp)
lr t2, offsetof_t2(sp)
- /* a0 - a5 should not be restored when coming from a syscall */
+ lr a0, offsetof_a0(sp)
+ lr a1, offsetof_a1(sp)
+ lr a2, offsetof_a2(sp)
+ lr a3, offsetof_a3(sp)
+ lr a4, offsetof_a4(sp)
+ lr a5, offsetof_a5(sp)
lr a6, offsetof_a6(sp)
+ lr a7, offsetof_a7(sp)
lr s0, offsetof_s0(sp)
lr s1, offsetof_s1(sp)
lr s2, offsetof_s2(sp)
@@ -149,7 +127,6 @@ restore_noreturn:
lr s9, offsetof_s9(sp)
lr s10,offsetof_s10(sp)
lr s11,offsetof_s11(sp)
- lr a7, offsetof_a7(sp)
lr t3, offsetof_t3(sp)
lr t4, offsetof_t4(sp)
lr t5, offsetof_t5(sp)
diff --git a/common/dispatch.c b/common/dispatch.c
index 7fc13cf..25ff0eb 100644
--- a/common/dispatch.c
+++ b/common/dispatch.c
@@ -22,14 +22,17 @@
* @param d Argument 2.
* @param e Argument 3.
* @param f Argument 4.
- * @return Return value of taken action.
+ *
+ * Returns value of taken action.
*/
-struct sys_ret dispatch(sys_arg_t a, sys_arg_t b, sys_arg_t c,
- sys_arg_t d, sys_arg_t e, sys_arg_t f)
+void dispatch(sys_arg_t a, sys_arg_t b, sys_arg_t c,
+ sys_arg_t d, sys_arg_t e, sys_arg_t f)
{
struct tcb *t = cur_tcb();
- if (clear_ipi(t))
- return handle_ipi(t);
+ if (clear_ipi(t)) {
+ handle_ipi(t);
+ return;
+ }
- return handle_syscall(t, a, b, c, d, e, f);
+ handle_syscall(a, b, c, d, e, f, t);
}
diff --git a/common/uapi/cap.c b/common/uapi/cap.c
index b094c43..f681e8d 100644
--- a/common/uapi/cap.c
+++ b/common/uapi/cap.c
@@ -29,6 +29,7 @@ static capflags_t *__get_tcb_caps(id_t tid, size_t off)
/**
* Set capabilities.
*
+ * @param t Current tcb.
* @param tid Thread ID whose capabilities to set.
* @param off Offset of capability, multiple of \c bits(cap).
* @param caps Mask of capabilities to set.
@@ -38,37 +39,37 @@ SYSCALL_DEFINE3(set_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t off,
sys_arg_t caps)
{
if (!is_set(t->caps, CAP_CAPS))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
capflags_t *c;
if (!(c = __get_tcb_caps(tid, off)))
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
set_caps(*c, off, caps);
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
/**
* Get capabilities.
*
+ * @param t Current tcb.
* @param tid Thread ID whose capabilities to get.
* @param off Offset of capability, multiple of \c bits(cap).
* @return \ref OK, capabilities.
*/
SYSCALL_DEFINE2(get_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t off)
{
- UNUSED(t);
-
capflags_t *c;
if (!(c = __get_tcb_caps(tid, off)))
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
- return SYS_RET2(OK, get_caps(*c, off));
+ return_args(t, SYS_RET2(OK, get_caps(*c, off)));
}
/**
* Clear capabilities.
*
+ * @param t Current tcb.
* @param tid Thread ID whose capabilities to clear.
* @param off Offset of capability, multiple of \c bits(cap).
* @param caps Mask of capabilities to clear.
@@ -79,12 +80,12 @@ SYSCALL_DEFINE3(clear_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t off,
sys_arg_t caps)
{
if (!is_set(t->caps, CAP_CAPS))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
capflags_t *c;
if (!(c = __get_tcb_caps(tid, off)))
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
clear_caps(*c, off, caps);
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
diff --git a/common/uapi/conf.c b/common/uapi/conf.c
index c405e2e..b3ac693 100644
--- a/common/uapi/conf.c
+++ b/common/uapi/conf.c
@@ -13,6 +13,8 @@
#include <apos/uapi.h>
#include <apos/conf.h>
+#include <arch/proc.h>
+
/** \todo stack size should really be set on a per-thread basis, and are the
* conf*-syscalls even necessary? */
size_t __thread_stack_size = SZ_2M;
@@ -32,13 +34,14 @@ enum conf_param {
*
* \todo Implement parameters.
*
+ * @param t Current tcb.
* @param param Parameter to read.
* @return \ref OK and parameter value.
*/
SYSCALL_DEFINE1(conf_get)(struct tcb *t, sys_arg_t param)
{
if (!has_cap(t->caps, CAP_CONF))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
long val = 0;
switch (param) {
@@ -55,10 +58,10 @@ SYSCALL_DEFINE1(conf_get)(struct tcb *t, sys_arg_t param)
break;
default:
- return SYS_RET1(ERR_NF);
+ return_args(t, SYS_RET1(ERR_NF));
}
- return SYS_RET2(OK, val);
+ return_args(t, SYS_RET2(OK, val));
}
/**
@@ -66,6 +69,7 @@ SYSCALL_DEFINE1(conf_get)(struct tcb *t, sys_arg_t param)
*
* \todo Implement parameters.
*
+ * @param t Current tcb.
* @param param Parameter to write.
* @param val Value to set \c param to.
* @return \ref OK and \c 0.
@@ -73,7 +77,7 @@ SYSCALL_DEFINE1(conf_get)(struct tcb *t, sys_arg_t param)
SYSCALL_DEFINE2(conf_set)(struct tcb *t, sys_arg_t param, sys_arg_t val)
{
if (!has_cap(t->caps, CAP_CONF))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
size_t size = 0;
switch (param) {
@@ -84,7 +88,7 @@ SYSCALL_DEFINE2(conf_set)(struct tcb *t, sys_arg_t param, sys_arg_t val)
case CONF_CALL_STACK:
size = align_up(val, RPC_STACK_RATIO * BASE_PAGE_SIZE);
if (size < __rpc_stack_size * RPC_STACK_RATIO)
- return SYS_RET1(ERR_MISC);
+ return_args(t, SYS_RET1(ERR_MISC));
__call_stack_size = size;
break;
@@ -92,18 +96,19 @@ SYSCALL_DEFINE2(conf_set)(struct tcb *t, sys_arg_t param, sys_arg_t val)
case CONF_RPC_STACK:
size = align_up(val, BASE_PAGE_SIZE);
if (size > __call_stack_size / RPC_STACK_RATIO)
- return SYS_RET1(ERR_MISC);
+ return_args(t, SYS_RET1(ERR_MISC));
__rpc_stack_size = size;
break;
}
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
/**
* Poweroff syscall handler.
*
+ * @param t Current tcb.
* @param type Type of poweroff.
* @return \ref ERR_INVAL and \c 0 if incorrect poweroff \c type give, otherwise
* does not return.
@@ -111,14 +116,14 @@ SYSCALL_DEFINE2(conf_set)(struct tcb *t, sys_arg_t param, sys_arg_t val)
SYSCALL_DEFINE1(poweroff)(struct tcb *t, sys_arg_t type)
{
if (!(has_cap(t->caps, CAP_POWER)))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
switch (type) {
case SHUTDOWN:
case COLD_REBOOT:
case WARM_REBOOT:
- return SYS_RET2(OK, poweroff(type));
+ return_args(t, SYS_RET2(OK, poweroff(type)));
};
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
}
diff --git a/common/uapi/dispatch.c b/common/uapi/dispatch.c
index 37b551a..aa63170 100644
--- a/common/uapi/dispatch.c
+++ b/common/uapi/dispatch.c
@@ -10,126 +10,78 @@
#include <apos/debug.h>
#include <apos/uapi.h>
-#include <arch/proc.h>
-
-/** Syscall number to syscall handler conversion. */
-static const sys_t syscall_table[] = {
- /* noop */
- [SYS_NOOP] = sys_noop,
-
- /* debugging */
- [SYS_PUTCH] = sys_putch,
-
- /* mem */
- [SYS_REQ_MEM] = sys_req_mem,
- [SYS_REQ_PMEM] = sys_req_pmem,
- [SYS_REQ_FIXMEM] = sys_req_fixmem,
- [SYS_FREE_MEM] = sys_free_mem,
-
- /* timers */
- [SYS_TIMEBASE] = sys_timebase,
- [SYS_TICKS] = sys_ticks,
- [SYS_REQ_REL_TIMER] = sys_req_rel_timer,
- [SYS_REQ_ABS_TIMER] = sys_req_abs_timer,
- [SYS_FREE_TIMER] = sys_free_timer,
-
- /* ipc */
- [SYS_IPC_SERVER] = sys_ipc_server,
- [SYS_IPC_REQ] = sys_ipc_req,
- [SYS_IPC_FWD] = sys_ipc_fwd,
- [SYS_IPC_RESP] = sys_ipc_resp,
- [SYS_IPC_NOTIFY] = sys_ipc_notify,
-
- /* proc */
- [SYS_CREATE] = sys_create,
- [SYS_FORK] = sys_fork,
- [SYS_EXEC] = sys_exec,
- [SYS_SPAWN] = sys_spawn,
- [SYS_SWAP] = sys_swap,
-
- /* conf */
- [SYS_CONF_SET] = sys_conf_set,
- [SYS_CONF_GET] = sys_conf_get,
-
- [SYS_SET_CAP] = sys_set_cap,
- [SYS_GET_CAP] = sys_get_cap,
- [SYS_CLEAR_CAP] = sys_clear_cap,
-
- [SYS_POWEROFF] = sys_poweroff,
-};
+/* not sure why doxygen requires these two definitions to state their return
+ * values, when they don't actually return anything but eh */
/**
* Noop syscall handler.
*
+ * @param t Current tcb.
+ *
* @return \ref OK and \c 0.
*/
SYSCALL_DEFINE0(noop)(struct tcb *t)
{
- UNUSED(t);
info("sys_noop\n");
- return SYS_RET1(OK);
+ set_args(t, SYS_RET1(OK));
}
/**
* Putch syscall handler.
*
+ * @param t Current tcb.
* @param a Character to put.
+ *
* @return \ref OK and 0.
*/
SYSCALL_DEFINE1(putch)(struct tcb *t, sys_arg_t a)
{
- UNUSED(t);
-
const char c[2] = {a, 0};
MAYBE_UNUSED(c);
dbg((const char *)&c);
- return SYS_RET1(OK);
+ set_args(t, SYS_RET1(OK));
}
-struct sys_ret handle_syscall(struct tcb *t,
- sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
- sys_arg_t c, sys_arg_t d, sys_arg_t e)
+void handle_syscall(sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
+ sys_arg_t c, sys_arg_t d, sys_arg_t e, struct tcb *t)
{
adjust_syscall(t);
- struct sys_ret r;
switch (syscall) {
- case SYS_NOOP: r = sys_noop(t, a, b, c, d, e); break;
- case SYS_PUTCH: r = sys_putch(t, a, b, c, d, e); break;
- case SYS_REQ_MEM: r = sys_req_mem(t, a, b, c, d, e); break;
- case SYS_REQ_PMEM: r = sys_req_pmem(t, a, b, c, d, e); break;
- case SYS_REQ_FIXMEM: r = sys_req_fixmem(t, a, b, c, d, e); break;
- case SYS_FREE_MEM: r = sys_free_mem(t, a, b, c, d, e); break;
- case SYS_TIMEBASE: r = sys_timebase(t, a, b, c, d, e); break;
- case SYS_TICKS: r = sys_ticks(t, a, b, c, d, e); break;
- case SYS_REQ_REL_TIMER: r = sys_req_rel_timer(t, a, b, c, d, e); break;
- case SYS_REQ_ABS_TIMER: r = sys_req_abs_timer(t, a, b, c, d, e); break;
- case SYS_IPC_SERVER: r = sys_ipc_server(t, a, b, c, d, e); break;
- case SYS_IPC_REQ: r = sys_ipc_req(t, a, b, c, d, e); break;
- case SYS_IPC_FWD: r = sys_ipc_fwd(t, a, b, c, d, e); break;
- case SYS_IPC_RESP: r = sys_ipc_resp(t, a, b, c, d, e); break;
- case SYS_IPC_NOTIFY: r = sys_ipc_notify(t, a, b, c, d, e); break;
- case SYS_CREATE: r = sys_create(t, a, b, c, d, e); break;
- case SYS_FORK: r = sys_fork(t, a, b, c, d, e); break;
- case SYS_EXEC: r = sys_exec(t, a, b, c, d, e); break;
- case SYS_SPAWN: r = sys_spawn(t, a, b, c, d, e); break;
- case SYS_KILL: r = sys_kill(t, a, b, c, d, e); break;
- case SYS_SWAP: r = sys_swap(t, a, b, c, d, e); break;
- case SYS_CONF_SET: r = sys_conf_set(t, a, b, c, d, e); break;
- case SYS_CONF_GET: r = sys_conf_get(t, a, b, c, d, e); break;
- case SYS_SET_CAP: r = sys_set_cap(t, a, b, c, d, e); break;
- case SYS_GET_CAP: r = sys_get_cap(t, a, b, c, d, e); break;
- case SYS_CLEAR_CAP: r = sys_clear_cap(t, a, b, c, d, e); break;
- case SYS_POWEROFF: r = sys_poweroff(t, a, b, c, d, e); break;
+ case SYS_NOOP: sys_noop(t, a, b, c, d, e); break;
+ case SYS_PUTCH: sys_putch(t, a, b, c, d, e); break;
+ case SYS_REQ_MEM: sys_req_mem(t, a, b, c, d, e); break;
+ case SYS_REQ_PMEM: sys_req_pmem(t, a, b, c, d, e); break;
+ case SYS_REQ_FIXMEM: sys_req_fixmem(t, a, b, c, d, e); break;
+ case SYS_FREE_MEM: sys_free_mem(t, a, b, c, d, e); break;
+ case SYS_TIMEBASE: sys_timebase(t, a, b, c, d, e); break;
+ case SYS_TICKS: sys_ticks(t, a, b, c, d, e); break;
+ case SYS_REQ_REL_TIMER: sys_req_rel_timer(t, a, b, c, d, e); break;
+ case SYS_REQ_ABS_TIMER: sys_req_abs_timer(t, a, b, c, d, e); break;
+ case SYS_IPC_SERVER: sys_ipc_server(t, a, b, c, d, e); break;
+ case SYS_IPC_REQ: sys_ipc_req(t, a, b, c, d, e); break;
+ case SYS_IPC_FWD: sys_ipc_fwd(t, a, b, c, d, e); break;
+ case SYS_IPC_RESP: sys_ipc_resp(t, a, b, c, d, e); break;
+ case SYS_IPC_NOTIFY: sys_ipc_notify(t, a, b, c, d, e); break;
+ case SYS_CREATE: sys_create(t, a, b, c, d, e); break;
+ case SYS_FORK: sys_fork(t, a, b, c, d, e); break;
+ case SYS_EXEC: sys_exec(t, a, b, c, d, e); break;
+ case SYS_SPAWN: sys_spawn(t, a, b, c, d, e); break;
+ case SYS_KILL: sys_kill(t, a, b, c, d, e); break;
+ case SYS_SWAP: sys_swap(t, a, b, c, d, e); break;
+ case SYS_CONF_SET: sys_conf_set(t, a, b, c, d, e); break;
+ case SYS_CONF_GET: sys_conf_get(t, a, b, c, d, e); break;
+ case SYS_SET_CAP: sys_set_cap(t, a, b, c, d, e); break;
+ case SYS_GET_CAP: sys_get_cap(t, a, b, c, d, e); break;
+ case SYS_CLEAR_CAP: sys_clear_cap(t, a, b, c, d, e); break;
+ case SYS_POWEROFF: sys_poweroff(t, a, b, c, d, e); break;
default:
error("Syscall %zu outside allowed range [0 - %i]\n", syscall,
SYS_NUM - 1);
- r = SYS_RET1(ERR_INVAL);
+ set_args(t, SYS_RET1(ERR_INVAL));
};
if (check_canary(t)) {
bug("Syscall %zu overwrote stack canary\n", syscall);
}
-
- return r;
}
diff --git a/common/uapi/ipc.c b/common/uapi/ipc.c
index 860ec54..93717e4 100644
--- a/common/uapi/ipc.c
+++ b/common/uapi/ipc.c
@@ -13,45 +13,51 @@
/**
* IPC server notification syscall handler.
*
+ * @param t Current tcb.
* @param callback Address of server callback.
* @return \ref OK and \c 0.
*/
SYSCALL_DEFINE1(ipc_server)(struct tcb *t, sys_arg_t callback)
{
get_cproc(t)->callback = callback;
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
/**
* Actual IPC syscall handler.
*
+ * @param t Current tcb.
* @param pid Process to request RPC to.
* @param d0 IPC argument 0.
* @param d1 IPC argument 1.
* @param d2 IPC argument 2.
* @param d3 IPC argument 3.
* @param fwd Whether to forward.
- * @return
+ *
+ * Returns \ref ERR_OOMEM if there isn't enough IPC stack left, \ref ERR_INVAL
+ * if the the target process doesn't exist, \ref ERR_NOINIT if the target
+ * process hasn't defined a callback. Otherwise \ref OK and whatever the target
+ * process sends back.
*/
-static struct sys_ret do_ipc(struct tcb *t,
- sys_arg_t pid,
- sys_arg_t d0,
- sys_arg_t d1,
- sys_arg_t d2,
- sys_arg_t d3,
- bool fwd)
+static void do_ipc(struct tcb *t,
+ sys_arg_t pid,
+ sys_arg_t d0,
+ sys_arg_t d1,
+ sys_arg_t d2,
+ sys_arg_t d3,
+ bool fwd)
{
if (!enough_rpc_stack(t))
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
struct tcb *r = get_tcb(pid);
if (!r)
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
r = get_rproc(r);
if (!r->callback)
- return SYS_RET1(ERR_NOINIT);
+ return_args(t, SYS_RET1(ERR_NOINIT));
clone_uvmem(r->proc.vmem, t->rpc.vmem);
use_vmem(t->rpc.vmem);
@@ -65,11 +71,12 @@ static struct sys_ret do_ipc(struct tcb *t,
t->pid = r->rid;
- return SYS_RET6(OK, t->eid, d0, d1, d2, d3);
+ return_args(t, SYS_RET6(OK, t->eid, d0, d1, d2, d3));
}
/**
* IPC request syscall handler.
*
+ * @param t Current tcb.
* @param pid Process to request RPC to.
* @param d0 IPC argument 0.
* @param d1 IPC argument 1.
@@ -80,12 +87,13 @@ static struct sys_ret do_ipc(struct tcb *t,
SYSCALL_DEFINE5(ipc_req)(struct tcb *t, sys_arg_t pid,
sys_arg_t d0, sys_arg_t d1, sys_arg_t d2, sys_arg_t d3)
{
- return do_ipc(t, pid, d0, d1, d2, d3, false);
+ do_ipc(t, pid, d0, d1, d2, d3, false);
}
/**
* IPC forwarding syscall handler.
*
+ * @param t Current tcb.
* @param pid Process to request RPC to.
* @param d0 IPC argument 0.
* @param d1 IPC argument 1.
@@ -96,12 +104,13 @@ SYSCALL_DEFINE5(ipc_req)(struct tcb *t, sys_arg_t pid,
SYSCALL_DEFINE5(ipc_fwd)(struct tcb *t, sys_arg_t pid,
sys_arg_t d0, sys_arg_t d1, sys_arg_t d2, sys_arg_t d3)
{
- return do_ipc(t, pid, d0, d1, d2, d3, true);
+ do_ipc(t, pid, d0, d1, d2, d3, true);
}
/**
* IPC response syscall handler.
*
+ * @param t Current tcb.
* @param d0 IPC return value 0.
* @param d1 IPC return value 1.
* @param d2 IPC return value 2.
@@ -121,7 +130,7 @@ SYSCALL_DEFINE4(ipc_resp)(struct tcb *t, sys_arg_t d0, sys_arg_t d1,
else
use_vmem(t->proc.vmem);
- return SYS_RET6(OK, t->tid, d0, d1, d2, d3);
+ return_args(t, SYS_RET6(OK, t->tid, d0, d1, d2, d3));
}
/**
@@ -129,25 +138,26 @@ SYSCALL_DEFINE4(ipc_resp)(struct tcb *t, sys_arg_t d0, sys_arg_t d1,
*
* \todo Implement.
*
+ * @param t Current tcb.
* @param tid Thread ID to notify.
* @return \ref OK and 0.
*/
SYSCALL_DEFINE1(ipc_notify)(struct tcb *t, sys_arg_t tid){
if (!has_cap(t->caps, CAP_CALL))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
struct tcb *r = get_tcb(tid);
if (r->notify_state == NOTIFY_QUEUED)
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
if (r->notify_state == NOTIFY_RUNNING) {
t->notify_state = NOTIFY_QUEUED;
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
r->notify_state = NOTIFY_QUEUED;
if (running(r))
send_ipi(r);
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
diff --git a/common/uapi/mem.c b/common/uapi/mem.c
index 1644a16..1de63f1 100644
--- a/common/uapi/mem.c
+++ b/common/uapi/mem.c
@@ -15,6 +15,7 @@
/**
* Memory request syscall handler.
*
+ * @param t Current tcb.
* @param size Minimum size of allocation.
* @param flags Flags of allocation.
* @return \ref OK and start of allocation when succesful,
@@ -25,14 +26,15 @@ SYSCALL_DEFINE2(req_mem)(struct tcb *t, sys_arg_t size, sys_arg_t flags)
struct tcb *r = get_cproc(t);
vm_t start = 0;
if ((start = alloc_uvmem(r, size, flags)))
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
- return SYS_RET2(OK, start);
+ return_args(t, SYS_RET2(OK, start));
}
/**
* Fixed memory request syscall handler.
*
+ * @param t Current tcb.
* @param fixed Address which should be included in allocation.
* @param size Minimum size of allocation after \c start.
* @param flags Flags of allocation.
@@ -45,14 +47,15 @@ SYSCALL_DEFINE3(req_fixmem)(struct tcb *t, sys_arg_t fixed, sys_arg_t size,
struct tcb *r = get_cproc(t);
vm_t start = 0;
if ((start = alloc_fixed_uvmem(r, fixed, size, flags)))
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
- return SYS_RET2(OK, start);
+ return_args(t, SYS_RET2(OK, start));
}
/**
* Free memory syscall handler.
*
+ * @param t Current tcb.
* @param start Start of allocation to free.
* @return \ref OK and \c 0 when succesful, \ref ERR_NF and \c 0 otherwise.
*/
@@ -68,14 +71,15 @@ SYSCALL_DEFINE1(free_mem)(struct tcb *t, sys_arg_t start)
status = free_devmem(r, vm_start);
if (status)
- return SYS_RET1(ERR_NF);
+ return_args(t, SYS_RET1(ERR_NF));
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
/**
* Request physical memory syscall handler.
*
+ * @param t Current tcb.
* @param paddr Physical address to map.
* @param size Minimum size of allocation.
* @param flags Flags of allocation.
@@ -93,14 +97,15 @@ SYSCALL_DEFINE3(req_pmem)(struct tcb *t, sys_arg_t paddr, sys_arg_t size,
struct tcb *r = get_cproc(t);
vm_t start = 0;
if ((start = alloc_devmem(r, paddr, size, flags)))
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
- return SYS_RET2(OK, start);
+ return_args(t, SYS_RET2(OK, start));
}
/**
* Request shared memory syscall handler.
*
+ * @param t Current tcb.
* @param size Minimum size of allocation.
* @param flags Flags of allocation.
* @return \ref OK and start of allocation when succesful,
@@ -112,14 +117,15 @@ SYSCALL_DEFINE2(req_sharedmem)(struct tcb *t, sys_arg_t size, sys_arg_t flags)
struct tcb *r = get_cproc(t);
vm_t start = 0;
if ((start = alloc_shared_uvmem(r, size, flags)))
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
- return SYS_RET2(OK, start);
+ return_args(t, SYS_RET2(OK, start));
}
/**
* Reference shared memory syscall handler.
*
+ * @param t Current tcb.
* @param tid Thread ID of shared memory owner.
* @param va Start of shared memory in \c tid.
* @param flags Flags of reference.
@@ -132,9 +138,9 @@ SYSCALL_DEFINE3(ref_sharedmem)(struct tcb *t, sys_arg_t tid, sys_arg_t va,
struct tcb *t2 = get_tcb(tid);
vm_t start = 0;
if ((start = ref_shared_uvmem(t, t2, va, flags)))
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
- return SYS_RET2(OK, start);
+ return_args(t, SYS_RET2(OK, start));
}
/** \todo add some way to specify who gets to access the shared memory? */
diff --git a/common/uapi/proc.c b/common/uapi/proc.c
index 2ce3382..607f028 100644
--- a/common/uapi/proc.c
+++ b/common/uapi/proc.c
@@ -12,11 +12,10 @@
#include <apos/bits.h>
#include <apos/mem_regions.h>
-#include <arch/proc.h>
-
/**
* Create syscall handler.
*
+ * @param t Current tcb.
* @param func Function to jump to at thread creation.
* @param d0 Argument 0.
* @param d1 Argument 1.
@@ -31,14 +30,14 @@ SYSCALL_DEFINE5(create)(struct tcb *t, sys_arg_t func,
{
struct tcb *c = create_thread(t);
if (!c)
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
alloc_stack(c);
set_args(c, SYS_RET5(c->tid, d0, d1, d2, d3));
set_return(c, func);
- return SYS_RET2(OK, c->tid);
+ return_args(t, SYS_RET2(OK, c->tid));
}
/**
@@ -54,30 +53,33 @@ SYSCALL_DEFINE5(create)(struct tcb *t, sys_arg_t func,
* would have to periodically ask the kernel about all threads it is aware of
* via sys_sync. Dunno.
*
+ * @param t Current tcb.
* @return \ref OK and 0.
*/
SYSCALL_DEFINE0(fork)(struct tcb *t)
{
struct tcb *c = get_cproc(t);
if (!(has_cap(c->caps, CAP_PROC)))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
struct tcb *n = create_proc(get_eproc(t));
if (!n)
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
/* prepare args for when we eventually swap to the new proc, giving
* parent ID as third return value */
set_args(n, SYS_RET3(OK, 0, n->pid));
- return SYS_RET2(OK, n->pid);
+ return_args(t, SYS_RET2(OK, n->pid));
}
/**
* Exec syscall handler.
*
+ * @param t Current tcb.
* @param bin Binary to execute.
* @param interp Optional interpreter binary.
+ *
* @return \see prepare_proc().
*/
SYSCALL_DEFINE2(exec)(struct tcb *t, sys_arg_t bin, sys_arg_t interp)
@@ -86,7 +88,7 @@ SYSCALL_DEFINE2(exec)(struct tcb *t, sys_arg_t bin, sys_arg_t interp)
/* mark binary to be kept */
struct mem_region *b = find_used_region(&t->sp_r, bin);
if (!b)
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
set_bit(b->flags, MR_KEEP);
@@ -95,7 +97,7 @@ SYSCALL_DEFINE2(exec)(struct tcb *t, sys_arg_t bin, sys_arg_t interp)
/* mark interpreter to be kept */
i = find_used_region(&t->sp_r, interp);
if (!i)
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
set_bit(i->flags, MR_KEEP);
}
@@ -108,32 +110,35 @@ SYSCALL_DEFINE2(exec)(struct tcb *t, sys_arg_t bin, sys_arg_t interp)
if (interp)
clear_bit(b->flags, MR_KEEP);
- return SYS_RET1(prepare_proc(t, bin, interp));
+ return_args(t, SYS_RET1(prepare_proc(t, bin, interp)));
}
/**
* Spawn syscall handler.
*
+ * @param t Current tcb.
* @param bin Binary to execute.
* @param interp Optional interpreter binary.
+ *
* @return \see prepare_proc() and process id of the new process.
*/
SYSCALL_DEFINE2(spawn)(struct tcb *t, sys_arg_t bin, sys_arg_t interp)
{
struct tcb *c = get_proc(t);
if (!(has_cap(c->caps, CAP_PROC)))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
struct tcb *n = create_proc(NULL);
if (!n)
- return SYS_RET1(ERR_OOMEM);
+ return_args(t, SYS_RET1(ERR_OOMEM));
- return SYS_RET2(prepare_proc(n, bin, interp), n->pid);
+ return_args(t, SYS_RET2(prepare_proc(n, bin, interp), n->pid));
}
/**
* Kill syscall handler.
*
+ * @param t Current tcb.
* @param tid Thread to kill.
* \todo Implement.
*
@@ -143,11 +148,11 @@ SYSCALL_DEFINE1(kill)(struct tcb *t, sys_arg_t tid)
{
struct tcb *c = get_cproc(t);
if (!(has_cap(c->caps, CAP_PROC)))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
/** @todo implement */
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
/**
@@ -157,17 +162,19 @@ SYSCALL_DEFINE1(kill)(struct tcb *t, sys_arg_t tid)
* \todo Should swap return the registers of the new thread that would be used
* for message passing?
*
+ * @param t Current tcb.
* @param tid Thread ID to swap to.
+ *
* @return \ref OK.
*/
SYSCALL_DEFINE1(swap)(struct tcb *t, sys_arg_t tid){
struct tcb *c = get_cproc(t);
if (!(has_cap(c->caps, CAP_PROC)))
- return SYS_RET1(ERR_PERM);
+ return_args(t, SYS_RET1(ERR_PERM));
struct tcb *s = get_tcb(tid);
if (!s)
- return SYS_RET1(ERR_INVAL);
+ return_args(t, SYS_RET1(ERR_INVAL));
/* switch over to new thread */
use_tcb(s);
@@ -176,5 +183,5 @@ SYSCALL_DEFINE1(swap)(struct tcb *t, sys_arg_t tid){
set_args(t, SYS_RET1(OK));
/* get register state for new thread */
- return get_args(s);
+ return_args(t, get_args(s));
}
diff --git a/common/uapi/timers.c b/common/uapi/timers.c
index b7c0ddd..929b630 100644
--- a/common/uapi/timers.c
+++ b/common/uapi/timers.c
@@ -35,18 +35,17 @@ static ticks_t scaled_ticks(sys_arg_t ticks, sys_arg_t mult)
/**
* Timebase syscall handler.
*
+ * @param t Current tcb.
* @return \ref OK and timebase in second argument if 64bit, otherwise high 32
* bits of timebase in second argument and low 32 bits in third argument.
*/
SYSCALL_DEFINE0(timebase)(struct tcb *t)
{
- UNUSED(t);
-
ticks_t tm = secs_to_ticks(1);
#if defined(_LP64)
- return SYS_RET2(OK, tm);
+ return_args(t, SYS_RET2(OK, tm));
#else
- return SYS_RET3(OK, tm >> 32, tm);
+ return_args(t, SYS_RET3(OK, tm >> 32, tm));
#endif
}
@@ -57,18 +56,17 @@ SYSCALL_DEFINE0(timebase)(struct tcb *t)
* should be preferred over this syscall on such platforms. Still, for
* completeness sake.
*
+ * @param t Current tcb.
* @return \ref OK and the current ticks when on 64bit systems, otherwise high
* 32 bits of ticks in second argument and low 32 bits in third.
*/
SYSCALL_DEFINE0(ticks)(struct tcb *t)
{
- UNUSED(t);
-
ticks_t tm = current_ticks();
#if defined(_LP64)
- return SYS_RET2(OK, tm);
+ return_args(t, SYS_RET2(OK, tm));
#else
- return SYS_RET3(OK, tm >> 32, tm);
+ return_args(t, SYS_RET3(OK, tm >> 32, tm));
#endif
}
@@ -79,18 +77,22 @@ SYSCALL_DEFINE0(ticks)(struct tcb *t)
* enough to contain essentially any timepoint we want. A couple thousand years
* when the clock runs at 5GHz, if I'm not completely mistaken.
*
+ * @param t Current tcb.
* @param ticks Number of ticks from now.
* @param mult Multiply \c ticks by this value.
* @return \ref OK and \c cid of created timer.
*/
SYSCALL_DEFINE2(req_rel_timer)(struct tcb *t, sys_arg_t ticks, sys_arg_t mult)
{
- return SYS_RET2(OK, new_rel_timer(t->tid, scaled_ticks(ticks, mult)));
+ return_args(t,
+ SYS_RET2(OK,
+ new_rel_timer(t->tid, scaled_ticks(ticks, mult))));
}
/**
* Absolute timer request syscall handler.
*
+ * @param t Current tcb.
* @param ticks Absolute timepoint relative to some start point defined at boot.
* @param mult Multiply \c ticks by this value.
* @return \ref OK and \c cid of created timer.
@@ -98,24 +100,25 @@ SYSCALL_DEFINE2(req_rel_timer)(struct tcb *t, sys_arg_t ticks, sys_arg_t mult)
*/
SYSCALL_DEFINE2(req_abs_timer)(struct tcb *t, sys_arg_t ticks, sys_arg_t mult)
{
- return SYS_RET2(OK, new_abs_timer(t->tid, scaled_ticks(ticks, mult)));
+ return_args(t,
+ SYS_RET2(OK,
+ new_abs_timer(t->tid, scaled_ticks(ticks, mult))));
}
/**
* Free timer request syscall handler.
*
+ * @param t Current tcb.
* @param cid \c cid of timer to free.
* @return \ref ERR_NF and \c 0if no timer could be found with \c cid, \ref OK
* and 0 otherwise.
*/
SYSCALL_DEFINE1(free_timer)(struct tcb *t, sys_arg_t cid)
{
- UNUSED(t);
-
struct timer *timer = find_timer(cid);
if (!timer)
- return SYS_RET1(ERR_NF);
+ return_args(t, SYS_RET1(ERR_NF));
remove_timer(timer);
- return SYS_RET1(OK);
+ return_args(t, SYS_RET1(OK));
}
diff --git a/include/apos/tcb.h b/include/apos/tcb.h
index 34b0457..c56a2b3 100644
--- a/include/apos/tcb.h
+++ b/include/apos/tcb.h
@@ -38,6 +38,10 @@
*/
#define get_proc(t) (get_tcb(t->eid))
+/**
+ * Alias for \ref get_proc(), to make it more obvious that we're accessing the
+ * effective process. Might be useful in some situations.
+ */
#define get_eproc(t) get_proc(t)
/**
diff --git a/include/apos/uapi.h b/include/apos/uapi.h
index 2d6f945..2a0dfcc 100644
--- a/include/apos/uapi.h
+++ b/include/apos/uapi.h
@@ -16,7 +16,7 @@
* Syscall function type.
* Let's start with five arguments and see where that goes
*/
-typedef struct sys_ret (*sys_t)(struct tcb *t, long, long, long, long, long);
+typedef void (*sys_t)(struct tcb *t, long, long, long, long, long);
/**
* Syscall argument type.
@@ -82,13 +82,13 @@ struct sys_ret {
*
* @param name Name of syscall.
*/
-#define SYSCALL_DECLARE0(name) \
- struct sys_ret sys_##name(struct tcb *t, \
- sys_arg_t a, \
- sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, \
- sys_arg_t e);
+#define SYSCALL_DECLARE0(name) \
+ void sys_##name(struct tcb *t, \
+ sys_arg_t a, \
+ sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, \
+ sys_arg_t e);
/**
* Helper macro for declaring syscalls with one argument.
@@ -96,10 +96,10 @@ struct sys_ret {
* @param name Name of syscall.
* @param a Name of argument.
*/
-#define SYSCALL_DECLARE1(name, a) \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e);
+#define SYSCALL_DECLARE1(name, a) \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e);
/**
* Helper macro for declaring syscalls with two arguments.
@@ -108,10 +108,10 @@ struct sys_ret {
* @param a Name of first argument.
* @param b Name of second argument.
*/
-#define SYSCALL_DECLARE2(name, a, b) \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e);
+#define SYSCALL_DECLARE2(name, a, b) \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e);
/**
* Helper macro for declaring syscalls with three arguments.
@@ -121,10 +121,10 @@ struct sys_ret {
* @param b Name of second argument.
* @param c Name of third argument.
*/
-#define SYSCALL_DECLARE3(name, a, b, c) \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e);
+#define SYSCALL_DECLARE3(name, a, b, c) \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e);
/**
* Helper macro for declaring syscalls with four arguments.
@@ -135,10 +135,10 @@ struct sys_ret {
* @param c Name of third argument.
* @param d Name of fourth argument.
*/
-#define SYSCALL_DECLARE4(name, a, b, c, d) \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e);
+#define SYSCALL_DECLARE4(name, a, b, c, d) \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e);
/**
* Helper macro for declaring syscalls with five arguments.
@@ -150,122 +150,122 @@ struct sys_ret {
* @param d Name of fourth argument.
* @param e Name of fifth argument.
*/
-#define SYSCALL_DECLARE5(name, a, b, c, d, e) \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e);
+#define SYSCALL_DECLARE5(name, a, b, c, d, e) \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e);
/**
* Helper macro for defining syscall with zero arguments.
*
* @param name Name of syscall.
*/
-#define SYSCALL_DEFINE0(name) \
- static inline struct sys_ret __##name(struct tcb *t); \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e) \
- { \
- UNUSED(a); \
- UNUSED(b); \
- UNUSED(c); \
- UNUSED(d); \
- UNUSED(e); \
- return __##name(t); \
- } \
- static struct sys_ret __##name
+#define SYSCALL_DEFINE0(name) \
+ static inline void __##name(struct tcb *t); \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e) \
+ { \
+ UNUSED(a); \
+ UNUSED(b); \
+ UNUSED(c); \
+ UNUSED(d); \
+ UNUSED(e); \
+ __##name(t); \
+ } \
+ static inline void __##name
/**
* Helper macro for defining syscall with one argument.
*
* @param name Name of syscall.
*/
-#define SYSCALL_DEFINE1(name) \
- static inline struct sys_ret __##name(struct tcb *, sys_arg_t); \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e) \
- { \
- UNUSED(b); \
- UNUSED(c); \
- UNUSED(d); \
- UNUSED(e); \
- return __##name(t, a); \
- } \
- static inline struct sys_ret __##name
+#define SYSCALL_DEFINE1(name) \
+ static inline void __##name(struct tcb *, sys_arg_t); \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e) \
+ { \
+ UNUSED(b); \
+ UNUSED(c); \
+ UNUSED(d); \
+ UNUSED(e); \
+ __##name(t, a); \
+ } \
+ static inline void __##name
/**
* Helper macro for defining syscall with two arguments.
*
* @param name Name of syscall.
*/
-#define SYSCALL_DEFINE2(name) \
- static inline struct sys_ret __##name(struct tcb *, sys_arg_t, \
- sys_arg_t); \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e) \
- { \
- UNUSED(c); \
- UNUSED(d); \
- UNUSED(e); \
- return __##name(t, a, b); \
- } \
- static inline struct sys_ret __##name
+#define SYSCALL_DEFINE2(name) \
+ static inline void __##name(struct tcb *, sys_arg_t, \
+ sys_arg_t); \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e) \
+ { \
+ UNUSED(c); \
+ UNUSED(d); \
+ UNUSED(e); \
+ __##name(t, a, b); \
+ } \
+ static inline void __##name
/**
* Helper macro for defining syscall with three arguments.
*
* @param name Name of syscall.
*/
-#define SYSCALL_DEFINE3(name) \
- static inline struct sys_ret __##name(struct tcb *, sys_arg_t, \
- sys_arg_t, \
- sys_arg_t); \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e) \
- { \
- UNUSED(d); \
- UNUSED(e); \
- return __##name(t, a, b, c); \
- } \
- static inline struct sys_ret __##name
+#define SYSCALL_DEFINE3(name) \
+ static inline void __##name(struct tcb *, sys_arg_t, \
+ sys_arg_t, \
+ sys_arg_t); \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e) \
+ { \
+ UNUSED(d); \
+ UNUSED(e); \
+ __##name(t, a, b, c); \
+ } \
+ static inline void __##name
/**
* Helper macro for defining syscall with four arguments.
*
* @param name Name of syscall.
*/
-#define SYSCALL_DEFINE4(name) \
- static inline struct sys_ret __##name(struct tcb *, sys_arg_t, \
- sys_arg_t, sys_arg_t, \
- sys_arg_t); \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e) \
- { \
- UNUSED(e); \
- return __##name(t, a, b, c, d); \
- } \
- static inline struct sys_ret __##name
+#define SYSCALL_DEFINE4(name) \
+ static inline void __##name(struct tcb *, sys_arg_t, \
+ sys_arg_t, sys_arg_t, \
+ sys_arg_t); \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e) \
+ { \
+ UNUSED(e); \
+ __##name(t, a, b, c, d); \
+ } \
+ static inline void __##name
/**
* Helper macro for defining syscall with five arguments.
*
* @param name Name of syscall.
*/
-#define SYSCALL_DEFINE5(name) \
- static inline struct sys_ret __##name(struct tcb *, sys_arg_t, \
- sys_arg_t, sys_arg_t, \
- sys_arg_t, sys_arg_t); \
- struct sys_ret sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
- sys_arg_t c, \
- sys_arg_t d, sys_arg_t e) \
- { \
- return __##name(t, a, b, c, d, e); \
- } \
- static inline struct sys_ret __##name
+#define SYSCALL_DEFINE5(name) \
+ static inline void __##name(struct tcb *, sys_arg_t, \
+ sys_arg_t, sys_arg_t, \
+ sys_arg_t, sys_arg_t); \
+ void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
+ sys_arg_t c, \
+ sys_arg_t d, sys_arg_t e) \
+ { \
+ __##name(t, a, b, c, d, e); \
+ } \
+ static void __##name
/** @name Misc syscalls. */
/** @{ */
@@ -273,24 +273,28 @@ struct sys_ret {
/**
* Noop syscall.
*
+ * @param t Current tcb.
* @param a Unused.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
*/
SYSCALL_DECLARE0(noop);
/**
* Putch syscall.
*
+ * @param t Current tcb.
* @param ch Character to put.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
*/
SYSCALL_DECLARE1(putch, ch);
@@ -304,12 +308,14 @@ SYSCALL_DECLARE1(putch, ch);
* Allocates at least the specified size of allocation to current effective
* process.
*
+ * @param t Current tcb.
* @param size Size of allocation.
* @param flags Flags of allocation.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and start of memory allocation.
+ *
+ * Returns \ref OK and start of memory allocation.
*/
SYSCALL_DECLARE2(req_mem, size, flags);
@@ -320,12 +326,14 @@ SYSCALL_DECLARE2(req_mem, size, flags);
* physical start address somewhere in the allocation to the current effective
* process.
*
+ * @param t Current tcb.
* @param paddr Start of physical allocation.
* @param size Size of physical allocation.
* @param flags Flags of physical allocation.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and start of memory allocation.
+ *
+ * Returns \ref OK and start of memory allocation.
*/
SYSCALL_DECLARE3(req_pmem, paddr, size, flags);
@@ -335,12 +343,14 @@ SYSCALL_DECLARE3(req_pmem, paddr, size, flags);
* Allocates at least the specified size of allocation which includes the start
* address of allocation to the current effective process.
*
+ * @param t Current tcb.
* @param start Start of allocation.
* @param size Size of allocation.
* @param flags Flags of allocation.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and start of memory allocation.
+ *
+ * Returns \ref OK and start of memory allocation.
*/
SYSCALL_DECLARE3(req_fixmem, start, size, flags);
@@ -352,12 +362,14 @@ SYSCALL_DECLARE3(req_fixmem, start, size, flags);
* underlying physical allocation will not be freed unless the owning reference
* (server) frees it.
*
+ * @param t Current tcb.
* @param size Size of allocation.
* @param flags Flags of allocation.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and start of memory allocation.
+ *
+ * Returns \ref OK and start of memory allocation.
*/
SYSCALL_DECLARE2(req_sharedmem, size, flags);
@@ -366,12 +378,14 @@ SYSCALL_DECLARE2(req_sharedmem, size, flags);
*
* \see sys_req_sharedmem().
*
+ * @param t Current tcb.
* @param tid Thread ID of owner of shared memory.
* @param va Start address of shared memory.
* @param flags Flags to use for reference.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and start of shared memory.
+ *
+ * Returns \ref OK and start of shared memory.
*/
SYSCALL_DECLARE3(ref_sharedmem, tid, va, flags);
@@ -380,12 +394,14 @@ SYSCALL_DECLARE3(ref_sharedmem, tid, va, flags);
*
* Frees the memory region pointed to.
*
+ * @param t Current tcb.
* @param start Start of memory.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
*/
SYSCALL_DECLARE1(free_mem, start);
/** @} */
@@ -395,12 +411,14 @@ SYSCALL_DECLARE1(free_mem, start);
/**
* Get timer accuracy in Hertz syscall.
*
+ * @param t Current tcb.
* @param a Unused.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and frequency.
+ *
+ * Returns \ref OK and frequency.
* \todo Should this be some kind of config request instead of a separate
* syscall?
*/
@@ -409,12 +427,14 @@ SYSCALL_DECLARE0(timebase);
/**
* Get current ticks.
*
+ * @param t Current tcb.
* @param a Unused.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return Current ticks.
+ *
+ * Returns current ticks.
*/
SYSCALL_DECLARE0(ticks);
@@ -423,12 +443,14 @@ SYSCALL_DECLARE0(ticks);
*
* Request timer that triggers a number of ticks in the future.
*
+ * @param t Current tcb.
* @param ticks Number of ticks from now.
* @param mult Number of times to trigger.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and ID of timer.
+ *
+ * Returns \ref OK and ID of timer.
*/
SYSCALL_DECLARE2(req_rel_timer, ticks, mult);
@@ -437,12 +459,14 @@ SYSCALL_DECLARE2(req_rel_timer, ticks, mult);
*
* Request timer that triggers at some absolute timepoint.
*
+ * @param t Current tcb.
* @param ticks Timepoint.
* @param mult Multiplier.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and ID of timer.
+ *
+ * Returns \ref OK and ID of timer.
* \todo Check repeat value.
*/
SYSCALL_DECLARE2(req_abs_timer, ticks, mult);
@@ -450,12 +474,14 @@ SYSCALL_DECLARE2(req_abs_timer, ticks, mult);
/**
* Free timer syscall.
*
+ * @param t Current tcb.
* @param cid ID of timer to free.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK.
*/
SYSCALL_DECLARE1(free_timer, cid);
/** @} */
@@ -465,24 +491,29 @@ SYSCALL_DECLARE1(free_timer, cid);
/**
* Report process status as server syscall.
*
+ * @param t Current tcb.
* @param callback Callback to request handler.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK.
*/
SYSCALL_DECLARE1(ipc_server, callback);
/**
* Request syscall.
*
+ * @param t Current tcb.
* @param pid Request target process.
* @param d0 First request argument.
* @param d1 Second request argument.
* @param d2 Third forwarding argument.
* @param d3 Fourth forwarding argument.
- * @return \c d0 and \c d1.
+ *
+ * Returns \ref OK and whatever the server sends back on success, otherwise some
+ * other status value.
*/
SYSCALL_DECLARE5(ipc_req, pid, d0, d1, d2, d3);
@@ -492,36 +523,43 @@ SYSCALL_DECLARE5(ipc_req, pid, d0, d1, d2, d3);
* In a server request handler, do a request to some other server on behalf of
* whoever called us up.
*
+ * @param t Current tcb.
* @param pid Forwarding target process.
* @param d0 First forwarding argument.
* @param d1 Second forwarding argument.
* @param d2 Third forwarding argument.
* @param d3 Fourth forwarding argument.
- * @return \c d0 and \c d1.
+ *
+ * Returns \ref OK and whatever the server sends back on success, otherwise some
+ * other status value.
*/
SYSCALL_DECLARE5(ipc_fwd, pid, d0, d1, d2, d3);
/**
* Response syscall.
*
+ * @param t Current tcb.
* @param d0 First response argument.
* @param d1 Second response argument.
* @param d2 Third response argument.
* @param d3 Fourth response argument.
* @param e Unused.
- * @return \c d0 and \c d1.
+ *
+ * Returns \c d0 and \c d1.
*/
SYSCALL_DECLARE4(ipc_resp, d0, d1, d2, d3);
/**
* Notify thread syscall.
*
+ * @param t Current tcb.
* @param tid Thread ID to notify.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
*/
SYSCALL_DECLARE1(ipc_notify, tid);
/** @} */
@@ -533,13 +571,14 @@ SYSCALL_DECLARE1(ipc_notify, tid);
*
* Creates thread in current effective process context.
*
+ * @param t Current tcb.
* @param func Function to call on startup.
* @param d0 Argument 0.
* @param d1 Argument 1.
* @param d2 Argument 2.
* @param d3 Argument 3.
*
- * @return \ref OK and 0.
+ * Returns \ref OK and 0.
* \todo Should this take stack size etc?
*/
SYSCALL_DECLARE5(create, func, d0, d1, d2, d3);
@@ -549,12 +588,14 @@ SYSCALL_DECLARE5(create, func, d0, d1, d2, d3);
*
* Forks a process, much like in *nix systems.
*
+ * @param t Current tcb.
* @param a Unused.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
*/
SYSCALL_DECLARE0(fork);
@@ -563,12 +604,14 @@ SYSCALL_DECLARE0(fork);
*
* Executes a new binary in existing process space.
*
+ * @param t Current tcb.
* @param bin Address of binary.
* @param interp Optional address of interpreter.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
* \todo Check other return codes.
*/
SYSCALL_DECLARE2(exec, bin, interp);
@@ -578,12 +621,14 @@ SYSCALL_DECLARE2(exec, bin, interp);
*
* Executes a new binary in new process space.
*
+ * @param t Current tcb.
* @param bin Address of binary.
* @param interp Optional address of interpreter.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Retuns \ref OK and 0.
* \todo Check other return codes.
*/
SYSCALL_DECLARE2(spawn, bin, interp);
@@ -591,12 +636,14 @@ SYSCALL_DECLARE2(spawn, bin, interp);
/**
* Kill syscall.
*
+ * @param t Current tcb.
* @param tid Thread ID to kill. 0 if self.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return No.
+ *
+ * Returns \ref OK if not called on itself, otherwise doesn't return.
*/
SYSCALL_DECLARE1(kill, tid);
@@ -605,12 +652,14 @@ SYSCALL_DECLARE1(kill, tid);
*
* Swap currently running thread.
*
+ * @param t Current tcb.
* @param tid Thread to swap to.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
*/
SYSCALL_DECLARE1(swap, tid);
@@ -623,12 +672,14 @@ SYSCALL_DECLARE1(swap, tid);
*
* Set some runtime parameter.
*
+ * @param t Current tcb.
* @param param Parameter to set.
* @param val Value to set parameter to.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ *
+ * Returns \ref OK and 0.
*/
SYSCALL_DECLARE2(conf_set, param, val);
@@ -637,48 +688,56 @@ SYSCALL_DECLARE2(conf_set, param, val);
*
* Get some runtime parameter.
*
+ * @param t Current tcb.
* @param param Parameter to get.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK.
+ *
+ * Returns \ref OK.
*/
SYSCALL_DECLARE1(conf_get, param);
/**
* Set capabilities.
*
+ * @param t Current tcb.
* @param tid Thread ID whose capabilities to set.
* @param off Offset of capability, multiple of \c bits(cap).
* @param caps Mask of capabilities to set.
* @param d Unused.
* @param e Unused.
- * @return \ref OK on success, \ref ERR_INVAL on invalid input.
+ *
+ * Returns \ref OK on success, \ref ERR_INVAL on invalid input.
*/
SYSCALL_DECLARE3(set_cap, tid, off, caps);
/**
* Get capabilities.
*
+ * @param t Current tcb.
* @param tid Thread ID whose capabilities to get.
* @param off Offset of capability, multiple of \c bits(cap).
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK, capabilities.
+ *
+ * Returns \ref OK, capabilities.
*/
SYSCALL_DECLARE2(get_cap, tid, off);
/**
* Clear capabilities.
*
+ * @param t Current tcb.
* @param tid Thread ID whose capabilities to clear.
* @param off Offset of capability, multiple of \c bits(cap).
* @param cap Mask of capabilities to clear.
* @param d Unused.
* @param e Unused.
- * @return \ref OK.
+ *
+ * Returns \ref OK.
*/
SYSCALL_DECLARE3(clear_cap, tid, off, cap);
@@ -687,12 +746,14 @@ SYSCALL_DECLARE3(clear_cap, tid, off, cap);
*
* Either shut down or reboot system.
*
+ * @param t Current tcb.
* @param type Type of shutdown. \see poweroff_type.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return Shouldn't return at all.
+ *
+ * Shouldn't return at all.
*/
SYSCALL_DECLARE1(poweroff, type);
/** @} */
@@ -700,19 +761,22 @@ SYSCALL_DECLARE1(poweroff, type);
/**
* Dispatch to correct syscall handler.
*
- * @param t Thread to do syscall on.
* @param syscall Syscall number.
* @param a Syscall argument 0.
* @param b Syscall argument 1.
* @param c Syscall argument 2.
* @param d Syscall argument 3.
* @param e Syscall argument 4.
- * @return Whatever the specified syscall returns.
+ * @param t Current tcb.
+ * Returns whatever the specified syscall returns.
*/
-struct sys_ret handle_syscall(struct tcb *t,
- sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
- sys_arg_t c, sys_arg_t d, sys_arg_t e);
+void handle_syscall(sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
+ sys_arg_t c, sys_arg_t d, sys_arg_t e, struct tcb *t);
/** \todo Should I add variable names as well, to make the documentation a bit
* more readable? */
+
+#include <arch/proc.h>
+#define return_args(t, x) {set_args((t), (x)); return;}
+
#endif /* APOS_UAPI_H */