]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/syscall_emulation.c
xnu-517.12.7.tar.gz
[apple/xnu.git] / osfmk / kern / syscall_emulation.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and ditribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52
53 #include <mach/error.h>
54 #include <mach/vm_param.h>
55 #include <mach/boolean.h>
56 #include <kern/misc_protos.h>
57 #include <kern/syscall_emulation.h>
58 #include <kern/task.h>
59 #include <kern/kalloc.h>
60 #include <vm/vm_kern.h>
61 #include <machine/thread.h> /* for syscall_emulation_sync */
62
63 /*
64 * Exported interface
65 */
66
67 /*
68 * WARNING:
69 * This code knows that kalloc() allocates memory most efficiently
70 * in sizes that are powers of 2, and asks for those sizes.
71 */
72
73 /*
74 * Go from number of entries to size of struct eml_dispatch and back.
75 */
76 #define base_size (sizeof(struct eml_dispatch) - sizeof(eml_routine_t))
77 #define count_to_size(count) \
78 (base_size + sizeof(vm_offset_t) * (count))
79
80 #define size_to_count(size) \
81 ( ((size) - base_size) / sizeof(vm_offset_t) )
82
83 /* Forwards */
84 kern_return_t
85 task_set_emulation_vector_internal(
86 task_t task,
87 int vector_start,
88 emulation_vector_t emulation_vector,
89 mach_msg_type_number_t emulation_vector_count);
90
91 /*
92 * eml_init: initialize user space emulation code
93 */
94 void
95 eml_init(void)
96 {
97 }
98
99 /*
100 * eml_task_reference() [Exported]
101 *
102 * Bumps the reference count on the common emulation
103 * vector.
104 */
105
106 void
107 eml_task_reference(
108 task_t task,
109 task_t parent)
110 {
111 register eml_dispatch_t eml;
112
113 if (parent == TASK_NULL)
114 eml = EML_DISPATCH_NULL;
115 else
116 eml = parent->eml_dispatch;
117
118 if (eml != EML_DISPATCH_NULL) {
119 mutex_lock(&eml->lock);
120 eml->ref_count++;
121 mutex_unlock(&eml->lock);
122 }
123 task->eml_dispatch = eml;
124 }
125
126
127 /*
128 * eml_task_deallocate() [Exported]
129 *
130 * Cleans up after the emulation code when a process exits.
131 */
132
133 void
134 eml_task_deallocate(
135 task_t task)
136 {
137 register eml_dispatch_t eml;
138
139 eml = task->eml_dispatch;
140 if (eml != EML_DISPATCH_NULL) {
141 int count;
142
143 mutex_lock(&eml->lock);
144 count = --eml->ref_count;
145 mutex_unlock(&eml->lock);
146
147 if (count == 0)
148 kfree((vm_offset_t)eml, count_to_size(eml->disp_count));
149
150 task->eml_dispatch = EML_DISPATCH_NULL;
151 }
152 }
153
154 /*
155 * task_set_emulation_vector: [Server Entry]
156 * set a list of emulated system calls for this task.
157 */
158 kern_return_t
159 task_set_emulation_vector_internal(
160 task_t task,
161 int vector_start,
162 emulation_vector_t emulation_vector,
163 mach_msg_type_number_t emulation_vector_count)
164 {
165 return KERN_NOT_SUPPORTED;
166 }
167
168 /*
169 * task_set_emulation_vector: [Server Entry]
170 *
171 * Set the list of emulated system calls for this task.
172 * The list is out-of-line.
173 */
174 kern_return_t
175 task_set_emulation_vector(
176 task_t task,
177 int vector_start,
178 emulation_vector_t emulation_vector,
179 mach_msg_type_number_t emulation_vector_count)
180 {
181 return KERN_NOT_SUPPORTED;
182 }
183
184 /*
185 * task_get_emulation_vector: [Server Entry]
186 *
187 * Get the list of emulated system calls for this task.
188 * List is returned out-of-line.
189 */
190 kern_return_t
191 task_get_emulation_vector(
192 task_t task,
193 int *vector_start, /* out */
194 emulation_vector_t *emulation_vector, /* out */
195 mach_msg_type_number_t *emulation_vector_count) /* out */
196 {
197 return KERN_NOT_SUPPORTED;
198 }
199
200 /*
201 * task_set_emulation: [Server Entry]
202 * set up for user space emulation of syscalls within this task.
203 */
204 kern_return_t
205 task_set_emulation(
206 task_t task,
207 vm_offset_t routine_entry_pt,
208 int routine_number)
209 {
210 return KERN_NOT_SUPPORTED;
211 }
212
213
214
215