diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-09 22:12:27 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-09 22:12:27 +0300 |
| commit | e8a1df103cc28419dd7d4439c0b1d1739d110f78 (patch) | |
| tree | 2b4646f262a9008d80ca58fb2ecab2b5bf897873 /src/uapi/cap.c | |
| parent | 89d7cf197b2cae130565467bdfad5d5ef5fed2dd (diff) | |
| download | kmi-e8a1df103cc28419dd7d4439c0b1d1739d110f78.tar.gz kmi-e8a1df103cc28419dd7d4439c0b1d1739d110f78.zip | |
start working on tests
+ Current setup will likely not last long, just a stopgap until I figure
out how I want to build each testcase etc.
Probably dir based, but I'll probably add some scripts that generate
the build rules for each test case (or binary?). Also, should probably
put ouput files in a build directory and keep the source clean, but
again, good enough for now.
Will have to start implementing more extensive tests, and probably
come up with some way to compare textual output etc.
Diffstat (limited to 'src/uapi/cap.c')
| -rw-r--r-- | src/uapi/cap.c | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/src/uapi/cap.c b/src/uapi/cap.c index 157ef47..050d181 100644 --- a/src/uapi/cap.c +++ b/src/uapi/cap.c @@ -11,25 +11,6 @@ */ /** - * Check that values are legal for thread ID and offset. - * - * @param tid Thread ID of thread whose caps should be fetched. - * @param off Offset of capabilities. - * @return Pointer to capabilities of \p tid, \c 0 otherwise. - */ -static capflags_t *__get_tcb_caps(id_t tid, size_t off) -{ - if (!cap_off_ok(off)) - return NULL; - - struct tcb *t = get_tcb(tid); - if (!t) - return NULL; - - return &t->caps; -} - -/** * Set capabilities. * * @param t Current tcb. @@ -38,17 +19,16 @@ static capflags_t *__get_tcb_caps(id_t tid, size_t off) * @param caps Mask of capabilities to set. * @return \ref OK on success, \ref ERR_INVAL on invalid input. */ -SYSCALL_DEFINE3(set_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t off, - sys_arg_t caps) +SYSCALL_DEFINE2(set_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t caps) { if (!is_set(t->caps, CAP_CAPS)) return_args1(t, ERR_PERM); - capflags_t *c; - if (!(c = __get_tcb_caps(tid, off))) - return_args1(t, ERR_INVAL); + struct tcb *c = get_tcb(tid); + if (!c) + return_args1(t, ERR_NF); - set_caps(*c, off, caps); + set_caps(c->caps, caps); return_args1(t, OK); } @@ -60,13 +40,13 @@ SYSCALL_DEFINE3(set_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t off, * @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) +SYSCALL_DEFINE1(get_cap)(struct tcb *t, sys_arg_t tid) { - capflags_t *c; - if (!(c = __get_tcb_caps(tid, off))) - return_args1(t, ERR_INVAL); + struct tcb *c = get_tcb(tid); + if (!c) + return_args1(t, ERR_NF); - return_args2(t, OK, get_caps(*c, off)); + return_args2(t, OK, c->caps); } /** @@ -74,21 +54,19 @@ SYSCALL_DEFINE2(get_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t off) * * @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. * @return ERR_LERM if invalid permissions, ERR_INVAL if \p tid doesn't exist, * otherwise OK. */ -SYSCALL_DEFINE3(clear_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t off, - sys_arg_t caps) +SYSCALL_DEFINE2(clear_cap)(struct tcb *t, sys_arg_t tid, sys_arg_t caps) { if (!is_set(t->caps, CAP_CAPS)) return_args1(t, ERR_PERM); - capflags_t *c; - if (!(c = __get_tcb_caps(tid, off))) - return_args1(t, ERR_INVAL); + struct tcb *c = get_tcb(tid); + if (!c) + return_args1(t, ERR_NF); - clear_caps(*c, off, caps); + clear_caps(c->caps, caps); return_args1(t, OK); } |
