From patchwork Thu Mar 13 10:45:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 68 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (caibbdcaaahc.dreamhost.com [208.113.200.72]) by wilcox.dreamhost.com (Postfix) with ESMTP id 65C573600CD for ; Thu, 13 Mar 2014 03:46:28 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14307373) id 1BE7440BF360C; Thu, 13 Mar 2014 03:46:27 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx20.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id A12E04088B8AD for ; Thu, 13 Mar 2014 03:46:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=lwiFUgYyxivjE5vfWSZRyDJgsFb1ptj 0+H2mDHU8Eb/5OXESdE7xJO7lxJDAyjLQnwDdWLPfgc+UXa6PcLEg7Xby8wJKia8 Mi/z1M2w5GJvqeOPVvmrFe4ZRpBVaxKwq1LjInAk5T8HC9fZSl4xlcrcY7RPh7mz ComhAzbJxMN8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=4ObGbOPCRjec4KDOYtOcBFjGpYo=; b=IWJya Agi1PhuJfFFgK05uIXhq/pAWfg9uq85LnaawuE7STajP/4ELy+wPm6LRPj1a5PUy vyFgOTYizEDEyfEyfERHRu/1yMSSeM+C+N5MoQQ7rcR8y1QRjHoUGJQopM8+dEki IE34a/vwU2RFjabPwEHW2ALZ4yOBi0BOoiVaLs= Received: (qmail 29187 invoked by alias); 13 Mar 2014 10:45:58 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 29119 invoked by uid 89); 13 Mar 2014 10:45:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f180.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=aTCDzwAK6nM0rO7Zq5fSZBBh/aeO5fl3zhjLqiogM3w=; b=OIZRmrYBk02KuejLudRTG5AB67A/id6mDtAmU7KLLqj/PGukaTNJGMdXSTaNqzSY58 IkT//uCobiJwLt2IrCigMxvgyHZraI1M4W97sAzlcEmB/gtOHclr0dBjanVJEzDgbNUy hxuAqKhskUZ3CMp0aLK847KPNT3x9vBIS1HfTrrFV9Yv2PoIdTQMquxXGz7dLct2gJoh 6otzxsibXW4D3ajRUmIJH7VWOI3jEdd6gJS+WKWv+iPkw/srqHtum0Ikes4mMSmH5abg q9woDWfgZLx6AOOdSCYa59UqG0B4J5vvqSuDVC2ukXfZMosqUEKK5090RPgR21aMb+8Y MGqA== X-Gm-Message-State: ALoCoQmy6wADAZWRQMpmSIze7rG31/O0lhDqZxmOGmeaBvOjJB+dFV8aiHcC+le3Hq5q3Zr77wWO X-Received: by 10.194.60.179 with SMTP id i19mr962065wjr.59.1394707553102; Thu, 13 Mar 2014 03:45:53 -0700 (PDT) From: Will Newton To: libc-alpha@sourceware.org Subject: [PATCH 4/4] manual/setjmp.texi: Clarify setcontext and signal handlers text Date: Thu, 13 Mar 2014 10:45:43 +0000 Message-Id: <1394707543-9690-4-git-send-email-will.newton@linaro.org> In-Reply-To: <1394707543-9690-1-git-send-email-will.newton@linaro.org> References: <1394707543-9690-1-git-send-email-will.newton@linaro.org> X-DH-Original-To: glibc@patchwork.siddhesh.in Calling setcontext from a signal handler can be done safely so it is sufficient to note that it is not recommended. Also mention in setcontext documentation that restoring a context created by a call to a signal handler is undefined. 2014-03-13 Will Newton * manual/setjmp.texi (System V contexts): Add note that calling setcontext on a context created by a call to a signal handler is undefined. Update text to note that setcontext from a signal handler is possible but not recommended. --- manual/setjmp.texi | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/manual/setjmp.texi b/manual/setjmp.texi index 9446abc..fe59c47 100644 --- a/manual/setjmp.texi +++ b/manual/setjmp.texi @@ -396,6 +396,9 @@ time of the call. If @code{uc_link} was a null pointer the application terminates normally with an exit status value of @code{EXIT_SUCCESS} (@pxref{Program Termination}). +If the context was created by a call to a signal handler or from any +other source then the behaviour of @code{setcontext} is undefined. + Since the context contains information about the stack no two threads should use the same context at the same time. The result in most cases would be disastrous. @@ -483,11 +486,11 @@ and then resume where execution was stopped. This an example how the context functions can be used to implement co-routines or cooperative multi-threading. All that has to be done is to call every once in a while @code{swapcontext} to continue running a -different context. It is not allowed to do the context switching from -the signal handler directly since neither @code{setcontext} nor -@code{swapcontext} are functions which can be called from a signal -handler. But setting a variable in the signal handler and checking it -in the body of the functions which are executed is OK. Since -@code{swapcontext} is saving the current context it is possible to have -multiple different scheduling points in the code. Execution will always -resume where it was left. +different context. It is not recommended to do the context switching from +the signal handler directly since leaving the signal handler via +@code{setcontext} if the signal was delivered during code that was not +asynchronous signal safe could lead to problems. Setting a variable in +the signal handler and checking it in the body of the functions which +are executed is a safer approach. Since @code{swapcontext} is saving the +current context it is possible to have multiple different scheduling points +in the code. Execution will always resume where it was left.