56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#if defined(__m68k__)
#if defined(AMIGA) /* Amiga running AmigaOS, not Linux */
#ifndef CODE_EXECUTABLE /* configure guesses wrong?? */
#define CODE_EXECUTABLE
#endif
#endif
#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
|
>
>
>
>
>
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#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
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#define EXECUTABLE_VIA_MMAP_DEVZERO
#endif
#else
#ifdef HAVE_SHM
/* Use an shmat'ed page. */
#define EXECUTABLE_VIA_SHM
#else
??
#endif
#endif
#endif
#endif
#include <stdio.h> /* declares fprintf() */
|
>
>
>
>
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#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() */
|
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
#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
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_LENGTH <= page_end)
{ *last = page; last = (char**)page; page += TRAMP_LENGTH; }
|
>
>
>
>
>
|
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
#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_LENGTH <= page_end)
{ *last = page; last = (char**)page; page += TRAMP_LENGTH; }
|