From d5bb01caa65f5b29fed07e3f5e81b2613f5859cb Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 12 Jul 2021 18:56:50 +0100 Subject: [PATCH] apple add mach_vm_map, mmap does not provide custom alignment so mach_vm_map is only way. --- libc-test/build.rs | 1 + libc-test/semver/apple.txt | 14 ++++++++++++++ src/unix/bsd/apple/mod.rs | 29 ++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 81fcc3d30888e..eeea3be42bbf3 100755 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -193,6 +193,7 @@ fn test_apple(target: &str) { "mach/mach_init.h", "mach/mach_time.h", "mach/mach_types.h", + "mach/mach_vm.h", "mach/thread_act.h", "mach/thread_policy.h", "malloc/malloc.h", diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index d54c4155a44af..e966d8ff485cc 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -729,6 +729,7 @@ MAXTHREADNAMESIZE MCL_CURRENT MCL_FUTURE MDMBUF +MEMORY_OBJECT_NULL MH_MAGIC MH_MAGIC_64 MINCORE_INCORE @@ -1414,6 +1415,10 @@ VM_MEMORY_TCMALLOC VM_MEMORY_UNSHARED_PMAP VM_MEMORY_WEBCORE_PURGEABLE_BUFFERS VM_METER +VM_PROT_EXECUTE +VM_PROT_NONE +VM_PROT_READ +VM_PROT_WRITE VM_SWAPUSAGE VSTATUS VT0 @@ -1700,6 +1705,10 @@ mach_port_t mach_thread_self mach_timebase_info mach_timebase_info_data_t +mach_vm_address_t +mach_vm_map +mach_vm_offset_t +mach_vm_size_t madvise malloc_default_zone malloc_printf @@ -1718,10 +1727,13 @@ malloc_zone_t malloc_zone_valloc max_align_t mcontext_t +memory_object_t +memory_object_offset_t memset_pattern4 memset_pattern8 memset_pattern16 memset_s +mem_entry_name_port_t mincore mkdirat mkstemps @@ -1902,6 +1914,8 @@ uselocale utimensat utmpx utmpxname +vm_inherit_t +vm_map_t vm_prot_t vm_size_t wait4 diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 5794c63d4325c..0da0391c9be0c 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -44,6 +44,15 @@ pub type processor_flavor_t = ::c_int; pub type thread_flavor_t = natural_t; pub type thread_inspect_t = mach_port_t; pub type policy_t = ::c_int; +pub type mach_vm_address_t = u64; +pub type mach_vm_offset_t = u64; +pub type mach_vm_size_t = u64; +pub type vm_map_t = ::mach_port_t; +pub type mem_entry_name_port_t = ::mach_port_t; +pub type memory_object_t = ::mach_port_t; +pub type memory_object_offset_t = ::c_ulonglong; +pub type vm_inherit_t = ::c_uint; +pub type vm_prot_t = ::c_int; pub type iconv_t = *mut ::c_void; @@ -88,7 +97,6 @@ pub type CCCryptorStatus = i32; pub type CCRNGStatus = ::CCCryptorStatus; deprecated_mach! { - pub type vm_prot_t = ::c_int; pub type vm_size_t = ::uintptr_t; pub type mach_timebase_info_data_t = mach_timebase_info; } @@ -3218,6 +3226,11 @@ pub const VM_LOADAVG: ::c_int = 2; pub const VM_MACHFACTOR: ::c_int = 4; pub const VM_SWAPUSAGE: ::c_int = 5; pub const VM_MAXID: ::c_int = 6; +pub const VM_PROT_NONE: ::vm_prot_t = 0x00; +pub const VM_PROT_READ: ::vm_prot_t = 0x01; +pub const VM_PROT_WRITE: ::vm_prot_t = 0x02; +pub const VM_PROT_EXECUTE: ::vm_prot_t = 0x04; +pub const MEMORY_OBJECT_NULL: ::memory_object_t = 0; pub const HW_MACHINE: ::c_int = 1; pub const HW_MODEL: ::c_int = 2; pub const HW_NCPU: ::c_int = 3; @@ -4289,6 +4302,20 @@ extern "C" { pub fn CCRandomGenerateBytes(bytes: *mut ::c_void, size: ::size_t) -> ::CCRNGStatus; pub fn _NSGetExecutablePath(buf: *mut ::c_char, bufsize: *mut u32) -> ::c_int; + + pub fn mach_vm_map( + target_task: ::vm_map_t, + address: *mut ::mach_vm_address_t, + size: ::mach_vm_size_t, + mask: ::mach_vm_offset_t, + flags: ::c_int, + object: ::mem_entry_name_port_t, + offset: ::memory_object_offset_t, + copy: ::boolean_t, + cur_protection: ::vm_prot_t, + max_protection: ::vm_prot_t, + inheritance: ::vm_inherit_t, + ) -> ::kern_return_t; } cfg_if! {