diff options
author | dzwdz | 2024-07-27 19:59:37 +0200 |
---|---|---|
committer | dzwdz | 2024-07-27 20:00:29 +0200 |
commit | fe6fbfa07aa8326926049cf62560d940bc7305c0 (patch) | |
tree | e97060cb23c8a5a227fe615b97d9213d5fc2ad1e /src | |
parent | 58514d351e1f0e8871f534422cf025109ddbb844 (diff) |
kernel: don't use pointer types for registers, add proc_savereturn
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/arch/amd64/registers.h | 11 | ||||
-rw-r--r-- | src/kernel/pipe.c | 8 | ||||
-rw-r--r-- | src/kernel/proc.c | 10 | ||||
-rw-r--r-- | src/kernel/proc.h | 3 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 6 | ||||
-rw-r--r-- | src/kernel/vfs/request.c | 6 | ||||
-rw-r--r-- | src/libc/intr.c | 2 | ||||
-rw-r--r-- | src/libk/include/camellia/types.h | 7 |
8 files changed, 26 insertions, 27 deletions
diff --git a/src/kernel/arch/amd64/registers.h b/src/kernel/arch/amd64/registers.h index cfbfa54..a76062f 100644 --- a/src/kernel/arch/amd64/registers.h +++ b/src/kernel/arch/amd64/registers.h @@ -5,14 +5,7 @@ /* requires 16-byte alignment */ struct CpuRegs { uint64_t r15, r14, r13, r12, r11, r10, r9, r8; - uint64_t rdi, rsi; - userptr_t rbp, rsp; - uint64_t rbx, rdx, rcx, rax, rip, flags; + uint64_t rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax; + uint64_t rip, flags; uint8_t _sse[512]; } __attribute__((__packed__)); - -// saves a return value according to the SysV ABI -static inline uint64_t regs_savereturn(CpuRegs *regs, uint64_t value) { - regs->rax = value; - return value; -} diff --git a/src/kernel/pipe.c b/src/kernel/pipe.c index b7f5ad3..5efafc8 100644 --- a/src/kernel/pipe.c +++ b/src/kernel/pipe.c @@ -9,7 +9,7 @@ void pipe_joinqueue(Handle *h, Proc *proc, void __user *pbuf, size_t pbuflen) { assert(h && h->type == HANDLE_PIPE); assert(h->readable ^ h->writeable); if (!h->pipe.sister) { - regs_savereturn(&proc->regs, h->readable ? 0 : -EPIPE); + proc_savereturn(proc, h->readable ? 0 : -EPIPE); return; } @@ -54,8 +54,8 @@ static void pipe_trytransfer(Handle *h) { h->pipe.sister->pipe.queued = h->pipe.sister->pipe.queued->waits4pipe.next; proc_setstate(rdr, PS_RUNNING); proc_setstate(wtr, PS_RUNNING); - regs_savereturn(&rdr->regs, len); - regs_savereturn(&wtr->regs, len); + proc_savereturn(rdr, len); + proc_savereturn(wtr, len); } void pipe_invalidate_end(Handle *h) { @@ -63,7 +63,7 @@ void pipe_invalidate_end(Handle *h) { while (p) { assert(p->state == PS_WAITS4PIPE); proc_setstate(p, PS_RUNNING); - regs_savereturn(&p->regs, -1); + proc_savereturn(p, -1); p = p->waits4pipe.next; } h->pipe.queued = NULL; diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 8be1080..d85384f 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -309,7 +309,7 @@ void proc_tryreap(Proc *dead) { if (parent->awaited_death.pid && parent->awaited_death.pid != pid) { return; /* we're not The One */ } - regs_savereturn(&parent->regs, pid); + proc_savereturn(parent, pid); if (parent->awaited_death.out) { struct sys_wait2 __user *out = parent->awaited_death.out; struct sys_wait2 data; @@ -417,14 +417,14 @@ static void proc_intr_deliver(Proc *p) { // one more because the buffer itself isn't NUL terminated // TODO ensure NUL termination - void __user *sp = p->regs.rsp - 128 - sizeof(d) - intr->len - 1; + void __user *sp = (void __user*)(p->regs.rsp - 128 - sizeof(d) - intr->len - 1); pcpy_to(p, sp, &d, sizeof(d)); pcpy_to(p, sp + sizeof(d), intr->buf, intr->len); pcpy_to(p, sp + sizeof(d) + intr->len, "", 1); /* switch to intr handler */ p->regs.rip = (uint64_t)p->intr_fn; - p->regs.rsp = sp; + p->regs.rsp = (uint64_t)sp; kfree(p->queuedintr); p->queuedintr = NULL; @@ -518,6 +518,10 @@ Proc *proc_next(Proc *root, Proc *p) { return p->sibling; } +void proc_savereturn(Proc *p, uint64_t val) { + p->regs.rax = val; +} + void proc_setstate(Proc *p, enum proc_state state) { assert(p->state != PS_FREED); if (state == PS_FREED) { diff --git a/src/kernel/proc.h b/src/kernel/proc.h index 96cd8ba..a371e04 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -131,6 +131,9 @@ _Noreturn void proc_switch_any(void); Proc *proc_next(Proc *root, Proc *p); +/** Saves a return value. */ +void proc_savereturn(Proc *p, uint64_t val); + void proc_setstate(Proc *, enum proc_state); size_t pcpy_to(Proc *p, __user void *dst, const void *src, size_t len); diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index ffd69b8..42f548e 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -14,7 +14,7 @@ #define SYSCALL_RETURN(val) do { \ assert(proc_cur->state == PS_RUNNING); \ - regs_savereturn(&proc_cur->regs, (long)(val)); \ + proc_savereturn(proc_cur, (long)(val)); \ return 0; \ } while (0) @@ -27,7 +27,7 @@ long _sys_fork(int flags, hid_t __user *fs_front) { Proc *child; child = proc_fork(proc_cur, flags); - regs_savereturn(&child->regs, 0); + proc_savereturn(child, 0); if (flags & FORK_NEWFS) { Handle *h; @@ -589,7 +589,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) { break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b); break; default: - regs_savereturn(&proc_cur->regs, -1); + proc_savereturn(proc_cur, -1); break; } /* return value is unused. execution continues in sysenter_stage2 */ diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 3f6fda7..69a007e 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -115,7 +115,7 @@ vfsreq_finish(VfsReq *req, char __user *stored, long ret, int flags, Proc *handl if (req->caller) { assert(req->caller->state == PS_WAITS4FS); - regs_savereturn(&req->caller->regs, ret); + proc_savereturn(req->caller, ret); proc_setstate(req->caller, PS_RUNNING); } kfree(req); @@ -181,7 +181,7 @@ vfsback_useraccept(VfsReq *req) if (hid < 0) panic_unimplemented(); h->req = req; proc_setstate(handler, PS_RUNNING); - regs_savereturn(&handler->regs, hid); + proc_savereturn(handler, hid); req->backend->user.handler = NULL; } @@ -210,7 +210,7 @@ vfsback_userdown(VfsBackend *b) Proc *p = b->user.handler; b->user.handler = NULL; assert(p->state == PS_WAITS4REQUEST); - regs_savereturn(&p->regs, -EPIPE); + proc_savereturn(p, -EPIPE); proc_setstate(p, PS_RUNNING); } } diff --git a/src/libc/intr.c b/src/libc/intr.c index c44a90e..12e6f4c 100644 --- a/src/libc/intr.c +++ b/src/libc/intr.c @@ -9,6 +9,6 @@ void intr_set(void (*fn)(struct intr_data *)) { _intr = fn ? fn : intr_null; } -void intr_default(struct intr_data *intr) { +void intr_default(struct intr_data *) { exit(-1); } diff --git a/src/libk/include/camellia/types.h b/src/libk/include/camellia/types.h index 86ffb56..6fee578 100644 --- a/src/libk/include/camellia/types.h +++ b/src/libk/include/camellia/types.h @@ -37,10 +37,9 @@ struct intr_data { * notable omissions: * - SSE registers (usually there's no need to save them, userland can do * that itself if it wants) */ - uint64_t r15, r14, r13, r12, r11, r10, r9, r8; - uint64_t rdi, rsi; - userptr_t rbp, rsp; - uint64_t rbx, rdx, rcx, rax, rip, flags; + uint64_t r15, r14, r13, r12, r11, r10, r9, r8; + uint64_t rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax; + uint64_t rip, flags; char msg[]; /* variable size, NUL terminated */ }; |