All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Calling native API in user-space signal handler
@ 2010-01-15 14:47 Andreas Glatz
  2010-01-15 18:24 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Glatz @ 2010-01-15 14:47 UTC (permalink / raw)
  To: xenomai@xenomai.org

Hi,

I wrote my on SIGSEGV signal handler which gathers information about the fault and passes that info to a separate process for post-processing.

I'm wondering if it's always save to call native API functions in a signal handler? 

(As according to man 7 signal', it's just save to call a subset of Glibc functions from within a signal handler.)

Andreas



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Calling native API in user-space signal handler
  2010-01-15 14:47 [Xenomai-help] Calling native API in user-space signal handler Andreas Glatz
@ 2010-01-15 18:24 ` Gilles Chanteperdrix
  2010-01-15 18:59   ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2010-01-15 18:24 UTC (permalink / raw)
  To: Andreas Glatz; +Cc: xenomai@xenomai.org

Andreas Glatz wrote:
> Hi,
> 
> I wrote my on SIGSEGV signal handler which gathers information about
> the fault and passes that info to a separate process for
> post-processing.
> 
> I'm wondering if it's always save to call native API functions in a
> signal handler?
> 
> (As according to man 7 signal', it's just save to call a subset of
> Glibc functions from within a signal handler.)

It is definitely not safe to assume that you may call any function in a
signal handler.

Calling pthread_mutex_lock in a signal handler can cause a multithreaded
application to deadlock for instance (if the preempted code was also in
the middle of a pthread_mutex_lock), so that calling the apparently
inocuous printf might deadlock.

Now, for the Xenomai services. You can in fact call any function whose
implementation is in fact a simple syscall. If a function does more than
simply emitting a syscall, then all bets are off. And of course, we can
not guarantee you that a function which is emitting a syscall now will
not get more complicated in later releases.

Another safe solution is to use the "ptrace" syscall, the one used by
gdb, instead of installing a handler for SIGSEGV. Granted, this will
become a bit more completely, but should be more safe.

Or enable generation of core files.

-- 
					    Gilles.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Calling native API in user-space signal handler
  2010-01-15 18:24 ` Gilles Chanteperdrix
@ 2010-01-15 18:59   ` Jan Kiszka
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2010-01-15 18:59 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai@xenomai.org, Andreas Glatz

Gilles Chanteperdrix wrote:
> Andreas Glatz wrote:
>> Hi,
>>
>> I wrote my on SIGSEGV signal handler which gathers information about
>> the fault and passes that info to a separate process for
>> post-processing.
>>
>> I'm wondering if it's always save to call native API functions in a
>> signal handler?
>>
>> (As according to man 7 signal', it's just save to call a subset of
>> Glibc functions from within a signal handler.)
> 
> It is definitely not safe to assume that you may call any function in a
> signal handler.
> 
> Calling pthread_mutex_lock in a signal handler can cause a multithreaded
> application to deadlock for instance (if the preempted code was also in
> the middle of a pthread_mutex_lock), so that calling the apparently
> inocuous printf might deadlock.
> 
> Now, for the Xenomai services. You can in fact call any function whose
> implementation is in fact a simple syscall. If a function does more than
> simply emitting a syscall, then all bets are off. And of course, we can
> not guarantee you that a function which is emitting a syscall now will
> not get more complicated in later releases.
> 
> Another safe solution is to use the "ptrace" syscall, the one used by
> gdb, instead of installing a handler for SIGSEGV. Granted, this will
> become a bit more completely, but should be more safe.
> 
> Or enable generation of core files.
> 

While it is true that one should be very careful with invoking services
from signal handler, for the debugging case SIGSEGV, printing, writing
to files, or even some diagnostic Xenomai native services will work in
(almost) all practical cases.

We have such handlers in the (test) field, and they did not cause
troubles so far though they call tons of unsafe services. Of course they
would lock up if the crash happened while holding some of the locks
acquired during print-out as well. But normally things crash elsewhere...

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-15 18:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-15 14:47 [Xenomai-help] Calling native API in user-space signal handler Andreas Glatz
2010-01-15 18:24 ` Gilles Chanteperdrix
2010-01-15 18:59   ` Jan Kiszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.