2 * Copyright (c) 2011 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <mach/mach_types.h>
30 #include <mach/mach_traps.h>
31 #include <mach/mach_vm_server.h>
32 #include <mach/mach_port_server.h>
33 #include <mach/vm_map.h>
34 #include <kern/task.h>
35 #include <kern/ipc_tt.h>
36 #include <vm/vm_protos.h>
39 _kernelrpc_mach_vm_allocate_trap(struct _kernelrpc_mach_vm_allocate_trap_args
*args
)
41 mach_vm_offset_t addr
;
42 task_t task
= port_name_to_task(args
->target
);
43 int rv
= MACH_SEND_INVALID_DEST
;
45 if (task
!= current_task())
48 if (copyin(args
->addr
, (char *)&addr
, sizeof (addr
)))
51 rv
= mach_vm_allocate(task
->map
, &addr
, args
->size
, args
->flags
);
52 if (rv
== KERN_SUCCESS
)
53 rv
= copyout(&addr
, args
->addr
, sizeof (addr
));
57 task_deallocate(task
);
62 _kernelrpc_mach_vm_deallocate_trap(struct _kernelrpc_mach_vm_deallocate_args
*args
)
64 task_t task
= port_name_to_task(args
->target
);
65 int rv
= MACH_SEND_INVALID_DEST
;
67 if (task
!= current_task())
70 rv
= mach_vm_deallocate(task
->map
, args
->address
, args
->size
);
74 task_deallocate(task
);
79 _kernelrpc_mach_vm_protect_trap(struct _kernelrpc_mach_vm_protect_args
*args
)
81 task_t task
= port_name_to_task(args
->target
);
82 int rv
= MACH_SEND_INVALID_DEST
;
84 if (task
!= current_task())
87 rv
= mach_vm_protect(task
->map
, args
->address
, args
->size
,
88 args
->set_maximum
, args
->new_protection
);
92 task_deallocate(task
);
97 _kernelrpc_mach_vm_map_trap(struct _kernelrpc_mach_vm_map_trap_args
*args
)
99 mach_vm_offset_t addr
;
100 task_t task
= port_name_to_task(args
->target
);
101 int rv
= MACH_SEND_INVALID_DEST
;
103 if (task
!= current_task())
106 if (copyin(args
->addr
, (char *)&addr
, sizeof (addr
)))
109 rv
= mach_vm_map(task
->map
, &addr
, args
->size
, args
->mask
, args
->flags
,
110 IPC_PORT_NULL
, 0, FALSE
, args
->cur_protection
, VM_PROT_ALL
,
112 if (rv
== KERN_SUCCESS
)
113 rv
= copyout(&addr
, args
->addr
, sizeof (addr
));
117 task_deallocate(task
);
122 _kernelrpc_mach_port_allocate_trap(struct _kernelrpc_mach_port_allocate_args
*args
)
124 task_t task
= port_name_to_task(args
->target
);
125 mach_port_name_t name
;
126 int rv
= MACH_SEND_INVALID_DEST
;
128 if (task
!= current_task())
131 rv
= mach_port_allocate(task
->itk_space
, args
->right
, &name
);
132 if (rv
== KERN_SUCCESS
)
133 rv
= copyout(&name
, args
->name
, sizeof (name
));
138 task_deallocate(task
);
143 _kernelrpc_mach_port_destroy_trap(struct _kernelrpc_mach_port_destroy_args
*args
)
145 task_t task
= port_name_to_task(args
->target
);
146 int rv
= MACH_SEND_INVALID_DEST
;
148 if (task
!= current_task())
151 rv
= mach_port_destroy(task
->itk_space
, args
->name
);
155 task_deallocate(task
);
160 _kernelrpc_mach_port_deallocate_trap(struct _kernelrpc_mach_port_deallocate_args
*args
)
162 task_t task
= port_name_to_task(args
->target
);
163 int rv
= MACH_SEND_INVALID_DEST
;
165 if (task
!= current_task())
168 rv
= mach_port_deallocate(task
->itk_space
, args
->name
);
172 task_deallocate(task
);
177 _kernelrpc_mach_port_mod_refs_trap(struct _kernelrpc_mach_port_mod_refs_args
*args
)
179 task_t task
= port_name_to_task(args
->target
);
180 int rv
= MACH_SEND_INVALID_DEST
;
182 if (task
!= current_task())
185 rv
= mach_port_mod_refs(task
->itk_space
, args
->name
, args
->right
, args
->delta
);
189 task_deallocate(task
);
195 _kernelrpc_mach_port_move_member_trap(struct _kernelrpc_mach_port_move_member_args
*args
)
197 task_t task
= port_name_to_task(args
->target
);
198 int rv
= MACH_SEND_INVALID_DEST
;
200 if (task
!= current_task())
203 rv
= mach_port_move_member(task
->itk_space
, args
->member
, args
->after
);
207 task_deallocate(task
);
212 _kernelrpc_mach_port_insert_right_trap(struct _kernelrpc_mach_port_insert_right_args
*args
)
214 task_t task
= port_name_to_task(args
->target
);
216 mach_msg_type_name_t disp
;
217 int rv
= MACH_SEND_INVALID_DEST
;
219 if (task
!= current_task())
222 rv
= ipc_object_copyin(task
->itk_space
, args
->poly
, args
->polyPoly
,
223 (ipc_object_t
*)&port
);
224 if (rv
!= KERN_SUCCESS
)
226 disp
= ipc_object_copyin_type(args
->polyPoly
);
228 rv
= mach_port_insert_right(task
->itk_space
, args
->name
, port
, disp
);
232 task_deallocate(task
);
237 _kernelrpc_mach_port_insert_member_trap(struct _kernelrpc_mach_port_insert_member_args
*args
)
239 task_t task
= port_name_to_task(args
->target
);
240 int rv
= MACH_SEND_INVALID_DEST
;
242 if (task
!= current_task())
245 rv
= mach_port_insert_member(task
->itk_space
, args
->name
, args
->pset
);
249 task_deallocate(task
);
255 _kernelrpc_mach_port_extract_member_trap(struct _kernelrpc_mach_port_extract_member_args
*args
)
257 task_t task
= port_name_to_task(args
->target
);
258 int rv
= MACH_SEND_INVALID_DEST
;
260 if (task
!= current_task())
263 rv
= mach_port_extract_member(task
->itk_space
, args
->name
, args
->pset
);
267 task_deallocate(task
);
272 _kernelrpc_mach_port_construct_trap(struct _kernelrpc_mach_port_construct_args
*args
)
274 task_t task
= port_name_to_task(args
->target
);
275 mach_port_name_t name
;
276 int rv
= MACH_SEND_INVALID_DEST
;
277 mach_port_options_t options
;
279 if (copyin(args
->options
, (char *)&options
, sizeof (options
))) {
280 rv
= MACH_SEND_INVALID_DATA
;
284 if (task
!= current_task())
287 rv
= mach_port_construct(task
->itk_space
, &options
, args
->context
, &name
);
288 if (rv
== KERN_SUCCESS
)
289 rv
= copyout(&name
, args
->name
, sizeof (name
));
293 task_deallocate(task
);
298 _kernelrpc_mach_port_destruct_trap(struct _kernelrpc_mach_port_destruct_args
*args
)
300 task_t task
= port_name_to_task(args
->target
);
301 int rv
= MACH_SEND_INVALID_DEST
;
303 if (task
!= current_task())
306 rv
= mach_port_destruct(task
->itk_space
, args
->name
, args
->srdelta
, args
->guard
);
310 task_deallocate(task
);
315 _kernelrpc_mach_port_guard_trap(struct _kernelrpc_mach_port_guard_args
*args
)
317 task_t task
= port_name_to_task(args
->target
);
318 int rv
= MACH_SEND_INVALID_DEST
;
320 if (task
!= current_task())
323 rv
= mach_port_guard(task
->itk_space
, args
->name
, args
->guard
, args
->strict
);
327 task_deallocate(task
);
332 _kernelrpc_mach_port_unguard_trap(struct _kernelrpc_mach_port_unguard_args
*args
)
334 task_t task
= port_name_to_task(args
->target
);
335 int rv
= MACH_SEND_INVALID_DEST
;
337 if (task
!= current_task())
340 rv
= mach_port_unguard(task
->itk_space
, args
->name
, args
->guard
);
344 task_deallocate(task
);