4Bytes
4Bytes

Reputation: 345

How code catches exceptions?

How code catches exceptions (try, catch(...))?

push 0FFFFFFFFh
...
mov eax, dword ptr fs:[00000000h]
...
mov dword ptr fs:[00000000h],eax  
mov dword ptr [ebp-10h],esp

What this code mean in "head" of function, which catches exceptions?

mov dword ptr [ebp-4], 0

And this (in head of "try")? Function does not have any local variables.

Function:

int SUM(int a, int b)
{
    try{}
    catch(...){}
    return 0;
}

What store in FS segment?

Upvotes: 2

Views: 939

Answers (2)

Igor Skochinsky
Igor Skochinsky

Reputation: 25278

How MSVC implements exceptions (on x86): https://www.openrce.org/articles/full_view/21

This covers both SEH (__try/__catch/__finally) and C++ (try/catch) exception implementation.

How MSVC (x64) and GCC (Linux/iOS) implements exception handling: http://www.hexblog.com/?p=704

Upvotes: 1

szx
szx

Reputation: 6926

The value stored in fs:[0] is a pointer to a linked list of EXCEPTION_REGISTRATION structures. Read here for more details:

A Crash Course on the Depths of Win32 Structured Exception Handling, MSJ January 1997

Upvotes: 7

Related Questions