Skip to content

Commit d5bb01c

Browse files
committed
apple add mach_vm_map, mmap does not provide custom alignment so
mach_vm_map is only way.
1 parent 13c8ceb commit d5bb01c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

libc-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ fn test_apple(target: &str) {
193193
"mach/mach_init.h",
194194
"mach/mach_time.h",
195195
"mach/mach_types.h",
196+
"mach/mach_vm.h",
196197
"mach/thread_act.h",
197198
"mach/thread_policy.h",
198199
"malloc/malloc.h",

libc-test/semver/apple.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ MAXTHREADNAMESIZE
729729
MCL_CURRENT
730730
MCL_FUTURE
731731
MDMBUF
732+
MEMORY_OBJECT_NULL
732733
MH_MAGIC
733734
MH_MAGIC_64
734735
MINCORE_INCORE
@@ -1414,6 +1415,10 @@ VM_MEMORY_TCMALLOC
14141415
VM_MEMORY_UNSHARED_PMAP
14151416
VM_MEMORY_WEBCORE_PURGEABLE_BUFFERS
14161417
VM_METER
1418+
VM_PROT_EXECUTE
1419+
VM_PROT_NONE
1420+
VM_PROT_READ
1421+
VM_PROT_WRITE
14171422
VM_SWAPUSAGE
14181423
VSTATUS
14191424
VT0
@@ -1700,6 +1705,10 @@ mach_port_t
17001705
mach_thread_self
17011706
mach_timebase_info
17021707
mach_timebase_info_data_t
1708+
mach_vm_address_t
1709+
mach_vm_map
1710+
mach_vm_offset_t
1711+
mach_vm_size_t
17031712
madvise
17041713
malloc_default_zone
17051714
malloc_printf
@@ -1718,10 +1727,13 @@ malloc_zone_t
17181727
malloc_zone_valloc
17191728
max_align_t
17201729
mcontext_t
1730+
memory_object_t
1731+
memory_object_offset_t
17211732
memset_pattern4
17221733
memset_pattern8
17231734
memset_pattern16
17241735
memset_s
1736+
mem_entry_name_port_t
17251737
mincore
17261738
mkdirat
17271739
mkstemps
@@ -1902,6 +1914,8 @@ uselocale
19021914
utimensat
19031915
utmpx
19041916
utmpxname
1917+
vm_inherit_t
1918+
vm_map_t
19051919
vm_prot_t
19061920
vm_size_t
19071921
wait4

src/unix/bsd/apple/mod.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ pub type processor_flavor_t = ::c_int;
4444
pub type thread_flavor_t = natural_t;
4545
pub type thread_inspect_t = mach_port_t;
4646
pub type policy_t = ::c_int;
47+
pub type mach_vm_address_t = u64;
48+
pub type mach_vm_offset_t = u64;
49+
pub type mach_vm_size_t = u64;
50+
pub type vm_map_t = ::mach_port_t;
51+
pub type mem_entry_name_port_t = ::mach_port_t;
52+
pub type memory_object_t = ::mach_port_t;
53+
pub type memory_object_offset_t = ::c_ulonglong;
54+
pub type vm_inherit_t = ::c_uint;
55+
pub type vm_prot_t = ::c_int;
4756

4857
pub type iconv_t = *mut ::c_void;
4958

@@ -88,7 +97,6 @@ pub type CCCryptorStatus = i32;
8897
pub type CCRNGStatus = ::CCCryptorStatus;
8998

9099
deprecated_mach! {
91-
pub type vm_prot_t = ::c_int;
92100
pub type vm_size_t = ::uintptr_t;
93101
pub type mach_timebase_info_data_t = mach_timebase_info;
94102
}
@@ -3218,6 +3226,11 @@ pub const VM_LOADAVG: ::c_int = 2;
32183226
pub const VM_MACHFACTOR: ::c_int = 4;
32193227
pub const VM_SWAPUSAGE: ::c_int = 5;
32203228
pub const VM_MAXID: ::c_int = 6;
3229+
pub const VM_PROT_NONE: ::vm_prot_t = 0x00;
3230+
pub const VM_PROT_READ: ::vm_prot_t = 0x01;
3231+
pub const VM_PROT_WRITE: ::vm_prot_t = 0x02;
3232+
pub const VM_PROT_EXECUTE: ::vm_prot_t = 0x04;
3233+
pub const MEMORY_OBJECT_NULL: ::memory_object_t = 0;
32213234
pub const HW_MACHINE: ::c_int = 1;
32223235
pub const HW_MODEL: ::c_int = 2;
32233236
pub const HW_NCPU: ::c_int = 3;
@@ -4289,6 +4302,20 @@ extern "C" {
42894302
pub fn CCRandomGenerateBytes(bytes: *mut ::c_void, size: ::size_t) -> ::CCRNGStatus;
42904303

42914304
pub fn _NSGetExecutablePath(buf: *mut ::c_char, bufsize: *mut u32) -> ::c_int;
4305+
4306+
pub fn mach_vm_map(
4307+
target_task: ::vm_map_t,
4308+
address: *mut ::mach_vm_address_t,
4309+
size: ::mach_vm_size_t,
4310+
mask: ::mach_vm_offset_t,
4311+
flags: ::c_int,
4312+
object: ::mem_entry_name_port_t,
4313+
offset: ::memory_object_offset_t,
4314+
copy: ::boolean_t,
4315+
cur_protection: ::vm_prot_t,
4316+
max_protection: ::vm_prot_t,
4317+
inheritance: ::vm_inherit_t,
4318+
) -> ::kern_return_t;
42924319
}
42934320

42944321
cfg_if! {

0 commit comments

Comments
 (0)