]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/_dyld_is_memory_immutable-lock.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / _dyld_is_memory_immutable-lock.dtest / main.c
1
2
3 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/lock.bundle
4 // BUILD: $CC main.c -o $BUILD_DIR/immutable-lock.exe -DRUN_DIR="$RUN_DIR"
5
6 // RUN: ./immutable-lock.exe
7
8 #include <stdio.h>
9 #include <dlfcn.h>
10 #include <stdlib.h>
11 #include <pthread.h>
12 #include <mach-o/dyld_priv.h>
13
14 #include "test_support.h"
15
16 static void* work(void* mh)
17 {
18 _dyld_is_memory_immutable(mh, 16);
19
20 return NULL;
21 }
22
23 static void notify(const struct mach_header* mh, intptr_t vmaddr_slide)
24 {
25 if ( mh->flags & 0x80000000 )
26 return;
27
28 // for each image notified that is not in the dyld cache, spin up a thread which calls _dyld_is_memory_immutable()
29 pthread_t workerThread;
30 if ( pthread_create(&workerThread, NULL, &work, (void*)mh) != 0 ) {
31 FAIL("pthread_create");
32 }
33 void* dummy;
34 pthread_join(workerThread, &dummy);
35 }
36
37
38
39 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
40 _dyld_register_func_for_add_image(&notify);
41
42 void* h = dlopen(RUN_DIR "/lock.bundle", 0);
43 if ( h == NULL ) {
44 FAIL("lock.bundle not loaded, dlopen(lock.bundle) failed with error: %s", dlerror());
45 }
46
47 PASS("Success");
48 }
49