Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755882AbcCEHjs (ORCPT ); Sat, 5 Mar 2016 02:39:48 -0500 Received: from smtp2.mail.ru ([94.100.179.91]:38235 "EHLO smtp2.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753785AbcCEHjj (ORCPT ); Sat, 5 Mar 2016 02:39:39 -0500 Subject: Re: [PATCH 1/2] sigaltstack: implement SS_AUTODISARM flag To: Andy Lutomirski References: <1456781345-8243-1-git-send-email-stsp@list.ru> <1456781345-8243-2-git-send-email-stsp@list.ru> 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@vger.kernel.org" , Linux API , Stas Sergeev From: Stas Sergeev Message-ID: <56DA8D25.20600@list.ru> Date: Sat, 5 Mar 2016 10:39:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Mras: Ok Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1244 Lines: 32 05.03.2016 01:22, Andy Lutomirski пишет: > 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 = 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.