diff options
-rw-r--r-- | orc/orcprogram-x86.c | 29 | ||||
-rw-r--r-- | orc/orcutils.h | 4 |
2 files changed, 33 insertions, 0 deletions
diff --git a/orc/orcprogram-x86.c b/orc/orcprogram-x86.c index 9e7242f..3aaf8d4 100644 --- a/orc/orcprogram-x86.c +++ b/orc/orcprogram-x86.c @@ -10,6 +10,10 @@ #include <orc/orcx86-private.h> #include <orc/orcinternal.h> +#if defined(_WIN32) +#include <windows.h> +#endif + #define ORC_X86_ALIGNED_DEST_CUTOFF 64 #define LABEL_REGION1_SKIP 1 #define LABEL_INNER_LOOP_START 2 @@ -1036,6 +1040,30 @@ orc_x86_compile (OrcCompiler *compiler) orc_x86_do_fixups (compiler); } +static void +orc_x86_flush_cache (OrcCode *code) +{ +#if defined(__APPLE__) + sys_dcache_flush(code->code, code->code_size); + sys_icache_invalidate(code->exec, code->code_size); +#elif defined (_WIN32) + HANDLE h_proc = GetCurrentProcess(); + + FlushInstructionCache(h_proc, code->code, code->code_size); + + if ((void *) code->exec != (void *) code->code) + FlushInstructionCache(h_proc, code->exec, code->code_size); +#elif __has_builtin(__builtin_clear_cache) + __builtin_clear_cache (code->code, code->code + code->code_size); + if ((void *) code->exec != (void *) code->code) + __builtin_clear_cache (code->exec, code->exec + code->code_size); +#else + __clear_cache (code->code, code->code + code->code_size); + if ((void *) code->exec != (void *) code->code) + __clear_cache (code->exec, code->exec + code->code_size); +#endif +} + void orc_x86_register_extension (OrcTarget *t, OrcX86Target *x86t) { @@ -1054,6 +1082,7 @@ orc_x86_register_extension (OrcTarget *t, OrcX86Target *x86t) t->load_constant = orc_x86_load_constant; t->get_flag_name = x86t->get_flag_name; t->load_constant_long = x86t->load_constant_long; + t->flush_cache = orc_x86_flush_cache; t->target_data = x86t; orc_target_register (t); } diff --git a/orc/orcutils.h b/orc/orcutils.h index f6c8a17..7f8df35 100644 --- a/orc/orcutils.h +++ b/orc/orcutils.h @@ -254,6 +254,10 @@ typedef unsigned int orc_bool; #endif #endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + ORC_BEGIN_DECLS #ifdef ORC_ENABLE_UNSTABLE_API |