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: 26200 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3ABB3206A0 for ; Thu, 13 Mar 2014 10:46:37 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wn1sf3145438obc.1 for ; Thu, 13 Mar 2014 03:46:36 -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=aTCDzwAK6nM0rO7Zq5fSZBBh/aeO5fl3zhjLqiogM3w=; b=h+r1KeA5xZRQCg+i+r1J96q+UGIWzk5weOMVG9e+Y35nBIxsVkMpreo/qJiJ4oUc2j AxKeUjRU8Ui4Zff5PaV4dl++Yy1b9ZocsKD91LIEFEfKpzw3Dmu+v0G6XmC/CGzNYaDJ ktu156o5fV4NUgmOMiJ1i4AL1n3VJGDnXjf0VSm3xQASWuVmrZwveIAbaM3uhYkopkRO uY13oAad7ItFneGiIzVoa92QPNWaUlVkWzDuP7aFzSK+p9FQ1Jd1dQHLhmlmQ9pqzFCX oFhEtoW/CDigrAcwUApcXMWFQC9FGDCPuE0VZfN100eM8+p+k1OaLxjmnXRWgCkN2WAE SBzQ== X-Gm-Message-State: ALoCoQkxdcI+lAA8hd3jQiKZPzT/ZtSoZkawyfUGBqWlb2VL58HbEy5tOAQQVu/Jc53y+/m/qzXv X-Received: by 10.43.92.73 with SMTP id bp9mr417426icc.26.1394707596738; Thu, 13 Mar 2014 03:46:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.33.203 with SMTP id j69ls221942qgj.27.gmail; Thu, 13 Mar 2014 03:46:36 -0700 (PDT) X-Received: by 10.52.247.231 with SMTP id yh7mr388465vdc.34.1394707596613; Thu, 13 Mar 2014 03:46:36 -0700 (PDT) Received: from mail-ve0-x22d.google.com (mail-ve0-x22d.google.com [2607:f8b0:400c:c01::22d]) by mx.google.com with ESMTPS id xj4si661586vec.94.2014.03.13.03.46.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Mar 2014 03:46:36 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22d 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:c01::22d; Received: by mail-ve0-f173.google.com with SMTP id oy12so870388veb.32 for ; Thu, 13 Mar 2014 03:46:36 -0700 (PDT) X-Received: by 10.220.12.140 with SMTP id x12mr812203vcx.19.1394707596545; Thu, 13 Mar 2014 03:46:36 -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.78.9 with SMTP id i9csp357663vck; Thu, 13 Mar 2014 03:46:36 -0700 (PDT) X-Received: by 10.66.123.5 with SMTP id lw5mr1346459pab.83.1394707595726; Thu, 13 Mar 2014 03:46:35 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id iu9si1127106pac.207.2014.03.13.03.46.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Mar 2014 03:46:35 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-48043-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 29187 invoked by alias); 13 Mar 2014 10:45:58 -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 29119 invoked by uid 89); 13 Mar 2014 10:45:57 -0000 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-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-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22d 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 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.