From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stas Sergeev Subject: Re: [PATCH 1/2] sigaltstack: implement SS_AUTODISARM flag Date: Sat, 5 Mar 2016 10:39:17 +0300 Message-ID: <56DA8D25.20600@list.ru> References: <1456781345-8243-1-git-send-email-stsp@list.ru> <1456781345-8243-2-git-send-email-stsp@list.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Andy Lutomirski Cc: Ingo Molnar , Peter Zijlstra , Richard Weinberger , Andrew Morton , Oleg Nesterov , Tejun Heo , Heinrich Schuchardt , Jason Low , Andrea Arcangeli , Frederic Weisbecker , Konstantin Khlebnikov , Josh Triplett , "Eric W. Biederman" , Aleksa Sarai , Amanieu d'Antras , Paul Moore , Sasha Levin , Palmer Dabbelt , Vladimir Davydov , "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , Linux API , Stas Sergeev List-Id: linux-api@vger.kernel.org 05.03.2016 01:22, Andy Lutomirski =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > On Mon, Feb 29, 2016 at 1:29 PM, Stas Sergeev 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 =3D sigaltstack(SS_ONSTACK | SS_AUTODISARM); if (err =3D=3D EINVAL) { i_dont_have_this_feature =3D 1; err =3D 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.