xref: /xnu-11215.81.4/libsyscall/mach/mach_vm.c (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1*d4514f0bSApple OSS Distributions /*
2*d4514f0bSApple OSS Distributions  * Copyright (c) 2011 Apple Inc. All rights reserved.
3*d4514f0bSApple OSS Distributions  *
4*d4514f0bSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*d4514f0bSApple OSS Distributions  *
6*d4514f0bSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*d4514f0bSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*d4514f0bSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*d4514f0bSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*d4514f0bSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*d4514f0bSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*d4514f0bSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*d4514f0bSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*d4514f0bSApple OSS Distributions  *
15*d4514f0bSApple OSS Distributions  * Please obtain a copy of the License at
16*d4514f0bSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*d4514f0bSApple OSS Distributions  *
18*d4514f0bSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*d4514f0bSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*d4514f0bSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*d4514f0bSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*d4514f0bSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*d4514f0bSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*d4514f0bSApple OSS Distributions  * limitations under the License.
25*d4514f0bSApple OSS Distributions  *
26*d4514f0bSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*d4514f0bSApple OSS Distributions  */
28*d4514f0bSApple OSS Distributions 
29*d4514f0bSApple OSS Distributions /*
30*d4514f0bSApple OSS Distributions  * Make sure we don't accidentally include the external definitions of
31*d4514f0bSApple OSS Distributions  * the routines we're interposing on below.
32*d4514f0bSApple OSS Distributions  */
33*d4514f0bSApple OSS Distributions #define _vm_map_user_
34*d4514f0bSApple OSS Distributions #define _mach_vm_user_
35*d4514f0bSApple OSS Distributions #include <mach/mach.h>
36*d4514f0bSApple OSS Distributions #include <mach/mach_traps.h>
37*d4514f0bSApple OSS Distributions #undef _vm_map_user_
38*d4514f0bSApple OSS Distributions #include <mach/vm_map_internal.h>
39*d4514f0bSApple OSS Distributions #undef _mach_vm_user_
40*d4514f0bSApple OSS Distributions #include <mach/mach_vm_internal.h>
41*d4514f0bSApple OSS Distributions 
42*d4514f0bSApple OSS Distributions #include "stack_logging_internal.h"
43*d4514f0bSApple OSS Distributions 
44*d4514f0bSApple OSS Distributions malloc_logger_t *__syscall_logger = NULL;   // This may get set by Libc's malloc stack logging initialization code.
45*d4514f0bSApple OSS Distributions 
46*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_allocate(mach_port_name_t target,mach_vm_address_t * address,mach_vm_size_t size,int flags)47*d4514f0bSApple OSS Distributions mach_vm_allocate(
48*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
49*d4514f0bSApple OSS Distributions 	mach_vm_address_t *address,
50*d4514f0bSApple OSS Distributions 	mach_vm_size_t size,
51*d4514f0bSApple OSS Distributions 	int flags)
52*d4514f0bSApple OSS Distributions {
53*d4514f0bSApple OSS Distributions 	kern_return_t rv;
54*d4514f0bSApple OSS Distributions 
55*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_mach_vm_allocate_trap(target, address, size, flags);
56*d4514f0bSApple OSS Distributions 
57*d4514f0bSApple OSS Distributions 	if (rv == MACH_SEND_INVALID_DEST) {
58*d4514f0bSApple OSS Distributions 		rv = _kernelrpc_mach_vm_allocate(target, address, size, flags);
59*d4514f0bSApple OSS Distributions 	}
60*d4514f0bSApple OSS Distributions 
61*d4514f0bSApple OSS Distributions 	int userTagFlags = flags & VM_FLAGS_ALIAS_MASK;
62*d4514f0bSApple OSS Distributions 	if (__syscall_logger && rv == KERN_SUCCESS && (userTagFlags != VM_MAKE_TAG(VM_MEMORY_STACK))) {
63*d4514f0bSApple OSS Distributions 		__syscall_logger(stack_logging_type_vm_allocate | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0);
64*d4514f0bSApple OSS Distributions 	}
65*d4514f0bSApple OSS Distributions 
66*d4514f0bSApple OSS Distributions 	return rv;
67*d4514f0bSApple OSS Distributions }
68*d4514f0bSApple OSS Distributions 
69*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_deallocate(mach_port_name_t target,mach_vm_address_t address,mach_vm_size_t size)70*d4514f0bSApple OSS Distributions mach_vm_deallocate(
71*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
72*d4514f0bSApple OSS Distributions 	mach_vm_address_t address,
73*d4514f0bSApple OSS Distributions 	mach_vm_size_t size)
74*d4514f0bSApple OSS Distributions {
75*d4514f0bSApple OSS Distributions 	kern_return_t rv;
76*d4514f0bSApple OSS Distributions 
77*d4514f0bSApple OSS Distributions 	if (__syscall_logger) {
78*d4514f0bSApple OSS Distributions 		__syscall_logger(stack_logging_type_vm_deallocate, (uintptr_t)target, (uintptr_t)address, (uintptr_t)size, 0, 0);
79*d4514f0bSApple OSS Distributions 	}
80*d4514f0bSApple OSS Distributions 
81*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_mach_vm_deallocate_trap(target, address, size);
82*d4514f0bSApple OSS Distributions 
83*d4514f0bSApple OSS Distributions 	if (rv == MACH_SEND_INVALID_DEST) {
84*d4514f0bSApple OSS Distributions 		rv = _kernelrpc_mach_vm_deallocate(target, address, size);
85*d4514f0bSApple OSS Distributions 	}
86*d4514f0bSApple OSS Distributions 
87*d4514f0bSApple OSS Distributions 	return rv;
88*d4514f0bSApple OSS Distributions }
89*d4514f0bSApple OSS Distributions 
90*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_protect(mach_port_name_t task,mach_vm_address_t address,mach_vm_size_t size,boolean_t set_maximum,vm_prot_t new_protection)91*d4514f0bSApple OSS Distributions mach_vm_protect(
92*d4514f0bSApple OSS Distributions 	mach_port_name_t task,
93*d4514f0bSApple OSS Distributions 	mach_vm_address_t address,
94*d4514f0bSApple OSS Distributions 	mach_vm_size_t size,
95*d4514f0bSApple OSS Distributions 	boolean_t set_maximum,
96*d4514f0bSApple OSS Distributions 	vm_prot_t new_protection)
97*d4514f0bSApple OSS Distributions {
98*d4514f0bSApple OSS Distributions 	kern_return_t rv;
99*d4514f0bSApple OSS Distributions 
100*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_mach_vm_protect_trap(task, address, size, set_maximum,
101*d4514f0bSApple OSS Distributions 	    new_protection);
102*d4514f0bSApple OSS Distributions 
103*d4514f0bSApple OSS Distributions 	if (rv == MACH_SEND_INVALID_DEST) {
104*d4514f0bSApple OSS Distributions 		rv = _kernelrpc_mach_vm_protect(task, address, size,
105*d4514f0bSApple OSS Distributions 		    set_maximum, new_protection);
106*d4514f0bSApple OSS Distributions 	}
107*d4514f0bSApple OSS Distributions 
108*d4514f0bSApple OSS Distributions 	return rv;
109*d4514f0bSApple OSS Distributions }
110*d4514f0bSApple OSS Distributions 
111*d4514f0bSApple OSS Distributions kern_return_t
vm_allocate(mach_port_name_t task,vm_address_t * address,vm_size_t size,int flags)112*d4514f0bSApple OSS Distributions vm_allocate(
113*d4514f0bSApple OSS Distributions 	mach_port_name_t task,
114*d4514f0bSApple OSS Distributions 	vm_address_t *address,
115*d4514f0bSApple OSS Distributions 	vm_size_t size,
116*d4514f0bSApple OSS Distributions 	int flags)
117*d4514f0bSApple OSS Distributions {
118*d4514f0bSApple OSS Distributions 	kern_return_t rv;
119*d4514f0bSApple OSS Distributions 	mach_vm_address_t mach_addr;
120*d4514f0bSApple OSS Distributions 
121*d4514f0bSApple OSS Distributions 	mach_addr = (mach_vm_address_t)*address;
122*d4514f0bSApple OSS Distributions 	rv = mach_vm_allocate(task, &mach_addr, size, flags);
123*d4514f0bSApple OSS Distributions #if defined(__LP64__)
124*d4514f0bSApple OSS Distributions 	*address = mach_addr;
125*d4514f0bSApple OSS Distributions #else
126*d4514f0bSApple OSS Distributions 	*address = (vm_address_t)(mach_addr & ((vm_address_t)-1));
127*d4514f0bSApple OSS Distributions #endif
128*d4514f0bSApple OSS Distributions 
129*d4514f0bSApple OSS Distributions 	return rv;
130*d4514f0bSApple OSS Distributions }
131*d4514f0bSApple OSS Distributions 
132*d4514f0bSApple OSS Distributions kern_return_t
vm_deallocate(mach_port_name_t task,vm_address_t address,vm_size_t size)133*d4514f0bSApple OSS Distributions vm_deallocate(
134*d4514f0bSApple OSS Distributions 	mach_port_name_t task,
135*d4514f0bSApple OSS Distributions 	vm_address_t address,
136*d4514f0bSApple OSS Distributions 	vm_size_t size)
137*d4514f0bSApple OSS Distributions {
138*d4514f0bSApple OSS Distributions 	kern_return_t rv;
139*d4514f0bSApple OSS Distributions 
140*d4514f0bSApple OSS Distributions 	rv = mach_vm_deallocate(task, address, size);
141*d4514f0bSApple OSS Distributions 
142*d4514f0bSApple OSS Distributions 	return rv;
143*d4514f0bSApple OSS Distributions }
144*d4514f0bSApple OSS Distributions 
145*d4514f0bSApple OSS Distributions kern_return_t
vm_protect(mach_port_name_t task,vm_address_t address,vm_size_t size,boolean_t set_maximum,vm_prot_t new_protection)146*d4514f0bSApple OSS Distributions vm_protect(
147*d4514f0bSApple OSS Distributions 	mach_port_name_t task,
148*d4514f0bSApple OSS Distributions 	vm_address_t address,
149*d4514f0bSApple OSS Distributions 	vm_size_t size,
150*d4514f0bSApple OSS Distributions 	boolean_t set_maximum,
151*d4514f0bSApple OSS Distributions 	vm_prot_t new_protection)
152*d4514f0bSApple OSS Distributions {
153*d4514f0bSApple OSS Distributions 	kern_return_t rv;
154*d4514f0bSApple OSS Distributions 
155*d4514f0bSApple OSS Distributions 	rv = mach_vm_protect(task, address, size, set_maximum, new_protection);
156*d4514f0bSApple OSS Distributions 
157*d4514f0bSApple OSS Distributions 	return rv;
158*d4514f0bSApple OSS Distributions }
159*d4514f0bSApple OSS Distributions 
160*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_map(mach_port_name_t target,mach_vm_address_t * address,mach_vm_size_t size,mach_vm_offset_t mask,int flags,mem_entry_name_port_t object,memory_object_offset_t offset,boolean_t copy,vm_prot_t cur_protection,vm_prot_t max_protection,vm_inherit_t inheritance)161*d4514f0bSApple OSS Distributions mach_vm_map(
162*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
163*d4514f0bSApple OSS Distributions 	mach_vm_address_t *address,
164*d4514f0bSApple OSS Distributions 	mach_vm_size_t size,
165*d4514f0bSApple OSS Distributions 	mach_vm_offset_t mask,
166*d4514f0bSApple OSS Distributions 	int flags,
167*d4514f0bSApple OSS Distributions 	mem_entry_name_port_t object,
168*d4514f0bSApple OSS Distributions 	memory_object_offset_t offset,
169*d4514f0bSApple OSS Distributions 	boolean_t copy,
170*d4514f0bSApple OSS Distributions 	vm_prot_t cur_protection,
171*d4514f0bSApple OSS Distributions 	vm_prot_t max_protection,
172*d4514f0bSApple OSS Distributions 	vm_inherit_t inheritance)
173*d4514f0bSApple OSS Distributions {
174*d4514f0bSApple OSS Distributions 	kern_return_t rv = MACH_SEND_INVALID_DEST;
175*d4514f0bSApple OSS Distributions 
176*d4514f0bSApple OSS Distributions 	if (object == MEMORY_OBJECT_NULL && max_protection == VM_PROT_ALL &&
177*d4514f0bSApple OSS Distributions 	    inheritance == VM_INHERIT_DEFAULT) {
178*d4514f0bSApple OSS Distributions 		rv = _kernelrpc_mach_vm_map_trap(target, address, size, mask, flags,
179*d4514f0bSApple OSS Distributions 		    cur_protection);
180*d4514f0bSApple OSS Distributions 	}
181*d4514f0bSApple OSS Distributions 
182*d4514f0bSApple OSS Distributions 	if (rv == MACH_SEND_INVALID_DEST) {
183*d4514f0bSApple OSS Distributions 		rv = _kernelrpc_mach_vm_map(target, address, size, mask, flags, object,
184*d4514f0bSApple OSS Distributions 		    offset, copy, cur_protection, max_protection, inheritance);
185*d4514f0bSApple OSS Distributions 	}
186*d4514f0bSApple OSS Distributions 
187*d4514f0bSApple OSS Distributions 	int userTagFlags = flags & VM_FLAGS_ALIAS_MASK;
188*d4514f0bSApple OSS Distributions 	if (__syscall_logger && rv == KERN_SUCCESS && (userTagFlags != VM_MAKE_TAG(VM_MEMORY_STACK))) {
189*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
190*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0);
191*d4514f0bSApple OSS Distributions 	}
192*d4514f0bSApple OSS Distributions 
193*d4514f0bSApple OSS Distributions 	return rv;
194*d4514f0bSApple OSS Distributions }
195*d4514f0bSApple OSS Distributions 
196*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_remap(mach_port_name_t target,mach_vm_address_t * address,mach_vm_size_t size,mach_vm_offset_t mask,int flags,mach_port_name_t src_task,mach_vm_address_t src_address,boolean_t copy,vm_prot_t * cur_protection,vm_prot_t * max_protection,vm_inherit_t inheritance)197*d4514f0bSApple OSS Distributions mach_vm_remap(
198*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
199*d4514f0bSApple OSS Distributions 	mach_vm_address_t *address,
200*d4514f0bSApple OSS Distributions 	mach_vm_size_t size,
201*d4514f0bSApple OSS Distributions 	mach_vm_offset_t mask,
202*d4514f0bSApple OSS Distributions 	int flags,
203*d4514f0bSApple OSS Distributions 	mach_port_name_t src_task,
204*d4514f0bSApple OSS Distributions 	mach_vm_address_t src_address,
205*d4514f0bSApple OSS Distributions 	boolean_t copy,
206*d4514f0bSApple OSS Distributions 	vm_prot_t *cur_protection,
207*d4514f0bSApple OSS Distributions 	vm_prot_t *max_protection,
208*d4514f0bSApple OSS Distributions 	vm_inherit_t inheritance)
209*d4514f0bSApple OSS Distributions {
210*d4514f0bSApple OSS Distributions 	kern_return_t rv;
211*d4514f0bSApple OSS Distributions 
212*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_mach_vm_remap(target, address, size, mask, flags,
213*d4514f0bSApple OSS Distributions 	    src_task, src_address, copy, cur_protection, max_protection,
214*d4514f0bSApple OSS Distributions 	    inheritance);
215*d4514f0bSApple OSS Distributions 
216*d4514f0bSApple OSS Distributions 	if (__syscall_logger && rv == KERN_SUCCESS) {
217*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
218*d4514f0bSApple OSS Distributions 		int userTagFlags = flags & VM_FLAGS_ALIAS_MASK;
219*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0);
220*d4514f0bSApple OSS Distributions 	}
221*d4514f0bSApple OSS Distributions 
222*d4514f0bSApple OSS Distributions 	return rv;
223*d4514f0bSApple OSS Distributions }
224*d4514f0bSApple OSS Distributions 
225*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_remap_new(mach_port_name_t target,mach_vm_address_t * address,mach_vm_size_t size,mach_vm_offset_t mask,int flags,mach_port_name_t src_task,mach_vm_address_t src_address,boolean_t copy,vm_prot_t * cur_protection,vm_prot_t * max_protection,vm_inherit_t inheritance)226*d4514f0bSApple OSS Distributions mach_vm_remap_new(
227*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
228*d4514f0bSApple OSS Distributions 	mach_vm_address_t *address,
229*d4514f0bSApple OSS Distributions 	mach_vm_size_t size,
230*d4514f0bSApple OSS Distributions 	mach_vm_offset_t mask,
231*d4514f0bSApple OSS Distributions 	int flags,
232*d4514f0bSApple OSS Distributions 	mach_port_name_t src_task,
233*d4514f0bSApple OSS Distributions 	mach_vm_address_t src_address,
234*d4514f0bSApple OSS Distributions 	boolean_t copy,
235*d4514f0bSApple OSS Distributions 	vm_prot_t *cur_protection,
236*d4514f0bSApple OSS Distributions 	vm_prot_t *max_protection,
237*d4514f0bSApple OSS Distributions 	vm_inherit_t inheritance)
238*d4514f0bSApple OSS Distributions {
239*d4514f0bSApple OSS Distributions 	kern_return_t rv;
240*d4514f0bSApple OSS Distributions 
241*d4514f0bSApple OSS Distributions 	/* {max,cur}_protection is inout */
242*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_mach_vm_remap_new(target, address, size, mask, flags,
243*d4514f0bSApple OSS Distributions 	    src_task, src_address, copy, cur_protection, max_protection,
244*d4514f0bSApple OSS Distributions 	    inheritance);
245*d4514f0bSApple OSS Distributions 
246*d4514f0bSApple OSS Distributions 	if (__syscall_logger && rv == KERN_SUCCESS) {
247*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
248*d4514f0bSApple OSS Distributions 		int userTagFlags = flags & VM_FLAGS_ALIAS_MASK;
249*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0);
250*d4514f0bSApple OSS Distributions 	}
251*d4514f0bSApple OSS Distributions 
252*d4514f0bSApple OSS Distributions 	return rv;
253*d4514f0bSApple OSS Distributions }
254*d4514f0bSApple OSS Distributions 
255*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_read(mach_port_name_t target,mach_vm_address_t address,mach_vm_size_t size,vm_offset_t * data,mach_msg_type_number_t * dataCnt)256*d4514f0bSApple OSS Distributions mach_vm_read(
257*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
258*d4514f0bSApple OSS Distributions 	mach_vm_address_t address,
259*d4514f0bSApple OSS Distributions 	mach_vm_size_t size,
260*d4514f0bSApple OSS Distributions 	vm_offset_t *data,
261*d4514f0bSApple OSS Distributions 	mach_msg_type_number_t *dataCnt)
262*d4514f0bSApple OSS Distributions {
263*d4514f0bSApple OSS Distributions 	kern_return_t rv;
264*d4514f0bSApple OSS Distributions 
265*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_mach_vm_read(target, address, size, data, dataCnt);
266*d4514f0bSApple OSS Distributions 
267*d4514f0bSApple OSS Distributions 	if (__syscall_logger && rv == KERN_SUCCESS) {
268*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
269*d4514f0bSApple OSS Distributions 		// The target argument is the remote task from which data is being read,
270*d4514f0bSApple OSS Distributions 		// so pass mach_task_self() as the destination task receiving the allocation.
271*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags, (uintptr_t)mach_task_self(), (uintptr_t)*dataCnt, 0, *data, 0);
272*d4514f0bSApple OSS Distributions 	}
273*d4514f0bSApple OSS Distributions 
274*d4514f0bSApple OSS Distributions 	return rv;
275*d4514f0bSApple OSS Distributions }
276*d4514f0bSApple OSS Distributions 
277*d4514f0bSApple OSS Distributions kern_return_t
vm_map(mach_port_name_t target,vm_address_t * address,vm_size_t size,vm_offset_t mask,int flags,mem_entry_name_port_t object,vm_offset_t offset,boolean_t copy,vm_prot_t cur_protection,vm_prot_t max_protection,vm_inherit_t inheritance)278*d4514f0bSApple OSS Distributions vm_map(
279*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
280*d4514f0bSApple OSS Distributions 	vm_address_t *address,
281*d4514f0bSApple OSS Distributions 	vm_size_t size,
282*d4514f0bSApple OSS Distributions 	vm_offset_t mask,
283*d4514f0bSApple OSS Distributions 	int flags,
284*d4514f0bSApple OSS Distributions 	mem_entry_name_port_t object,
285*d4514f0bSApple OSS Distributions 	vm_offset_t offset,
286*d4514f0bSApple OSS Distributions 	boolean_t copy,
287*d4514f0bSApple OSS Distributions 	vm_prot_t cur_protection,
288*d4514f0bSApple OSS Distributions 	vm_prot_t max_protection,
289*d4514f0bSApple OSS Distributions 	vm_inherit_t inheritance)
290*d4514f0bSApple OSS Distributions {
291*d4514f0bSApple OSS Distributions 	kern_return_t rv;
292*d4514f0bSApple OSS Distributions 
293*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_vm_map(target, address, size, mask, flags, object,
294*d4514f0bSApple OSS Distributions 	    offset, copy, cur_protection, max_protection, inheritance);
295*d4514f0bSApple OSS Distributions 
296*d4514f0bSApple OSS Distributions 	if (__syscall_logger && rv == KERN_SUCCESS) {
297*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
298*d4514f0bSApple OSS Distributions 		int userTagFlags = flags & VM_FLAGS_ALIAS_MASK;
299*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0);
300*d4514f0bSApple OSS Distributions 	}
301*d4514f0bSApple OSS Distributions 
302*d4514f0bSApple OSS Distributions 	return rv;
303*d4514f0bSApple OSS Distributions }
304*d4514f0bSApple OSS Distributions 
305*d4514f0bSApple OSS Distributions kern_return_t
vm_remap(mach_port_name_t target,vm_address_t * address,vm_size_t size,vm_offset_t mask,int flags,mach_port_name_t src_task,vm_address_t src_address,boolean_t copy,vm_prot_t * cur_protection,vm_prot_t * max_protection,vm_inherit_t inheritance)306*d4514f0bSApple OSS Distributions vm_remap(
307*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
308*d4514f0bSApple OSS Distributions 	vm_address_t *address,
309*d4514f0bSApple OSS Distributions 	vm_size_t size,
310*d4514f0bSApple OSS Distributions 	vm_offset_t mask,
311*d4514f0bSApple OSS Distributions 	int flags,
312*d4514f0bSApple OSS Distributions 	mach_port_name_t src_task,
313*d4514f0bSApple OSS Distributions 	vm_address_t src_address,
314*d4514f0bSApple OSS Distributions 	boolean_t copy,
315*d4514f0bSApple OSS Distributions 	vm_prot_t *cur_protection,
316*d4514f0bSApple OSS Distributions 	vm_prot_t *max_protection,
317*d4514f0bSApple OSS Distributions 	vm_inherit_t inheritance)
318*d4514f0bSApple OSS Distributions {
319*d4514f0bSApple OSS Distributions 	kern_return_t rv;
320*d4514f0bSApple OSS Distributions 
321*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_vm_remap(target, address, size, mask, flags,
322*d4514f0bSApple OSS Distributions 	    src_task, src_address, copy, cur_protection, max_protection,
323*d4514f0bSApple OSS Distributions 	    inheritance);
324*d4514f0bSApple OSS Distributions 
325*d4514f0bSApple OSS Distributions 	if (__syscall_logger) {
326*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
327*d4514f0bSApple OSS Distributions 		int userTagFlags = flags & VM_FLAGS_ALIAS_MASK;
328*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0);
329*d4514f0bSApple OSS Distributions 	}
330*d4514f0bSApple OSS Distributions 
331*d4514f0bSApple OSS Distributions 	return rv;
332*d4514f0bSApple OSS Distributions }
333*d4514f0bSApple OSS Distributions 
334*d4514f0bSApple OSS Distributions kern_return_t
vm_remap_new(mach_port_name_t target,vm_address_t * address,vm_size_t size,vm_offset_t mask,int flags,mach_port_name_t src_task,vm_address_t src_address,boolean_t copy,vm_prot_t * cur_protection,vm_prot_t * max_protection,vm_inherit_t inheritance)335*d4514f0bSApple OSS Distributions vm_remap_new(
336*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
337*d4514f0bSApple OSS Distributions 	vm_address_t *address,
338*d4514f0bSApple OSS Distributions 	vm_size_t size,
339*d4514f0bSApple OSS Distributions 	vm_offset_t mask,
340*d4514f0bSApple OSS Distributions 	int flags,
341*d4514f0bSApple OSS Distributions 	mach_port_name_t src_task,
342*d4514f0bSApple OSS Distributions 	vm_address_t src_address,
343*d4514f0bSApple OSS Distributions 	boolean_t copy,
344*d4514f0bSApple OSS Distributions 	vm_prot_t *cur_protection,
345*d4514f0bSApple OSS Distributions 	vm_prot_t *max_protection,
346*d4514f0bSApple OSS Distributions 	vm_inherit_t inheritance)
347*d4514f0bSApple OSS Distributions {
348*d4514f0bSApple OSS Distributions 	kern_return_t rv;
349*d4514f0bSApple OSS Distributions 
350*d4514f0bSApple OSS Distributions 	/* {max,cur}_protection is inout */
351*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_vm_remap_new(target, address, size, mask, flags,
352*d4514f0bSApple OSS Distributions 	    src_task, src_address, copy, cur_protection, max_protection,
353*d4514f0bSApple OSS Distributions 	    inheritance);
354*d4514f0bSApple OSS Distributions 
355*d4514f0bSApple OSS Distributions 	if (__syscall_logger) {
356*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
357*d4514f0bSApple OSS Distributions 		int userTagFlags = flags & VM_FLAGS_ALIAS_MASK;
358*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0);
359*d4514f0bSApple OSS Distributions 	}
360*d4514f0bSApple OSS Distributions 
361*d4514f0bSApple OSS Distributions 	return rv;
362*d4514f0bSApple OSS Distributions }
363*d4514f0bSApple OSS Distributions 
364*d4514f0bSApple OSS Distributions kern_return_t
vm_read(mach_port_name_t target,vm_address_t address,vm_size_t size,vm_offset_t * data,mach_msg_type_number_t * dataCnt)365*d4514f0bSApple OSS Distributions vm_read(
366*d4514f0bSApple OSS Distributions 	mach_port_name_t target,
367*d4514f0bSApple OSS Distributions 	vm_address_t address,
368*d4514f0bSApple OSS Distributions 	vm_size_t size,
369*d4514f0bSApple OSS Distributions 	vm_offset_t *data,
370*d4514f0bSApple OSS Distributions 	mach_msg_type_number_t *dataCnt)
371*d4514f0bSApple OSS Distributions {
372*d4514f0bSApple OSS Distributions 	kern_return_t rv;
373*d4514f0bSApple OSS Distributions 
374*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_vm_read(target, address, size, data, dataCnt);
375*d4514f0bSApple OSS Distributions 
376*d4514f0bSApple OSS Distributions 	if (__syscall_logger && rv == KERN_SUCCESS) {
377*d4514f0bSApple OSS Distributions 		int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem;
378*d4514f0bSApple OSS Distributions 		// The target argument is the remote task from which data is being read,
379*d4514f0bSApple OSS Distributions 		// so pass mach_task_self() as the destination task receiving the allocation.
380*d4514f0bSApple OSS Distributions 		__syscall_logger(eventTypeFlags, (uintptr_t)mach_task_self(), (uintptr_t)*dataCnt, 0, *data, 0);
381*d4514f0bSApple OSS Distributions 	}
382*d4514f0bSApple OSS Distributions 
383*d4514f0bSApple OSS Distributions 	return rv;
384*d4514f0bSApple OSS Distributions }
385*d4514f0bSApple OSS Distributions 
386*d4514f0bSApple OSS Distributions kern_return_t
mach_vm_purgable_control(mach_port_name_t target,mach_vm_offset_t address,vm_purgable_t control,int * state)387*d4514f0bSApple OSS Distributions mach_vm_purgable_control(
388*d4514f0bSApple OSS Distributions 	mach_port_name_t        target,
389*d4514f0bSApple OSS Distributions 	mach_vm_offset_t        address,
390*d4514f0bSApple OSS Distributions 	vm_purgable_t           control,
391*d4514f0bSApple OSS Distributions 	int                     *state)
392*d4514f0bSApple OSS Distributions {
393*d4514f0bSApple OSS Distributions 	kern_return_t rv;
394*d4514f0bSApple OSS Distributions 
395*d4514f0bSApple OSS Distributions 	rv = _kernelrpc_mach_vm_purgable_control_trap(target, address, control, state);
396*d4514f0bSApple OSS Distributions 
397*d4514f0bSApple OSS Distributions 	if (rv == MACH_SEND_INVALID_DEST) {
398*d4514f0bSApple OSS Distributions 		rv = _kernelrpc_mach_vm_purgable_control(target, address, control, state);
399*d4514f0bSApple OSS Distributions 	}
400*d4514f0bSApple OSS Distributions 
401*d4514f0bSApple OSS Distributions 	return rv;
402*d4514f0bSApple OSS Distributions }
403*d4514f0bSApple OSS Distributions 
404*d4514f0bSApple OSS Distributions kern_return_t
vm_purgable_control(mach_port_name_t task,vm_offset_t address,vm_purgable_t control,int * state)405*d4514f0bSApple OSS Distributions vm_purgable_control(
406*d4514f0bSApple OSS Distributions 	mach_port_name_t        task,
407*d4514f0bSApple OSS Distributions 	vm_offset_t             address,
408*d4514f0bSApple OSS Distributions 	vm_purgable_t           control,
409*d4514f0bSApple OSS Distributions 	int                     *state)
410*d4514f0bSApple OSS Distributions {
411*d4514f0bSApple OSS Distributions 	return mach_vm_purgable_control(task,
412*d4514f0bSApple OSS Distributions 	           (mach_vm_offset_t) address,
413*d4514f0bSApple OSS Distributions 	           control,
414*d4514f0bSApple OSS Distributions 	           state);
415*d4514f0bSApple OSS Distributions }
416