]> git.saurik.com Git - apple/dyld.git/blobdiff - src/dyldNew.cpp
dyld-851.27.tar.gz
[apple/dyld.git] / src / dyldNew.cpp
index fb393fa0b45c15c8dfc3b1edbf6e3899f9a05e73..2bdafba21da777798b99a917f906e6d5e87d7811 100644 (file)
@@ -31,7 +31,7 @@
 
 extern "C" void* __dso_handle;
 
-#include "dyld.h"
+#include "dyld2.h"
 #include "dyldLibSystemInterface.h"
 
 //
@@ -51,7 +51,10 @@ struct dyld_static_pool {
        dyld_static_pool*       previousPool;
        uint8_t*                        current;
        uint8_t*                        end;
-       uint8_t                         pool[1]; 
+
+    // libunwind, and probably others, need the pool to be 16-byte aligned as malloc guarantees that
+    __attribute__((__aligned__(16)))
+    uint8_t                            pool[1];
 };
 
 // allocate initial pool independently of pool header to take less space on disk
@@ -68,9 +71,12 @@ void* malloc(size_t size)
                return p;
        }
        else {
+        // keep allocations 16-byte aligned
+        size = ((size + 15) & -16);
+
                if ( size > DYLD_POOL_CHUNK_SIZE ) {
-                       dyld::log("dyld malloc overflow: size=%zu\n", size);
-                       exit(1);
+                       dyld::log("dyld malloc overflow: size=%lu\n", size);
+                       dyld::halt("dyld malloc overflow\n");
                }
                size = (size+sizeof(void*)-1) & (-sizeof(void*)); // pointer align
                uint8_t* result = currentPool->current;
@@ -79,8 +85,7 @@ void* malloc(size_t size)
                        vm_address_t addr = 0;
                        kern_return_t r = vm_allocate(mach_task_self(), &addr, DYLD_POOL_CHUNK_SIZE, VM_FLAGS_ANYWHERE);
                        if ( r != KERN_SUCCESS ) {
-                               dyld::log("out of address space for dyld memory pool\n");
-                               exit(1);
+                               dyld::halt("out of address space for dyld memory pool\n");
                        }
                        dyld_static_pool* newPool = (dyld_static_pool*)addr;
                        newPool->previousPool = NULL;
@@ -90,7 +95,7 @@ void* malloc(size_t size)
                        currentPool = newPool;
                        if ( (currentPool->current + size) > currentPool->end ) {
                                dyld::log("dyld memory pool exhausted: size=%lu\n", size);
-                               exit(1);
+                               dyld::halt("dyld memory pool exhausted\n");
                        }
                        result = currentPool->current;
                        currentPool->current += size;