|
8 | 8 | #define UNW_STEP_SUCCESS 1
|
9 | 9 | #define UNW_STEP_END 0
|
10 | 10 |
|
11 |
| -#ifdef __APPLE__ |
| 11 | +#if defined(TARGET_APPLE) |
12 | 12 | #include <mach-o/getsect.h>
|
13 | 13 | #endif
|
14 | 14 |
|
@@ -883,3 +883,34 @@ bool UnwindHelpers::GetUnwindProcInfo(PCODE pc, UnwindInfoSections &uwInfoSectio
|
883 | 883 | uc.getInfo(procInfo);
|
884 | 884 | return true;
|
885 | 885 | }
|
| 886 | + |
| 887 | +#if defined(TARGET_APPLE) |
| 888 | +// Apple considers _dyld_find_unwind_sections to be private API that cannot be used |
| 889 | +// by apps submitted to App Store and TestFlight, both for iOS-like and macOS platforms. |
| 890 | +// We reimplement it using public API surface. |
| 891 | +// |
| 892 | +// Ref: https://github.com/llvm/llvm-project/blob/c37145cab12168798a603e22af6b6bf6f606b705/libunwind/src/AddressSpace.hpp#L67-L93 |
| 893 | +bool _dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info) |
| 894 | +{ |
| 895 | + // Find mach-o image containing address. |
| 896 | + Dl_info dlinfo; |
| 897 | + if (!dladdr(addr, &dlinfo)) |
| 898 | + return false; |
| 899 | + |
| 900 | + const struct mach_header_64 *mh = (const struct mach_header_64 *)dlinfo.dli_fbase; |
| 901 | + |
| 902 | + // Initialize the return struct |
| 903 | + info->mh = (const struct mach_header *)mh; |
| 904 | + info->dwarf_section = getsectiondata(mh, "__TEXT", "__eh_frame", &info->dwarf_section_length); |
| 905 | + info->compact_unwind_section = getsectiondata(mh, "__TEXT", "__unwind_info", &info->compact_unwind_section_length); |
| 906 | + |
| 907 | + if (!info->dwarf_section) { |
| 908 | + info->dwarf_section_length = 0; |
| 909 | + } |
| 910 | + if (!info->compact_unwind_section) { |
| 911 | + info->compact_unwind_section_length = 0; |
| 912 | + } |
| 913 | + |
| 914 | + return true; |
| 915 | +} |
| 916 | +#endif |
0 commit comments