public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Yubin Ruan <ablacktshirt@gmail.com>, libc-help@sourceware.org
Cc: nd@arm.com
Subject: Re: determine whether code is running in a signal handler context
Date: Fri, 20 Oct 2017 10:32:00 -0000	[thread overview]
Message-ID: <59E9D0C2.4090900@arm.com> (raw)
In-Reply-To: <CAJYFCiPkMNCr0X61AQ9MqhXyagOb0k4tTp5mRAD171VLkedVYQ@mail.gmail.com>

On 18/10/17 15:18, Yubin Ruan wrote:
> Hi,
> 
> I am writing to see if this is any util functions in libc that can
> help to determine it is currently running in a signal.
> 
> I wrote some library and provide a function which will be used in many
> client code. However this function is not async-signal safe (it calls
> malloc(3)) so when it is called, I want to detect whether it is
> currently running in a signal handler. If it is, I can avoid calling
> those not-async-signal-safe functions which might cause deadlock.
> 

note that in posix as-safety is symmetric between the
interrupted code and interrupt handler: if any of the
interrupt and interrupt handler is as-safe then the
behaviour is well defined.

so calling non-as-safe code in an asynchronous signal
handler is perfectly fine if the interrupted code is
as-safe.

there are synchronous signals too, i.e. raise(sig),
and then the signal handler runs in well-defined state
(one can use signal masks to make sure a signal handler
only runs in such state)

so using "in_signal_handler_context()" is not a valid
way to verify the as-safety interface contract.

> that is, I want a `in_signal_handler_context()' utility that can be
> used as this:
> 
> int mylibfunc( void ) {
>     if( in_signal_handler_context() ) { return(-1) }
>     // rest of function goes here
>     return( 0 );
> }
> 
> 
> Yubin
> 

  parent reply	other threads:[~2017-10-20 10:32 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 14:18 Yubin Ruan
2017-10-18 18:34 ` Carlos O'Donell
2017-10-19  1:52   ` Yubin Ruan
2017-10-19  2:19     ` Carlos O'Donell
2017-10-19  2:39       ` Will Hawkins
2017-10-19  3:12         ` Carlos O'Donell
2017-10-19  4:07           ` Yubin Ruan
2017-10-19  4:56             ` Carlos O'Donell
2017-10-19  4:19           ` Will Hawkins
2017-10-19  4:01       ` Yubin Ruan
2017-10-19  2:59 ` Sean Conner
2017-10-19  3:12 ` Sean Conner
2017-10-19  3:51   ` Yubin Ruan
2017-10-19  7:10     ` Jeffrey Walton
2017-10-20 10:32 ` Szabolcs Nagy [this message]
2017-10-20 11:23   ` Yubin Ruan
2017-10-20 11:31     ` Szabolcs Nagy
2017-10-20 17:19       ` Carlos O'Donell
2017-10-20 17:48         ` Szabolcs Nagy
2017-10-22  6:09           ` Carlos O'Donell
2017-10-22 23:39             ` where is the definition of idtype_t supposed to live? John Lumby
2017-10-23 13:57               ` Florian Weimer
     [not found]                 ` <BN6PR22MB16662DE3DFB590B3D6006F81A3460@BN6PR22MB1666.namprd22.prod.outlook.com>
2017-10-23 14:20                   ` Florian Weimer
2017-10-23 10:01             ` determine whether code is running in a signal handler context Szabolcs Nagy
2017-10-23 14:30               ` Carlos O'Donell
2017-10-24  1:00                 ` Yubin Ruan
2017-11-27  8:43 ` Yubin Ruan
2017-11-27 11:55   ` Florian Weimer
2017-11-27 12:50     ` Yubin Ruan
2017-11-27 12:51       ` Florian Weimer
2017-11-27 12:58         ` Adhemerval Zanella

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=59E9D0C2.4090900@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=ablacktshirt@gmail.com \
    --cc=libc-help@sourceware.org \
    --cc=nd@arm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).