Move helper for syncing data/instruction cache to lj_mcode.c.

Sync caches after dynamic code generation for FFI callbacks.
This commit is contained in:
Mike Pall
2011-12-12 22:49:19 +01:00
parent 2d8f3d75df
commit 10474987bd
8 changed files with 69 additions and 56 deletions

View File

@@ -7,18 +7,65 @@
#define LUA_CORE
#include "lj_obj.h"
#if LJ_HASJIT
#include "lj_gc.h"
#include "lj_jit.h"
#include "lj_mcode.h"
#include "lj_trace.h"
#include "lj_dispatch.h"
#include "lj_vm.h"
#endif
/* -- OS-specific functions ----------------------------------------------- */
#if LJ_HASJIT || LJ_HASFFI
/* Define this if you want to run LuaJIT with Valgrind. */
#ifdef LUAJIT_USE_VALGRIND
#include <valgrind/valgrind.h>
#endif
#if !LJ_TARGET_X86ORX64 && LJ_TARGET_OSX
void sys_icache_invalidate(void *start, size_t len);
#endif
#if LJ_TARGET_LINUX && LJ_TARGET_PPC
#include <dlfcn.h>
static void (*mcode_sync_ppc)(void *start, void *end);
static void mcode_sync_dummy(void *start, void *end)
{
UNUSED(start); UNUSED(end);
}
#endif
/* Synchronize data/instruction cache. */
void lj_mcode_sync(void *start, void *end)
{
#ifdef LUAJIT_USE_VALGRIND
VALGRIND_DISCARD_TRANSLATIONS(start, (char *)end-(char *)start);
#endif
#if LJ_TARGET_X86ORX64
UNUSED(start); UNUSED(end);
#elif LJ_TARGET_OSX
sys_icache_invalidate(start, (char *)end-(char *)start);
#elif LJ_TARGET_LINUX && LJ_TARGET_PPC
if (!mcode_sync_ppc) {
void *vdso = dlopen("linux-vdso32.so.1", RTLD_LAZY);
if (!vdso || !(mcode_sync_ppc = dlsym(vdso, "__kernel_sync_dicache")))
mcode_sync_ppc = mcode_sync_dummy;
}
mcode_sync_ppc(start, end);
#elif defined(__GNUC__) && !LJ_TARGET_PPC
__clear_cache(start, end);
#else
#error "Missing builtin to flush instruction cache"
#endif
}
#endif
#if LJ_HASJIT
#if LJ_TARGET_WINDOWS
#define WIN32_LEAN_AND_MEAN