Slight tweak to fork1() calling conventions. Add a third argument so

the caller can easily find the child proc struct.  fork(), rfork() etc
syscalls set p->p_retval[] themselves.  Simplify the SYSINIT_KT() code
and other kernel thread creators to not need to use pfind() to find the
child based on the pid.  While here, partly tidy up some of the fork1()
code for RF_SIGSHARE etc.
This commit is contained in:
Peter Wemm 1999-06-30 15:33:41 +00:00
parent fbf8dd228a
commit df8abd0bb9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=48377
5 changed files with 65 additions and 54 deletions

View File

@ -39,7 +39,7 @@
* SUCH DAMAGE.
*
* @(#)init_main.c 8.9 (Berkeley) 1/21/94
* $Id: init_main.c,v 1.121 1999/05/09 20:42:45 peter Exp $
* $Id: init_main.c,v 1.122 1999/05/11 10:08:10 jb Exp $
*/
#include "opt_devfs.h"
@ -180,6 +180,7 @@ mi_startup(framep)
register struct sysinit **sipp; /* system initialization*/
register struct sysinit **xipp; /* interior loop of sort*/
register struct sysinit *save; /* bubble*/
struct proc *p2;
/*
* Copy the locore.s frame pointer for proc0, this is forked into
@ -227,17 +228,15 @@ mi_startup(framep)
case SI_TYPE_KTHREAD:
/* kernel thread*/
if (fork1(&proc0, RFMEM|RFFDG|RFPROC))
if (fork1(&proc0, RFMEM|RFFDG|RFPROC, &p2))
panic("fork kernel thread");
cpu_set_fork_handler(pfind(proc0.p_retval[0]),
(*sipp)->func, (*sipp)->udata);
cpu_set_fork_handler(p2, (*sipp)->func, (*sipp)->udata);
break;
case SI_TYPE_KPROCESS:
if (fork1(&proc0, RFFDG|RFPROC))
if (fork1(&proc0, RFFDG|RFPROC, &p2))
panic("fork kernel process");
cpu_set_fork_handler(pfind(proc0.p_retval[0]),
(*sipp)->func, (*sipp)->udata);
cpu_set_fork_handler(p2, (*sipp)->func, (*sipp)->udata);
break;
default:

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_fork.c 8.6 (Berkeley) 4/8/94
* $Id: kern_fork.c,v 1.60 1999/04/28 01:04:27 luoqi Exp $
* $Id: kern_fork.c,v 1.61 1999/04/28 11:36:53 phk Exp $
*/
#include "opt_ktrace.h"
@ -92,8 +92,15 @@ fork(p, uap)
struct proc *p;
struct fork_args *uap;
{
int error;
struct proc *p2;
return (fork1(p, RFFDG | RFPROC));
error = fork1(p, RFFDG | RFPROC, &p2);
if (error == 0) {
p->p_retval[0] = p2->p_pid;
p->p_retval[1] = 0;
}
return error;
}
/* ARGSUSED */
@ -102,18 +109,31 @@ vfork(p, uap)
struct proc *p;
struct vfork_args *uap;
{
int error;
struct proc *p2;
return (fork1(p, RFFDG | RFPROC | RFPPWAIT | (fast_vfork ? RFMEM : 0)));
error = fork1(p, RFFDG | RFPROC | RFPPWAIT | RFMEM, &p2);
if (error == 0) {
p->p_retval[0] = p2->p_pid;
p->p_retval[1] = 0;
}
return error;
}
/* ARGSUSED */
int
rfork(p, uap)
struct proc *p;
struct rfork_args *uap;
{
int error;
struct proc *p2;
return (fork1(p, uap->flags));
error = fork1(p, uap->flags, &p2);
if (error == 0) {
p->p_retval[0] = p2->p_pid;
p->p_retval[1] = 0;
}
return error;
}
@ -121,12 +141,13 @@ int nprocs = 1; /* process 0 */
static int nextpid = 0;
int
fork1(p1, flags)
register struct proc *p1;
fork1(p1, flags, procp)
struct proc *p1;
int flags;
struct proc **procp;
{
register struct proc *p2, *pptr;
register uid_t uid;
struct proc *p2, *pptr;
uid_t uid;
struct proc *newproc;
int count;
static int pidchecked = 0;
@ -213,9 +234,9 @@ fork1(p1, flags)
/* Allocate new proc. */
newproc = zalloc(proc_zone);
/*
* Setup linkage for kernel based threading
*/
/*
* Setup linkage for kernel based threading
*/
if((flags & RFTHREAD) != 0) {
newproc->p_peers = p1->p_peers;
p1->p_peers = newproc;
@ -321,31 +342,28 @@ fork1(p1, flags)
struct sigacts *newsigacts;
int s;
if (p2->p_procsig->ps_refcnt != 2)
printf ("PID:%d Creating shared sigacts with procsig->ps_refcnt %d\n",
p2->p_pid, p2->p_procsig->ps_refcnt);
/* Create the shared sigacts structure */
MALLOC (newsigacts, struct sigacts *, sizeof (struct sigacts),
M_SUBPROC, M_WAITOK);
MALLOC(newsigacts, struct sigacts *,
sizeof(struct sigacts), M_SUBPROC, M_WAITOK);
s = splhigh();
/* Set p_sigacts to the new shared structure. Note that this
* is updating p1->p_sigacts at the same time, since p_sigacts
* is just a pointer to the shared p_procsig->ps_sigacts.
/*
* Set p_sigacts to the new shared structure.
* Note that this is updating p1->p_sigacts at the
* same time, since p_sigacts is just a pointer to
* the shared p_procsig->ps_sigacts.
*/
p2->p_sigacts = newsigacts;
/* Copy in the values from the u area */
bcopy(&p1->p_addr->u_sigacts, p2->p_sigacts,
sizeof(*p2->p_sigacts));
*p2->p_sigacts = p1->p_addr->u_sigacts;
splx (s);
splx(s);
}
} else {
MALLOC (p2->p_procsig, struct procsig *, sizeof(struct procsig),
M_SUBPROC, M_WAITOK);
bcopy(&p1->p_procsig->ps_begincopy, &p2->p_procsig->ps_begincopy,
(char *)&p1->p_procsig->ps_endcopy -
(char *)&p1->p_procsig->ps_begincopy);
MALLOC(p2->p_procsig, struct procsig *, sizeof(struct procsig),
M_SUBPROC, M_WAITOK);
bcopy(p1->p_procsig, p2->p_procsig, sizeof(*p2->p_procsig));
p2->p_procsig->ps_refcnt = 1;
/* Note that we fill in the values of sigacts in vm_fork */
p2->p_sigacts = NULL;
p2->p_sigacts = NULL; /* finished in vm_fork() */
}
if (flags & RFLINUXTHPN)
p2->p_sigparent = SIGUSR1;
@ -467,11 +485,9 @@ fork1(p1, flags)
tsleep(p1, PWAIT, "ppwait", 0);
/*
* Return child pid to parent process,
* marking us as parent via p1->p_retval[1].
* Return child proc pointer to parent.
*/
p1->p_retval[0] = p2->p_pid;
p1->p_retval[1] = 0;
*procp = p2;
return (0);
}

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: kern_linker.c,v 1.31 1999/04/28 01:04:28 luoqi Exp $
* $Id: kern_linker.c,v 1.32 1999/05/08 13:01:56 peter Exp $
*/
#include "opt_ddb.h"
@ -96,6 +96,7 @@ linker_file_sysinit(linker_file_t lf)
struct sysinit** sipp;
struct sysinit** xipp;
struct sysinit* save;
struct proc *p2;
const moduledata_t *moddata;
int error;
@ -156,18 +157,16 @@ linker_file_sysinit(linker_file_t lf)
case SI_TYPE_KTHREAD:
/* kernel thread*/
if (fork1(&proc0, RFFDG|RFPROC|RFMEM))
if (fork1(&proc0, RFFDG|RFPROC|RFMEM, &p2))
panic("fork kernel thread");
cpu_set_fork_handler(pfind(proc0.p_retval[0]),
(*sipp)->func, (*sipp)->udata);
cpu_set_fork_handler(p2, (*sipp)->func, (*sipp)->udata);
break;
case SI_TYPE_KPROCESS:
/* kernel thread*/
if (fork1(&proc0, RFFDG|RFPROC))
if (fork1(&proc0, RFFDG|RFPROC, &p2))
panic("fork kernel process");
cpu_set_fork_handler(pfind(proc0.p_retval[0]),
(*sipp)->func, (*sipp)->udata);
cpu_set_fork_handler(p2, (*sipp)->func, (*sipp)->udata);
break;
default:

View File

@ -13,7 +13,7 @@
* bad that happens because of using this software isn't the responsibility
* of the author. This software is distributed AS-IS.
*
* $Id: vfs_aio.c,v 1.51 1999/06/01 18:56:24 phk Exp $
* $Id: vfs_aio.c,v 1.52 1999/06/26 02:46:05 mckusick Exp $
*/
/*
@ -890,10 +890,9 @@ aio_newproc()
struct proc *p, *np;
p = &proc0;
error = fork1(p, RFPROC|RFMEM|RFNOWAIT);
error = fork1(p, RFPROC|RFMEM|RFNOWAIT, &np);
if (error)
return error;
np = pfind(p->p_retval[0]);
cpu_set_fork_handler(np, aio_daemon, curproc);
/*

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)proc.h 8.15 (Berkeley) 5/19/95
* $Id: proc.h,v 1.81 1999/04/28 11:38:04 phk Exp $
* $Id: proc.h,v 1.82 1999/06/28 09:14:18 peter Exp $
*/
#ifndef _SYS_PROC_H_
@ -78,12 +78,10 @@ struct pgrp {
};
struct procsig {
#define ps_begincopy ps_sigignore
sigset_t ps_sigignore; /* Signals being ignored. */
sigset_t ps_sigcatch; /* Signals being caught by user. */
int ps_flag;
struct sigacts *ps_sigacts;
#define ps_endcopy ps_refcnt
int ps_refcnt;
};
@ -402,7 +400,7 @@ void exit1 __P((struct proc *, int)) __dead2;
void cpu_fork __P((struct proc *, struct proc *));
void cpu_set_fork_handler __P((struct proc *, void (*pc)(const void *),
const void *));
int fork1 __P((struct proc *, int));
int fork1 __P((struct proc *, int, struct proc **));
int trace_req __P((struct proc *));
void cpu_wait __P((struct proc *));
int cpu_coredump __P((struct proc *, struct vnode *, struct ucred *));