1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/* Trampoline construction */
/*
* Copyright 1995-1999, 2001-2006 Bruno Haible, <bruno@clisp.org>
*
* This is free software distributed under the GNU General Public Licence
* described in the file COPYING. Contact the author if you don't have this
* or can't live with it. There is ABSOLUTELY NO WARRANTY, explicit or implied,
* on this software.
*/
#include "config.h"
#include "trampoline_r.h"
#if defined(__hppa__)
#if 0
#define __hppaold__ /* Old trampoline, real machine code. */
#else
#define __hppanew__ /* New trampoline, just a closure. */
#endif
#endif
#if defined(__powerpc__) && !defined(__powerpc64__)
#if !defined(_AIX)
#define __powerpcsysv4__ /* SysV.4 ABI, real machine code. */
#else
#define __powerpcaix__ /* AIX ABI, just a closure. */
#endif
#endif
#if defined(__powerpc64__)
/* The only ABI on powerpc64 known so far is the AIX ABI. */
#define __powerpc64aix__ /* AIX ABI, just a closure. */
#endif
#if defined(__hppanew__)
/*
* A function pointer is a biased pointer to a data area whose first word
* contains the actual address of the function.
*/
extern void tramp_r (); /* trampoline prototype */
/* We don't need to take any special measures to make the code executable
* since the actual instructions are in the text segment.
*/
#ifndef CODE_EXECUTABLE
#define CODE_EXECUTABLE
#endif
#endif
#if defined(__powerpcaix__) || defined(__powerpc64aix__) || defined(__ia64__)
/*
* A function pointer is a pointer to a data area whose first word contains
* the actual address of the function.
*/
extern void (*tramp_r) (); /* trampoline prototype */
/* We don't need to take any special measures to make the code executable
* since the actual instructions are in the text segment.
|
|
|
>
>
>
|
|
<
<
<
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/* Trampoline construction */
/*
* Copyright 1995-1999, 2001-2004 Bruno Haible, <bruno@clisp.org>
*
* This is free software distributed under the GNU General Public Licence
* described in the file COPYING. Contact the author if you don't have this
* or can't live with it. There is ABSOLUTELY NO WARRANTY, explicit or implied,
* on this software.
*/
#include "config.h"
#include "trampoline_r.h"
#if defined(__hppa__)
#if 0
#define __hppaold__ /* Old trampoline, real machine code. */
#else
#define __hppanew__ /* New trampoline, just a closure. */
#endif
#endif
#if defined(__rs6000__)
#if defined(__NetBSD__)
#define __rs6000netbsd__
#else
#if !defined(_AIX)
#define __rs6000sysv4__ /* SysV.4 ABI, real machine code. */
#else
#define __rs6000aix__ /* AIX ABI, just a closure. */
#endif
#endif
#endif
#if defined(__hppanew__)
/*
* A function pointer is a biased pointer to a data area whose first word
* contains the actual address of the function.
*/
extern void tramp_r (); /* trampoline prototype */
/* We don't need to take any special measures to make the code executable
* since the actual instructions are in the text segment.
*/
#ifndef CODE_EXECUTABLE
#define CODE_EXECUTABLE
#endif
#endif
#if defined(__rs6000aix__) || defined(__ia64__)
/*
* A function pointer is a pointer to a data area whose first word contains
* the actual address of the function.
*/
extern void (*tramp_r) (); /* trampoline prototype */
/* We don't need to take any special measures to make the code executable
* since the actual instructions are in the text segment.
|
︙ | | | ︙ | |
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#include <unistd.h>
#endif
/* Declare getpagesize(). */
#ifdef HAVE_GETPAGESIZE
#ifdef __cplusplus
extern "C" RETGETPAGESIZETYPE getpagesize (void);
#else
extern RETGETPAGESIZETYPE getpagesize (void);
#endif
#else
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#else
/* Not Unix, e.g. mingw32 */
#define PAGESIZE 4096
|
>
>
|
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#include <unistd.h>
#endif
/* Declare getpagesize(). */
#ifdef HAVE_GETPAGESIZE
#ifdef __cplusplus
extern "C" RETGETPAGESIZETYPE getpagesize (void);
#elif defined(__STDC__)
extern RETGETPAGESIZETYPE getpagesize (void);
#else
extern RETGETPAGESIZETYPE getpagesize ();
#endif
#else
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#else
/* Not Unix, e.g. mingw32 */
#define PAGESIZE 4096
|
︙ | | | ︙ | |
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
#endif
/* Declare open(). */
#ifdef EXECUTABLE_VIA_MMAP_DEVZERO
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#endif
/* Declare shmget(), shmat(), shmctl(). */
#ifdef EXECUTABLE_VIA_SHM
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
|
>
>
>
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#endif
/* Declare open(). */
#ifdef EXECUTABLE_VIA_MMAP_DEVZERO
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef OPEN_NEEDS_SYS_FILE_H
#include <sys/file.h>
#endif
#endif
/* Declare shmget(), shmat(), shmctl(). */
#ifdef EXECUTABLE_VIA_SHM
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
|
︙ | | | ︙ | |
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
#endif
#endif
#endif
#ifdef __m88k__
#include <sys/syslocal.h>
#endif
/* Inline assembly function for instruction cache flush. */
#if defined(__sparc__) || defined(__sparc64__) || defined(__alpha__) || defined(__hppaold__) || defined(__powerpcsysv4__) || defined(__convex__)
#ifdef __GNUC__
extern inline
#if defined(__sparc__) || defined(__sparc64__)
#include "cache-sparc.c"
#endif
#ifdef __alpha__
#include "cache-alpha.c"
#endif
#ifdef __hppa__
#include "cache-hppa.c"
#endif
#if defined(__powerpc__) && !defined(__powerpc64__)
#include "cache-powerpc.c"
#endif
#ifdef __convex__
#include "cache-convex.c"
#endif
#else
#if defined(__sparc__) || defined(__sparc64__)
extern void __TR_clear_cache_4();
|
|
|
|
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
#endif
#endif
#endif
#ifdef __m88k__
#include <sys/syslocal.h>
#endif
/* Inline assembly function for instruction cache flush. */
#if defined(__sparc__) || defined(__sparc64__) || defined(__alpha__) || defined(__hppaold__) || defined(__rs6000sysv4__) || defined(__rs6000netbsd__) || defined(__convex__)
#ifdef __GNUC__
extern inline
#if defined(__sparc__) || defined(__sparc64__)
#include "cache-sparc.c"
#endif
#ifdef __alpha__
#include "cache-alpha.c"
#endif
#ifdef __hppa__
#include "cache-hppa.c"
#endif
#ifdef __rs6000__
#include "cache-rs6000.c"
#endif
#ifdef __convex__
#include "cache-convex.c"
#endif
#else
#if defined(__sparc__) || defined(__sparc64__)
extern void __TR_clear_cache_4();
|
︙ | | | ︙ | |
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
#define TRAMP_LENGTH 16
#define TRAMP_ALIGN 16 /* 4 for a i386, 16 for a i486 */
#endif
#ifdef __m68k__
#define TRAMP_LENGTH 14
#define TRAMP_ALIGN 16
#endif
#if defined(__mips__) || defined(__mipsn32__) && !defined(__mips64__)
#define TRAMP_LENGTH 24
#define TRAMP_ALIGN 4
#endif
#ifdef __mips64old__
#define TRAMP_LENGTH 56
#define TRAMP_ALIGN 4
#endif
|
|
>
>
>
>
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
#define TRAMP_LENGTH 16
#define TRAMP_ALIGN 16 /* 4 for a i386, 16 for a i486 */
#endif
#ifdef __m68k__
#define TRAMP_LENGTH 14
#define TRAMP_ALIGN 16
#endif
#if defined(__mips__) && !defined(__mipsn32__)
#define TRAMP_LENGTH 24
#define TRAMP_ALIGN 4
#endif
#ifdef __mipsn32__
#define TRAMP_LENGTH 24
#define TRAMP_ALIGN 4
#endif
#ifdef __mips64old__
#define TRAMP_LENGTH 56
#define TRAMP_ALIGN 4
#endif
|
︙ | | | ︙ | |
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
#endif
#ifdef __hppanew__
#define TRAMP_LENGTH 16
#define TRAMP_ALIGN 16
#define TRAMP_BIAS 2
#endif
#ifdef __arm__
#define TRAMP_LENGTH 16
#define TRAMP_ALIGN 4
#endif
#ifdef __powerpcsysv4__
#define TRAMP_LENGTH 24
#define TRAMP_ALIGN 4
#endif
#ifdef __powerpcaix__
#define TRAMP_LENGTH 20
#define TRAMP_ALIGN 4
#endif
#ifdef __powerpc64aix__
#define TRAMP_LENGTH 40
#define TRAMP_ALIGN 8
#endif
#ifdef __m88k__
#define TRAMP_LENGTH 20
#define TRAMP_ALIGN 8
#endif
#ifdef __convex__
#define TRAMP_LENGTH 14
#define TRAMP_ALIGN 4
|
|
|
>
>
>
>
|
<
<
<
<
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
#endif
#ifdef __hppanew__
#define TRAMP_LENGTH 16
#define TRAMP_ALIGN 16
#define TRAMP_BIAS 2
#endif
#ifdef __arm__
#define TRAMP_LENGTH 32
#define TRAMP_ALIGN 4
#endif
#ifdef __rs6000sysv4__
#define TRAMP_LENGTH 24
#define TRAMP_ALIGN 4
#endif
#ifdef __rs6000netbsd__
#define TRAMP_LENGTH 24
#define TRAMP_ALIGN 4
#endif
#ifdef __rs6000aix__
#define TRAMP_LENGTH 20
#define TRAMP_ALIGN 4
#endif
#ifdef __m88k__
#define TRAMP_LENGTH 20
#define TRAMP_ALIGN 8
#endif
#ifdef __convex__
#define TRAMP_LENGTH 14
#define TRAMP_ALIGN 4
|
︙ | | | ︙ | |
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
/* AIX doesn't support mprotect() in malloc'ed memory. Must get pages of
* memory with execute permission via mmap(). Then keep a free list of
* free trampolines.
*/
static char* freelist = NULL;
#endif
__TR_function alloc_trampoline_r (__TR_function address, void* data0, void* data1)
{
char* function;
char* data;
#if !defined(CODE_EXECUTABLE)
static long pagesize = 0;
#if defined(EXECUTABLE_VIA_MMAP_DEVZERO)
|
>
>
>
>
>
>
>
|
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
/* AIX doesn't support mprotect() in malloc'ed memory. Must get pages of
* memory with execute permission via mmap(). Then keep a free list of
* free trampolines.
*/
static char* freelist = NULL;
#endif
#if defined(__STDC__) || defined(__GNUC__) || defined(__cplusplus)
__TR_function alloc_trampoline_r (__TR_function address, void* data0, void* data1)
#else
__TR_function alloc_trampoline_r (address, data0, data1)
__TR_function address;
void* data0;
void* data1;
#endif
{
char* function;
char* data;
#if !defined(CODE_EXECUTABLE)
static long pagesize = 0;
#if defined(EXECUTABLE_VIA_MMAP_DEVZERO)
|
︙ | | | ︙ | |
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
/* 1. Allocate room */
#if !defined(CODE_EXECUTABLE) && !defined(EXECUTABLE_VIA_MPROTECT)
/* Note: This memory allocation is not multithread-safe. We might need
* to add special (platform dependent) code for locking.
* Fortunately, most modern systems where multithread-safety matters
* have EXECUTABLE_VIA_MPROTECT, and those which don't (AIX on powerpc and
* HP-UX on hppa) have CODE_EXECUTABLE. Thus no locking code is needed
* for the moment.
*/
if (freelist == NULL)
{ /* Get a new page. */
char* page;
#ifdef EXECUTABLE_VIA_MMAP_ANONYMOUS
|
|
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
/* 1. Allocate room */
#if !defined(CODE_EXECUTABLE) && !defined(EXECUTABLE_VIA_MPROTECT)
/* Note: This memory allocation is not multithread-safe. We might need
* to add special (platform dependent) code for locking.
* Fortunately, most modern systems where multithread-safety matters
* have EXECUTABLE_VIA_MPROTECT, and those which don't (AIX on rs6000 and
* HP-UX on hppa) have CODE_EXECUTABLE. Thus no locking code is needed
* for the moment.
*/
if (freelist == NULL)
{ /* Get a new page. */
char* page;
#ifdef EXECUTABLE_VIA_MMAP_ANONYMOUS
|
︙ | | | ︙ | |
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
*(unsigned short *) (function + 6) == 0xE951
#define tramp_address(function) \
*(long *) (function + 8) + (long) (function + 12)
#define tramp_data(function) \
*(long *) (function + 2)
#endif
#ifdef __m68k__
#ifdef __NetBSD__
/* function:
* movel #<data>,a1 22 7C <data>
* jmp <address> 4E F9 <address>
* nop 4E 71
*/
*(short *) (function + 0) = 0x227C;
*(long *) (function + 2) = (long) data;
*(short *) (function + 6) = 0x4EF9;
*(long *) (function + 8) = (long) address;
*(short *) (function +12) = 0x4E71;
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x227C && \
*(unsigned short *) (function + 6) == 0x4EF9 && \
*(unsigned short *) (function +12) == 0x4E71
#else
/* function:
* movel #<data>,a0 20 7C <data>
* jmp <address> 4E F9 <address>
* nop 4E 71
*/
*(short *) (function + 0) = 0x207C;
*(long *) (function + 2) = (long) data;
*(short *) (function + 6) = 0x4EF9;
*(long *) (function + 8) = (long) address;
*(short *) (function +12) = 0x4E71;
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x207C && \
*(unsigned short *) (function + 6) == 0x4EF9 && \
*(unsigned short *) (function +12) == 0x4E71
#endif
#define tramp_address(function) \
*(long *) (function + 8)
#define tramp_data(function) \
*(long *) (function + 2)
#endif
#if defined(__mips__) || defined(__mipsn32__) && !defined(__mips64__)
/* function:
* lw $2,16($25) 8F 22 00 10
* lw $25,20($25) 8F 39 00 14
* j $25 03 20 00 08
* nop 00 00 00 00
* .word <data> <data>
* .word <address> <address>
*/
*(unsigned int *) (function + 0) = 0x8F220010;
*(unsigned int *) (function + 4) = 0x8F390014;
*(unsigned int *) (function + 8) = 0x03200008;
*(unsigned int *) (function +12) = 0x00000000;
*(unsigned int *) (function +16) = (unsigned int) data;
*(unsigned int *) (function +20) = (unsigned int) address;
#define is_tramp(function) \
*(unsigned int *) (function + 0) == 0x8F220010 && \
*(unsigned int *) (function + 4) == 0x8F390014 && \
*(unsigned int *) (function + 8) == 0x03200008 && \
*(unsigned int *) (function +12) == 0x00000000
#define tramp_address(function) \
*(unsigned int *) (function +20)
#define tramp_data(function) \
*(unsigned int *) (function +16)
#endif
#ifdef __mips64old__
/* function:
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
*(unsigned short *) (function + 6) == 0xE951
#define tramp_address(function) \
*(long *) (function + 8) + (long) (function + 12)
#define tramp_data(function) \
*(long *) (function + 2)
#endif
#ifdef __m68k__
/* function:
* movel #<data>,a0 20 7C <data>
* jmp <address> 4E F9 <address>
* nop 4E 71
*/
*(short *) (function + 0) = 0x207C;
*(long *) (function + 2) = (long) data;
*(short *) (function + 6) = 0x4EF9;
*(long *) (function + 8) = (long) address;
*(short *) (function +12) = 0x4E71;
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x207C && \
*(unsigned short *) (function + 6) == 0x4EF9 && \
*(unsigned short *) (function +12) == 0x4E71
#define tramp_address(function) \
*(long *) (function + 8)
#define tramp_data(function) \
*(long *) (function + 2)
#endif
#if defined(__mips__) && !defined(__mipsn32__)
/* function:
* li $2,<data>&0xffff0000 3C 02 hi16(<data>)
* ori $2,$2,<data>&0xffff 34 42 lo16(<data>)
* li $25,<address>&0xffff0000 3C 19 hi16(<address>)
* ori $25,$25,<address>&0xffff 37 39 lo16(<address>)
* j $25 03 20 00 08
* nop 00 00 00 00
*/
/* What about big endian / little endian ?? */
*(short *) (function + 0) = 0x3C02;
*(short *) (function + 2) = (unsigned long) data >> 16;
*(short *) (function + 4) = 0x3442;
*(short *) (function + 6) = (unsigned long) data & 0xffff;
*(short *) (function + 8) = 0x3C19;
*(short *) (function +10) = (unsigned long) address >> 16;
*(short *) (function +12) = 0x3739;
*(short *) (function +14) = (unsigned long) address & 0xffff;
*(long *) (function +16) = 0x03200008;
*(long *) (function +20) = 0x00000000;
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x3C02 && \
*(unsigned short *) (function + 4) == 0x3442 && \
*(unsigned short *) (function + 8) == 0x3C19 && \
*(unsigned short *) (function +12) == 0x3739 && \
*(unsigned long *) (function +16) == 0x03200008 && \
*(unsigned long *) (function +20) == 0x00000000
#define hilo(hiword,loword) \
(((unsigned long) (hiword) << 16) | (unsigned long) (loword))
#define tramp_address(function) \
hilo(*(unsigned short *) (function +10), *(unsigned short *) (function +14))
#define tramp_data(function) \
hilo(*(unsigned short *) (function + 2), *(unsigned short *) (function + 6))
#endif
#ifdef __mipsn32__
/* function:
* lw $2,16($25) 8F 22 00 10
* lw $25,20($25) 8F 39 00 14
* j $25 03 20 00 08
* nop 00 00 00 00
* .word <data> <data>
* .word <address> <address>
*/
/* What about big endian / little endian ?? */
*(unsigned int *) (function + 0) = 0x8F220010;
*(unsigned int *) (function + 4) = 0x8F390014;
*(unsigned int *) (function + 8) = 0x03200008;
*(unsigned int *) (function +12) = 0x00000000;
*(unsigned int *) (function +16) = (unsigned int) data;
*(unsigned int *) (function +20) = (unsigned int) address;
#define is_tramp(function) \
*(int *) (function + 0) == 0x8F220010 && \
*(int *) (function + 4) == 0x8F390014 && \
*(int *) (function + 8) == 0x03200008 && \
*(int *) (function +12) == 0x00000000
#define tramp_address(function) \
*(unsigned int *) (function +20)
#define tramp_data(function) \
*(unsigned int *) (function +16)
#endif
#ifdef __mips64old__
/* function:
|
︙ | | | ︙ | |
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
* ld $2,16($25) DF 22 00 10
* ld $25,24($25) DF 39 00 18
* j $25 03 20 00 08
* nop 00 00 00 00
* .dword <data> <data>
* .dword <address> <address>
*/
*(unsigned int *) (function + 0) = 0xDF220010;
*(unsigned int *) (function + 4) = 0xDF390018;
*(unsigned int *) (function + 8) = 0x03200008;
*(unsigned int *) (function +12) = 0x00000000;
*(unsigned long *) (function +16) = (unsigned long) data;
*(unsigned long *) (function +24) = (unsigned long) address;
#define is_tramp(function) \
*(unsigned int *) (function + 0) == 0xDF220010 && \
*(unsigned int *) (function + 4) == 0xDF390018 && \
*(unsigned int *) (function + 8) == 0x03200008 && \
*(unsigned int *) (function +12) == 0x00000000
#define tramp_address(function) \
*(unsigned long *) (function +24)
#define tramp_data(function) \
*(unsigned long *) (function +16)
#endif
#if defined(__sparc__) && !defined(__sparc64__)
/* function:
|
>
|
<
|
<
|
<
|
<
|
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|
* ld $2,16($25) DF 22 00 10
* ld $25,24($25) DF 39 00 18
* j $25 03 20 00 08
* nop 00 00 00 00
* .dword <data> <data>
* .dword <address> <address>
*/
/* What about big endian / little endian ?? */
*(long *) (function + 0) = 0xDF220010DF390018L;
*(long *) (function + 8) = 0x0320000800000000L;
*(unsigned long *) (function +16) = (unsigned long) data;
*(unsigned long *) (function +24) = (unsigned long) address;
#define is_tramp(function) \
*(long *) (function + 0) == 0xDF220010DF390018L && \
*(long *) (function + 8) == 0x0320000800000000L
#define tramp_address(function) \
*(unsigned long *) (function +24)
#define tramp_data(function) \
*(unsigned long *) (function +16)
#endif
#if defined(__sparc__) && !defined(__sparc64__)
/* function:
|
︙ | | | ︙ | |
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
|
#define tramp_address(function) \
((long *) function)[3]
#define tramp_data(function) \
((long *) function)[2]
#endif
#ifdef __arm__
/* function:
* add r12,pc,#8 E28FC008
* ldr pc,[pc] E59FF000
* _data:
* .word <data>
* _function:
* .word <address>
*/
{
((long *) function)[0] = 0xE28FC008;
((long *) function)[1] = 0xE59FF000;
((long *) function)[2] = (long) data;
((long *) function)[3] = (long) address;
}
#define is_tramp(function) \
((long *) function)[0] == 0xE28FC008 && \
((long *) function)[1] == 0xE59FF000
#define tramp_address(function) \
((long *) function)[3]
#define tramp_data(function) \
((long *) function)[2]
#endif
#ifdef __powerpcsysv4__
#ifdef __NetBSD__
/* function:
* {liu|lis} 13,hi16(<data>) 3D A0 hi16(<data>)
* {oril|ori} 13,13,lo16(<data>) 61 AD lo16(<data>)
* {liu|lis} 0,hi16(<address>) 3C 00 hi16(<address>)
* {oril|ori} 0,0,lo16(<address>) 60 00 lo16(<address>)
* mtctr 0 7C 09 03 A6
* bctr 4E 80 04 20
*/
*(short *) (function + 0) = 0x3DA0;
*(short *) (function + 2) = (unsigned long) data >> 16;
*(short *) (function + 4) = 0x61AD;
*(short *) (function + 6) = (unsigned long) data & 0xffff;
*(short *) (function + 8) = 0x3C00;
*(short *) (function +10) = (unsigned long) address >> 16;
*(short *) (function +12) = 0x6000;
*(short *) (function +14) = (unsigned long) address & 0xffff;
*(long *) (function +16) = 0x7C0903A6;
*(long *) (function +20) = 0x4E800420;
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x3DA0 && \
*(unsigned short *) (function + 4) == 0x61AD && \
*(unsigned short *) (function + 8) == 0x3C00 && \
*(unsigned short *) (function +12) == 0x6000 && \
*(unsigned long *) (function +16) == 0x7C0903A6 && \
*(unsigned long *) (function +20) == 0x4E800420
#else
/* function:
* {liu|lis} 11,hi16(<data>) 3D 60 hi16(<data>)
* {oril|ori} 11,11,lo16(<data>) 61 6B lo16(<data>)
* {liu|lis} 0,hi16(<address>) 3C 00 hi16(<address>)
* {oril|ori} 0,0,lo16(<address>) 60 00 lo16(<address>)
* mtctr 0 7C 09 03 A6
* bctr 4E 80 04 20
|
>
>
|
|
>
>
|
|
<
|
>
|
<
<
|
|
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
>
|
|
|
|
|
<
|
|
|
|
|
|
<
<
<
|
>
|
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
|
#define tramp_address(function) \
((long *) function)[3]
#define tramp_data(function) \
((long *) function)[2]
#endif
#ifdef __arm__
/* function:
* ldr ip,[pc,#_function-.-8] E59FC014
* ldr ip,[ip,#0] E59CC000 ??Is this correct??
* stmfd sp!,{ip} E92D1000
* ldr ip,[pc,#_data-.-8] E59FC004
* ldr ip,[ip,#0] E59CC000 ??Is this correct??
* ldmfd sp!,{pc}^ E8FD8000
* _data:
* .word <data> <data>
* _function:
* .word <address> <address>
*/
{ static long code [6] =
{ 0xE59FC014, 0xE59CC000, 0xE92D1000, 0xE59FC004,
0xE59CC000, 0xE8FD8000
};
int i;
for (i=0; i<6; i++) { ((long *) function)[i] = code[i]; }
((long *) function)[6] = (long) data;
((long *) function)[7] = (long) address;
}
#define is_tramp(function) \
((long *) function)[0] == 0xE59FC014 && \
((long *) function)[1] == 0xE59CC000 && \
((long *) function)[2] == 0xE92D1000 && \
((long *) function)[3] == 0xE59FC004 && \
((long *) function)[4] == 0xE59CC000 && \
((long *) function)[5] == 0xE8FD8000
#define tramp_address(function) \
((long *) function)[7]
#define tramp_data(function) \
((long *) function)[6]
#endif
#ifdef __rs6000sysv4__
/* function:
* {liu|lis} 11,hi16(<data>) 3D 60 hi16(<data>)
* {oril|ori} 11,11,lo16(<data>) 61 6B lo16(<data>)
* {liu|lis} 0,hi16(<address>) 3C 00 hi16(<address>)
* {oril|ori} 0,0,lo16(<address>) 60 00 lo16(<address>)
* mtctr 0 7C 09 03 A6
* bctr 4E 80 04 20
|
︙ | | | ︙ | |
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
|
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x3D60 && \
*(unsigned short *) (function + 4) == 0x616B && \
*(unsigned short *) (function + 8) == 0x3C00 && \
*(unsigned short *) (function +12) == 0x6000 && \
*(unsigned long *) (function +16) == 0x7C0903A6 && \
*(unsigned long *) (function +20) == 0x4E800420
#endif
#define hilo(hiword,loword) \
(((unsigned long) (hiword) << 16) | (unsigned long) (loword))
#define tramp_address(function) \
hilo(*(unsigned short *) (function +10), *(unsigned short *) (function +14))
#define tramp_data(function) \
hilo(*(unsigned short *) (function + 2), *(unsigned short *) (function + 6))
#endif
#ifdef __powerpcaix__
/* function:
* .long .tramp_r
* .long .mytoc
* .long 0
* .mytoc:
* .long <data>
* .long <address>
*/
*(long *) (function + 0) = ((long *) &tramp_r)[0];
*(long *) (function + 4) = (long) (function + 12);
*(long *) (function + 8) = 0;
*(long *) (function +12) = (long) data;
*(long *) (function +16) = (long) address;
#define is_tramp(function) \
((long *) function)[0] == ((long *) &tramp_r)[0]
#define tramp_address(function) \
((long *) function)[4]
#define tramp_data(function) \
((long *) function)[3]
#endif
#ifdef __powerpc64aix__
/* function:
* .quad .tramp_r
* .quad .mytoc
* .quad 0
* .mytoc:
* .quad <data>
* .quad <address>
*/
*(long *) (function + 0) = ((long *) &tramp_r)[0];
*(long *) (function + 8) = (long) (function + 24);
*(long *) (function +16) = 0;
*(long *) (function +24) = (long) data;
*(long *) (function +32) = (long) address;
#define is_tramp(function) \
((long *) function)[0] == ((long *) &tramp_r)[0]
#define tramp_address(function) \
((long *) function)[4]
#define tramp_data(function) \
((long *) function)[3]
#endif
#ifdef __m88k__
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
|
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x3D60 && \
*(unsigned short *) (function + 4) == 0x616B && \
*(unsigned short *) (function + 8) == 0x3C00 && \
*(unsigned short *) (function +12) == 0x6000 && \
*(unsigned long *) (function +16) == 0x7C0903A6 && \
*(unsigned long *) (function +20) == 0x4E800420
#define hilo(hiword,loword) \
(((unsigned long) (hiword) << 16) | (unsigned long) (loword))
#define tramp_address(function) \
hilo(*(unsigned short *) (function +10), *(unsigned short *) (function +14))
#define tramp_data(function) \
hilo(*(unsigned short *) (function + 2), *(unsigned short *) (function + 6))
#endif
#ifdef __rs6000netbsd__
/* function:
* {liu|lis} 13,hi16(<data>) 3D A0 hi16(<data>)
* {oril|ori} 13,13,lo16(<data>) 61 AD lo16(<data>)
* {liu|lis} 0,hi16(<address>) 3C 00 hi16(<address>)
* {oril|ori} 0,0,lo16(<address>) 60 00 lo16(<address>)
* mtctr 0 7C 09 03 A6
* bctr 4E 80 04 20
*/
*(short *) (function + 0) = 0x3DA0;
*(short *) (function + 2) = (unsigned long) data >> 16;
*(short *) (function + 4) = 0x61AD;
*(short *) (function + 6) = (unsigned long) data & 0xffff;
*(short *) (function + 8) = 0x3C00;
*(short *) (function +10) = (unsigned long) address >> 16;
*(short *) (function +12) = 0x6000;
*(short *) (function +14) = (unsigned long) address & 0xffff;
*(long *) (function +16) = 0x7C0903A6;
*(long *) (function +20) = 0x4E800420;
#define is_tramp(function) \
*(unsigned short *) (function + 0) == 0x3DA0 && \
*(unsigned short *) (function + 4) == 0x61AD && \
*(unsigned short *) (function + 8) == 0x3C00 && \
*(unsigned short *) (function +12) == 0x6000 && \
*(unsigned long *) (function +16) == 0x7C0903A6 && \
*(unsigned long *) (function +20) == 0x4E800420
#define hilo(hiword,loword) \
(((unsigned long) (hiword) << 16) | (unsigned long) (loword))
#define tramp_address(function) \
hilo(*(unsigned short *) (function +10), *(unsigned short *) (function +14))
#define tramp_data(function) \
hilo(*(unsigned short *) (function + 2), *(unsigned short *) (function + 6))
#endif
#ifdef __rs6000aix__
/* function:
* .long .tramp_r
* .long .mytoc
* .long 0
* .mytoc:
* .long <data>
* .long <address>
*/
*(long *) (function + 0) = ((long *) &tramp_r)[0];
*(long *) (function + 4) = (long) (function + 12);
*(long *) (function + 8) = 0;
*(long *) (function +12) = (long) data;
*(long *) (function +16) = (long) address;
#define is_tramp(function) \
((long *) function)[0] == ((long *) &tramp_r)[0]
#define tramp_address(function) \
((long *) function)[4]
#define tramp_data(function) \
((long *) function)[3]
#endif
#ifdef __m88k__
|
︙ | | | ︙ | |
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
|
#endif
/* 4. Flush instruction cache */
/* We need this because some CPUs have separate data cache and instruction
* cache. The freshly built trampoline is visible to the data cache, but not
* maybe not to the instruction cache. This is hairy.
*/
#if !(defined(__hppanew__) || defined(__powerpcaix__) || defined(__powerpc64aix__) || defined(__ia64__))
/* Only needed if we really set up machine instructions. */
#ifdef __i386__
#if defined(_WIN32)
while (!FlushInstructionCache(GetCurrentProcess(),function,TRAMP_LENGTH))
continue;
#endif
#endif
|
|
|
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
|
#endif
/* 4. Flush instruction cache */
/* We need this because some CPUs have separate data cache and instruction
* cache. The freshly built trampoline is visible to the data cache, but not
* maybe not to the instruction cache. This is hairy.
*/
#if !(defined(__hppanew__) || defined(__rs6000aix__) || defined(__ia64__))
/* Only needed if we really set up machine instructions. */
#ifdef __i386__
#if defined(_WIN32)
while (!FlushInstructionCache(GetCurrentProcess(),function,TRAMP_LENGTH))
continue;
#endif
#endif
|
︙ | | | ︙ | |
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
|
__TR_clear_cache();
#endif
#ifdef __hppa__
/* This assumes that the trampoline fits in at most two cache lines. */
__TR_clear_cache(function,function+TRAMP_LENGTH-1);
#endif
#ifdef __arm__
__TR_clear_cache(function,function+TRAMP_LENGTH);
#endif
#if defined(__powerpc__) && !defined(__powerpc64__)
__TR_clear_cache(function);
#endif
#ifdef __m88k__
sysmot(S88CACHEFLUSHPAGE, (unsigned long)function & -pagesize);
#endif
#ifdef __convex__
__TR_clear_cache();
#endif
#endif
/* 5. Return. */
return (__TR_function) (function + TRAMP_BIAS);
}
void free_trampoline_r (__TR_function function)
{
#if TRAMP_BIAS
function = (__TR_function)((char*)function - TRAMP_BIAS);
#endif
#if !defined(CODE_EXECUTABLE) && !defined(EXECUTABLE_VIA_MPROTECT)
*(char**)function = freelist; freelist = (char*)function;
/* It is probably not worth calling munmap() for entirely freed pages. */
#else
free(((char**)function)[-1]);
#endif
}
int is_trampoline_r (void* function)
{
#if defined(is_tramp) && defined(tramp_data)
#ifdef __hppanew__
void* tramp_r_address = &tramp_r;
if (!(((long)function & 3) == (TRAMP_BIAS & 3))) return 0;
#endif
return
((is_tramp(((char*)function - TRAMP_BIAS)))
&& ((tramp_data(((char*)function - TRAMP_BIAS))) == (long)((char*)function - TRAMP_BIAS + TRAMP_LENGTH))
? 1 : 0
);
#else
abort();
#endif
}
__TR_function trampoline_r_address (void* function)
{
#ifdef tramp_address
return (__TR_function)(tramp_address(((char*)function - TRAMP_BIAS)));
#else
abort();
#endif
}
void* trampoline_r_data0 (void* function)
{
#ifdef tramp_data
return ((void**)((char*)function-TRAMP_BIAS+TRAMP_LENGTH))[0];
#else
abort();
#endif
}
void* trampoline_r_data1 (void* function)
{
#ifdef tramp_data
return ((void**)((char*)function-TRAMP_BIAS+TRAMP_LENGTH))[1];
#else
abort();
#endif
}
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
|
__TR_clear_cache();
#endif
#ifdef __hppa__
/* This assumes that the trampoline fits in at most two cache lines. */
__TR_clear_cache(function,function+TRAMP_LENGTH-1);
#endif
#ifdef __arm__
/* This CPU does not have a separate instruction cache. (I think.) */
#endif
#ifdef __rs6000__
__TR_clear_cache(function);
#endif
#ifdef __m88k__
sysmot(S88CACHEFLUSHPAGE, (unsigned long)function & -pagesize);
#endif
#ifdef __convex__
__TR_clear_cache();
#endif
#endif
/* 5. Return. */
return (__TR_function) (function + TRAMP_BIAS);
}
#if defined(__STDC__) || defined(__GNUC__) || defined(__cplusplus)
void free_trampoline_r (__TR_function function)
#else
void free_trampoline_r (function)
__TR_function function;
#endif
{
#if TRAMP_BIAS
function = (__TR_function)((char*)function - TRAMP_BIAS);
#endif
#if !defined(CODE_EXECUTABLE) && !defined(EXECUTABLE_VIA_MPROTECT)
*(char**)function = freelist; freelist = (char*)function;
/* It is probably not worth calling munmap() for entirely freed pages. */
#else
free(((char**)function)[-1]);
#endif
}
#if defined(__STDC__) || defined(__GNUC__) || defined(__cplusplus)
int is_trampoline_r (void* function)
#else
int is_trampoline_r (function)
void* function;
#endif
{
#if defined(is_tramp) && defined(tramp_data)
#ifdef __hppanew__
void* tramp_r_address = &tramp_r;
if (!(((long)function & 3) == (TRAMP_BIAS & 3))) return 0;
#endif
return
((is_tramp(((char*)function - TRAMP_BIAS)))
&& ((tramp_data(((char*)function - TRAMP_BIAS))) == (long)((char*)function - TRAMP_BIAS + TRAMP_LENGTH))
? 1 : 0
);
#else
abort();
#endif
}
#if defined(__STDC__) || defined(__GNUC__) || defined(__cplusplus)
__TR_function trampoline_r_address (void* function)
#else
__TR_function trampoline_r_address (function)
void* function;
#endif
{
#ifdef tramp_address
return (__TR_function)(tramp_address(((char*)function - TRAMP_BIAS)));
#else
abort();
#endif
}
#if defined(__STDC__) || defined(__GNUC__) || defined(__cplusplus)
void* trampoline_r_data0 (void* function)
#else
void* trampoline_r_data0 (function)
void* function;
#endif
{
#ifdef tramp_data
return ((void**)((char*)function-TRAMP_BIAS+TRAMP_LENGTH))[0];
#else
abort();
#endif
}
#if defined(__STDC__) || defined(__GNUC__) || defined(__cplusplus)
void* trampoline_r_data1 (void* function)
#else
void* trampoline_r_data1 (function)
void* function;
#endif
{
#ifdef tramp_data
return ((void**)((char*)function-TRAMP_BIAS+TRAMP_LENGTH))[1];
#else
abort();
#endif
}
|