diff options
author | dzwdz | 2023-01-25 01:02:04 +0100 |
---|---|---|
committer | dzwdz | 2023-01-25 01:04:49 +0100 |
commit | 2a2fc4dffe0117ce874a6cf1dcc34321ed8add77 (patch) | |
tree | af1e24f72241dbbff97797b9e186f7d27b5b54b4 /src/kernel/vfs | |
parent | 52e7fe3c679469032e77a5ca4adf19618ba1201b (diff) |
kernel/virt: replace the virt_cpy api with a more foolproof one
Diffstat (limited to 'src/kernel/vfs')
-rw-r--r-- | src/kernel/vfs/procfs.c | 11 | ||||
-rw-r--r-- | src/kernel/vfs/request.c | 22 |
2 files changed, 16 insertions, 17 deletions
diff --git a/src/kernel/vfs/procfs.c b/src/kernel/vfs/procfs.c index be907fd..78dad0d 100644 --- a/src/kernel/vfs/procfs.c +++ b/src/kernel/vfs/procfs.c @@ -1,4 +1,5 @@ #include <camellia/errno.h> +#include <kernel/mem/alloc.h> #include <kernel/mem/virt.h> #include <kernel/panic.h> #include <kernel/proc.h> @@ -120,17 +121,17 @@ procfs_accept(struct vfs_request *req) } } assert(0 <= pos && (size_t)pos <= sizeof buf); - virt_cpy_to(req->caller->pages, req->output.buf, buf, pos); + pcpy_to(req->caller, req->output.buf, buf, pos); vfsreq_finish_short(req, pos); } else if (req->type == VFSOP_READ && h->type == PhMem) { if (p->pages == NULL || req->caller->pages == NULL) { vfsreq_finish_short(req, 0); return; } - size_t res = virt_cpy( - req->caller->pages, req->output.buf, - p->pages, (__user void*)req->offset, - req->output.len, NULL + size_t res = pcpy_bi( + req->caller, req->output.buf, + p, (__user void*)req->offset, + req->output.len ); vfsreq_finish_short(req, res); } else if (req->type == VFSOP_WRITE && h->type == PhIntr) { diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 1cd2787..c98913a 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -106,27 +106,26 @@ void vfs_backend_tryaccept(struct vfs_backend *backend) { static void vfs_backend_user_accept(struct vfs_request *req) { struct process *handler; struct ufs_request res = {0}; - struct virt_cpy_error cpyerr; int len; assert(req && req->backend && req->backend->user.handler); handler = req->backend->user.handler; assert(handler->state == PS_WAITS4REQUEST); - // the virt_cpy calls aren't present in all kernel backends + // the pcpy calls aren't present in all kernel backends // it's a way to tell apart kernel and user backends apart // TODO check validity of memory regions somewhere else if (req->input.buf) { + __user void *buf = handler->awaited_req.buf; len = min(req->input.len, handler->awaited_req.max_len); - virt_cpy(handler->pages, handler->awaited_req.buf, - req->input.kern ? NULL : req->caller->pages, req->input.buf, - len, &cpyerr); - if (cpyerr.write_fail) - panic_unimplemented(); - if (cpyerr.read_fail) { - vfsreq_finish_short(req, -EFAULT); - return; + if (req->input.kern) { + pcpy_to(handler, buf, req->input.buf_kern, len); + } else { + len = pcpy_bi( + handler, buf, + req->caller, req->input.buf, len + ); } } else { len = req->output.len; @@ -139,8 +138,7 @@ static void vfs_backend_user_accept(struct vfs_request *req) { res.flags = req->flags; res.op = req->type; - if (!virt_cpy_to(handler->pages, - handler->awaited_req.res, &res, sizeof res)) + if (pcpy_to(handler, handler->awaited_req.res, &res, sizeof res) < sizeof(res)) { panic_unimplemented(); } |