File: has_mach_vm.cpp

package info (click to toggle)
cpptrace 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,996 kB
  • sloc: cpp: 15,646; python: 962; ansic: 155; sh: 103; makefile: 86
file content (23 lines) | stat: -rw-r--r-- 667 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
    );
}