Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756123AbcCEHlS (ORCPT ); Sat, 5 Mar 2016 02:41:18 -0500 Received: from smtp37.i.mail.ru ([94.100.177.97]:48377 "EHLO smtp37.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751170AbcCEHlF (ORCPT ); Sat, 5 Mar 2016 02:41:05 -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> <56DA8D25.20600@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: <56DA8D88.5060301@list.ru> Date: Sat, 5 Mar 2016 10:40:56 +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: <56DA8D25.20600@list.ru> 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: 1042 Lines: 26 05.03.2016 10:39, Stas Sergeev пишет: > 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 guess I mean here if (err && errno == EINVAL)