From f231ff592234d4113ad95dfebc2f4a80e9a2c113 Mon Sep 17 00:00:00 2001 From: guenther Date: Thu, 9 Dec 2021 00:26:10 +0000 Subject: [PATCH] We only have one syscall table: inline sysent/SYS_MAXSYSCALL and SYS_syscall as the nosys() function into the MD syscall entry routines and the SYSCALL_DEBUG support. Adjust alpha's syscall check to match the other archs. Also, make sysent const to get it into .rodata. With that, 'struct emul' is unused: delete it and all its references ok millert@ --- sys/arch/alpha/alpha/trap.c | 16 ++++++-------- sys/arch/amd64/amd64/trap.c | 10 ++++----- sys/arch/arm/arm/syscall.c | 12 +++++------ sys/arch/arm64/arm64/syscall.c | 12 +++++------ sys/arch/hppa/hppa/trap.c | 17 ++++++--------- sys/arch/i386/i386/trap.c | 17 ++++++--------- sys/arch/m88k/m88k/trap.c | 30 ++++++++++---------------- sys/arch/mips64/mips64/trap.c | 17 +++++++-------- sys/arch/powerpc/powerpc/trap.c | 17 ++++++--------- sys/arch/powerpc64/powerpc64/syscall.c | 11 +++++----- sys/arch/riscv64/riscv64/syscall.c | 11 +++++----- sys/arch/sh/sh/trap.c | 17 ++++++--------- sys/arch/sparc64/sparc64/trap.c | 12 +++++------ sys/dev/dt/dt_prov_syscall.c | 5 ++--- sys/kern/exec_elf.c | 17 +-------------- sys/kern/init_main.c | 11 ++-------- sys/kern/init_sysent.c | 4 ++-- sys/kern/kern_exec.c | 10 ++------- sys/kern/kern_xxx.c | 29 ++++++++++--------------- sys/kern/makesyscalls.sh | 6 +++--- sys/sys/exec.h | 5 ++--- sys/sys/proc.h | 19 ++-------------- sys/sys/systm.h | 4 ++-- 23 files changed, 114 insertions(+), 195 deletions(-) diff --git a/sys/arch/alpha/alpha/trap.c b/sys/arch/alpha/alpha/trap.c index 2fd696df0a5..f5a8ca8f70c 100644 --- a/sys/arch/alpha/alpha/trap.c +++ b/sys/arch/alpha/alpha/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.99 2020/11/07 16:12:20 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.100 2021/12/09 00:26:11 guenther Exp $ */ /* $NetBSD: trap.c,v 1.52 2000/05/24 16:48:33 thorpej Exp $ */ /*- @@ -525,9 +525,9 @@ syscall(code, framep) u_int64_t code; struct trapframe *framep; { - struct sysent *callp; + const struct sysent *callp; struct proc *p; - int error, numsys; + int error; u_int64_t opc; u_long rval[2]; u_long args[10]; /* XXX */ @@ -539,9 +539,6 @@ syscall(code, framep) framep->tf_regs[FRAME_SP] = alpha_pal_rdusp(); opc = framep->tf_regs[FRAME_PC] - 4; - callp = p->p_p->ps_emul->e_sysent; - numsys = p->p_p->ps_emul->e_nsysent; - switch(code) { case SYS_syscall: case SYS___syscall: @@ -557,10 +554,11 @@ syscall(code, framep) } error = 0; - if (code < numsys) - callp += code; + callp = sysent; + if (code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else - callp += p->p_p->ps_emul->e_nosys; + callp += code; nargs = callp->sy_narg + hidden; switch (nargs) { diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c index 87e65841638..334502b2e3f 100644 --- a/sys/arch/amd64/amd64/trap.c +++ b/sys/arch/amd64/amd64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.89 2021/06/02 00:39:26 cheloha Exp $ */ +/* $OpenBSD: trap.c,v 1.90 2021/12/09 00:26:11 guenther Exp $ */ /* $NetBSD: trap.c,v 1.2 2003/05/04 23:51:56 fvdl Exp $ */ /*- @@ -521,7 +521,6 @@ syscall(struct trapframe *frame) const struct sysent *callp; struct proc *p; int error; - int nsys; size_t argsize, argoff; register_t code, args[9], rval[2], *argp; @@ -530,8 +529,6 @@ syscall(struct trapframe *frame) p = curproc; code = frame->tf_rax; - callp = p->p_p->ps_emul->e_sysent; - nsys = p->p_p->ps_emul->e_nsysent; argp = &args[0]; argoff = 0; @@ -549,8 +546,9 @@ syscall(struct trapframe *frame) break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; diff --git a/sys/arch/arm/arm/syscall.c b/sys/arch/arm/arm/syscall.c index 1f0f284ee99..d8f97b18104 100644 --- a/sys/arch/arm/arm/syscall.c +++ b/sys/arch/arm/arm/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.23 2021/05/16 03:39:27 jsg Exp $ */ +/* $OpenBSD: syscall.c,v 1.24 2021/12/09 00:26:11 guenther Exp $ */ /* $NetBSD: syscall.c,v 1.24 2003/11/14 19:03:17 scw Exp $ */ /*- @@ -115,7 +115,6 @@ swi_handler(trapframe_t *frame) code = frame->tf_r12; ap = &frame->tf_r0; - callp = p->p_p->ps_emul->e_sysent; switch (code) { case SYS_syscall: @@ -129,11 +128,12 @@ swi_handler(trapframe_t *frame) break; } - if (code < 0 || code >= p->p_p->ps_emul->e_nsysent) { - callp += p->p_p->ps_emul->e_nosys; - } else { + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; + else callp += code; - } + nargs = callp->sy_argsize / sizeof(register_t); if (nargs <= nap) { args = ap; diff --git a/sys/arch/arm64/arm64/syscall.c b/sys/arch/arm64/arm64/syscall.c index 8412c2b93cc..a222c8410b0 100644 --- a/sys/arch/arm64/arm64/syscall.c +++ b/sys/arch/arm64/arm64/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.8 2021/05/16 03:30:33 jsg Exp $ */ +/* $OpenBSD: syscall.c,v 1.9 2021/12/09 00:26:11 guenther Exp $ */ /* * Copyright (c) 2015 Dale Rahn * @@ -56,7 +56,6 @@ svc_handler(trapframe_t *frame) code = frame->tf_x[8]; ap = &frame->tf_x[0]; - callp = p->p_p->ps_emul->e_sysent; switch (code) { case SYS_syscall: @@ -69,11 +68,12 @@ svc_handler(trapframe_t *frame) break; } - if (code < 0 || code >= p->p_p->ps_emul->e_nsysent) { - callp += p->p_p->ps_emul->e_nosys; - } else { + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; + else callp += code; - } + nargs = callp->sy_argsize / sizeof(register_t); if (nargs <= nap) { args = ap; diff --git a/sys/arch/hppa/hppa/trap.c b/sys/arch/hppa/hppa/trap.c index 2a90ad3f0ae..2df8bb365ef 100644 --- a/sys/arch/hppa/hppa/trap.c +++ b/sys/arch/hppa/hppa/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.154 2021/10/07 08:21:22 claudio Exp $ */ +/* $OpenBSD: trap.c,v 1.155 2021/12/09 00:26:11 guenther Exp $ */ /* * Copyright (c) 1998-2004 Michael Shalayeff @@ -762,9 +762,9 @@ void syscall(struct trapframe *frame); void syscall(struct trapframe *frame) { - register struct proc *p = curproc; - register const struct sysent *callp; - int retq, nsys, code, argsize, argoff, error; + struct proc *p = curproc; + const struct sysent *callp; + int retq, code, argsize, argoff, error; register_t args[8], rval[2]; #ifdef DIAGNOSTIC int oldcpl = curcpu()->ci_cpl; @@ -776,8 +776,6 @@ syscall(struct trapframe *frame) panic("syscall"); p->p_md.md_regs = frame; - nsys = p->p_p->ps_emul->e_nsysent; - callp = p->p_p->ps_emul->e_sysent; argoff = 4; retq = 0; switch (code = frame->tf_t1) { @@ -789,8 +787,6 @@ syscall(struct trapframe *frame) argoff = 3; break; case SYS___syscall: - if (callp != sysent) - break; /* * this works, because quads get magically swapped * due to the args being laid backwards on the stack @@ -810,8 +806,9 @@ syscall(struct trapframe *frame) break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; /* bad syscall # */ + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; diff --git a/sys/arch/i386/i386/trap.c b/sys/arch/i386/i386/trap.c index 86ca52a1b1b..8af32449dbd 100644 --- a/sys/arch/i386/i386/trap.c +++ b/sys/arch/i386/i386/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.155 2021/09/19 10:43:26 mpi Exp $ */ +/* $OpenBSD: trap.c,v 1.156 2021/12/09 00:26:11 guenther Exp $ */ /* $NetBSD: trap.c,v 1.95 1996/05/05 06:50:02 mycroft Exp $ */ /*- @@ -517,9 +517,9 @@ void syscall(struct trapframe *frame) { caddr_t params; - struct sysent *callp; + const struct sysent *callp; struct proc *p; - int error, nsys; + int error; register_t code, args[8], rval[2]; #ifdef DIAGNOSTIC int ocpl = lapic_tpr; @@ -545,9 +545,6 @@ syscall(struct trapframe *frame) p->p_md.md_regs = frame; code = frame->tf_eax; - nsys = p->p_p->ps_emul->e_nsysent; - callp = p->p_p->ps_emul->e_sysent; - params = (caddr_t)frame->tf_esp + sizeof(int); switch (code) { @@ -563,16 +560,16 @@ syscall(struct trapframe *frame) * Like syscall, but code is a quad, so as to maintain * quad alignment for the rest of the arguments. */ - if (callp != sysent) - break; copyin(params + _QUAD_LOWWORD * sizeof(int), &code, sizeof(int)); params += sizeof(quad_t); break; default: break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; /* illegal */ + + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; argsize = callp->sy_argsize; diff --git a/sys/arch/m88k/m88k/trap.c b/sys/arch/m88k/m88k/trap.c index 8ace9507e9b..28cdc6be601 100644 --- a/sys/arch/m88k/m88k/trap.c +++ b/sys/arch/m88k/m88k/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.119 2020/10/30 17:11:20 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.120 2021/12/09 00:26:11 guenther Exp $ */ /* * Copyright (c) 2004, Miodrag Vallat. * Copyright (c) 1998 Steve Murphree, Jr. @@ -1141,8 +1141,8 @@ error_fatal(struct trapframe *frame) void m88100_syscall(register_t code, struct trapframe *tf) { - int i, nsys, nap; - struct sysent *callp; + int i, nap; + const struct sysent *callp; struct proc *p = curproc; int error; register_t args[8] __aligned(8); @@ -1151,9 +1151,6 @@ m88100_syscall(register_t code, struct trapframe *tf) uvmexp.syscalls++; - callp = p->p_p->ps_emul->e_sysent; - nsys = p->p_p->ps_emul->e_nsysent; - p->p_md.md_tf = tf; /* @@ -1172,16 +1169,15 @@ m88100_syscall(register_t code, struct trapframe *tf) nap--; break; case SYS___syscall: - if (callp != sysent) - break; code = ap[_QUAD_LOWWORD]; ap += 2; nap -= 2; break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; @@ -1264,8 +1260,8 @@ m88100_syscall(register_t code, struct trapframe *tf) void m88110_syscall(register_t code, struct trapframe *tf) { - int i, nsys, nap; - struct sysent *callp; + int i, nap; + const struct sysent *callp; struct proc *p = curproc; int error; register_t args[8] __aligned(8); @@ -1274,9 +1270,6 @@ m88110_syscall(register_t code, struct trapframe *tf) uvmexp.syscalls++; - callp = p->p_p->ps_emul->e_sysent; - nsys = p->p_p->ps_emul->e_nsysent; - p->p_md.md_tf = tf; /* @@ -1295,16 +1288,15 @@ m88110_syscall(register_t code, struct trapframe *tf) nap--; break; case SYS___syscall: - if (callp != sysent) - break; code = ap[_QUAD_LOWWORD]; ap += 2; nap -= 2; break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; diff --git a/sys/arch/mips64/mips64/trap.c b/sys/arch/mips64/mips64/trap.c index 3c359ca6c64..857f9fed7c6 100644 --- a/sys/arch/mips64/mips64/trap.c +++ b/sys/arch/mips64/mips64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.155 2021/10/24 15:29:10 visa Exp $ */ +/* $OpenBSD: trap.c,v 1.156 2021/12/09 00:26:11 guenther Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -400,11 +400,11 @@ fault_common_no_miss: case T_SYSCALL+T_USER: { struct trapframe *locr0 = p->p_md.md_regs; - struct sysent *callp; + const struct sysent *callp; unsigned int code; register_t tpc; uint32_t branch = 0; - int error, numarg, numsys; + int error, numarg; struct args { register_t i[8]; } args; @@ -426,8 +426,7 @@ fault_common_no_miss: trapframe->pc, 0, branch); } else locr0->pc += 4; - callp = p->p_p->ps_emul->e_sysent; - numsys = p->p_p->ps_emul->e_nsysent; + callp = sysent; code = locr0->v0; switch (code) { case SYS_syscall: @@ -439,8 +438,8 @@ fault_common_no_miss: * platforms, which doesn't change anything here. */ code = locr0->a0; - if (code >= numsys) - callp += p->p_p->ps_emul->e_nosys; /* (illegal) */ + if (code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; numarg = callp->sy_argsize / sizeof(register_t); @@ -459,8 +458,8 @@ fault_common_no_miss: } break; default: - if (code >= numsys) - callp += p->p_p->ps_emul->e_nosys; /* (illegal) */ + if (code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; diff --git a/sys/arch/powerpc/powerpc/trap.c b/sys/arch/powerpc/powerpc/trap.c index eee4b367bb5..5831bc1cf7e 100644 --- a/sys/arch/powerpc/powerpc/trap.c +++ b/sys/arch/powerpc/powerpc/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.122 2021/11/26 14:59:42 jsg Exp $ */ +/* $OpenBSD: trap.c,v 1.123 2021/12/09 00:26:11 guenther Exp $ */ /* $NetBSD: trap.c,v 1.3 1996/10/13 03:31:37 christos Exp $ */ /* @@ -236,11 +236,11 @@ trap(struct trapframe *frame) struct vm_map *map; vaddr_t va; int access_type; - struct sysent *callp; + const struct sysent *callp; size_t argsize; register_t code, error; register_t *params, rval[2], args[10]; - int nsys, n; + int n; if (frame->srr1 & PSL_PR) { type |= EXC_USER; @@ -357,9 +357,6 @@ trap(struct trapframe *frame) case EXC_SC|EXC_USER: uvmexp.syscalls++; - nsys = p->p_p->ps_emul->e_nsysent; - callp = p->p_p->ps_emul->e_sysent; - code = frame->fixreg[0]; params = frame->fixreg + FIRSTARG; @@ -377,16 +374,16 @@ trap(struct trapframe *frame) * so as to maintain quad alignment * for the rest of the args. */ - if (callp != sysent) - break; params++; code = *params++; break; default: break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; + + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; argsize = callp->sy_argsize; diff --git a/sys/arch/powerpc64/powerpc64/syscall.c b/sys/arch/powerpc64/powerpc64/syscall.c index b383c7978f3..95fb92b5915 100644 --- a/sys/arch/powerpc64/powerpc64/syscall.c +++ b/sys/arch/powerpc64/powerpc64/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.7 2020/10/09 20:30:18 kettenis Exp $ */ +/* $OpenBSD: syscall.c,v 1.8 2021/12/09 00:26:11 guenther Exp $ */ /* * Copyright (c) 2015 Dale Rahn @@ -31,13 +31,11 @@ syscall(struct trapframe *frame) { struct proc *p = curproc; const struct sysent *callp; - int code, error, nsys; + int code, error; int nap = 8, nargs; register_t *ap, *args, copyargs[MAXARGS], rval[2]; code = frame->fixreg[0]; - callp = p->p_p->ps_emul->e_sysent; - nsys = p->p_p->ps_emul->e_nsysent; ap = &frame->fixreg[3]; switch (code) { @@ -48,8 +46,9 @@ syscall(struct trapframe *frame) break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; nargs = callp->sy_argsize / sizeof(register_t); diff --git a/sys/arch/riscv64/riscv64/syscall.c b/sys/arch/riscv64/riscv64/syscall.c index 615d2c9dfd1..44520a83e33 100644 --- a/sys/arch/riscv64/riscv64/syscall.c +++ b/sys/arch/riscv64/riscv64/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.10 2021/06/21 14:39:30 deraadt Exp $ */ +/* $OpenBSD: syscall.c,v 1.11 2021/12/09 00:26:11 guenther Exp $ */ /* * Copyright (c) 2020 Brian Bamsch @@ -54,7 +54,6 @@ svc_handler(trapframe_t *frame) ap = &frame->tf_a[0]; code = frame->tf_t[0]; - callp = p->p_p->ps_emul->e_sysent; switch (code) { case SYS_syscall: @@ -67,11 +66,11 @@ svc_handler(trapframe_t *frame) break; } - if (code < 0 || code >= p->p_p->ps_emul->e_nsysent) { - callp += p->p_p->ps_emul->e_nosys; - } else { + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; + else callp += code; - } nargs = callp->sy_argsize / sizeof(register_t); if (nargs <= nap) { args = ap; diff --git a/sys/arch/sh/sh/trap.c b/sys/arch/sh/sh/trap.c index b75d7582038..64e969df7be 100644 --- a/sys/arch/sh/sh/trap.c +++ b/sys/arch/sh/sh/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.48 2021/03/11 11:17:00 jsg Exp $ */ +/* $OpenBSD: trap.c,v 1.49 2021/12/09 00:26:11 guenther Exp $ */ /* $NetBSD: exception.c,v 1.32 2006/09/04 23:57:52 uwe Exp $ */ /* $NetBSD: syscall.c,v 1.6 2006/03/07 07:21:50 thorpej Exp $ */ @@ -512,7 +512,7 @@ syscall(struct proc *p, struct trapframe *tf) { caddr_t params; const struct sysent *callp; - int error, opc, nsys; + int error, opc; size_t argsize; register_t code, args[8], rval[2], ocode; @@ -521,9 +521,6 @@ syscall(struct proc *p, struct trapframe *tf) opc = tf->tf_spc; ocode = code = tf->tf_r0; - nsys = p->p_p->ps_emul->e_nsysent; - callp = p->p_p->ps_emul->e_sysent; - params = (caddr_t)tf->tf_r15; switch (code) { @@ -538,8 +535,6 @@ syscall(struct proc *p, struct trapframe *tf) * Like syscall, but code is a quad, so as to maintain * quad alignment for the rest of the arguments. */ - if (callp != sysent) - break; #if _BYTE_ORDER == BIG_ENDIAN code = tf->tf_r5; #else @@ -549,14 +544,16 @@ syscall(struct proc *p, struct trapframe *tf) default: break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; /* illegal */ + + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else callp += code; argsize = callp->sy_argsize; #ifdef DIAGNOSTIC if (argsize > sizeof args) { - callp += p->p_p->ps_emul->e_nosys - code; + callp += SYS_syscall - code; argsize = callp->sy_argsize; } #endif diff --git a/sys/arch/sparc64/sparc64/trap.c b/sys/arch/sparc64/sparc64/trap.c index 1d7165d172f..0f996f913bf 100644 --- a/sys/arch/sparc64/sparc64/trap.c +++ b/sys/arch/sparc64/sparc64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.109 2021/05/05 07:29:01 mpi Exp $ */ +/* $OpenBSD: trap.c,v 1.110 2021/12/09 00:26:11 guenther Exp $ */ /* $NetBSD: trap.c,v 1.73 2001/08/09 01:03:01 eeh Exp $ */ /* @@ -1102,7 +1102,7 @@ out: void syscall(struct trapframe64 *tf, register_t code, register_t pc) { - int i, nsys, nap; + int i, nap; int64_t *ap; const struct sysent *callp; struct proc *p = curproc; @@ -1126,9 +1126,6 @@ syscall(struct trapframe64 *tf, register_t code, register_t pc) new = code & SYSCALL_G2RFLAG; code &= ~SYSCALL_G2RFLAG; - callp = p->p_p->ps_emul->e_sysent; - nsys = p->p_p->ps_emul->e_nsysent; - /* * The first six system call arguments are in the six %o registers. * Any arguments beyond that are in the `argument extension' area @@ -1151,8 +1148,9 @@ syscall(struct trapframe64 *tf, register_t code, register_t pc) break; } - if (code < 0 || code >= nsys) - callp += p->p_p->ps_emul->e_nosys; + callp = sysent; + if (code < 0 || code >= SYS_MAXSYSCALL) + callp += SYS_syscall; else { register_t *argp; diff --git a/sys/dev/dt/dt_prov_syscall.c b/sys/dev/dt/dt_prov_syscall.c index 33822dade1b..530033df487 100644 --- a/sys/dev/dt/dt_prov_syscall.c +++ b/sys/dev/dt/dt_prov_syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_prov_syscall.c,v 1.6 2021/09/03 16:45:45 jasper Exp $ */ +/* $OpenBSD: dt_prov_syscall.c,v 1.7 2021/12/09 00:26:11 guenther Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -21,12 +21,11 @@ #include #include #include +#include #include #include -extern struct sysent sysent[]; - /* Arrays of probes per syscall. */ struct dt_probe **dtps_entry; struct dt_probe **dtps_return; diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c index 330108cd19c..567a252640b 100644 --- a/sys/kern/exec_elf.c +++ b/sys/kern/exec_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.c,v 1.164 2021/12/07 22:17:02 guenther Exp $ */ +/* $OpenBSD: exec_elf.c,v 1.165 2021/12/09 00:26:10 guenther Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -112,15 +112,6 @@ int elf_os_pt_note(struct proc *, struct exec_package *, Elf_Ehdr *, int *); */ #define ELF_MAX_VALID_PHDR 32 -/* - * This is the OpenBSD ELF emul - */ -struct emul emul_elf = { - SYS_syscall, - SYS_MAXSYSCALL, - sysent, -}; - #define ELF_NOTE_NAME_OPENBSD 0x01 struct elf_note_name { @@ -547,12 +538,6 @@ exec_elf_makecmds(struct proc *p, struct exec_package *epp) exe_base = uvm_map_pie(base_ph->p_align); } - /* - * OK, we want a slightly different twist of the - * standard emulation package for "real" elf. - */ - epp->ep_emul = &emul_elf; - /* * Verify this is an OpenBSD executable. If it's marked that way * via a PT_NOTE then also check for a PT_OPENBSD_WXNEEDED segment. diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index fce15e4af6e..423f4cffa5f 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.312 2021/12/07 22:17:02 guenther Exp $ */ +/* $OpenBSD: init_main.c,v 1.313 2021/12/09 00:26:10 guenther Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -154,12 +154,6 @@ void timeout_proc_init(void); void pool_gc_pages(void *); void percpu_init(void); -struct emul emul_native = { - SYS_syscall, - SYS_MAXSYSCALL, - sysent, -}; - #ifdef DIAGNOSTIC int pdevinit_done = 0; #endif @@ -297,7 +291,6 @@ main(void *framep) atomic_setbits_int(&p->p_flag, P_SYSTEM); p->p_stat = SONPROC; pr->ps_nice = NZERO; - pr->ps_emul = &emul_native; strlcpy(pr->ps_comm, "swapper", sizeof(pr->ps_comm)); /* Init timeouts. */ @@ -416,7 +409,7 @@ main(void *framep) kqueue_init_percpu(); uvm_init_percpu(); - /* init exec and emul */ + /* init exec */ init_exec(); /* Start the scheduler */ diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c index 67a01afbef5..834f3988391 100644 --- a/sys/kern/init_sysent.c +++ b/sys/kern/init_sysent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_sysent.c,v 1.231 2021/11/29 16:31:43 mvs Exp $ */ +/* $OpenBSD: init_sysent.c,v 1.232 2021/12/09 00:26:10 guenther Exp $ */ /* * System call switch table. @@ -16,7 +16,7 @@ #define s(type) sizeof(type) -struct sysent sysent[] = { +const struct sysent sysent[] = { { 0, 0, 0, sys_nosys }, /* 0 = syscall (indir) */ { 1, s(struct sys_exit_args), 0, diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 4ec7d22d453..636e625385f 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.227 2021/12/07 22:17:02 guenther Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.228 2021/12/09 00:26:10 guenther Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -270,7 +270,6 @@ sys_execve(struct proc *p, void *v, register_t *retval) char *stack; struct ps_strings arginfo; struct vmspace *vm; - extern struct emul emul_native; struct vnode *otvp; /* get other threads to stop */ @@ -300,7 +299,6 @@ sys_execve(struct proc *p, void *v, register_t *retval) pack.ep_auxinfo = NULL; VMCMDSET_INIT(&pack.ep_vmcmds); pack.ep_vap = &attr; - pack.ep_emul = &emul_native; pack.ep_flags = 0; /* see if we can run it. */ @@ -713,9 +711,6 @@ sys_execve(struct proc *p, void *v, register_t *retval) else atomic_clearbits_int(&p->p_p->ps_flags, PS_WXNEEDED); - /* update ps_emul, the old value is no longer needed */ - pr->ps_emul = pack.ep_emul; - atomic_clearbits_int(&pr->ps_flags, PS_INEXEC); single_thread_clear(p, P_SUSPSIG); @@ -884,8 +879,7 @@ exec_timekeep_map(struct process *pr) size_t timekeep_sz = round_page(sizeof(struct timekeep)); /* - * Similar to the sigcode object, except that there is a single - * timekeep object, and not one per emulation. + * Similar to the sigcode object */ if (timekeep_object == NULL) { vaddr_t va = 0; diff --git a/sys/kern/kern_xxx.c b/sys/kern/kern_xxx.c index a74bb06acf1..cd72f263879 100644 --- a/sys/kern/kern_xxx.c +++ b/sys/kern/kern_xxx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_xxx.c,v 1.37 2021/12/07 22:17:02 guenther Exp $ */ +/* $OpenBSD: kern_xxx.c,v 1.38 2021/12/09 00:26:10 guenther Exp $ */ /* $NetBSD: kern_xxx.c,v 1.32 1996/04/22 01:38:41 christos Exp $ */ /* @@ -87,6 +87,7 @@ __stack_smash_handler(char func[], int damaged) #ifdef SYSCALL_DEBUG #include +#include #define SCDEBUG_CALLS 0x0001 /* show calls */ #define SCDEBUG_RETURNS 0x0002 /* show returns */ @@ -101,28 +102,24 @@ void scdebug_call(struct proc *p, register_t code, const register_t args[]) { struct process *pr; - struct sysent *sy; - struct emul *em; int i; if (!(scdebug & SCDEBUG_CALLS)) return; - pr = p->p_p; - em = pr->ps_emul; - sy = &em->e_sysent[code]; - if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent || - sy->sy_call == sys_nosys)) + if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= SYS_MAXSYSCALL || + sysent[code].sy_call == sys_nosys)) return; + pr = p->p_p; printf("proc %d (%s): num ", pr->ps_pid, pr->ps_comm); - if (code < 0 || code >= em->e_nsysent) + if (code < 0 || code >= SYS_MAXSYSCALL) printf("OUT OF RANGE (%ld)", code); else { printf("%ld call: %s", code, syscallnames[code]); if (scdebug & SCDEBUG_SHOWARGS) { printf("("); - for (i = 0; i < sy->sy_argsize / sizeof(register_t); + for (i = 0; i < sysent[code].sy_argsize / sizeof(register_t); i++) printf("%s0x%lx", i == 0 ? "" : ", ", args[i]); printf(")"); @@ -136,21 +133,17 @@ scdebug_ret(struct proc *p, register_t code, int error, const register_t retval[]) { struct process *pr; - struct sysent *sy; - struct emul *em; if (!(scdebug & SCDEBUG_RETURNS)) return; - pr = p->p_p; - em = pr->ps_emul; - sy = &em->e_sysent[code]; - if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent || - sy->sy_call == sys_nosys)) + if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= SYS_MAXSYSCALL || + sysent[code].sy_call == sys_nosys)) return; + pr = p->p_p; printf("proc %d (%s): num ", pr->ps_pid, pr->ps_comm); - if (code < 0 || code >= em->e_nsysent) + if (code < 0 || code >= SYS_MAXSYSCALL) printf("OUT OF RANGE (%ld)", code); else printf("%ld ret: err = %d, rv = 0x%lx,0x%lx", code, diff --git a/sys/kern/makesyscalls.sh b/sys/kern/makesyscalls.sh index 86d35806ebe..705310840bc 100644 --- a/sys/kern/makesyscalls.sh +++ b/sys/kern/makesyscalls.sh @@ -1,5 +1,5 @@ #! /bin/sh - -# $OpenBSD: makesyscalls.sh,v 1.14 2021/12/07 22:17:02 guenther Exp $ +# $OpenBSD: makesyscalls.sh,v 1.15 2021/12/09 00:26:10 guenther Exp $ # $NetBSD: makesyscalls.sh,v 1.26 1998/01/09 06:17:51 thorpej Exp $ # # Copyright (c) 1994,1996 Christopher G. Demetriou @@ -56,7 +56,7 @@ esac # syssw the syscall switch file # sysarghdr the syscall argument struct definitions # compatopts those syscall types that are for 'compat' syscalls -# switchname the name for the 'struct sysent' we define +# switchname the name for the 'const struct sysent' we define # namesname the name for the 'const char *const[]' we define # constprefix the prefix for the system call constants # @@ -150,7 +150,7 @@ BEGIN { } printf "\n#define\ts(type)\tsizeof(type)\n\n" > sysent - printf "struct sysent %s[] = {\n",switchname > sysent + printf "const struct sysent %s[] = {\n",switchname > sysent printf "/*\t\$OpenBSD\$\t*/\n\n" > sysnames printf "/*\n * System call names.\n *\n" > sysnames diff --git a/sys/sys/exec.h b/sys/sys/exec.h index 61a91e00192..a2c75023f81 100644 --- a/sys/sys/exec.h +++ b/sys/sys/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.45 2021/12/06 21:21:10 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.46 2021/12/09 00:26:10 guenther Exp $ */ /* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */ /*- @@ -59,7 +59,7 @@ struct ps_strings { /* * Below the PS_STRINGS and sigtramp, we may require a gap on the stack - * (used to copyin/copyout various emulation data structures). + * (used to copyin/copyout various XXX emulation data structures). */ #define STACKGAPLEN (2*1024) /* plenty enough for now */ @@ -132,7 +132,6 @@ struct exec_package { u_int ep_flags; /* flags; see below. */ char **ep_fa; /* a fake args vector for scripts */ int ep_fd; /* a file descriptor we're holding */ - struct emul *ep_emul; /* os emulation */ struct elf_args *ep_args; /* ELF info */ void *ep_auxinfo; /* userspace auxinfo address */ char *ep_interp; /* name of interpreter if any */ diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 1e691b018c7..7b4b8db6ee4 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.321 2021/12/07 22:17:03 guenther Exp $ */ +/* $OpenBSD: proc.h,v 1.322 2021/12/09 00:26:10 guenther Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -85,21 +85,6 @@ struct pgrp { int pg_jobc; /* # procs qualifying pgrp for job control */ }; -/* - * One structure allocated per emulation. - */ -struct exec_package; -struct proc; -struct ps_strings; -struct uvm_object; -union sigval; - -struct emul { - int e_nosys; /* Offset of the nosys() syscall */ - int e_nsysent; /* Number of system call entries */ - struct sysent *e_sysent; /* System call array */ -}; - /* * time usage: accumulated times in ticks * Once a second, each thread's immediate counts (p_[usi]ticks) are @@ -127,6 +112,7 @@ struct tusage { #ifdef __need_process struct futex; LIST_HEAD(futex_list, futex); +struct proc; struct tslpentry; TAILQ_HEAD(tslpqueue, tslpentry); struct unveil; @@ -225,7 +211,6 @@ struct process { #define ps_startcopy ps_limit struct plimit *ps_limit; /* [m,R] Process limits. */ struct pgrp *ps_pgrp; /* Pointer to process group. */ - struct emul *ps_emul; /* Emulation information */ char ps_comm[MAXCOMLEN+1]; diff --git a/sys/sys/systm.h b/sys/sys/systm.h index a0ef9a3dd7f..6124c6ce2cc 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.154 2021/06/02 00:39:25 cheloha Exp $ */ +/* $OpenBSD: systm.h,v 1.155 2021/12/09 00:26:10 guenther Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -114,7 +114,7 @@ struct process; typedef int sy_call_t(struct proc *, void *, register_t *); -extern struct sysent { /* system call table */ +extern const struct sysent { /* system call table */ short sy_narg; /* number of args */ short sy_argsize; /* total size of arguments */ int sy_flags; -- 2.20.1