git: 7c9060c7f38c - main - pdfork(2): add kern_pdfork

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Mon, 09 Nov 2026 11:54:21 UTC
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=7c9060c7f38cf07908ee37baa0205848ea2bdaba

commit 7c9060c7f38cf07908ee37baa0205848ea2bdaba
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2025-11-21 17:33:07 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-09 11:28:00 +0000

    pdfork(2): add kern_pdfork
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/kern_fork.c  | 16 +++++++++++-----
 sys/sys/syscallsubr.h |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index a456f0ac1490..839fa1c440f7 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -70,9 +70,9 @@
 #include <sys/syscallsubr.h>
 #include <sys/sysent.h>
 #include <sys/sysproto.h>
+#include <sys/unistd.h>
 #include <sys/vmmeter.h>
 #include <sys/vnode.h>
-#include <sys/unistd.h>
 
 #include <security/audit/audit.h>
 #include <security/mac/mac_framework.h>
@@ -123,6 +123,12 @@ sys_fork(struct thread *td, struct fork_args *uap)
 /* ARGUSED */
 int
 sys_pdfork(struct thread *td, struct pdfork_args *uap)
+{
+	return (kern_pdfork(td, uap->fdp, uap->flags));
+}
+
+int
+kern_pdfork(struct thread *td, int *fdp, int flags)
 {
 	struct fork_req fr;
 	struct filecaps fcaps;
@@ -132,12 +138,12 @@ sys_pdfork(struct thread *td, struct pdfork_args *uap)
 	fr.fr_flags = RFFDG | RFPROC | RFPROCDESC;
 	fr.fr_pidp = &pid;
 	fr.fr_pd_fd = &fd;
-	fr.fr_pd_flags = uap->flags;
+	fr.fr_pd_flags = flags;
 	filecaps_fill(&fcaps);
-	if ((uap->flags & PD_PTRACE_CAP) == 0)
+	if ((flags & PD_PTRACE_CAP) == 0)
 		cap_rights_clear(&fcaps.fc_rights, CAP_PTRACE);
 	fr.fr_pd_fcaps = &fcaps;
-	AUDIT_ARG_FFLAGS(uap->flags);
+	AUDIT_ARG_FFLAGS(flags);
 	/*
 	 * It is necessary to return fd by reference because 0 is a valid file
 	 * descriptor number, and the child needs to be able to distinguish
@@ -147,7 +153,7 @@ sys_pdfork(struct thread *td, struct pdfork_args *uap)
 	if (error == 0) {
 		td->td_retval[0] = pid;
 		td->td_retval[1] = 0;
-		error = copyout(&fd, uap->fdp, sizeof(fd));
+		error = copyout(&fd, fdp, sizeof(fd));
 	}
 	return (error);
 }
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 5f91185729cc..fc452fe88647 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -348,6 +348,7 @@ int	kern_openatfp(struct thread *td, int dirfd, const char *path,
 	    enum uio_seg pathseg, int flags, int mode, struct file **fpp);
 int	kern_pathconf(struct thread *td, const char *path,
 	    enum uio_seg pathseg, int name, u_long flags, long *valuep);
+int	kern_pdfork(struct thread *td, int *fdp, int flags);
 int	kern_pipe(struct thread *td, int fildes[2], int flags,
 	    struct filecaps *fcaps1, struct filecaps *fcaps2);
 int	kern_poll(struct thread *td, struct pollfd *fds, u_int nfds,