> 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 ?
And, how do you set the thread to be uninterruptible ? Any samples for this around ? thread_set_state seems promising, but, not sure if thats the one. Can this be done on the current_thread ?
Regards,
Ratheesh
----- Original Message ----
From: Terry Lambert <email@hidden>
To: Ratheesh Ramachandran <email@hidden>
Cc: Michael Smith <email@hidden>; Darwin-Kernel List <email@hidden>
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