Loading...
src/dyldNew.cpp dyld-852 dyld-210.2.3
--- dyld/dyld-852/src/dyldNew.cpp
+++ dyld/dyld-210.2.3/src/dyldNew.cpp
@@ -27,11 +27,10 @@
 #include <stdint.h>
 #include <string.h>
 #include <mach/mach.h>
-#include <sys/mman.h>
 
 extern "C" void* __dso_handle;
 
-#include "dyld2.h"
+#include "dyld.h"
 #include "dyldLibSystemInterface.h"
 
 //
@@ -51,10 +50,7 @@
 	dyld_static_pool*	previousPool;
 	uint8_t*			current;
 	uint8_t*			end;
-
-    // libunwind, and probably others, need the pool to be 16-byte aligned as malloc guarantees that
-    __attribute__((__aligned__(16)))
-    uint8_t				pool[1];
+	uint8_t				pool[1]; 
 };
 
 // allocate initial pool independently of pool header to take less space on disk
@@ -65,19 +61,12 @@
 
 void* malloc(size_t size)
 {
-	if ( (dyld::gLibSystemHelpers != NULL) && dyld::gProcessInfo->libSystemInitialized ) {
+	if ( dyld::gLibSystemHelpers != NULL) {
 		void* p = dyld::gLibSystemHelpers->malloc(size);
 		//dyld::log("malloc(%lu) => %p from libSystem\n", size, p);
 		return p;
 	}
 	else {
-        // keep allocations 16-byte aligned
-        size = ((size + 15) & -16);
-
-		if ( size > DYLD_POOL_CHUNK_SIZE ) {
-			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;
 		currentPool->current += size;
@@ -85,7 +74,8 @@
 			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::halt("out of address space for dyld memory pool\n");
+				dyld::log("out of address space for dyld memory pool\n");
+				exit(1);
 			}
 			dyld_static_pool* newPool = (dyld_static_pool*)addr;
 			newPool->previousPool = NULL;
@@ -95,7 +85,7 @@
 			currentPool = newPool;
 			if ( (currentPool->current + size) > currentPool->end ) {
 				dyld::log("dyld memory pool exhausted: size=%lu\n", size);
-				dyld::halt("dyld memory pool exhausted\n");
+				exit(1);
 			}
 			result = currentPool->current;
 			currentPool->current += size;
@@ -111,8 +101,8 @@
 	// ignore any pointer within dyld (i.e. stuff from pool or static strings)
 	if ( (dyld::gLibSystemHelpers != NULL) && ((ptr < &__dso_handle) || (ptr >= &initialPoolContent[DYLD_POOL_CHUNK_SIZE])) ) {
 		// ignore stuff in any dynamically alloated dyld pools
-		for (dyld_static_pool* p = currentPool; p != NULL; p = p->previousPool) {
-			if ( (p->pool <= ptr) && (ptr < p->end) ) {
+		for (dyld_static_pool* p = initialPool.previousPool; p != NULL; p = p->previousPool) {
+			if ( (p->pool < ptr) && (ptr < p->end) ) {
 				// do nothing, pool entries can't be reclaimed
 				//dyld::log("free(%p) from dynamic pool\n", ptr);
 				return;
@@ -131,21 +121,13 @@
 
 void* calloc(size_t count, size_t size)
 {
-    // Check for overflow of integer multiplication
-    size_t total = count * size;
-    if ( total/count != size ) {
-        dyld::log("dyld calloc overflow: count=%zu, size=%zu\n", count, size);
-        dyld::halt("dyld calloc overflow");
-    }
 	if ( dyld::gLibSystemHelpers != NULL ) {
-		void* result = dyld::gLibSystemHelpers->malloc(total);
-        if ( result != NULL )
-		    bzero(result, total);
+		void* result = dyld::gLibSystemHelpers->malloc(size*count);
+		bzero(result, size*count);
 		return result;
 	}
 	else {
-        // this allocates out of static buffer which is already zero filled
-		return malloc(total);
+		return malloc(count*size);
 	}
 }
 
@@ -165,26 +147,3 @@
 int _malloc_lock = 0;
 
 
-// <rdar://problem/12857033> dyld calls this which uses libSystem.dylib's vm_allocate if available
-int vm_alloc(vm_address_t* addr, vm_size_t size, uint32_t flags)
-{
-	if ( (dyld::gLibSystemHelpers != NULL) && (dyld::gLibSystemHelpers->version >= 12) ) {
-		return dyld::gLibSystemHelpers->vm_alloc(mach_task_self(), addr, size, flags);
-	}
-	else {
-		return ::vm_allocate(mach_task_self(), addr, size, flags);
-	}
-}
-
-void* xmmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset)
-{
-	if ( (dyld::gLibSystemHelpers != NULL) && (dyld::gLibSystemHelpers->version >= 12) ) {
-		return dyld::gLibSystemHelpers->mmap(addr, len, prot, flags, fd, offset);
-	}
-	else {
-		return ::mmap(addr, len, prot, flags, fd, offset);
-	}
-}
-
-
-