Skip to content

Commit 480ba68

Browse files
committed
Auto merge of #2283 - devnexen:mach_vm_map_apple, r=JohnTitor
apple add mach_vm_map, mmap does not provide custom alignment so mach_vm_map is only way.
2 parents 9c1489f + d5bb01c commit 480ba68

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
@@ -1419,6 +1420,10 @@ VM_MEMORY_TCMALLOC
14191420
VM_MEMORY_UNSHARED_PMAP
14201421
VM_MEMORY_WEBCORE_PURGEABLE_BUFFERS
14211422
VM_METER
1423+
VM_PROT_EXECUTE
1424+
VM_PROT_NONE
1425+
VM_PROT_READ
1426+
VM_PROT_WRITE
14221427
VM_SWAPUSAGE
14231428
VSTATUS
14241429
VT0
@@ -1705,6 +1710,10 @@ mach_port_t
17051710
mach_thread_self
17061711
mach_timebase_info
17071712
mach_timebase_info_data_t
1713+
mach_vm_address_t
1714+
mach_vm_map
1715+
mach_vm_offset_t
1716+
mach_vm_size_t
17081717
madvise
17091718
malloc_default_zone
17101719
malloc_printf
@@ -1723,10 +1732,13 @@ malloc_zone_t
17231732
malloc_zone_valloc
17241733
max_align_t
17251734
mcontext_t
1735+
memory_object_t
1736+
memory_object_offset_t
17261737
memset_pattern4
17271738
memset_pattern8
17281739
memset_pattern16
17291740
memset_s
1741+
mem_entry_name_port_t
17301742
mincore
17311743
mkdirat
17321744
mkstemps
@@ -1909,6 +1921,8 @@ uselocale
19091921
utimensat
19101922
utmpx
19111923
utmpxname
1924+
vm_inherit_t
1925+
vm_map_t
19121926
vm_prot_t
19131927
vm_size_t
19141928
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

@@ -93,7 +102,6 @@ pub type CCCryptorStatus = i32;
93102
pub type CCRNGStatus = ::CCCryptorStatus;
94103

95104
deprecated_mach! {
96-
pub type vm_prot_t = ::c_int;
97105
pub type vm_size_t = ::uintptr_t;
98106
pub type mach_timebase_info_data_t = mach_timebase_info;
99107
}
@@ -3318,6 +3326,11 @@ pub const VM_LOADAVG: ::c_int = 2;
33183326
pub const VM_MACHFACTOR: ::c_int = 4;
33193327
pub const VM_SWAPUSAGE: ::c_int = 5;
33203328
pub const VM_MAXID: ::c_int = 6;
3329+
pub const VM_PROT_NONE: ::vm_prot_t = 0x00;
3330+
pub const VM_PROT_READ: ::vm_prot_t = 0x01;
3331+
pub const VM_PROT_WRITE: ::vm_prot_t = 0x02;
3332+
pub const VM_PROT_EXECUTE: ::vm_prot_t = 0x04;
3333+
pub const MEMORY_OBJECT_NULL: ::memory_object_t = 0;
33213334
pub const HW_MACHINE: ::c_int = 1;
33223335
pub const HW_MODEL: ::c_int = 2;
33233336
pub const HW_NCPU: ::c_int = 3;
@@ -4403,6 +4416,20 @@ extern "C" {
44034416
pub fn CCRandomGenerateBytes(bytes: *mut ::c_void, size: ::size_t) -> ::CCRNGStatus;
44044417

44054418
pub fn _NSGetExecutablePath(buf: *mut ::c_char, bufsize: *mut u32) -> ::c_int;
4419+
4420+
pub fn mach_vm_map(
4421+
target_task: ::vm_map_t,
4422+
address: *mut ::mach_vm_address_t,
4423+
size: ::mach_vm_size_t,
4424+
mask: ::mach_vm_offset_t,
4425+
flags: ::c_int,
4426+
object: ::mem_entry_name_port_t,
4427+
offset: ::memory_object_offset_t,
4428+
copy: ::boolean_t,
4429+
cur_protection: ::vm_prot_t,
4430+
max_protection: ::vm_prot_t,
4431+
inheritance: ::vm_inherit_t,
4432+
) -> ::kern_return_t;
44064433
}
44074434

44084435
cfg_if! {

0 commit comments

Comments
 (0)