diff options
author | Mike Pall <mike> | 2011-12-12 22:49:19 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-12-12 23:10:46 +0100 |
commit | 10474987bd58a2183d848cc7ef40aa2d4e9125ba (patch) | |
tree | dce63a72e48b85750e06430cc838f6e7ba3d344b /src/lj_mcode.c | |
parent | 2d8f3d75dfae1839224cf0c726eef9cb3b77eaa3 (diff) | |
download | luajit-10474987bd58a2183d848cc7ef40aa2d4e9125ba.tar.gz luajit-10474987bd58a2183d848cc7ef40aa2d4e9125ba.tar.bz2 luajit-10474987bd58a2183d848cc7ef40aa2d4e9125ba.zip |
Move helper for syncing data/instruction cache to lj_mcode.c.
Sync caches after dynamic code generation for FFI callbacks.
Diffstat (limited to 'src/lj_mcode.c')
-rw-r--r-- | src/lj_mcode.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/lj_mcode.c b/src/lj_mcode.c index 279854f8..90ac34fc 100644 --- a/src/lj_mcode.c +++ b/src/lj_mcode.c | |||
@@ -7,18 +7,65 @@ | |||
7 | #define LUA_CORE | 7 | #define LUA_CORE |
8 | 8 | ||
9 | #include "lj_obj.h" | 9 | #include "lj_obj.h" |
10 | |||
11 | #if LJ_HASJIT | 10 | #if LJ_HASJIT |
12 | |||
13 | #include "lj_gc.h" | 11 | #include "lj_gc.h" |
14 | #include "lj_jit.h" | 12 | #include "lj_jit.h" |
15 | #include "lj_mcode.h" | 13 | #include "lj_mcode.h" |
16 | #include "lj_trace.h" | 14 | #include "lj_trace.h" |
17 | #include "lj_dispatch.h" | 15 | #include "lj_dispatch.h" |
18 | #include "lj_vm.h" | 16 | #include "lj_vm.h" |
17 | #endif | ||
19 | 18 | ||
20 | /* -- OS-specific functions ----------------------------------------------- */ | 19 | /* -- OS-specific functions ----------------------------------------------- */ |
21 | 20 | ||
21 | #if LJ_HASJIT || LJ_HASFFI | ||
22 | |||
23 | /* Define this if you want to run LuaJIT with Valgrind. */ | ||
24 | #ifdef LUAJIT_USE_VALGRIND | ||
25 | #include <valgrind/valgrind.h> | ||
26 | #endif | ||
27 | |||
28 | #if !LJ_TARGET_X86ORX64 && LJ_TARGET_OSX | ||
29 | void sys_icache_invalidate(void *start, size_t len); | ||
30 | #endif | ||
31 | |||
32 | #if LJ_TARGET_LINUX && LJ_TARGET_PPC | ||
33 | #include <dlfcn.h> | ||
34 | static void (*mcode_sync_ppc)(void *start, void *end); | ||
35 | static void mcode_sync_dummy(void *start, void *end) | ||
36 | { | ||
37 | UNUSED(start); UNUSED(end); | ||
38 | } | ||
39 | #endif | ||
40 | |||
41 | /* Synchronize data/instruction cache. */ | ||
42 | void lj_mcode_sync(void *start, void *end) | ||
43 | { | ||
44 | #ifdef LUAJIT_USE_VALGRIND | ||
45 | VALGRIND_DISCARD_TRANSLATIONS(start, (char *)end-(char *)start); | ||
46 | #endif | ||
47 | #if LJ_TARGET_X86ORX64 | ||
48 | UNUSED(start); UNUSED(end); | ||
49 | #elif LJ_TARGET_OSX | ||
50 | sys_icache_invalidate(start, (char *)end-(char *)start); | ||
51 | #elif LJ_TARGET_LINUX && LJ_TARGET_PPC | ||
52 | if (!mcode_sync_ppc) { | ||
53 | void *vdso = dlopen("linux-vdso32.so.1", RTLD_LAZY); | ||
54 | if (!vdso || !(mcode_sync_ppc = dlsym(vdso, "__kernel_sync_dicache"))) | ||
55 | mcode_sync_ppc = mcode_sync_dummy; | ||
56 | } | ||
57 | mcode_sync_ppc(start, end); | ||
58 | #elif defined(__GNUC__) && !LJ_TARGET_PPC | ||
59 | __clear_cache(start, end); | ||
60 | #else | ||
61 | #error "Missing builtin to flush instruction cache" | ||
62 | #endif | ||
63 | } | ||
64 | |||
65 | #endif | ||
66 | |||
67 | #if LJ_HASJIT | ||
68 | |||
22 | #if LJ_TARGET_WINDOWS | 69 | #if LJ_TARGET_WINDOWS |
23 | 70 | ||
24 | #define WIN32_LEAN_AND_MEAN | 71 | #define WIN32_LEAN_AND_MEAN |