Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Jan 2009 16:49:17 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 156293 for review
Message-ID:  <200901171649.n0HGnHmX000167@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=156293

Change 156293 by rwatson@rwatson_freebsd_capabilities on 2009/01/17 16:48:44

	Return the process descriptor from pdfork() by reference, as 0
	is a valid file descriptor number, and the child needs to be able
	to check for 0 in order to tell if it is the child or not.

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/sys/kern/init_sysent.c#22 edit
.. //depot/projects/trustedbsd/capabilities/src/sys/kern/kern_fork.c#6 edit
.. //depot/projects/trustedbsd/capabilities/src/sys/kern/syscalls.c#23 edit
.. //depot/projects/trustedbsd/capabilities/src/sys/kern/syscalls.master#15 edit
.. //depot/projects/trustedbsd/capabilities/src/sys/kern/systrace_args.c#23 edit
.. //depot/projects/trustedbsd/capabilities/src/sys/sys/syscall.h#23 edit
.. //depot/projects/trustedbsd/capabilities/src/sys/sys/syscall.mk#23 edit
.. //depot/projects/trustedbsd/capabilities/src/sys/sys/sysproto.h#23 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/sys/kern/init_sysent.c#22 (text+ko) ====

@@ -538,7 +538,7 @@
 	{ AS(cap_getrights_args), (sy_call_t *)cap_getrights, AUE_CAP_GETRIGHTS, NULL, 0, 0, SYF_CAPENABLED },	/* 507 = cap_getrights */
 	{ 0, (sy_call_t *)cap_enter, AUE_CAP_ENTER, NULL, 0, 0, SYF_CAPENABLED },	/* 508 = cap_enter */
 	{ AS(cap_getmode_args), (sy_call_t *)cap_getmode, AUE_CAP_GETMODE, NULL, 0, 0, SYF_CAPENABLED },	/* 509 = cap_getmode */
-	{ 0, (sy_call_t *)pdfork, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED },		/* 510 = pdfork */
+	{ AS(pdfork_args), (sy_call_t *)pdfork, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED },	/* 510 = pdfork */
 	{ AS(pdkill_args), (sy_call_t *)pdkill, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED },	/* 511 = pdkill */
 	{ AS(pdgetpid_args), (sy_call_t *)pdgetpid, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED },	/* 512 = pdgetpid */
 	{ AS(pdwait4_args), (sy_call_t *)pdwait4, AUE_NULL, NULL, 0, 0, SYF_CAPENABLED },	/* 513 = pdwait4 */

==== //depot/projects/trustedbsd/capabilities/src/sys/kern/kern_fork.c#6 (text+ko) ====

@@ -121,13 +121,25 @@
 	struct pdfork_args *uap;
 {
 #ifdef PROCDESC
-	int error;
+	int error, fd;
 	struct proc *p2;
 
+	/*
+	 * XXXRW: For now, we play a slight game here to avoid changing the
+	 * arguments to fork1() - when a process descriptor is requested, we
+	 * will initially return the file descriptor via td_retval[0], then
+	 * in pdfork(), we copy that out and replace the retval with the pid.
+	 *
+	 * It is necessary to return fd by reference as 0 is a valid file
+	 * descriptor number, and the child needs to be able to distinguish
+	 * itself from the parent using the return value.
+	 */
 	error = fork1(td, RFFDG | RFPROC | RFPROCDESC, 0, &p2);
 	if (error == 0) {
-		/* td->td_retval[0] will be set to fd in fork1(). */
+		fd = td->td_retval[0];
+		td->td_retval[0] = p2->p_pid;
 		td->td_retval[1] = 0;
+		error = copyout(&fd, uap->fdp, sizeof(fd));
 	}
 	return (error);
 #else

==== //depot/projects/trustedbsd/capabilities/src/sys/kern/syscalls.c#23 (text+ko) ====


==== //depot/projects/trustedbsd/capabilities/src/sys/kern/syscalls.master#15 (text+ko) ====

@@ -910,7 +910,7 @@
 ;
 ; Process descriptor system calls.  These need audit event identifiers.
 ;
-510	AUE_NULL	STD	{ int pdfork(void); }
+510	AUE_NULL	STD	{ int pdfork(int *fdp); }
 511	AUE_NULL	STD	{ int pdkill(int fd, int signum); }
 512	AUE_NULL	STD	{ int pdgetpid(int fd, pid_t *pidp); }
 513	AUE_NULL	STD	{ int pdwait4(int fd, int *status, \

==== //depot/projects/trustedbsd/capabilities/src/sys/kern/systrace_args.c#23 (text+ko) ====

@@ -3070,7 +3070,9 @@
 	}
 	/* pdfork */
 	case 510: {
-		*n_args = 0;
+		struct pdfork_args *p = params;
+		uarg[0] = (intptr_t) p->fdp; /* int * */
+		*n_args = 1;
 		break;
 	}
 	/* pdkill */
@@ -8170,6 +8172,13 @@
 		break;
 	/* pdfork */
 	case 510:
+		switch(ndx) {
+		case 0:
+			p = "int *";
+			break;
+		default:
+			break;
+		};
 		break;
 	/* pdkill */
 	case 511:

==== //depot/projects/trustedbsd/capabilities/src/sys/sys/syscall.h#23 (text+ko) ====


==== //depot/projects/trustedbsd/capabilities/src/sys/sys/syscall.mk#23 (text+ko) ====


==== //depot/projects/trustedbsd/capabilities/src/sys/sys/sysproto.h#23 (text+ko) ====

@@ -1640,7 +1640,7 @@
 	char modep_l_[PADL_(u_int *)]; u_int * modep; char modep_r_[PADR_(u_int *)];
 };
 struct pdfork_args {
-	register_t dummy;
+	char fdp_l_[PADL_(int *)]; int * fdp; char fdp_r_[PADR_(int *)];
 };
 struct pdkill_args {
 	char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901171649.n0HGnHmX000167>