]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/read-only-data.dtest/foo.c
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / read-only-data.dtest / foo.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdbool.h>
4 #include <stdlib.h>
5 #include <mach/mach.h>
6 #include <mach/vm_region.h>
7 #include <dlfcn.h>
8
9 const void* const funcs[] = { &malloc, &free, &strcmp, &printf };
10
11 bool isReadOnly(const void* addr)
12 {
13 mach_port_t objName;
14 vm_address_t testAddr = (vm_address_t)addr;
15 vm_size_t regionSize;
16 vm_region_basic_info_data_64_t info;
17 mach_msg_type_number_t len = VM_REGION_BASIC_INFO_COUNT_64;
18 kern_return_t err = vm_region_64(mach_task_self(), &testAddr, &regionSize, VM_REGION_BASIC_INFO_64, (vm_region_info_t)&info, &len, &objName);
19
20 if ( err == 0 ) {
21 if ( info.protection & VM_PROT_WRITE )
22 return false;
23 return true;
24 }
25 return false;
26 }
27
28
29
30 #if BUNDLE
31 bool testBundle()
32 {
33 return isReadOnly(&funcs[1]);
34 }
35 #else
36 bool testLib()
37 {
38 return isReadOnly(&funcs[1]);
39 }
40 #endif
41