From d96ea910f11eeaf09d1a7d0afbfd43b0b3a3b056 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 14 Mar 2011 02:14:46 +0100 Subject: Also warn about mach_port_destroy on invalid ports * ipc/mach_port.c (mach_port_destroy): Warn (and possibly call debugger) when ipc_right_lookup_write didn't find the port name. --- ipc/mach_port.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'ipc') diff --git a/ipc/mach_port.c b/ipc/mach_port.c index d902e22..122d5d9 100644 --- a/ipc/mach_port.c +++ b/ipc/mach_port.c @@ -552,6 +552,8 @@ mach_port_allocate(space, right, namep) * KERN_INVALID_NAME The name doesn't denote a right. */ +static volatile int mach_port_deallocate_debug = 0; + kern_return_t mach_port_destroy( ipc_space_t space, @@ -564,8 +566,14 @@ mach_port_destroy( return KERN_INVALID_TASK; kr = ipc_right_lookup_write(space, name, &entry); - if (kr != KERN_SUCCESS) + if (kr != KERN_SUCCESS) { + if (name != MACH_PORT_NULL && name != MACH_PORT_DEAD) { + printf("task %p destroying an invalid port %u, most probably a bug.\n", current_task(), name); + if (mach_port_deallocate_debug) + SoftDebugger("mach_port_deallocate"); + } return kr; + } /* space is write-locked and active */ kr = ipc_right_destroy(space, name, entry); /* unlocks space */ @@ -590,7 +598,6 @@ mach_port_destroy( * KERN_INVALID_RIGHT The right isn't correct. */ -static volatile int mach_port_deallocate_debug = 0; kern_return_t mach_port_deallocate( ipc_space_t space, -- cgit v1.2.3