Implement MemChunk::registerAllocFreeCallbacks().

This function allows a driver implementation to register its own handler for
allocating/freeing MemChunk objects. MemChunk is primarily used by the ELF
loader for various code/data segments.

Change-Id: If497f07a538c714933fcaa1b0c04ed5a6febeeba
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index 3357969..4aad52a 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -20,6 +20,7 @@
 #include "rsdAllocation.h"
 #include "rsdBcc.h"
 #ifndef RS_COMPATIBILITY_LIB
+    #include "MemChunk.h"
     #include "rsdGL.h"
     #include "rsdPath.h"
     #include "rsdProgramStore.h"
@@ -189,7 +190,7 @@
     }
     rsc->mHal.drv = dc;
 
-    dc->mCpuRef = RsdCpuReference::create((Context *)c, version_major, version_minor,
+    dc->mCpuRef = RsdCpuReference::create(rsc, version_major, version_minor,
                                           &rsdLookupRuntimeStub, &LookupScript);
     if (!dc->mCpuRef) {
         ALOGE("RsdCpuReference::create for driver hal failed.");
@@ -202,6 +203,16 @@
     if (false) {
         dc->mCpuRef->setSetupCompilerCallback(NULL);
     }
+
+    // Set a callback for switching MemChunk's allocator here.
+    // Note that the allocation function must return page-aligned memory, so
+    // that it can be mprotected properly (i.e. code should be written and
+    // later switched to read+execute only).
+    if (false) {
+        MemChunk::registerAllocFreeCallbacks(
+                rsc->mHal.funcs.allocRuntimeMem,
+                rsc->mHal.funcs.freeRuntimeMem);
+    }
 #endif
 
     return true;