Mac OS X Support : Signals support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
This patch add in signal_powerpc.c of ntdll support for darwin signal.
Cheers,

Pierre

Modified files:
dlls/ntdll/signal_powerpc.c

ChangeLog:
Add support for Darwin's signals.

Index: dlls/ntdll/signal_powerpc.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/signal_powerpc.c,v
retrieving revision 1.12
diff -u -r1.12 signal_powerpc.c
--- dlls/ntdll/signal_powerpc.c	3 Apr 2003 23:57:11 -0000	1.12
+++ dlls/ntdll/signal_powerpc.c	3 May 2003 19:19:40 -0000
@@ -31,6 +31,15 @@
 # include <unistd.h>
 #endif
 
+#ifdef __darwin__
+// FIXME : should probably use HAVE_SYS_UCONTEXT_H
+# include <sys/ucontext.h>
+// FIXME : should probbably use HAVE_SIGNAL_H
+# include <signal.h>
+#include <sys/types.h>
+typedef siginfo_t siginfo;
+#endif
+
 #ifdef HAVE_SYS_PARAM_H
 # include <sys/param.h>
 #endif
@@ -69,7 +78,12 @@
 
 typedef struct ucontext SIGCONTEXT;
 
-#define HANDLER_DEF(name) void name( int __signal, struct siginfo *__siginfo, SIGCONTEXT *__context )
+#ifdef __darwin__
+# define HANDLER_DEF(name) void name( int __signal,        siginfo *__siginfo, SIGCONTEXT *__context )
+#else
+# define HANDLER_DEF(name) void name( int __signal, struct siginfo *__siginfo, SIGCONTEXT *__context )
+#endif
+
 #define HANDLER_CONTEXT (__context)
 
 typedef int (*wine_signal_handler)(unsigned int sig);
@@ -94,16 +108,27 @@
  */
 static void save_context( CONTEXT *context, const SIGCONTEXT *sigcontext )
 {
-#define CX(x,y) context->x = sigcontext->uc_mcontext.regs->y
-#define C(x) CX(Gpr##x,gpr[x])
+#ifdef __darwin__
+// Handle context using darwin way
+# define CX(x,y) context->x = sigcontext->uc_mcontext->ss.y
+# define C(x) CX(Gpr##x,r##x)
+#else
+# define CX(x,y) context->x = sigcontext->uc_mcontext.regs->y
+# define C(x) CX(Gpr##x,gpr[x])
+#endif
 	C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
 	C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
 	C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
 	C(31);
-
+#ifdef __darwin__
+	CX(Iar,srr0); /* Program Counter */
+	CX(Msr,srr1);  /* Machine State Reister (Supervisor) */
+	CX(Ctr,ctr);
+#else
 	CX(Iar,nip);
 	CX(Msr,msr);
 	CX(Ctr,ctr);
+#endif /* __darwin__ */
 #undef CX
 	/* FIXME: fp regs? */
 
@@ -128,15 +153,26 @@
  */
 static void restore_context( const CONTEXT *context, SIGCONTEXT *sigcontext )
 {
-#define CX(x,y) sigcontext->uc_mcontext.regs->y = context->x
+#ifdef __darwin__
+# define CX(x,y) sigcontext->uc_mcontext->ss.y = context->x
+#else
+# define CX(x,y) sigcontext->uc_mcontext.regs->y = context->x
+#endif /* __darwin__ */
 	C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
 	C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
 	C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
 	C(31);
 
+#ifdef __darwin__
+	CX(Iar,srr0); /* Program Counter */
+	CX(Msr,srr1);  /* Machine State Reister (Supervisor) */
+	CX(Ctr,ctr);
+#else /* __darwin__ */
 	CX(Iar,nip);
 	CX(Msr,msr);
 	CX(Ctr,ctr);
+#endif /* __darwin__ */
+
 #undef CX
 }
 
@@ -187,6 +223,67 @@
     return EXCEPTION_FLT_INVALID_OPERATION;  /* generic error */
 }
 
+#ifdef __darwin__
+/**********************************************************************
+ *		segv_handler
+ *
+ * Handler for SIGSEGV and related errors.
+ */
+static HANDLER_DEF(segv_handler)
+{
+    CONTEXT context;
+    EXCEPTION_RECORD rec;
+    DWORD page_fault_code = EXCEPTION_ACCESS_VIOLATION;
+
+    save_context( &context, HANDLER_CONTEXT );
+
+    rec.ExceptionRecord  = NULL;
+    rec.ExceptionFlags   = EXCEPTION_CONTINUABLE;
+    rec.ExceptionAddress = (LPVOID)HANDLER_CONTEXT->uc_mcontext->ss.srr0;
+    rec.NumberParameters = 0;
+    switch (__siginfo->si_signo) {
+    case SIGSEGV:
+    	switch ( __siginfo->si_code & 0xffff ) {
+	case SEGV_MAPERR:
+	case SEGV_ACCERR:
+		rec.NumberParameters = 2;
+		rec.ExceptionInformation[0] = 0; /* FIXME ? */
+		rec.ExceptionInformation[1] = (DWORD)__siginfo->si_addr;
+		if (!(page_fault_code=VIRTUAL_HandleFault(__siginfo->si_addr)))
+			return;
+		rec.ExceptionCode = page_fault_code;
+		break;
+	default:FIXME("Unhandled SIGSEGV/%x\n",__siginfo->si_code);
+		break;
+	}
+    	break;
+    case SIGBUS:
+    	switch ( __siginfo->si_code & 0xffff ) {
+	case BUS_ADRALN:
+		rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
+		break;
+	default:FIXME("Unhandled SIGBUS/%x\n",__siginfo->si_code);
+		break;
+	}
+    	break;
+    case SIGILL:
+    	switch ( __siginfo->si_code & 0xffff ) {
+	case ILL_ILLOPC: /* illegal opcode */
+	case ILL_ILLTRP: /* illegal trap */
+		rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
+		break;
+	case ILL_PRVOPC: /* privileged opcode */
+		rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
+		break;
+	default:FIXME("Unhandled SIGILL/%x\n",__siginfo->si_code);
+		break;
+	}
+    	break;
+    }
+    EXC_RtlRaiseException( &rec, &context );
+    restore_context( &context, HANDLER_CONTEXT );
+}
+#else /* __darwin__ */
 
 /**********************************************************************
  *		segv_handler
@@ -264,7 +361,35 @@
     EXC_RtlRaiseException( &rec, &context );
     restore_context( &context, HANDLER_CONTEXT );
 }
+#endif /* __darwin__ */
 
+#ifdef __darwin__
+/**********************************************************************
+ *		trap_handler for darwin
+ *
+ * Handler for SIGTRAP.
+ */
+static HANDLER_DEF(trap_handler)
+{
+    CONTEXT context;
+    EXCEPTION_RECORD rec;
+
+    save_context( &context, HANDLER_CONTEXT );
+
+    rec.ExceptionFlags   = EXCEPTION_CONTINUABLE;
+    rec.ExceptionRecord  = NULL;
+    rec.ExceptionAddress = (LPVOID)__context->uc_mcontext->ss.srr0;
+    rec.NumberParameters = 0;
+
+    /* FIXME: check if we might need to modify PC */
+    switch (__siginfo->si_code & 0xffff) {
+    default:FIXME("Unhandled SIGTRAP/%x\n",__siginfo->si_code);
+		break;
+    }
+    EXC_RtlRaiseException( &rec, &context );
+    restore_context( &context, HANDLER_CONTEXT );
+}
+#else /* __darwin__ */
 /**********************************************************************
  *		trap_handler
  *
@@ -294,8 +419,49 @@
     EXC_RtlRaiseException( &rec, &context );
     restore_context( &context, HANDLER_CONTEXT );
 }
+#endif /* __darwin__ */
 
+#ifdef __darwin__
+/**********************************************************************
+ *		fpe_handler
+ *
+ * Handler for SIGFPE.
+ */
+static HANDLER_DEF(fpe_handler)
+{
+    CONTEXT context;
+    EXCEPTION_RECORD rec;
+
+    /*save_fpu( &context, HANDLER_CONTEXT );*/
+    save_context( &context, HANDLER_CONTEXT );
 
+    switch ( __siginfo->si_code  & 0xffff ) {
+    case FPE_FLTDIV:
+        rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
+        break;
+    case FPE_FLTOVF:
+        rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
+        break;
+    case FPE_FLTUND:
+        rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
+        break;
+    case FPE_FLTRES:
+        rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
+        break;
+    case FPE_FLTINV:
+    default:
+        rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
+        break;
+    }
+    rec.ExceptionFlags   = EXCEPTION_CONTINUABLE;
+    rec.ExceptionRecord  = NULL;
+    rec.ExceptionAddress = (LPVOID)__context->uc_mcontext->ss.srr0;
+    rec.NumberParameters = 0;
+    EXC_RtlRaiseException( &rec, &context );
+    restore_context( &context, HANDLER_CONTEXT );
+    /*restore_fpu( &context, HANDLER_CONTEXT );*/
+}
+#else /* __darwin__ */
 /**********************************************************************
  *		fpe_handler
  *
@@ -344,7 +510,7 @@
     restore_context( &context, HANDLER_CONTEXT );
     /*restore_fpu( &context, HANDLER_CONTEXT );*/
 }
-
+#endif /* __darwin__ */
 
 /**********************************************************************
  *		int_handler
@@ -469,7 +635,7 @@
     }
 #endif  /* HAVE_SIGALTSTACK */
 
-    sigfillset( &all_sigs );
+    /* sigfillset( &all_sigs ); Do not use it*/
 
     if (set_handler( SIGINT,  have_sigaltstack, (void (*)())int_handler ) == -1) goto error;
     if (set_handler( SIGFPE,  have_sigaltstack, (void (*)())fpe_handler ) == -1) goto error;

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux