@@ -300,7 +300,10 @@ _PyCode_Validate(struct _PyCodeConstructor *con)
300
300
return 0 ;
301
301
}
302
302
303
- py_trampoline compile_blech (void ) {
303
+ extern void * _Py_trampoline_func_start ;
304
+ extern void * _Py_trampoline_func_end ;
305
+
306
+ py_trampoline compile_trampoline (void ) {
304
307
char * memory = mmap (NULL , // address
305
308
4096 , // size
306
309
PROT_READ | PROT_WRITE | PROT_EXEC ,
@@ -312,57 +315,10 @@ py_trampoline compile_blech(void) {
312
315
exit (1 );
313
316
}
314
317
315
- int i = 0 ;
316
-
317
- memory [i ++ ] = 0x55 ;
318
- memory [i ++ ] = 0x48 ;
319
- memory [i ++ ] = 0x89 ;
320
- memory [i ++ ] = 0xe5 ;
321
- memory [i ++ ] = 0x48 ;
322
- memory [i ++ ] = 0x83 ;
323
- memory [i ++ ] = 0xec ;
324
- memory [i ++ ] = 0x20 ;
325
- memory [i ++ ] = 0x48 ;
326
- memory [i ++ ] = 0x89 ;
327
- memory [i ++ ] = 0x7d ;
328
- memory [i ++ ] = 0xf8 ;
329
- memory [i ++ ] = 0x48 ;
330
- memory [i ++ ] = 0x89 ;
331
- memory [i ++ ] = 0x75 ;
332
- memory [i ++ ] = 0xf0 ;
333
- memory [i ++ ] = 0x48 ;
334
- memory [i ++ ] = 0x89 ;
335
- memory [i ++ ] = 0x55 ;
336
- memory [i ++ ] = 0xe8 ;
337
- memory [i ++ ] = 0x89 ;
338
- memory [i ++ ] = 0x4d ;
339
- memory [i ++ ] = 0xe4 ;
340
- memory [i ++ ] = 0x8b ;
341
- memory [i ++ ] = 0x55 ;
342
- memory [i ++ ] = 0xe4 ;
343
- memory [i ++ ] = 0x48 ;
344
- memory [i ++ ] = 0x8b ;
345
- memory [i ++ ] = 0x4d ;
346
- memory [i ++ ] = 0xe8 ;
347
- memory [i ++ ] = 0x48 ;
348
- memory [i ++ ] = 0x8b ;
349
- memory [i ++ ] = 0x45 ;
350
- memory [i ++ ] = 0xf0 ;
351
- memory [i ++ ] = 0x4c ;
352
- memory [i ++ ] = 0x8b ;
353
- memory [i ++ ] = 0x45 ;
354
- memory [i ++ ] = 0xf8 ;
355
- memory [i ++ ] = 0x48 ;
356
- memory [i ++ ] = 0x89 ;
357
- memory [i ++ ] = 0xce ;
358
- memory [i ++ ] = 0x48 ;
359
- memory [i ++ ] = 0x89 ;
360
- memory [i ++ ] = 0xc7 ;
361
- memory [i ++ ] = 0x41 ;
362
- memory [i ++ ] = 0xff ;
363
- memory [i ++ ] = 0xd0 ;
364
- memory [i ++ ] = 0xc9 ;
365
- memory [i ++ ] = 0xc3 ;
318
+ void * start = & _Py_trampoline_func_start ;
319
+ void * end = & _Py_trampoline_func_end ;
320
+ size_t ss = end - start ;
321
+ memcpy (memory , start , ss * sizeof (char ));
366
322
367
323
return (py_trampoline ) memory ;
368
324
}
@@ -391,10 +347,6 @@ void perf_map_write_entry(FILE *method_file, const void* code_addr, unsigned int
391
347
392
348
typedef PyObject * (* py_evaluator )(PyThreadState * , _PyInterpreterFrame * , int throwflag );
393
349
394
- PyObject * the_trampoline (py_evaluator eval , PyThreadState * t , _PyInterpreterFrame * f , int p ) {
395
- return eval (t , f ,p );
396
- }
397
-
398
350
static void
399
351
init_code (PyCodeObject * co , struct _PyCodeConstructor * con )
400
352
{
@@ -410,7 +362,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
410
362
Py_INCREF (con -> qualname );
411
363
co -> co_qualname = con -> qualname ;
412
364
413
- py_trampoline f = compile_blech ();
365
+ py_trampoline f = compile_trampoline ();
414
366
FILE * pfile = perf_map_open (getpid ());
415
367
perf_map_write_entry (pfile , f , 4096 , PyUnicode_AsUTF8 (con -> qualname ));
416
368
perf_map_close (pfile );
0 commit comments