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 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 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(readlink, SYS_readlink) /* 90 */ 120 IN_KERNEL_SYSCALL(waitid, SYS_waitid) /* 107 */ 121 122 /* 123 * This table must have at least NSYSCALL entries in it. 124 * 125 * The second parameter of each entry in the brand_sysent_table 126 * contains the number of parameters and flags that describe the 127 * syscall return value encoding. See the block comments at the 128 * top of this file for more information about the syscall return 129 * value flags and when they should be used. 130 */ 131 brand_sysent_table_t brand_sysent_table[] = { 132 #if defined(__sparc) && !defined(__sparcv9) 133 EMULATE(brand_indir, 9 | RV_64RVAL), /* 0 */ 134 #else /* !__sparc || __sparcv9 */ 135 NOSYS, /* 0 */ 136 #endif /* !__sparc || __sparcv9 */ 137 NOSYS, /* 1 */ 138 NOSYS, /* 2 */ 139 EMULATE(sn1_read, 3 | RV_DEFAULT), /* 3 */ 140 EMULATE(sn1_write, 3 | RV_DEFAULT), /* 4 */ 141 NOSYS, /* 5 */ 142 NOSYS, /* 6 */ 143 NOSYS, /* 7 */ 144 NOSYS, /* 8 */ 145 NOSYS, /* 9 */ 146 NOSYS, /* 10 */ 147 NOSYS, /* 11 */ 148 NOSYS, /* 12 */ 149 EMULATE(sn1_time, 0 | RV_DEFAULT), /* 13 */ 150 NOSYS, /* 14 */ 151 NOSYS, /* 15 */ 152 NOSYS, /* 16 */ 153 NOSYS, /* 17 */ 154 NOSYS, /* 18 */ 155 NOSYS, /* 19 */ 156 EMULATE(sn1_getpid, 0 | RV_32RVAL2), /* 20 */ 157 EMULATE(sn1_mount, 8 | RV_DEFAULT), /* 21 */ 158 NOSYS, /* 22 */ 159 NOSYS, /* 23 */ 160 EMULATE(sn1_getuid, 0 | RV_32RVAL2), /* 24 */ 161 NOSYS, /* 25 */ 162 NOSYS, /* 26 */ 163 NOSYS, /* 27 */ 164 NOSYS, /* 28 */ 165 NOSYS, /* 29 */ 166 NOSYS, /* 30 */ 167 NOSYS, /* 31 */ 168 NOSYS, /* 32 */ 169 NOSYS, /* 33 */ 170 NOSYS, /* 34 */ 171 NOSYS, /* 35 */ 172 NOSYS, /* 36 */ 173 NOSYS, /* 37 */ 174 NOSYS, /* 38 */ 175 NOSYS, /* 39 */ 176 NOSYS, /* 40 */ 177 NOSYS, /* 41 */ 178 NOSYS, /* 42 */ 179 EMULATE(sn1_times, 1 | RV_DEFAULT), /* 43 */ 180 NOSYS, /* 44 */ 181 NOSYS, /* 45 */ 182 NOSYS, /* 46 */ 183 EMULATE(sn1_getgid, 0 | RV_32RVAL2), /* 47 */ 184 NOSYS, /* 48 */ 185 NOSYS, /* 49 */ 186 NOSYS, /* 50 */ 187 NOSYS, /* 51 */ 188 NOSYS, /* 52 */ 189 NOSYS, /* 53 */ 190 NOSYS, /* 54 */ 191 NOSYS, /* 55 */ 192 NOSYS, /* 56 */ 193 EMULATE(sn1_utssys, 4 | RV_32RVAL2), /* 57 */ 194 NOSYS, /* 58 */ 195 NOSYS, /* 59 */ 196 NOSYS, /* 60 */ 197 NOSYS, /* 61 */ 198 NOSYS, /* 62 */ 199 NOSYS, /* 63 */ 200 NOSYS, /* 64 */ 201 NOSYS, /* 65 */ 202 NOSYS, /* 66 */ 203 NOSYS, /* 67 */ 204 NOSYS, /* 68 */ 205 NOSYS, /* 69 */ 206 NOSYS, /* 70 */ 207 NOSYS, /* 71 */ 208 NOSYS, /* 72 */ 209 NOSYS, /* 73 */ 210 NOSYS, /* 74 */ 211 NOSYS, /* 75 */ 212 NOSYS, /* 76 */ 213 NOSYS, /* 77 */ 214 NOSYS, /* 78 */ 215 NOSYS, /* 79 */ 216 NOSYS, /* 80 */ 217 NOSYS, /* 81 */ 218 NOSYS, /* 82 */ 219 NOSYS, /* 83 */ 220 NOSYS, /* 84 */ 221 NOSYS, /* 85 */ 222 NOSYS, /* 86 */ 223 NOSYS, /* 87 */ 224 NOSYS, /* 88 */ 225 NOSYS, /* 89 */ 226 EMULATE(sn1_readlink, 3 | RV_DEFAULT), /* 90 */ 227 NOSYS, /* 91 */ 228 NOSYS, /* 92 */ 229 NOSYS, /* 93 */ 230 NOSYS, /* 94 */ 231 NOSYS, /* 95 */ 232 NOSYS, /* 96 */ 233 NOSYS, /* 97 */ 234 NOSYS, /* 98 */ 235 NOSYS, /* 99 */ 236 NOSYS, /* 100 */ 237 NOSYS, /* 101 */ 238 NOSYS, /* 102 */ 239 NOSYS, /* 103 */ 240 NOSYS, /* 104 */ 241 NOSYS, /* 105 */ 242 NOSYS, /* 106 */ 243 EMULATE(sn1_waitid, 4 | RV_DEFAULT), /* 107 */ 244 NOSYS, /* 108 */ 245 NOSYS, /* 109 */ 246 NOSYS, /* 110 */ 247 NOSYS, /* 111 */ 248 NOSYS, /* 112 */ 249 NOSYS, /* 113 */ 250 NOSYS, /* 114 */ 251 NOSYS, /* 115 */ 252 NOSYS, /* 116 */ 253 NOSYS, /* 117 */ 254 NOSYS, /* 118 */ 255 NOSYS, /* 119 */ 256 NOSYS, /* 120 */ 257 NOSYS, /* 121 */ 258 NOSYS, /* 122 */ 259 NOSYS, /* 123 */ 260 NOSYS, /* 124 */ 261 NOSYS, /* 125 */ 262 NOSYS, /* 126 */ 263 NOSYS, /* 127 */ 264 NOSYS, /* 128 */ 265 NOSYS, /* 129 */ 266 NOSYS, /* 130 */ 267 NOSYS, /* 131 */ 268 NOSYS, /* 132 */ 269 NOSYS, /* 133 */ 270 NOSYS, /* 134 */ 271 EMULATE(sn1_uname, 1 | RV_DEFAULT), /* 135 */ 272 NOSYS, /* 136 */ 273 NOSYS, /* 137 */ 274 NOSYS, /* 138 */ 275 NOSYS, /* 139 */ 276 NOSYS, /* 140 */ 277 NOSYS, /* 141 */ 278 NOSYS, /* 142 */ 279 NOSYS, /* 143 */ 280 NOSYS, /* 144 */ 281 NOSYS, /* 145 */ 282 NOSYS, /* 146 */ 283 NOSYS, /* 147 */ 284 NOSYS, /* 148 */ 285 NOSYS, /* 149 */ 286 NOSYS, /* 150 */ 287 NOSYS, /* 151 */ 288 NOSYS, /* 152 */ 289 NOSYS, /* 153 */ 290 NOSYS, /* 154 */ 291 NOSYS, /* 155 */ 292 NOSYS, /* 156 */ 293 NOSYS, /* 157 */ 294 NOSYS, /* 158 */ 295 NOSYS, /* 159 */ 296 NOSYS, /* 160 */ 297 NOSYS, /* 161 */ 298 NOSYS, /* 162 */ 299 NOSYS, /* 163 */ 300 NOSYS, /* 164 */ 301 NOSYS, /* 165 */ 302 NOSYS, /* 166 */ 303 NOSYS, /* 167 */ 304 NOSYS, /* 168 */ 305 NOSYS, /* 169 */ 306 NOSYS, /* 170 */ 307 NOSYS, /* 171 */ 308 NOSYS, /* 172 */ 309 NOSYS, /* 173 */ 310 NOSYS, /* 174 */ 311 NOSYS, /* 175 */ 312 NOSYS, /* 176 */ 313 NOSYS, /* 177 */ 314 NOSYS, /* 178 */ 315 NOSYS, /* 179 */ 316 NOSYS, /* 180 */ 317 NOSYS, /* 181 */ 318 NOSYS, /* 182 */ 319 NOSYS, /* 183 */ 320 NOSYS, /* 184 */ 321 NOSYS, /* 185 */ 322 NOSYS, /* 186 */ 323 NOSYS, /* 187 */ 324 NOSYS, /* 188 */ 325 NOSYS, /* 189 */ 326 NOSYS, /* 190 */ 327 NOSYS, /* 191 */ 328 NOSYS, /* 192 */ 329 NOSYS, /* 193 */ 330 NOSYS, /* 194 */ 331 NOSYS, /* 195 */ 332 NOSYS, /* 196 */ 333 NOSYS, /* 197 */ 334 NOSYS, /* 198 */ 335 NOSYS, /* 199 */ 336 NOSYS, /* 200 */ 337 NOSYS, /* 201 */ 338 NOSYS, /* 202 */ 339 NOSYS, /* 203 */ 340 NOSYS, /* 204 */ 341 NOSYS, /* 205 */ 342 NOSYS, /* 206 */ 343 NOSYS, /* 207 */ 344 NOSYS, /* 208 */ 345 NOSYS, /* 209 */ 346 NOSYS, /* 210 */ 347 NOSYS, /* 211 */ 348 NOSYS, /* 212 */ 349 NOSYS, /* 213 */ 350 NOSYS, /* 214 */ 351 NOSYS, /* 215 */ 352 NOSYS, /* 216 */ 353 NOSYS, /* 217 */ 354 NOSYS, /* 218 */ 355 NOSYS, /* 219 */ 356 NOSYS, /* 220 */ 357 NOSYS, /* 221 */ 358 NOSYS, /* 222 */ 359 NOSYS, /* 223 */ 360 NOSYS, /* 224 */ 361 NOSYS, /* 225 */ 362 NOSYS, /* 226 */ 363 NOSYS, /* 227 */ 364 NOSYS, /* 228 */ 365 NOSYS, /* 229 */ 366 NOSYS, /* 230 */ 367 NOSYS, /* 231 */ 368 NOSYS, /* 232 */ 369 NOSYS, /* 233 */ 370 NOSYS, /* 234 */ 371 NOSYS, /* 235 */ 372 NOSYS, /* 236 */ 373 NOSYS, /* 237 */ 374 NOSYS, /* 238 */ 375 NOSYS, /* 239 */ 376 NOSYS, /* 240 */ 377 NOSYS, /* 241 */ 378 NOSYS, /* 242 */ 379 NOSYS, /* 243 */ 380 NOSYS, /* 244 */ 381 NOSYS, /* 245 */ 382 NOSYS, /* 246 */ 383 NOSYS, /* 247 */ 384 NOSYS, /* 248 */ 385 NOSYS, /* 249 */ 386 NOSYS, /* 250 */ 387 NOSYS, /* 251 */ 388 NOSYS, /* 252 */ 389 NOSYS, /* 253 */ 390 NOSYS, /* 254 */ 391 NOSYS /* 255 */ 392 }; 393