From dc241dc1bf6a237a69cec008c1cb98082160524c Mon Sep 17 00:00:00 2001 From: theraven Date: Wed, 19 Mar 2014 07:26:52 +0000 Subject: [PATCH] Make sure that we flush the instruction cache when creating a new IMP at run time. --- block_to_imp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/block_to_imp.c b/block_to_imp.c index c5c31a0..9e0e639 100644 --- a/block_to_imp.c +++ b/block_to_imp.c @@ -17,6 +17,13 @@ #include "lock.h" #include "visibility.h" +#if __has_builtin(__builtin___clear_cache) +# define clear_cache __builtin___clear_cache +#else +void __clear_cache(void* start, void* end); +# define clear_cache __clear_cache +#endif + /* QNX needs a special header for asprintf() */ #ifdef __QNXNTO__ @@ -122,7 +129,9 @@ IMP imp_implementationWithBlock(void *block) out[1] = Block_copy(b); memcpy(&out[2], start, trampolineSize); out = buf.x; - return (IMP)&out[2]; + char *newIMP = (char*)&out[2]; + clear_cache(newIMP, newIMP+trampolineSize); + return (IMP)newIMP; } static void* isBlockIMP(void *anIMP)