Fix compilation on ios (#167)

This aims to address #163
This commit is contained in:
Jeremy Rifkin 2024-09-04 17:22:32 -05:00 committed by GitHub
parent 26093d5791
commit 7fdbbfdf67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 2 deletions

View File

@ -99,6 +99,10 @@ if(UNIX AND NOT APPLE)
endif()
endif()
if(APPLE)
check_support(HAS_MACH_VM has_mach_vm.cpp "" "" "")
endif()
# =============================================== Autoconfig unwinding ===============================================
# Unwind back-ends
if(
@ -340,6 +344,10 @@ if(HAS_DLADDR1)
target_compile_definitions(${target_name} PUBLIC CPPTRACE_HAS_DLADDR1)
endif()
if(HAS_MACH_VM)
target_compile_definitions(${target_name} PUBLIC HAS_MACH_VM)
endif()
# Symbols
if(CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE)
if(NOT HAS_BACKTRACE)

23
cmake/has_mach_vm.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <cstdint>
int main() {
mach_vm_size_t vmsize;
uintptr_t addr = reinterpret_cast<uintptr_t>(&vmsize);
uintptr_t page_addr = addr & ~(4096 - 1);
mach_vm_address_t address = (mach_vm_address_t)page_addr;
vm_region_basic_info_data_t info;
mach_msg_type_number_t info_count =
sizeof(size_t) == 8 ? VM_REGION_BASIC_INFO_COUNT_64 : VM_REGION_BASIC_INFO_COUNT;
memory_object_name_t object;
mach_vm_region(
mach_task_self(),
&address,
&vmsize,
VM_REGION_BASIC_INFO,
(vm_region_info_t)&info,
&info_count,
&object
);
}

View File

@ -20,7 +20,9 @@
#include <unistd.h>
#if IS_APPLE
#include <mach/mach.h>
#include <mach/mach_vm.h>
#ifdef HAS_MACH_VM
#include <mach/mach_vm.h>
#endif
#else
#include <fstream>
#include <iomanip>
@ -112,13 +114,24 @@ namespace cpptrace {
#if IS_APPLE
int get_page_protections(void* page) {
// https://stackoverflow.com/a/12627784/15675011
#ifdef HAS_MACH_VM
mach_vm_size_t vmsize;
mach_vm_address_t address = (mach_vm_address_t)page;
#else
vm_size_t vmsize;
vm_address_t address = (vm_address_t)page;
#endif
vm_region_basic_info_data_t info;
mach_msg_type_number_t info_count =
sizeof(size_t) == 8 ? VM_REGION_BASIC_INFO_COUNT_64 : VM_REGION_BASIC_INFO_COUNT;
memory_object_name_t object;
kern_return_t status = mach_vm_region(
kern_return_t status =
#ifdef HAS_MACH_VM
mach_vm_region
#else
vm_region_64
#endif
(
mach_task_self(),
&address,
&vmsize,