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