aarch64: Flush code mapping in addition to data mapping (#471)
authorFlorian Weimer <fw@deneb.enyo.de>
Tue, 19 Feb 2019 11:55:11 +0000 (12:55 +0100)
committerAnthony Green <green@moxielogic.com>
Tue, 19 Feb 2019 11:55:11 +0000 (06:55 -0500)
This needs a new function, ffi_data_to_code_pointer, to translate
from data pointers to code pointers.

Fixes issue #470.

include/ffi_common.h
src/aarch64/ffi.c
src/closures.c

index ee9cdcb6b153f659c17c1c70719969231d1d24f7..76b9dd6fafe5766524f2a2eddf3236287a4e3e65 100644 (file)
@@ -99,6 +99,10 @@ ffi_status ffi_prep_cif_core(ffi_cif *cif,
                             ffi_type *rtype,
                             ffi_type **atypes);
 
+/* Translate a data pointer to a code pointer.  Needed for closures on
+   some targets.  */
+void *ffi_data_to_code_pointer (void *data) FFI_HIDDEN;
+
 /* Extended cif, used in callback from assembly routine */
 typedef struct
 {
index c48c549f9b8770c98847a832d218e75e282a8289..188acf25bdf2d4ecb5f18a6c7511ff96c4ecd66d 100644 (file)
@@ -773,6 +773,10 @@ ffi_prep_closure_loc (ffi_closure *closure,
   *(UINT64 *)(tramp + 16) = (uintptr_t)start;
 
   ffi_clear_cache(tramp, tramp + FFI_TRAMPOLINE_SIZE);
+
+  /* Also flush the cache for code mapping.  */
+  unsigned char *tramp_code = ffi_data_to_code_pointer (tramp);
+  ffi_clear_cache (tramp_code, tramp_code + FFI_TRAMPOLINE_SIZE);
 #endif
 
   closure->cif = cif;
index 15e6e0f0f4c36566825c957b470055e23a62df55..e9e058ea5fc3e6f8ed43ac22409f9993d651a95b 100644 (file)
@@ -921,6 +921,13 @@ ffi_closure_alloc (size_t size, void **code)
   return ptr;
 }
 
+void *
+ffi_data_to_code_pointer (void *data)
+{
+  msegmentptr seg = segment_holding (gm, data);
+  return add_segment_exec_offset (data, seg);
+}
+
 /* Release a chunk of memory allocated with ffi_closure_alloc.  If
    FFI_CLOSURE_FREE_CODE is nonzero, the given address can be the
    writable or the executable address given.  Otherwise, only the
@@ -960,6 +967,12 @@ ffi_closure_free (void *ptr)
   free (ptr);
 }
 
+void *
+ffi_data_to_code_pointer (void *data)
+{
+  return data;
+}
+
 # endif /* ! FFI_MMAP_EXEC_WRIT */
 #endif /* FFI_CLOSURES */