1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2004 Tim J. Robbins 5 * Copyright (c) 2002 Doug Rabson 6 * Copyright (c) 2000 Marcel Moolenaar 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer 14 * in this position and unchanged. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> 34 __FBSDID("$FreeBSD$"); 35 36 #include "opt_compat.h" 37 38 #include <sys/param.h> 39 #include <sys/capsicum.h> 40 #include <sys/clock.h> 41 #include <sys/fcntl.h> 42 #include <sys/file.h> 43 #include <sys/imgact.h> 44 #include <sys/kernel.h> 45 #include <sys/limits.h> 46 #include <sys/lock.h> 47 #include <sys/malloc.h> 48 #include <sys/mman.h> 49 #include <sys/mutex.h> 50 #include <sys/priv.h> 51 #include <sys/proc.h> 52 #include <sys/reg.h> 53 #include <sys/resource.h> 54 #include <sys/resourcevar.h> 55 #include <sys/syscallsubr.h> 56 #include <sys/sysproto.h> 57 #include <sys/systm.h> 58 #include <sys/unistd.h> 59 #include <sys/wait.h> 60 61 #include <machine/frame.h> 62 #include <machine/md_var.h> 63 #include <machine/pcb.h> 64 #include <machine/psl.h> 65 #include <machine/segments.h> 66 #include <machine/specialreg.h> 67 #include <x86/ifunc.h> 68 69 #include <vm/pmap.h> 70 #include <vm/vm.h> 71 #include <vm/vm_map.h> 72 73 #include <security/audit/audit.h> 74 75 #include <compat/freebsd32/freebsd32_util.h> 76 #include <amd64/linux32/linux.h> 77 #include <amd64/linux32/linux32_proto.h> 78 #include <compat/linux/linux_emul.h> 79 #include <compat/linux/linux_fork.h> 80 #include <compat/linux/linux_ipc.h> 81 #include <compat/linux/linux_misc.h> 82 #include <compat/linux/linux_mmap.h> 83 #include <compat/linux/linux_signal.h> 84 #include <compat/linux/linux_util.h> 85 86 static void bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru); 87 88 struct l_old_select_argv { 89 l_int nfds; 90 l_uintptr_t readfds; 91 l_uintptr_t writefds; 92 l_uintptr_t exceptfds; 93 l_uintptr_t timeout; 94 } __packed; 95 96 static void 97 bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru) 98 { 99 100 lru->ru_utime.tv_sec = ru->ru_utime.tv_sec; 101 lru->ru_utime.tv_usec = ru->ru_utime.tv_usec; 102 lru->ru_stime.tv_sec = ru->ru_stime.tv_sec; 103 lru->ru_stime.tv_usec = ru->ru_stime.tv_usec; 104 lru->ru_maxrss = ru->ru_maxrss; 105 lru->ru_ixrss = ru->ru_ixrss; 106 lru->ru_idrss = ru->ru_idrss; 107 lru->ru_isrss = ru->ru_isrss; 108 lru->ru_minflt = ru->ru_minflt; 109 lru->ru_majflt = ru->ru_majflt; 110 lru->ru_nswap = ru->ru_nswap; 111 lru->ru_inblock = ru->ru_inblock; 112 lru->ru_oublock = ru->ru_oublock; 113 lru->ru_msgsnd = ru->ru_msgsnd; 114 lru->ru_msgrcv = ru->ru_msgrcv; 115 lru->ru_nsignals = ru->ru_nsignals; 116 lru->ru_nvcsw = ru->ru_nvcsw; 117 lru->ru_nivcsw = ru->ru_nivcsw; 118 } 119 120 int 121 linux_copyout_rusage(struct rusage *ru, void *uaddr) 122 { 123 struct l_rusage lru; 124 125 bsd_to_linux_rusage(ru, &lru); 126 127 return (copyout(&lru, uaddr, sizeof(struct l_rusage))); 128 } 129 130 int 131 linux_execve(struct thread *td, struct linux_execve_args *args) 132 { 133 struct image_args eargs; 134 char *path; 135 int error; 136 137 if (!LUSECONVPATH(td)) { 138 error = freebsd32_exec_copyin_args(&eargs, args->path, UIO_USERSPACE, 139 args->argp, args->envp); 140 } else { 141 LCONVPATHEXIST(args->path, &path); 142 error = freebsd32_exec_copyin_args(&eargs, path, UIO_SYSSPACE, 143 args->argp, args->envp); 144 LFREEPATH(path); 145 } 146 if (error == 0) 147 error = linux_common_execve(td, &eargs); 148 AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); 149 return (error); 150 } 151 152 CTASSERT(sizeof(struct l_iovec32) == 8); 153 154 int 155 linux32_copyinuio(struct l_iovec32 *iovp, l_ulong iovcnt, struct uio **uiop) 156 { 157 struct l_iovec32 iov32; 158 struct iovec *iov; 159 struct uio *uio; 160 uint32_t iovlen; 161 int error, i; 162 163 *uiop = NULL; 164 if (iovcnt > UIO_MAXIOV) 165 return (EINVAL); 166 iovlen = iovcnt * sizeof(struct iovec); 167 uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK); 168 iov = (struct iovec *)(uio + 1); 169 for (i = 0; i < iovcnt; i++) { 170 error = copyin(&iovp[i], &iov32, sizeof(struct l_iovec32)); 171 if (error) { 172 free(uio, M_IOV); 173 return (error); 174 } 175 iov[i].iov_base = PTRIN(iov32.iov_base); 176 iov[i].iov_len = iov32.iov_len; 177 } 178 uio->uio_iov = iov; 179 uio->uio_iovcnt = iovcnt; 180 uio->uio_segflg = UIO_USERSPACE; 181 uio->uio_offset = -1; 182 uio->uio_resid = 0; 183 for (i = 0; i < iovcnt; i++) { 184 if (iov->iov_len > INT_MAX - uio->uio_resid) { 185 free(uio, M_IOV); 186 return (EINVAL); 187 } 188 uio->uio_resid += iov->iov_len; 189 iov++; 190 } 191 *uiop = uio; 192 return (0); 193 } 194 195 int 196 linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt, struct iovec **iovp, 197 int error) 198 { 199 struct l_iovec32 iov32; 200 struct iovec *iov; 201 uint32_t iovlen; 202 int i; 203 204 *iovp = NULL; 205 if (iovcnt > UIO_MAXIOV) 206 return (error); 207 iovlen = iovcnt * sizeof(struct iovec); 208 iov = malloc(iovlen, M_IOV, M_WAITOK); 209 for (i = 0; i < iovcnt; i++) { 210 error = copyin(&iovp32[i], &iov32, sizeof(struct l_iovec32)); 211 if (error) { 212 free(iov, M_IOV); 213 return (error); 214 } 215 iov[i].iov_base = PTRIN(iov32.iov_base); 216 iov[i].iov_len = iov32.iov_len; 217 } 218 *iovp = iov; 219 return(0); 220 221 } 222 223 int 224 linux_readv(struct thread *td, struct linux_readv_args *uap) 225 { 226 struct uio *auio; 227 int error; 228 229 error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio); 230 if (error) 231 return (error); 232 error = kern_readv(td, uap->fd, auio); 233 free(auio, M_IOV); 234 return (error); 235 } 236 237 int 238 linux_writev(struct thread *td, struct linux_writev_args *uap) 239 { 240 struct uio *auio; 241 int error; 242 243 error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio); 244 if (error) 245 return (error); 246 error = kern_writev(td, uap->fd, auio); 247 free(auio, M_IOV); 248 return (error); 249 } 250 251 struct l_ipc_kludge { 252 l_uintptr_t msgp; 253 l_long msgtyp; 254 } __packed; 255 256 int 257 linux_ipc(struct thread *td, struct linux_ipc_args *args) 258 { 259 260 switch (args->what & 0xFFFF) { 261 case LINUX_SEMOP: { 262 263 return (kern_semop(td, args->arg1, PTRIN(args->ptr), 264 args->arg2, NULL)); 265 } 266 case LINUX_SEMGET: { 267 struct linux_semget_args a; 268 269 a.key = args->arg1; 270 a.nsems = args->arg2; 271 a.semflg = args->arg3; 272 return (linux_semget(td, &a)); 273 } 274 case LINUX_SEMCTL: { 275 struct linux_semctl_args a; 276 int error; 277 278 a.semid = args->arg1; 279 a.semnum = args->arg2; 280 a.cmd = args->arg3; 281 error = copyin(PTRIN(args->ptr), &a.arg, sizeof(a.arg)); 282 if (error) 283 return (error); 284 return (linux_semctl(td, &a)); 285 } 286 case LINUX_SEMTIMEDOP: { 287 struct linux_semtimedop_args a; 288 289 a.semid = args->arg1; 290 a.tsops = PTRIN(args->ptr); 291 a.nsops = args->arg2; 292 a.timeout = PTRIN(args->arg5); 293 return (linux_semtimedop(td, &a)); 294 } 295 case LINUX_MSGSND: { 296 struct linux_msgsnd_args a; 297 298 a.msqid = args->arg1; 299 a.msgp = PTRIN(args->ptr); 300 a.msgsz = args->arg2; 301 a.msgflg = args->arg3; 302 return (linux_msgsnd(td, &a)); 303 } 304 case LINUX_MSGRCV: { 305 struct linux_msgrcv_args a; 306 307 a.msqid = args->arg1; 308 a.msgsz = args->arg2; 309 a.msgflg = args->arg3; 310 if ((args->what >> 16) == 0) { 311 struct l_ipc_kludge tmp; 312 int error; 313 314 if (args->ptr == 0) 315 return (EINVAL); 316 error = copyin(PTRIN(args->ptr), &tmp, sizeof(tmp)); 317 if (error) 318 return (error); 319 a.msgp = PTRIN(tmp.msgp); 320 a.msgtyp = tmp.msgtyp; 321 } else { 322 a.msgp = PTRIN(args->ptr); 323 a.msgtyp = args->arg5; 324 } 325 return (linux_msgrcv(td, &a)); 326 } 327 case LINUX_MSGGET: { 328 struct linux_msgget_args a; 329 330 a.key = args->arg1; 331 a.msgflg = args->arg2; 332 return (linux_msgget(td, &a)); 333 } 334 case LINUX_MSGCTL: { 335 struct linux_msgctl_args a; 336 337 a.msqid = args->arg1; 338 a.cmd = args->arg2; 339 a.buf = PTRIN(args->ptr); 340 return (linux_msgctl(td, &a)); 341 } 342 case LINUX_SHMAT: { 343 struct linux_shmat_args a; 344 l_uintptr_t addr; 345 int error; 346 347 a.shmid = args->arg1; 348 a.shmaddr = PTRIN(args->ptr); 349 a.shmflg = args->arg2; 350 error = linux_shmat(td, &a); 351 if (error != 0) 352 return (error); 353 addr = td->td_retval[0]; 354 error = copyout(&addr, PTRIN(args->arg3), sizeof(addr)); 355 td->td_retval[0] = 0; 356 return (error); 357 } 358 case LINUX_SHMDT: { 359 struct linux_shmdt_args a; 360 361 a.shmaddr = PTRIN(args->ptr); 362 return (linux_shmdt(td, &a)); 363 } 364 case LINUX_SHMGET: { 365 struct linux_shmget_args a; 366 367 a.key = args->arg1; 368 a.size = args->arg2; 369 a.shmflg = args->arg3; 370 return (linux_shmget(td, &a)); 371 } 372 case LINUX_SHMCTL: { 373 struct linux_shmctl_args a; 374 375 a.shmid = args->arg1; 376 a.cmd = args->arg2; 377 a.buf = PTRIN(args->ptr); 378 return (linux_shmctl(td, &a)); 379 } 380 default: 381 break; 382 } 383 384 return (EINVAL); 385 } 386 387 int 388 linux_old_select(struct thread *td, struct linux_old_select_args *args) 389 { 390 struct l_old_select_argv linux_args; 391 struct linux_select_args newsel; 392 int error; 393 394 error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 395 if (error) 396 return (error); 397 398 newsel.nfds = linux_args.nfds; 399 newsel.readfds = PTRIN(linux_args.readfds); 400 newsel.writefds = PTRIN(linux_args.writefds); 401 newsel.exceptfds = PTRIN(linux_args.exceptfds); 402 newsel.timeout = PTRIN(linux_args.timeout); 403 return (linux_select(td, &newsel)); 404 } 405 406 int 407 linux_set_cloned_tls(struct thread *td, void *desc) 408 { 409 struct l_user_desc info; 410 struct pcb *pcb; 411 int error; 412 413 error = copyin(desc, &info, sizeof(struct l_user_desc)); 414 if (error) { 415 linux_msg(td, "set_cloned_tls copyin info failed!"); 416 } else { 417 /* We might copy out the entry_number as GUGS32_SEL. */ 418 info.entry_number = GUGS32_SEL; 419 error = copyout(&info, desc, sizeof(struct l_user_desc)); 420 if (error) 421 linux_msg(td, "set_cloned_tls copyout info failed!"); 422 423 pcb = td->td_pcb; 424 update_pcb_bases(pcb); 425 pcb->pcb_gsbase = (register_t)info.base_addr; 426 td->td_frame->tf_gs = GSEL(GUGS32_SEL, SEL_UPL); 427 } 428 429 return (error); 430 } 431 432 int 433 linux_set_upcall(struct thread *td, register_t stack) 434 { 435 436 if (stack) 437 td->td_frame->tf_rsp = stack; 438 439 /* 440 * The newly created Linux thread returns 441 * to the user space by the same path that a parent do. 442 */ 443 td->td_frame->tf_rax = 0; 444 return (0); 445 } 446 447 int 448 linux_mmap2(struct thread *td, struct linux_mmap2_args *args) 449 { 450 451 return (linux_mmap_common(td, PTROUT(args->addr), args->len, args->prot, 452 args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff * 453 PAGE_SIZE)); 454 } 455 456 int 457 linux_mmap(struct thread *td, struct linux_mmap_args *args) 458 { 459 int error; 460 struct l_mmap_argv linux_args; 461 462 error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 463 if (error) 464 return (error); 465 466 return (linux_mmap_common(td, linux_args.addr, linux_args.len, 467 linux_args.prot, linux_args.flags, linux_args.fd, 468 (uint32_t)linux_args.pgoff)); 469 } 470 471 int 472 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap) 473 { 474 475 return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len, uap->prot)); 476 } 477 478 int 479 linux_madvise(struct thread *td, struct linux_madvise_args *uap) 480 { 481 482 return (linux_madvise_common(td, PTROUT(uap->addr), uap->len, uap->behav)); 483 } 484 485 int 486 linux_iopl(struct thread *td, struct linux_iopl_args *args) 487 { 488 int error; 489 490 if (args->level < 0 || args->level > 3) 491 return (EINVAL); 492 if ((error = priv_check(td, PRIV_IO)) != 0) 493 return (error); 494 if ((error = securelevel_gt(td->td_ucred, 0)) != 0) 495 return (error); 496 td->td_frame->tf_rflags = (td->td_frame->tf_rflags & ~PSL_IOPL) | 497 (args->level * (PSL_IOPL / 3)); 498 499 return (0); 500 } 501 502 int 503 linux_sigaction(struct thread *td, struct linux_sigaction_args *args) 504 { 505 l_osigaction_t osa; 506 l_sigaction_t act, oact; 507 int error; 508 509 if (args->nsa != NULL) { 510 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t)); 511 if (error) 512 return (error); 513 act.lsa_handler = osa.lsa_handler; 514 act.lsa_flags = osa.lsa_flags; 515 act.lsa_restorer = osa.lsa_restorer; 516 LINUX_SIGEMPTYSET(act.lsa_mask); 517 act.lsa_mask.__mask = osa.lsa_mask; 518 } 519 520 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL, 521 args->osa ? &oact : NULL); 522 523 if (args->osa != NULL && !error) { 524 osa.lsa_handler = oact.lsa_handler; 525 osa.lsa_flags = oact.lsa_flags; 526 osa.lsa_restorer = oact.lsa_restorer; 527 osa.lsa_mask = oact.lsa_mask.__mask; 528 error = copyout(&osa, args->osa, sizeof(l_osigaction_t)); 529 } 530 531 return (error); 532 } 533 534 /* 535 * Linux has two extra args, restart and oldmask. We don't use these, 536 * but it seems that "restart" is actually a context pointer that 537 * enables the signal to happen with a different register set. 538 */ 539 int 540 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args) 541 { 542 sigset_t sigmask; 543 l_sigset_t mask; 544 545 LINUX_SIGEMPTYSET(mask); 546 mask.__mask = args->mask; 547 linux_to_bsd_sigset(&mask, &sigmask); 548 return (kern_sigsuspend(td, sigmask)); 549 } 550 551 int 552 linux_pause(struct thread *td, struct linux_pause_args *args) 553 { 554 struct proc *p = td->td_proc; 555 sigset_t sigmask; 556 557 PROC_LOCK(p); 558 sigmask = td->td_sigmask; 559 PROC_UNLOCK(p); 560 return (kern_sigsuspend(td, sigmask)); 561 } 562 563 int 564 linux_gettimeofday(struct thread *td, struct linux_gettimeofday_args *uap) 565 { 566 struct timeval atv; 567 l_timeval atv32; 568 struct timezone rtz; 569 int error = 0; 570 571 if (uap->tp) { 572 microtime(&atv); 573 atv32.tv_sec = atv.tv_sec; 574 atv32.tv_usec = atv.tv_usec; 575 error = copyout(&atv32, uap->tp, sizeof(atv32)); 576 } 577 if (error == 0 && uap->tzp != NULL) { 578 rtz.tz_minuteswest = 0; 579 rtz.tz_dsttime = 0; 580 error = copyout(&rtz, uap->tzp, sizeof(rtz)); 581 } 582 return (error); 583 } 584 585 int 586 linux_settimeofday(struct thread *td, struct linux_settimeofday_args *uap) 587 { 588 l_timeval atv32; 589 struct timeval atv, *tvp; 590 struct timezone atz, *tzp; 591 int error; 592 593 if (uap->tp) { 594 error = copyin(uap->tp, &atv32, sizeof(atv32)); 595 if (error) 596 return (error); 597 atv.tv_sec = atv32.tv_sec; 598 atv.tv_usec = atv32.tv_usec; 599 tvp = &atv; 600 } else 601 tvp = NULL; 602 if (uap->tzp) { 603 error = copyin(uap->tzp, &atz, sizeof(atz)); 604 if (error) 605 return (error); 606 tzp = &atz; 607 } else 608 tzp = NULL; 609 return (kern_settimeofday(td, tvp, tzp)); 610 } 611 612 int 613 linux_getrusage(struct thread *td, struct linux_getrusage_args *uap) 614 { 615 struct rusage s; 616 int error; 617 618 error = kern_getrusage(td, uap->who, &s); 619 if (error != 0) 620 return (error); 621 if (uap->rusage != NULL) 622 error = linux_copyout_rusage(&s, uap->rusage); 623 return (error); 624 } 625 626 int 627 linux_set_thread_area(struct thread *td, 628 struct linux_set_thread_area_args *args) 629 { 630 struct l_user_desc info; 631 struct pcb *pcb; 632 int error; 633 634 error = copyin(args->desc, &info, sizeof(struct l_user_desc)); 635 if (error) 636 return (error); 637 638 /* 639 * Semantics of Linux version: every thread in the system has array 640 * of three TLS descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. 641 * This syscall loads one of the selected TLS decriptors with a value 642 * and also loads GDT descriptors 6, 7 and 8 with the content of 643 * the per-thread descriptors. 644 * 645 * Semantics of FreeBSD version: I think we can ignore that Linux has 646 * three per-thread descriptors and use just the first one. 647 * The tls_array[] is used only in [gs]et_thread_area() syscalls and 648 * for loading the GDT descriptors. We use just one GDT descriptor 649 * for TLS, so we will load just one. 650 * 651 * XXX: This doesn't work when a user space process tries to use more 652 * than one TLS segment. Comment in the Linux source says wine might 653 * do this. 654 */ 655 656 /* 657 * GLIBC reads current %gs and call set_thread_area() with it. 658 * We should let GUDATA_SEL and GUGS32_SEL proceed as well because 659 * we use these segments. 660 */ 661 switch (info.entry_number) { 662 case GUGS32_SEL: 663 case GUDATA_SEL: 664 case 6: 665 case -1: 666 info.entry_number = GUGS32_SEL; 667 break; 668 default: 669 return (EINVAL); 670 } 671 672 /* 673 * We have to copy out the GDT entry we use. 674 * 675 * XXX: What if a user space program does not check the return value 676 * and tries to use 6, 7 or 8? 677 */ 678 error = copyout(&info, args->desc, sizeof(struct l_user_desc)); 679 if (error) 680 return (error); 681 682 pcb = td->td_pcb; 683 update_pcb_bases(pcb); 684 pcb->pcb_gsbase = (register_t)info.base_addr; 685 update_gdt_gsbase(td, info.base_addr); 686 687 return (0); 688 } 689 690 void 691 bsd_to_linux_regset32(const struct reg32 *b_reg, 692 struct linux_pt_regset32 *l_regset) 693 { 694 695 l_regset->ebx = b_reg->r_ebx; 696 l_regset->ecx = b_reg->r_ecx; 697 l_regset->edx = b_reg->r_edx; 698 l_regset->esi = b_reg->r_esi; 699 l_regset->edi = b_reg->r_edi; 700 l_regset->ebp = b_reg->r_ebp; 701 l_regset->eax = b_reg->r_eax; 702 l_regset->ds = b_reg->r_ds; 703 l_regset->es = b_reg->r_es; 704 l_regset->fs = b_reg->r_fs; 705 l_regset->gs = b_reg->r_gs; 706 l_regset->orig_eax = b_reg->r_eax; 707 l_regset->eip = b_reg->r_eip; 708 l_regset->cs = b_reg->r_cs; 709 l_regset->eflags = b_reg->r_eflags; 710 l_regset->esp = b_reg->r_esp; 711 l_regset->ss = b_reg->r_ss; 712 } 713 714 int futex_xchgl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 715 int futex_xchgl_smap(int oparg, uint32_t *uaddr, int *oldval); 716 DEFINE_IFUNC(, int, futex_xchgl, (int, uint32_t *, int *)) 717 { 718 719 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 720 futex_xchgl_smap : futex_xchgl_nosmap); 721 } 722 723 int futex_addl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 724 int futex_addl_smap(int oparg, uint32_t *uaddr, int *oldval); 725 DEFINE_IFUNC(, int, futex_addl, (int, uint32_t *, int *)) 726 { 727 728 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 729 futex_addl_smap : futex_addl_nosmap); 730 } 731 732 int futex_orl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 733 int futex_orl_smap(int oparg, uint32_t *uaddr, int *oldval); 734 DEFINE_IFUNC(, int, futex_orl, (int, uint32_t *, int *)) 735 { 736 737 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 738 futex_orl_smap : futex_orl_nosmap); 739 } 740 741 int futex_andl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 742 int futex_andl_smap(int oparg, uint32_t *uaddr, int *oldval); 743 DEFINE_IFUNC(, int, futex_andl, (int, uint32_t *, int *)) 744 { 745 746 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 747 futex_andl_smap : futex_andl_nosmap); 748 } 749 750 int futex_xorl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 751 int futex_xorl_smap(int oparg, uint32_t *uaddr, int *oldval); 752 DEFINE_IFUNC(, int, futex_xorl, (int, uint32_t *, int *)) 753 { 754 755 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 756 futex_xorl_smap : futex_xorl_nosmap); 757 } 758