All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: "xenomai@xenomai.org" <xenomai@xenomai.org>,
	Andreas Glatz <AndreasGlatz@domain.hid>
Subject: Re: [Xenomai-help] Calling native API in user-space signal handler
Date: Fri, 15 Jan 2010 19:59:00 +0100	[thread overview]
Message-ID: <4B50BAF4.9070604@domain.hid> (raw)
In-Reply-To: <4B50B2C4.1020904@domain.hid>

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


      reply	other threads:[~2010-01-15 18:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B50BAF4.9070604@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=AndreasGlatz@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.