Browse Source

* signal handling using sigaction when compiled with -dnewsignal
(allows multiple signals to be received in one run)

Jonas Maebe 25 years ago
parent
commit
cc86370fa3
2 changed files with 177 additions and 2 deletions
  1. 148 0
      rtl/linux/i386/signal.inc
  2. 29 2
      rtl/linux/syslinux.pp

+ 148 - 0
rtl/linux/i386/signal.inc

@@ -0,0 +1,148 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Jonas Maebe,
+    member of the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{$packrecords C}
+const
+  SI_PAD_SIZE	= ((128/sizeof(longint)) - 3);
+
+type
+  tfpreg = record 
+	  significand: array[0..3] of word;
+	  exponent: word;
+  end;
+
+  pfpstate = ^tfpstate;
+  tfpstate = record
+	   cw, sw, tag, ipoff, cssel, dataoff, datasel: cardinal;
+	   st: array[0..7] of tfpreg;
+	   status: cardinal;
+  end;
+
+  PSigContextRec = ^SigContextRec;
+  SigContextRec = record
+    gs, __gsh: word;
+    fs, __fsh: word;
+    es, __esh: word;
+    ds, __dsh: word;
+    edi: cardinal;
+    esi: cardinal;
+    ebp: cardinal;
+    esp: cardinal;
+    ebx: cardinal;
+    edx: cardinal;
+    ecx: cardinal;
+    eax: cardinal;
+    trapno: cardinal;
+    err: cardinal;
+    eip: cardinal;
+    cs, __csh: word;
+    eflags: cardinal;
+    esp_at_signal: cardinal;
+    ss, __ssh: word;
+    fpstate: pfpstate;
+    oldmask: cardinal;
+    cr2: cardinal;
+  end;
+
+(*
+  PSigInfoRec = ^SigInfoRec;
+  SigInfoRec = record
+    si_signo: longint;
+    si_errno: longint;
+    si_code: longint;
+
+    case longint of
+      0:
+        (pad: array[SI_PAD_SIZE] of longint);
+      1: { kill }
+        ( kill: record
+            pid: longint;  { sender's pid }
+            uid : longint; { sender's uid }
+          end );
+      2: { POSIX.1b timers }
+        ( timer : record
+            timer1 : cardinal;
+            timer2 : cardinal;
+           end );
+      3: { POSIX.1b signals }
+        ( rt : record
+            pid : longint;    { sender's pid }
+            uid : longint;    { sender's uid }
+            sigval : longint;
+         end );
+      4: { SIGCHLD }
+        ( sigchld : record
+          pid : longint;    { which child }
+          uid : longint;    { sender's uid }
+          status : longint; { exit code }
+          utime : timeval;
+          stime : timeval;
+         end );
+      5: { SIGILL, SIGFPE, SIGSEGV, SIGBUS }
+        ( sigfault : record
+            addr : pointer;{ faulting insn/memory ref. }
+          end );
+      6:
+        ( sigpoll : record
+            band : longint; { POLL_IN, POLL_OUT, POLL_MSG }
+            fd : longint;
+          end );
+  end;
+*)
+
+  SignalHandler   = Procedure(Sig : Longint);cdecl;
+  PSignalHandler  = ^SignalHandler;
+  SignalRestorer  = Procedure;cdecl;
+  PSignalRestorer = ^SignalRestorer;
+  TSigAction = procedure(Sig: Longint; SigContext: PSigContextRec);cdecl;
+
+  SigSet  = Longint;
+  PSigSet = ^SigSet;
+
+  SigActionRec = packed record
+    Handler  : record
+      case byte of
+        0: (Sh: SignalHandler);
+        1: (Sa: TSigAction);
+      end;
+    Sa_Mask     : SigSet;
+    Sa_Flags    : Longint;
+    Sa_restorer : SignalRestorer; { Obsolete - Don't use }
+  end;
+  PSigActionRec = ^SigActionRec;
+
+Procedure SigAction(Signum:Integer;Act,OldAct:PSigActionRec );
+{
+  Change action of process upon receipt of a signal.
+  Signum specifies the signal (all except SigKill and SigStop).
+  If Act is non-nil, it is used to specify the new action.
+  If OldAct is non-nil the previous action is saved there.
+}
+Var
+  sr : Syscallregs;
+begin
+  sr.reg2:=Signum;
+  sr.reg3:=Longint(act);
+  sr.reg4:=Longint(oldact);
+  SysCall(Syscall_nr_sigaction,sr);
+end;
+
+{
+  $Log$
+  Revision 1.1  2000-03-31 13:24:28  jonas
+    * signal handling using sigaction when compiled with -dnewsignal
+      (allows multiple signals to be received in one run)
+
+}

+ 29 - 2
rtl/linux/syslinux.pp

@@ -625,6 +625,7 @@ end;
                          SystemUnit Initialization
 *****************************************************************************}
 
+{$ifndef newSignal}
 Procedure SignalToRunError(Sig:longint);
 begin
   case sig of
@@ -633,7 +634,6 @@ begin
   end;
 end;
 
-
 Procedure InstallSignals;
 var
   sr : syscallregs;
@@ -646,6 +646,29 @@ begin
   sr.reg2:=8;
   syscall(syscall_nr_signal,sr);
 end;
+{$else newSignal}
+
+{$i i386/signal.inc}
+
+procedure SignalToRunerror(Sig: longint); cdecl;
+begin
+  case sig of
+    8 : HandleError(200);
+   11 : HandleError(216);
+  end;
+end;
+
+Procedure InstallSignals;
+const
+  act: SigActionRec = (handler:(Sh:@SignalToRunError);sa_mask:0;sa_flags:$40000000 or $10000000;
+                       Sa_restorer: NIL);
+  oldact: PSigActionRec = Nil;
+begin
+  SigAction(8,@act,oldact);
+  SigAction(11,@act,oldact);
+end;
+{$endif newSignal}
+
 
 
 procedure SetupCmdLine;
@@ -724,7 +747,11 @@ End.
 
 {
   $Log$
-  Revision 1.39  2000-03-25 12:28:37  peter
+  Revision 1.40  2000-03-31 13:24:28  jonas
+    * signal handling using sigaction when compiled with -dnewsignal
+      (allows multiple signals to be received in one run)
+
+  Revision 1.39  2000/03/25 12:28:37  peter
     * patch for getdir from Pierre
 
   Revision 1.38  2000/03/23 15:24:18  peter