From nobody Mon Mar 28 18:43:48 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 970BB1A4A305; Mon, 28 Mar 2022 18:43:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KS1n03RbYz3CbL; Mon, 28 Mar 2022 18:43:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648493028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DTl6UH4hOIMjdmPWx2q41OHsRo6h77Qs7Ec22en9CJE=; b=cSIxwBvRYxVcHzFn+dvLofaoxqPBlGADU+91vMTtJzHFSrfHhJEr8Ow1gR1x7GjX6HZzO8 kicZWcRMqGKVKR/hq6SF8pHrldbNxxP3osQGoqLKiLyH936ZXh4kPtiN1Q61HfqZlpOjMp o9x+LWIUwyi3WwzuizTcMbGbh6o2C0duh3efyXOXZv7lvYxnIGQwHNUOiuo8ENQyPxc/Xp apAqEvDXE4VLloJFFIq5fDB0itHOiqQrF7bY+mmg60j8pxDOSAJ2Q/HccSFK1KmaAJ+ZtR uh/IW+7So5N+KLoqzhS96Fz5M/w/DIEnkpZEu12wDhABJmjzo5qPpzeMMae+UA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3FD5B765C; Mon, 28 Mar 2022 18:43:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22SIhmYK058269; Mon, 28 Mar 2022 18:43:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22SIhmHf058268; Mon, 28 Mar 2022 18:43:48 GMT (envelope-from git) Date: Mon, 28 Mar 2022 18:43:48 GMT Message-Id: <202203281843.22SIhmHf058268@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: b1ad6a9000c3 - main - syscallarg_t: Add a type for system call arguments List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b1ad6a9000c3fc58d4373fa5a4733d46a9a365ca Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648493028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DTl6UH4hOIMjdmPWx2q41OHsRo6h77Qs7Ec22en9CJE=; b=mVqejCTdIYSR8KF2jf49M+5qzkUG0a2D1wjGd90cuukLoWbBmoX0J7KtBEdgibnsMzrdG4 XaHvFdZszcjSGv5qZdmUAcXyzm1DebM2GboQrF7oAvrNBo0eJNj7WXPTYrE0BhDJAHbBPg 3xmDnyeP0TLHMUqacxEoB7a8KmIdrcHmN55aavif7HFMhaHwHoTxKeocoCKXFxF/rwEjoB +nzIzTVRj5NKCznelLVMmjyLrhTVq2Jg4FNrS92dPdm80o0ebA3YDSRPtC7A7rLQNvER0Q 6Ldow7Kla340H8fnXO2QtQs6HIcBaTCD73aa3F/2pVyDjLO40X+Q50ak9+GhqQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648493028; a=rsa-sha256; cv=none; b=wYRqZpCXFbnKqo35f4sRd6IUXrRJjYDbT5hn4mfPIgJQjpVvQ+W7lh9YciatbMs8yF/rsc jOGPKl/+ZOiDmey4XpPXTnaMtKoLMoHLB8hZVuKWMHFAPkC2HSZz64npaaTpzm1DqfJLIa f5oIV1jqZBtj+zlVDD6Weq/i219RjY9Gn/T9LXcuXM3u5QLMqD0muRH9eWoGneqkriS3L7 h1HzTC++PPRs4jTAz3d8m+pOQX6dOeCd6YXgRAadaGYf79lPpEeoQ5nxQEB0MYz42G6/52 Xm8wz0FGZ6OJFJcJDK/kYVechTLg4YTM2q1m1FDDAbSqGCMpt5eJVB3PygeASQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=b1ad6a9000c3fc58d4373fa5a4733d46a9a365ca commit b1ad6a9000c3fc58d4373fa5a4733d46a9a365ca Author: Brooks Davis AuthorDate: 2022-03-28 18:43:03 +0000 Commit: Brooks Davis CommitDate: 2022-03-28 18:43:03 +0000 syscallarg_t: Add a type for system call arguments This more clearly differentiates system call arguments from integer registers and return values. On current architectures it has no effect, but on architectures where pointers are not integers (CHERI) and may not even share registers (CHERI-MIPS) it is necessiary to differentiate between system call arguments (syscallarg_t) and integer register values (register_t). Obtained from: CheriBSD Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D33780 --- sys/amd64/amd64/trap.c | 2 +- sys/arm/arm/syscall.c | 6 +++--- sys/arm64/arm64/trap.c | 4 ++-- sys/kern/kern_ktrace.c | 2 +- sys/kern/sys_process.c | 4 ++-- sys/riscv/riscv/trap.c | 4 ++-- sys/sys/ktrace.h | 2 +- sys/sys/proc.h | 2 +- sys/sys/ptrace.h | 2 +- sys/sys/types.h | 2 ++ sys/tools/makesyscalls.lua | 10 +++++----- sys/vm/vm_mmap.c | 2 +- usr.bin/truss/setup.c | 2 +- usr.bin/truss/syscall.h | 8 ++++---- usr.bin/truss/syscalls.c | 8 ++++---- usr.bin/truss/truss.h | 2 +- 16 files changed, 32 insertions(+), 30 deletions(-) diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index 8d8bdd6fbb6e..19b0c5065e68 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -1011,7 +1011,7 @@ cpu_fetch_syscall_args_fallback(struct thread *td, struct syscall_args *sa) { struct proc *p; struct trapframe *frame; - register_t *argp; + syscallarg_t *argp; caddr_t params; int reg, regcnt, error; diff --git a/sys/arm/arm/syscall.c b/sys/arm/arm/syscall.c index a635de0ec716..c083bf552eb5 100644 --- a/sys/arm/arm/syscall.c +++ b/sys/arm/arm/syscall.c @@ -100,7 +100,7 @@ int cpu_fetch_syscall_args(struct thread *td) { struct proc *p; - register_t *ap; + syscallarg_t *ap; struct syscall_args *sa; u_int nap; int error; @@ -124,10 +124,10 @@ cpu_fetch_syscall_args(struct thread *td) else sa->callp = &p->p_sysent->sv_table[sa->code]; error = 0; - memcpy(sa->args, ap, nap * sizeof(register_t)); + memcpy(sa->args, ap, nap * sizeof(*sa->args)); if (sa->callp->sy_narg > nap) { error = copyin((void *)td->td_frame->tf_usr_sp, sa->args + - nap, (sa->callp->sy_narg - nap) * sizeof(register_t)); + nap, (sa->callp->sy_narg - nap) * sizeof(*sa->args)); } if (error == 0) { td->td_retval[0] = 0; diff --git a/sys/arm64/arm64/trap.c b/sys/arm64/arm64/trap.c index 226f69592952..b664501b62fa 100644 --- a/sys/arm64/arm64/trap.c +++ b/sys/arm64/arm64/trap.c @@ -134,7 +134,7 @@ int cpu_fetch_syscall_args(struct thread *td) { struct proc *p; - register_t *ap, *dst_ap; + syscallarg_t *ap, *dst_ap; struct syscall_args *sa; p = td->td_proc; @@ -159,7 +159,7 @@ cpu_fetch_syscall_args(struct thread *td) KASSERT(sa->callp->sy_narg <= nitems(sa->args), ("Syscall %d takes too many arguments", sa->code)); - memcpy(dst_ap, ap, (nitems(sa->args) - 1) * sizeof(register_t)); + memcpy(dst_ap, ap, (nitems(sa->args) - 1) * sizeof(*dst_ap)); td->td_retval[0] = 0; td->td_retval[1] = 0; diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index f102f7e7b0a4..be3081ac9983 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -524,7 +524,7 @@ ktr_get_tracevp(struct proc *p, bool ref) } void -ktrsyscall(int code, int narg, register_t args[]) +ktrsyscall(int code, int narg, syscallarg_t args[]) { struct ktr_request *req; struct ktr_syscall *ktp; diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 965e22a38598..ce8529bee256 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -596,7 +596,7 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap) struct fpreg fpreg; struct reg reg; struct iovec vec; - char args[sizeof(td->td_sa.args)]; + syscallarg_t args[nitems(td->td_sa.args)]; struct ptrace_sc_ret psr; int ptevents; } r; @@ -1143,7 +1143,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) /* See the explanation in linux_ptrace_get_syscall_info(). */ bcopy(td2->td_sa.args, addr, SV_PROC_ABI(td->td_proc) == SV_ABI_LINUX ? sizeof(td2->td_sa.args) : - td2->td_sa.callp->sy_narg * sizeof(register_t)); + td2->td_sa.callp->sy_narg * sizeof(syscallarg_t)); break; case PT_GET_SC_RET: diff --git a/sys/riscv/riscv/trap.c b/sys/riscv/riscv/trap.c index b89eae325e0c..0744f5a25fb3 100644 --- a/sys/riscv/riscv/trap.c +++ b/sys/riscv/riscv/trap.c @@ -94,7 +94,7 @@ int cpu_fetch_syscall_args(struct thread *td) { struct proc *p; - register_t *ap, *dst_ap; + syscallarg_t *ap, *dst_ap; struct syscall_args *sa; p = td->td_proc; @@ -119,7 +119,7 @@ cpu_fetch_syscall_args(struct thread *td) KASSERT(sa->callp->sy_narg <= nitems(sa->args), ("Syscall %d takes too many arguments", sa->code)); - memcpy(dst_ap, ap, (NARGREG - 1) * sizeof(register_t)); + memcpy(dst_ap, ap, (NARGREG - 1) * sizeof(*dst_ap)); td->td_retval[0] = 0; td->td_retval[1] = 0; diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index 283a95c36d6c..d00981a93d24 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -284,7 +284,7 @@ void ktrpsig(int, sig_t, sigset_t *, int); void ktrfault(vm_offset_t, int); void ktrfaultend(int); void ktrgenio(int, enum uio_rw, struct uio *, int); -void ktrsyscall(int, int narg, register_t args[]); +void ktrsyscall(int, int narg, syscallarg_t args[]); void ktrsysctl(int *name, u_int namelen); void ktrsysret(int, int, register_t); void ktrprocctor(struct proc *); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 71105239e40e..2556fd574d84 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -357,7 +357,7 @@ struct thread { } td_state; /* (t) thread state */ /* Note: td_state must be accessed using TD_{GET,SET}_STATE(). */ union { - register_t tdu_retval[2]; + syscallarg_t tdu_retval[2]; off_t tdu_off; } td_uretoff; /* (k) Syscall aux returns. */ #define td_retval td_uretoff.tdu_retval diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index 197ac1692dfb..80797f290a41 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -162,7 +162,7 @@ struct ptrace_lwpinfo32 { /* Argument structure for PT_GET_SC_RET. */ struct ptrace_sc_ret { - register_t sr_retval[2]; /* Only valid if sr_error == 0. */ + syscallarg_t sr_retval[2]; /* Only valid if sr_error == 0. */ int sr_error; }; diff --git a/sys/sys/types.h b/sys/sys/types.h index 66f11aa3e31d..d37ab8b823dc 100644 --- a/sys/sys/types.h +++ b/sys/sys/types.h @@ -270,6 +270,8 @@ typedef __vm_size_t vm_size_t; typedef __rman_res_t rman_res_t; +typedef __register_t syscallarg_t; + #ifdef _KERNEL typedef int boolean_t; typedef struct _device *device_t; diff --git a/sys/tools/makesyscalls.lua b/sys/tools/makesyscalls.lua index 178869d03b0e..ec79ae30d130 100644 --- a/sys/tools/makesyscalls.lua +++ b/sys/tools/makesyscalls.lua @@ -860,7 +860,7 @@ local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype, write_line("sysarg", "};\n") else write_line("sysarg", string.format( - "struct %s {\n\tregister_t dummy;\n};\n", argalias)) + "struct %s {\n\tsyscallarg_t dummy;\n};\n", argalias)) end end @@ -986,7 +986,7 @@ local function handle_compat(sysnum, thr_flag, flags, sysflags, rettype, write_line(out, "};\n") elseif flags & nargflags == 0 then write_line("sysarg", string.format( - "struct %s {\n\tregister_t dummy;\n};\n", argalias)) + "struct %s {\n\tsyscallarg_t dummy;\n};\n", argalias)) end if flags & dprotoflags == 0 then write_line(outdcl, string.format( @@ -1439,8 +1439,8 @@ struct proc; struct thread; -#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ - 0 : sizeof(register_t) - sizeof(t)) +#define PAD_(t) (sizeof(syscallarg_t) <= sizeof(t) ? \ + 0 : sizeof(syscallarg_t) - sizeof(t)) #if BYTE_ORDER == LITTLE_ENDIAN #define PADL_(t) 0 @@ -1530,7 +1530,7 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz) process_sysfile(sysfile) write_line("sysinc", - "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n") + "\n#define AS(name) (sizeof(struct name) / sizeof(syscallarg_t))\n") for _, v in pairs(compat_options) do if v["count"] > 0 then diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 8ad049ed6d5e..db9a32d1c9bc 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -420,7 +420,7 @@ kern_mmap(struct thread *td, const struct mmap_req *mrp) } if (error == 0) - td->td_retval[0] = (register_t) (addr + pageoff); + td->td_retval[0] = addr + pageoff; done: if (fp) fdrop(fp, td); diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c index b5a1d4e32d2b..db5361a88e86 100644 --- a/usr.bin/truss/setup.c +++ b/usr.bin/truss/setup.c @@ -561,7 +561,7 @@ exit_syscall(struct trussinfo *info, struct ptrace_lwpinfo *pl) */ if (psr.sr_error != 0) { asprintf(&temp, "0x%lx", - t->cs.args[sc->decode.args[i].offset]); + (long)t->cs.args[sc->decode.args[i].offset]); } else { temp = print_arg(&sc->decode.args[i], t->cs.args, psr.sr_retval, info); diff --git a/usr.bin/truss/syscall.h b/usr.bin/truss/syscall.h index 53a1fd6ee8d7..c16aed732230 100644 --- a/usr.bin/truss/syscall.h +++ b/usr.bin/truss/syscall.h @@ -228,7 +228,7 @@ struct syscall { }; struct syscall *get_syscall(struct threadinfo *, u_int, u_int); -char *print_arg(struct syscall_arg *, unsigned long *, register_t *, +char *print_arg(struct syscall_arg *, syscallarg_t *, syscallarg_t *, struct trussinfo *); /* @@ -252,8 +252,8 @@ char *print_arg(struct syscall_arg *, unsigned long *, register_t *, #define LINUX_SENDMSG 16 #define LINUX_RECVMSG 17 -#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ - 0 : sizeof(register_t) - sizeof(t)) +#define PAD_(t) (sizeof(syscallarg_t) <= sizeof(t) ? \ + 0 : sizeof(syscallarg_t) - sizeof(t)) #if BYTE_ORDER == LITTLE_ENDIAN #define PADL_(t) 0 @@ -272,5 +272,5 @@ struct linux_socketcall_args { }; void print_syscall(struct trussinfo *); -void print_syscall_ret(struct trussinfo *, int, register_t *); +void print_syscall_ret(struct trussinfo *, int, syscallarg_t *); void print_summary(struct trussinfo *trussinfo); diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index d611f3f73471..bd055fb687ed 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -1558,7 +1558,7 @@ user_ptr32_to_psaddr(int32_t user_pointer) * an array of all of the system call arguments. */ char * -print_arg(struct syscall_arg *sc, unsigned long *args, register_t *retval, +print_arg(struct syscall_arg *sc, syscallarg_t *args, syscallarg_t *retval, struct trussinfo *trussinfo) { FILE *fp; @@ -1592,10 +1592,10 @@ print_arg(struct syscall_arg *sc, unsigned long *args, register_t *retval, break; } case LongHex: - fprintf(fp, "0x%lx", args[sc->offset]); + fprintf(fp, "0x%lx", (long)args[sc->offset]); break; case Long: - fprintf(fp, "%ld", args[sc->offset]); + fprintf(fp, "%ld", (long)args[sc->offset]); break; case Sizet: fprintf(fp, "%zu", (size_t)args[sc->offset]); @@ -2734,7 +2734,7 @@ print_syscall(struct trussinfo *trussinfo) } void -print_syscall_ret(struct trussinfo *trussinfo, int error, register_t *retval) +print_syscall_ret(struct trussinfo *trussinfo, int error, syscallarg_t *retval) { struct timespec timediff; struct threadinfo *t; diff --git a/usr.bin/truss/truss.h b/usr.bin/truss/truss.h index a3ce8f27d953..4d2680cd4913 100644 --- a/usr.bin/truss/truss.h +++ b/usr.bin/truss/truss.h @@ -81,7 +81,7 @@ struct current_syscall { struct syscall *sc; unsigned int number; unsigned int nargs; - unsigned long args[10]; + syscallarg_t args[10]; char *s_args[10]; /* the printable arguments */ };