Re: [AD] PATCH: updated mprotect patch for allegro-4.2.1 which also work on Linux

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




Evert Glebbeek wrote:
On Sunday 12 March 2006 10:25, Hans de Goede wrote:
C99 and Allegro define uintptr_t for casting pointers to int types.
Would
probably be better if you used that instead.
Makes no difference this always hold: sizeof(long) == sizeof(void *)

It may make no difference now, but there is nothing in the C standard that says that this should be true. Best to use the proper C99 type for this; it's there, afterall. Could you make a clean patch that doesn't contain the other OpenBSD fixes? That will make it a bit easier to commit.


As requested, see attachment.

Regards,

Hans
diff -ur allegro-4.2.0.orig/src/i386/istretch.c allegro-4.2.0/src/i386/istretch.c
--- allegro-4.2.0.orig/src/i386/istretch.c	2006-03-12 11:27:32.000000000 +0100
+++ allegro-4.2.0/src/i386/istretch.c	2006-03-11 23:31:44.000000000 +0100
@@ -33,6 +33,7 @@
 #ifdef HAVE_MPROTECT
    #include <sys/types.h>
    #include <sys/mman.h>
+   #include <sys/user.h>
 #endif
 
 
@@ -440,7 +441,12 @@
    /* Play nice with Windows executable memory protection */
    VirtualProtect(_scratch_mem, _scratch_mem_size, PAGE_EXECUTE_READWRITE, &old_protect);
  #elif defined(HAVE_MPROTECT)
-   mprotect(_scratch_mem, _scratch_mem_size, PROT_EXEC|PROT_READ|PROT_WRITE);
+   {
+      char *p = (char *)((uintptr_t)_scratch_mem & ~(PAGE_SIZE-1ul));
+      if (mprotect(p, _scratch_mem_size + ((char *)_scratch_mem - p),
+            PROT_EXEC|PROT_READ|PROT_WRITE))
+         perror("allegro-error: mprotect failed during stretched blit!");
+   }
  #endif
 
    /* call the stretcher */


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