linux_exec_hint_x86_64.c (752B)
1 /* x86_64 Linux runtime-alias hint: place the runtime alias in the low 2 GiB 2 * (MAP_32BIT) so that direct call/jmp displacements from text (typically 3 * loaded around 0x400000 under PIE) reach without large-code-model thunks. 4 * The write alias has no PC-relative usage and can live anywhere. */ 5 6 #include <stddef.h> 7 #include <stdint.h> 8 #include <sys/mman.h> 9 10 #include "env_posix.h" 11 12 int env_execmem_runtime_extra_flags(void) { return MAP_32BIT; } 13 14 void* env_execmem_low_runtime_hint(size_t size) { 15 static uintptr_t g = 0x40000000u; 16 uintptr_t p = g; 17 uintptr_t step = (uintptr_t)((size + 0xffffu) & ~(size_t)0xffffu); 18 if (step < 0x10000u) step = 0x10000u; 19 g = p + step + 0x10000u; 20 if (g > 0x78000000u) g = 0x40000000u; 21 return (void*)p; 22 }