Re: Framework Registers/Stack restoration on exceptions by Jack
Jack
Tue Mar 18 13:13:55 CDT 2008
Peter Duniho wrote:
> On Mon, 17 Mar 2008 13:58:11 -0700, Jack <raoul@coin.fr> wrote:
>
>> [...]
>> Framework use a sucking algorithm (probably based on stack size needed
>> by function parameters) and badly restore the stack.
>
> I'm not sure what you mean by "sucking algorithm", but if you mean that
> .NET itself is using a poor algorithm, I'd say you've got a long way to
> go before you demonstrate that.
>
>> That's why I need informations on it...
>> So from now, you may understand my question better, my have you some
>> documentation ?
>
> I don't see that you've really managed to describe what it is you're
> doing in a precise enough way. Not that I'm personally likely to have
> the answer in any case, but I doubt that even the person who does could
> provide it given the information you've only provided so far.
>
> From what you _have_ described, I'd say that if you are auto-generating
> assembly code and calling that from .NET and that an exception thrown
> from within the ASM code causes problems, then it's your ASM that has
> problems. You need to figure out the right way to handle exceptions in
> your ASM code so that you don't corrupt the stack.
>
> Pete
.NET use a "poor algorithm" yes really, instead of saving registers as
c++, c and all other compiled language do, and use the
unexpected_handler as unique exception handler. Anyway
My asm is not generating exception, the flow is the following
The think I want to do is hooking of .NET in win32 (I know
EnterLeaveFunction of ICorprofiler exits)
Entering .NET asm generated code of my .Net function f_NET()
execution of my asm code part1
execution of .Net asm generated code --> my .Net code design to throw an
error (software exception with throw, or an hadware one)
execution of my asm code part2
- if no .Net error is thrown all is ok
- if .Net error is thrown and catch is inside the same .Net function
(f_NET) there is no error, as .Net stack retrieval algo is not used
(stack has not to be restored as exception handler is in the same function)
- if .Net error is catch on function calling f_NET(), stack has to be
restored by .NET framework, and has it seems they don't save esp/ebp but
try to restore them software crash