parent
26093d5791
commit
7fdbbfdf67
@ -99,6 +99,10 @@ if(UNIX AND NOT APPLE)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
check_support(HAS_MACH_VM has_mach_vm.cpp "" "" "")
|
||||||
|
endif()
|
||||||
|
|
||||||
# =============================================== Autoconfig unwinding ===============================================
|
# =============================================== Autoconfig unwinding ===============================================
|
||||||
# Unwind back-ends
|
# Unwind back-ends
|
||||||
if(
|
if(
|
||||||
@ -340,6 +344,10 @@ if(HAS_DLADDR1)
|
|||||||
target_compile_definitions(${target_name} PUBLIC CPPTRACE_HAS_DLADDR1)
|
target_compile_definitions(${target_name} PUBLIC CPPTRACE_HAS_DLADDR1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(HAS_MACH_VM)
|
||||||
|
target_compile_definitions(${target_name} PUBLIC HAS_MACH_VM)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Symbols
|
# Symbols
|
||||||
if(CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE)
|
if(CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE)
|
||||||
if(NOT HAS_BACKTRACE)
|
if(NOT HAS_BACKTRACE)
|
||||||
|
|||||||
23
cmake/has_mach_vm.cpp
Normal file
23
cmake/has_mach_vm.cpp
Normal 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
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -20,7 +20,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if IS_APPLE
|
#if IS_APPLE
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
|
#ifdef HAS_MACH_VM
|
||||||
#include <mach/mach_vm.h>
|
#include <mach/mach_vm.h>
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -112,13 +114,24 @@ namespace cpptrace {
|
|||||||
#if IS_APPLE
|
#if IS_APPLE
|
||||||
int get_page_protections(void* page) {
|
int get_page_protections(void* page) {
|
||||||
// https://stackoverflow.com/a/12627784/15675011
|
// https://stackoverflow.com/a/12627784/15675011
|
||||||
|
#ifdef HAS_MACH_VM
|
||||||
mach_vm_size_t vmsize;
|
mach_vm_size_t vmsize;
|
||||||
mach_vm_address_t address = (mach_vm_address_t)page;
|
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;
|
vm_region_basic_info_data_t info;
|
||||||
mach_msg_type_number_t info_count =
|
mach_msg_type_number_t info_count =
|
||||||
sizeof(size_t) == 8 ? VM_REGION_BASIC_INFO_COUNT_64 : VM_REGION_BASIC_INFO_COUNT;
|
sizeof(size_t) == 8 ? VM_REGION_BASIC_INFO_COUNT_64 : VM_REGION_BASIC_INFO_COUNT;
|
||||||
memory_object_name_t object;
|
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(),
|
mach_task_self(),
|
||||||
&address,
|
&address,
|
||||||
&vmsize,
|
&vmsize,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user