[Mono-dev] backport of some openbsd stuff to 2.6

Robert Nagy robert at openbsd.org
Tue Apr 27 09:43:27 EDT 2010


Hi

The attached diff backports some missing stuff from HEAD to branch_2_6
that was probably forgotten to be commited when we worked on it because
some parts of it are in already.
It also fixed a null pointer reference that was fixed in HEAD too,
the other changes are OpenBSD only.
Please commit.
-------------- next part --------------
Index: mono/metadata/threadpool.c
===================================================================
--- mono/metadata/threadpool.c	(revision 156177)
+++ mono/metadata/threadpool.c	(working copy)
@@ -527,7 +527,8 @@
 
 			for (i = 1; i < allocated; i++) {
 				pfd = &pfds [i];
-				if (pfd->fd == -1 || pfd->fd == data->newpfd->fd)
+				if (pfd->fd == -1 || data->newpfd == NULL ||
+				    pfd->fd == data->newpfd->fd)
 					break;
 			}
 
Index: mono/mini/mini-amd64.h
===================================================================
--- mono/mini/mini-amd64.h	(revision 156177)
+++ mono/mini/mini-amd64.h	(working copy)
@@ -254,10 +254,6 @@
 
 #endif
 
-#ifdef __OpenBSD__
-#undef MONO_ARCH_USE_SIGACTION
-#endif
-
 #endif /* PLATFORM_WIN32 */
 
 #if defined (__NetBSD__)
@@ -282,8 +278,12 @@
 
 #define MONO_ARCH_NOMAP32BIT
 
-#elif defined (__FreeBSD__) || defined (__OpenBSD__)
+#elif defined (__OpenBSD__)
 
+#define MONO_ARCH_NOMAP32BIT
+
+#elif defined (__FreeBSD__)
+
 #define REG_RAX 7
 #define REG_RCX 4
 #define REG_RDX 3
Index: mono/mini/exceptions-amd64.c
===================================================================
--- mono/mini/exceptions-amd64.c	(revision 156177)
+++ mono/mini/exceptions-amd64.c	(working copy)
@@ -711,7 +711,7 @@
 	return TRUE;
 }
 
-#ifdef MONO_ARCH_USE_SIGACTION
+#if defined(MONO_ARCH_USE_SIGACTION) && defined(UCONTEXT_GREGS)
 static inline guint64*
 gregs_from_ucontext (ucontext_t *ctx)
 {
@@ -721,7 +721,7 @@
 void
 mono_arch_sigctx_to_monoctx (void *sigctx, MonoContext *mctx)
 {
-#ifdef MONO_ARCH_USE_SIGACTION
+#if defined(MONO_ARCH_USE_SIGACTION) && defined(UCONTEXT_GREGS)
 	ucontext_t *ctx = (ucontext_t*)sigctx;
 
     guint64 *gregs = gregs_from_ucontext (ctx);
@@ -739,6 +739,22 @@
 	mctx->r13 = gregs [REG_R13];
 	mctx->r14 = gregs [REG_R14];
 	mctx->r15 = gregs [REG_R15];
+#elif defined(MONO_ARCH_USE_SIGACTION)
+	ucontext_t *ctx = (ucontext_t*)sigctx;
+
+	mctx->rax = UCONTEXT_REG_RAX (ctx);
+	mctx->rbx = UCONTEXT_REG_RBX (ctx);
+	mctx->rcx = UCONTEXT_REG_RCX (ctx);
+	mctx->rdx = UCONTEXT_REG_RDX (ctx);
+	mctx->rbp = UCONTEXT_REG_RBP (ctx);
+	mctx->rsp = UCONTEXT_REG_RSP (ctx);
+	mctx->rsi = UCONTEXT_REG_RSI (ctx);
+	mctx->rdi = UCONTEXT_REG_RDI (ctx);
+	mctx->rip = UCONTEXT_REG_RIP (ctx);
+	mctx->r12 = UCONTEXT_REG_R12 (ctx);
+	mctx->r13 = UCONTEXT_REG_R13 (ctx);
+	mctx->r14 = UCONTEXT_REG_R14 (ctx);
+	mctx->r15 = UCONTEXT_REG_R15 (ctx);
 #else
 	MonoContext *ctx = (MonoContext *)sigctx;
 
@@ -761,7 +777,7 @@
 void
 mono_arch_monoctx_to_sigctx (MonoContext *mctx, void *sigctx)
 {
-#ifdef MONO_ARCH_USE_SIGACTION
+#if defined(MONO_ARCH_USE_SIGACTION) && defined(UCONTEXT_GREGS)
 	ucontext_t *ctx = (ucontext_t*)sigctx;
 
     guint64 *gregs = gregs_from_ucontext (ctx);
@@ -779,6 +795,22 @@
 	gregs [REG_R13] = mctx->r13;
 	gregs [REG_R14] = mctx->r14;
 	gregs [REG_R15] = mctx->r15;
+#elif defined(MONO_ARCH_USE_SIGACTION)
+	ucontext_t *ctx = (ucontext_t*)sigctx;
+
+	UCONTEXT_REG_RAX (ctx) = mctx->rax;
+	UCONTEXT_REG_RBX (ctx) = mctx->rbx;
+	UCONTEXT_REG_RCX (ctx) = mctx->rcx;
+	UCONTEXT_REG_RDX (ctx) = mctx->rdx;
+	UCONTEXT_REG_RBP (ctx) = mctx->rbp;
+	UCONTEXT_REG_RSP (ctx) = mctx->rsp;
+	UCONTEXT_REG_RSI (ctx) = mctx->rsi;
+	UCONTEXT_REG_RDI (ctx) = mctx->rdi;
+	UCONTEXT_REG_RIP (ctx) = mctx->rip;
+	UCONTEXT_REG_R12 (ctx) = mctx->r12;
+	UCONTEXT_REG_R13 (ctx) = mctx->r13;
+	UCONTEXT_REG_R14 (ctx) = mctx->r14;
+	UCONTEXT_REG_R15 (ctx) = mctx->r15;
 #else
 	MonoContext *ctx = (MonoContext *)sigctx;
 
@@ -801,14 +833,16 @@
 gpointer
 mono_arch_ip_from_context (void *sigctx)
 {
-	
-#ifdef MONO_ARCH_USE_SIGACTION
-
+#if defined(MONO_ARCH_USE_SIGACTION) && defined(UCONTEXT_GREGS)
 	ucontext_t *ctx = (ucontext_t*)sigctx;
 
     guint64 *gregs = gregs_from_ucontext (ctx);
 
 	return (gpointer)gregs [REG_RIP];
+#elif defined(MONO_ARCH_USE_SIGACTION)
+	ucontext_t *ctx = (ucontext_t*)sigctx;
+
+	return (gpointer)UCONTEXT_REG_RIP (ctx);
 #else
 	MonoContext *ctx = sigctx;
 	return (gpointer)ctx->rip;
@@ -865,7 +899,7 @@
 void
 mono_arch_handle_altstack_exception (void *sigctx, gpointer fault_addr, gboolean stack_ovf)
 {
-#ifdef MONO_ARCH_USE_SIGACTION
+#if defined(MONO_ARCH_USE_SIGACTION) && defined(UCONTEXT_GREGS)
 	MonoException *exc = NULL;
 	ucontext_t *ctx = (ucontext_t*)sigctx;
 	guint64 *gregs = gregs_from_ucontext (ctx);
Index: mono/utils/mono-sigcontext.h
===================================================================
--- mono/utils/mono-sigcontext.h	(revision 156177)
+++ mono/utils/mono-sigcontext.h	(working copy)
@@ -80,6 +80,21 @@
 
 #ifdef __FreeBSD__
 #define UCONTEXT_GREGS(ctx)	&(((ucontext_t*)(ctx))->uc_mcontext)
+#elif defined(__OpenBSD__)
+	/* OpenBSD/amd64 has no gregs array, ucontext_t == sigcontext */
+	#define UCONTEXT_REG_RAX(ctx) ((ctx)->sc_rax)
+	#define UCONTEXT_REG_RBX(ctx) ((ctx)->sc_rbx)
+	#define UCONTEXT_REG_RCX(ctx) ((ctx)->sc_rcx)
+	#define UCONTEXT_REG_RDX(ctx) ((ctx)->sc_rdx)
+	#define UCONTEXT_REG_RBP(ctx) ((ctx)->sc_rbp)
+	#define UCONTEXT_REG_RSP(ctx) ((ctx)->sc_rsp)
+	#define UCONTEXT_REG_RSI(ctx) ((ctx)->sc_rsi)
+	#define UCONTEXT_REG_RDI(ctx) ((ctx)->sc_rdi)
+	#define UCONTEXT_REG_RIP(ctx) ((ctx)->sc_rip)
+	#define UCONTEXT_REG_R12(ctx) ((ctx)->sc_r12)
+	#define UCONTEXT_REG_R13(ctx) ((ctx)->sc_r13)
+	#define UCONTEXT_REG_R14(ctx) ((ctx)->sc_r14)
+	#define UCONTEXT_REG_R15(ctx) ((ctx)->sc_r15)
 #else
 #define UCONTEXT_GREGS(ctx)	&(((ucontext_t*)(ctx))->uc_mcontext.gregs)
 #endif
Index: configure.in
===================================================================
--- configure.in	(revision 156177)
+++ configure.in	(working copy)
@@ -1802,7 +1802,7 @@
 
 case "{$target}" in
     *-openbsd*)
-    NAME_DEV_RANDOM="/dev/srandom"
+    NAME_DEV_RANDOM="/dev/arandom"
     ;;
 
 dnl Win32 does not have /dev/random, they have their own method...


More information about the Mono-devel-list mailing list