[AD] Improvements for OpenBSD

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hello, attached is a patch that makes the following improvements:

* Call mprotect() on generated stretcher code before running it.
  OpenBSD protects memory pages returned from malloc() from being
  executed by default, so this is required for stretch_blit() to not
  segfault, on i386.
* Add an OSTYPE_OPENBSD define and detect it.
* Fix a warning in src/unix/uesd.c.

regards,
Graue
diff -ru allegro-4.2.0/configure allegro-4.2.0-modified/configure
--- allegro-4.2.0/configure	Mon Feb  6 16:12:40 2006
+++ allegro-4.2.0-modified/configure	Mon Feb  6 16:21:22 2006
@@ -11225,7 +11225,8 @@
 
 
 
-for ac_func in mmap memcmp mkstemp stricmp strlwr strupr vprintf
+for ac_func in mmap mprotect memcmp mkstemp stricmp strlwr strupr vprintf
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5
diff -ru allegro-4.2.0/configure.in allegro-4.2.0-modified/configure.in
--- allegro-4.2.0/configure.in	Mon Feb  6 16:12:40 2006
+++ allegro-4.2.0-modified/configure.in	Mon Feb  6 16:20:50 2006
@@ -713,7 +713,7 @@
 AC_STRUCT_TM
 AC_TYPE_SIGNAL
 
-AC_CHECK_FUNCS(mmap memcmp mkstemp stricmp strlwr strupr vprintf)
+AC_CHECK_FUNCS(mmap mprotect memcmp mkstemp stricmp strlwr strupr vprintf)
 
 dnl Tweak header files for library build
 CFLAGS="$CFLAGS -DALLEGRO_LIB_BUILD"
diff -ru allegro-4.2.0/include/allegro/platform/alunixac.hin allegro-4.2.0-modified/include/allegro/platform/alunixac.hin
--- allegro-4.2.0/include/allegro/platform/alunixac.hin	Mon Feb  6 16:12:40 2006
+++ allegro-4.2.0-modified/include/allegro/platform/alunixac.hin	Mon Feb  6 16:38:31 2006
@@ -169,6 +169,9 @@
 /* Define to 1 if you have the `mmap' function. */
 #undef HAVE_MMAP
 
+/* Define to 1 if you have the `mprotect' function. */
+#undef HAVE_MPROTECT
+
 /* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
 #undef HAVE_NDIR_H
 
diff -ru allegro-4.2.0/include/allegro/system.h allegro-4.2.0-modified/include/allegro/system.h
--- allegro-4.2.0/include/allegro/system.h	Mon Feb  6 16:12:40 2006
+++ allegro-4.2.0-modified/include/allegro/system.h	Mon Feb  6 16:15:49 2006
@@ -53,6 +53,7 @@
 #define OSTYPE_SUNOS       AL_ID('S','U','N',' ')
 #define OSTYPE_FREEBSD     AL_ID('F','B','S','D')
 #define OSTYPE_NETBSD      AL_ID('N','B','S','D')
+#define OSTYPE_OPENBSD     AL_ID('O','B','S','D')
 #define OSTYPE_IRIX        AL_ID('I','R','I','X')
 #define OSTYPE_DARWIN      AL_ID('D','A','R','W')
 #define OSTYPE_QNX         AL_ID('Q','N','X',' ')
diff -ru allegro-4.2.0/src/i386/istretch.c allegro-4.2.0-modified/src/i386/istretch.c
--- allegro-4.2.0/src/i386/istretch.c	Mon Feb  6 16:12:37 2006
+++ allegro-4.2.0-modified/src/i386/istretch.c	Mon Feb  6 16:49:06 2006
@@ -30,8 +30,11 @@
    #include "winalleg.h"   /* For VirtualProtect */
 #endif     /* ifdef ALLEGRO_WINDOWS */
 
+#ifdef HAVE_MPROTECT
+#include <sys/types.h>
+#include <sys/mman.h>
+#endif
 
 /* helper macro for generating stretchers in each color depth */
 #define DECLARE_STRETCHER(sz, mask, scale)                                   \
 {                                                                            \
@@ -432,10 +435,13 @@
 
    COMPILER_RET();
 
  #ifdef ALLEGRO_WINDOWS
    /* Play nice with Windows executable memory protection */
    VirtualProtect(_scratch_mem, _scratch_mem_size, PAGE_EXECUTE_READWRITE, &old_protect);
- #endif     /* ifdef ALLEGRO_WINDOWS */
+ #elif defined(HAVE_MPROTECT)
+   mprotect(_scratch_mem, _scratch_mem_size, PROT_EXEC|PROT_READ|PROT_WRITE);
+ #endif
 
    /* call the stretcher */
    _do_stretch(source, dest, _scratch_mem, sx>>16, sy, syd, 
diff -ru allegro-4.2.0/src/unix/uesd.c allegro-4.2.0-modified/src/unix/uesd.c
--- allegro-4.2.0/src/unix/uesd.c	Mon Feb  6 16:12:37 2006
+++ allegro-4.2.0-modified/src/unix/uesd.c	Mon Feb  6 16:42:44 2006
@@ -27,6 +27,7 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
+#include <string.h> /* FD_ZERO() needs this */
 #include <unistd.h>
 #include <esd.h>
 
diff -ru allegro-4.2.0/src/unix/usystem.c allegro-4.2.0-modified/src/unix/usystem.c
--- allegro-4.2.0/src/unix/usystem.c	Mon Feb  6 16:12:37 2006
+++ allegro-4.2.0-modified/src/unix/usystem.c	Mon Feb  6 16:16:24 2006
@@ -196,6 +196,9 @@
       else if (!strcmp(utsn.sysname, "NetBSD")) {
 	 os_type = OSTYPE_NETBSD;
       }
+      else if (!strcmp(utsn.sysname, "OpenBSD")) {
+	 os_type = OSTYPE_OPENBSD;
+      }
       else if ((!strcmp(utsn.sysname, "IRIX"))
 	       || (!strcmp(utsn.sysname, "IRIX64"))) {
 	 os_type = OSTYPE_IRIX;
diff -ru allegro-4.2.0/tools/grabber.c allegro-4.2.0-modified/tools/grabber.c
--- allegro-4.2.0/tools/grabber.c	Mon Feb  6 16:12:40 2006
+++ allegro-4.2.0-modified/tools/grabber.c	Mon Feb  6 16:17:14 2006
@@ -3121,6 +3121,7 @@
       case OSTYPE_SUNOS:      s = "SunOS/Solaris";              break;
       case OSTYPE_FREEBSD:    s = "FreeBSD";                    break;
       case OSTYPE_NETBSD:     s = "NetBSD";                     break;
+      case OSTYPE_OPENBSD:    s = "OpenBSD";                    break;
       case OSTYPE_IRIX:       s = "IRIX";                       break;
       case OSTYPE_DARWIN:     s = "Darwin";                     break;
       case OSTYPE_QNX:        s = "QNX";                        break;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/