]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/mach_kernelrpc.c
75244966f01b67eb69a7a7635bcf4446a93535f1
[apple/xnu.git] / osfmk / ipc / mach_kernelrpc.c
1 /*
2 * Copyright (c) 2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
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>
37
38 int
39 _kernelrpc_mach_vm_allocate_trap(struct _kernelrpc_mach_vm_allocate_trap_args *args)
40 {
41 mach_vm_offset_t addr;
42 task_t task = port_name_to_task(args->target);
43 int rv = MACH_SEND_INVALID_DEST;
44
45 if (task != current_task())
46 goto done;
47
48 if (copyin(args->addr, (char *)&addr, sizeof (addr)))
49 goto done;
50
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));
54
55 done:
56 if (task)
57 task_deallocate(task);
58 return (rv);
59 }
60
61 int
62 _kernelrpc_mach_vm_deallocate_trap(struct _kernelrpc_mach_vm_deallocate_args *args)
63 {
64 task_t task = port_name_to_task(args->target);
65 int rv = MACH_SEND_INVALID_DEST;
66
67 if (task != current_task())
68 goto done;
69
70 rv = mach_vm_deallocate(task->map, args->address, args->size);
71
72 done:
73 if (task)
74 task_deallocate(task);
75 return (rv);
76 }
77
78 int
79 _kernelrpc_mach_vm_protect_trap(struct _kernelrpc_mach_vm_protect_args *args)
80 {
81 task_t task = port_name_to_task(args->target);
82 int rv = MACH_SEND_INVALID_DEST;
83
84 if (task != current_task())
85 goto done;
86
87 rv = mach_vm_protect(task->map, args->address, args->size,
88 args->set_maximum, args->new_protection);
89
90 done:
91 if (task)
92 task_deallocate(task);
93 return (rv);
94 }
95
96 int
97 _kernelrpc_mach_port_allocate_trap(struct _kernelrpc_mach_port_allocate_args *args)
98 {
99 task_t task = port_name_to_task(args->target);
100 mach_port_name_t name;
101 int rv = MACH_SEND_INVALID_DEST;
102
103 if (task != current_task())
104 goto done;
105
106 rv = mach_port_allocate(task->itk_space, args->right, &name);
107 if (rv == KERN_SUCCESS)
108 rv = copyout(&name, args->name, sizeof (name));
109
110
111 done:
112 if (task)
113 task_deallocate(task);
114 return (rv);
115 }
116
117 int
118 _kernelrpc_mach_port_destroy_trap(struct _kernelrpc_mach_port_destroy_args *args)
119 {
120 task_t task = port_name_to_task(args->target);
121 int rv = MACH_SEND_INVALID_DEST;
122
123 if (task != current_task())
124 goto done;
125
126 rv = mach_port_destroy(task->itk_space, args->name);
127
128 done:
129 if (task)
130 task_deallocate(task);
131 return (rv);
132 }
133
134 int
135 _kernelrpc_mach_port_deallocate_trap(struct _kernelrpc_mach_port_deallocate_args *args)
136 {
137 task_t task = port_name_to_task(args->target);
138 int rv = MACH_SEND_INVALID_DEST;
139
140 if (task != current_task())
141 goto done;
142
143 rv = mach_port_deallocate(task->itk_space, args->name);
144
145 done:
146 if (task)
147 task_deallocate(task);
148 return (rv);
149 }
150
151 int
152 _kernelrpc_mach_port_mod_refs_trap(struct _kernelrpc_mach_port_mod_refs_args *args)
153 {
154 task_t task = port_name_to_task(args->target);
155 int rv = MACH_SEND_INVALID_DEST;
156
157 if (task != current_task())
158 goto done;
159
160 rv = mach_port_mod_refs(task->itk_space, args->name, args->right, args->delta);
161
162 done:
163 if (task)
164 task_deallocate(task);
165 return (rv);
166 }
167
168
169 int
170 _kernelrpc_mach_port_move_member_trap(struct _kernelrpc_mach_port_move_member_args *args)
171 {
172 task_t task = port_name_to_task(args->target);
173 int rv = MACH_SEND_INVALID_DEST;
174
175 if (task != current_task())
176 goto done;
177
178 rv = mach_port_move_member(task->itk_space, args->member, args->after);
179
180 done:
181 if (task)
182 task_deallocate(task);
183 return (rv);
184 }
185
186 int
187 _kernelrpc_mach_port_insert_right_trap(struct _kernelrpc_mach_port_insert_right_args *args)
188 {
189 task_t task = port_name_to_task(args->target);
190 ipc_port_t port;
191 mach_msg_type_name_t disp;
192 int rv = MACH_SEND_INVALID_DEST;
193
194 if (task != current_task())
195 goto done;
196
197 rv = ipc_object_copyin(task->itk_space, args->poly, args->polyPoly,
198 (ipc_object_t *)&port);
199 if (rv != KERN_SUCCESS)
200 goto done;
201 disp = ipc_object_copyin_type(args->polyPoly);
202
203 rv = mach_port_insert_right(task->itk_space, args->name, port, disp);
204
205 done:
206 if (task)
207 task_deallocate(task);
208 return (rv);
209 }
210
211 int
212 _kernelrpc_mach_port_insert_member_trap(struct _kernelrpc_mach_port_insert_member_args *args)
213 {
214 task_t task = port_name_to_task(args->target);
215 int rv = MACH_SEND_INVALID_DEST;
216
217 if (task != current_task())
218 goto done;
219
220 rv = mach_port_insert_member(task->itk_space, args->name, args->pset);
221
222 done:
223 if (task)
224 task_deallocate(task);
225 return (rv);
226 }
227
228
229 int
230 _kernelrpc_mach_port_extract_member_trap(struct _kernelrpc_mach_port_extract_member_args *args)
231 {
232 task_t task = port_name_to_task(args->target);
233 int rv = MACH_SEND_INVALID_DEST;
234
235 if (task != current_task())
236 goto done;
237
238 rv = mach_port_extract_member(task->itk_space, args->name, args->pset);
239
240 done:
241 if (task)
242 task_deallocate(task);
243 return (rv);
244 }