From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 77023 invoked by alias); 21 Oct 2016 13:45:27 -0000 Mailing-List: contact gnu-gabi-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: gnu-gabi-owner@sourceware.org Received: (qmail 77006 invoked by uid 89); 21 Oct 2016 13:45:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2772, saved, imprecise, interest X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mx2.suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Date: Fri, 01 Jan 2016 00:00:00 -0000 From: Michael Matz To: Florian Weimer cc: "H.J. Lu" , gnu-gabi@sourceware.org Subject: Re: [PATCH] Make _Unwind_GetIPInfo part of the ABI In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2016-q4/txt/msg00015.txt.bz2 Hi, On Fri, 21 Oct 2016, Florian Weimer wrote: > On 10/21/2016 02:58 PM, Michael Matz wrote: > > +This function returns the same value as \code{\_Unwind\_GetIP}. In > > +addition, the argument \code{ip\_before\_insn} must not be not null, and > > +\code{*ip\_before\_insn} is updated with a flag which indicates whether > > +the returned pointer is at or after the first not yet fully executed > > +instruction. > > I think this is rather misleading. On x86_64, the location of the IP > value is the same for calls and asynchronous signals: it always points > to the next instruction to be executed. No, that's simply wrong. The saved instruction pointer points _at_ the instruction causing the fault for faults, and _after_ the instruction for traps. Traps are things like single-stepping, breakpoints or INTO. Most other interrupts are faults or aborts (the latter being imprecise and hence can't be restarted anyway). For calls the saved instruction pointer always points to after the call and hence can be handled like a trap for unwinding purposes. > There are no partially executed instructions. That's not 100% correct either (e.g. certain load-state instructions can be interrupted in the middle, though that usually just causes a double fault). But in the interest of being clearer, I guess I should have written "not yet completed" instruction, instead of that "fully executed" part. > The difference that if we unwind through a call which has not yet > returned, the caller is assumed to be still within the exception > handling region in which the call instruction is located. This is the > consequence of the desired exception handling semantics of a > non-returned function call. Unwinding through one call or one trap is the same. The interesting instruction is the one ending right before the reported IP. > It is not directly related to the instruction pointer value returned by > _Unwind_GetIPInfo. Yes it is. GetIPInfo always returns the instruction pointer as encoded in the given unwind context (like GetIP itself). That's exactly the one that's also stored on the stack (well, on x86-64 at least, for other architectures it might be stored in a register and might be in encoded form), and is the one to be used to look up exception regions _except_ that you normally need to subtract one from it, because the IP stored in the context and stack points to after the insn you're interested in. Except for those situations where it doesn't, for which this function was introduced to start with, in order to be able to differ between those (basically the kernel needs to mark the signal frame as being the result of a fault or a trap, and GetIPInfo uses this to set the flag). Ciao, Michael.