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_port_allocate_trap(struct _kernelrpc_mach_port_allocate_args
*args
)
99 task_t task
= port_name_to_task(args
->target
);
100 mach_port_name_t name
;
101 int rv
= MACH_SEND_INVALID_DEST
;
103 if (task
!= current_task())
106 rv
= mach_port_allocate(task
->itk_space
, args
->right
, &name
);
107 if (rv
== KERN_SUCCESS
)
108 rv
= copyout(&name
, args
->name
, sizeof (name
));
113 task_deallocate(task
);
118 _kernelrpc_mach_port_destroy_trap(struct _kernelrpc_mach_port_destroy_args
*args
)
120 task_t task
= port_name_to_task(args
->target
);
121 int rv
= MACH_SEND_INVALID_DEST
;
123 if (task
!= current_task())
126 rv
= mach_port_destroy(task
->itk_space
, args
->name
);
130 task_deallocate(task
);
135 _kernelrpc_mach_port_deallocate_trap(struct _kernelrpc_mach_port_deallocate_args
*args
)
137 task_t task
= port_name_to_task(args
->target
);
138 int rv
= MACH_SEND_INVALID_DEST
;
140 if (task
!= current_task())
143 rv
= mach_port_deallocate(task
->itk_space
, args
->name
);
147 task_deallocate(task
);
152 _kernelrpc_mach_port_mod_refs_trap(struct _kernelrpc_mach_port_mod_refs_args
*args
)
154 task_t task
= port_name_to_task(args
->target
);
155 int rv
= MACH_SEND_INVALID_DEST
;
157 if (task
!= current_task())
160 rv
= mach_port_mod_refs(task
->itk_space
, args
->name
, args
->right
, args
->delta
);
164 task_deallocate(task
);
170 _kernelrpc_mach_port_move_member_trap(struct _kernelrpc_mach_port_move_member_args
*args
)
172 task_t task
= port_name_to_task(args
->target
);
173 int rv
= MACH_SEND_INVALID_DEST
;
175 if (task
!= current_task())
178 rv
= mach_port_move_member(task
->itk_space
, args
->member
, args
->after
);
182 task_deallocate(task
);
187 _kernelrpc_mach_port_insert_right_trap(struct _kernelrpc_mach_port_insert_right_args
*args
)
189 task_t task
= port_name_to_task(args
->target
);
191 mach_msg_type_name_t disp
;
192 int rv
= MACH_SEND_INVALID_DEST
;
194 if (task
!= current_task())
197 rv
= ipc_object_copyin(task
->itk_space
, args
->poly
, args
->polyPoly
,
198 (ipc_object_t
*)&port
);
199 if (rv
!= KERN_SUCCESS
)
201 disp
= ipc_object_copyin_type(args
->polyPoly
);
203 rv
= mach_port_insert_right(task
->itk_space
, args
->name
, port
, disp
);
207 task_deallocate(task
);
212 _kernelrpc_mach_port_insert_member_trap(struct _kernelrpc_mach_port_insert_member_args
*args
)
214 task_t task
= port_name_to_task(args
->target
);
215 int rv
= MACH_SEND_INVALID_DEST
;
217 if (task
!= current_task())
220 rv
= mach_port_insert_member(task
->itk_space
, args
->name
, args
->pset
);
224 task_deallocate(task
);
230 _kernelrpc_mach_port_extract_member_trap(struct _kernelrpc_mach_port_extract_member_args
*args
)
232 task_t task
= port_name_to_task(args
->target
);
233 int rv
= MACH_SEND_INVALID_DEST
;
235 if (task
!= current_task())
238 rv
= mach_port_extract_member(task
->itk_space
, args
->name
, args
->pset
);
242 task_deallocate(task
);