summaryrefslogtreecommitdiff
path: root/boot/boot.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1995-07-08 16:43:03 +0000
committerMiles Bader <miles@gnu.org>1995-07-08 16:43:03 +0000
commitce9d889cbf002d8b3e88d2d7dc5ae10c4b787f52 (patch)
treecad1dbb501422d16d1aa4af4fe1bd36dd3b60b0e /boot/boot.c
parent17bf8dba7084eb56d7e924b54e25266149b3b919 (diff)
(free_reply_ports, free_reply_ports_lock): New variables.
(__mig_get_reply_port, __mig_put_reply_port, __mig_dealloc_reply_port, mig_get_reply_port, mig_put_reply_port, mig_dealloc_reply_port): Provide better versions of these routines that won't leak reply ports.
Diffstat (limited to 'boot/boot.c')
-rw-r--r--boot/boot.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/boot/boot.c b/boot/boot.c
index 44b0dcaa..eeea2b64 100644
--- a/boot/boot.c
+++ b/boot/boot.c
@@ -90,20 +90,60 @@ void set_mach_stack_args ();
/* These will prevent the Hurd-ish versions from being used */
+struct free_reply_port
+{
+ mach_port_t port;
+ struct free_reply_port *next;
+};
+static struct free_reply_port *free_reply_ports = NULL;
+static spin_lock_t free_reply_ports_lock = SPIN_LOCK_INITIALIZER;
+
mach_port_t __mig_get_reply_port ()
{
- return __mach_reply_port ();
+ spin_lock (&free_reply_ports_lock);
+ if (free_reply_ports == NULL)
+ {
+ spin_unlock (&free_reply_ports_lock);
+ return __mach_reply_port ();
+ }
+ else
+ {
+ struct free_reply_port *frp = free_reply_ports;
+ mach_port_t reply_port = frp->port;
+ free_reply_ports = free_reply_ports->next;
+ spin_unlock (&free_reply_ports_lock);
+ free (frp);
+ return reply_port;
+ }
}
mach_port_t mig_get_reply_port ()
{
- return __mach_reply_port ();
+ return __mig_get_reply_port ();
+}
+void __mig_put_reply_port (mach_port_t port)
+{
+ struct free_reply_port *frp = malloc (sizeof (struct free_reply_port));
+ frp->port = port;
+ spin_lock (&free_reply_ports_lock);
+ frp->next = free_reply_ports;
+ free_reply_ports = frp;
+ spin_unlock (&free_reply_ports_lock);
+}
+void mig_put_reply_port (mach_port_t port)
+{
+ __mig_put_reply_port (port);
+}
+void __mig_dealloc_reply_port (mach_port_t port)
+{
+ __mach_port_mod_refs (__mach_task_self (), port,
+ MACH_PORT_RIGHT_RECEIVE, -1);
+}
+void mig_dealloc_reply_port (mach_port_t port)
+{
+ __mig_dealloc_reply_port (port);
}
void __mig_init (void *stack) {}
void mig_init (void *stack) {}
-void __mig_dealloc_reply_port (mach_port_t port) {}
-void mig_dealloc_reply_port (mach_port_t port) {}
-void __mig_put_reply_port (mach_port_t port) {}
-void mig_put_reply_port (mach_port_t port) {}
int
task_by_pid (int pid)