kern_fork.c (8d0f10857a48c0f5e04bf0cbe3d7443cb4f8051a) kern_fork.c (367a13f905874f6ad0a5f78cb88a4923cfe86e5e)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 90 unchanged lines hidden (view full) ---

99
100/* ARGSUSED */
101int
102sys_fork(struct thread *td, struct fork_args *uap)
103{
104 int error;
105 struct proc *p2;
106
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 90 unchanged lines hidden (view full) ---

99
100/* ARGSUSED */
101int
102sys_fork(struct thread *td, struct fork_args *uap)
103{
104 int error;
105 struct proc *p2;
106
107 error = fork1(td, RFFDG | RFPROC, 0, &p2, NULL, 0);
107 error = fork1(td, RFFDG | RFPROC, 0, &p2, NULL, 0, NULL);
108 if (error == 0) {
109 td->td_retval[0] = p2->p_pid;
110 td->td_retval[1] = 0;
111 }
112 return (error);
113}
114
115/* ARGUSED */

--- 6 unchanged lines hidden (view full) ---

122 struct proc *p2;
123
124 /*
125 * It is necessary to return fd by reference because 0 is a valid file
126 * descriptor number, and the child needs to be able to distinguish
127 * itself from the parent using the return value.
128 */
129 error = fork1(td, RFFDG | RFPROC | RFPROCDESC, 0, &p2,
108 if (error == 0) {
109 td->td_retval[0] = p2->p_pid;
110 td->td_retval[1] = 0;
111 }
112 return (error);
113}
114
115/* ARGUSED */

--- 6 unchanged lines hidden (view full) ---

122 struct proc *p2;
123
124 /*
125 * It is necessary to return fd by reference because 0 is a valid file
126 * descriptor number, and the child needs to be able to distinguish
127 * itself from the parent using the return value.
128 */
129 error = fork1(td, RFFDG | RFPROC | RFPROCDESC, 0, &p2,
130 &fd, uap->flags);
130 &fd, uap->flags, NULL);
131 if (error == 0) {
132 td->td_retval[0] = p2->p_pid;
133 td->td_retval[1] = 0;
134 error = copyout(&fd, uap->fdp, sizeof(fd));
135 }
136 return (error);
137}
138
139/* ARGSUSED */
140int
141sys_vfork(struct thread *td, struct vfork_args *uap)
142{
143 int error, flags;
144 struct proc *p2;
145
146 flags = RFFDG | RFPROC | RFPPWAIT | RFMEM;
131 if (error == 0) {
132 td->td_retval[0] = p2->p_pid;
133 td->td_retval[1] = 0;
134 error = copyout(&fd, uap->fdp, sizeof(fd));
135 }
136 return (error);
137}
138
139/* ARGSUSED */
140int
141sys_vfork(struct thread *td, struct vfork_args *uap)
142{
143 int error, flags;
144 struct proc *p2;
145
146 flags = RFFDG | RFPROC | RFPPWAIT | RFMEM;
147 error = fork1(td, flags, 0, &p2, NULL, 0);
147 error = fork1(td, flags, 0, &p2, NULL, 0, NULL);
148 if (error == 0) {
149 td->td_retval[0] = p2->p_pid;
150 td->td_retval[1] = 0;
151 }
152 return (error);
153}
154
155int
156sys_rfork(struct thread *td, struct rfork_args *uap)
157{
158 struct proc *p2;
159 int error;
160
161 /* Don't allow kernel-only flags. */
162 if ((uap->flags & RFKERNELONLY) != 0)
163 return (EINVAL);
164
165 AUDIT_ARG_FFLAGS(uap->flags);
148 if (error == 0) {
149 td->td_retval[0] = p2->p_pid;
150 td->td_retval[1] = 0;
151 }
152 return (error);
153}
154
155int
156sys_rfork(struct thread *td, struct rfork_args *uap)
157{
158 struct proc *p2;
159 int error;
160
161 /* Don't allow kernel-only flags. */
162 if ((uap->flags & RFKERNELONLY) != 0)
163 return (EINVAL);
164
165 AUDIT_ARG_FFLAGS(uap->flags);
166 error = fork1(td, uap->flags, 0, &p2, NULL, 0);
166 error = fork1(td, uap->flags, 0, &p2, NULL, 0, NULL);
167 if (error == 0) {
168 td->td_retval[0] = p2 ? p2->p_pid : 0;
169 td->td_retval[1] = 0;
170 }
171 return (error);
172}
173
174int nprocs = 1; /* process 0 */

--- 588 unchanged lines hidden (view full) ---

763 cv_wait(&p2->p_dbgwait, &p2->p_mtx);
764 if (p2_held)
765 _PRELE(p2);
766 PROC_UNLOCK(p2);
767}
768
769int
770fork1(struct thread *td, int flags, int pages, struct proc **procp,
167 if (error == 0) {
168 td->td_retval[0] = p2 ? p2->p_pid : 0;
169 td->td_retval[1] = 0;
170 }
171 return (error);
172}
173
174int nprocs = 1; /* process 0 */

--- 588 unchanged lines hidden (view full) ---

763 cv_wait(&p2->p_dbgwait, &p2->p_mtx);
764 if (p2_held)
765 _PRELE(p2);
766 PROC_UNLOCK(p2);
767}
768
769int
770fork1(struct thread *td, int flags, int pages, struct proc **procp,
771 int *procdescp, int pdflags)
771 int *procdescp, int pdflags, struct filecaps *fcaps)
772{
773 struct proc *p1;
774 struct proc *newproc;
775 int ok;
776 struct thread *td2;
777 struct vmspace *vm2;
778 vm_ooffset_t mem_charged;
779 int error;

--- 39 unchanged lines hidden (view full) ---

819 }
820
821 /*
822 * If required, create a process descriptor in the parent first; we
823 * will abandon it if something goes wrong. We don't finit() until
824 * later.
825 */
826 if (flags & RFPROCDESC) {
772{
773 struct proc *p1;
774 struct proc *newproc;
775 int ok;
776 struct thread *td2;
777 struct vmspace *vm2;
778 vm_ooffset_t mem_charged;
779 int error;

--- 39 unchanged lines hidden (view full) ---

819 }
820
821 /*
822 * If required, create a process descriptor in the parent first; we
823 * will abandon it if something goes wrong. We don't finit() until
824 * later.
825 */
826 if (flags & RFPROCDESC) {
827 error = falloc(td, &fp_procdesc, procdescp, 0);
827 error = falloc_caps(td, &fp_procdesc, procdescp, 0,
828 fcaps);
828 if (error != 0)
829 return (error);
830 }
831
832 mem_charged = 0;
833 vm2 = NULL;
834 if (pages == 0)
835 pages = KSTACK_PAGES;

--- 237 unchanged lines hidden ---
829 if (error != 0)
830 return (error);
831 }
832
833 mem_charged = 0;
834 vm2 = NULL;
835 if (pages == 0)
836 pages = KSTACK_PAGES;

--- 237 unchanged lines hidden ---