]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/lazy-symbol-missing.dtest/runner.cpp
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / lazy-symbol-missing.dtest / runner.cpp
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <dlfcn.h>
5 #include <unistd.h>
6 #include <signal.h>
7 #include <errno.h>
8 #include <mach/mach.h>
9 #include <mach/machine.h>
10 #include <err.h>
11 #include <System/sys/reason.h>
12 #include <System/sys/proc_info.h>
13 #include <System/kern/kern_cdata.h>
14 #include <libproc.h>
15 #include <mach-o/dyld_priv.h>
16
17 #if __arm64e__
18 // arm64e uses chained binds which does not support lazy binding
19 #define SUPPORTS_LAZY_BINDING 0
20 #else
21 #define SUPPORTS_LAZY_BINDING 1
22 #endif
23
24 #include "test_support.h"
25
26 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
27 #if SUPPORTS_LAZY_BINDING
28 _process process;
29 process.set_executable_path(RUN_DIR "/lazy-symbol-missing-called.exe");
30 const char* env[] = { "TEST_OUTPUT=None", NULL};
31 process.set_env(env);
32 process.set_exit_handler(^(pid_t pid) {
33 LOG("Child exited pid=%d", pid);
34
35 struct proc_exitreasoninfo info;
36 bzero(&info, sizeof(info));
37 uint8_t packReasonData[OS_REASON_BUFFER_MAX_SIZE];
38 bzero(packReasonData, OS_REASON_BUFFER_MAX_SIZE);
39 info.eri_reason_buf_size = OS_REASON_BUFFER_MAX_SIZE;
40 info.eri_kcd_buf = (user_addr_t)packReasonData;
41 LOG("info=%p", &info);
42 int procResult = proc_pidinfo(pid, PROC_PIDEXITREASONINFO, 1, &info, PROC_PIDEXITREASONINFO_SIZE);
43 if ( procResult != sizeof(struct proc_exitreasoninfo) ) {
44 FAIL("bad return size from proc_pidinfo(), %d expected %lu", procResult, PROC_PIDEXITREASONINFO_SIZE);
45 }
46 if ( info.eri_namespace != OS_REASON_DYLD ) {
47 FAIL("eri_namespace (%d) != OS_REASON_DYLD", info.eri_namespace);
48 }
49 PASS("Success");
50 });
51 (void)process.launch();
52 #endif
53 PASS("Success");
54 }
55