lkml.org 
[lkml]   [2016]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 1/2] sigaltstack: implement SS_AUTODISARM flag
From
Date
05.03.2016 01:22, Andy Lutomirski пишет:
> On Mon, Feb 29, 2016 at 1:29 PM, Stas Sergeev <stsp@list.ru> wrote:
>> This patch implements the SS_AUTODISARM flag that can be ORed with
>> SS_ONSTACK when forming ss_flags.
>> When this flag is set, sigaltstack will be disabled when entering
>> the signal handler; more precisely, after saving sas to uc_stack.
>> When leaving the signal handler, the sigaltstack is restored by
>> uc_stack.
>> When this flag is used, it is safe to switch from sighandler with
>> swapcontext(). Without this flag, the subsequent signal will corrupt
>> the state of the switched-away sighandler.
>>
> This looks reasonable to me with one exception: how does a user
> program detect the presence of this feature?
Compile-time detection:
#ifdef SS_AUTODISARM
# I have this feature
...
#endif

Run-time detection:
int err = sigaltstack(SS_ONSTACK | SS_AUTODISARM);
if (err == EINVAL) {
i_dont_have_this_feature = 1;
err = sigaltstack(SS_ONSTACK);
}

Note: if you want to keep such detection for the future
additions, the mask can be enlarged to, say, ((1 << 24) - 1),
and whenever someone adds a new flag, he can lower the
mask by one bit.
But I think this would be an overkill in that particular case.

\
 
 \ /
  Last update: 2016-03-05 09:21    [W:0.365 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site