The branch main has been updated by sjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=586838724e4086016ad62f0914248fc58ce26e35

commit 586838724e4086016ad62f0914248fc58ce26e35
Author:     Simon J. Gerraty <[email protected]>
AuthorDate: 2026-05-07 03:49:06 +0000
Commit:     Simon J. Gerraty <[email protected]>
CommitDate: 2026-05-07 03:49:06 +0000

    Remove PROC_CHECK_PRIV macro from sys_process.c
    
    Just put the priv_check calls in the code.
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D56864
---
 sys/kern/sys_process.c | 59 ++++++++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 19 deletions(-)

diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 487dc5d06614..dece6457a4bf 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -72,13 +72,6 @@
 /* Assert it's safe to unlock a process, e.g. to allocate working memory */
 #define        PROC_ASSERT_TRACEREQ(p) MPASS(((p)->p_flag2 & P2_PTRACEREQ) != 
0)
 
-#define PROC_PRIV_CHECK(priv) do {                             \
-               int _error;                                     \
-               _error = priv_check(curthread, priv);   \
-               if (_error)                                     \
-                       return (_error);                        \
-       } while (0)
-
 /*
  * Functions implemented below:
  *
@@ -115,8 +108,12 @@ proc_read_regs(struct thread *td, struct reg *regs)
 int
 proc_write_regs(struct thread *td, struct reg *regs)
 {
+       int error;
+
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+       error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+       if (error != 0)
+               return (error);
        return (set_regs(td, regs));
 }
 
@@ -130,8 +127,12 @@ proc_read_dbregs(struct thread *td, struct dbreg *dbregs)
 int
 proc_write_dbregs(struct thread *td, struct dbreg *dbregs)
 {
+       int error;
+
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+       error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+       if (error != 0)
+               return (error);
        return (set_dbregs(td, dbregs));
 }
 
@@ -149,8 +150,12 @@ proc_read_fpregs(struct thread *td, struct fpreg *fpregs)
 int
 proc_write_fpregs(struct thread *td, struct fpreg *fpregs)
 {
+       int error;
+
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+       error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+       if (error != 0)
+               return (error);
        return (set_fpregs(td, fpregs));
 }
 
@@ -271,7 +276,9 @@ proc_write_regset(struct thread *td, int note, struct iovec 
*iov)
        if (regset->set == NULL)
                return (EINVAL);
 
-       PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+       error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+       if (error != 0)
+               return (error);
 
        p = td->td_proc;
 
@@ -305,8 +312,12 @@ proc_read_regs32(struct thread *td, struct reg32 *regs32)
 int
 proc_write_regs32(struct thread *td, struct reg32 *regs32)
 {
+       int error;
+
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+       error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+       if (error != 0)
+               return (error);
        return (set_regs32(td, regs32));
 }
 
@@ -320,8 +331,12 @@ proc_read_dbregs32(struct thread *td, struct dbreg32 
*dbregs32)
 int
 proc_write_dbregs32(struct thread *td, struct dbreg32 *dbregs32)
 {
+       int error;
+
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+       error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+       if (error != 0)
+               return (error);
        return (set_dbregs32(td, dbregs32));
 }
 
@@ -335,8 +350,12 @@ proc_read_fpregs32(struct thread *td, struct fpreg32 
*fpregs32)
 int
 proc_write_fpregs32(struct thread *td, struct fpreg32 *fpregs32)
 {
+       int error;
+
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+       error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+       if (error != 0)
+               return (error);
        return (set_fpregs32(td, fpregs32));
 }
 #endif
@@ -378,7 +397,9 @@ proc_rwmem(struct proc *p, struct uio *uio)
        fault_flags = writing ? VM_FAULT_DIRTY : VM_FAULT_NORMAL;
 
        if (writing) {
-               PROC_PRIV_CHECK(PRIV_PROC_MEM_WRITE);
+               error = priv_check(curthread, PRIV_PROC_MEM_WRITE);
+               if (error != 0)
+                       return (error);
        }
 
        /*
@@ -710,11 +731,11 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap)
                addr = uap->addr;
                break;
        }
-       if (error)
+       if (error != 0)
                return (error);
 
        error = kern_ptrace(td, uap->req, uap->pid, addr, uap->data);
-       if (error)
+       if (error != 0)
                return (error);
 
        switch (uap->req) {
@@ -1250,7 +1271,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void 
*addr, int data)
                        CTR3(KTR_PTRACE, "PT_STEP: tid %d (pid %d), sig = %d",
                            td2->td_tid, p->p_pid, data);
                        error = ptrace_single_step(td2);
-                       if (error)
+                       if (error != 0)
                                goto out;
                        break;
                case PT_CONTINUE:
@@ -1260,7 +1281,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void 
*addr, int data)
                        if (addr != (void *)1) {
                                error = ptrace_set_pc(td2,
                                    (u_long)(uintfptr_t)addr);
-                               if (error)
+                               if (error != 0)
                                        goto out;
                                td2->td_dbgflags |= TDB_USERWR;
                        }

Reply via email to