linux_machdep.c revision 195074
1104476Ssam/*- 2139825Simp * Copyright (c) 2000 Marcel Moolenaar 3104476Ssam * All rights reserved. 4104476Ssam * 5104476Ssam * Redistribution and use in source and binary forms, with or without 6104476Ssam * modification, are permitted provided that the following conditions 7104476Ssam * are met: 8104476Ssam * 1. Redistributions of source code must retain the above copyright 9104476Ssam * notice, this list of conditions and the following disclaimer 10104476Ssam * in this position and unchanged. 11104476Ssam * 2. Redistributions in binary form must reproduce the above copyright 12104476Ssam * notice, this list of conditions and the following disclaimer in the 13104476Ssam * documentation and/or other materials provided with the distribution. 14104476Ssam * 3. The name of the author may not be used to endorse or promote products 15104476Ssam * derived from this software without specific prior written permission. 16104476Ssam * 17104476Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18104476Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19104476Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20104476Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21104476Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22104476Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23104476Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24104476Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25116191Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26104476Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27104476Ssam */ 28104476Ssam 29104476Ssam#include <sys/cdefs.h> 30104476Ssam__FBSDID("$FreeBSD: head/sys/i386/linux/linux_machdep.c 195074 2009-06-26 19:39:33Z jhb $"); 31116191Sobrien 32116191Sobrien#include <sys/param.h> 33116191Sobrien#include <sys/systm.h> 34116191Sobrien#include <sys/file.h> 35104476Ssam#include <sys/fcntl.h> 36104476Ssam#include <sys/imgact.h> 37104476Ssam#include <sys/lock.h> 38104476Ssam#include <sys/malloc.h> 39104476Ssam#include <sys/mman.h> 40104476Ssam#include <sys/mutex.h> 41104476Ssam#include <sys/sx.h> 42104476Ssam#include <sys/priv.h> 43104476Ssam#include <sys/proc.h> 44104476Ssam#include <sys/queue.h> 45104476Ssam#include <sys/resource.h> 46104476Ssam#include <sys/resourcevar.h> 47104476Ssam#include <sys/signalvar.h> 48104476Ssam#include <sys/syscallsubr.h> 49104476Ssam#include <sys/sysproto.h> 50104476Ssam#include <sys/unistd.h> 51104476Ssam#include <sys/wait.h> 52104476Ssam#include <sys/sched.h> 53104476Ssam 54104476Ssam#include <machine/frame.h> 55104476Ssam#include <machine/psl.h> 56104476Ssam#include <machine/segments.h> 57104476Ssam#include <machine/sysarch.h> 58104476Ssam 59104476Ssam#include <vm/vm.h> 60104476Ssam#include <vm/pmap.h> 61104476Ssam#include <vm/vm_map.h> 62104476Ssam 63104476Ssam#include <i386/linux/linux.h> 64104476Ssam#include <i386/linux/linux_proto.h> 65104476Ssam#include <compat/linux/linux_ipc.h> 66104476Ssam#include <compat/linux/linux_signal.h> 67104476Ssam#include <compat/linux/linux_util.h> 68104476Ssam#include <compat/linux/linux_emul.h> 69104476Ssam 70104476Ssam#include <i386/include/pcb.h> /* needed for pcb definition in linux_set_thread_area */ 71104476Ssam 72104476Ssam#include "opt_posix.h" 73104476Ssam 74104476Ssamextern struct sysentvec elf32_freebsd_sysvec; /* defined in i386/i386/elf_machdep.c */ 75104476Ssam 76104476Ssamstruct l_descriptor { 77104476Ssam l_uint entry_number; 78104476Ssam l_ulong base_addr; 79104476Ssam l_uint limit; 80104476Ssam l_uint seg_32bit:1; 81104476Ssam l_uint contents:2; 82104476Ssam l_uint read_exec_only:1; 83104476Ssam l_uint limit_in_pages:1; 84104476Ssam l_uint seg_not_present:1; 85104476Ssam l_uint useable:1; 86104476Ssam}; 87104476Ssam 88104476Ssamstruct l_old_select_argv { 89104476Ssam l_int nfds; 90104476Ssam l_fd_set *readfds; 91104476Ssam l_fd_set *writefds; 92104476Ssam l_fd_set *exceptfds; 93104476Ssam struct l_timeval *timeout; 94104476Ssam}; 95104476Ssam 96104476Ssamint 97104476Ssamlinux_to_bsd_sigaltstack(int lsa) 98104476Ssam{ 99104476Ssam int bsa = 0; 100104476Ssam 101104476Ssam if (lsa & LINUX_SS_DISABLE) 102104476Ssam bsa |= SS_DISABLE; 103104476Ssam if (lsa & LINUX_SS_ONSTACK) 104104476Ssam bsa |= SS_ONSTACK; 105104476Ssam return (bsa); 106104476Ssam} 107104476Ssam 108104476Ssamint 109104476Ssambsd_to_linux_sigaltstack(int bsa) 110104476Ssam{ 111104476Ssam int lsa = 0; 112104476Ssam 113104476Ssam if (bsa & SS_DISABLE) 114104476Ssam lsa |= LINUX_SS_DISABLE; 115104476Ssam if (bsa & SS_ONSTACK) 116104476Ssam lsa |= LINUX_SS_ONSTACK; 117104476Ssam return (lsa); 118104476Ssam} 119104476Ssam 120104476Ssamint 121104476Ssamlinux_execve(struct thread *td, struct linux_execve_args *args) 122104476Ssam{ 123104476Ssam int error; 124104476Ssam char *newpath; 125104476Ssam struct image_args eargs; 126104476Ssam 127104476Ssam LCONVPATHEXIST(td, args->path, &newpath); 128104476Ssam 129104476Ssam#ifdef DEBUG 130104476Ssam if (ldebug(execve)) 131104476Ssam printf(ARGS(execve, "%s"), newpath); 132104476Ssam#endif 133104476Ssam 134104476Ssam error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE, 135104476Ssam args->argp, args->envp); 136104476Ssam free(newpath, M_TEMP); 137104476Ssam if (error == 0) 138104476Ssam error = kern_execve(td, &eargs, NULL); 139104476Ssam if (error == 0) 140104476Ssam /* linux process can exec fbsd one, dont attempt 141104476Ssam * to create emuldata for such process using 142104476Ssam * linux_proc_init, this leads to a panic on KASSERT 143104476Ssam * because such process has p->p_emuldata == NULL 144104476Ssam */ 145104476Ssam if (td->td_proc->p_sysent == &elf_linux_sysvec) 146104476Ssam error = linux_proc_init(td, 0, 0); 147104476Ssam return (error); 148104476Ssam} 149104476Ssam 150104476Ssamstruct l_ipc_kludge { 151104476Ssam struct l_msgbuf *msgp; 152104476Ssam l_long msgtyp; 153104476Ssam}; 154104476Ssam 155104476Ssamint 156104476Ssamlinux_ipc(struct thread *td, struct linux_ipc_args *args) 157104476Ssam{ 158104476Ssam 159104476Ssam switch (args->what & 0xFFFF) { 160104476Ssam case LINUX_SEMOP: { 161104476Ssam struct linux_semop_args a; 162104476Ssam 163104476Ssam a.semid = args->arg1; 164104476Ssam a.tsops = args->ptr; 165104476Ssam a.nsops = args->arg2; 166104476Ssam return (linux_semop(td, &a)); 167104476Ssam } 168104476Ssam case LINUX_SEMGET: { 169104476Ssam struct linux_semget_args a; 170104476Ssam 171104476Ssam a.key = args->arg1; 172104476Ssam a.nsems = args->arg2; 173104476Ssam a.semflg = args->arg3; 174104476Ssam return (linux_semget(td, &a)); 175104476Ssam } 176104476Ssam case LINUX_SEMCTL: { 177104476Ssam struct linux_semctl_args a; 178104476Ssam int error; 179104476Ssam 180104476Ssam a.semid = args->arg1; 181104476Ssam a.semnum = args->arg2; 182104476Ssam a.cmd = args->arg3; 183104476Ssam error = copyin(args->ptr, &a.arg, sizeof(a.arg)); 184104476Ssam if (error) 185104476Ssam return (error); 186104476Ssam return (linux_semctl(td, &a)); 187104476Ssam } 188104476Ssam case LINUX_MSGSND: { 189104476Ssam struct linux_msgsnd_args a; 190104476Ssam 191104476Ssam a.msqid = args->arg1; 192104476Ssam a.msgp = args->ptr; 193104476Ssam a.msgsz = args->arg2; 194104476Ssam a.msgflg = args->arg3; 195104476Ssam return (linux_msgsnd(td, &a)); 196104476Ssam } 197104476Ssam case LINUX_MSGRCV: { 198104476Ssam struct linux_msgrcv_args a; 199104476Ssam 200104476Ssam a.msqid = args->arg1; 201104476Ssam a.msgsz = args->arg2; 202104476Ssam a.msgflg = args->arg3; 203104476Ssam if ((args->what >> 16) == 0) { 204104476Ssam struct l_ipc_kludge tmp; 205104476Ssam int error; 206104476Ssam 207104476Ssam if (args->ptr == NULL) 208104476Ssam return (EINVAL); 209104476Ssam error = copyin(args->ptr, &tmp, sizeof(tmp)); 210104476Ssam if (error) 211104476Ssam return (error); 212104476Ssam a.msgp = tmp.msgp; 213104476Ssam a.msgtyp = tmp.msgtyp; 214104476Ssam } else { 215104476Ssam a.msgp = args->ptr; 216104476Ssam a.msgtyp = args->arg5; 217104476Ssam } 218104476Ssam return (linux_msgrcv(td, &a)); 219104476Ssam } 220104476Ssam case LINUX_MSGGET: { 221104476Ssam struct linux_msgget_args a; 222104476Ssam 223104476Ssam a.key = args->arg1; 224104476Ssam a.msgflg = args->arg2; 225104476Ssam return (linux_msgget(td, &a)); 226104476Ssam } 227104476Ssam case LINUX_MSGCTL: { 228104476Ssam struct linux_msgctl_args a; 229104476Ssam 230104476Ssam a.msqid = args->arg1; 231104476Ssam a.cmd = args->arg2; 232104476Ssam a.buf = args->ptr; 233104476Ssam return (linux_msgctl(td, &a)); 234104476Ssam } 235104476Ssam case LINUX_SHMAT: { 236104476Ssam struct linux_shmat_args a; 237104476Ssam 238104476Ssam a.shmid = args->arg1; 239104476Ssam a.shmaddr = args->ptr; 240104476Ssam a.shmflg = args->arg2; 241104476Ssam a.raddr = (l_ulong *)args->arg3; 242104476Ssam return (linux_shmat(td, &a)); 243104476Ssam } 244104476Ssam case LINUX_SHMDT: { 245104476Ssam struct linux_shmdt_args a; 246104476Ssam 247104476Ssam a.shmaddr = args->ptr; 248104476Ssam return (linux_shmdt(td, &a)); 249104476Ssam } 250104476Ssam case LINUX_SHMGET: { 251104476Ssam struct linux_shmget_args a; 252104476Ssam 253104476Ssam a.key = args->arg1; 254104476Ssam a.size = args->arg2; 255104476Ssam a.shmflg = args->arg3; 256104476Ssam return (linux_shmget(td, &a)); 257104476Ssam } 258104476Ssam case LINUX_SHMCTL: { 259104476Ssam struct linux_shmctl_args a; 260104476Ssam 261104476Ssam a.shmid = args->arg1; 262104476Ssam a.cmd = args->arg2; 263104476Ssam a.buf = args->ptr; 264104476Ssam return (linux_shmctl(td, &a)); 265104476Ssam } 266104476Ssam default: 267104476Ssam break; 268104476Ssam } 269104476Ssam 270104476Ssam return (EINVAL); 271104476Ssam} 272104476Ssam 273104476Ssamint 274104476Ssamlinux_old_select(struct thread *td, struct linux_old_select_args *args) 275104476Ssam{ 276104476Ssam struct l_old_select_argv linux_args; 277104476Ssam struct linux_select_args newsel; 278104476Ssam int error; 279104476Ssam 280104476Ssam#ifdef DEBUG 281104476Ssam if (ldebug(old_select)) 282104476Ssam printf(ARGS(old_select, "%p"), args->ptr); 283104476Ssam#endif 284104476Ssam 285104476Ssam error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 286104476Ssam if (error) 287104476Ssam return (error); 288104476Ssam 289104476Ssam newsel.nfds = linux_args.nfds; 290104476Ssam newsel.readfds = linux_args.readfds; 291104476Ssam newsel.writefds = linux_args.writefds; 292104476Ssam newsel.exceptfds = linux_args.exceptfds; 293104476Ssam newsel.timeout = linux_args.timeout; 294104476Ssam return (linux_select(td, &newsel)); 295104476Ssam} 296104476Ssam 297104476Ssamint 298104476Ssamlinux_fork(struct thread *td, struct linux_fork_args *args) 299104476Ssam{ 300104476Ssam int error; 301104476Ssam struct proc *p2; 302104476Ssam struct thread *td2; 303104476Ssam 304104476Ssam#ifdef DEBUG 305104476Ssam if (ldebug(fork)) 306104476Ssam printf(ARGS(fork, "")); 307104476Ssam#endif 308104476Ssam 309104476Ssam if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2)) != 0) 310104476Ssam return (error); 311104476Ssam 312104476Ssam if (error == 0) { 313104476Ssam td->td_retval[0] = p2->p_pid; 314104476Ssam td->td_retval[1] = 0; 315104476Ssam } 316104476Ssam 317104476Ssam if (td->td_retval[1] == 1) 318104476Ssam td->td_retval[0] = 0; 319104476Ssam error = linux_proc_init(td, td->td_retval[0], 0); 320104476Ssam if (error) 321104476Ssam return (error); 322104476Ssam 323104476Ssam td2 = FIRST_THREAD_IN_PROC(p2); 324104476Ssam 325104476Ssam /* 326104476Ssam * Make this runnable after we are finished with it. 327104476Ssam */ 328104476Ssam thread_lock(td2); 329104476Ssam TD_SET_CAN_RUN(td2); 330104476Ssam sched_add(td2, SRQ_BORING); 331104476Ssam thread_unlock(td2); 332104476Ssam 333104476Ssam return (0); 334104476Ssam} 335104476Ssam 336104476Ssamint 337104476Ssamlinux_vfork(struct thread *td, struct linux_vfork_args *args) 338104476Ssam{ 339104476Ssam int error; 340104476Ssam struct proc *p2; 341104476Ssam struct thread *td2; 342104476Ssam 343104476Ssam#ifdef DEBUG 344104476Ssam if (ldebug(vfork)) 345104476Ssam printf(ARGS(vfork, "")); 346104476Ssam#endif 347104476Ssam 348104476Ssam /* exclude RFPPWAIT */ 349104476Ssam if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2)) != 0) 350104476Ssam return (error); 351104476Ssam if (error == 0) { 352104476Ssam td->td_retval[0] = p2->p_pid; 353104476Ssam td->td_retval[1] = 0; 354104476Ssam } 355104476Ssam /* Are we the child? */ 356104476Ssam if (td->td_retval[1] == 1) 357104476Ssam td->td_retval[0] = 0; 358104476Ssam error = linux_proc_init(td, td->td_retval[0], 0); 359104476Ssam if (error) 360104476Ssam return (error); 361104476Ssam 362104476Ssam PROC_LOCK(p2); 363104476Ssam p2->p_flag |= P_PPWAIT; 364104476Ssam PROC_UNLOCK(p2); 365104476Ssam 366104476Ssam td2 = FIRST_THREAD_IN_PROC(p2); 367104476Ssam 368 /* 369 * Make this runnable after we are finished with it. 370 */ 371 thread_lock(td2); 372 TD_SET_CAN_RUN(td2); 373 sched_add(td2, SRQ_BORING); 374 thread_unlock(td2); 375 376 /* wait for the children to exit, ie. emulate vfork */ 377 PROC_LOCK(p2); 378 while (p2->p_flag & P_PPWAIT) 379 cv_wait(&p2->p_pwait, &p2->p_mtx); 380 PROC_UNLOCK(p2); 381 382 return (0); 383} 384 385int 386linux_clone(struct thread *td, struct linux_clone_args *args) 387{ 388 int error, ff = RFPROC | RFSTOPPED; 389 struct proc *p2; 390 struct thread *td2; 391 int exit_signal; 392 struct linux_emuldata *em; 393 394#ifdef DEBUG 395 if (ldebug(clone)) { 396 printf(ARGS(clone, "flags %x, stack %x, parent tid: %x, child tid: %x"), 397 (unsigned int)args->flags, (unsigned int)args->stack, 398 (unsigned int)args->parent_tidptr, (unsigned int)args->child_tidptr); 399 } 400#endif 401 402 exit_signal = args->flags & 0x000000ff; 403 if (LINUX_SIG_VALID(exit_signal)) { 404 if (exit_signal <= LINUX_SIGTBLSZ) 405 exit_signal = 406 linux_to_bsd_signal[_SIG_IDX(exit_signal)]; 407 } else if (exit_signal != 0) 408 return (EINVAL); 409 410 if (args->flags & LINUX_CLONE_VM) 411 ff |= RFMEM; 412 if (args->flags & LINUX_CLONE_SIGHAND) 413 ff |= RFSIGSHARE; 414 /* 415 * XXX: in linux sharing of fs info (chroot/cwd/umask) 416 * and open files is independant. in fbsd its in one 417 * structure but in reality it doesn't cause any problems 418 * because both of these flags are usually set together. 419 */ 420 if (!(args->flags & (LINUX_CLONE_FILES | LINUX_CLONE_FS))) 421 ff |= RFFDG; 422 423 /* 424 * Attempt to detect when linux_clone(2) is used for creating 425 * kernel threads. Unfortunately despite the existence of the 426 * CLONE_THREAD flag, version of linuxthreads package used in 427 * most popular distros as of beginning of 2005 doesn't make 428 * any use of it. Therefore, this detection relies on 429 * empirical observation that linuxthreads sets certain 430 * combination of flags, so that we can make more or less 431 * precise detection and notify the FreeBSD kernel that several 432 * processes are in fact part of the same threading group, so 433 * that special treatment is necessary for signal delivery 434 * between those processes and fd locking. 435 */ 436 if ((args->flags & 0xffffff00) == LINUX_THREADING_FLAGS) 437 ff |= RFTHREAD; 438 439 if (args->flags & LINUX_CLONE_PARENT_SETTID) 440 if (args->parent_tidptr == NULL) 441 return (EINVAL); 442 443 error = fork1(td, ff, 0, &p2); 444 if (error) 445 return (error); 446 447 if (args->flags & (LINUX_CLONE_PARENT | LINUX_CLONE_THREAD)) { 448 sx_xlock(&proctree_lock); 449 PROC_LOCK(p2); 450 proc_reparent(p2, td->td_proc->p_pptr); 451 PROC_UNLOCK(p2); 452 sx_xunlock(&proctree_lock); 453 } 454 455 /* create the emuldata */ 456 error = linux_proc_init(td, p2->p_pid, args->flags); 457 /* reference it - no need to check this */ 458 em = em_find(p2, EMUL_DOLOCK); 459 KASSERT(em != NULL, ("clone: emuldata not found.\n")); 460 /* and adjust it */ 461 462 if (args->flags & LINUX_CLONE_THREAD) { 463 /* XXX: linux mangles pgrp and pptr somehow 464 * I think it might be this but I am not sure. 465 */ 466#ifdef notyet 467 PROC_LOCK(p2); 468 p2->p_pgrp = td->td_proc->p_pgrp; 469 PROC_UNLOCK(p2); 470#endif 471 exit_signal = 0; 472 } 473 474 if (args->flags & LINUX_CLONE_CHILD_SETTID) 475 em->child_set_tid = args->child_tidptr; 476 else 477 em->child_set_tid = NULL; 478 479 if (args->flags & LINUX_CLONE_CHILD_CLEARTID) 480 em->child_clear_tid = args->child_tidptr; 481 else 482 em->child_clear_tid = NULL; 483 484 EMUL_UNLOCK(&emul_lock); 485 486 if (args->flags & LINUX_CLONE_PARENT_SETTID) { 487 error = copyout(&p2->p_pid, args->parent_tidptr, sizeof(p2->p_pid)); 488 if (error) 489 printf(LMSG("copyout failed!")); 490 } 491 492 PROC_LOCK(p2); 493 p2->p_sigparent = exit_signal; 494 PROC_UNLOCK(p2); 495 td2 = FIRST_THREAD_IN_PROC(p2); 496 /* 497 * in a case of stack = NULL we are supposed to COW calling process stack 498 * this is what normal fork() does so we just keep the tf_esp arg intact 499 */ 500 if (args->stack) 501 td2->td_frame->tf_esp = (unsigned int)args->stack; 502 503 if (args->flags & LINUX_CLONE_SETTLS) { 504 struct l_user_desc info; 505 int idx; 506 int a[2]; 507 struct segment_descriptor sd; 508 509 error = copyin((void *)td->td_frame->tf_esi, &info, sizeof(struct l_user_desc)); 510 if (error) { 511 printf(LMSG("copyin failed!")); 512 } else { 513 514 idx = info.entry_number; 515 516 /* 517 * looks like we're getting the idx we returned 518 * in the set_thread_area() syscall 519 */ 520 if (idx != 6 && idx != 3) { 521 printf(LMSG("resetting idx!")); 522 idx = 3; 523 } 524 525 /* this doesnt happen in practice */ 526 if (idx == 6) { 527 /* we might copy out the entry_number as 3 */ 528 info.entry_number = 3; 529 error = copyout(&info, (void *) td->td_frame->tf_esi, sizeof(struct l_user_desc)); 530 if (error) 531 printf(LMSG("copyout failed!")); 532 } 533 534 a[0] = LINUX_LDT_entry_a(&info); 535 a[1] = LINUX_LDT_entry_b(&info); 536 537 memcpy(&sd, &a, sizeof(a)); 538#ifdef DEBUG 539 if (ldebug(clone)) 540 printf("Segment created in clone with CLONE_SETTLS: lobase: %x, hibase: %x, lolimit: %x, hilimit: %x, type: %i, dpl: %i, p: %i, xx: %i, def32: %i, gran: %i\n", sd.sd_lobase, 541 sd.sd_hibase, 542 sd.sd_lolimit, 543 sd.sd_hilimit, 544 sd.sd_type, 545 sd.sd_dpl, 546 sd.sd_p, 547 sd.sd_xx, 548 sd.sd_def32, 549 sd.sd_gran); 550#endif 551 552 /* set %gs */ 553 td2->td_pcb->pcb_gsd = sd; 554 td2->td_pcb->pcb_gs = GSEL(GUGS_SEL, SEL_UPL); 555 } 556 } 557 558#ifdef DEBUG 559 if (ldebug(clone)) 560 printf(LMSG("clone: successful rfork to %ld, stack %p sig = %d"), 561 (long)p2->p_pid, args->stack, exit_signal); 562#endif 563 if (args->flags & LINUX_CLONE_VFORK) { 564 PROC_LOCK(p2); 565 p2->p_flag |= P_PPWAIT; 566 PROC_UNLOCK(p2); 567 } 568 569 /* 570 * Make this runnable after we are finished with it. 571 */ 572 thread_lock(td2); 573 TD_SET_CAN_RUN(td2); 574 sched_add(td2, SRQ_BORING); 575 thread_unlock(td2); 576 577 td->td_retval[0] = p2->p_pid; 578 td->td_retval[1] = 0; 579 580 if (args->flags & LINUX_CLONE_VFORK) { 581 /* wait for the children to exit, ie. emulate vfork */ 582 PROC_LOCK(p2); 583 while (p2->p_flag & P_PPWAIT) 584 cv_wait(&p2->p_pwait, &p2->p_mtx); 585 PROC_UNLOCK(p2); 586 } 587 588 return (0); 589} 590 591#define STACK_SIZE (2 * 1024 * 1024) 592#define GUARD_SIZE (4 * PAGE_SIZE) 593 594static int linux_mmap_common(struct thread *, struct l_mmap_argv *); 595 596int 597linux_mmap2(struct thread *td, struct linux_mmap2_args *args) 598{ 599 struct l_mmap_argv linux_args; 600 601#ifdef DEBUG 602 if (ldebug(mmap2)) 603 printf(ARGS(mmap2, "%p, %d, %d, 0x%08x, %d, %d"), 604 (void *)args->addr, args->len, args->prot, 605 args->flags, args->fd, args->pgoff); 606#endif 607 608 linux_args.addr = args->addr; 609 linux_args.len = args->len; 610 linux_args.prot = args->prot; 611 linux_args.flags = args->flags; 612 linux_args.fd = args->fd; 613 linux_args.pgoff = args->pgoff * PAGE_SIZE; 614 615 return (linux_mmap_common(td, &linux_args)); 616} 617 618int 619linux_mmap(struct thread *td, struct linux_mmap_args *args) 620{ 621 int error; 622 struct l_mmap_argv linux_args; 623 624 error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 625 if (error) 626 return (error); 627 628#ifdef DEBUG 629 if (ldebug(mmap)) 630 printf(ARGS(mmap, "%p, %d, %d, 0x%08x, %d, %d"), 631 (void *)linux_args.addr, linux_args.len, linux_args.prot, 632 linux_args.flags, linux_args.fd, linux_args.pgoff); 633#endif 634 635 return (linux_mmap_common(td, &linux_args)); 636} 637 638static int 639linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args) 640{ 641 struct proc *p = td->td_proc; 642 struct mmap_args /* { 643 caddr_t addr; 644 size_t len; 645 int prot; 646 int flags; 647 int fd; 648 long pad; 649 off_t pos; 650 } */ bsd_args; 651 int error; 652 struct file *fp; 653 654 error = 0; 655 bsd_args.flags = 0; 656 fp = NULL; 657 658 /* 659 * Linux mmap(2): 660 * You must specify exactly one of MAP_SHARED and MAP_PRIVATE 661 */ 662 if (! ((linux_args->flags & LINUX_MAP_SHARED) ^ 663 (linux_args->flags & LINUX_MAP_PRIVATE))) 664 return (EINVAL); 665 666 if (linux_args->flags & LINUX_MAP_SHARED) 667 bsd_args.flags |= MAP_SHARED; 668 if (linux_args->flags & LINUX_MAP_PRIVATE) 669 bsd_args.flags |= MAP_PRIVATE; 670 if (linux_args->flags & LINUX_MAP_FIXED) 671 bsd_args.flags |= MAP_FIXED; 672 if (linux_args->flags & LINUX_MAP_ANON) 673 bsd_args.flags |= MAP_ANON; 674 else 675 bsd_args.flags |= MAP_NOSYNC; 676 if (linux_args->flags & LINUX_MAP_GROWSDOWN) 677 bsd_args.flags |= MAP_STACK; 678 679 /* 680 * PROT_READ, PROT_WRITE, or PROT_EXEC implies PROT_READ and PROT_EXEC 681 * on Linux/i386. We do this to ensure maximum compatibility. 682 * Linux/ia64 does the same in i386 emulation mode. 683 */ 684 bsd_args.prot = linux_args->prot; 685 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) 686 bsd_args.prot |= PROT_READ | PROT_EXEC; 687 688 /* Linux does not check file descriptor when MAP_ANONYMOUS is set. */ 689 bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : linux_args->fd; 690 if (bsd_args.fd != -1) { 691 /* 692 * Linux follows Solaris mmap(2) description: 693 * The file descriptor fildes is opened with 694 * read permission, regardless of the 695 * protection options specified. 696 */ 697 698 if ((error = fget(td, bsd_args.fd, &fp)) != 0) 699 return (error); 700 if (fp->f_type != DTYPE_VNODE) { 701 fdrop(fp, td); 702 return (EINVAL); 703 } 704 705 /* Linux mmap() just fails for O_WRONLY files */ 706 if (!(fp->f_flag & FREAD)) { 707 fdrop(fp, td); 708 return (EACCES); 709 } 710 711 fdrop(fp, td); 712 } 713 714 if (linux_args->flags & LINUX_MAP_GROWSDOWN) { 715 /* 716 * The linux MAP_GROWSDOWN option does not limit auto 717 * growth of the region. Linux mmap with this option 718 * takes as addr the inital BOS, and as len, the initial 719 * region size. It can then grow down from addr without 720 * limit. However, linux threads has an implicit internal 721 * limit to stack size of STACK_SIZE. Its just not 722 * enforced explicitly in linux. But, here we impose 723 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack 724 * region, since we can do this with our mmap. 725 * 726 * Our mmap with MAP_STACK takes addr as the maximum 727 * downsize limit on BOS, and as len the max size of 728 * the region. It them maps the top SGROWSIZ bytes, 729 * and auto grows the region down, up to the limit 730 * in addr. 731 * 732 * If we don't use the MAP_STACK option, the effect 733 * of this code is to allocate a stack region of a 734 * fixed size of (STACK_SIZE - GUARD_SIZE). 735 */ 736 737 if ((caddr_t)PTRIN(linux_args->addr) + linux_args->len > 738 p->p_vmspace->vm_maxsaddr) { 739 /* 740 * Some linux apps will attempt to mmap 741 * thread stacks near the top of their 742 * address space. If their TOS is greater 743 * than vm_maxsaddr, vm_map_growstack() 744 * will confuse the thread stack with the 745 * process stack and deliver a SEGV if they 746 * attempt to grow the thread stack past their 747 * current stacksize rlimit. To avoid this, 748 * adjust vm_maxsaddr upwards to reflect 749 * the current stacksize rlimit rather 750 * than the maximum possible stacksize. 751 * It would be better to adjust the 752 * mmap'ed region, but some apps do not check 753 * mmap's return value. 754 */ 755 PROC_LOCK(p); 756 p->p_vmspace->vm_maxsaddr = (char *)USRSTACK - 757 lim_cur(p, RLIMIT_STACK); 758 PROC_UNLOCK(p); 759 } 760 761 /* 762 * This gives us our maximum stack size and a new BOS. 763 * If we're using VM_STACK, then mmap will just map 764 * the top SGROWSIZ bytes, and let the stack grow down 765 * to the limit at BOS. If we're not using VM_STACK 766 * we map the full stack, since we don't have a way 767 * to autogrow it. 768 */ 769 if (linux_args->len > STACK_SIZE - GUARD_SIZE) { 770 bsd_args.addr = (caddr_t)PTRIN(linux_args->addr); 771 bsd_args.len = linux_args->len; 772 } else { 773 bsd_args.addr = (caddr_t)PTRIN(linux_args->addr) - 774 (STACK_SIZE - GUARD_SIZE - linux_args->len); 775 bsd_args.len = STACK_SIZE - GUARD_SIZE; 776 } 777 } else { 778 bsd_args.addr = (caddr_t)PTRIN(linux_args->addr); 779 bsd_args.len = linux_args->len; 780 } 781 bsd_args.pos = linux_args->pgoff; 782 783#ifdef DEBUG 784 if (ldebug(mmap)) 785 printf("-> %s(%p, %d, %d, 0x%08x, %d, 0x%x)\n", 786 __func__, 787 (void *)bsd_args.addr, bsd_args.len, bsd_args.prot, 788 bsd_args.flags, bsd_args.fd, (int)bsd_args.pos); 789#endif 790 error = mmap(td, &bsd_args); 791#ifdef DEBUG 792 if (ldebug(mmap)) 793 printf("-> %s() return: 0x%x (0x%08x)\n", 794 __func__, error, (u_int)td->td_retval[0]); 795#endif 796 return (error); 797} 798 799int 800linux_mprotect(struct thread *td, struct linux_mprotect_args *uap) 801{ 802 struct mprotect_args bsd_args; 803 804 bsd_args.addr = uap->addr; 805 bsd_args.len = uap->len; 806 bsd_args.prot = uap->prot; 807 if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) 808 bsd_args.prot |= PROT_READ | PROT_EXEC; 809 return (mprotect(td, &bsd_args)); 810} 811 812int 813linux_pipe(struct thread *td, struct linux_pipe_args *args) 814{ 815 int error; 816 int fildes[2]; 817 818#ifdef DEBUG 819 if (ldebug(pipe)) 820 printf(ARGS(pipe, "*")); 821#endif 822 823 error = kern_pipe(td, fildes); 824 if (error) 825 return (error); 826 827 /* XXX: Close descriptors on error. */ 828 return (copyout(fildes, args->pipefds, sizeof fildes)); 829} 830 831int 832linux_ioperm(struct thread *td, struct linux_ioperm_args *args) 833{ 834 int error; 835 struct i386_ioperm_args iia; 836 837 iia.start = args->start; 838 iia.length = args->length; 839 iia.enable = args->enable; 840 error = i386_set_ioperm(td, &iia); 841 return (error); 842} 843 844int 845linux_iopl(struct thread *td, struct linux_iopl_args *args) 846{ 847 int error; 848 849 if (args->level < 0 || args->level > 3) 850 return (EINVAL); 851 if ((error = priv_check(td, PRIV_IO)) != 0) 852 return (error); 853 if ((error = securelevel_gt(td->td_ucred, 0)) != 0) 854 return (error); 855 td->td_frame->tf_eflags = (td->td_frame->tf_eflags & ~PSL_IOPL) | 856 (args->level * (PSL_IOPL / 3)); 857 return (0); 858} 859 860int 861linux_modify_ldt(struct thread *td, struct linux_modify_ldt_args *uap) 862{ 863 int error; 864 struct i386_ldt_args ldt; 865 struct l_descriptor ld; 866 union descriptor desc; 867 int size, written; 868 869 switch (uap->func) { 870 case 0x00: /* read_ldt */ 871 ldt.start = 0; 872 ldt.descs = uap->ptr; 873 ldt.num = uap->bytecount / sizeof(union descriptor); 874 error = i386_get_ldt(td, &ldt); 875 td->td_retval[0] *= sizeof(union descriptor); 876 break; 877 case 0x02: /* read_default_ldt = 0 */ 878 size = 5*sizeof(struct l_desc_struct); 879 if (size > uap->bytecount) 880 size = uap->bytecount; 881 for (written = error = 0; written < size && error == 0; written++) 882 error = subyte((char *)uap->ptr + written, 0); 883 td->td_retval[0] = written; 884 break; 885 case 0x01: /* write_ldt */ 886 case 0x11: /* write_ldt */ 887 if (uap->bytecount != sizeof(ld)) 888 return (EINVAL); 889 890 error = copyin(uap->ptr, &ld, sizeof(ld)); 891 if (error) 892 return (error); 893 894 ldt.start = ld.entry_number; 895 ldt.descs = &desc; 896 ldt.num = 1; 897 desc.sd.sd_lolimit = (ld.limit & 0x0000ffff); 898 desc.sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16; 899 desc.sd.sd_lobase = (ld.base_addr & 0x00ffffff); 900 desc.sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24; 901 desc.sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) | 902 (ld.contents << 2); 903 desc.sd.sd_dpl = 3; 904 desc.sd.sd_p = (ld.seg_not_present ^ 1); 905 desc.sd.sd_xx = 0; 906 desc.sd.sd_def32 = ld.seg_32bit; 907 desc.sd.sd_gran = ld.limit_in_pages; 908 error = i386_set_ldt(td, &ldt, &desc); 909 break; 910 default: 911 error = ENOSYS; 912 break; 913 } 914 915 if (error == EOPNOTSUPP) { 916 printf("linux: modify_ldt needs kernel option USER_LDT\n"); 917 error = ENOSYS; 918 } 919 920 return (error); 921} 922 923int 924linux_sigaction(struct thread *td, struct linux_sigaction_args *args) 925{ 926 l_osigaction_t osa; 927 l_sigaction_t act, oact; 928 int error; 929 930#ifdef DEBUG 931 if (ldebug(sigaction)) 932 printf(ARGS(sigaction, "%d, %p, %p"), 933 args->sig, (void *)args->nsa, (void *)args->osa); 934#endif 935 936 if (args->nsa != NULL) { 937 error = copyin(args->nsa, &osa, sizeof(l_osigaction_t)); 938 if (error) 939 return (error); 940 act.lsa_handler = osa.lsa_handler; 941 act.lsa_flags = osa.lsa_flags; 942 act.lsa_restorer = osa.lsa_restorer; 943 LINUX_SIGEMPTYSET(act.lsa_mask); 944 act.lsa_mask.__bits[0] = osa.lsa_mask; 945 } 946 947 error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL, 948 args->osa ? &oact : NULL); 949 950 if (args->osa != NULL && !error) { 951 osa.lsa_handler = oact.lsa_handler; 952 osa.lsa_flags = oact.lsa_flags; 953 osa.lsa_restorer = oact.lsa_restorer; 954 osa.lsa_mask = oact.lsa_mask.__bits[0]; 955 error = copyout(&osa, args->osa, sizeof(l_osigaction_t)); 956 } 957 958 return (error); 959} 960 961/* 962 * Linux has two extra args, restart and oldmask. We dont use these, 963 * but it seems that "restart" is actually a context pointer that 964 * enables the signal to happen with a different register set. 965 */ 966int 967linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args) 968{ 969 sigset_t sigmask; 970 l_sigset_t mask; 971 972#ifdef DEBUG 973 if (ldebug(sigsuspend)) 974 printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask); 975#endif 976 977 LINUX_SIGEMPTYSET(mask); 978 mask.__bits[0] = args->mask; 979 linux_to_bsd_sigset(&mask, &sigmask); 980 return (kern_sigsuspend(td, sigmask)); 981} 982 983int 984linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap) 985{ 986 l_sigset_t lmask; 987 sigset_t sigmask; 988 int error; 989 990#ifdef DEBUG 991 if (ldebug(rt_sigsuspend)) 992 printf(ARGS(rt_sigsuspend, "%p, %d"), 993 (void *)uap->newset, uap->sigsetsize); 994#endif 995 996 if (uap->sigsetsize != sizeof(l_sigset_t)) 997 return (EINVAL); 998 999 error = copyin(uap->newset, &lmask, sizeof(l_sigset_t)); 1000 if (error) 1001 return (error); 1002 1003 linux_to_bsd_sigset(&lmask, &sigmask); 1004 return (kern_sigsuspend(td, sigmask)); 1005} 1006 1007int 1008linux_pause(struct thread *td, struct linux_pause_args *args) 1009{ 1010 struct proc *p = td->td_proc; 1011 sigset_t sigmask; 1012 1013#ifdef DEBUG 1014 if (ldebug(pause)) 1015 printf(ARGS(pause, "")); 1016#endif 1017 1018 PROC_LOCK(p); 1019 sigmask = td->td_sigmask; 1020 PROC_UNLOCK(p); 1021 return (kern_sigsuspend(td, sigmask)); 1022} 1023 1024int 1025linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap) 1026{ 1027 stack_t ss, oss; 1028 l_stack_t lss; 1029 int error; 1030 1031#ifdef DEBUG 1032 if (ldebug(sigaltstack)) 1033 printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss); 1034#endif 1035 1036 if (uap->uss != NULL) { 1037 error = copyin(uap->uss, &lss, sizeof(l_stack_t)); 1038 if (error) 1039 return (error); 1040 1041 ss.ss_sp = lss.ss_sp; 1042 ss.ss_size = lss.ss_size; 1043 ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags); 1044 } 1045 error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL, 1046 (uap->uoss != NULL) ? &oss : NULL); 1047 if (!error && uap->uoss != NULL) { 1048 lss.ss_sp = oss.ss_sp; 1049 lss.ss_size = oss.ss_size; 1050 lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags); 1051 error = copyout(&lss, uap->uoss, sizeof(l_stack_t)); 1052 } 1053 1054 return (error); 1055} 1056 1057int 1058linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args) 1059{ 1060 struct ftruncate_args sa; 1061 1062#ifdef DEBUG 1063 if (ldebug(ftruncate64)) 1064 printf(ARGS(ftruncate64, "%u, %jd"), args->fd, 1065 (intmax_t)args->length); 1066#endif 1067 1068 sa.fd = args->fd; 1069 sa.length = args->length; 1070 return ftruncate(td, &sa); 1071} 1072 1073int 1074linux_set_thread_area(struct thread *td, struct linux_set_thread_area_args *args) 1075{ 1076 struct l_user_desc info; 1077 int error; 1078 int idx; 1079 int a[2]; 1080 struct segment_descriptor sd; 1081 1082 error = copyin(args->desc, &info, sizeof(struct l_user_desc)); 1083 if (error) 1084 return (error); 1085 1086#ifdef DEBUG 1087 if (ldebug(set_thread_area)) 1088 printf(ARGS(set_thread_area, "%i, %x, %x, %i, %i, %i, %i, %i, %i\n"), 1089 info.entry_number, 1090 info.base_addr, 1091 info.limit, 1092 info.seg_32bit, 1093 info.contents, 1094 info.read_exec_only, 1095 info.limit_in_pages, 1096 info.seg_not_present, 1097 info.useable); 1098#endif 1099 1100 idx = info.entry_number; 1101 /* 1102 * Semantics of linux version: every thread in the system has array of 1103 * 3 tls descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. This 1104 * syscall loads one of the selected tls decriptors with a value and 1105 * also loads GDT descriptors 6, 7 and 8 with the content of the 1106 * per-thread descriptors. 1107 * 1108 * Semantics of fbsd version: I think we can ignore that linux has 3 1109 * per-thread descriptors and use just the 1st one. The tls_array[] 1110 * is used only in set/get-thread_area() syscalls and for loading the 1111 * GDT descriptors. In fbsd we use just one GDT descriptor for TLS so 1112 * we will load just one. 1113 * 1114 * XXX: this doesn't work when a user space process tries to use more 1115 * than 1 TLS segment. Comment in the linux sources says wine might do 1116 * this. 1117 */ 1118 1119 /* 1120 * we support just GLIBC TLS now 1121 * we should let 3 proceed as well because we use this segment so 1122 * if code does two subsequent calls it should succeed 1123 */ 1124 if (idx != 6 && idx != -1 && idx != 3) 1125 return (EINVAL); 1126 1127 /* 1128 * we have to copy out the GDT entry we use 1129 * FreeBSD uses GDT entry #3 for storing %gs so load that 1130 * 1131 * XXX: what if a user space program doesn't check this value and tries 1132 * to use 6, 7 or 8? 1133 */ 1134 idx = info.entry_number = 3; 1135 error = copyout(&info, args->desc, sizeof(struct l_user_desc)); 1136 if (error) 1137 return (error); 1138 1139 if (LINUX_LDT_empty(&info)) { 1140 a[0] = 0; 1141 a[1] = 0; 1142 } else { 1143 a[0] = LINUX_LDT_entry_a(&info); 1144 a[1] = LINUX_LDT_entry_b(&info); 1145 } 1146 1147 memcpy(&sd, &a, sizeof(a)); 1148#ifdef DEBUG 1149 if (ldebug(set_thread_area)) 1150 printf("Segment created in set_thread_area: lobase: %x, hibase: %x, lolimit: %x, hilimit: %x, type: %i, dpl: %i, p: %i, xx: %i, def32: %i, gran: %i\n", sd.sd_lobase, 1151 sd.sd_hibase, 1152 sd.sd_lolimit, 1153 sd.sd_hilimit, 1154 sd.sd_type, 1155 sd.sd_dpl, 1156 sd.sd_p, 1157 sd.sd_xx, 1158 sd.sd_def32, 1159 sd.sd_gran); 1160#endif 1161 1162 /* this is taken from i386 version of cpu_set_user_tls() */ 1163 critical_enter(); 1164 /* set %gs */ 1165 td->td_pcb->pcb_gsd = sd; 1166 PCPU_GET(fsgs_gdt)[1] = sd; 1167 load_gs(GSEL(GUGS_SEL, SEL_UPL)); 1168 critical_exit(); 1169 1170 return (0); 1171} 1172 1173int 1174linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args) 1175{ 1176 1177 struct l_user_desc info; 1178 int error; 1179 int idx; 1180 struct l_desc_struct desc; 1181 struct segment_descriptor sd; 1182 1183#ifdef DEBUG 1184 if (ldebug(get_thread_area)) 1185 printf(ARGS(get_thread_area, "%p"), args->desc); 1186#endif 1187 1188 error = copyin(args->desc, &info, sizeof(struct l_user_desc)); 1189 if (error) 1190 return (error); 1191 1192 idx = info.entry_number; 1193 /* XXX: I am not sure if we want 3 to be allowed too. */ 1194 if (idx != 6 && idx != 3) 1195 return (EINVAL); 1196 1197 idx = 3; 1198 1199 memset(&info, 0, sizeof(info)); 1200 1201 sd = PCPU_GET(fsgs_gdt)[1]; 1202 1203 memcpy(&desc, &sd, sizeof(desc)); 1204 1205 info.entry_number = idx; 1206 info.base_addr = LINUX_GET_BASE(&desc); 1207 info.limit = LINUX_GET_LIMIT(&desc); 1208 info.seg_32bit = LINUX_GET_32BIT(&desc); 1209 info.contents = LINUX_GET_CONTENTS(&desc); 1210 info.read_exec_only = !LINUX_GET_WRITABLE(&desc); 1211 info.limit_in_pages = LINUX_GET_LIMIT_PAGES(&desc); 1212 info.seg_not_present = !LINUX_GET_PRESENT(&desc); 1213 info.useable = LINUX_GET_USEABLE(&desc); 1214 1215 error = copyout(&info, args->desc, sizeof(struct l_user_desc)); 1216 if (error) 1217 return (EFAULT); 1218 1219 return (0); 1220} 1221 1222/* copied from kern/kern_time.c */ 1223int 1224linux_timer_create(struct thread *td, struct linux_timer_create_args *args) 1225{ 1226 return ktimer_create(td, (struct ktimer_create_args *) args); 1227} 1228 1229int 1230linux_timer_settime(struct thread *td, struct linux_timer_settime_args *args) 1231{ 1232 return ktimer_settime(td, (struct ktimer_settime_args *) args); 1233} 1234 1235int 1236linux_timer_gettime(struct thread *td, struct linux_timer_gettime_args *args) 1237{ 1238 return ktimer_gettime(td, (struct ktimer_gettime_args *) args); 1239} 1240 1241int 1242linux_timer_getoverrun(struct thread *td, struct linux_timer_getoverrun_args *args) 1243{ 1244 return ktimer_getoverrun(td, (struct ktimer_getoverrun_args *) args); 1245} 1246 1247int 1248linux_timer_delete(struct thread *td, struct linux_timer_delete_args *args) 1249{ 1250 return ktimer_delete(td, (struct ktimer_delete_args *) args); 1251} 1252 1253/* XXX: this wont work with module - convert it */ 1254int 1255linux_mq_open(struct thread *td, struct linux_mq_open_args *args) 1256{ 1257#ifdef P1003_1B_MQUEUE 1258 return kmq_open(td, (struct kmq_open_args *) args); 1259#else 1260 return (ENOSYS); 1261#endif 1262} 1263 1264int 1265linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args) 1266{ 1267#ifdef P1003_1B_MQUEUE 1268 return kmq_unlink(td, (struct kmq_unlink_args *) args); 1269#else 1270 return (ENOSYS); 1271#endif 1272} 1273 1274int 1275linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args) 1276{ 1277#ifdef P1003_1B_MQUEUE 1278 return kmq_timedsend(td, (struct kmq_timedsend_args *) args); 1279#else 1280 return (ENOSYS); 1281#endif 1282} 1283 1284int 1285linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args) 1286{ 1287#ifdef P1003_1B_MQUEUE 1288 return kmq_timedreceive(td, (struct kmq_timedreceive_args *) args); 1289#else 1290 return (ENOSYS); 1291#endif 1292} 1293 1294int 1295linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args) 1296{ 1297#ifdef P1003_1B_MQUEUE 1298 return kmq_notify(td, (struct kmq_notify_args *) args); 1299#else 1300 return (ENOSYS); 1301#endif 1302} 1303 1304int 1305linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args) 1306{ 1307#ifdef P1003_1B_MQUEUE 1308 return kmq_setattr(td, (struct kmq_setattr_args *) args); 1309#else 1310 return (ENOSYS); 1311#endif 1312} 1313 1314