From 9900cc737988f25db30b5876f066a78e73389205 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 5 May 2022 22:12:55 +0200 Subject: kernel: syscalls now have to explicitly save the return value thus they can opt out of doing that so the calls which might return immediately but can return later don't have to both regs_savereturn and return to the caller. and because of that, the return values of a lot of VFS things have just got way saner --- src/kernel/vfs/request.c | 26 +++++++++++++------------- src/kernel/vfs/request.h | 17 ++++++----------- src/kernel/vfs/root.c | 8 +++----- src/kernel/vfs/root.h | 2 +- 4 files changed, 23 insertions(+), 30 deletions(-) (limited to 'src/kernel/vfs') diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index f463b86..3e7c9f0 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -6,7 +6,7 @@ #include #include -int vfsreq_create(struct vfs_request req_) { +void vfsreq_create(struct vfs_request req_) { struct vfs_request *req = kmalloc(sizeof *req); // freed in vfsreq_finish memcpy(req, &req_, sizeof *req); @@ -19,17 +19,17 @@ int vfsreq_create(struct vfs_request req_) { } if (!req->backend || !req->backend->potential_handlers) - return vfsreq_finish(req, -1); + vfsreq_finish(req, -1); struct vfs_request **iter = &req->backend->queue; while (*iter != NULL) // find free spot in queue iter = &(*iter)->queue_next; *iter = req; - return vfs_backend_tryaccept(req->backend); + vfs_backend_tryaccept(req->backend); } -int vfsreq_finish(struct vfs_request *req, int ret) { +void vfsreq_finish(struct vfs_request *req, int ret) { if (req->type == VFSOP_OPEN && ret >= 0) { // open() calls need special handling // we need to wrap the id returned by the VFS in a handle passed to @@ -63,32 +63,32 @@ int vfsreq_finish(struct vfs_request *req, int ret) { vfs_backend_refdown(req->backend); kfree(req); - return ret; + return; } -int vfs_backend_tryaccept(struct vfs_backend *backend) { +void vfs_backend_tryaccept(struct vfs_backend *backend) { struct vfs_request *req = backend->queue; - if (!req) return -1; + if (!req) return; /* ensure backend is ready to accept request */ if (backend->is_user) { - if (!backend->user.handler) return -1; + if (!backend->user.handler) return; } else { assert(backend->kern.ready); - if (!backend->kern.ready(backend)) return -1; + if (!backend->kern.ready(backend)) return; } backend->queue = req->queue_next; if (backend->is_user) { - return vfs_backend_user_accept(req); + vfs_backend_user_accept(req); } else { assert(backend->kern.accept); - return backend->kern.accept(req); + backend->kern.accept(req); } } -int vfs_backend_user_accept(struct vfs_request *req) { +void vfs_backend_user_accept(struct vfs_request *req) { struct process *handler; struct fs_wait_response res = {0}; int len = 0; @@ -123,7 +123,7 @@ int vfs_backend_user_accept(struct vfs_request *req) { handler->handled_req = req; req->backend->user.handler = NULL; regs_savereturn(&handler->regs, 0); - return 0; + return; fail: panic_unimplemented(); // TODO } diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h index b4624fa..9dc6088 100644 --- a/src/kernel/vfs/request.h +++ b/src/kernel/vfs/request.h @@ -25,10 +25,7 @@ struct vfs_backend { } user; struct { bool (*ready)(struct vfs_backend *); - - // return value might be passed to caller - // TODO make return void - int (*accept)(struct vfs_request *); + void (*accept)(struct vfs_request *); } kern; }; }; @@ -59,13 +56,11 @@ struct vfs_request { }; /** Assigns the vfs_request to the caller, and dispatches the call */ -int vfsreq_create(struct vfs_request); -int vfsreq_finish(struct vfs_request *, int ret); +void vfsreq_create(struct vfs_request); +void vfsreq_finish(struct vfs_request *, int ret); -/** Try to accept an enqueued request - * @return same as _syscall_fs_wait, passed to it. except on calls to kern backend, where it returns the result of the fs op - also gets directly passed to caller. it's a mess */ -// TODO fix the return value mess -int vfs_backend_tryaccept(struct vfs_backend *); -int vfs_backend_user_accept(struct vfs_request *req); +/** Try to accept an enqueued request */ +void vfs_backend_tryaccept(struct vfs_backend *); +void vfs_backend_user_accept(struct vfs_request *req); void vfs_backend_refdown(struct vfs_backend *); diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c index c7bd717..989c77e 100644 --- a/src/kernel/vfs/root.c +++ b/src/kernel/vfs/root.c @@ -130,17 +130,15 @@ static int handle(struct vfs_request *req, bool *ready) { } } -int vfs_root_accept(struct vfs_request *req) { +void vfs_root_accept(struct vfs_request *req) { if (req->caller) { bool ready = true; int ret = handle(req, &ready); if (ready) { - return vfsreq_finish(req, ret); - } else { - return -1; + vfsreq_finish(req, ret); } } else { - return vfsreq_finish(req, -1); + vfsreq_finish(req, -1); } } diff --git a/src/kernel/vfs/root.h b/src/kernel/vfs/root.h index f10fb85..3db958d 100644 --- a/src/kernel/vfs/root.h +++ b/src/kernel/vfs/root.h @@ -1,5 +1,5 @@ #pragma once #include -int vfs_root_accept(struct vfs_request *); +void vfs_root_accept(struct vfs_request *); bool vfs_root_ready(struct vfs_backend *); -- cgit v1.2.3