Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-6]: src Pull up following revision(s) (requested by martin in tic...
details: https://anonhg.NetBSD.org/src/rev/863639ded9db
branches: netbsd-6
changeset: 774000:863639ded9db
user: riz <riz%NetBSD.org@localhost>
date: Thu Apr 12 17:05:36 2012 +0000
description:
Pull up following revision(s) (requested by martin in ticket #175):
sys/kern/kern_exit.c: revision 1.238
tests/lib/libc/gen/posix_spawn/t_fileactions.c: revision 1.4
tests/lib/libc/gen/posix_spawn/t_fileactions.c: revision 1.5
sys/uvm/uvm_extern.h: revision 1.183
lib/libc/gen/posix_spawn_fileactions.c: revision 1.2
sys/kern/kern_exec.c: revision 1.348
sys/kern/kern_exec.c: revision 1.349
sys/compat/netbsd32/syscalls.master: revision 1.95
sys/uvm/uvm_glue.c: revision 1.159
sys/uvm/uvm_map.c: revision 1.317
sys/compat/netbsd32/netbsd32.h: revision 1.95
sys/kern/exec_elf.c: revision 1.38
sys/sys/spawn.h: revision 1.2
sys/sys/exec.h: revision 1.135
sys/compat/netbsd32/netbsd32_execve.c: revision 1.34
Rework posix_spawn locking and memory management:
- always provide a vmspace for the new proc, initially borrowing from proc0
(this part fixes PR 46286)
- increase parallelism between parent and child if arguments allow this,
avoiding a potential deadlock on exec_lock
- add a new flag for userland to request old (lockstepped) behaviour for
better error reporting
- adapt test cases to the previous two and add a new variant to test the
diagnostics flag
- fix a few memory (and lock) leaks
- provide netbsd32 compat
Fix asynchronous posix_spawn child exit status (and test for it).
diffstat:
lib/libc/gen/posix_spawn_fileactions.c | 8 +-
sys/compat/netbsd32/netbsd32.h | 28 +-
sys/compat/netbsd32/netbsd32_execve.c | 145 +++++++++-
sys/compat/netbsd32/syscalls.master | 9 +-
sys/kern/exec_elf.c | 7 +-
sys/kern/kern_exec.c | 394 ++++++++++++++++--------
sys/kern/kern_exit.c | 13 +-
sys/sys/exec.h | 11 +-
sys/sys/spawn.h | 23 +-
sys/uvm/uvm_extern.h | 3 +-
sys/uvm/uvm_glue.c | 14 +-
sys/uvm/uvm_map.c | 40 +-
tests/lib/libc/gen/posix_spawn/t_fileactions.c | 54 +++-
13 files changed, 569 insertions(+), 180 deletions(-)
diffs (truncated from 1307 to 300 lines):
diff -r e07436dbac99 -r 863639ded9db lib/libc/gen/posix_spawn_fileactions.c
--- a/lib/libc/gen/posix_spawn_fileactions.c Mon Apr 09 18:17:45 2012 +0000
+++ b/lib/libc/gen/posix_spawn_fileactions.c Thu Apr 12 17:05:36 2012 +0000
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: posix_spawn_fileactions.c,v 1.1 2012/02/11 23:31:24 martin Exp $");
+__RCSID("$NetBSD: posix_spawn_fileactions.c,v 1.1.2.1 2012/04/12 17:05:37 riz Exp $");
#include "namespace.h"
@@ -62,7 +62,7 @@
int
posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *fa)
{
- int i;
+ unsigned int i;
if (fa == NULL)
return (-1);
@@ -80,7 +80,7 @@
posix_spawn_file_actions_getentry(posix_spawn_file_actions_t *fa)
{
if (fa == NULL)
- return (-1);
+ return -1;
if (fa->len < fa->size)
return fa->len;
@@ -89,7 +89,7 @@
sizeof(struct posix_spawn_file_actions_entry));
if (fa->fae == NULL)
- return (-1);
+ return -1;
fa->size += MIN_SIZE;
diff -r e07436dbac99 -r 863639ded9db sys/compat/netbsd32/netbsd32.h
--- a/sys/compat/netbsd32/netbsd32.h Mon Apr 09 18:17:45 2012 +0000
+++ b/sys/compat/netbsd32/netbsd32.h Thu Apr 12 17:05:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32.h,v 1.92 2012/02/01 05:46:46 dholland Exp $ */
+/* $NetBSD: netbsd32.h,v 1.92.2.1 2012/04/12 17:05:37 riz Exp $ */
/*
* Copyright (c) 1998, 2001, 2008 Matthew R. Green
@@ -151,6 +151,10 @@
typedef netbsd32_pointer_t netbsd32_ucontextp;
typedef netbsd32_pointer_t netbsd32_caddr_t;
typedef netbsd32_pointer_t netbsd32_lwpctlp;
+typedef netbsd32_pointer_t netbsd32_posix_spawn_file_actionsp;
+typedef netbsd32_pointer_t netbsd32_posix_spawnattrp;
+typedef netbsd32_pointer_t netbsd32_posix_spawn_file_actions_entryp;
+typedef netbsd32_pointer_t netbsd32_pid_tp;
/*
* now, the compatibility structures and their fake pointer types.
@@ -935,6 +939,28 @@
netbsd32_charp hostname; /* server's name */
};
+struct netbsd32_posix_spawn_file_actions_entry {
+ enum { FAE32_OPEN, FAE32_DUP2, FAE32_CLOSE } fae_action;
+
+ int fae_fildes;
+ union {
+ struct {
+ netbsd32_charp path;
+ int oflag;
+ mode_t mode;
+ } open;
+ struct {
+ int newfildes;
+ } dup2;
+ } fae_data;
+};
+
+struct netbsd32_posix_spawn_file_actions {
+ unsigned int size; /* size of fae array */
+ unsigned int len; /* how many slots are used */
+ netbsd32_posix_spawn_file_actions_entryp fae;
+};
+
#if 0
int netbsd32_kevent(struct lwp *, void *, register_t *);
#endif
diff -r e07436dbac99 -r 863639ded9db sys/compat/netbsd32/netbsd32_execve.c
--- a/sys/compat/netbsd32/netbsd32_execve.c Mon Apr 09 18:17:45 2012 +0000
+++ b/sys/compat/netbsd32/netbsd32_execve.c Thu Apr 12 17:05:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_execve.c,v 1.33 2012/01/31 22:53:56 matt Exp $ */
+/* $NetBSD: netbsd32_execve.c,v 1.33.2.1 2012/04/12 17:05:38 riz Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -28,12 +28,16 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.33 2012/01/31 22:53:56 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.33.2.1 2012/04/12 17:05:38 riz Exp $");
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/atomic.h>
#include <sys/mount.h>
+#include <sys/namei.h>
#include <sys/stat.h>
+#include <sys/spawn.h>
+#include <sys/uidinfo.h>
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/filedesc.h>
@@ -90,3 +94,140 @@
return sys_fexecve(l, &ua, retval);
}
+
+static int
+netbsd32_posix_spawn_fa_alloc(struct posix_spawn_file_actions **fap,
+ const struct netbsd32_posix_spawn_file_actions *ufa)
+{
+ struct posix_spawn_file_actions *fa;
+ struct netbsd32_posix_spawn_file_actions fa32;
+ struct netbsd32_posix_spawn_file_actions_entry *fae32 = NULL, *f32 = NULL;
+ struct posix_spawn_file_actions_entry *fae;
+ char *pbuf = NULL;
+ int error;
+ size_t fal, fal32, slen, i = 0;
+
+ error = copyin(ufa, &fa32, sizeof(fa32));
+ if (error)
+ return error;
+
+ if (fa32.len == 0)
+ return 0;
+
+ fa = kmem_alloc(sizeof(*fa), KM_SLEEP);
+ fa->len = fa->size = fa32.len;
+
+ fal = fa->len * sizeof(*fae);
+ fal32 = fa->len * sizeof(*fae32);
+
+ fa->fae = kmem_alloc(fal, KM_SLEEP);
+ fae32 = kmem_alloc(fal32, KM_SLEEP);
+ error = copyin(NETBSD32PTR64(fa32.fae), fae32, fal32);
+ if (error)
+ goto out;
+
+ pbuf = PNBUF_GET();
+ for (; i < fa->len; i++) {
+ fae = &fa->fae[i];
+ f32 = &fae32[i];
+ fae->fae_action = f32->fae_action;
+ fae->fae_fildes = f32->fae_fildes;
+ if (fae->fae_action == FAE_DUP2)
+ fae->fae_data.dup2.newfildes =
+ f32->fae_data.dup2.newfildes;
+ if (fae->fae_action != FAE_OPEN)
+ continue;
+ error = copyinstr(NETBSD32PTR64(f32->fae_path), pbuf,
+ MAXPATHLEN, &slen);
+ if (error)
+ goto out;
+ fae->fae_path = kmem_alloc(fal, KM_SLEEP);
+ memcpy(fae->fae_path, pbuf, slen);
+ fae->fae_oflag = f32->fae_oflag;
+ fae->fae_mode = f32->fae_mode;
+ }
+ PNBUF_PUT(pbuf);
+ if (fae32)
+ kmem_free(fae32, fal32);
+ *fap = fa;
+ return 0;
+
+out:
+ if (fae32)
+ kmem_free(fae32, fal32);
+ if (pbuf)
+ PNBUF_PUT(pbuf);
+ posix_spawn_fa_free(fa, i);
+ return error;
+}
+
+int
+netbsd32_posix_spawn(struct lwp *l,
+ const struct netbsd32_posix_spawn_args *uap, register_t *retval)
+{
+ /* {
+ syscallarg(netbsd32_pid_tp) pid;
+ syscallarg(const netbsd32_charp) path;
+ syscallarg(const netbsd32_posix_spawn_file_actionsp) file_actions;
+ syscallarg(const netbsd32_posix_spawnattrp) attrp;
+ syscallarg(netbsd32_charpp) argv;
+ syscallarg(netbsd32_charpp) envp;
+ } */
+
+ int error;
+ struct posix_spawn_file_actions *fa = NULL;
+ struct posix_spawnattr *sa = NULL;
+ pid_t pid;
+ bool child_ok = false;
+
+ error = check_posix_spawn(l);
+ if (error) {
+ *retval = error;
+ return 0;
+ }
+
+ /* copy in file_actions struct */
+ if (SCARG_P32(uap, file_actions) != NULL) {
+ error = netbsd32_posix_spawn_fa_alloc(&fa,
+ SCARG_P32(uap, file_actions));
+ if (error)
+ goto error_exit;
+ }
+
+ /* copyin posix_spawnattr struct */
+ if (SCARG_P32(uap, attrp) != NULL) {
+ sa = kmem_alloc(sizeof(*sa), KM_SLEEP);
+ error = copyin(SCARG_P32(uap, attrp), sa, sizeof(*sa));
+ if (error)
+ goto error_exit;
+ }
+
+ /*
+ * Do the spawn
+ */
+ error = do_posix_spawn(l, &pid, &child_ok, SCARG_P32(uap, path), fa,
+ sa, SCARG_P32(uap, argv), SCARG_P32(uap, envp),
+ netbsd32_execve_fetch_element);
+ if (error)
+ goto error_exit;
+
+ if (error == 0 && SCARG_P32(uap, pid) != NULL)
+ error = copyout(&pid, SCARG_P32(uap, pid), sizeof(pid));
+
+ *retval = error;
+ return 0;
+
+ error_exit:
+ if (!child_ok) {
+ (void)chgproccnt(kauth_cred_getuid(l->l_cred), -1);
+ atomic_dec_uint(&nprocs);
+
+ if (sa)
+ kmem_free(sa, sizeof(*sa));
+ if (fa)
+ posix_spawn_fa_free(fa, fa->len);
+ }
+
+ *retval = error;
+ return 0;
+}
diff -r e07436dbac99 -r 863639ded9db sys/compat/netbsd32/syscalls.master
--- a/sys/compat/netbsd32/syscalls.master Mon Apr 09 18:17:45 2012 +0000
+++ b/sys/compat/netbsd32/syscalls.master Thu Apr 12 17:05:36 2012 +0000
@@ -1,4 +1,4 @@
- $NetBSD: syscalls.master,v 1.91 2012/02/01 05:40:01 dholland Exp $
+ $NetBSD: syscalls.master,v 1.91.2.1 2012/04/12 17:05:37 riz Exp $
; from: NetBSD: syscalls.master,v 1.81 1998/07/05 08:49:50 jonathan Exp
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@@ -1039,3 +1039,10 @@
const netbsd32_timespecp_t tptr); }
473 STD { int|netbsd32||__quotactl(const netbsd32_charp path, \
netbsd32_voidp args); }
+474 NOERR { int|netbsd32||posix_spawn(netbsd32_pid_tp pid, \
+ const netbsd32_charp path, \
+ const netbsd32_posix_spawn_file_actionsp \
+ file_actions, \
+ const netbsd32_posix_spawnattrp attrp, \
+ netbsd32_charpp argv, netbsd32_charpp envp); }
+
diff -r e07436dbac99 -r 863639ded9db sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c Mon Apr 09 18:17:45 2012 +0000
+++ b/sys/kern/exec_elf.c Thu Apr 12 17:05:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.37 2012/02/11 23:16:16 martin Exp $ */
+/* $NetBSD: exec_elf.c,v 1.37.2.1 2012/04/12 17:05:36 riz Exp $ */
/*-
* Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.37 2012/02/11 23:16:16 martin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.37.2.1 2012/04/12 17:05:36 riz Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -421,7 +421,8 @@
p = l->l_proc;
- if (p->p_vmspace)
+ KASSERT(p->p_vmspace);
Home |
Main Index |
Thread Index |
Old Index