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 LCONVPATHEXIST(td, args->path, &path); 138 139 error = freebsd32_exec_copyin_args(&eargs, path, UIO_SYSSPACE, 140 args->argp, args->envp); 141 free(path, M_TEMP); 142 if (error == 0) 143 error = linux_common_execve(td, &eargs); 144 AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); 145 return (error); 146 } 147 148 CTASSERT(sizeof(struct l_iovec32) == 8); 149 150 int 151 linux32_copyinuio(struct l_iovec32 *iovp, l_ulong iovcnt, struct uio **uiop) 152 { 153 struct l_iovec32 iov32; 154 struct iovec *iov; 155 struct uio *uio; 156 uint32_t iovlen; 157 int error, i; 158 159 *uiop = NULL; 160 if (iovcnt > UIO_MAXIOV) 161 return (EINVAL); 162 iovlen = iovcnt * sizeof(struct iovec); 163 uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK); 164 iov = (struct iovec *)(uio + 1); 165 for (i = 0; i < iovcnt; i++) { 166 error = copyin(&iovp[i], &iov32, sizeof(struct l_iovec32)); 167 if (error) { 168 free(uio, M_IOV); 169 return (error); 170 } 171 iov[i].iov_base = PTRIN(iov32.iov_base); 172 iov[i].iov_len = iov32.iov_len; 173 } 174 uio->uio_iov = iov; 175 uio->uio_iovcnt = iovcnt; 176 uio->uio_segflg = UIO_USERSPACE; 177 uio->uio_offset = -1; 178 uio->uio_resid = 0; 179 for (i = 0; i < iovcnt; i++) { 180 if (iov->iov_len > INT_MAX - uio->uio_resid) { 181 free(uio, M_IOV); 182 return (EINVAL); 183 } 184 uio->uio_resid += iov->iov_len; 185 iov++; 186 } 187 *uiop = uio; 188 return (0); 189 } 190 191 int 192 linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt, struct iovec **iovp, 193 int error) 194 { 195 struct l_iovec32 iov32; 196 struct iovec *iov; 197 uint32_t iovlen; 198 int i; 199 200 *iovp = NULL; 201 if (iovcnt > UIO_MAXIOV) 202 return (error); 203 iovlen = iovcnt * sizeof(struct iovec); 204 iov = malloc(iovlen, M_IOV, M_WAITOK); 205 for (i = 0; i < iovcnt; i++) { 206 error = copyin(&iovp32[i], &iov32, sizeof(struct l_iovec32)); 207 if (error) { 208 free(iov, M_IOV); 209 return (error); 210 } 211 iov[i].iov_base = PTRIN(iov32.iov_base); 212 iov[i].iov_len = iov32.iov_len; 213 } 214 *iovp = iov; 215 return(0); 216 217 } 218 219 int 220 linux_readv(struct thread *td, struct linux_readv_args *uap) 221 { 222 struct uio *auio; 223 int error; 224 225 error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio); 226 if (error) 227 return (error); 228 error = kern_readv(td, uap->fd, auio); 229 free(auio, M_IOV); 230 return (error); 231 } 232 233 int 234 linux_writev(struct thread *td, struct linux_writev_args *uap) 235 { 236 struct uio *auio; 237 int error; 238 239 error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio); 240 if (error) 241 return (error); 242 error = kern_writev(td, uap->fd, auio); 243 free(auio, M_IOV); 244 return (error); 245 } 246 247 struct l_ipc_kludge { 248 l_uintptr_t msgp; 249 l_long msgtyp; 250 } __packed; 251 252 int 253 linux_ipc(struct thread *td, struct linux_ipc_args *args) 254 { 255 256 switch (args->what & 0xFFFF) { 257 case LINUX_SEMOP: { 258 struct linux_semop_args a; 259 260 a.semid = args->arg1; 261 a.tsops = PTRIN(args->ptr); 262 a.nsops = args->arg2; 263 return (linux_semop(td, &a)); 264 } 265 case LINUX_SEMGET: { 266 struct linux_semget_args a; 267 268 a.key = args->arg1; 269 a.nsems = args->arg2; 270 a.semflg = args->arg3; 271 return (linux_semget(td, &a)); 272 } 273 case LINUX_SEMCTL: { 274 struct linux_semctl_args a; 275 int error; 276 277 a.semid = args->arg1; 278 a.semnum = args->arg2; 279 a.cmd = args->arg3; 280 error = copyin(PTRIN(args->ptr), &a.arg, sizeof(a.arg)); 281 if (error) 282 return (error); 283 return (linux_semctl(td, &a)); 284 } 285 case LINUX_MSGSND: { 286 struct linux_msgsnd_args a; 287 288 a.msqid = args->arg1; 289 a.msgp = PTRIN(args->ptr); 290 a.msgsz = args->arg2; 291 a.msgflg = args->arg3; 292 return (linux_msgsnd(td, &a)); 293 } 294 case LINUX_MSGRCV: { 295 struct linux_msgrcv_args a; 296 297 a.msqid = args->arg1; 298 a.msgsz = args->arg2; 299 a.msgflg = args->arg3; 300 if ((args->what >> 16) == 0) { 301 struct l_ipc_kludge tmp; 302 int error; 303 304 if (args->ptr == 0) 305 return (EINVAL); 306 error = copyin(PTRIN(args->ptr), &tmp, sizeof(tmp)); 307 if (error) 308 return (error); 309 a.msgp = PTRIN(tmp.msgp); 310 a.msgtyp = tmp.msgtyp; 311 } else { 312 a.msgp = PTRIN(args->ptr); 313 a.msgtyp = args->arg5; 314 } 315 return (linux_msgrcv(td, &a)); 316 } 317 case LINUX_MSGGET: { 318 struct linux_msgget_args a; 319 320 a.key = args->arg1; 321 a.msgflg = args->arg2; 322 return (linux_msgget(td, &a)); 323 } 324 case LINUX_MSGCTL: { 325 struct linux_msgctl_args a; 326 327 a.msqid = args->arg1; 328 a.cmd = args->arg2; 329 a.buf = PTRIN(args->ptr); 330 return (linux_msgctl(td, &a)); 331 } 332 case LINUX_SHMAT: { 333 struct linux_shmat_args a; 334 l_uintptr_t addr; 335 int error; 336 337 a.shmid = args->arg1; 338 a.shmaddr = PTRIN(args->ptr); 339 a.shmflg = args->arg2; 340 error = linux_shmat(td, &a); 341 if (error != 0) 342 return (error); 343 addr = td->td_retval[0]; 344 error = copyout(&addr, PTRIN(args->arg3), sizeof(addr)); 345 td->td_retval[0] = 0; 346 return (error); 347 } 348 case LINUX_SHMDT: { 349 struct linux_shmdt_args a; 350 351 a.shmaddr = PTRIN(args->ptr); 352 return (linux_shmdt(td, &a)); 353 } 354 case LINUX_SHMGET: { 355 struct linux_shmget_args a; 356 357 a.key = args->arg1; 358 a.size = args->arg2; 359 a.shmflg = args->arg3; 360 return (linux_shmget(td, &a)); 361 } 362 case LINUX_SHMCTL: { 363 struct linux_shmctl_args a; 364 365 a.shmid = args->arg1; 366 a.cmd = args->arg2; 367 a.buf = PTRIN(args->ptr); 368 return (linux_shmctl(td, &a)); 369 } 370 default: 371 break; 372 } 373 374 return (EINVAL); 375 } 376 377 int 378 linux_old_select(struct thread *td, struct linux_old_select_args *args) 379 { 380 struct l_old_select_argv linux_args; 381 struct linux_select_args newsel; 382 int error; 383 384 error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 385 if (error) 386 return (error); 387 388 newsel.nfds = linux_args.nfds; 389 newsel.readfds = PTRIN(linux_args.readfds); 390 newsel.writefds = PTRIN(linux_args.writefds); 391 newsel.exceptfds = PTRIN(linux_args.exceptfds); 392 newsel.timeout = PTRIN(linux_args.timeout); 393 return (linux_select(td, &newsel)); 394 } 395 396 int 397 linux_set_cloned_tls(struct thread *td, void *desc) 398 { 399 struct l_user_desc info; 400 struct pcb *pcb; 401 int error; 402 403 error = copyin(desc, &info, sizeof(struct l_user_desc)); 404 if (error) { 405 linux_msg(td, "set_cloned_tls copyin info failed!"); 406 } else { 407 /* We might copy out the entry_number as GUGS32_SEL. */ 408 info.entry_number = GUGS32_SEL; 409 error = copyout(&info, desc, sizeof(struct l_user_desc)); 410 if (error) 411 linux_msg(td, "set_cloned_tls copyout info failed!"); 412 413 pcb = td->td_pcb; 414 update_pcb_bases(pcb); 415 pcb->pcb_gsbase = (register_t)info.base_addr; 416 td->td_frame->tf_gs = GSEL(GUGS32_SEL, SEL_UPL); 417 } 418 419 return (error); 420 } 421 422 int 423 linux_set_upcall(struct thread *td, register_t stack) 424 { 425 426 if (stack) 427 td->td_frame->tf_rsp = stack; 428 429 /* 430 * The newly created Linux thread returns 431 * to the user space by the same path that a parent do. 432 */ 433 td->td_frame->tf_rax = 0; 434 return (0); 435 } 436 437 int 438 linux_mmap2(struct thread *td, struct linux_mmap2_args *args) 439 { 440 441 return (linux_mmap_common(td, PTROUT(args->addr), args->len, args->prot, 442 args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff * 443 PAGE_SIZE)); 444 } 445 446 int 447 linux_mmap(struct thread *td, struct linux_mmap_args *args) 448 { 449 int error; 450 struct l_mmap_argv linux_args; 451 452 error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 453 if (error) 454 return (error); 455 456 return (linux_mmap_common(td, linux_args.addr, linux_args.len, 457 linux_args.prot, linux_args.flags, linux_args.fd, 458 (uint32_t)linux_args.pgoff)); 459 } 460 461 int 462 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap) 463 { 464 465 return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len, uap->prot)); 466 } 467 468 int 469 linux_madvise(struct thread *td, struct linux_madvise_args *uap) 470 { 471 472 return (linux_madvise_common(td, PTROUT(uap->addr), uap->len, uap->behav)); 473 } 474 475 int 476 linux_iopl(struct thread *td, struct linux_iopl_args *args) 477 { 478 int error; 479 480 if (args->level < 0 || args->level > 3) 481 return (EINVAL); 482 if ((error = priv_check(td, PRIV_IO)) != 0) 483 return (error); 484 if ((error = securelevel_gt(td->td_ucred, 0)) != 0) 485 return (error); 486 td->td_frame->tf_rflags = (td->td_frame->tf_rflags & ~PSL_IOPL) | 487 (args->level * (PSL_IOPL / 3)); 488 489 return (0); 490 } 491 492 int 493 linux_sigaction(struct thread *td, struct linux_sigaction_args *args) 494 { 495 l_osigaction_t osa; 496 l_sigaction_t act, oact; 497 int error; 498 499 if (args->nsa != NULL) { 500 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t)); 501 if (error) 502 return (error); 503 act.lsa_handler = osa.lsa_handler; 504 act.lsa_flags = osa.lsa_flags; 505 act.lsa_restorer = osa.lsa_restorer; 506 LINUX_SIGEMPTYSET(act.lsa_mask); 507 act.lsa_mask.__mask = osa.lsa_mask; 508 } 509 510 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL, 511 args->osa ? &oact : NULL); 512 513 if (args->osa != NULL && !error) { 514 osa.lsa_handler = oact.lsa_handler; 515 osa.lsa_flags = oact.lsa_flags; 516 osa.lsa_restorer = oact.lsa_restorer; 517 osa.lsa_mask = oact.lsa_mask.__mask; 518 error = copyout(&osa, args->osa, sizeof(l_osigaction_t)); 519 } 520 521 return (error); 522 } 523 524 /* 525 * Linux has two extra args, restart and oldmask. We don't use these, 526 * but it seems that "restart" is actually a context pointer that 527 * enables the signal to happen with a different register set. 528 */ 529 int 530 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args) 531 { 532 sigset_t sigmask; 533 l_sigset_t mask; 534 535 LINUX_SIGEMPTYSET(mask); 536 mask.__mask = args->mask; 537 linux_to_bsd_sigset(&mask, &sigmask); 538 return (kern_sigsuspend(td, sigmask)); 539 } 540 541 int 542 linux_pause(struct thread *td, struct linux_pause_args *args) 543 { 544 struct proc *p = td->td_proc; 545 sigset_t sigmask; 546 547 PROC_LOCK(p); 548 sigmask = td->td_sigmask; 549 PROC_UNLOCK(p); 550 return (kern_sigsuspend(td, sigmask)); 551 } 552 553 int 554 linux_gettimeofday(struct thread *td, struct linux_gettimeofday_args *uap) 555 { 556 struct timeval atv; 557 l_timeval atv32; 558 struct timezone rtz; 559 int error = 0; 560 561 if (uap->tp) { 562 microtime(&atv); 563 atv32.tv_sec = atv.tv_sec; 564 atv32.tv_usec = atv.tv_usec; 565 error = copyout(&atv32, uap->tp, sizeof(atv32)); 566 } 567 if (error == 0 && uap->tzp != NULL) { 568 rtz.tz_minuteswest = 0; 569 rtz.tz_dsttime = 0; 570 error = copyout(&rtz, uap->tzp, sizeof(rtz)); 571 } 572 return (error); 573 } 574 575 int 576 linux_settimeofday(struct thread *td, struct linux_settimeofday_args *uap) 577 { 578 l_timeval atv32; 579 struct timeval atv, *tvp; 580 struct timezone atz, *tzp; 581 int error; 582 583 if (uap->tp) { 584 error = copyin(uap->tp, &atv32, sizeof(atv32)); 585 if (error) 586 return (error); 587 atv.tv_sec = atv32.tv_sec; 588 atv.tv_usec = atv32.tv_usec; 589 tvp = &atv; 590 } else 591 tvp = NULL; 592 if (uap->tzp) { 593 error = copyin(uap->tzp, &atz, sizeof(atz)); 594 if (error) 595 return (error); 596 tzp = &atz; 597 } else 598 tzp = NULL; 599 return (kern_settimeofday(td, tvp, tzp)); 600 } 601 602 int 603 linux_getrusage(struct thread *td, struct linux_getrusage_args *uap) 604 { 605 struct rusage s; 606 int error; 607 608 error = kern_getrusage(td, uap->who, &s); 609 if (error != 0) 610 return (error); 611 if (uap->rusage != NULL) 612 error = linux_copyout_rusage(&s, uap->rusage); 613 return (error); 614 } 615 616 int 617 linux_set_thread_area(struct thread *td, 618 struct linux_set_thread_area_args *args) 619 { 620 struct l_user_desc info; 621 struct pcb *pcb; 622 int error; 623 624 error = copyin(args->desc, &info, sizeof(struct l_user_desc)); 625 if (error) 626 return (error); 627 628 /* 629 * Semantics of Linux version: every thread in the system has array 630 * of three TLS descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. 631 * This syscall loads one of the selected TLS decriptors with a value 632 * and also loads GDT descriptors 6, 7 and 8 with the content of 633 * the per-thread descriptors. 634 * 635 * Semantics of FreeBSD version: I think we can ignore that Linux has 636 * three per-thread descriptors and use just the first one. 637 * The tls_array[] is used only in [gs]et_thread_area() syscalls and 638 * for loading the GDT descriptors. We use just one GDT descriptor 639 * for TLS, so we will load just one. 640 * 641 * XXX: This doesn't work when a user space process tries to use more 642 * than one TLS segment. Comment in the Linux source says wine might 643 * do this. 644 */ 645 646 /* 647 * GLIBC reads current %gs and call set_thread_area() with it. 648 * We should let GUDATA_SEL and GUGS32_SEL proceed as well because 649 * we use these segments. 650 */ 651 switch (info.entry_number) { 652 case GUGS32_SEL: 653 case GUDATA_SEL: 654 case 6: 655 case -1: 656 info.entry_number = GUGS32_SEL; 657 break; 658 default: 659 return (EINVAL); 660 } 661 662 /* 663 * We have to copy out the GDT entry we use. 664 * 665 * XXX: What if a user space program does not check the return value 666 * and tries to use 6, 7 or 8? 667 */ 668 error = copyout(&info, args->desc, sizeof(struct l_user_desc)); 669 if (error) 670 return (error); 671 672 pcb = td->td_pcb; 673 update_pcb_bases(pcb); 674 pcb->pcb_gsbase = (register_t)info.base_addr; 675 update_gdt_gsbase(td, info.base_addr); 676 677 return (0); 678 } 679 680 void 681 bsd_to_linux_regset32(const struct reg32 *b_reg, 682 struct linux_pt_regset32 *l_regset) 683 { 684 685 l_regset->ebx = b_reg->r_ebx; 686 l_regset->ecx = b_reg->r_ecx; 687 l_regset->edx = b_reg->r_edx; 688 l_regset->esi = b_reg->r_esi; 689 l_regset->edi = b_reg->r_edi; 690 l_regset->ebp = b_reg->r_ebp; 691 l_regset->eax = b_reg->r_eax; 692 l_regset->ds = b_reg->r_ds; 693 l_regset->es = b_reg->r_es; 694 l_regset->fs = b_reg->r_fs; 695 l_regset->gs = b_reg->r_gs; 696 l_regset->orig_eax = b_reg->r_eax; 697 l_regset->eip = b_reg->r_eip; 698 l_regset->cs = b_reg->r_cs; 699 l_regset->eflags = b_reg->r_eflags; 700 l_regset->esp = b_reg->r_esp; 701 l_regset->ss = b_reg->r_ss; 702 } 703 704 int futex_xchgl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 705 int futex_xchgl_smap(int oparg, uint32_t *uaddr, int *oldval); 706 DEFINE_IFUNC(, int, futex_xchgl, (int, uint32_t *, int *)) 707 { 708 709 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 710 futex_xchgl_smap : futex_xchgl_nosmap); 711 } 712 713 int futex_addl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 714 int futex_addl_smap(int oparg, uint32_t *uaddr, int *oldval); 715 DEFINE_IFUNC(, int, futex_addl, (int, uint32_t *, int *)) 716 { 717 718 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 719 futex_addl_smap : futex_addl_nosmap); 720 } 721 722 int futex_orl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 723 int futex_orl_smap(int oparg, uint32_t *uaddr, int *oldval); 724 DEFINE_IFUNC(, int, futex_orl, (int, uint32_t *, int *)) 725 { 726 727 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 728 futex_orl_smap : futex_orl_nosmap); 729 } 730 731 int futex_andl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 732 int futex_andl_smap(int oparg, uint32_t *uaddr, int *oldval); 733 DEFINE_IFUNC(, int, futex_andl, (int, uint32_t *, int *)) 734 { 735 736 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 737 futex_andl_smap : futex_andl_nosmap); 738 } 739 740 int futex_xorl_nosmap(int oparg, uint32_t *uaddr, int *oldval); 741 int futex_xorl_smap(int oparg, uint32_t *uaddr, int *oldval); 742 DEFINE_IFUNC(, int, futex_xorl, (int, uint32_t *, int *)) 743 { 744 745 return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? 746 futex_xorl_smap : futex_xorl_nosmap); 747 } 748