comparison loader/win32.c @ 21462:bd6a451d2588

mmap memory area for generated code to avoid crashes on machines which support noexec
author reimar
date Sun, 03 Dec 2006 20:26:00 +0000
parents 71235c49d6ac
children 97639699240b
comparison
equal deleted inserted replaced
21461:71235c49d6ac 21462:bd6a451d2588
67 #include <sys/time.h> 67 #include <sys/time.h>
68 #include <sys/timeb.h> 68 #include <sys/timeb.h>
69 #ifdef HAVE_KSTAT 69 #ifdef HAVE_KSTAT
70 #include <kstat.h> 70 #include <kstat.h>
71 #endif 71 #endif
72
73 #include <sys/mman.h>
74 #include "osdep/mmap_anon.h"
72 75
73 #if HAVE_VSSCANF 76 #if HAVE_VSSCANF
74 int vsscanf( const char *str, const char *format, va_list ap); 77 int vsscanf( const char *str, const char *format, va_list ap);
75 #else 78 #else
76 /* system has no vsscanf. try to provide one */ 79 /* system has no vsscanf. try to provide one */
5297 } 5300 }
5298 5301
5299 #define MAX_STUB_SIZE 0x60 5302 #define MAX_STUB_SIZE 0x60
5300 #define MAX_NUM_STUBS 200 5303 #define MAX_NUM_STUBS 200
5301 static int pos=0; 5304 static int pos=0;
5302 static char extcode[MAX_NUM_STUBS * MAX_STUB_SIZE]; 5305 static char *extcode = NULL;
5303 5306
5304 static void* add_stub(void) 5307 static void* add_stub(void)
5305 { 5308 {
5306 int i; 5309 int i;
5307 int found = 0; 5310 int found = 0;
5308 // generated code in runtime! 5311 // generated code in runtime!
5309 char* answ = extcode + pos * MAX_STUB_SIZE; 5312 char* answ;
5313 if (!extcode)
5314 extcode = mmap_anon(NULL, MAX_NUM_STUBS * MAX_STUB_SIZE,
5315 PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, 0);
5316 answ = extcode + pos * MAX_STUB_SIZE;
5310 if (pos >= MAX_NUM_STUBS) { 5317 if (pos >= MAX_NUM_STUBS) {
5311 printf("too many stubs, expect crash\n"); 5318 printf("too many stubs, expect crash\n");
5312 return NULL; 5319 return NULL;
5313 } 5320 }
5314 memcpy(answ, ext_stubs, MAX_STUB_SIZE); 5321 memcpy(answ, ext_stubs, MAX_STUB_SIZE);