Structured Exception Handler and Delphi?

Windows requires all stack frames to be inside the stack allocated by the system. It also requires the stack frames to be in sequential order on the stack. Furthermore, for exception handling, it requires all 'exception records' to be on the stack, and for them to chain in a sequential order through stack memory.

Windows requires all stack frames to be inside the stack allocated by the system. It also requires the stack frames to be in sequential order on the stack. Furthermore, for exception handling, it requires all 'exception records' to be on the stack, and for them to chain in a sequential order through stack memory.

I figured this out/read this somewhere years ago while writing a micro-thread library (eternallines.com/microthreads).

Thanks for your answer that shades a light on what was bothering me. Thanks a lot – opc0de Aug 9 at 22:06.

For the first code, the TSeh is on the DATA global section of the executable, whereas the 2nd code stores it on the Stack. This is IMHO where the difference is. The _EXCEPTION_REGISTRATION_RECORD structure should probably be on stack.

Don't know why, honestly (some low-level SS register trick? ). To raise an exception, you should better try something like a division per zero or an access to a nil absolute address: PInteger(nil)^ := 0; // will always raise an exception asm xor eax,eax mov eax,eax // will always raise an exception end; About how to intercept exceptions in Delphi, take a look at this article.In fact, Delphi add some custom layer over SEH over Windows.

And note also that the exception handling changes in Win64 mode. Worth reading when moving to up to come Delphi XE2.

The TSeh instance would be on stack, just like for the 2nd code. AFAIK the only diff is that the _EXCEPTION_REGISTRATION_RECORD is in the DATA block of the program for the 1st code, whereas it is on stack for the 2nd... – Arnaud Bouchez Aug 9 at 11:48.

You can't use test procedure as exception callback function because exception callback function have different prototype. Read Matt Pietrek article, IMO the best source of information about Win32 SEH. Update For the further investigations I would recommend the following changes in the code to make the problem a bit more clean: function test: Integer; begin WriteLn(' Result:= 0; end; (because exception callback should return integer value in EAX) And for the first code snippet begin asm mov eax,fs:0 mov old_seh,eax end; eu.

OldSeh := old_seh; eu. NewSeh := Cardinal(@test); asm lea eax, eu mov fs:0,eax mov ds:0,eax //This will cause an AV exception end; end. Now you see that the exception is handled correctly as: --------------------------- Debugger Fault Notification --------------------------- Project C:\Users\Serg\Documents\RAD Studio\Projects\Project13.

Exe faulted with message: 'access violation at 0x004050f5: write of address 0x00000000'. Process Stopped. Use Step or Run to continue.

--------------------------- but not by your exception handler. Probably OS ignores exception registration records that are not stack-based (OS can easily do it because it knows minimum and maximum stack values).

– opc0de Aug 9 at 10:13 the exception function is stdcall defined, so it will work with a procedure defined without any parameters, like test – Arnaud Bouchez Aug 9 at 10:57 @opc0de Interesting that the first code snippet does not handle exception. Looks like OS does not like exception registration record that is not stack-based. – Serg Aug 9 at 12:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions