mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-30 04:52:05 +01:00
* fixes for signal handling.
This commit is contained in:
parent
896f306291
commit
aebc04656f
@ -508,11 +508,52 @@ begin
|
|||||||
reenable_signal:=geterrno=0;
|
reenable_signal:=geterrno=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure SignalToRunerror(Sig: cint; var info : tsiginfo_t;Var SigContext:SigContextRec); cdecl;
|
||||||
|
|
||||||
|
var
|
||||||
|
res : word;
|
||||||
|
|
||||||
|
begin
|
||||||
|
res:=0;
|
||||||
|
case sig of
|
||||||
|
SIGFPE :
|
||||||
|
begin
|
||||||
|
Case Info.si_code Of
|
||||||
|
FPE_INTDIV : Res:=200; {integer divide fault. Div0?}
|
||||||
|
FPE_FLTOVF : Res:=205; {Overflow trap}
|
||||||
|
FPE_FLTUND : Res:=206; {Stack over/underflow}
|
||||||
|
FPE_FLTRES : Res:=216; {Device not available}
|
||||||
|
FPE_FLTINV : Res:=216; {Invalid floating point operation}
|
||||||
|
Else
|
||||||
|
Res:=208; {coprocessor error}
|
||||||
|
End;
|
||||||
|
sysResetFPU;
|
||||||
|
End;
|
||||||
|
SIGILL,
|
||||||
|
SIGBUS,
|
||||||
|
SIGSEGV :
|
||||||
|
res:=216;
|
||||||
|
end;
|
||||||
|
{$ifdef FPC_USE_SIGPROCMASK}
|
||||||
|
reenable_signal(sig);
|
||||||
|
{$endif }
|
||||||
|
{ give runtime error at the position where the signal was raised }
|
||||||
|
if res<>0 then
|
||||||
|
begin
|
||||||
|
{$ifdef I386}
|
||||||
|
HandleErrorAddrFrame(res,Pointer(SigContext.sc_eip),pointer(SigContext.sc_ebp));
|
||||||
|
{$else}
|
||||||
|
HandleError(res);
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{
|
||||||
procedure SignalToRunerror(signo: cint); cdecl;
|
procedure SignalToRunerror(signo: cint); cdecl;
|
||||||
var
|
var
|
||||||
res : word;
|
res : word;
|
||||||
begin
|
begin
|
||||||
res:=0;
|
res:=0;
|
||||||
|
|
||||||
if signo = SIGFPE then
|
if signo = SIGFPE then
|
||||||
begin
|
begin
|
||||||
res := 200;
|
res := 200;
|
||||||
@ -528,7 +569,7 @@ begin
|
|||||||
HandleError(res);
|
HandleError(res);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
}
|
||||||
|
|
||||||
var
|
var
|
||||||
act: SigActionRec;
|
act: SigActionRec;
|
||||||
@ -541,7 +582,8 @@ begin
|
|||||||
{ all flags and information set to zero }
|
{ all flags and information set to zero }
|
||||||
FillChar(act, sizeof(SigActionRec),0);
|
FillChar(act, sizeof(SigActionRec),0);
|
||||||
{ initialize handler }
|
{ initialize handler }
|
||||||
act.sa_handler := @SignalToRunError;
|
act.sa_handler :=@SignalToRunError;
|
||||||
|
act.sa_flags:=SA_SIGINFO;
|
||||||
FpSigAction(SIGFPE,act,oldact);
|
FpSigAction(SIGFPE,act,oldact);
|
||||||
FpSigAction(SIGSEGV,act,oldact);
|
FpSigAction(SIGSEGV,act,oldact);
|
||||||
FpSigAction(SIGBUS,act,oldact);
|
FpSigAction(SIGBUS,act,oldact);
|
||||||
@ -628,7 +670,10 @@ End.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.4 2003-10-26 17:01:04 marco
|
Revision 1.5 2003-10-27 17:12:45 marco
|
||||||
|
* fixes for signal handling.
|
||||||
|
|
||||||
|
Revision 1.4 2003/10/26 17:01:04 marco
|
||||||
* moved sigprocmask to system
|
* moved sigprocmask to system
|
||||||
|
|
||||||
Revision 1.3 2003/09/27 13:04:58 peter
|
Revision 1.3 2003/09/27 13:04:58 peter
|
||||||
|
|||||||
@ -121,11 +121,43 @@ type sigset_t = array[0..3] of Longint;
|
|||||||
fpr_pad : array[0..63] of char;
|
fpr_pad : array[0..63] of char;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Sigval = Record
|
||||||
|
Case Boolean OF
|
||||||
|
{ Members as suggested by Annex C of POSIX 1003.1b. }
|
||||||
|
false : (sigval_int : Longint);
|
||||||
|
True : (sigval_ptr : Pointer);
|
||||||
|
End;
|
||||||
|
|
||||||
|
|
||||||
|
TSigInfo_t = record
|
||||||
|
si_signo, { signal number }
|
||||||
|
si_errno, { errno association }
|
||||||
|
{
|
||||||
|
* Cause of signal, one of the SI_ macros or signal-specific
|
||||||
|
* values, i.e. one of the FPE_... values for SIGFPE. This
|
||||||
|
* value is equivalent to the second argument to an old-style
|
||||||
|
* FreeBSD signal handler.
|
||||||
|
}
|
||||||
|
si_code, { signal code }
|
||||||
|
si_pid : Longint; { sending process }
|
||||||
|
si_uid : Cardinal; { sender's ruid }
|
||||||
|
si_status : Longint; { exit value }
|
||||||
|
si_addr : Pointer; { faulting instruction }
|
||||||
|
si_value : SigVal; { signal value }
|
||||||
|
si_band : Cardinal; { band event for SIGPOLL }
|
||||||
|
__spare : array[0..6] of Longint; { gimme some slack
|
||||||
|
}
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SignalHandler = Procedure(Sig : Longint);cdecl;
|
SignalHandler = Procedure(Sig : Longint);cdecl;
|
||||||
PSignalHandler = ^SignalHandler;
|
PSignalHandler = ^SignalHandler;
|
||||||
SignalRestorer = Procedure;cdecl;
|
SignalRestorer = Procedure;cdecl;
|
||||||
PSignalRestorer = ^SignalRestorer;
|
PSignalRestorer = ^SignalRestorer;
|
||||||
TSigAction = procedure(Sig: Longint; SigContext: SigContextRec;someptr:pointer);cdecl;
|
TSigAction = procedure(Sig: Longint; var sininfo:tsiginfo_t;var SigContext: SigContextRec);cdecl;
|
||||||
|
|
||||||
TSigset=sigset_t;
|
TSigset=sigset_t;
|
||||||
sigset=tsigset;
|
sigset=tsigset;
|
||||||
@ -137,7 +169,7 @@ type sigset_t = array[0..3] of Longint;
|
|||||||
0: (Sh: SignalHandler);
|
0: (Sh: SignalHandler);
|
||||||
1: (Sa: TSigAction);
|
1: (Sa: TSigAction);
|
||||||
end;}
|
end;}
|
||||||
sa_handler : signalhandler;
|
sa_handler : tsigAction;
|
||||||
Sa_Flags : Longint;
|
Sa_Flags : Longint;
|
||||||
Sa_Mask : TSigSet;
|
Sa_Mask : TSigSet;
|
||||||
end;
|
end;
|
||||||
@ -149,11 +181,24 @@ type sigset_t = array[0..3] of Longint;
|
|||||||
If Act is non-nil, it is used to specify the new action.
|
If Act is non-nil, it is used to specify the new action.
|
||||||
If OldAct is non-nil the previous action is saved there.
|
If OldAct is non-nil the previous action is saved there.
|
||||||
}
|
}
|
||||||
|
const
|
||||||
|
FPE_INTOVF =1; { integer overflow }
|
||||||
|
FPE_INTDIV =2; { integer divide by zero }
|
||||||
|
FPE_FLTDIV =3; { floating point divide by zero }
|
||||||
|
FPE_FLTOVF =4; { floating point overflow }
|
||||||
|
FPE_FLTUND =5; { floating point underflow }
|
||||||
|
FPE_FLTRES =6; { floating point inexact result }
|
||||||
|
FPE_FLTINV =7; { invalid floating point operation }
|
||||||
|
FPE_FLTSUB =8; { subscript out of range }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.7 2003-01-05 19:02:29 marco
|
Revision 1.8 2003-10-27 17:12:45 marco
|
||||||
|
* fixes for signal handling.
|
||||||
|
|
||||||
|
Revision 1.7 2003/01/05 19:02:29 marco
|
||||||
* Should now work with baseunx. (gmake all works)
|
* Should now work with baseunx. (gmake all works)
|
||||||
|
|
||||||
Revision 1.6 2002/10/26 18:27:52 marco
|
Revision 1.6 2002/10/26 18:27:52 marco
|
||||||
|
|||||||
@ -65,8 +65,6 @@ begin
|
|||||||
ThreadRoot:=nil;
|
ThreadRoot:=nil;
|
||||||
ThreadsInited:=true;
|
ThreadsInited:=true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This will install SIGCHLD signal handler
|
// This will install SIGCHLD signal handler
|
||||||
// signal() installs "one-shot" handler,
|
// signal() installs "one-shot" handler,
|
||||||
// so it is better to install and set up handler with sigaction()
|
// so it is better to install and set up handler with sigaction()
|
||||||
@ -74,7 +72,8 @@ begin
|
|||||||
GetMem(Act, SizeOf(SigActionRec));
|
GetMem(Act, SizeOf(SigActionRec));
|
||||||
GetMem(OldAct, SizeOf(SigActionRec));
|
GetMem(OldAct, SizeOf(SigActionRec));
|
||||||
|
|
||||||
Act^.sa_handler := @SIGCHLDHandler;
|
signalhandler(Act^.sa_handler) := @SIGCHLDHandler;
|
||||||
|
|
||||||
fillchar(Act^.sa_mask,sizeof(sigset_t),#0);
|
fillchar(Act^.sa_mask,sizeof(sigset_t),#0);
|
||||||
Act^.sa_flags := SA_NOCLDSTOP {or SA_NOMASK or SA_RESTART};
|
Act^.sa_flags := SA_NOCLDSTOP {or SA_NOMASK or SA_RESTART};
|
||||||
//Do not block all signals ??. Don't need if SA_NOMASK in flags
|
//Do not block all signals ??. Don't need if SA_NOMASK in flags
|
||||||
@ -297,7 +296,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.2 2003-10-09 10:55:20 marco
|
Revision 1.3 2003-10-27 17:12:45 marco
|
||||||
|
* fixes for signal handling.
|
||||||
|
|
||||||
|
Revision 1.2 2003/10/09 10:55:20 marco
|
||||||
* fix for moving classes to rtl while cycling with 1.0 start
|
* fix for moving classes to rtl while cycling with 1.0 start
|
||||||
|
|
||||||
Revision 1.1 2003/10/06 21:01:06 peter
|
Revision 1.1 2003/10/06 21:01:06 peter
|
||||||
|
|||||||
@ -115,11 +115,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Function FpSignal(signum:longint;Handler:signalhandler):signalhandler;
|
Function FpSignal(signum:longint;Handler:signalhandler):signalhandler;
|
||||||
|
// should be moved out of generic files. Too specific.
|
||||||
|
|
||||||
var sa,osa : sigactionrec;
|
var sa,osa : sigactionrec;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$Ifdef BSD}
|
||||||
|
sa.sa_handler:=tsigaction(handler);
|
||||||
|
{$else}
|
||||||
sa.sa_handler:=handler;
|
sa.sa_handler:=handler;
|
||||||
|
{$endif}
|
||||||
FillChar(sa.sa_mask,sizeof(sigset),#0);
|
FillChar(sa.sa_mask,sizeof(sigset),#0);
|
||||||
sa.sa_flags := 0;
|
sa.sa_flags := 0;
|
||||||
{ if (sigintr and signum) =0 then
|
{ if (sigintr and signum) =0 then
|
||||||
@ -130,7 +135,11 @@ begin
|
|||||||
if getErrNo<>0 then
|
if getErrNo<>0 then
|
||||||
fpsignal:=NIL
|
fpsignal:=NIL
|
||||||
else
|
else
|
||||||
|
{$ifdef BSD}
|
||||||
|
fpsignal:=signalhandler(osa.sa_handler);
|
||||||
|
{$else}
|
||||||
fpsignal:=osa.sa_handler;
|
fpsignal:=osa.sa_handler;
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function xFpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; external name 'FPC_SYSC_READ';
|
function xFpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; external name 'FPC_SYSC_READ';
|
||||||
@ -310,7 +319,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.6 2003-10-13 11:37:57 marco
|
Revision 1.7 2003-10-27 17:12:45 marco
|
||||||
|
* fixes for signal handling.
|
||||||
|
|
||||||
|
Revision 1.6 2003/10/13 11:37:57 marco
|
||||||
* more small fixes
|
* more small fixes
|
||||||
|
|
||||||
Revision 1.5 2003/10/12 14:37:10 marco
|
Revision 1.5 2003/10/12 14:37:10 marco
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user