diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/handle.c | 2 | ||||
-rw-r--r-- | src/kernel/handle.h | 3 | ||||
-rw-r--r-- | src/kernel/proc.c | 9 | ||||
-rw-r--r-- | src/kernel/proc.h | 1 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 43 | ||||
-rw-r--r-- | src/kernel/vfs/request.c | 9 | ||||
-rw-r--r-- | src/shared/include/camellia/syscalls.h | 6 | ||||
-rw-r--r-- | src/user/app/init/driver/initctl.c | 9 | ||||
-rw-r--r-- | src/user/app/init/driver/ps2.c | 9 | ||||
-rw-r--r-- | src/user/app/login/login.c | 9 | ||||
-rw-r--r-- | src/user/app/tests/kernel/path.c | 7 | ||||
-rw-r--r-- | src/user/app/tmpfs/tmpfs.c | 27 | ||||
-rw-r--r-- | src/user/app/vterm/vterm.c | 11 | ||||
-rw-r--r-- | src/user/bootstrap/tar.c | 17 | ||||
-rw-r--r-- | src/user/lib/compat.c | 20 | ||||
-rw-r--r-- | src/user/lib/compat.h | 6 | ||||
-rw-r--r-- | src/user/lib/fs/misc.c | 45 | ||||
-rw-r--r-- | src/user/lib/syscall.c | 8 |
18 files changed, 136 insertions, 105 deletions
diff --git a/src/kernel/handle.c b/src/kernel/handle.c index d95962c..b21ebdc 100644 --- a/src/kernel/handle.c +++ b/src/kernel/handle.c @@ -31,6 +31,8 @@ void handle_close(struct handle *h) { pipe_invalidate_end(h->pipe.sister); h->pipe.sister->pipe.sister = NULL; } + } else if (h->type == HANDLE_FS_REQ) { + if (h->req) vfsreq_finish_short(h->req, -1); } if (h->backend) diff --git a/src/kernel/handle.h b/src/kernel/handle.h index 54ef412..6b095e5 100644 --- a/src/kernel/handle.h +++ b/src/kernel/handle.h @@ -4,6 +4,7 @@ enum handle_type; // forward declaration for proc.h #include <camellia/types.h> #include <kernel/vfs/mount.h> +#include <kernel/vfs/request.h> #include <stddef.h> enum handle_type { @@ -11,6 +12,7 @@ enum handle_type { HANDLE_FILE, HANDLE_PIPE, HANDLE_FS_FRONT, + HANDLE_FS_REQ, }; struct handle { @@ -18,6 +20,7 @@ struct handle { struct vfs_backend *backend; // HANDLE_FILE | HANDLE_FS_FRONT void __user *file_id; // only applicable to HANDLE_FILE bool ro; /* currently only for HANDLE_FILE */ + struct vfs_request *req; /* HANDLE_FS_REQ */ struct { struct process *queued; bool write_end; diff --git a/src/kernel/proc.c b/src/kernel/proc.c index ebd7cce..ed7180b 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -74,10 +74,6 @@ struct process *process_fork(struct process *parent, int flags) { child->id = next_pid++; - // TODO control this with a flag - child->handled_req = parent->handled_req; - parent->handled_req = NULL; - if ((flags & FORK_NEWFS) == 0 && parent->controlled) { child->controlled = parent->controlled; child->controlled->potential_handlers++; @@ -122,11 +118,6 @@ static bool unref(uint64_t *refcount) { void process_kill(struct process *p, int ret) { if (p->state != PS_DEAD) { - if (p->handled_req) { - vfsreq_finish_short(p->handled_req, -1); - p->handled_req = NULL; - } - if (p->controlled) { // TODO vfs_backend_user_handlerdown assert(p->controlled->potential_handlers > 0); diff --git a/src/kernel/proc.h b/src/kernel/proc.h index f445eab..780c8ee 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -59,7 +59,6 @@ struct process { /* vfs_backend controlled (not exclusively) by this process */ struct vfs_backend *controlled; - struct vfs_request *handled_req; struct { void *buf; diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index d6b23d0..33f56cd 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -259,7 +259,7 @@ long _syscall_close(handle_t hid) { SYSCALL_RETURN(0); } -long _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res) { +handle_t _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res) { struct vfs_backend *backend = process_current->controlled; // TODO can be used to tell if you're init if (!backend) SYSCALL_RETURN(-1); @@ -276,25 +276,28 @@ long _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __ return -1; // dummy } -long _syscall_fs_respond(void __user *buf, long ret, int flags) { - struct vfs_request *req = process_current->handled_req; - if (!req) SYSCALL_RETURN(-1); - - if (req->output.len > 0 && ret > 0) { - // if this vfsop outputs data and ret is positive, it's the length of the buffer - // TODO document - ret = min(ret, capped_cast32(req->output.len)); - struct virt_cpy_error err; - virt_cpy(req->caller->pages, req->output.buf, - process_current->pages, buf, ret, &err); - - if (err.read_fail) - panic_unimplemented(); - /* write failures are ignored */ +long _syscall_fs_respond(handle_t hid, void __user *buf, long ret, int flags) { + struct handle *h = process_handle_get(process_current, hid); + if (!h || h->type != HANDLE_FS_REQ) SYSCALL_RETURN(-EBADF); + struct vfs_request *req = h->req; + if (req) { + if (req->output.len > 0 && ret > 0) { + // if this vfsop outputs data and ret is positive, it's the length of the buffer + // TODO document + // TODO move to vfsreq_finish + ret = min(ret, capped_cast32(req->output.len)); + struct virt_cpy_error err; + virt_cpy(req->caller->pages, req->output.buf, + process_current->pages, buf, ret, &err); + + if (err.read_fail) + panic_unimplemented(); + /* write failures are ignored */ + } + vfsreq_finish(req, buf, ret, flags, process_current); } - - process_current->handled_req = NULL; - vfsreq_finish(req, buf, ret, flags, process_current); + h->req = NULL; + process_handle_close(process_current, hid); SYSCALL_RETURN(0); } @@ -400,7 +403,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) { break; case _SYSCALL_REMOVE: _syscall_remove(a); break; case _SYSCALL_CLOSE: _syscall_close(a); break; case _SYSCALL_FS_WAIT: _syscall_fs_wait((userptr_t)a, b, (userptr_t)c); - break; case _SYSCALL_FS_RESPOND: _syscall_fs_respond((userptr_t)a, b, c); + break; case _SYSCALL_FS_RESPOND: _syscall_fs_respond(a, (userptr_t)b, c, d); break; case _SYSCALL_MEMFLAG: _syscall_memflag((userptr_t)a, b, c); break; case _SYSCALL_PIPE: _syscall_pipe((userptr_t)a, b); break; case _SYSCALL_SLEEP: _syscall_sleep(a); diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index a3be057..959b051 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -99,8 +99,6 @@ void vfs_backend_user_accept(struct vfs_request *req) { assert(req && req->backend && req->backend->user.handler); handler = req->backend->user.handler; assert(handler->state == PS_WAITS4REQUEST); - if (handler->handled_req) - panic_unimplemented(); // the virt_cpy calls aren't present in all kernel backends // it's a way to tell apart kernel and user backends apart @@ -134,10 +132,13 @@ void vfs_backend_user_accept(struct vfs_request *req) { panic_unimplemented(); } + struct handle *h; + handle_t hid = process_handle_init(handler, HANDLE_FS_REQ, &h); + if (hid < 0) panic_unimplemented(); + h->req = req; process_transition(handler, PS_RUNNING); - handler->handled_req = req; + regs_savereturn(&handler->regs, hid); req->backend->user.handler = NULL; - regs_savereturn(&handler->regs, 0); return; } diff --git a/src/shared/include/camellia/syscalls.h b/src/shared/include/camellia/syscalls.h index 50fd5c8..dfc964f 100644 --- a/src/shared/include/camellia/syscalls.h +++ b/src/shared/include/camellia/syscalls.h @@ -62,10 +62,8 @@ long _syscall_getsize(handle_t h); long _syscall_remove(handle_t h); long _syscall_close(handle_t h); -/** Blocks until an fs request is made. - * @return 0 if everything was successful */ -long _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res); -long _syscall_fs_respond(void __user *buf, long ret, int flags); +handle_t _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res); +long _syscall_fs_respond(handle_t hid, void __user *buf, long ret, int flags); /** Modifies the virtual address space. * diff --git a/src/user/app/init/driver/initctl.c b/src/user/app/init/driver/initctl.c index c31e8fb..34171de 100644 --- a/src/user/app/init/driver/initctl.c +++ b/src/user/app/init/driver/initctl.c @@ -4,15 +4,16 @@ #include <errno.h> #include <string.h> #include <unistd.h> +#include <user/lib/compat.h> void initctl_drv(handle_t killswitch) { struct fs_wait_response res; char buf[64]; const size_t buflen = sizeof buf; - while (!_syscall_fs_wait(buf, buflen, &res)) { + while (!c0_fs_wait(buf, buflen, &res)) { switch (res.op) { case VFSOP_OPEN: - _syscall_fs_respond(NULL, res.len == 0 ? 0 : -1, 0); + c0_fs_respond(NULL, res.len == 0 ? 0 : -1, 0); break; case VFSOP_WRITE: /* null terminate */ @@ -30,10 +31,10 @@ void initctl_drv(handle_t killswitch) { _syscall_write(killswitch, "halt", 4, 0, 0); exit(1); } - _syscall_fs_respond(NULL, res.len, 0); + c0_fs_respond(NULL, res.len, 0); break; default: - _syscall_fs_respond(NULL, -ENOSYS, 0); + c0_fs_respond(NULL, -ENOSYS, 0); break; } } diff --git a/src/user/app/init/driver/ps2.c b/src/user/app/init/driver/ps2.c index 7653f83..961ea53 100644 --- a/src/user/app/init/driver/ps2.c +++ b/src/user/app/init/driver/ps2.c @@ -3,6 +3,7 @@ #include <shared/container/ring.h> #include <stdbool.h> #include <unistd.h> +#include <user/lib/compat.h> static const char keymap_lower[] = { @@ -53,10 +54,10 @@ static void main_loop(void) { static char buf[512]; struct fs_wait_response res; int ret; - while (!_syscall_fs_wait(buf, sizeof buf, &res)) { + while (!c0_fs_wait(buf, sizeof buf, &res)) { switch (res.op) { case VFSOP_OPEN: - _syscall_fs_respond(NULL, 1, 0); + c0_fs_respond(NULL, 1, 0); break; case VFSOP_READ: @@ -68,11 +69,11 @@ static void main_loop(void) { parse_scancode(buf[i]); } ret = ring_get((void*)&backlog, buf, res.capacity); - _syscall_fs_respond(buf, ret, 0); + c0_fs_respond(buf, ret, 0); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } diff --git a/src/user/app/login/login.c b/src/user/app/login/login.c index 241bcfe..9f8ba6d 100644 --- a/src/user/app/login/login.c +++ b/src/user/app/login/login.c @@ -6,6 +6,7 @@ #include <stdio.h> #include <string.h> #include <unistd.h> +#include <user/lib/compat.h> #include <user/lib/fs/misc.h> static const char *shell = "/bin/shell"; @@ -39,12 +40,12 @@ static void drv(const char *prefix) { struct fs_wait_response res; size_t prefixlen = strlen(prefix); char buf[128]; - while (!_syscall_fs_wait(buf, sizeof buf, &res)) { + while (!c0_fs_wait(buf, sizeof buf, &res)) { switch (res.op) { handle_t h; case VFSOP_OPEN: if (res.len == sizeof buf) { - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } buf[res.len] = '\0'; @@ -56,11 +57,11 @@ static void drv(const char *prefix) { } else { h = -EACCES; } - _syscall_fs_respond(NULL, h, FSR_DELEGATE); + c0_fs_respond(NULL, h, FSR_DELEGATE); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } diff --git a/src/user/app/tests/kernel/path.c b/src/user/app/tests/kernel/path.c index e25154d..5fb3123 100644 --- a/src/user/app/tests/kernel/path.c +++ b/src/user/app/tests/kernel/path.c @@ -1,6 +1,7 @@ #include "../tests.h" #include <camellia/path.h> #include <string.h> +#include <user/lib/compat.h> #include <user/lib/fs/misc.h> static void test_path_simplify(void) { @@ -66,9 +67,9 @@ static void mount_resolve_drv(const char *path) { if (fork2_n_mount(path)) return; struct fs_wait_response res; - while (!_syscall_fs_wait(NULL, 0, &res)) { - // TODO does the first argument of _syscall_fs_respond need to be non-const? - _syscall_fs_respond((void*)path, strlen(path), 0); + while (!c0_fs_wait(NULL, 0, &res)) { + // TODO does the first argument of c0_fs_respond need to be non-const? + c0_fs_respond((void*)path, strlen(path), 0); } exit(1); } diff --git a/src/user/app/tmpfs/tmpfs.c b/src/user/app/tmpfs/tmpfs.c index 401bab3..606d682 100644 --- a/src/user/app/tmpfs/tmpfs.c +++ b/src/user/app/tmpfs/tmpfs.c @@ -7,6 +7,7 @@ #include <stddef.h> #include <stdlib.h> #include <unistd.h> +#include <user/lib/compat.h> #include <user/lib/fs/dir.h> struct node { @@ -103,11 +104,11 @@ int main(void) { char *buf = malloc(buflen); struct fs_wait_response res; struct node *ptr; - while (!_syscall_fs_wait(buf, buflen, &res)) { + while (!c0_fs_wait(buf, buflen, &res)) { switch (res.op) { case VFSOP_OPEN: ptr = tmpfs_open(buf, &res); - _syscall_fs_respond(ptr, ptr ? 0 : -1, 0); + c0_fs_respond(ptr, ptr ? 0 : -1, 0); break; case VFSOP_READ: @@ -117,23 +118,23 @@ int main(void) { dir_start(&db, res.offset, buf, buflen); for (struct node *iter = ptr->child; iter; iter = iter->sibling) dir_append(&db, iter->name); - _syscall_fs_respond(buf, dir_finish(&db), 0); + c0_fs_respond(buf, dir_finish(&db), 0); } else { fs_normslice(&res.offset, &res.len, ptr->size, false); - _syscall_fs_respond(ptr->buf + res.offset, res.len, 0); + c0_fs_respond(ptr->buf + res.offset, res.len, 0); } break; case VFSOP_WRITE: ptr = (void*)res.id; if (ptr == &special_root) { - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } if (res.len > 0 && !ptr->buf) { ptr->buf = malloc(256); if (!ptr->buf) { - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } memset(ptr->buf, 0, 256); @@ -146,7 +147,7 @@ int main(void) { while (newcap && newcap <= res.offset + res.len) newcap *= 2; if (!newcap) { /* overflow */ - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } ptr->capacity = newcap; @@ -157,7 +158,7 @@ int main(void) { if ((res.flags & WRITE_TRUNCATE) || ptr->size < res.offset + res.len) { ptr->size = res.offset + res.len; } - _syscall_fs_respond(NULL, res.len, 0); + c0_fs_respond(NULL, res.len, 0); break; case VFSOP_GETSIZE: @@ -168,25 +169,25 @@ int main(void) { dir_start(&db, res.offset, NULL, buflen); for (struct node *iter = ptr->child; iter; iter = iter->sibling) dir_append(&db, iter->name); - _syscall_fs_respond(NULL, dir_finish(&db), 0); + c0_fs_respond(NULL, dir_finish(&db), 0); } else { - _syscall_fs_respond(NULL, ptr->size, 0); + c0_fs_respond(NULL, ptr->size, 0); } break; case VFSOP_REMOVE: ptr = (void*)res.id; - _syscall_fs_respond(NULL, remove_node(ptr), 0); + c0_fs_respond(NULL, remove_node(ptr), 0); break; case VFSOP_CLOSE: ptr = (void*)res.id; handle_down(ptr); - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } diff --git a/src/user/app/vterm/vterm.c b/src/user/app/vterm/vterm.c index 7ae24c2..102513d 100644 --- a/src/user/app/vterm/vterm.c +++ b/src/user/app/vterm/vterm.c @@ -5,6 +5,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <user/lib/compat.h> struct point cursor = {0}; @@ -38,26 +39,26 @@ int main(void) { static char buf[512]; struct fs_wait_response res; - while (!_syscall_fs_wait(buf, sizeof buf, &res)) { + while (!c0_fs_wait(buf, sizeof buf, &res)) { switch (res.op) { case VFSOP_OPEN: // TODO check path - _syscall_fs_respond(NULL, 0, 0); + c0_fs_respond(NULL, 0, 0); break; case VFSOP_WRITE: if (res.flags) { - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); } else { for (size_t i = 0; i < res.len; i++) in_char(buf[i]); dirty_flush(&dirty, &fb); - _syscall_fs_respond(NULL, res.len, 0); + c0_fs_respond(NULL, res.len, 0); } break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } diff --git a/src/user/bootstrap/tar.c b/src/user/bootstrap/tar.c index 10c3701..0a6a8a9 100644 --- a/src/user/bootstrap/tar.c +++ b/src/user/bootstrap/tar.c @@ -6,6 +6,7 @@ #include <stdint.h> #include <string.h> #include <unistd.h> +#include <user/lib/compat.h> #include <user/lib/fs/dir.h> #define BUF_SIZE 64 @@ -25,11 +26,11 @@ void tar_driver(void *base) { static char buf[BUF_SIZE]; struct fs_wait_response res; void *ptr; - while (!_syscall_fs_wait(buf, BUF_SIZE, &res)) { + while (!c0_fs_wait(buf, BUF_SIZE, &res)) { switch (res.op) { case VFSOP_OPEN: ptr = tar_open(buf, res.len, base, ~0); - _syscall_fs_respond(ptr, ptr ? 0 : -1, 0); + c0_fs_respond(ptr, ptr ? 0 : -1, 0); break; case VFSOP_READ: @@ -38,17 +39,17 @@ void tar_driver(void *base) { case VFSOP_GETSIZE: if (tar_type(res.id) != '5') { - _syscall_fs_respond(NULL, tar_size(res.id), 0); + c0_fs_respond(NULL, tar_size(res.id), 0); } else { struct dirbuild db; dir_start(&db, res.offset, NULL, 0); tar_dirbuild(&db, res.id, base, ~0); - _syscall_fs_respond(NULL, dir_finish(&db), 0); + c0_fs_respond(NULL, dir_finish(&db), 0); } break; default: - _syscall_fs_respond(NULL, -1, 0); // unsupported + c0_fs_respond(NULL, -1, 0); // unsupported break; } } @@ -107,18 +108,18 @@ static void tar_read(struct fs_wait_response *res, void *base, size_t base_len) case '\0': case '0': /* normal files */ fs_normslice(&res->offset, &res->len, tar_size(meta), false); - _syscall_fs_respond(meta + 512 + res->offset, res->len, 0); + c0_fs_respond(meta + 512 + res->offset, res->len, 0); break; case '5': /* directory */ struct dirbuild db; dir_start(&db, res->offset, buf, sizeof buf); tar_dirbuild(&db, meta, base, base_len); - _syscall_fs_respond(buf, dir_finish(&db), 0); + c0_fs_respond(buf, dir_finish(&db), 0); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } diff --git a/src/user/lib/compat.c b/src/user/lib/compat.c new file mode 100644 index 0000000..cadc77f --- /dev/null +++ b/src/user/lib/compat.c @@ -0,0 +1,20 @@ +#include <camellia/syscalls.h> +#include <stdio.h> +#include <user/lib/compat.h> + +#define eprintf(fmt, ...) fprintf(stderr, "user/lib/compat: "fmt"\n" __VA_OPT__(,) __VA_ARGS__) + +static handle_t h = -1; +long c0_fs_wait(char *buf, long len, struct fs_wait_response *res) { + if (h != -1) { + eprintf("didn't respond to request!"); + c0_fs_respond(NULL, -1, 0); + } + h = _syscall_fs_wait(buf, len, res); + return h >= 0 ? 0 : -1; +} +long c0_fs_respond(void *buf, long ret, int flags) { + ret = _syscall_fs_respond(h, buf, ret, flags); + h = -1; + return ret; +} diff --git a/src/user/lib/compat.h b/src/user/lib/compat.h new file mode 100644 index 0000000..b678cf5 --- /dev/null +++ b/src/user/lib/compat.h @@ -0,0 +1,6 @@ +#pragma once +#include <camellia/types.h> + +/* c0 - fs_wait returning a handle */ +long c0_fs_wait(char *buf, long len, struct fs_wait_response *res); +long c0_fs_respond(void *buf, long ret, int flags); diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c index 038cd3b..d130901 100644 --- a/src/user/lib/fs/misc.c +++ b/src/user/lib/fs/misc.c @@ -6,6 +6,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <user/lib/compat.h> #include <user/lib/fs/dir.h> #include <user/lib/fs/misc.h> @@ -41,12 +42,12 @@ void fs_passthru(const char *prefix) { int prefix_len = prefix ? strlen(prefix) : 0; if (!buf) exit(1); - while (!_syscall_fs_wait(buf, buf_len, &res)) { + while (!c0_fs_wait(buf, buf_len, &res)) { switch (res.op) { case VFSOP_OPEN: if (prefix) { if (prefix_len + res.len > buf_len) { - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } @@ -57,11 +58,11 @@ void fs_passthru(const char *prefix) { memcpy(buf, prefix, prefix_len); res.len += prefix_len; } - _syscall_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE); + c0_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } @@ -77,7 +78,7 @@ void fs_whitelist(const char **list) { struct dirbuild db; if (!buf) exit(1); - while (!_syscall_fs_wait(buf, buf_len, &res)) { + while (!c0_fs_wait(buf, buf_len, &res)) { size_t blen; ipath = res.id; switch (res.op) { @@ -103,15 +104,15 @@ void fs_whitelist(const char **list) { } } if (passthru) { - _syscall_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE); + c0_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE); } else if (inject) { // TODO all the inject points could be precomputed ipath = malloc(res.len + 1); memcpy(ipath, buf, res.len); ipath[res.len] = '\0'; - _syscall_fs_respond(ipath, 0, 0); + c0_fs_respond(ipath, 0, 0); } else { - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); } break; @@ -126,16 +127,16 @@ void fs_whitelist(const char **list) { if (blen < len && !memcmp(ipath, *iter, blen)) dir_appendl(&db, *iter + blen, dir_seglen(*iter + blen)); } - _syscall_fs_respond(target, dir_finish(&db), 0); + c0_fs_respond(target, dir_finish(&db), 0); break; case VFSOP_CLOSE: free(ipath); - _syscall_fs_respond(NULL, 0, 0); + c0_fs_respond(NULL, 0, 0); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } @@ -157,11 +158,11 @@ void fs_union(const char **list) { struct dirbuild db; if (!pre) exit(1); - while (!_syscall_fs_wait(post, postlen, &res)) { + while (!c0_fs_wait(post, postlen, &res)) { switch (res.op) { case VFSOP_OPEN: if (res.len == 1) { /* root directory */ - _syscall_fs_respond(NULL, 0, 0); + c0_fs_respond(NULL, 0, 0); break; } @@ -178,7 +179,7 @@ void fs_union(const char **list) { post[res.len] = '\0'; } if (ret < 0) ret = -1; - _syscall_fs_respond(NULL, ret, FSR_DELEGATE); + c0_fs_respond(NULL, ret, FSR_DELEGATE); break; case VFSOP_READ: @@ -198,11 +199,11 @@ void fs_union(const char **list) { end = end || dir_append_from(&db, h); _syscall_close(h); } - _syscall_fs_respond(target, dir_finish(&db), 0); + c0_fs_respond(target, dir_finish(&db), 0); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } @@ -225,7 +226,7 @@ void fs_dir_inject(const char *path) { if (!buf) exit(1); - while (!_syscall_fs_wait(buf, buf_len, &res)) { + while (!c0_fs_wait(buf, buf_len, &res)) { data = res.id; switch (res.op) { case VFSOP_OPEN: @@ -237,9 +238,9 @@ void fs_dir_inject(const char *path) { data->delegate = _syscall_open(buf, res.len, res.flags); data->inject = path + res.len; data->inject_len = dir_seglen(data->inject); - _syscall_fs_respond(data, 0, 0); + c0_fs_respond(data, 0, 0); } else { - _syscall_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE); + c0_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE); } break; @@ -247,7 +248,7 @@ void fs_dir_inject(const char *path) { if (data->delegate >= 0) close(data->delegate); free(data); - _syscall_fs_respond(NULL, 0, 0); + c0_fs_respond(NULL, 0, 0); break; case VFSOP_READ: @@ -259,11 +260,11 @@ void fs_dir_inject(const char *path) { dir_appendl(&db, data->inject, data->inject_len); if (data->delegate >= 0) dir_append_from(&db, data->delegate); - _syscall_fs_respond(target, dir_finish(&db), 0); + c0_fs_respond(target, dir_finish(&db), 0); break; default: - _syscall_fs_respond(NULL, -1, 0); + c0_fs_respond(NULL, -1, 0); break; } } diff --git a/src/user/lib/syscall.c b/src/user/lib/syscall.c index 1635636..d001990 100644 --- a/src/user/lib/syscall.c +++ b/src/user/lib/syscall.c @@ -50,12 +50,12 @@ long _syscall_close(handle_t h) { return _syscall(_SYSCALL_CLOSE, (long)h, 0, 0, 0, 0); } -long _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res) { - return _syscall(_SYSCALL_FS_WAIT, (long)buf, max_len, (long)res, 0, 0); +handle_t _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res) { + return (handle_t)_syscall(_SYSCALL_FS_WAIT, (long)buf, max_len, (long)res, 0, 0); } -long _syscall_fs_respond(void __user *buf, long ret, int flags) { - return _syscall(_SYSCALL_FS_RESPOND, (long)buf, ret, (long)flags, 0, 0); +long _syscall_fs_respond(handle_t hid, void __user *buf, long ret, int flags) { + return _syscall(_SYSCALL_FS_RESPOND, (long)hid, (long)buf, ret, (long)flags, 0); } void __user *_syscall_memflag(void __user *addr, size_t len, int flags) { |