User exception handler in C (Developers)
Aha, it was not so hard.
My implementation in FreePascal:
(not the mentioned SSE check but a very simple example how to catch out the division by zero and how to revert the handler to original state)
uses dpmiexcp;
var was_excp:boolean;
Function SignalHandler(i:longint):longint;cdecl;
var pexp:PException_State;
jmp_rec:dpmi_jmp_buf;
eip:longint;
begin
pexp:=djgpp_exception_state;
eip:=pexp^.__eip;
if {eip=$310f} 1=1 then
begin
was_excp:=true;
Move(pexp^,jmp_rec,sizeof(dpmi_jmp_buf));
jmp_rec.eip:=pexp^.__eip+2;
jmp_rec.edx:=0;
dpmi_LongJmp(jmp_rec,0);
end;
end;
Procedure Do_Something;
var a:byte;
begin
a:=0;
writeln(2 div a); {I can't write just "2 div 0" because of the FPC sanity check }
end;
{=========== main ===========}
begin
was_excp:=false;
Signal(SIGFPE,@SignalHandler);
Do_Something;
Signal(SIGFPE,@SIG_DFL);
writeln(was_excp);
end.
---
DOS-u-akbar!
Complete thread:
- User exception handler in C - RayeR, 24.07.2020, 13:15 (Developers)
- User exception handler in C - Japheth, 24.07.2020, 18:07
- User exception handler in C - Rugxulo, 24.07.2020, 18:39
- User exception handler in C - tkchia, 24.07.2020, 20:47
- User exception handler in C - RayeR, 30.07.2020, 13:18
- User exception handler in C - tom, 30.07.2020, 23:54
- User exception handler in C - RayeR, 01.08.2020, 02:13
- User exception handler in C - Laaca, 16.08.2020, 21:27
- User exception handler in C - Laaca, 16.08.2020, 22:38
- User exception handler in C - Rugxulo, 17.08.2020, 22:35
- User exception handler in C - marcov, 18.08.2020, 12:23
- User exception handler in C - Laaca, 18.08.2020, 20:15
- User exception handler in C - Rugxulo, 19.08.2020, 19:44
- User exception handler in C - Laaca, 19.08.2020, 21:50
- User exception handler in C - Rugxulo, 23.08.2020, 17:32
- User exception handler in C - Japheth, 23.08.2020, 20:36
- User exception handler in C - Rugxulo, 23.08.2020, 17:32
- User exception handler in C - Laaca, 19.08.2020, 21:50
- User exception handler in C - Rugxulo, 19.08.2020, 19:44
- User exception handler in C - Laaca, 18.08.2020, 20:15
- User exception handler in C - marcov, 18.08.2020, 12:23
- User exception handler in C - Rugxulo, 17.08.2020, 22:35
- User exception handler in C - Rugxulo, 17.08.2020, 22:26
- User exception handler in C - tkchia, 19.08.2020, 18:52
- User exception handler in C - marcov, 20.08.2020, 00:00
- User exception handler in C - Laaca, 20.08.2020, 15:31
- User exception handler in C - marcov, 20.08.2020, 00:00
- User exception handler in C - Laaca, 16.08.2020, 22:38
- User exception handler in C - Laaca, 16.08.2020, 21:27
- User exception handler in C - RayeR, 01.08.2020, 02:13
- User exception handler in C - tkchia, 31.07.2020, 19:36
- User exception handler in C - RayeR, 01.08.2020, 02:16
- User exception handler in C - tom, 30.07.2020, 23:54
- User exception handler in C - RayeR, 30.07.2020, 13:18
- User exception handler in C - Guti, 27.07.2020, 08:22