2
0
Эх сурвалжийг харах

haiku: made signal handling properly support x86_64 as well, and sync'd SigContextRec and related structures with current Haiku code

git-svn-id: trunk@40829 -
Károly Balogh 6 жил өмнө
parent
commit
cc68e36efc

+ 5 - 5
rtl/haiku/i386/sighnd.inc

@@ -29,8 +29,8 @@ begin
         res:=200;
         // fp_status always here under BeOS and x86 CPU
         // (fp_status is not behind a pointer in the BeOS context record)
-        FpuState:=ucontext^.xregs.state.old_format.fp_status;
-            
+        FpuState:=ucontext^.uc_mcontext.xregs.state.old_format.fp_status;
+
         if (FpuState and FPU_ExceptionMask) <> 0 then
           begin
             { first check the more precise options }
@@ -47,7 +47,7 @@ begin
             else
               res:=207;  {'Coprocessor Error'}
           end;
-        with ucontext^.xregs.state.old_format do
+        with ucontext^.uc_mcontext.xregs.state.old_format do
         begin
           fp_status := fp_status and not FPU_ExceptionMask;
         end;
@@ -85,8 +85,8 @@ begin
 { give runtime error at the position where the signal was raised }
   if res<>0 then
   begin
-    HandleErrorAddrFrame(res, pointer(ucontext^.eip),
-                              pointer(ucontext^.ebp));    
+    HandleErrorAddrFrame(res, pointer(ucontext^.uc_mcontext.eip),
+                              pointer(ucontext^.uc_mcontext.ebp));
   end;
 end;
 

+ 0 - 2
rtl/haiku/ostypes.inc

@@ -64,9 +64,7 @@ Const
 
 CONST               // OS specific parameters for general<fd,sig>set behaviour
    BITSINWORD      = 8*sizeof(longint);
-//   SIG_MAXSIG      = 32;    //128;	// highest signal version
    FD_MAXFDSET     = 1024;
-//   wordsinsigset   = 4;           // words in sigset_t
    ln2bitsinword   = 5;         { 32bit : ln(32)/ln(2)=5 } 
    ln2bitmask	   = 2 shl ln2bitsinword - 1;
    wordsinfdset    = FD_MAXFDSET DIV BITSINWORD;        // words in fdset_t

+ 1 - 1
rtl/haiku/ptypes.inc

@@ -227,7 +227,7 @@ CONST
 
     SYS_NMLN = 32;              {BSD utsname struct limit}
 
-    SIG_MAXSIG = 32; //128;	// highest signal version  // BeOS  
+    SIG_MAXSIG = 64;    { __MAX_SIGNO in signal.h }
 
 const
   { For getting/setting priority }

+ 56 - 243
rtl/haiku/signal.inc

@@ -29,20 +29,20 @@ Const   { For sending a signal }
   SIG_BLOCK   = 1;
   SIG_UNBLOCK = 2;
   SIG_SETMASK = 3;
-  
+
 { values for ss_flags }
-  SS_ONSTACK	= $1;
-  SS_DISABLE	= $2;
-  
-  MINSIGSTKSZ	= 4096;
-  SIGSTKSZ		= 16384;
-	
+  SS_ONSTACK = $1;
+  SS_DISABLE = $2;
+
+  MINSIGSTKSZ = 4096;
+  SIGSTKSZ = 16384;
+
 {Haiku Checked}
 {
    The numbering of signals for BeOS attempts to maintain 
    some consistency with UN*X conventions so that things 
    like "kill -9" do what you expect.
-}   
+}
 
   SIG_DFL  =  0;
   SIG_IGN  =  1;
@@ -81,264 +81,79 @@ Const   { For sending a signal }
   SIGBUS     = 30;
   SIGRESERVED1 = 31;
   SIGRESERVED2 = 32;
-  
-{
-   Signal numbers 23-32 are currently free but may be used in future
-   releases.  Use them at your own peril (if you do use them, at least
-   be smart and use them backwards from signal 32).
-}
 
-{$packrecords C}
-const
-  SI_PAD_SIZE   = ((128/sizeof(longint)) - 3);
 
-{
- * The sequence of the fields/registers in struct sigcontext should match
- * those in mcontext_t.
- }
+{ Include BeOS/Haiku specific vregs struct, which is architecture dependent
+  and maps directly as mcontext_t }
+{$include sig_cpu.inc}
 
-type 
-  packed_fp_stack = packed record
-    st0 : array[0..9] of byte;
-    st1 : array[0..9] of byte;
-    st2 : array[0..9] of byte;
-    st3 : array[0..9] of byte;
-    st4 : array[0..9] of byte;
-    st5 : array[0..9] of byte;
-    st6 : array[0..9] of byte;    
-    st7 : array[0..9] of byte;    
-  end;
-  
-  packed_mmx_regs = packed record
-    mm0 : array[0..9] of byte;
-    mm1 : array[0..9] of byte;
-    mm2 : array[0..9] of byte;
-    mm3 : array[0..9] of byte;
-    mm4 : array[0..9] of byte;
-    mm5 : array[0..9] of byte;
-    mm6 : array[0..9] of byte;    
-    mm7 : array[0..9] of byte;    
-  end;
-  
-  old_extended_regs = packed record
-    fp_control 	: word;
-    _reserved1 	: word;
-    fp_status 	: word;
-    _reserved2 	: word;
-    fp_tag 		: word;
-    _reserved3 	: word;
-    fp_eip 		: cardinal;
-    fp_cs 		: word;
-    fp_opcode	: word;
-    fp_datap	: word;
-    fp_ds		: word;
-    _reserved4	: word;
-    fp_mmx : record
-      case fp_mmx : byte of
-        0 : (fp	: packed_fp_stack);
-        1 : (mmx	: packed_mmx_regs);
-    end;
-  end;
-  
-  fp_stack = record
-    st0 : array[0..9] of byte;
-    _reserved_42_47 : array[0..5] of byte;
-    st1 : array[0..9] of byte;
-    _reserved_58_63 : array[0..5] of byte;
-    st2 : array[0..9] of byte;
-    _reserved_74_79 : array[0..5] of byte;
-    st3 : array[0..9] of byte;
-    _reserved_90_95 : array[0..5] of byte;
-    st4 : array[0..9] of byte;
-    _reserved_106_111 : array[0..5] of byte;
-    st5 : array[0..9] of byte;
-    _reserved_122_127 : array[0..5] of byte;
-    st6 : array[0..9] of byte;    
-    _reserved_138_143 : array[0..5] of byte;
-    st7 : array[0..9] of byte;        
-    _reserved_154_159 : array[0..5] of byte;
-  end;
-  
-  mmx_regs = record
-    mm0 : array[0..9] of byte;
-    _reserved_42_47 : array[0..5] of byte;
-    mm1 : array[0..9] of byte;
-    _reserved_58_63 : array[0..5] of byte;
-    mm2 : array[0..9] of byte;
-    _reserved_74_79 : array[0..5] of byte;
-    mm3 : array[0..9] of byte;
-    _reserved_90_95 : array[0..5] of byte;
-    mm4 : array[0..9] of byte;
-    _reserved_106_111 : array[0..5] of byte;
-    mm5 : array[0..9] of byte;
-    _reserved_122_127 : array[0..5] of byte;
-    mm6 : array[0..9] of byte;    
-    _reserved_138_143 : array[0..5] of byte;
-    mm7 : array[0..9] of byte;    
-    _reserved_154_159 : array[0..5] of byte;
-  end;
-  
-  xmmx_regs = record
-    xmm0 : array [0..15] of byte;
-    xmm1 : array [0..15] of byte;
-    xmm2 : array [0..15] of byte;
-    xmm3 : array [0..15] of byte;
-    xmm4 : array [0..15] of byte;
-    xmm5 : array [0..15] of byte;
-    xmm6 : array [0..15] of byte;
-    xmm7 : array [0..15] of byte;
-  end;
-  
-  new_extended_regs = record
-    fp_control 	: word;
-    fp_status 	: word;
-    fp_tag		: word;
-    fp_opcode	: word;
-    fp_eip		: Cardinal;
-    fp_cs		: word;
-    res_14_15	: word;
-    fp_datap	: Cardinal;
-    fp_ds		: word;
-    _reserved_22_23 : word;
-    mxcsr		: Cardinal;
-    _reserved_28_31 : Cardinal;
-    fp_mmx : record
-      case byte of
-        0 : (fp : fp_stack);
-        1 : (mmx : mmx_regs);
-    end;
-    xmmx : xmmx_regs;
-    _reserved_288_511 : array[0..223] of byte;
-  end;
-  
-  extended_regs = record
-    state : record
-      case byte of
-  	    0 : (old_format : old_extended_regs);
-  	    1 : (new_format : new_extended_regs);  	  
-  	end;
-  	format	: Cardinal;
-  end;
-  
-  vregs = record
-    eip 	: Cardinal;
-    eflags 	: cardinal;
-    eax		: Cardinal;
-    ecx		: Cardinal;
-    edx		: Cardinal;
-    esp		: Cardinal;
-    ebp		: Cardinal;
-    _reserved_1 : Cardinal;
-    xregs	: extended_regs;
-    _reserved_2 : array[0..2] of Cardinal;
-  end;
-  
+{$packrecords C}
+type
+  mcontext_t = vregs;
   Pvregs = ^vregs;
 
-  sigset_t = array[0..1] of Cardinal;
-
-    PSigContext = ^vregs;
-
-    PSigContextRec = ^SigContextRec;
-    SigContextRec = record
-       sc_mask      : sigset_t;          { signal mask to restore }
-       sc_onstack   : longint;              { sigstack state to restore }
+  pstack_t = ^stack_t;
+  stack_t = record
+    ss_sp: pointer;                       {* signal stack base *}
+    ss_size: size_t;                    {* signal stack length *}
+    ss_flags: cint;                     {* SS_DISABLE and/or SS_ONSTACK *}
+  end;
+  TStack = stack_t;
+  PStack = pstack_t;
 
-       sc_gs        : longint;              { machine state (struct trapframe): }
-       sc_fs        : longint;
-       sc_es        : longint;
-       sc_ds        : longint;
-       sc_edi       : longint;
-       sc_esi       : longint;
-       sc_ebp       : longint;
-       sc_isp       : longint;
-       sc_ebx       : longint;
-       sc_edx       : longint;
-       sc_ecx       : longint;
-       sc_eax       : longint;
-       sc_trapno    : longint;
-       sc_err       : longint;
-       sc_eip       : longint;
-       sc_cs        : longint;
-       sc_efl       : longint;
-       sc_esp       : longint;
-       sc_ss        : longint;
-        {
-         * XXX FPU state is 27 * 4 bytes h/w, 1 * 4 bytes s/w (probably not
-         * needed here), or that + 16 * 4 bytes for emulators (probably all
-         * needed here).  The "spare" bytes are mostly not spare.
-         }
-       en_cw        : cardinal;     { control word (16bits used) }
-       en_sw        : cardinal;     { status word (16bits) }
-       en_tw        : cardinal;     { tag word (16bits) }
-       en_fip       : cardinal;     { floating point instruction pointer }
-       en_fcs       : word;         { floating code segment selector }
-       en_opcode    : word;         { opcode last executed (11 bits ) }
-       en_foo       : cardinal;     { floating operand offset }
-       en_fos       : cardinal;     { floating operand segment selector }
-       fpr_acc      : array[0..79] of char;
-       fpr_ex_sw    : cardinal;
-       fpr_pad      : array[0..63] of char;
-       end;
+  sigset_t = array[0..wordsinsigset-1] of dword;
 
-  Sigval = Record
-            Case Boolean OF
-        { Members as suggested by Annex C of POSIX 1003.1b. }
-                false : (sigval_int : Longint);
-                True  : (sigval_ptr : Pointer);
-            End;
+  PSigContext = ^SigContextRec;
+  PSigContextRec = ^SigContextRec;
+  SigContextRec = record
+    uc_link: PSigContextRec;
+    uc_sigmask: sigset_t;
+    uc_stack: stack_t;
+    uc_mcontext: mcontext_t;
+  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;
 
   PSigInfo   = ^SigInfo_t;
   PSigInfo_t = ^SigInfo_t;
-  SigInfo_t = packed record
-                si_signo,                       { signal number }
-                si_code,                        { signal code }
-                si_errno,                       { errno association }
-                si_pid          : pid_t;      { sending process }
-                si_uid          : uid_t;     { sender's ruid }
-                si_addr         : Pointer;      { faulting instruction }                
-                si_status       : Longint;      { exit value }
-                si_band         : Cardinal;     { band event for SIGPOLL }                
-                si_value        : SigVal;       { signal value }
-                end;
+  SigInfo_t = record
+    si_signo: cint;     { signal number }
+    si_code: cint;      { signal code }
+    si_errno: cint;     { if non zero, an error number associated with this signal }
+    si_pid: pid_t;      { sending process }
+    si_uid: uid_t;      { sender's ruid }
+    si_addr: Pointer;   { faulting instruction }
+    si_status: cint;    { exit value }
+    si_band: clong;     { band event for SIGPOLL }
+    si_value: SigVal;   { signal value }
+  end;
   TSigInfo = SigInfo_t;
-  TSigInfo_t = TSigInfo;       
-       
+  TSigInfo_t = TSigInfo;
+
   SignalHandler   = Procedure(Sig : Longint);cdecl;
   PSignalHandler  = ^SignalHandler;
   SignalRestorer  = Procedure;cdecl;
   PSignalRestorer = ^SignalRestorer;
-  sigActionHandler = procedure(Sig: Longint; SigInfo: PSigInfo; uContext : PSigContext);cdecl;
-
+  SigActionHandler = procedure(Sig: Longint; SigInfo: PSigInfo; uContext : PSigContext);cdecl;
 
   Sigset=sigset_t;
   TSigset=sigset_t;
   PSigSet = ^SigSet;
   psigset_t=psigset;
 
+  PSigActionRec = ^SigActionRec;
   SigActionRec = record
-//    Handler  : record
-    sa_handler : sigActionHandler;
-//      case byte of
-//        0: (Sh: SignalHandler);
-//        1: (Sa: TSigAction);
-//      end;
-    sa_Mask     : SigSet;
-    sa_Flags    : Longint;
-    sa_userdata : pointer
+    sa_handler : SigActionHandler;
+    sa_Mask    : SigSet;
+    sa_Flags   : Longint;
+    sa_userdata: pointer;
   end;
 
-  PSigActionRec = ^SigActionRec;
-
-  pstack_t = ^stack_t;
-  stack_t = record
-    ss_sp: pChar;                       {* signal stack base *}
-    ss_size: size_t;                    {* signal stack length *}
-    ss_flags: cInt;                     {* SS_DISABLE and/or SS_ONSTACK *}
-  end;
-  TStack = stack_t;
-  PStack = pstack_t;
 
 {
   Change action of process upon receipt of a signal.
@@ -346,5 +161,3 @@ type
   If Act is non-nil, it is used to specify the new action.
   If OldAct is non-nil the previous action is saved there.
 }
-
-

+ 6 - 7
rtl/haiku/x86_64/sighnd.inc

@@ -29,8 +29,8 @@ begin
         res:=200;
         // fp_status always here under BeOS and x86 CPU
         // (fp_status is not behind a pointer in the BeOS context record)
-        FpuState:=ucontext^.xregs.state.old_format.fp_status;
-            
+        FpuState:=ucontext^.uc_mcontext.fpu.status;
+
         if (FpuState and FPU_ExceptionMask) <> 0 then
           begin
             { first check the more precise options }
@@ -47,9 +47,9 @@ begin
             else
               res:=207;  {'Coprocessor Error'}
           end;
-        with ucontext^.xregs.state.old_format do
+        with ucontext^.uc_mcontext.fpu do
         begin
-          fp_status := fp_status and not FPU_ExceptionMask;
+          status := status and not FPU_ExceptionMask;
         end;
         SysResetFPU;
       end;
@@ -86,9 +86,8 @@ begin
 { give runtime error at the position where the signal was raised }
   if res<>0 then
   begin
-    HandleErrorAddrFrame(res, pointer(ucontext^.eip),
-                              pointer(ucontext^.ebp));    
+    HandleErrorAddrFrame(res, pointer(ucontext^.uc_mcontext.rip),
+                              pointer(ucontext^.uc_mcontext.rbp));
   end;
 end;
 
-