9 #include <mach/machine.h>
11 #include <System/sys/reason.h>
12 #include <System/sys/proc_info.h>
13 #include <System/kern/kern_cdata.h>
15 #include <mach-o/dyld_priv.h>
18 // arm64e uses chained binds which does not support lazy binding
19 #define SUPPORTS_LAZY_BINDING 0
21 #define SUPPORTS_LAZY_BINDING 1
24 #include "test_support.h"
26 static const char* getUserDescription(struct proc_exitreasoninfo
& info
) {
27 kcdata_iter_t iter
= kcdata_iter((void*)info
.eri_kcd_buf
, info
.eri_reason_buf_size
);
28 if ( !kcdata_iter_valid(iter
) )
30 if ( kcdata_iter_type(iter
) != KCDATA_BUFFER_BEGIN_OS_REASON
)
32 iter
= kcdata_iter_find_type(iter
, EXIT_REASON_USER_DESC
);
33 if ( !kcdata_iter_valid(iter
) ) {
36 return kcdata_iter_string(iter
, 0);
39 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
40 #if SUPPORTS_LAZY_BINDING
43 process
.set_executable_path(RUN_DIR
"/lazy-symbol-missing-called-weak-lib.exe");
45 process
.set_executable_path(RUN_DIR
"/lazy-symbol-missing-called.exe");
47 const char* env
[] = { "TEST_OUTPUT=None", NULL
};
49 process
.set_exit_handler(^(pid_t pid
) {
50 LOG("Child exited pid=%d", pid
);
52 struct proc_exitreasoninfo info
;
53 bzero(&info
, sizeof(info
));
54 uint8_t packReasonData
[OS_REASON_BUFFER_MAX_SIZE
];
55 bzero(packReasonData
, OS_REASON_BUFFER_MAX_SIZE
);
56 info
.eri_reason_buf_size
= OS_REASON_BUFFER_MAX_SIZE
;
57 info
.eri_kcd_buf
= (user_addr_t
)packReasonData
;
58 LOG("info=%p", &info
);
59 int procResult
= proc_pidinfo(pid
, PROC_PIDEXITREASONINFO
, 1, &info
, PROC_PIDEXITREASONINFO_SIZE
);
60 if ( procResult
!= sizeof(struct proc_exitreasoninfo
) ) {
61 FAIL("bad return size from proc_pidinfo(), %d expected %lu", procResult
, PROC_PIDEXITREASONINFO_SIZE
);
63 if ( info
.eri_namespace
!= OS_REASON_DYLD
) {
64 FAIL("eri_namespace (%d) != OS_REASON_DYLD", info
.eri_namespace
);
66 const char* userDesc
= getUserDescription(info
);
67 if ( userDesc
!= NULL
) {
68 LOG("user desc=%s", (const char*)userDesc
);
71 // Make sure we print a dylib name, not a dependency library # when referencing a symbol from a missing library
72 if ( userDesc
!= NULL
) {
73 if ( strstr(userDesc
, "libbar-missing.dylib") == NULL
) {
74 FAIL("Expected name of missing dylib");
80 (void)process
.launch();