1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <strings.h>
30 #include <unistd.h>
31 #include <sys/auxv.h>
32 #include <sys/bitmap.h>
33 #include <sys/brand.h>
34 #include <sys/inttypes.h>
35 #include <sys/lwp.h>
36 #include <sys/syscall.h>
37 #include <sys/systm.h>
38 #include <sys/utsname.h>
39 #include <fcntl.h>
40
41 #include <sn1_brand.h>
42 #include <brand_misc.h>
43
44 /*
45 * See usr/src/lib/brand/shared/brand/common/brand_util.c for general
46 * emulation notes.
47 *
48 * *** sn1 brand emulation scope considerations
49 *
50 * Given that the sn1 brand exists for testing purposes, it should
51 * eventually be enhanced to redirect all system calls through the
52 * brand emulation library. This will ensure the maximum testing
53 * exposure for the brandz infrastructure. Some other options to
54 * consider for improving brandz test exposure are:
55 * - Folding the sn1 brand into the native brand and only enabling
56 * it on DEBUG builds.
57 * - Modifying the zones test suite to use sn1 branded zones by default,
58 * and adapting functional test harnesses to use sn1 branded zones
59 * by default instead of native zones.
60 */
61
62 static long
sn1_uname(sysret_t * rv,uintptr_t p1)63 sn1_uname(sysret_t *rv, uintptr_t p1)
64 {
65 struct utsname un, *unp = (struct utsname *)p1;
66 int rev, err;
67
68 if ((err = __systemcall(rv, SYS_uname + 1024, &un)) != 0)
69 return (err);
70
71 rev = atoi(&un.release[2]);
72 brand_assert(rev >= 10);
73 (void) sprintf(un.release, "5.%d", rev - 1);
74
75 if (uucopy(&un, unp, sizeof (un)) != 0)
76 return (EFAULT);
77 return (0);
78 }
79
80 /*ARGSUSED*/
81 int
brand_init(int argc,char * argv[],char * envp[])82 brand_init(int argc, char *argv[], char *envp[])
83 {
84 ulong_t ldentry;
85
86 brand_pre_init();
87 ldentry = brand_post_init(SN1_VERSION, argc, argv, envp);
88
89 brand_runexe(argv, ldentry);
90 /*NOTREACHED*/
91 brand_abort(0, "brand_runexe() returned");
92 return (-1);
93 }
94
95 #define IN_KERNEL_SYSCALL(name, num) \
96 static long \
97 sn1_##name(sysret_t *rv, \
98 uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, \
99 uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7) \
100 { \
101 return (__systemcall(rv, num + 1024, \
102 a0, a1, a2, a3, a4, a5, a6, a7)); \
103 }
104
105 /*
106 * These are branded system calls, which have been redirected to this
107 * userland emulation library, and are emulated by passing them strait
108 * on to the kernel as native system calls.
109 */
110 IN_KERNEL_SYSCALL(read, SYS_read) /* 3 */
111 IN_KERNEL_SYSCALL(write, SYS_write) /* 4 */
112 IN_KERNEL_SYSCALL(time, SYS_time) /* 13 */
113 IN_KERNEL_SYSCALL(getpid, SYS_getpid) /* 20 */
114 IN_KERNEL_SYSCALL(mount, SYS_mount) /* 21 */
115 IN_KERNEL_SYSCALL(getuid, SYS_getuid) /* 24 */
116 IN_KERNEL_SYSCALL(times, SYS_times) /* 43 */
117 IN_KERNEL_SYSCALL(getgid, SYS_getgid) /* 47 */
118 IN_KERNEL_SYSCALL(utssys, SYS_utssys) /* 57 */
119 IN_KERNEL_SYSCALL(waitid, SYS_waitid) /* 107 */
120
121 /*
122 * This table must have at least NSYSCALL entries in it.
123 *
124 * The second parameter of each entry in the brand_sysent_table
125 * contains the number of parameters and flags that describe the
126 * syscall return value encoding. See the block comments at the
127 * top of this file for more information about the syscall return
128 * value flags and when they should be used.
129 */
130 brand_sysent_table_t brand_sysent_table[] = {
131 #if defined(__sparc) && !defined(__sparcv9)
132 EMULATE(brand_indir, 9 | RV_64RVAL), /* 0 */
133 #else /* !__sparc || __sparcv9 */
134 NOSYS, /* 0 */
135 #endif /* !__sparc || __sparcv9 */
136 NOSYS, /* 1 */
137 NOSYS, /* 2 */
138 EMULATE(sn1_read, 3 | RV_DEFAULT), /* 3 */
139 EMULATE(sn1_write, 3 | RV_DEFAULT), /* 4 */
140 NOSYS, /* 5 */
141 NOSYS, /* 6 */
142 NOSYS, /* 7 */
143 NOSYS, /* 8 */
144 NOSYS, /* 9 */
145 NOSYS, /* 10 */
146 NOSYS, /* 11 */
147 NOSYS, /* 12 */
148 EMULATE(sn1_time, 0 | RV_DEFAULT), /* 13 */
149 NOSYS, /* 14 */
150 NOSYS, /* 15 */
151 NOSYS, /* 16 */
152 NOSYS, /* 17 */
153 NOSYS, /* 18 */
154 NOSYS, /* 19 */
155 EMULATE(sn1_getpid, 0 | RV_32RVAL2), /* 20 */
156 EMULATE(sn1_mount, 8 | RV_DEFAULT), /* 21 */
157 NOSYS, /* 22 */
158 NOSYS, /* 23 */
159 EMULATE(sn1_getuid, 0 | RV_32RVAL2), /* 24 */
160 NOSYS, /* 25 */
161 NOSYS, /* 26 */
162 NOSYS, /* 27 */
163 NOSYS, /* 28 */
164 NOSYS, /* 29 */
165 NOSYS, /* 30 */
166 NOSYS, /* 31 */
167 NOSYS, /* 32 */
168 NOSYS, /* 33 */
169 NOSYS, /* 34 */
170 NOSYS, /* 35 */
171 NOSYS, /* 36 */
172 NOSYS, /* 37 */
173 NOSYS, /* 38 */
174 NOSYS, /* 39 */
175 NOSYS, /* 40 */
176 NOSYS, /* 41 */
177 NOSYS, /* 42 */
178 EMULATE(sn1_times, 1 | RV_DEFAULT), /* 43 */
179 NOSYS, /* 44 */
180 NOSYS, /* 45 */
181 NOSYS, /* 46 */
182 EMULATE(sn1_getgid, 0 | RV_32RVAL2), /* 47 */
183 NOSYS, /* 48 */
184 NOSYS, /* 49 */
185 NOSYS, /* 50 */
186 NOSYS, /* 51 */
187 NOSYS, /* 52 */
188 NOSYS, /* 53 */
189 NOSYS, /* 54 */
190 NOSYS, /* 55 */
191 NOSYS, /* 56 */
192 EMULATE(sn1_utssys, 4 | RV_32RVAL2), /* 57 */
193 NOSYS, /* 58 */
194 NOSYS, /* 59 */
195 NOSYS, /* 60 */
196 NOSYS, /* 61 */
197 NOSYS, /* 62 */
198 NOSYS, /* 63 */
199 NOSYS, /* 64 */
200 NOSYS, /* 65 */
201 NOSYS, /* 66 */
202 NOSYS, /* 67 */
203 NOSYS, /* 68 */
204 NOSYS, /* 69 */
205 NOSYS, /* 70 */
206 NOSYS, /* 71 */
207 NOSYS, /* 72 */
208 NOSYS, /* 73 */
209 NOSYS, /* 74 */
210 NOSYS, /* 75 */
211 NOSYS, /* 76 */
212 NOSYS, /* 77 */
213 NOSYS, /* 78 */
214 NOSYS, /* 79 */
215 NOSYS, /* 80 */
216 NOSYS, /* 81 */
217 NOSYS, /* 82 */
218 NOSYS, /* 83 */
219 NOSYS, /* 84 */
220 NOSYS, /* 85 */
221 NOSYS, /* 86 */
222 NOSYS, /* 87 */
223 NOSYS, /* 88 */
224 NOSYS, /* 89 */
225 NOSYS, /* 90 */
226 NOSYS, /* 91 */
227 NOSYS, /* 92 */
228 NOSYS, /* 93 */
229 NOSYS, /* 94 */
230 NOSYS, /* 95 */
231 NOSYS, /* 96 */
232 NOSYS, /* 97 */
233 NOSYS, /* 98 */
234 NOSYS, /* 99 */
235 NOSYS, /* 100 */
236 NOSYS, /* 101 */
237 NOSYS, /* 102 */
238 NOSYS, /* 103 */
239 NOSYS, /* 104 */
240 NOSYS, /* 105 */
241 NOSYS, /* 106 */
242 EMULATE(sn1_waitid, 4 | RV_DEFAULT), /* 107 */
243 NOSYS, /* 108 */
244 NOSYS, /* 109 */
245 NOSYS, /* 110 */
246 NOSYS, /* 111 */
247 NOSYS, /* 112 */
248 NOSYS, /* 113 */
249 NOSYS, /* 114 */
250 NOSYS, /* 115 */
251 NOSYS, /* 116 */
252 NOSYS, /* 117 */
253 NOSYS, /* 118 */
254 NOSYS, /* 119 */
255 NOSYS, /* 120 */
256 NOSYS, /* 121 */
257 NOSYS, /* 122 */
258 NOSYS, /* 123 */
259 NOSYS, /* 124 */
260 NOSYS, /* 125 */
261 NOSYS, /* 126 */
262 NOSYS, /* 127 */
263 NOSYS, /* 128 */
264 NOSYS, /* 129 */
265 NOSYS, /* 130 */
266 NOSYS, /* 131 */
267 NOSYS, /* 132 */
268 NOSYS, /* 133 */
269 NOSYS, /* 134 */
270 EMULATE(sn1_uname, 1 | RV_DEFAULT), /* 135 */
271 NOSYS, /* 136 */
272 NOSYS, /* 137 */
273 NOSYS, /* 138 */
274 NOSYS, /* 139 */
275 NOSYS, /* 140 */
276 NOSYS, /* 141 */
277 NOSYS, /* 142 */
278 NOSYS, /* 143 */
279 NOSYS, /* 144 */
280 NOSYS, /* 145 */
281 NOSYS, /* 146 */
282 NOSYS, /* 147 */
283 NOSYS, /* 148 */
284 NOSYS, /* 149 */
285 NOSYS, /* 150 */
286 NOSYS, /* 151 */
287 NOSYS, /* 152 */
288 NOSYS, /* 153 */
289 NOSYS, /* 154 */
290 NOSYS, /* 155 */
291 NOSYS, /* 156 */
292 NOSYS, /* 157 */
293 NOSYS, /* 158 */
294 NOSYS, /* 159 */
295 NOSYS, /* 160 */
296 NOSYS, /* 161 */
297 NOSYS, /* 162 */
298 NOSYS, /* 163 */
299 NOSYS, /* 164 */
300 NOSYS, /* 165 */
301 NOSYS, /* 166 */
302 NOSYS, /* 167 */
303 NOSYS, /* 168 */
304 NOSYS, /* 169 */
305 NOSYS, /* 170 */
306 NOSYS, /* 171 */
307 NOSYS, /* 172 */
308 NOSYS, /* 173 */
309 NOSYS, /* 174 */
310 NOSYS, /* 175 */
311 NOSYS, /* 176 */
312 NOSYS, /* 177 */
313 NOSYS, /* 178 */
314 NOSYS, /* 179 */
315 NOSYS, /* 180 */
316 NOSYS, /* 181 */
317 NOSYS, /* 182 */
318 NOSYS, /* 183 */
319 NOSYS, /* 184 */
320 NOSYS, /* 185 */
321 NOSYS, /* 186 */
322 NOSYS, /* 187 */
323 NOSYS, /* 188 */
324 NOSYS, /* 189 */
325 NOSYS, /* 190 */
326 NOSYS, /* 191 */
327 NOSYS, /* 192 */
328 NOSYS, /* 193 */
329 NOSYS, /* 194 */
330 NOSYS, /* 195 */
331 NOSYS, /* 196 */
332 NOSYS, /* 197 */
333 NOSYS, /* 198 */
334 NOSYS, /* 199 */
335 NOSYS, /* 200 */
336 NOSYS, /* 201 */
337 NOSYS, /* 202 */
338 NOSYS, /* 203 */
339 NOSYS, /* 204 */
340 NOSYS, /* 205 */
341 NOSYS, /* 206 */
342 NOSYS, /* 207 */
343 NOSYS, /* 208 */
344 NOSYS, /* 209 */
345 NOSYS, /* 210 */
346 NOSYS, /* 211 */
347 NOSYS, /* 212 */
348 NOSYS, /* 213 */
349 NOSYS, /* 214 */
350 NOSYS, /* 215 */
351 NOSYS, /* 216 */
352 NOSYS, /* 217 */
353 NOSYS, /* 218 */
354 NOSYS, /* 219 */
355 NOSYS, /* 220 */
356 NOSYS, /* 221 */
357 NOSYS, /* 222 */
358 NOSYS, /* 223 */
359 NOSYS, /* 224 */
360 NOSYS, /* 225 */
361 NOSYS, /* 226 */
362 NOSYS, /* 227 */
363 NOSYS, /* 228 */
364 NOSYS, /* 229 */
365 NOSYS, /* 230 */
366 NOSYS, /* 231 */
367 NOSYS, /* 232 */
368 NOSYS, /* 233 */
369 NOSYS, /* 234 */
370 NOSYS, /* 235 */
371 NOSYS, /* 236 */
372 NOSYS, /* 237 */
373 NOSYS, /* 238 */
374 NOSYS, /* 239 */
375 NOSYS, /* 240 */
376 NOSYS, /* 241 */
377 NOSYS, /* 242 */
378 NOSYS, /* 243 */
379 NOSYS, /* 244 */
380 NOSYS, /* 245 */
381 NOSYS, /* 246 */
382 NOSYS, /* 247 */
383 NOSYS, /* 248 */
384 NOSYS, /* 249 */
385 NOSYS, /* 250 */
386 NOSYS, /* 251 */
387 NOSYS, /* 252 */
388 NOSYS, /* 253 */
389 NOSYS, /* 254 */
390 NOSYS /* 255 */
391 };
392