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 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #include <errno.h> 27 #include <fcntl.h> 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <strings.h> 31 #include <unistd.h> 32 #include <thread.h> 33 #include <sys/auxv.h> 34 #include <sys/bitmap.h> 35 #include <sys/brand.h> 36 #include <sys/inttypes.h> 37 #include <sys/lwp.h> 38 #include <sys/syscall.h> 39 #include <sys/systm.h> 40 #include <sys/utsname.h> 41 #include <sys/systeminfo.h> 42 #include <sys/zone.h> 43 #include <sys/stat.h> 44 #include <sys/mntent.h> 45 #include <sys/ctfs.h> 46 #include <sys/priv.h> 47 #include <sys/acctctl.h> 48 #include <libgen.h> 49 #include <bsm/audit.h> 50 #include <sys/crypto/ioctl.h> 51 #include <sys/fs/zfs.h> 52 #include <sys/zfs_ioctl.h> 53 #include <sys/ucontext.h> 54 #include <sys/mntio.h> 55 #include <sys/mnttab.h> 56 #include <atomic.h> 57 58 #include <s10_brand.h> 59 #include <s10_misc.h> 60 61 /* 62 * Principles of emulation 101. 63 * 64 * 65 * *** Setting errno 66 * 67 * Just don't do it. This emulation library is loaded onto a 68 * seperate link map from the application who's address space we're 69 * running in. We have our own private copy of libc, so there for, 70 * the errno value accessible from here is is also private and changing 71 * it will not affect any errno value that the processes who's address 72 * space we are running in will see. To return an error condition we 73 * should return the negated errno value we'd like the system to return. 74 * For more information about this see the comment in s10_handler(). 75 * Basically, when we return to the caller that initiated the system 76 * call it's their responsibility to set errno. 77 * 78 * 79 * *** Recursion Considerations 80 * 81 * When emulating system calls we need to be very careful about what 82 * library calls we invoke. Library calls should be kept to a minimum. 83 * One issue is that library calls can invoke system calls, so if we're 84 * emulating a system call and we invoke a library call that depends on 85 * that system call we will probably enter a recursive loop, which would 86 * be bad. 87 * 88 * 89 * *** Return Values. 90 * 91 * When declaring new syscall emulation functions, it is very important 92 * to to set the proper RV_* flags in the s10_sysent_table. Upon failure, 93 * syscall emulation fuctions should return an errno value. Upon success 94 * syscall emulation functions should return 0 and set the sysret_t return 95 * value parameters accordingly. 96 * 97 * There are five possible syscall macro wrappers used in the kernel's system 98 * call sysent table. These turn into the following return values: 99 * SYSENT_CL -> SYSENT_C or SYSENT_CI 100 * SYSENT_C SE_64RVAL RV_DEFAULT 101 * SYSENT_CI SE_32RVAL1 RV_DEFAULT 102 * SYSENT_2CI SE_32RVAL1|SE_32RVAL2 RV_32RVAL2 103 * SYSENT_AP SE_64RVAL RV_64RVAL 104 * 105 * 106 * *** Agent lwp considerations 107 * 108 * It is currently impossible to do any emulation for these system call 109 * when they are being invoked on behalf of an agent lwp. To understand why 110 * it's impossible you have to understand how agent lwp syscalls work. 111 * 112 * The agent lwp syscall process works as follows: 113 * 1 The controlling process stops the target. 114 * 2 The controlling process injects an agent lwp which is also stopped. 115 * This agent lwp assumes the userland stack and register values 116 * of another stopped lwp in the current process. 117 * 3 The controlling process configures the agent lwp to start 118 * executing the requested system call. 119 * 4 The controlling process configure /proc to stop the agent lwp when 120 * it enters the requested system call. 121 * 5 The controlling processes allows the agent lwp to start executing. 122 * 6 The agent lwp traps into the kernel to perform the requested system 123 * call and immediately stop. 124 * 7 The controlling process copies all the arguments for the requested 125 * system call onto the agent lwp's stack. 126 * 8 The controlling process configures /proc to stop the agent lwp 127 * when it completes the requested system call. 128 * 9 The controlling processes allows the agent lwp to start executing. 129 * 10 The agent lwp executes the system call and then stop before returning 130 * to userland. 131 * 11 The controlling process copies the return value and return arguments 132 * back from the agent lwps stack. 133 * 12 The controlling process destroys the agent lwp and restarts 134 * the target process. 135 * 136 * The fundamental problem is that when the agent executes the request 137 * system call in step 5, if we're emulating that system call then the 138 * lwp is redirected back to our emulation layer without blocking 139 * in the kernel. But our emulation layer can't access the arguments 140 * for the system call because they haven't been copied to the stack 141 * yet and they still only exist in the controlling processes address 142 * space. This prevents us from being able to do any emulation of 143 * agent lwp system calls. Hence, currently our brand trap interposition 144 * callback (s10_brand_syscall_callback_common) will detect if a system 145 * call is being made by an agent lwp, and if this is the case it will 146 * never redirect the system call to this emulation library. 147 * 148 * In the future, if this proves to be a problem the the easiest solution 149 * would probably be to replace the branded versions of these application 150 * with their native counterparts. Ie, truss, plimit, and pfiles could be 151 * replace with wrapper scripts that execute the native versions of these 152 * applications. In the case of plimit and pfiles this should be pretty 153 * strait forward. Truss would probably be more tricky since it can 154 * execute applications which would be branded applications, so in that 155 * case it might be necessary to create a loadable library which could 156 * be LD_PRELOADed into truss and this library would interpose on the 157 * exec() system call to allow truss to correctly execute branded 158 * processes. It should be pointed out that this solution could work 159 * because "native agent lwps" (ie, agent lwps created by native 160 * processes) can be treated differently from "branded aged lwps" (ie, 161 * agent lwps created by branded processes), since native agent lwps 162 * would presumably be making native system calls and hence not need 163 * any interposition. 164 * 165 */ 166 167 static zoneid_t zoneid; 168 static boolean_t emul_global_zone = B_FALSE; 169 static int emul_vers; 170 pid_t zone_init_pid; 171 172 #define EMULATE(cb, args) { (sysent_cb_t)(cb), (args) } 173 #define NOSYS EMULATE(s10_unimpl, (0 | RV_DEFAULT)) 174 175 typedef long (*sysent_cb_t)(); 176 typedef struct s10_sysent_table { 177 sysent_cb_t st_callc; 178 uintptr_t st_args; 179 } s10_sysent_table_t; 180 s10_sysent_table_t s10_sysent_table[]; 181 182 #define S10_UTS_RELEASE "5.10" 183 #define S10_UTS_VERSION "Generic_Virtual" 184 185 /*LINTED: static unused*/ 186 static volatile int s10_abort_err; 187 /*LINTED: static unused*/ 188 static volatile const char *s10_abort_msg; 189 /*LINTED: static unused*/ 190 static volatile const char *s10_abort_file; 191 /*LINTED: static unused*/ 192 static volatile int s10_abort_line; 193 194 extern int errno; 195 196 /*ARGSUSED*/ 197 void 198 _s10_abort(int err, const char *msg, const char *file, int line) 199 { 200 sysret_t rval; 201 202 /* Save the error message into convenient globals */ 203 s10_abort_err = err; 204 s10_abort_msg = msg; 205 s10_abort_file = file; 206 s10_abort_line = line; 207 208 /* kill ourselves */ 209 abort(); 210 211 /* If abort() didn't work, try something stronger. */ 212 (void) __systemcall(&rval, SYS_lwp_kill + 1024, _lwp_self(), SIGKILL); 213 } 214 215 static int 216 s10_uucopy(const void *from, void *to, size_t size) 217 { 218 sysret_t rval; 219 220 if (__systemcall(&rval, SYS_uucopy + 1024, from, to, size) != 0) 221 return (EFAULT); 222 return (0); 223 } 224 225 /* 226 * ATTENTION: uucopystr() does NOT ensure that string are null terminated! 227 */ 228 static int 229 s10_uucopystr(const void *from, void *to, size_t size) 230 { 231 sysret_t rval; 232 233 if (__systemcall(&rval, SYS_uucopystr + 1024, from, to, size) != 0) 234 return (EFAULT); 235 return (0); 236 } 237 238 /* 239 * Figures out the PID of init for the zone. Also returns a boolean 240 * indicating whether this process currently has that pid: if so, 241 * then at this moment, we are init. 242 */ 243 static boolean_t 244 get_initpid_info(void) 245 { 246 pid_t pid; 247 sysret_t rval; 248 int err; 249 250 /* 251 * Determine the current process PID and the PID of the zone's init. 252 * We use care not to call getpid() here, because we're not supposed 253 * to call getpid() until after the program is fully linked-- the 254 * first call to getpid() is a signal from the linker to debuggers 255 * that linking has been completed. 256 */ 257 if ((err = __systemcall(&rval, SYS_brand, 258 B_S10_PIDINFO, &pid, &zone_init_pid)) != 0) { 259 s10_abort(err, "Failed to get init's pid"); 260 } 261 262 /* 263 * Note that we need to be cautious with the pid we get back-- 264 * it should not be stashed and used in place of getpid(), since 265 * we might fork(2). So we keep zone_init_pid and toss the pid 266 * we otherwise got. 267 */ 268 if (pid == zone_init_pid) 269 return (B_TRUE); 270 271 return (B_FALSE); 272 } 273 274 /* 275 * This function is defined to be NOSYS but it won't be called from the 276 * the kernel since the NOSYS system calls are not enabled in the kernel. 277 * Thus, the only time this function is called is directly from within the 278 * indirect system call path. 279 */ 280 /*ARGSUSED*/ 281 static long 282 s10_unimpl(sysret_t *rv, uintptr_t p1) 283 { 284 sysret_t rval; 285 286 /* 287 * We'd like to print out some kind of error message here like 288 * "unsupported syscall", but we can't because it's not safe to 289 * assume that stderr or STDERR_FILENO actually points to something 290 * that is a terminal, and if we wrote to those files we could 291 * inadvertantly write to some applications open files, which would 292 * be bad. 293 * 294 * Normally, if an application calls an invalid system call 295 * it get a SIGSYS sent to it. So we'll just go ahead and send 296 * ourselves a signal here. Note that this is far from ideal since 297 * if the application has registered a signal handler, that signal 298 * handler may recieve a ucontext_t as the third parameter to 299 * indicate the context of the process when the signal was 300 * generated, and in this case that context will not be what the 301 * application is expecting. Hence, we should probably create a 302 * brandsys() kernel function that can deliver the signal to us 303 * with the correct ucontext_t. 304 */ 305 (void) __systemcall(&rval, SYS_lwp_kill + 1024, _lwp_self(), SIGSYS); 306 return (ENOSYS); 307 } 308 309 #if defined(__sparc) && !defined(__sparcv9) 310 /* 311 * Yuck. For 32-bit sparc applications, handle indirect system calls. 312 * Note that we declare this interface to use the maximum number of 313 * system call arguments. If we recieve a system call that uses less 314 * arguments, then the additional arguments will be garbage, but they 315 * will also be ignored so that should be ok. 316 */ 317 static long 318 s10_indir(sysret_t *rv, int code, 319 uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, 320 uintptr_t a5, uintptr_t a6, uintptr_t a7) 321 { 322 s10_sysent_table_t *sst = &(s10_sysent_table[code]); 323 324 s10_assert(code < NSYSCALL); 325 switch (sst->st_args & NARGS_MASK) { 326 case 0: 327 return ((sst->st_callc)(rv)); 328 case 1: 329 return ((sst->st_callc)(rv, a0)); 330 case 2: 331 return ((sst->st_callc)(rv, a0, a1)); 332 case 3: 333 return ((sst->st_callc)(rv, a0, a1, a2)); 334 case 4: 335 return ((sst->st_callc)(rv, a0, a1, a2, a3)); 336 case 5: 337 return ((sst->st_callc)(rv, a0, a1, a2, a3, a4)); 338 case 6: 339 return ((sst->st_callc)(rv, rv, a0, a1, a2, a3, a4, a5)); 340 case 7: 341 return ((sst->st_callc)(rv, a0, a1, a2, a3, a4, a5, a6)); 342 case 8: 343 return ((sst->st_callc)(rv, a0, a1, a2, a3, a4, a5, a6, a7)); 344 } 345 s10_abort(0, "invalid entry in s10_sysent_table"); 346 return (EINVAL); 347 } 348 #endif /* __sparc && !__sparcv9 */ 349 350 /* Free the thread-local storage provided my mntfs_get_mntentbuf() */ 351 static void 352 mntfs_free_mntentbuf(void *arg) 353 { 354 struct mntentbuf *embufp = arg; 355 356 if (embufp == NULL) 357 return; 358 if (embufp->mbuf_emp) 359 free(embufp->mbuf_emp); 360 if (embufp->mbuf_buf) 361 free(embufp->mbuf_buf); 362 bzero(embufp, sizeof (struct mntentbuf)); 363 free(embufp); 364 } 365 366 /* Provide the thread-local storage required by mntfs_ioctl() */ 367 static struct mntentbuf * 368 mntfs_get_mntentbuf(size_t size) 369 { 370 static mutex_t keylock; 371 static thread_key_t key; 372 static int once_per_keyname = 0; 373 void *tsd = NULL; 374 struct mntentbuf *embufp; 375 376 /* Create the key. */ 377 if (!once_per_keyname) { 378 (void) mutex_lock(&keylock); 379 if (!once_per_keyname) { 380 if (thr_keycreate(&key, mntfs_free_mntentbuf)) { 381 (void) mutex_unlock(&keylock); 382 return (NULL); 383 } else { 384 once_per_keyname++; 385 } 386 } 387 (void) mutex_unlock(&keylock); 388 } 389 390 /* 391 * The thread-specific datum for this key is the address of a struct 392 * mntentbuf. If this is the first time here then we allocate the struct 393 * and its contents, and associate its address with the thread; if there 394 * are any problems then we abort. 395 */ 396 if (thr_getspecific(key, &tsd)) 397 return (NULL); 398 if (tsd == NULL) { 399 if (!(embufp = calloc(1, sizeof (struct mntentbuf))) || 400 !(embufp->mbuf_emp = malloc(sizeof (struct extmnttab))) || 401 thr_setspecific(key, embufp)) { 402 mntfs_free_mntentbuf(embufp); 403 return (NULL); 404 } 405 } else { 406 embufp = tsd; 407 } 408 409 /* Return the buffer, resizing it if necessary. */ 410 if (size > embufp->mbuf_bufsize) { 411 if (embufp->mbuf_buf) 412 free(embufp->mbuf_buf); 413 if ((embufp->mbuf_buf = malloc(size)) == NULL) { 414 embufp->mbuf_bufsize = 0; 415 return (NULL); 416 } else { 417 embufp->mbuf_bufsize = size; 418 } 419 } 420 return (embufp); 421 } 422 423 /* 424 * The MNTIOC_GETMNTENT command in this release differs from that in Solaris 10. 425 * Previously, the command would copy a pointer to a struct extmnttab to an 426 * address provided as an argument. The pointer would be somewhere within a 427 * mapping already present within the user's address space. In addition, the 428 * text to which the struct's members pointed would also be within a 429 * pre-existing mapping. Now, the user is required to allocate memory for both 430 * the struct and the text buffer, and to pass the address of each within a 431 * struct mntentbuf. In order to conceal these details from a Solaris 10 client 432 * we allocate some thread-local storage in which to create the necessary data 433 * structures; this is static, thread-safe memory that will be cleaned up 434 * without the caller's intervention. 435 * 436 * MNTIOC_GETEXTMNTENT and MNTIOC_GETMNTANY are new in this release; they should 437 * not work for older clients. 438 */ 439 int 440 mntfs_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg) 441 { 442 int err; 443 struct stat statbuf; 444 struct mntentbuf *embufp; 445 static size_t bufsize = MNT_LINE_MAX; 446 447 if ((err = __systemcall(rval, SYS_fstat + 1024, fdes, &statbuf)) != 0) 448 return (err); 449 if (strcmp(statbuf.st_fstype, MNTTYPE_MNTFS) != 0) 450 return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg)); 451 452 if (cmd == MNTIOC_GETEXTMNTENT || cmd == MNTIOC_GETMNTANY) 453 return (EINVAL); 454 455 if ((embufp = mntfs_get_mntentbuf(bufsize)) == NULL) 456 return (ENOMEM); 457 458 /* 459 * MNTIOC_GETEXTMNTENT advances the file pointer once it has 460 * successfully copied out the result to the address provided. We 461 * therefore need to check the user-supplied address now since the 462 * one we'll be providing is guaranteed to work. 463 */ 464 if (s10_uucopy(&embufp->mbuf_emp, (void *)arg, sizeof (void *)) != 0) 465 return (EFAULT); 466 467 /* 468 * Keep retrying for as long as we fail for want of a large enough 469 * buffer. 470 */ 471 for (;;) { 472 if ((err = __systemcall(rval, SYS_ioctl + 1024, fdes, 473 MNTIOC_GETEXTMNTENT, embufp)) != 0) 474 return (err); 475 476 if (rval->sys_rval1 == MNTFS_TOOLONG) { 477 /* The buffer wasn't large enough. */ 478 (void) atomic_swap_ulong((unsigned long *)&bufsize, 479 2 * embufp->mbuf_bufsize); 480 if ((embufp = mntfs_get_mntentbuf(bufsize)) == NULL) 481 return (ENOMEM); 482 } else { 483 break; 484 } 485 } 486 487 if (s10_uucopy(&embufp->mbuf_emp, (void *)arg, sizeof (void *)) != 0) 488 return (EFAULT); 489 490 return (0); 491 } 492 493 /* 494 * Assign the structure member value from the s (source) structure to the 495 * d (dest) structure. 496 */ 497 #define struct_assign(d, s, val) (((d).val) = ((s).val)) 498 499 /* 500 * The CRYPTO_GET_FUNCTION_LIST parameter structure crypto_function_list_t 501 * changed between S10 and Nevada, so we have to emulate the old S10 502 * crypto_function_list_t structure when interposing on the ioctl syscall. 503 */ 504 typedef struct s10_crypto_function_list { 505 boolean_t fl_digest_init; 506 boolean_t fl_digest; 507 boolean_t fl_digest_update; 508 boolean_t fl_digest_key; 509 boolean_t fl_digest_final; 510 511 boolean_t fl_encrypt_init; 512 boolean_t fl_encrypt; 513 boolean_t fl_encrypt_update; 514 boolean_t fl_encrypt_final; 515 516 boolean_t fl_decrypt_init; 517 boolean_t fl_decrypt; 518 boolean_t fl_decrypt_update; 519 boolean_t fl_decrypt_final; 520 521 boolean_t fl_mac_init; 522 boolean_t fl_mac; 523 boolean_t fl_mac_update; 524 boolean_t fl_mac_final; 525 526 boolean_t fl_sign_init; 527 boolean_t fl_sign; 528 boolean_t fl_sign_update; 529 boolean_t fl_sign_final; 530 boolean_t fl_sign_recover_init; 531 boolean_t fl_sign_recover; 532 533 boolean_t fl_verify_init; 534 boolean_t fl_verify; 535 boolean_t fl_verify_update; 536 boolean_t fl_verify_final; 537 boolean_t fl_verify_recover_init; 538 boolean_t fl_verify_recover; 539 540 boolean_t fl_digest_encrypt_update; 541 boolean_t fl_decrypt_digest_update; 542 boolean_t fl_sign_encrypt_update; 543 boolean_t fl_decrypt_verify_update; 544 545 boolean_t fl_seed_random; 546 boolean_t fl_generate_random; 547 548 boolean_t fl_session_open; 549 boolean_t fl_session_close; 550 boolean_t fl_session_login; 551 boolean_t fl_session_logout; 552 553 boolean_t fl_object_create; 554 boolean_t fl_object_copy; 555 boolean_t fl_object_destroy; 556 boolean_t fl_object_get_size; 557 boolean_t fl_object_get_attribute_value; 558 boolean_t fl_object_set_attribute_value; 559 boolean_t fl_object_find_init; 560 boolean_t fl_object_find; 561 boolean_t fl_object_find_final; 562 563 boolean_t fl_key_generate; 564 boolean_t fl_key_generate_pair; 565 boolean_t fl_key_wrap; 566 boolean_t fl_key_unwrap; 567 boolean_t fl_key_derive; 568 569 boolean_t fl_init_token; 570 boolean_t fl_init_pin; 571 boolean_t fl_set_pin; 572 573 boolean_t prov_is_limited; 574 uint32_t prov_hash_threshold; 575 uint32_t prov_hash_limit; 576 } s10_crypto_function_list_t; 577 578 typedef struct s10_crypto_get_function_list { 579 uint_t fl_return_value; 580 crypto_provider_id_t fl_provider_id; 581 s10_crypto_function_list_t fl_list; 582 } s10_crypto_get_function_list_t; 583 584 /* 585 * The structure returned by the CRYPTO_GET_FUNCTION_LIST ioctl on /dev/crypto 586 * increased in size due to: 587 * 6482533 Threshold for HW offload via PKCS11 interface 588 * between S10 and Nevada. This is a relatively simple process of filling 589 * in the S10 structure fields with the Nevada data. 590 * 591 * We stat the device to make sure that the ioctl is meant for /dev/crypto. 592 * 593 */ 594 static int 595 crypto_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg) 596 { 597 int err; 598 s10_crypto_get_function_list_t s10_param; 599 crypto_get_function_list_t native_param; 600 static dev_t crypto_dev = (dev_t)-1; 601 struct stat sbuf; 602 603 if (crypto_dev == (dev_t)-1) { 604 if ((err = __systemcall(rval, SYS_stat + 1024, "/dev/crypto", 605 &sbuf)) != 0) 606 goto nonemuioctl; 607 crypto_dev = major(sbuf.st_rdev); 608 } 609 if ((err = __systemcall(rval, SYS_fstat + 1024, fdes, &sbuf)) != 0) 610 return (err); 611 /* Each open fd of /dev/crypto gets a new minor device. */ 612 if (major(sbuf.st_rdev) != crypto_dev) 613 goto nonemuioctl; 614 615 if (s10_uucopy((const void *)arg, &s10_param, sizeof (s10_param)) != 0) 616 return (EFAULT); 617 struct_assign(native_param, s10_param, fl_provider_id); 618 if ((err = __systemcall(rval, SYS_ioctl + 1024, fdes, cmd, 619 &native_param)) != 0) 620 return (err); 621 622 struct_assign(s10_param, native_param, fl_return_value); 623 struct_assign(s10_param, native_param, fl_provider_id); 624 625 struct_assign(s10_param, native_param, fl_list.fl_digest_init); 626 struct_assign(s10_param, native_param, fl_list.fl_digest); 627 struct_assign(s10_param, native_param, fl_list.fl_digest_update); 628 struct_assign(s10_param, native_param, fl_list.fl_digest_key); 629 struct_assign(s10_param, native_param, fl_list.fl_digest_final); 630 631 struct_assign(s10_param, native_param, fl_list.fl_encrypt_init); 632 struct_assign(s10_param, native_param, fl_list.fl_encrypt); 633 struct_assign(s10_param, native_param, fl_list.fl_encrypt_update); 634 struct_assign(s10_param, native_param, fl_list.fl_encrypt_final); 635 636 struct_assign(s10_param, native_param, fl_list.fl_decrypt_init); 637 struct_assign(s10_param, native_param, fl_list.fl_decrypt); 638 struct_assign(s10_param, native_param, fl_list.fl_decrypt_update); 639 struct_assign(s10_param, native_param, fl_list.fl_decrypt_final); 640 641 struct_assign(s10_param, native_param, fl_list.fl_mac_init); 642 struct_assign(s10_param, native_param, fl_list.fl_mac); 643 struct_assign(s10_param, native_param, fl_list.fl_mac_update); 644 struct_assign(s10_param, native_param, fl_list.fl_mac_final); 645 646 struct_assign(s10_param, native_param, fl_list.fl_sign_init); 647 struct_assign(s10_param, native_param, fl_list.fl_sign); 648 struct_assign(s10_param, native_param, fl_list.fl_sign_update); 649 struct_assign(s10_param, native_param, fl_list.fl_sign_final); 650 struct_assign(s10_param, native_param, fl_list.fl_sign_recover_init); 651 struct_assign(s10_param, native_param, fl_list.fl_sign_recover); 652 653 struct_assign(s10_param, native_param, fl_list.fl_verify_init); 654 struct_assign(s10_param, native_param, fl_list.fl_verify); 655 struct_assign(s10_param, native_param, fl_list.fl_verify_update); 656 struct_assign(s10_param, native_param, fl_list.fl_verify_final); 657 struct_assign(s10_param, native_param, fl_list.fl_verify_recover_init); 658 struct_assign(s10_param, native_param, fl_list.fl_verify_recover); 659 660 struct_assign(s10_param, native_param, 661 fl_list.fl_digest_encrypt_update); 662 struct_assign(s10_param, native_param, 663 fl_list.fl_decrypt_digest_update); 664 struct_assign(s10_param, native_param, fl_list.fl_sign_encrypt_update); 665 struct_assign(s10_param, native_param, 666 fl_list.fl_decrypt_verify_update); 667 668 struct_assign(s10_param, native_param, fl_list.fl_seed_random); 669 struct_assign(s10_param, native_param, fl_list.fl_generate_random); 670 671 struct_assign(s10_param, native_param, fl_list.fl_session_open); 672 struct_assign(s10_param, native_param, fl_list.fl_session_close); 673 struct_assign(s10_param, native_param, fl_list.fl_session_login); 674 struct_assign(s10_param, native_param, fl_list.fl_session_logout); 675 676 struct_assign(s10_param, native_param, fl_list.fl_object_create); 677 struct_assign(s10_param, native_param, fl_list.fl_object_copy); 678 struct_assign(s10_param, native_param, fl_list.fl_object_destroy); 679 struct_assign(s10_param, native_param, fl_list.fl_object_get_size); 680 struct_assign(s10_param, native_param, 681 fl_list.fl_object_get_attribute_value); 682 struct_assign(s10_param, native_param, 683 fl_list.fl_object_set_attribute_value); 684 struct_assign(s10_param, native_param, fl_list.fl_object_find_init); 685 struct_assign(s10_param, native_param, fl_list.fl_object_find); 686 struct_assign(s10_param, native_param, fl_list.fl_object_find_final); 687 688 struct_assign(s10_param, native_param, fl_list.fl_key_generate); 689 struct_assign(s10_param, native_param, fl_list.fl_key_generate_pair); 690 struct_assign(s10_param, native_param, fl_list.fl_key_wrap); 691 struct_assign(s10_param, native_param, fl_list.fl_key_unwrap); 692 struct_assign(s10_param, native_param, fl_list.fl_key_derive); 693 694 struct_assign(s10_param, native_param, fl_list.fl_init_token); 695 struct_assign(s10_param, native_param, fl_list.fl_init_pin); 696 struct_assign(s10_param, native_param, fl_list.fl_set_pin); 697 698 struct_assign(s10_param, native_param, fl_list.prov_is_limited); 699 struct_assign(s10_param, native_param, fl_list.prov_hash_threshold); 700 struct_assign(s10_param, native_param, fl_list.prov_hash_limit); 701 702 return (s10_uucopy(&s10_param, (void *)arg, sizeof (s10_param))); 703 704 nonemuioctl: 705 return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg)); 706 } 707 708 /* 709 * The process contract CT_TGET and CT_TSET parameter structure ct_param_t 710 * changed between S10 and Nevada, so we have to emulate the old S10 711 * ct_param_t structure when interposing on the ioctl syscall. 712 */ 713 typedef struct s10_ct_param { 714 uint32_t ctpm_id; 715 uint32_t ctpm_pad; 716 uint64_t ctpm_value; 717 } s10_ct_param_t; 718 719 /* 720 * We have to emulate process contract ioctls for init(1M) because the 721 * ioctl parameter structure changed between S10 and Nevada. This is 722 * a relatively simple process of filling Nevada structure fields, 723 * shuffling values, and initiating a native system call. 724 * 725 * For now, we'll assume that all consumers of CT_TGET and CT_TSET will 726 * need emulation. We'll issue a stat to make sure that the ioctl 727 * is meant for the contract file system. 728 * 729 */ 730 static int 731 ctfs_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg) 732 { 733 int err; 734 s10_ct_param_t s10param; 735 ct_param_t param; 736 struct stat statbuf; 737 738 if ((err = __systemcall(rval, SYS_fstat + 1024, fdes, &statbuf)) != 0) 739 return (err); 740 if (strcmp(statbuf.st_fstype, MNTTYPE_CTFS) != 0) 741 return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg)); 742 743 if (s10_uucopy((const void *)arg, &s10param, sizeof (s10param)) != 0) 744 return (EFAULT); 745 param.ctpm_id = s10param.ctpm_id; 746 param.ctpm_size = sizeof (uint64_t); 747 param.ctpm_value = &s10param.ctpm_value; 748 if ((err = __systemcall(rval, SYS_ioctl + 1024, fdes, cmd, ¶m)) 749 != 0) 750 return (err); 751 752 if (cmd == CT_TGET) 753 return (s10_uucopy(&s10param, (void *)arg, sizeof (s10param))); 754 755 return (0); 756 } 757 758 typedef struct s10_zfs_cmd { 759 char zc_name[MAXPATHLEN]; 760 char zc_value[MAXPATHLEN * 2]; 761 char zc_string[MAXNAMELEN]; 762 uint64_t zc_guid; 763 uint64_t zc_nvlist_conf; /* really (char *) */ 764 uint64_t zc_nvlist_conf_size; 765 uint64_t zc_nvlist_src; /* really (char *) */ 766 uint64_t zc_nvlist_src_size; 767 uint64_t zc_nvlist_dst; /* really (char *) */ 768 uint64_t zc_nvlist_dst_size; 769 uint64_t zc_cookie; 770 uint64_t zc_objset_type; 771 uint64_t zc_perm_action; 772 uint64_t zc_history; /* really (char *) */ 773 uint64_t zc_history_len; 774 uint64_t zc_history_offset; 775 uint64_t zc_obj; 776 /* Solaris Next added zc_iflags member here */ 777 zfs_share_t zc_share; 778 dmu_objset_stats_t zc_objset_stats; 779 struct drr_begin zc_begin_record; 780 zinject_record_t zc_inject_record; 781 } s10_zfs_cmd_t; 782 783 /* 784 * There is a difference in the zfs_cmd_t ioctl parameter between S10 and 785 * Solaris Next so we need to translate between the two structures when 786 * making ZFS ioctls. 787 */ 788 static int 789 zfs_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg) 790 { 791 int err; 792 s10_zfs_cmd_t s10_param; 793 zfs_cmd_t native_param; 794 static dev_t zfs_dev = (dev_t)-1; 795 struct stat sbuf; 796 797 if (zfs_dev == (dev_t)-1) { 798 if ((err = __systemcall(rval, SYS_stat + 1024, "/dev/zfs", 799 &sbuf)) != 0) 800 goto nonemuioctl; 801 zfs_dev = major(sbuf.st_rdev); 802 } 803 if ((err = __systemcall(rval, SYS_fstat + 1024, fdes, &sbuf)) != 0) 804 return (err); 805 if (major(sbuf.st_rdev) != zfs_dev) 806 goto nonemuioctl; 807 808 if (s10_uucopy((const void *)arg, &s10_param, sizeof (s10_param)) != 0) 809 return (EFAULT); 810 811 bcopy((const void *)s10_param.zc_name, (void *)native_param.zc_name, 812 sizeof (s10_param.zc_name)); 813 bcopy((const void *)s10_param.zc_value, (void *)native_param.zc_value, 814 sizeof (s10_param.zc_value)); 815 bcopy((const void *)s10_param.zc_string, (void *)native_param.zc_string, 816 sizeof (s10_param.zc_string)); 817 struct_assign(native_param, s10_param, zc_guid); 818 struct_assign(native_param, s10_param, zc_nvlist_conf); 819 struct_assign(native_param, s10_param, zc_nvlist_conf_size); 820 struct_assign(native_param, s10_param, zc_nvlist_src); 821 struct_assign(native_param, s10_param, zc_nvlist_src_size); 822 struct_assign(native_param, s10_param, zc_nvlist_dst); 823 struct_assign(native_param, s10_param, zc_nvlist_dst_size); 824 struct_assign(native_param, s10_param, zc_cookie); 825 struct_assign(native_param, s10_param, zc_objset_type); 826 struct_assign(native_param, s10_param, zc_perm_action); 827 struct_assign(native_param, s10_param, zc_history); 828 struct_assign(native_param, s10_param, zc_history_len); 829 struct_assign(native_param, s10_param, zc_history_offset); 830 struct_assign(native_param, s10_param, zc_obj); 831 native_param.zc_iflags = 0; 832 struct_assign(native_param, s10_param, zc_share); 833 struct_assign(native_param, s10_param, zc_objset_stats); 834 struct_assign(native_param, s10_param, zc_begin_record); 835 struct_assign(native_param, s10_param, zc_inject_record); 836 837 err = __systemcall(rval, SYS_ioctl + 1024, fdes, cmd, &native_param); 838 839 bcopy((const void *)native_param.zc_name, (void *)s10_param.zc_name, 840 sizeof (s10_param.zc_name)); 841 bcopy((const void *)native_param.zc_value, (void *)s10_param.zc_value, 842 sizeof (s10_param.zc_value)); 843 bcopy((const void *)native_param.zc_string, (void *)s10_param.zc_string, 844 sizeof (s10_param.zc_string)); 845 struct_assign(s10_param, native_param, zc_guid); 846 struct_assign(s10_param, native_param, zc_nvlist_conf); 847 struct_assign(s10_param, native_param, zc_nvlist_conf_size); 848 struct_assign(s10_param, native_param, zc_nvlist_src); 849 struct_assign(s10_param, native_param, zc_nvlist_src_size); 850 struct_assign(s10_param, native_param, zc_nvlist_dst); 851 struct_assign(s10_param, native_param, zc_nvlist_dst_size); 852 struct_assign(s10_param, native_param, zc_cookie); 853 struct_assign(s10_param, native_param, zc_objset_type); 854 struct_assign(s10_param, native_param, zc_perm_action); 855 struct_assign(s10_param, native_param, zc_history); 856 struct_assign(s10_param, native_param, zc_history_len); 857 struct_assign(s10_param, native_param, zc_history_offset); 858 struct_assign(s10_param, native_param, zc_obj); 859 struct_assign(s10_param, native_param, zc_share); 860 struct_assign(s10_param, native_param, zc_objset_stats); 861 struct_assign(s10_param, native_param, zc_begin_record); 862 struct_assign(s10_param, native_param, zc_inject_record); 863 864 (void) s10_uucopy(&s10_param, (void *)arg, sizeof (s10_param)); 865 return (err); 866 867 nonemuioctl: 868 return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg)); 869 } 870 871 int 872 s10_ioctl(sysret_t *rval, int fdes, int cmd, intptr_t arg) 873 { 874 switch (cmd) { 875 case CRYPTO_GET_FUNCTION_LIST: 876 return (crypto_ioctl(rval, fdes, cmd, arg)); 877 case CT_TGET: 878 /*FALLTHRU*/ 879 case CT_TSET: 880 return (ctfs_ioctl(rval, fdes, cmd, arg)); 881 case MNTIOC_GETMNTENT: 882 /*FALLTHRU*/ 883 case MNTIOC_GETEXTMNTENT: 884 /*FALLTHRU*/ 885 case MNTIOC_GETMNTANY: 886 return (mntfs_ioctl(rval, fdes, cmd, arg)); 887 } 888 889 if ((cmd & 0xff00) == ZFS_IOC) 890 return (zfs_ioctl(rval, fdes, cmd, arg)); 891 892 return (__systemcall(rval, SYS_ioctl + 1024, fdes, cmd, arg)); 893 } 894 895 /* 896 * Unfortunately, pwrite()'s behavior differs between S10 and Nevada when 897 * applied to files opened with O_APPEND. The offset argument is ignored and 898 * the buffer is appended to the target file in S10, whereas the current file 899 * position is ignored in Nevada (i.e., pwrite() acts as though the target file 900 * wasn't opened with O_APPEND). This is a result of the fix for CR 6655660 901 * (pwrite() must ignore the O_APPEND/FAPPEND flag). 902 * 903 * We emulate the old S10 pwrite() behavior by checking whether the target file 904 * was opened with O_APPEND. If it was, then invoke the write() system call 905 * instead of pwrite(); otherwise, invoke the pwrite() system call as usual. 906 */ 907 static int 908 s10_pwrite(sysret_t *rval, int fd, const void *bufferp, size_t num_bytes, 909 off_t offset) 910 { 911 int err; 912 913 if ((err = __systemcall(rval, SYS_fcntl + 1024, fd, F_GETFL)) != 0) 914 return (err); 915 if (rval->sys_rval1 & O_APPEND) 916 return (__systemcall(rval, SYS_write + 1024, fd, bufferp, 917 num_bytes)); 918 return (__systemcall(rval, SYS_pwrite + 1024, fd, bufferp, num_bytes, 919 offset)); 920 } 921 922 #ifndef _LP64 923 /* 924 * This is the large file version of the pwrite() system call for 32-bit 925 * processes. This exists for the same reason that s10_pwrite() exists; see 926 * the comment above s10_pwrite(). 927 */ 928 static int 929 s10_pwrite64(sysret_t *rval, int fd, const void *bufferp, size32_t num_bytes, 930 uint32_t offset_1, uint32_t offset_2) 931 { 932 int err; 933 934 if ((err = __systemcall(rval, SYS_fcntl + 1024, fd, F_GETFL)) != 0) 935 return (err); 936 if (rval->sys_rval1 & O_APPEND) 937 return (__systemcall(rval, SYS_write + 1024, fd, bufferp, 938 num_bytes)); 939 return (__systemcall(rval, SYS_pwrite64 + 1024, fd, bufferp, 940 num_bytes, offset_1, offset_2)); 941 } 942 #endif /* !_LP64 */ 943 944 #define S10_AC_PROC (0x1 << 28) 945 #define S10_AC_TASK (0x2 << 28) 946 #define S10_AC_FLOW (0x4 << 28) 947 #define S10_AC_MODE(x) ((x) & 0xf0000000) 948 #define S10_AC_OPTION(x) ((x) & 0x0fffffff) 949 950 /* 951 * The mode shift, mode mask and option mask for acctctl have changed. The 952 * mode is currently the top full byte and the option is the lower 3 full bytes. 953 */ 954 int 955 s10_acctctl(sysret_t *rval, int cmd, void *buf, size_t bufsz) 956 { 957 int mode = S10_AC_MODE(cmd); 958 int option = S10_AC_OPTION(cmd); 959 960 switch (mode) { 961 case S10_AC_PROC: 962 mode = AC_PROC; 963 break; 964 case S10_AC_TASK: 965 mode = AC_TASK; 966 break; 967 case S10_AC_FLOW: 968 mode = AC_FLOW; 969 break; 970 default: 971 return (S10_TRUSS_POINT_3(rval, SYS_acctctl, EINVAL, cmd, buf, 972 bufsz)); 973 } 974 975 return (__systemcall(rval, SYS_acctctl + 1024, mode | option, buf, 976 bufsz)); 977 } 978 979 /* 980 * The Audit Policy parameters have changed due to: 981 * 6466722 audituser and AUDIT_USER are defined, unused, undocumented and 982 * should be removed. 983 * 984 * In S10 we had the following flag: 985 * #define AUDIT_USER 0x0040 986 * which doesn't exist in Solaris Next where the subsequent flags are shifted 987 * down. For example, in S10 we had: 988 * #define AUDIT_GROUP 0x0080 989 * but on Solaris Next we have: 990 * #define AUDIT_GROUP 0x0040 991 * AUDIT_GROUP has the value AUDIT_USER had in S10 and all of the subsequent 992 * bits are also shifted one place. 993 * 994 * When we're getting or setting the Audit Policy parameters we need to 995 * shift the outgoing or incoming bits into their proper positions. Since 996 * S10_AUDIT_USER was always unused, we always clear that bit on A_GETPOLICY. 997 * 998 * The command we care about, BSM_AUDITCTL, passes the most parameters (3), 999 * so declare this function to take up to 4 args and just pass them on. 1000 * The number of parameters for s10_auditsys needs to be equal to the BSM_* 1001 * subcommand that has the most parameters, since we want to pass all 1002 * parameters through, regardless of which subcommands we interpose on. 1003 * 1004 * Note that the auditsys system call uses the SYSENT_AP macro wrapper instead 1005 * of the more common SYSENT_CI macro. This means the return value is a 1006 * SE_64RVAL so the syscall table uses RV_64RVAL. 1007 */ 1008 1009 #define S10_AUDIT_HMASK 0xffffffc0 1010 #define S10_AUDIT_LMASK 0x3f 1011 1012 int 1013 s10_auditsys(sysret_t *rval, int bsmcmd, intptr_t a0, intptr_t a1, intptr_t a2) 1014 { 1015 int err; 1016 uint_t m; 1017 1018 if (bsmcmd != BSM_AUDITCTL) 1019 return (__systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, a1, 1020 a2)); 1021 1022 if ((int)a0 == A_GETPOLICY) { 1023 if ((err = __systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, 1024 &m, a2)) != 0) 1025 return (err); 1026 m = ((m & S10_AUDIT_HMASK) << 1) | (m & S10_AUDIT_LMASK); 1027 if (s10_uucopy(&m, (void *)a1, sizeof (m)) != 0) 1028 return (EFAULT); 1029 return (0); 1030 1031 } else if ((int)a0 == A_SETPOLICY) { 1032 if (s10_uucopy((const void *)a1, &m, sizeof (m)) != 0) 1033 return (EFAULT); 1034 m = ((m >> 1) & S10_AUDIT_HMASK) | (m & S10_AUDIT_LMASK); 1035 return (__systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, &m, 1036 a2)); 1037 } 1038 1039 return (__systemcall(rval, SYS_auditsys + 1024, bsmcmd, a0, a1, a2)); 1040 } 1041 1042 /* 1043 * Determine whether the executable passed to SYS_exec or SYS_execve is a 1044 * native executable. The s10_npreload.so invokes the B_S10_NATIVE brand 1045 * operation which patches up the processes exec info to eliminate any trace 1046 * of the wrapper. That will make pgrep and other commands that examine 1047 * process' executable names and command-line parameters work properly. 1048 */ 1049 static int 1050 s10_exec_native(sysret_t *rval, const char *fname, const char **argp, 1051 const char **envp) 1052 { 1053 const char *filename = fname; 1054 char path[64]; 1055 int err; 1056 1057 /* Get a copy of the executable we're trying to run */ 1058 path[0] = '\0'; 1059 (void) s10_uucopystr(filename, path, sizeof (path)); 1060 1061 /* Check if we're trying to run a native binary */ 1062 if (strncmp(path, "/.SUNWnative/usr/lib/brand/solaris10/s10_native", 1063 sizeof (path)) != 0) 1064 return (0); 1065 1066 /* Skip the first element in the argv array */ 1067 argp++; 1068 1069 /* 1070 * The the path of the dynamic linker is the second parameter 1071 * of s10_native_exec(). 1072 */ 1073 if (s10_uucopy(argp, &filename, sizeof (char *)) != 0) 1074 return (EFAULT); 1075 1076 /* If an exec call succeeds, it never returns */ 1077 err = __systemcall(rval, SYS_brand + 1024, B_EXEC_NATIVE, filename, 1078 argp, envp, NULL, NULL, NULL); 1079 s10_assert(err != 0); 1080 return (err); 1081 } 1082 1083 /* 1084 * Interpose on the SYS_exec syscall to detect native wrappers. 1085 */ 1086 int 1087 s10_exec(sysret_t *rval, const char *fname, const char **argp) 1088 { 1089 int err; 1090 1091 if ((err = s10_exec_native(rval, fname, argp, NULL)) != 0) 1092 return (err); 1093 1094 /* If an exec call succeeds, it never returns */ 1095 err = __systemcall(rval, SYS_exec + 1024, fname, argp); 1096 s10_assert(err != 0); 1097 return (err); 1098 } 1099 1100 /* 1101 * Interpose on the SYS_execve syscall to detect native wrappers. 1102 */ 1103 int 1104 s10_execve(sysret_t *rval, const char *fname, const char **argp, 1105 const char **envp) 1106 { 1107 int err; 1108 1109 if ((err = s10_exec_native(rval, fname, argp, envp)) != 0) 1110 return (err); 1111 1112 /* If an exec call succeeds, it never returns */ 1113 err = __systemcall(rval, SYS_execve + 1024, fname, argp, envp); 1114 s10_assert(err != 0); 1115 return (err); 1116 } 1117 1118 /* 1119 * S10's issetugid() syscall is now a subcode to privsys(). 1120 */ 1121 static int 1122 s10_issetugid(sysret_t *rval) 1123 { 1124 return (__systemcall(rval, SYS_privsys + 1024, PRIVSYS_ISSETUGID, 1125 0, 0, 0, 0, 0)); 1126 } 1127 1128 /* 1129 * New last arg "block" flag should be zero. The block flag is used by 1130 * the Opensolaris AIO implementation, which is now part of libc. 1131 */ 1132 static int 1133 s10_sigqueue(sysret_t *rval, pid_t pid, int signo, void *value, int si_code) 1134 { 1135 return (__systemcall(rval, SYS_sigqueue + 1024, pid, signo, value, 1136 si_code, 0)); 1137 } 1138 1139 static long 1140 s10_uname(sysret_t *rv, uintptr_t p1) 1141 { 1142 struct utsname un, *unp = (struct utsname *)p1; 1143 int rev, err; 1144 1145 if ((err = __systemcall(rv, SYS_uname + 1024, &un)) != 0) 1146 return (err); 1147 1148 rev = atoi(&un.release[2]); 1149 s10_assert(rev >= 11); 1150 bzero(un.release, _SYS_NMLN); 1151 (void) strlcpy(un.release, S10_UTS_RELEASE, _SYS_NMLN); 1152 bzero(un.version, _SYS_NMLN); 1153 (void) strlcpy(un.version, S10_UTS_VERSION, _SYS_NMLN); 1154 1155 /* copy out the modified uname info */ 1156 return (s10_uucopy(&un, unp, sizeof (un))); 1157 } 1158 1159 int 1160 s10_sysinfo(sysret_t *rv, int command, char *buf, long count) 1161 { 1162 char *value; 1163 int len; 1164 1165 /* 1166 * We must interpose on the sysinfo(2) commands SI_RELEASE and 1167 * SI_VERSION; all others get passed to the native sysinfo(2) 1168 * command. 1169 */ 1170 switch (command) { 1171 case SI_RELEASE: 1172 value = S10_UTS_RELEASE; 1173 break; 1174 1175 case SI_VERSION: 1176 value = S10_UTS_VERSION; 1177 break; 1178 1179 default: 1180 /* 1181 * The default action is to pass the command to the 1182 * native sysinfo(2) syscall. 1183 */ 1184 return (__systemcall(rv, SYS_systeminfo + 1024, 1185 command, buf, count)); 1186 } 1187 1188 len = strlen(value) + 1; 1189 if (count > 0) { 1190 if (s10_uucopystr(value, buf, count) != 0) 1191 return (EFAULT); 1192 1193 /* Assure NULL termination of buf as s10_uucopystr() doesn't. */ 1194 if (len > count && s10_uucopy("\0", buf + (count - 1), 1) != 0) 1195 return (EFAULT); 1196 } 1197 1198 /* 1199 * On success, sysinfo(2) returns the size of buffer required to hold 1200 * the complete value plus its terminating NULL byte. 1201 */ 1202 (void) S10_TRUSS_POINT_3(rv, SYS_systeminfo, 0, command, buf, count); 1203 rv->sys_rval1 = len; 1204 rv->sys_rval2 = 0; 1205 return (0); 1206 } 1207 1208 #ifdef __x86 1209 #ifdef __amd64 1210 /* 1211 * 64-bit x86 LWPs created by SYS_lwp_create start here if they need to set 1212 * their %fs registers to the legacy Solaris 10 selector value. 1213 * 1214 * This function does three things: 1215 * 1216 * 1. Trap to the kernel so that it can set %fs to the legacy Solaris 10 1217 * selector value. 1218 * 2. Read the LWP's true entry point (the entry point supplied by libc 1219 * when SYS_lwp_create was invoked) from %r14. 1220 * 3. Eliminate this function's stack frame and pass control to the LWP's 1221 * true entry point. 1222 * 1223 * See the comment above s10_lwp_create_correct_fs() (see below) for the reason 1224 * why this function exists. 1225 */ 1226 /*ARGSUSED*/ 1227 static void 1228 s10_lwp_create_entry_point(void *ulwp_structp) 1229 { 1230 sysret_t rval; 1231 1232 /* 1233 * The new LWP's %fs register is initially zero, but libc won't 1234 * function correctly when %fs is zero. Change the LWP's %fs register 1235 * via SYS_brand. 1236 */ 1237 (void) __systemcall(&rval, SYS_brand + 1024, B_S10_FSREGCORRECTION); 1238 1239 /* 1240 * Jump to the true entry point, which is stored in %r14. 1241 * Remove our stack frame before jumping so that 1242 * s10_lwp_create_entry_point() won't be seen in stack traces. 1243 * 1244 * NOTE: s10_lwp_create_entry_point() pushes %r12 onto its stack frame 1245 * so that it can use it as a temporary register. We don't restore %r12 1246 * in this assembly block because we don't care about its value (and 1247 * neither does _lwp_start()). Besides, the System V ABI AMD64 1248 * Actirecture Processor Supplement doesn't specify that %r12 should 1249 * have a special value when LWPs start, so we can ignore its value when 1250 * we jump to the true entry point. Furthermore, %r12 is a callee-saved 1251 * register, so the true entry point should push %r12 onto its stack 1252 * before using the register. We ignore %r14 after we read it for 1253 * similar reasons. 1254 * 1255 * NOTE: The compiler will generate a function epilogue for this 1256 * function despite the fact that the LWP will never execute it. 1257 * We could hand-code this entire function in assembly to eliminate 1258 * the epilogue, but the epilogue is only three or four instructions, 1259 * so we wouldn't save much space. Besides, why would we want 1260 * to create yet another ugly, hard-to-maintain assembly function when 1261 * we could write most of it in C? 1262 */ 1263 __asm__ __volatile__( 1264 "movq %0, %%rdi\n\t" /* pass ulwp_structp as arg1 */ 1265 "movq %%rbp, %%rsp\n\t" /* eliminate the stack frame */ 1266 "popq %%rbp\n\t" 1267 "jmp *%%r14\n\t" /* jump to the true entry point */ 1268 : : "r" (ulwp_structp)); 1269 /*NOTREACHED*/ 1270 } 1271 1272 /* 1273 * The S10 libc expects that %fs will be nonzero for new 64-bit x86 LWPs but the 1274 * Nevada kernel clears %fs for such LWPs. Unforunately, new LWPs do not issue 1275 * SYS_lwp_private (see s10_lwp_private() below) after they are created, so 1276 * we must ensure that new LWPs invoke a brand operation that sets %fs to a 1277 * nonzero value immediately after their creation. 1278 * 1279 * The easiest way to do this is to make new LWPs start at a special function, 1280 * s10_lwp_create_entry_point() (see its definition above), that invokes the 1281 * brand operation that corrects %fs. We'll store the entry points of new LWPs 1282 * in their %r14 registers so that s10_lwp_create_entry_point() can find and 1283 * call them after invoking the special brand operation. %r14 is a callee-saved 1284 * register; therefore, any functions invoked by s10_lwp_create_entry_point() 1285 * and all functions dealing with signals (e.g., sigacthandler()) will preserve 1286 * %r14 for s10_lwp_create_entry_point(). 1287 * 1288 * The Nevada kernel can safely work with nonzero %fs values because the kernel 1289 * configures per-thread %fs segment descriptors so that the legacy %fs selector 1290 * value will still work. See the comment in lwp_load() regarding %fs and 1291 * %fsbase in 64-bit x86 processes. 1292 * 1293 * This emulation exists thanks to CRs 6467491 and 6501650. 1294 */ 1295 static int 1296 s10_lwp_create_correct_fs(sysret_t *rval, ucontext_t *ucp, int flags, 1297 id_t *new_lwp) 1298 { 1299 ucontext_t s10_uc; 1300 1301 /* 1302 * Copy the supplied ucontext_t structure to the local stack 1303 * frame and store the new LWP's entry point (the value of %rip 1304 * stored in the ucontext_t) in the new LWP's %r14 register. 1305 * Then make s10_lwp_create_entry_point() the new LWP's entry 1306 * point. 1307 */ 1308 if (s10_uucopy(ucp, &s10_uc, sizeof (s10_uc)) != 0) 1309 return (EFAULT); 1310 s10_uc.uc_mcontext.gregs[REG_R14] = s10_uc.uc_mcontext.gregs[REG_RIP]; 1311 s10_uc.uc_mcontext.gregs[REG_RIP] = (greg_t)s10_lwp_create_entry_point; 1312 1313 /* 1314 * Issue SYS_lwp_create to create the new LWP. We pass the 1315 * modified ucontext_t to make sure that the new LWP starts at 1316 * s10_lwp_create_entry_point(). 1317 */ 1318 return (__systemcall(rval, SYS_lwp_create + 1024, &s10_uc, 1319 flags, new_lwp)); 1320 } 1321 #endif /* __amd64 */ 1322 1323 /* 1324 * This function is invoked on x86 systems when SYS_lwp_create is issued but no 1325 * %fs register correction is necessary. 1326 * 1327 * See the comment above s10_lwp_create_correct_fs() above for more details. 1328 */ 1329 static int 1330 s10_lwp_create(sysret_t *rval, ucontext_t *ucp, int flags, id_t *new_lwp) 1331 { 1332 return (__systemcall(rval, SYS_lwp_create + 1024, ucp, flags, new_lwp)); 1333 } 1334 1335 /* 1336 * SYS_lwp_private is issued by libc_init() to set %fsbase in 64-bit x86 1337 * processes. The Nevada kernel sets %fs to zero but the S10 libc expects 1338 * %fs to be nonzero. We'll pass the issued system call to the kernel untouched 1339 * and invoke a brand operation to set %fs to the legacy S10 selector value. 1340 * 1341 * This emulation exists thanks to CRs 6467491 and 6501650. 1342 */ 1343 static int 1344 s10_lwp_private(sysret_t *rval, int cmd, int which, uintptr_t base) 1345 { 1346 #ifdef __amd64 1347 int err; 1348 1349 /* 1350 * The current LWP's %fs register should be zero. Determine whether the 1351 * Solaris 10 libc with which we're working functions correctly when %fs 1352 * is zero by calling thr_main() after issuing the SYS_lwp_private 1353 * syscall. If thr_main() barfs (returns -1), then change the LWP's %fs 1354 * register via SYS_brand and patch s10_sysent_table so that issuing 1355 * SYS_lwp_create executes s10_lwp_create_correct_fs() rather than the 1356 * default s10_lwp_create(). s10_lwp_create_correct_fs() will 1357 * guarantee that new LWPs will have correct %fs values. 1358 */ 1359 if ((err = __systemcall(rval, SYS_lwp_private + 1024, cmd, which, 1360 base)) != 0) 1361 return (err); 1362 if (thr_main() == -1) { 1363 /* 1364 * SYS_lwp_private is only issued by libc_init(), which is 1365 * executed when libc is first loaded by ld.so.1. Thus we 1366 * are guaranteed to be single-threaded at this point. Even 1367 * if we were multithreaded at this point, writing a 64-bit 1368 * value to the st_callc field of a s10_sysent_table 1369 * entry is guaranteed to be atomic on 64-bit x86 chips 1370 * as long as the field is not split across cache lines 1371 * (It shouldn't be.). See chapter 8, section 1.1 of 1372 * "The Intel 64 and IA32 Architectures Software Developer's 1373 * Manual," Volume 3A for more details. 1374 */ 1375 s10_sysent_table[SYS_lwp_create].st_callc = 1376 (sysent_cb_t)s10_lwp_create_correct_fs; 1377 return (__systemcall(rval, SYS_brand + 1024, 1378 B_S10_FSREGCORRECTION)); 1379 } 1380 return (0); 1381 #else /* !__amd64 */ 1382 return (__systemcall(rval, SYS_lwp_private + 1024, cmd, which, base)); 1383 #endif /* !__amd64 */ 1384 } 1385 #endif /* __x86 */ 1386 1387 /* 1388 * The Opensolaris versions of lwp_mutex_timedlock() and lwp_mutex_trylock() 1389 * add an extra argument to the interfaces, a uintptr_t value for the mutex's 1390 * mutex_owner field. The Solaris 10 libc assigns the mutex_owner field at 1391 * user-level, so we just make the extra argument be zero in both syscalls. 1392 */ 1393 1394 static int 1395 s10_lwp_mutex_timedlock(sysret_t *rval, lwp_mutex_t *lp, timespec_t *tsp) 1396 { 1397 return (__systemcall(rval, SYS_lwp_mutex_timedlock + 1024, lp, tsp, 0)); 1398 } 1399 1400 static int 1401 s10_lwp_mutex_trylock(sysret_t *rval, lwp_mutex_t *lp) 1402 { 1403 return (__systemcall(rval, SYS_lwp_mutex_trylock + 1024, lp, 0)); 1404 } 1405 1406 /* 1407 * If the emul_global_zone flag is set then emulate some aspects of the 1408 * zone system call. In particular, emulate the global zone ID on the 1409 * ZONE_LOOKUP subcommand and emulate some of the global zone attributes 1410 * on the ZONE_GETATTR subcommand. If the flag is not set or we're performing 1411 * some other operation, simply pass the calls through. 1412 */ 1413 int 1414 s10_zone(sysret_t *rval, int cmd, void *arg1, void *arg2, void *arg3, 1415 void *arg4) 1416 { 1417 char *aval; 1418 int len; 1419 zoneid_t zid; 1420 int attr; 1421 char *buf; 1422 size_t bufsize; 1423 1424 /* 1425 * We only emulate the zone syscall for a subset of specific commands, 1426 * otherwise we just pass the call through. 1427 */ 1428 if (!emul_global_zone) 1429 return (__systemcall(rval, SYS_zone + 1024, cmd, arg1, arg2, 1430 arg3, arg4)); 1431 1432 switch (cmd) { 1433 case ZONE_LOOKUP: 1434 (void) S10_TRUSS_POINT_1(rval, SYS_zone, 0, cmd); 1435 rval->sys_rval1 = GLOBAL_ZONEID; 1436 rval->sys_rval2 = 0; 1437 return (0); 1438 1439 case ZONE_GETATTR: 1440 zid = (zoneid_t)(uintptr_t)arg1; 1441 attr = (int)(uintptr_t)arg2; 1442 buf = (char *)arg3; 1443 bufsize = (size_t)arg4; 1444 1445 /* 1446 * If the request is for the global zone then we're emulating 1447 * that, otherwise pass this thru. 1448 */ 1449 if (zid != GLOBAL_ZONEID) 1450 goto passthru; 1451 1452 switch (attr) { 1453 case ZONE_ATTR_NAME: 1454 aval = GLOBAL_ZONENAME; 1455 break; 1456 1457 case ZONE_ATTR_BRAND: 1458 aval = NATIVE_BRAND_NAME; 1459 break; 1460 default: 1461 /* 1462 * We only emulate a subset of the attrs, use the 1463 * real zone id to pass thru the rest. 1464 */ 1465 arg1 = (void *)(uintptr_t)zoneid; 1466 goto passthru; 1467 } 1468 1469 (void) S10_TRUSS_POINT_5(rval, SYS_zone, 0, cmd, zid, attr, 1470 buf, bufsize); 1471 1472 len = strlen(aval) + 1; 1473 if (len > bufsize) 1474 return (ENAMETOOLONG); 1475 1476 if (buf != NULL) { 1477 if (len == 1) { 1478 if (s10_uucopy("\0", buf, 1) != 0) 1479 return (EFAULT); 1480 } else { 1481 if (s10_uucopystr(aval, buf, len) != 0) 1482 return (EFAULT); 1483 1484 /* 1485 * Assure NULL termination of "buf" as 1486 * s10_uucopystr() does NOT. 1487 */ 1488 if (s10_uucopy("\0", buf + (len - 1), 1) != 0) 1489 return (EFAULT); 1490 } 1491 } 1492 1493 rval->sys_rval1 = len; 1494 rval->sys_rval2 = 0; 1495 return (0); 1496 1497 default: 1498 break; 1499 } 1500 1501 passthru: 1502 return (__systemcall(rval, SYS_zone + 1024, cmd, arg1, arg2, arg3, 1503 arg4)); 1504 } 1505 1506 /* 1507 * Close a libc file handle, but don't actually close the underlying 1508 * file descriptor. 1509 */ 1510 static void 1511 s10_close_fh(FILE *file) 1512 { 1513 int fd, fd_new; 1514 1515 if (file == NULL) 1516 return; 1517 1518 if ((fd = fileno(file)) < 0) 1519 return; 1520 1521 fd_new = dup(fd); 1522 if (fd_new == -1) 1523 return; 1524 1525 (void) fclose(file); 1526 (void) dup2(fd_new, fd); 1527 (void) close(fd_new); 1528 } 1529 1530 /*ARGSUSED*/ 1531 int 1532 s10_init(int argc, char *argv[], char *envp[]) 1533 { 1534 sysret_t rval; 1535 s10_brand_reg_t reg; 1536 s10_elf_data_t sed; 1537 auxv_t *ap; 1538 uintptr_t *p; 1539 int i, err; 1540 char *bname; 1541 1542 /* Sanity check our translation table return value codes */ 1543 for (i = 0; i < NSYSCALL; i++) { 1544 s10_sysent_table_t *est = &(s10_sysent_table[i]); 1545 s10_assert(BIT_ONLYONESET(est->st_args & RV_MASK)); 1546 } 1547 1548 /* 1549 * We need to shutdown all libc stdio. libc stdio normally goes to 1550 * file descriptors, but since we're actually part of a another 1551 * process we don't own these file descriptors and we can't make 1552 * any assumptions about their state. 1553 */ 1554 s10_close_fh(stdin); 1555 s10_close_fh(stdout); 1556 s10_close_fh(stderr); 1557 1558 /* 1559 * Cache the pid of the zone's init process and determine if 1560 * we're init(1m) for the zone. Remember: we might be init 1561 * now, but as soon as we fork(2) we won't be. 1562 */ 1563 (void) get_initpid_info(); 1564 1565 /* get the current zoneid */ 1566 err = __systemcall(&rval, SYS_zone, ZONE_LOOKUP, NULL); 1567 s10_assert(err == 0); 1568 zoneid = (zoneid_t)rval.sys_rval1; 1569 1570 /* Get the emulation version number. */ 1571 if ((err = __systemcall(&rval, SYS_zone, ZONE_GETATTR, zoneid, 1572 S10_EMUL_VERSION_NUM, &emul_vers, sizeof (emul_vers))) != 0 || 1573 emul_vers != 0) { 1574 s10_abort(err, "The zone's patch level is unsupported"); 1575 /*NOTREACHED*/ 1576 } 1577 1578 bname = basename(argv[0]); 1579 1580 /* 1581 * In general we want the S10 commands that are zone-aware to continue 1582 * to behave as they normally do within a zone. Since these commands 1583 * are zone-aware, they should continue to "do the right thing". 1584 * However, some zone-aware commands aren't going to work the way 1585 * we expect them to inside the branded zone. In particular, the pkg 1586 * and patch commands will not properly manage all pkgs/patches 1587 * unless the commands think they are running in the global zone. For 1588 * these commands we want to emulate the global zone. 1589 * 1590 * We don't do any emulation for pkgcond since it is typically used 1591 * in pkg/patch postinstall scripts and we want those scripts to do 1592 * the right thing inside a zone. 1593 * 1594 * One issue is the handling of hollow pkgs. Since the pkgs are 1595 * hollow, they won't use pkgcond in their postinstall scripts. These 1596 * pkgs typically are installing drivers so we handle that by 1597 * replacing add_drv and rem_drv in the s10_boot script. 1598 */ 1599 if (strcmp("pkgadd", bname) == 0 || strcmp("pkgrm", bname) == 0 || 1600 strcmp("patchadd", bname) == 0 || strcmp("patchrm", bname) == 0) 1601 emul_global_zone = B_TRUE; 1602 1603 /* 1604 * Register our syscall emulation table with the kernel. 1605 * Note that we don't have to do invoke (syscall_number + 1024) 1606 * until we've actually establised a syscall emulation callback 1607 * handler address, which is what we're doing with this brand 1608 * syscall. 1609 */ 1610 reg.sbr_version = S10_VERSION; 1611 reg.sbr_handler = (caddr_t)s10_handler; 1612 if ((err = __systemcall(&rval, SYS_brand, B_REGISTER, ®)) != 0) { 1613 s10_abort(err, "Failed to brand current process"); 1614 /*NOTREACHED*/ 1615 } 1616 1617 /* Get data about the executable we're running from the kernel. */ 1618 if ((err = __systemcall(&rval, SYS_brand + 1024, 1619 B_ELFDATA, (void *)&sed)) != 0) { 1620 s10_abort(err, 1621 "Failed to get required brand ELF data from the kernel"); 1622 /*NOTREACHED*/ 1623 } 1624 1625 /* 1626 * Find the aux vector on the stack. 1627 */ 1628 p = (uintptr_t *)envp; 1629 while (*p != NULL) 1630 p++; 1631 1632 /* 1633 * p is now pointing at the 0 word after the environ pointers. 1634 * After that is the aux vectors. 1635 * 1636 * The aux vectors are currently pointing to the brand emulation 1637 * library and associated linker. We're going to change them to 1638 * point to the brand executable and associated linker (or to no 1639 * linker for static binaries). This matches the process data 1640 * stored within the kernel and visible from /proc, which was 1641 * all setup in s10_elfexec(). We do this so that when a debugger 1642 * attaches to the process it sees the process as a normal solaris 1643 * process, this brand emulation library and everything on it's 1644 * link map will not be visible, unless our librtld_db plugin 1645 * is used. Note that this is very different from how Linux 1646 * branded processes are implemented within lx branded zones. 1647 * In that situation, the primary linkmap of the process is the 1648 * brand emulation libraries linkmap, not the Linux applications 1649 * linkmap. 1650 * 1651 * We also need to clear the AF_SUN_NOPLM flag from the AT_SUN_AUXFLAGS 1652 * aux vector. This flag told our linker that we don't have a 1653 * primary link map. Now that our linker is done initializing, we 1654 * want to clear this flag before we transfer control to the 1655 * applications copy of the linker, since we want that linker to have 1656 * a primary link map which will be the link map for the application 1657 * we're running. 1658 */ 1659 p++; 1660 for (ap = (auxv_t *)p; ap->a_type != AT_NULL; ap++) { 1661 switch (ap->a_type) { 1662 case AT_BASE: 1663 /* Hide AT_BASE if static binary */ 1664 if (sed.sed_base == NULL) { 1665 ap->a_type = AT_IGNORE; 1666 ap->a_un.a_val = NULL; 1667 } else { 1668 ap->a_un.a_val = sed.sed_base; 1669 } 1670 break; 1671 case AT_ENTRY: 1672 ap->a_un.a_val = sed.sed_entry; 1673 break; 1674 case AT_PHDR: 1675 ap->a_un.a_val = sed.sed_phdr; 1676 break; 1677 case AT_PHENT: 1678 ap->a_un.a_val = sed.sed_phent; 1679 break; 1680 case AT_PHNUM: 1681 ap->a_un.a_val = sed.sed_phnum; 1682 break; 1683 case AT_SUN_AUXFLAGS: 1684 ap->a_un.a_val &= ~AF_SUN_NOPLM; 1685 break; 1686 case AT_SUN_EMULATOR: 1687 /* 1688 * ld.so.1 inspects AT_SUN_EMULATOR to see if 1689 * if it is the linker for the brand emulation 1690 * library. Hide AT_SUN_EMULATOR, as the 1691 * linker we are about to jump to is the linker 1692 * for the binary. 1693 */ 1694 ap->a_type = AT_IGNORE; 1695 ap->a_un.a_val = NULL; 1696 break; 1697 case AT_SUN_LDDATA: 1698 /* Hide AT_SUN_LDDATA if static binary */ 1699 if (sed.sed_lddata == NULL) { 1700 ap->a_type = AT_IGNORE; 1701 ap->a_un.a_val = NULL; 1702 } else { 1703 ap->a_un.a_val = sed.sed_lddata; 1704 } 1705 break; 1706 default: 1707 break; 1708 } 1709 } 1710 1711 s10_runexe(argv, sed.sed_ldentry); 1712 /*NOTREACHED*/ 1713 s10_abort(0, "s10_runexe() returned"); 1714 return (-1); 1715 } 1716 1717 /* 1718 * This table must have at least NSYSCALL entries in it. 1719 * 1720 * The second parameter of each entry in the s10_sysent_table 1721 * contains the number of parameters and flags that describe the 1722 * syscall return value encoding. See the block comments at the 1723 * top of this file for more information about the syscall return 1724 * value flags and when they should be used. 1725 */ 1726 s10_sysent_table_t s10_sysent_table[] = { 1727 #if defined(__sparc) && !defined(__sparcv9) 1728 EMULATE(s10_indir, 9 | RV_64RVAL), /* 0 */ 1729 #else /* !__sparc || __sparcv9 */ 1730 NOSYS, /* 0 */ 1731 #endif /* !__sparc || __sparcv9 */ 1732 NOSYS, /* 1 */ 1733 NOSYS, /* 2 */ 1734 NOSYS, /* 3 */ 1735 NOSYS, /* 4 */ 1736 NOSYS, /* 5 */ 1737 NOSYS, /* 6 */ 1738 NOSYS, /* 7 */ 1739 NOSYS, /* 8 */ 1740 NOSYS, /* 9 */ 1741 NOSYS, /* 10 */ 1742 EMULATE(s10_exec, 2 | RV_DEFAULT), /* 11 */ 1743 NOSYS, /* 12 */ 1744 NOSYS, /* 13 */ 1745 NOSYS, /* 14 */ 1746 NOSYS, /* 15 */ 1747 NOSYS, /* 16 */ 1748 NOSYS, /* 17 */ 1749 NOSYS, /* 18 */ 1750 NOSYS, /* 19 */ 1751 NOSYS, /* 20 */ 1752 NOSYS, /* 21 */ 1753 NOSYS, /* 22 */ 1754 NOSYS, /* 23 */ 1755 NOSYS, /* 24 */ 1756 NOSYS, /* 25 */ 1757 NOSYS, /* 26 */ 1758 NOSYS, /* 27 */ 1759 NOSYS, /* 28 */ 1760 NOSYS, /* 29 */ 1761 NOSYS, /* 30 */ 1762 NOSYS, /* 31 */ 1763 NOSYS, /* 32 */ 1764 NOSYS, /* 33 */ 1765 NOSYS, /* 34 */ 1766 NOSYS, /* 35 */ 1767 NOSYS, /* 36 */ 1768 NOSYS, /* 37 */ 1769 NOSYS, /* 38 */ 1770 NOSYS, /* 39 */ 1771 NOSYS, /* 40 */ 1772 NOSYS, /* 41 */ 1773 NOSYS, /* 42 */ 1774 NOSYS, /* 43 */ 1775 NOSYS, /* 44 */ 1776 NOSYS, /* 45 */ 1777 NOSYS, /* 46 */ 1778 NOSYS, /* 47 */ 1779 NOSYS, /* 48 */ 1780 NOSYS, /* 49 */ 1781 NOSYS, /* 50 */ 1782 NOSYS, /* 51 */ 1783 NOSYS, /* 52 */ 1784 NOSYS, /* 53 */ 1785 EMULATE(s10_ioctl, 3 | RV_DEFAULT), /* 54 */ 1786 NOSYS, /* 55 */ 1787 NOSYS, /* 56 */ 1788 NOSYS, /* 57 */ 1789 NOSYS, /* 58 */ 1790 EMULATE(s10_execve, 3 | RV_DEFAULT), /* 59 */ 1791 NOSYS, /* 60 */ 1792 NOSYS, /* 61 */ 1793 NOSYS, /* 62 */ 1794 NOSYS, /* 63 */ 1795 NOSYS, /* 64 */ 1796 NOSYS, /* 65 */ 1797 NOSYS, /* 66 */ 1798 NOSYS, /* 67 */ 1799 NOSYS, /* 68 */ 1800 NOSYS, /* 69 */ 1801 NOSYS, /* 70 */ 1802 EMULATE(s10_acctctl, 3 | RV_DEFAULT), /* 71 */ 1803 NOSYS, /* 72 */ 1804 NOSYS, /* 73 */ 1805 NOSYS, /* 74 */ 1806 EMULATE(s10_issetugid, 0 | RV_DEFAULT), /* 75 */ 1807 NOSYS, /* 76 */ 1808 NOSYS, /* 77 */ 1809 NOSYS, /* 78 */ 1810 NOSYS, /* 79 */ 1811 NOSYS, /* 80 */ 1812 NOSYS, /* 81 */ 1813 NOSYS, /* 82 */ 1814 NOSYS, /* 83 */ 1815 NOSYS, /* 84 */ 1816 NOSYS, /* 85 */ 1817 NOSYS, /* 86 */ 1818 NOSYS, /* 87 */ 1819 NOSYS, /* 88 */ 1820 NOSYS, /* 89 */ 1821 NOSYS, /* 90 */ 1822 NOSYS, /* 91 */ 1823 NOSYS, /* 92 */ 1824 NOSYS, /* 93 */ 1825 NOSYS, /* 94 */ 1826 NOSYS, /* 95 */ 1827 NOSYS, /* 96 */ 1828 NOSYS, /* 97 */ 1829 NOSYS, /* 98 */ 1830 NOSYS, /* 99 */ 1831 NOSYS, /* 100 */ 1832 NOSYS, /* 101 */ 1833 NOSYS, /* 102 */ 1834 NOSYS, /* 103 */ 1835 NOSYS, /* 104 */ 1836 NOSYS, /* 105 */ 1837 NOSYS, /* 106 */ 1838 NOSYS, /* 107 */ 1839 NOSYS, /* 108 */ 1840 NOSYS, /* 109 */ 1841 NOSYS, /* 110 */ 1842 NOSYS, /* 111 */ 1843 NOSYS, /* 112 */ 1844 NOSYS, /* 113 */ 1845 NOSYS, /* 114 */ 1846 NOSYS, /* 115 */ 1847 NOSYS, /* 116 */ 1848 NOSYS, /* 117 */ 1849 NOSYS, /* 118 */ 1850 NOSYS, /* 119 */ 1851 NOSYS, /* 120 */ 1852 NOSYS, /* 121 */ 1853 NOSYS, /* 122 */ 1854 NOSYS, /* 123 */ 1855 NOSYS, /* 124 */ 1856 NOSYS, /* 125 */ 1857 NOSYS, /* 126 */ 1858 NOSYS, /* 127 */ 1859 NOSYS, /* 128 */ 1860 NOSYS, /* 129 */ 1861 NOSYS, /* 130 */ 1862 NOSYS, /* 131 */ 1863 NOSYS, /* 132 */ 1864 NOSYS, /* 133 */ 1865 NOSYS, /* 134 */ 1866 EMULATE(s10_uname, 1 | RV_DEFAULT), /* 135 */ 1867 NOSYS, /* 136 */ 1868 NOSYS, /* 137 */ 1869 NOSYS, /* 138 */ 1870 EMULATE(s10_sysinfo, 3 | RV_DEFAULT), /* 139 */ 1871 NOSYS, /* 140 */ 1872 NOSYS, /* 141 */ 1873 NOSYS, /* 142 */ 1874 NOSYS, /* 143 */ 1875 NOSYS, /* 144 */ 1876 NOSYS, /* 145 */ 1877 NOSYS, /* 146 */ 1878 NOSYS, /* 147 */ 1879 NOSYS, /* 148 */ 1880 NOSYS, /* 149 */ 1881 NOSYS, /* 150 */ 1882 NOSYS, /* 151 */ 1883 NOSYS, /* 152 */ 1884 NOSYS, /* 153 */ 1885 NOSYS, /* 154 */ 1886 NOSYS, /* 155 */ 1887 NOSYS, /* 156 */ 1888 NOSYS, /* 157 */ 1889 NOSYS, /* 158 */ 1890 #ifdef __x86 1891 EMULATE(s10_lwp_create, 3 | RV_DEFAULT), /* 159 */ 1892 #else /* !__x86 */ 1893 NOSYS, /* 159 */ 1894 #endif /* !__x86 */ 1895 NOSYS, /* 160 */ 1896 NOSYS, /* 161 */ 1897 NOSYS, /* 162 */ 1898 NOSYS, /* 163 */ 1899 NOSYS, /* 164 */ 1900 NOSYS, /* 165 */ 1901 #ifdef __x86 1902 EMULATE(s10_lwp_private, 3 | RV_DEFAULT), /* 166 */ 1903 #else /* !__x86 */ 1904 NOSYS, /* 166 */ 1905 #endif /* !__x86 */ 1906 NOSYS, /* 167 */ 1907 NOSYS, /* 168 */ 1908 NOSYS, /* 169 */ 1909 NOSYS, /* 170 */ 1910 NOSYS, /* 171 */ 1911 NOSYS, /* 172 */ 1912 NOSYS, /* 173 */ 1913 EMULATE(s10_pwrite, 4 | RV_DEFAULT), /* 174 */ 1914 NOSYS, /* 175 */ 1915 NOSYS, /* 176 */ 1916 NOSYS, /* 177 */ 1917 NOSYS, /* 178 */ 1918 NOSYS, /* 179 */ 1919 NOSYS, /* 180 */ 1920 NOSYS, /* 181 */ 1921 NOSYS, /* 182 */ 1922 NOSYS, /* 183 */ 1923 NOSYS, /* 184 */ 1924 NOSYS, /* 185 */ 1925 EMULATE(s10_auditsys, 4 | RV_64RVAL), /* 186 */ 1926 NOSYS, /* 187 */ 1927 NOSYS, /* 188 */ 1928 NOSYS, /* 189 */ 1929 EMULATE(s10_sigqueue, 4 | RV_DEFAULT), /* 190 */ 1930 NOSYS, /* 191 */ 1931 NOSYS, /* 192 */ 1932 NOSYS, /* 193 */ 1933 NOSYS, /* 194 */ 1934 NOSYS, /* 195 */ 1935 NOSYS, /* 196 */ 1936 NOSYS, /* 197 */ 1937 NOSYS, /* 198 */ 1938 NOSYS, /* 199 */ 1939 NOSYS, /* 200 */ 1940 NOSYS, /* 201 */ 1941 NOSYS, /* 202 */ 1942 NOSYS, /* 203 */ 1943 NOSYS, /* 204 */ 1944 NOSYS, /* 205 */ 1945 NOSYS, /* 206 */ 1946 NOSYS, /* 207 */ 1947 NOSYS, /* 208 */ 1948 NOSYS, /* 209 */ 1949 EMULATE(s10_lwp_mutex_timedlock, 2 | RV_DEFAULT), /* 210 */ 1950 NOSYS, /* 211 */ 1951 NOSYS, /* 212 */ 1952 NOSYS, /* 213 */ 1953 NOSYS, /* 214 */ 1954 NOSYS, /* 215 */ 1955 NOSYS, /* 216 */ 1956 NOSYS, /* 217 */ 1957 NOSYS, /* 218 */ 1958 NOSYS, /* 219 */ 1959 NOSYS, /* 220 */ 1960 NOSYS, /* 221 */ 1961 NOSYS, /* 222 */ 1962 #ifdef _LP64 1963 NOSYS, /* 223 */ 1964 #else /* !_LP64 */ 1965 EMULATE(s10_pwrite64, 5 | RV_DEFAULT), /* 223 */ 1966 #endif /* !_LP64 */ 1967 NOSYS, /* 224 */ 1968 NOSYS, /* 225 */ 1969 NOSYS, /* 226 */ 1970 EMULATE(s10_zone, 5 | RV_DEFAULT), /* 227 */ 1971 NOSYS, /* 228 */ 1972 NOSYS, /* 229 */ 1973 NOSYS, /* 230 */ 1974 NOSYS, /* 231 */ 1975 NOSYS, /* 232 */ 1976 NOSYS, /* 233 */ 1977 NOSYS, /* 234 */ 1978 NOSYS, /* 235 */ 1979 NOSYS, /* 236 */ 1980 NOSYS, /* 237 */ 1981 NOSYS, /* 238 */ 1982 NOSYS, /* 239 */ 1983 NOSYS, /* 240 */ 1984 NOSYS, /* 241 */ 1985 NOSYS, /* 242 */ 1986 NOSYS, /* 243 */ 1987 NOSYS, /* 244 */ 1988 NOSYS, /* 245 */ 1989 NOSYS, /* 246 */ 1990 NOSYS, /* 247 */ 1991 NOSYS, /* 248 */ 1992 NOSYS, /* 249 */ 1993 NOSYS, /* 250 */ 1994 EMULATE(s10_lwp_mutex_trylock, 1 | RV_DEFAULT), /* 251 */ 1995 NOSYS, /* 252 */ 1996 NOSYS, /* 253 */ 1997 NOSYS, /* 254 */ 1998 NOSYS /* 255 */ 1999 }; 2000