60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
+
+
+
+
+
|
#if defined(__m68k__)
#if defined(AMIGA) /* Amiga running AmigaOS, not Linux */
#ifndef CODE_EXECUTABLE /* configure guesses wrong?? */
#define CODE_EXECUTABLE
#endif
#endif
#endif
/* As of Windows XP SP 2, malloc'd memory is not executable */
#ifdef _WIN32
#undef CODE_EXECUTABLE
#endif
#ifndef CODE_EXECUTABLE
/* How do we make the trampoline's code executable? */
#if defined(HAVE_MACH_VM) || defined(__convex__) || defined(HAVE_WORKING_MPROTECT) || defined(HAVE_SYS_M88KBCS_H)
/* mprotect() [or equivalent] the malloc'ed area. */
#define EXECUTABLE_VIA_MPROTECT
#else
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
+
+
+
+
|
#define EXECUTABLE_VIA_MMAP_DEVZERO
#endif
#else
#ifdef HAVE_SHM
/* Use an shmat'ed page. */
#define EXECUTABLE_VIA_SHM
#else
#ifdef _WIN32
/* Use VirtualAlloc */
#else
??
#endif
#endif
#endif
#endif
#endif
#include <stdio.h> /* declares fprintf() */
|
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
+
+
+
+
+
|
#ifdef EXECUTABLE_VIA_SHM
int shmid = shmget(IPC_PRIVATE, pagesize, 0700|IPC_CREAT);
if (shmid<0)
{ page = (char*)(-1); }
else
{ page = shmat(shmid, 0, 0); shmctl(shmid, IPC_RMID, 0); }
#endif
#ifdef _WIN32
page = VirtualAlloc(NULL, pagesize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (page == 0)
{ page = (char*)(-1); }
#endif
if (page == (char*)(-1))
{ fprintf(stderr,"trampoline: Out of virtual memory!\n"); abort(); }
/* Fill it with free trampolines. */
{ char** last = &freelist;
char* page_end = page + pagesize;
while (page+TRAMP_TOTAL_LENGTH <= page_end)
{ *last = page; last = (char**)page; page += TRAMP_TOTAL_LENGTH; }
|