From patchwork Tue Apr 1 11:32:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 27531 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2484C20341 for ; Tue, 1 Apr 2014 11:33:29 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id hn18sf9779296igb.8 for ; Tue, 01 Apr 2014 04:33:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results; bh=qHZvncrjWldOXJnw5BW8y5ZzGlAo/jAlhh+HqYjHEQg=; b=B3iA7TGc7mbSsC08Cshf99VA2IdgP5gyc++z4nF8uj2s0DuYD/eSya97deCvDaMrj9 TOSVBjKQ8vpWyMXhexKCN2cbYwqvlYSwsALvwfqDv+mCEqIiBvQprSrT512Sv6WbzYgT rcot3vBNS82lpmIRjN9UbnzrbaeMmjHHjX5W8AP/Dt5xDh0OAjyZZiJQrnFltxvrZ323 8YtWhojGbM4wOXR5btqg5vs6a9CUBVPQE5xEaEHzh0p4jxyq4rknA6H7PB/abhwHvDYU QBlPQh3W/ImLBNynRl0efrdT46VL8eekncxNCeuo+9h8ErsGaxjRl7mXN8NIfNHVGTIR jD2A== X-Gm-Message-State: ALoCoQncV7A4RNbkFmUyqPQwjHRqHuD4N9Y36X075sVT4WK4kCvFEhTOauNgGWuwc9p7DFpzVcE9 X-Received: by 10.43.163.199 with SMTP id mp7mr11000243icc.6.1396352009482; Tue, 01 Apr 2014 04:33:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.141 with SMTP id g13ls1119720qge.76.gmail; Tue, 01 Apr 2014 04:33:29 -0700 (PDT) X-Received: by 10.221.28.202 with SMTP id rv10mr28332286vcb.10.1396352009364; Tue, 01 Apr 2014 04:33:29 -0700 (PDT) Received: from mail-vc0-x232.google.com (mail-vc0-x232.google.com [2607:f8b0:400c:c03::232]) by mx.google.com with ESMTPS id mp4si3447144vcb.112.2014.04.01.04.33.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 04:33:29 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c03::232 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c03::232; Received: by mail-vc0-f178.google.com with SMTP id im17so9774670vcb.9 for ; Tue, 01 Apr 2014 04:33:29 -0700 (PDT) X-Received: by 10.220.98.143 with SMTP id q15mr86864vcn.38.1396352009291; Tue, 01 Apr 2014 04:33:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp228325vcv; Tue, 1 Apr 2014 04:33:28 -0700 (PDT) X-Received: by 10.66.146.229 with SMTP id tf5mr30979736pab.50.1396352008258; Tue, 01 Apr 2014 04:33:28 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f8si11048954pbc.114.2014.04.01.04.33.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Apr 2014 04:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-48771-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 5253 invoked by alias); 1 Apr 2014 11:33:01 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 5058 invoked by uid 89); 1 Apr 2014 11:33:00 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f174.google.com X-Received: by 10.194.203.2 with SMTP id km2mr11882776wjc.72.1396351975069; Tue, 01 Apr 2014 04:32:55 -0700 (PDT) From: Will Newton To: libc-alpha@sourceware.org Subject: [PATCH v2 3/3] manual/setjmp.texi: Clarify setcontext and signal handlers text Date: Tue, 1 Apr 2014 12:32:47 +0100 Message-Id: <1396351967-1952-3-git-send-email-will.newton@linaro.org> In-Reply-To: <1396351967-1952-1-git-send-email-will.newton@linaro.org> References: <1396351967-1952-1-git-send-email-will.newton@linaro.org> X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c03::232 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 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 the behaviour of setcontext when restoring a context created by a call to a signal handler is unspecified. 2014-04-01 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(-) Changes in v2: - Use "unspecified" rather than "undefined" diff --git a/manual/setjmp.texi b/manual/setjmp.texi index 9446abc..ec79c26 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 unspecified. + 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.