Fixed bug #528 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sat, 29 Dec 2007 03:50:29 +0000
branchSDL-1.2
changeset 4108 3feb94233f90
parent 4107 4e3b250c950e
child 4109 cd2ab40f1219
Fixed bug #528
OpenBSD (and possibly others) do not have executable memory by default,
so use mprotect() to allow execution of dynamic assembly block.
src/video/SDL_stretch.c
--- a/src/video/SDL_stretch.c	Sat Dec 29 02:34:53 2007 +0000
+++ b/src/video/SDL_stretch.c	Sat Dec 29 03:50:29 2007 +0000
@@ -42,6 +42,15 @@
 
 #ifdef USE_ASM_STRETCH
 
+/* OpenBSD has non-executable memory by default, so use mprotect() */
+#ifdef __OpenBSD__
+#define USE_MPROTECT
+#endif
+#ifdef USE_MPROTECT
+#include <sys/types.h>
+#include <sys/mman.h>
+#endif
+
 #if defined(_M_IX86) || defined(i386)
 #define PREFIX16	0x66
 #define STORE_BYTE	0xAA
@@ -91,6 +100,9 @@
 		SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp);
 		return(-1);
 	}
+#ifdef USE_MPROTECT
+	mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_WRITE|PROT_EXEC);
+#endif
 	pos = 0x10000;
 	inc = (src_w << 16) / dst_w;
 	eip = copy_row;