On Fri, 7 Dec 2012 16:40:28 +0100, "Borneq"
<> wrote:
>U?ytkownik "James Kuyper" <> napisa? w wiadomo?ci
>news:k9spjv$8cb$...
>> On the other hand: if your entire program never actually handles
>> exceptions, then you may be able to adequately emulate exceptions simply
>> by replacing throw() with exit(). That's the case for the C++ code I'm
>> working on right now.
>
>Is http://www.microsoft.com/msj/0197/Ex...Exception.aspx with code:
>int main()
>{
> DWORD handler = (DWORD)_except_handler;
>
> __asm
> { // Build EXCEPTION_REGISTRATION record:
> push handler // Address of handler function
> push FS:[0] // Address of previous handler
> mov FS:[0],ESP // Install new EXECEPTION_REGISTRATION
so here FS:[0] point to a region of mem that has in its first 4bytes
the address of the *previous* handler; right?
> }
>
> __asm
> {
> mov eax,0 // Zero out EAX
> mov [eax], 1 // Write to EAX to deliberately cause a
>fault
> }
>
> printf( "After writing!\n" );
>
> __asm
> { // Remove our EXECEPTION_REGISTRATION record
> mov eax,[ESP] // Get pointer to previous record
> mov FS:[0], EAX // Install previous record
> add esp, 8 // Clean our EXECEPTION_REGISTRATION off
>stack
> }
>
> return 0;
>}
>
what is one handler?
if it is one function, what arg it has? what it return?
this here crash...
__________
;nasmw -fobj that.asm
section _DATA use32 public class=DATA
global _fini
global _fend
dat dd 0, 0, 0, 0
section _TEXT use32 public class=CODE
; 0ra, 4P_address_hadler_function
_fini:
mov edx, dword[esp+ 4]
cmp edx, 0
jne .1
..e: mov eax, -1
stc
jmp short .z
..1: mov eax, [fs:0]
cmp eax, 0
je .e
mov [dat], eax ; store address of previos hf
mov [dat+4], edx ; store address of hf
mov ecx, dat
mov [fs:0], ecx
xor eax, eax
..z:
ret
_fend:
mov eax, [dat]
cmp eax, 0
je .z
mov [fs:0], eax
..z:
ret
__________
/*bcc32 -v this.c that.obj */
#include <stdio.h>
int fini(char* a);
int fend(void);
int except_handler(void){return 1;}
int main()
{unsigned a,b;
fini(except_handler);
a=0; b=9; b=b/a;
printf( "After writing! %u\n", b);
fend();
return 0;
}