summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2014-12-09 11:00:35 +0100
committerJustus Winter <4winter@informatik.uni-hamburg.de>2014-12-09 11:00:35 +0100
commitfd015781614b0ee9128f5a05941cf70585596b54 (patch)
tree72c5e5d42590d9d0f0445c9ee00cbe45a79f6ebd
parent5be4b38ddb241e76c2b5dc6da9471fc109a06a56 (diff)
add patch series
-rw-r--r--debian/patches/0001-Makeconf-handle-the-task_notify-protocol.patch25
-rw-r--r--debian/patches/0002-proc-register-for-new-task-notifications.patch126
-rw-r--r--debian/patches/0003-proc-implement-proc_make_task_namespace.patch224
-rw-r--r--debian/patches/0004-hurd-add-proc_make_task_namespace.patch45
-rw-r--r--debian/patches/0005-proc-fix-build.patch26
-rw-r--r--debian/patches/series5
6 files changed, 451 insertions, 0 deletions
diff --git a/debian/patches/0001-Makeconf-handle-the-task_notify-protocol.patch b/debian/patches/0001-Makeconf-handle-the-task_notify-protocol.patch
new file mode 100644
index 00000000..3861a30f
--- /dev/null
+++ b/debian/patches/0001-Makeconf-handle-the-task_notify-protocol.patch
@@ -0,0 +1,25 @@
+From 27fe3ee065b446b07389f52de42820c5b417fab5 Mon Sep 17 00:00:00 2001
+From: Justus Winter <4winter@informatik.uni-hamburg.de>
+Date: Fri, 7 Nov 2014 11:47:09 +0100
+Subject: [PATCH hurd 1/5] Makeconf: handle the task_notify protocol
+
+* Makeconf (mach_defs_names): Add `task_notify'.
+---
+ Makeconf | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/Makeconf b/Makeconf
+index f0d3fe3..5439913 100644
+--- a/Makeconf
++++ b/Makeconf
+@@ -577,6 +577,7 @@ mach_defs_names = bootstrap exc mach mach4 \
+ mach_host mach_port mach_timer_reply memory_object \
+ memory_object_default notify \
+ gnumach \
++ task_notify \
+
+ mach_debug_defs_names = mach_debug
+ device_defs_names = dev_forward device device_reply device_request
+--
+2.1.3
+
diff --git a/debian/patches/0002-proc-register-for-new-task-notifications.patch b/debian/patches/0002-proc-register-for-new-task-notifications.patch
new file mode 100644
index 00000000..f982e448
--- /dev/null
+++ b/debian/patches/0002-proc-register-for-new-task-notifications.patch
@@ -0,0 +1,126 @@
+From df3730a2eb4da4687dd76ad8668808af247db903 Mon Sep 17 00:00:00 2001
+From: Justus Winter <4winter@informatik.uni-hamburg.de>
+Date: Mon, 16 Sep 2013 16:09:05 +0200
+Subject: [PATCH hurd 2/5] proc: register for new task notifications
+
+* proc/Makefile (MIGSTUBS): Add `gnumachServer.o'.
+* proc/main.c (message_demuxer): Handle the `task_notify' protocol.
+(main): Register for new task notificatinos.
+* proc/mgt.c (S_mach_notify_new_task): Add server function.
+---
+ proc/Makefile | 4 +++-
+ proc/main.c | 11 ++++++++++-
+ proc/mgt.c | 35 ++++++++++++++++++++++++++++++++++-
+ 3 files changed, 47 insertions(+), 3 deletions(-)
+
+diff --git a/proc/Makefile b/proc/Makefile
+index aa31ffb..2275a66 100644
+--- a/proc/Makefile
++++ b/proc/Makefile
+@@ -27,9 +27,11 @@ SRCS = wait.c hash.c host.c info.c main.c mgt.c notify.c pgrp.c msg.c \
+ MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
+
+ MIGSTUBS = processServer.o notifyServer.o \
+- ourmsgUser.o proc_excUser.o proc_excServer.o
++ ourmsgUser.o proc_excUser.o proc_excServer.o \
++ task_notifyServer.o
+ OBJS = $(SRCS:.c=.o) $(MIGSTUBS)
+ HURDLIBS = ihash ports shouldbeinlibc
++
+ OTHERLIBS = -lpthread
+
+ include ../Makeconf
+diff --git a/proc/main.c b/proc/main.c
+index 3419d44..b4288fb 100644
+--- a/proc/main.c
++++ b/proc/main.c
+@@ -31,6 +31,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+ #include <pids.h>
+
+ #include "proc.h"
++#include "gnumach_U.h"
+
+ const char *argp_program_version = STANDARD_HURD_VERSION (proc);
+
+@@ -38,6 +39,7 @@ const char *argp_program_version = STANDARD_HURD_VERSION (proc);
+ #include "notify_S.h"
+ #include "../libports/interrupt_S.h"
+ #include "proc_exc_S.h"
++#include "task_notify_S.h"
+
+ int
+ message_demuxer (mach_msg_header_t *inp,
+@@ -47,7 +49,8 @@ message_demuxer (mach_msg_header_t *inp,
+ if ((routine = process_server_routine (inp)) ||
+ (routine = notify_server_routine (inp)) ||
+ (routine = ports_interrupt_server_routine (inp)) ||
+- (routine = proc_exc_server_routine (inp)))
++ (routine = proc_exc_server_routine (inp)) ||
++ (routine = task_notify_server_routine (inp)))
+ {
+ pthread_mutex_lock (&global_lock);
+ (*routine) (inp, outp);
+@@ -152,6 +155,12 @@ main (int argc, char **argv, char **envp)
+ if (err)
+ error (0, err, "Increasing priority failed");
+
++ err = register_new_task_notification (_hurd_host_priv,
++ generic_port,
++ MACH_MSG_TYPE_MAKE_SEND);
++ if (err)
++ error (0, err, "Registering task notifications failed");
++
+ {
+ /* Get our stderr set up to print on the console, in case we have
+ to panic or something. */
+diff --git a/proc/mgt.c b/proc/mgt.c
+index 02d69db..32408ae 100644
+--- a/proc/mgt.c
++++ b/proc/mgt.c
+@@ -1,5 +1,5 @@
+ /* Process management
+- Copyright (C) 1992,93,94,95,96,99,2000,01,02,13
++ Copyright (C) 1992,93,94,95,96,99,2000,01,02,13,14
+ Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+@@ -981,3 +981,36 @@ S_proc_get_code (struct proc *callerp,
+
+ return 0;
+ }
++
++/* Handle new task notifications from the kernel. */
++error_t
++S_mach_notify_new_task (mach_port_t notify,
++ mach_port_t task,
++ mach_port_t parent)
++{
++ struct proc *parentp, *childp;
++
++ if (notify != generic_port)
++ return EOPNOTSUPP;
++
++ parentp = task_find_nocreate (parent);
++ if (! parentp)
++ {
++ mach_port_deallocate (mach_task_self (), task);
++ mach_port_deallocate (mach_task_self (), parent);
++ return ESRCH;
++ }
++
++ childp = task_find_nocreate (task);
++ if (! childp)
++ {
++ mach_port_mod_refs (mach_task_self (), task, MACH_PORT_RIGHT_SEND, +1);
++ childp = new_proc (task);
++ }
++
++ /* XXX do something interesting */
++
++ mach_port_deallocate (mach_task_self (), task);
++ mach_port_deallocate (mach_task_self (), parent);
++ return 0;
++}
+--
+2.1.3
+
diff --git a/debian/patches/0003-proc-implement-proc_make_task_namespace.patch b/debian/patches/0003-proc-implement-proc_make_task_namespace.patch
new file mode 100644
index 00000000..cd8ba153
--- /dev/null
+++ b/debian/patches/0003-proc-implement-proc_make_task_namespace.patch
@@ -0,0 +1,224 @@
+From bd5cf8cc59b6aae65af960136b4951c44102821a Mon Sep 17 00:00:00 2001
+From: Justus Winter <4winter@informatik.uni-hamburg.de>
+Date: Tue, 11 Nov 2014 21:23:42 +0100
+Subject: [PATCH hurd 3/5] proc: implement `proc_make_task_namespace'
+
+* proc/proc.h (struct proc): Add field `p_task_namespace'.
+* proc/mgt.c (S_proc_child): Propagate `p_task_namespace' to child.
+(allocate_proc): Initialize `p_task_namespace'.
+(namespace_terminate): New function.
+(process_has_exited): Reparent children of dead tasks in the namespace
+to the root process. Terminate all tasks if the root process dies.
+Reap dead tasks.
+(S_mach_notify_new_task): For newly created tasks thats parent is in a
+namespace, call S_proc_child and forward the `mach_notify_new_task'
+message.
+(S_proc_make_task_namespace): New function.
+---
+ proc/mgt.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
+ proc/proc.h | 4 +++
+ 2 files changed, 107 insertions(+), 9 deletions(-)
+
+diff --git a/proc/mgt.c b/proc/mgt.c
+index 32408ae..bf400ba 100644
+--- a/proc/mgt.c
++++ b/proc/mgt.c
+@@ -220,6 +220,13 @@ S_proc_child (struct proc *parentp,
+ childp->end_code = parentp->end_code;
+ }
+
++ if (MACH_PORT_VALID (parentp->p_task_namespace))
++ {
++ mach_port_mod_refs (mach_task_self (), parentp->p_task_namespace,
++ MACH_PORT_RIGHT_SEND, +1);
++ childp->p_task_namespace = parentp->p_task_namespace;
++ }
++
+ return 0;
+ }
+
+@@ -577,6 +584,7 @@ allocate_proc (task_t task)
+
+ memset (&p->p_pi + 1, 0, sizeof *p - sizeof p->p_pi);
+ p->p_task = task;
++ p->p_task_namespace = MACH_PORT_NULL;
+ p->p_msgport = MACH_PORT_NULL;
+
+ pthread_cond_init (&p->p_wakeup, NULL);
+@@ -721,6 +729,16 @@ new_proc (task_t task)
+ return p;
+ }
+
++/* Used with prociterate to terminate all tasks in a task
++ namespace. */
++static void
++namespace_terminate (struct proc *p, void *cookie)
++{
++ mach_port_t *namespacep = cookie;
++ if (p->p_task_namespace == *namespacep)
++ task_terminate (p->p_task);
++}
++
+ /* The task associated with process P has died. Drop most state,
+ and then record us as dead. Our parent will eventually complete the
+ deallocation. */
+@@ -751,13 +769,39 @@ process_has_exited (struct proc *p)
+
+ ids_rele (p->p_id);
+
+- /* Reparent our children to init by attaching the head and tail
+- of our list onto init's. */
++ /* Reparent our children to init by attaching the head and tail of
++ our list onto init's. If the process is part of a task
++ namespace, reparent to the process that created the namespace
++ instead. */
+ if (p->p_ochild)
+ {
++ struct proc *reparent_to = init_proc;
+ struct proc *tp; /* will point to the last one. */
+ int isdead = 0;
+
++ if (MACH_PORT_VALID (p->p_task_namespace))
++ {
++ for (tp = p;
++ MACH_PORT_VALID (tp->p_parent->p_task_namespace);
++ tp = tp->p_parent)
++ {
++ /* Walk up the process hierarchy until we find the
++ creator of the task namespace. */
++ }
++
++ if (p == tp)
++ {
++ /* The creator of the task namespace died. Terminate
++ all tasks. */
++ prociterate (namespace_terminate, &p->p_task_namespace);
++
++ mach_port_deallocate (mach_task_self (), p->p_task_namespace);
++ p->p_task_namespace = MACH_PORT_NULL;
++ }
++ else
++ reparent_to = tp;
++ }
++
+ /* first tell them their parent is changing */
+ for (tp = p->p_ochild; tp->p_sib; tp = tp->p_sib)
+ {
+@@ -765,7 +809,7 @@ process_has_exited (struct proc *p)
+ nowait_msg_proc_newids (tp->p_msgport, tp->p_task,
+ 1, tp->p_pgrp->pg_pgid,
+ !tp->p_pgrp->pg_orphcnt);
+- tp->p_parent = init_proc;
++ tp->p_parent = reparent_to;
+ if (tp->p_dead)
+ isdead = 1;
+ }
+@@ -773,17 +817,17 @@ process_has_exited (struct proc *p)
+ nowait_msg_proc_newids (tp->p_msgport, tp->p_task,
+ 1, tp->p_pgrp->pg_pgid,
+ !tp->p_pgrp->pg_orphcnt);
+- tp->p_parent = init_proc;
++ tp->p_parent = reparent_to;
+
+ /* And now append the lists. */
+- tp->p_sib = init_proc->p_ochild;
++ tp->p_sib = reparent_to->p_ochild;
+ if (tp->p_sib)
+ tp->p_sib->p_prevsib = &tp->p_sib;
+- init_proc->p_ochild = p->p_ochild;
+- p->p_ochild->p_prevsib = &init_proc->p_ochild;
++ reparent_to->p_ochild = p->p_ochild;
++ p->p_ochild->p_prevsib = &reparent_to->p_ochild;
+
+ if (isdead)
+- alert_parent (init_proc);
++ alert_parent (reparent_to);
+ }
+
+ /* If an operation is in progress for this process, cause it
+@@ -795,6 +839,23 @@ process_has_exited (struct proc *p)
+
+ /* Cancel any outstanding RPCs done on behalf of the dying process. */
+ ports_interrupt_rpcs (p);
++
++ /* No one is going to wait for processes in a task namespace. */
++ if (MACH_PORT_VALID (p->p_task_namespace))
++ {
++ mach_port_t task;
++ mach_port_deallocate (mach_task_self (), p->p_task_namespace);
++ p->p_waited = 1;
++
++ /* XXX: `complete_exit' will destroy p->p_task if it is valid.
++ Prevent this so that `do_mach_notify_dead_name' can
++ deallocate the right. The proper fix is not to use
++ mach_port_destroy in the first place. */
++ task = p->p_task;
++ p->p_task = MACH_PORT_NULL;
++ complete_exit (p);
++ mach_port_deallocate (mach_task_self (), task);
++ }
+ }
+
+ void
+@@ -1008,9 +1069,42 @@ S_mach_notify_new_task (mach_port_t notify,
+ childp = new_proc (task);
+ }
+
+- /* XXX do something interesting */
++ if (MACH_PORT_VALID (parentp->p_task_namespace))
++ {
++ error_t err;
++ /* Tasks in a task namespace are not expected to call
++ proc_child, so we do it on their behalf. */
++ mach_port_mod_refs (mach_task_self (), task, MACH_PORT_RIGHT_SEND, +1);
++ err = S_proc_child (parentp, task);
++ if (! err)
++ /* Relay the notification. This consumes TASK and PARENT. */
++ return mach_notify_new_task (childp->p_task_namespace, task, parent);
++ }
+
+ mach_port_deallocate (mach_task_self (), task);
+ mach_port_deallocate (mach_task_self (), parent);
+ return 0;
+ }
++
++/* Implement proc_make_task_namespace as described in
++ <hurd/process.defs>. */
++error_t
++S_proc_make_task_namespace (struct proc *callerp,
++ mach_port_t notify)
++{
++ if (! callerp)
++ return EOPNOTSUPP;
++
++ if (! MACH_PORT_VALID (notify))
++ return EINVAL;
++
++ if (MACH_PORT_VALID (callerp->p_task_namespace))
++ {
++ mach_port_deallocate (mach_task_self (), notify);
++ return EBUSY;
++ }
++
++ callerp->p_task_namespace = notify;
++
++ return 0;
++}
+diff --git a/proc/proc.h b/proc/proc.h
+index 6196697..a056d18 100644
+--- a/proc/proc.h
++++ b/proc/proc.h
+@@ -58,6 +58,10 @@ struct proc
+ /* Process group structure */
+ struct pgrp *p_pgrp;
+
++ /* Processes may live in a task namespace identified by the
++ notification port registered by proc_make_task_namespace. */
++ mach_port_t p_task_namespace; /* send right */
++
+ /* Communication */
+ mach_port_t p_msgport; /* send right */
+
+--
+2.1.3
+
diff --git a/debian/patches/0004-hurd-add-proc_make_task_namespace.patch b/debian/patches/0004-hurd-add-proc_make_task_namespace.patch
new file mode 100644
index 00000000..b20dd055
--- /dev/null
+++ b/debian/patches/0004-hurd-add-proc_make_task_namespace.patch
@@ -0,0 +1,45 @@
+From 698ce8e25499776fce864a59ef3dbb57040735a8 Mon Sep 17 00:00:00 2001
+From: Justus Winter <4winter@informatik.uni-hamburg.de>
+Date: Wed, 12 Nov 2014 15:30:18 +0100
+Subject: [PATCH hurd 4/5] hurd: add `proc_make_task_namespace'
+
+Add a new RPC to the process protocol to create task namespaces.
+These can be used by an unprivileged process to claims the
+responsibility to manage all tasks in this namespace. Any task
+created in this namespace will automatically be declared a child of
+the root process, and a `mach_notify_new_task' message is sent to a
+given port. If the root process dies, the proc server will terminate
+all tasks in the namespace.
+
+* hurd/process.defs (proc_make_task_namespace): New RPC.
+---
+ hurd/process.defs | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/hurd/process.defs b/hurd/process.defs
+index 498faba..4ceb69e 100644
+--- a/hurd/process.defs
++++ b/hurd/process.defs
+@@ -1,5 +1,5 @@
+ /* Definitions for process server interface
+- Copyright (C) 1992,93,94,95,96,97,2001,2013 Free Software Foundation
++ Copyright (C) 1992,93,94,95,96,97,2001,13,14 Free Software Foundation
+
+ This file is part of the GNU Hurd.
+
+@@ -404,3 +404,12 @@ routine proc_get_code (
+ process: process_t;
+ out start_code: vm_address_t;
+ out end_code: vm_address_t);
++
++/* Create a new task namespace. PROCESS claims the responsibility to
++ manage all tasks in this namespace. Any task created in this
++ namespace will automatically be declared a child of PROCESS, and a
++ `mach_notify_new_task' message is sent to NOTIFY. If PROCESS dies,
++ the proc server will terminate all tasks in the namespace. */
++routine proc_make_task_namespace (
++ process: process_t;
++ notify: mach_port_send_t);
+--
+2.1.3
+
diff --git a/debian/patches/0005-proc-fix-build.patch b/debian/patches/0005-proc-fix-build.patch
new file mode 100644
index 00000000..7bfc5c8c
--- /dev/null
+++ b/debian/patches/0005-proc-fix-build.patch
@@ -0,0 +1,26 @@
+From 124fa7af77bfbf47dd4cd0a8c1707699963ac106 Mon Sep 17 00:00:00 2001
+From: Justus Winter <4winter@informatik.uni-hamburg.de>
+Date: Thu, 13 Nov 2014 05:27:57 +0100
+Subject: [PATCH hurd 5/5] proc: fix build
+
+---
+ proc/Makefile | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/proc/Makefile b/proc/Makefile
+index 2275a66..7cc4af5 100644
+--- a/proc/Makefile
++++ b/proc/Makefile
+@@ -32,6 +32,9 @@ MIGSTUBS = processServer.o notifyServer.o \
+ OBJS = $(SRCS:.c=.o) $(MIGSTUBS)
+ HURDLIBS = ihash ports shouldbeinlibc
+
++# XXX: fix build
++MIGSTUBS += gnumachUser.o task_notifyUser.o
++
+ OTHERLIBS = -lpthread
+
+ include ../Makeconf
+--
+2.1.3
+
diff --git a/debian/patches/series b/debian/patches/series
index 492399cb..3cda6e14 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -44,3 +44,8 @@ startup-avoid-broken-puts.patch
pfinet_dhcp.patch
libports-payloads.patch
+0001-Makeconf-handle-the-task_notify-protocol.patch
+0002-proc-register-for-new-task-notifications.patch
+0003-proc-implement-proc_make_task_namespace.patch
+0004-hurd-add-proc_make_task_namespace.patch
+0005-proc-fix-build.patch