]> git.saurik.com Git - apple/dyld.git/blobdiff - unit-tests/test-cases/interpose-shared-cache/mymalloc.c
dyld-851.27.tar.gz
[apple/dyld.git] / unit-tests / test-cases / interpose-shared-cache / mymalloc.c
index 9afe7f15bd865d2a29c99d170bf6ddf83dd22edb..bca0938823d2b1e8b85e66a79cd04f7ea35e9092 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2005-2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2011 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
  */
 
 #include <stdlib.h>
  */
 
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 #include <string.h>
+#include <stdbool.h>
 #include <mach-o/dyld-interposing.h>
 #include <mach-o/dyld-interposing.h>
+#include <malloc/malloc.h>
 
 
-// return blocks that have preceeding 16-bytes filled with "hello"
+static void* seenAllocations[128];
+static int seenAllocationIndex = 0;
+
+// record each malloc result in a ring buffer
 void* my_malloc(size_t size)
 {
 void* my_malloc(size_t size)
 {
-       char* x = malloc(size+16);
-       strcpy(x, "hello");
-       return &x[16];
+       char* x = malloc(size);
+       seenAllocations[seenAllocationIndex++] = x;
+       seenAllocationIndex = (seenAllocationIndex & 127); //wrap around
+       return x;
 }
 
 DYLD_INTERPOSE(my_malloc, malloc)
 }
 
 DYLD_INTERPOSE(my_malloc, malloc)
+
+bool allocationSeen(void* p)
+{
+       for(int i=0; i < 127; ++i) {
+               if ( seenAllocations[i] == p )
+                       return true;
+       }
+       return false;
+}
+
+
+