$OpenBSD$
--- os_dep.c.orig	Sun Sep  3 17:36:00 2006
+++ os_dep.c	Sun Sep  3 17:43:47 2006
@@ -91,7 +91,7 @@
 #  endif
 #endif
 
-#if (defined(NETBSD) || defined(OPENBSD)) && defined(__ELF__) \
+#if defined(NETBSD)  && defined(__ELF__) \
     && !defined(NEED_FIND_LIMIT)
    /* Used by GC_init_netbsd_elf() below.	*/
 #  define NEED_FIND_LIMIT
@@ -380,7 +380,7 @@ static void *tiny_sbrk(ptrdiff_t increme
 #define sbrk tiny_sbrk
 # endif /* ECOS */
 
-#if (defined(NETBSD) || defined(OPENBSD)) && defined(__ELF__)
+#if defined(NETBSD) && defined(__ELF__)
   ptr_t GC_data_start;
 
   void GC_init_netbsd_elf()
@@ -393,6 +393,46 @@ static void *tiny_sbrk(ptrdiff_t increme
   }
 #endif
 
+
+#if defined(OPENBSD)
+#undef	OPENBSD_USING_INTERNAL_FINDLIMIT		/* use boehm-gc find-limit tools */
+#undef	OPENBSD_USING_EXTERNAL_FINDLIMIT	/* use external find-limit tools */
+#endif
+
+#define	OPENBSD_USING_INTERNAL_FINDLIMIT
+
+
+#if defined(OPENBSD) && defined(OPENBSD_USING_INTERNAL_FINDLIMIT)
+
+/* GC_init_openbsd_elf **************************************************
+
+ This would be the simple way, except it does not work
+
+ ************************************************************************/
+
+extern ptr_t GC_stackbottom;
+
+ptr_t GC_data_start;
+
+void GC_init_openbsd_elf()
+{
+	int dummy = 0;
+    extern ptr_t GC_find_limit();
+
+	GC_data_start = GC_find_limit( (ptr_t) &end, FALSE);
+	GC_stackbottom = GC_find_limit( (ptr_t) &dummy, TRUE);
+
+#ifdef DEBUG_THREADS
+	GC_printf1("openbsd GC_data_start: %p\n", GC_data_start );
+	GC_printf1("openbsd GC_data_end:   %p\n", (void*) &end );
+	GC_printf1("openbsd GC_stackbottom: %p\n", GC_stackbottom );
+#endif
+
+}
+#endif
+
+
+
 # ifdef OS2
 
 # include <stddef.h>
@@ -533,6 +573,11 @@ static SIGSET_T dummy;
 
 void GC_disable_signals()
 {
+
+#if !defined(NO_DEBUGGING)
+	GC_printf0("GC_disable_signals: enter\n");
+#endif
+
     if (!mask_initialized) {
     	SIG_FILL(new_mask);
 
@@ -556,17 +601,36 @@ void GC_disable_signals()
 #   ifdef CHECK_SIGNALS
 	if (GC_sig_disabled != 0) ABORT("Nested disables");
 	GC_sig_disabled++;
+#	else
+#	warning not checking signal disenabling/enabling
 #   endif
     SIGSETMASK(old_mask,new_mask);
+
+#if !defined(NO_DEBUGGING)
+	GC_printf0("GC_disable_signals: leave\n");
+#endif
+
 }
 
 void GC_enable_signals()
 {
+
+#if !defined(NO_DEBUGGING)
+	GC_printf0("GC_enable_signals: enter\n");
+#endif
+
 #   ifdef CHECK_SIGNALS
 	if (GC_sig_disabled != 1) ABORT("Unmatched enable");
 	GC_sig_disabled--;
+#	else
+#	warning not checking signal disabling/enabling
 #   endif
     SIGSETMASK(dummy,old_mask);
+
+#if !defined(NO_DEBUGGING)
+	GC_printf0("GC_enable_signals: leave\n");
+#endif
+
 }
 
 #  endif  /* !PCR */
@@ -682,6 +746,15 @@ ptr_t GC_get_stack_base()
 #   undef GC_AMIGA_SB
 # endif /* AMIGA */
 
+# if defined(OPENBSD) && defined(OPENBSD_USING_EXTERNAL_FINDLIMIT)
+/* these macros are not needed beyond this point */
+/* OpenBSD would be normally considered to be "unix like" */
+/* The "find limit" tools have some issues */
+# undef UNIX_LIKE
+# undef NEED_FIND_LIMIT
+# include "openbsd.c"
+# endif
+
 # if defined(NEED_FIND_LIMIT) || defined(UNIX_LIKE)
 
 #   ifdef __STDC__
@@ -691,10 +764,10 @@ ptr_t GC_get_stack_base()
 #   endif
 
 #   if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \
-    || defined(HURD) || defined(NETBSD)
+    || defined(HURD) || defined(NETBSD)	|| defined(OPENBSD)
 	static struct sigaction old_segv_act;
 #	if defined(IRIX5) || defined(HPUX) \
-	|| defined(HURD) || defined(NETBSD)
+	|| defined(HURD) || defined(NETBSD) || defined(OPENBSD)
 	    static struct sigaction old_bus_act;
 #	endif
 #   else
@@ -709,7 +782,7 @@ ptr_t GC_get_stack_base()
 #   endif
     {
 #	if defined(SUNOS5SIGS) || defined(IRIX5)  \
-        || defined(OSF1) || defined(HURD) || defined(NETBSD)
+        || defined(OSF1) || defined(HURD) || defined(NETBSD) || defined(OPENBSD)
 	  struct sigaction	act;
 
 	  act.sa_handler	= h;
@@ -717,7 +790,13 @@ ptr_t GC_get_stack_base()
 	       /* NetBSD bugs.						*/
             act.sa_flags          = SA_RESTART | SA_NODEFER;
 #         else
-            act.sa_flags          = SA_RESTART;
+            act.sa_flags = 
+#if defined(OPENBSD)
+				SA_ONSTACK | SA_NODEFER
+#else
+					SA_RESTART
+#endif
+			;
 #	  endif
 
 	  (void) sigemptyset(&act.sa_mask);
@@ -767,10 +846,10 @@ ptr_t GC_get_stack_base()
     void GC_reset_fault_handler()
     {
 #       if defined(SUNOS5SIGS) || defined(IRIX5) \
-	   || defined(OSF1) || defined(HURD) || defined(NETBSD)
+	   || defined(OSF1) || defined(HURD) || defined(NETBSD) || defined(OPENBSD)
 	  (void) sigaction(SIGSEGV, &old_segv_act, 0);
 #	  if defined(IRIX5) \
-	     || defined(HPUX) || defined(HURD) || defined(NETBSD)
+	     || defined(HPUX) || defined(HURD) || defined(NETBSD) || defined(OPENBSD)
 	      (void) sigaction(SIGBUS, &old_bus_act, 0);
 #	  endif
 #       else
@@ -801,11 +880,11 @@ ptr_t GC_get_stack_base()
 			      & ~(MIN_PAGE_SIZE-1));
 	    for (;;) {
  	        if (up) {
-		    result += MIN_PAGE_SIZE;
+		   	 result += MIN_PAGE_SIZE;
  	        } else {
-		    result -= MIN_PAGE_SIZE;
+		     result -= MIN_PAGE_SIZE;
  	        }
-		GC_noop1((word)(*result));
+			GC_noop1((word)(*result));
 	    }
 	}
 	GC_reset_fault_handler();
@@ -3118,7 +3197,7 @@ void GC_dirty_init()
 	    	      		(GC_words_allocd + GC_words_allocd_before_gc));
 #	endif       
     }
-    sprintf(buf, "/proc/%d", getpid());
+    snprintf(buf, sizeof(buf), "/proc/%d", getpid());
     fd = open(buf, O_RDONLY);
     if (fd < 0) {
     	ABORT("/proc open failed");
@@ -4150,7 +4229,7 @@ struct callinfo info[NFRAMES];
 #	  else
 	    char buf[40];
 	    char *name = buf;
-     	    sprintf(buf, "##PC##= 0x%lx", info[i].ci_pc);
+     	    snprintf(buf, sizeof(buf), "##PC##= 0x%lx", info[i].ci_pc);
 #	  endif
 #	  if defined(LINUX) && !defined(SMALL_CONFIG)
 	    /* Try for a line number. */
@@ -4184,7 +4263,7 @@ struct callinfo info[NFRAMES];
 		/* Then we use popen to start addr2line -e <exe> <addr>	*/
 		/* There are faster ways to do this, but hopefully this	*/
 		/* isn't time critical.					*/
-		sprintf(cmd_buf, "/usr/bin/addr2line -f -e %s 0x%lx", exe_name,
+		snprintf(cmd_buf, sizeof(cmd_buff), "/usr/bin/addr2line -f -e %s 0x%lx", exe_name,
 				 (unsigned long)info[i].ci_pc);
 		old_preload = getenv ("LD_PRELOAD");
 	        if (0 != old_preload) {
@@ -4192,7 +4271,7 @@ struct callinfo info[NFRAMES];
 		    will_fail = TRUE;
 		    goto out;
 		  }
-		  strcpy (preload_buf, old_preload);
+		  strlcpy (preload_buf, old_preload, PRELOAD_SZ);
 		  unsetenv ("LD_PRELOAD");
 	        }
 		pipe = popen(cmd_buf, "r");
@@ -4227,7 +4306,7 @@ struct callinfo info[NFRAMES];
 		}
 		if (result_len < RESULT_SZ - 25) {
 		  /* Add in hex address	*/
-		    sprintf(result_buf + result_len, " [0x%lx]",
+		    snprintf(result_buf + result_len, RESULT_SZ - result_len, " [1x%lx]",
 			  (unsigned long)info[i].ci_pc);
 		}
 		name = result_buf;
