Date: Sat, 3 Aug 2013 02:05:06 +0900 From: Piyus Kedia <piyuskedia@gmail.com> To: Konstantin Belousov <kostikbel@gmail.com> Cc: freebsd-arch@freebsd.org, Ian Lepore <ian@freebsd.org>, Sorav Bansal <sbansal@cse.iitd.ernet.in> Subject: Re: Fwd: Use of the PC value in interrupt/exception handlers Message-ID: <CAFqkpAaqPOeb7iLU%2B_7VF1nf-AwMD5i8QgV6dWViT5og97r8=w@mail.gmail.com> In-Reply-To: <20130802165836.GC4972@kib.kiev.ua> References: <CA%2BmWYFvbcRc=Hh1B2OFvadkJWFmwCXF-%2BBF2zzk7ZeO8YF=B9A@mail.gmail.com> <CAFqkpAY1yBrHfutanF=h7Ke=jVCV95Rzg397okhKw6JYQ_PgUA@mail.gmail.com> <1375457493.45247.249.camel@revolution.hippie.lan> <20130802165836.GC4972@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
Thank you, this explains things very clearly. It helped us a lot. On Sat, Aug 3, 2013 at 1:58 AM, Konstantin Belousov <kostikbel@gmail.com>wrote: > On Fri, Aug 02, 2013 at 09:31:33AM -0600, Ian Lepore wrote: > > On Fri, 2013-08-02 at 19:08 +0900, Piyus Kedia wrote: > > > Dear all, > > > > > > We are working on developing a dynamic binary translator for the > kernel. > > > Towards this, we wanted to confirm if the interrupted PC value pushed > on > > > stack by an interrupt/exception is used by the interrupt/exception > > > handlers? For example, is the PC value compared against a fixed > address to > > > determine the handler behaviour (like > > > Linux's page fault handler compares the faulting PC against an > exception > > > table, to allow functions like copy_from_user to fault). > > > > > > Basically, we are wondering if it is safe to replace the pushed PC > value on > > > stack by another value. This would be safe if the PC value is only > used for > > > returning from interrupt, or for reading contents at that PC address > (e.g., > > > to decode the instruction at current PC). It would be unsafe if the > value > > > of the address itself is meaningful to the handler. > > > > > > We found that in FreeBSD segment-not-present exception handler checks > the > > > trapped PC value against some fixed kernel PC by looking at the code, > > > except that it is only used for debugging purposes. It would be nice if > > > somebody could also confirm this. > > > > > > Thanks, > > > Piyus > > > > For the ARM architectures which use Restartable Atomic Sequences (RAS) > > to implement atomic operations, examining the value of the saved PC and > > possibly modifying it is how RAS works. See the PUSHFRAMEINSVC macro in > > sys/arm/include/asmacros.h. > > > > In a nutshell, the RAS code works by having userland code store the > > begin/end addresses of a small block of code that must be executed to > > completion without interruption to be correct. If an exception or > > interrupt happens while the PC is in that range, the exception-entry > > code implemented by PUSHFRAMEINSVC modifies the saved PC so that on > > return to userland, execution resumes at the beginning of the atomic > > sequence. > > This reminds of me the following MIPS code: > http://svnweb.freebsd.org/base?view=revision&revision=226517 >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFqkpAaqPOeb7iLU%2B_7VF1nf-AwMD5i8QgV6dWViT5og97r8=w>