[Mono-list] you do not need Linux to hack on mono
Serge
serge@wildwestsoftware.com
Sun, 3 Mar 2002 23:39:12 +0200
Fergus,
(I'm sending copy to the list, maybe someone else will be interested).
Very detailed description of SEH internals can be found here:
http://www.jorgon.freeserve.co.uk/ExceptFrame.htm
(author's home page is at http://www.godevtool.com)
Since sample code in the article is written in assembly I also coded a
couple of small samples.
The code can be compiled with both GCC/mingw and Microsoft compiler (or any
other Windows compiler):
1) http://mono.eurosoft.od.ua/doc/seh2.c
this one uses thread-specific handler (the same thing is used by __try) to
handle div by 0 exception.
It generates exception handler setup code on the fly (this can be done with
inline assembly as well), it's x86 specific but works for all versions of
Windows on x86, including CE/x86.
The same can be done for other CPUs, though it's slightly more complicated.
BTW, exception handlers is not the only data accessible with FS register,
for example fastest way to obtain thread id is to read it from fs:[0x18],
same for TLS. I believe, Sun's JVM use these features.
The other sample uses fully documented SetUnhandledExceptionFilter API.
2) http://mono.eurosoft.od.ua/doc/seh3.c
Both samples resume execution by incrementing EIP, thus skipping failed
instruction (idiv in this case). The code doesn't make attempt to decode
instruction, so increment is hardcoded and must be changed from 3 to 2 if
compiled with optimization enabled.
Sergey
----- Original Message -----
From: "Fergus Henderson" <fjh@cs.mu.OZ.AU>
To: "Serge" <serge@wildwestsoftware.com>
Sent: Sunday, March 03, 2002 1:23 PM
Subject: Re: [Mono-list] you do not need Linux to hack on mono
> On 01-Mar-2002, Serge <serge@wildwestsoftware.com> wrote:
> > Actually SEH is an OS feature and as such can be used without special
> > compiler support (without keywords such as __try).
> > This will require architecture-specific code, however (but context
> > structures are CPU-specific anyway).
> > If someone is interested I have some pointers and some sample code.
>
> Yes please, I'm interested.
>
> --
> Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the
pursuit
> The University of Melbourne | of excellence is a lethal habit"
> WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
>