Re: kernel panic on wakeup from hibernation
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=H/3Ii8OHWb+Cf7O5xAbJbH+DLyGX7QAwV2apAYbWVfs=; b=ib0AzJd8deUWhF+wTEytoPsHRq/Vb7FJ2sjGxxCoJ7X3i6FG0lRRYChCYj9N2dORLi4weKYMf0AWltLcZkLL3Lj8/hv77mHzjDa6uKQOW6vant1YhyBcV9CgghPe+TfyaUgb3XkF8p8Hk+9fKXvvSvsW+4UcXV1GTi6KsYYHYik= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=dA45M2r92B9yxpa5bkWpQ+X/VmjT20fzLwAevR2evjNsSfNYQ5iw7XK2PWRi/qeibeSwPoLPOQdWrgtrocPyK7LxbDzxaWoVvIijLr9M9FXBEJoAak/X4pwasPRxpCUa66ad01CEzHXMxfnBIq4mO+0MCzE96ILCi09skbGp6QM= On Wed, Mar 19, 2008 at 1:40 AM, Ratheesh Ramachandran <ratheesh_jakarta@yahoo.com> wrote:
See execargs_alloc in xnu in bsd/kern/kern_exec.c for an example of how to do an allocation using semaphore_wait() without breaking.
I looked at this. It is returning without allocating if the semaphore_wait() returns a KERN_ABORTED... which is fine.
Alternately, indicate that your thread us uninterruptible until it gets the lock (and make sure that you _get_ the lock sometime, or you will block forever -- better to just do it right).
Will this approach work with semaphores ? I mean -- does semaphore_wait require thread to be interruptible ?
I think so
And, how do you set the thread to be uninterruptible ? Any samples for this
assert_wait thread_block
around ? thread_set_state seems promising, but, not sure if thats the one. Can this be done on the current_thread ?
the thread_set_state methods is machine dependent, however you can the status using thread_info ( thread_basic_info struct )
Regards, Ratheesh
----- Original Message ---- From: Terry Lambert <tlambert@apple.com> To: Ratheesh Ramachandran <ratheesh_jakarta@yahoo.com> Cc: Michael Smith <drivers@mu.org>; Darwin-Kernel List <darwin-kernel@lists.apple.com> Sent: Wednesday, 19 March, 2008 2:48:29 AM Subject: Re: kernel panic on wakeup from hibernation
On Mar 18, 2008, at 1:33 AM, Ratheesh Ramachandran wrote:
My thinking is that this is not a "regular" bad access scenario. But, something getting triggered by thread-safety issues (ie. the semaphore_wait's KERN_ABORTED error). I have a memory allocator function which looks something like this:
void *my_malloc(int size, char *tag) {
lock(); //calls semaphore_wait internally
//get memory
unlock(); }
Notice, I am not checking the result of lock.
If somebody does a thread_terminate() on one of the threads waiting on lock, thread-safety is compromised ie, multiple threads may access the critical section. The memory allocator may assign the same chunk of memory to different threads, one of them may free it, crashing the others.
Is my reasoning correct ie. consistent with how darwin works ?
What is the best way to handle such a situation ? Should my_malloc() have returned if lock() returned a KERN_ABORTED ? Should it have retried ? Will KERN_ABORTED always imply thread termination ?
You are doing this wrong.
See execargs_alloc in xnu in bsd/kern/kern_exec.c for an example of how to do an allocation using semaphore_wait() without breaking.
Alternately, indicate that your thread us uninterruptible until it gets the lock (and make sure that you _get_ the lock sometime, or you will block forever -- better to just do it right).
-- Terry
________________________________
Share files, take polls, and discuss your passions - all under one roof. Click here. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-kernel/openspecies%40gmail.com
This email sent to openspecies@gmail.com
-- -mmw _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
mm w