Ticket #8562: 0001-Use-new-flushExec-implementation-on-all-operating-sy.patch

File 0001-Use-new-flushExec-implementation-on-all-operating-sy.patch, 3.4 KB (added by heatsink, 17 months ago)

Patch applying the linux fix to other OSes

  • rts/sm/Storage.c

    From b869455a665c201e98cd0192b0be142be856eb35 Mon Sep 17 00:00:00 2001
    From: Christopher Rodrigues <[email protected]>
    Date: Fri, 29 Nov 2013 23:05:50 -0600
    Subject: [PATCH] Use new flushExec implementation on all operating systems
     (#8562)
    
    An earlier patch fixes a bug in flushExec on linux only.  This
    patch uses the fixed code on all operating systems.
    ---
     rts/sm/Storage.c | 56 +++++++++++++++++++-------------------------------------
     1 file changed, 19 insertions(+), 37 deletions(-)
    
    diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c
    index b5f3202..6313f82 100644
    a b calcNeeded (rtsBool force_major, memcount *blocks_needed) 
    11341134         should be modified to use allocateExec instead of VirtualAlloc. 
    11351135   ------------------------------------------------------------------------- */ 
    11361136 
    1137 #if defined(linux_HOST_OS) 
    1138  
    1139 // On Linux we need to use libffi for allocating executable memory, 
    1140 // because it knows how to work around the restrictions put in place 
    1141 // by SELinux. 
    1142  
    1143 AdjustorWritable allocateExec (W_ bytes, AdjustorExecutable *exec_ret) 
    1144 { 
    1145     void **ret, **exec; 
    1146     ACQUIRE_SM_LOCK; 
    1147     ret = ffi_closure_alloc (sizeof(void *) + (size_t)bytes, (void**)&exec); 
    1148     RELEASE_SM_LOCK; 
    1149     if (ret == NULL) return ret; 
    1150     *ret = ret; // save the address of the writable mapping, for freeExec(). 
    1151     *exec_ret = exec + 1; 
    1152     return (ret + 1); 
    1153 } 
    1154  
    11551137#if defined(arm_HOST_ARCH) && defined(ios_HOST_OS) 
    11561138void sys_icache_invalidate(void *start, size_t len); 
    11571139#endif 
    void flushExec (W_ len, AdjustorExecutable exec_addr) 
    11771159#endif 
    11781160} 
    11791161 
     1162#if defined(linux_HOST_OS) 
     1163 
     1164// On Linux we need to use libffi for allocating executable memory, 
     1165// because it knows how to work around the restrictions put in place 
     1166// by SELinux. 
     1167 
     1168AdjustorWritable allocateExec (W_ bytes, AdjustorExecutable *exec_ret) 
     1169{ 
     1170    void **ret, **exec; 
     1171    ACQUIRE_SM_LOCK; 
     1172    ret = ffi_closure_alloc (sizeof(void *) + (size_t)bytes, (void**)&exec); 
     1173    RELEASE_SM_LOCK; 
     1174    if (ret == NULL) return ret; 
     1175    *ret = ret; // save the address of the writable mapping, for freeExec(). 
     1176    *exec_ret = exec + 1; 
     1177    return (ret + 1); 
     1178} 
     1179 
    11801180// freeExec gets passed the executable address, not the writable address. 
    11811181void freeExec (AdjustorExecutable addr) 
    11821182{ 
    AdjustorWritable execToWritable(AdjustorExecutable exec) 
    12231223    return writ; 
    12241224} 
    12251225 
    1226 void flushExec (W_ len, AdjustorExecutable exec_addr) 
    1227 { 
    1228   /* On ARM and other platforms, we need to flush the cache after 
    1229      writing code into memory, so the processor reliably sees it. */ 
    1230   unsigned char* begin = (unsigned char*)exec_addr; 
    1231   unsigned char* end   = begin + len; 
    1232   __builtin___clear_cache(begin, end); 
    1233 } 
    1234  
    12351226void freeExec(AdjustorExecutable exec) 
    12361227{ 
    12371228    AdjustorWritable writ; 
    AdjustorWritable allocateExec (W_ bytes, AdjustorExecutable *exec_ret) 
    12851276    return ret; 
    12861277} 
    12871278 
    1288 void flushExec (W_ len, AdjustorExecutable exec_addr) 
    1289 { 
    1290   /* On ARM and other platforms, we need to flush the cache after 
    1291      writing code into memory, so the processor reliably sees it. */ 
    1292   unsigned char* begin = (unsigned char*)exec_addr; 
    1293   unsigned char* end   = begin + len; 
    1294   __builtin___clear_cache(begin, end); 
    1295 } 
    1296  
    12971279void freeExec (void *addr) 
    12981280{ 
    12991281    StgPtr p = (StgPtr)addr - 1; 
    void freeExec (void *addr) 
    13281310    RELEASE_SM_LOCK 
    13291311} 
    13301312 
    1331 #endif /* mingw32_HOST_OS */ 
     1313#endif /* switch(HOST_OS) */ 
    13321314 
    13331315#ifdef DEBUG 
    13341316