xref: /freebsd/sys/i386/linux/linux_machdep.c (revision e17f5b1d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2000 Marcel Moolenaar
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #include <sys/param.h>
33 #include <sys/capsicum.h>
34 #include <sys/fcntl.h>
35 #include <sys/file.h>
36 #include <sys/imgact.h>
37 #include <sys/lock.h>
38 #include <sys/malloc.h>
39 #include <sys/mman.h>
40 #include <sys/mutex.h>
41 #include <sys/priv.h>
42 #include <sys/proc.h>
43 #include <sys/queue.h>
44 #include <sys/resource.h>
45 #include <sys/resourcevar.h>
46 #include <sys/sched.h>
47 #include <sys/signalvar.h>
48 #include <sys/syscallsubr.h>
49 #include <sys/sysproto.h>
50 #include <sys/systm.h>
51 #include <sys/sx.h>
52 #include <sys/unistd.h>
53 #include <sys/wait.h>
54 
55 #include <machine/frame.h>
56 #include <machine/psl.h>
57 #include <machine/segments.h>
58 #include <machine/sysarch.h>
59 
60 #include <vm/pmap.h>
61 #include <vm/vm.h>
62 #include <vm/vm_map.h>
63 
64 #include <i386/linux/linux.h>
65 #include <i386/linux/linux_proto.h>
66 #include <compat/linux/linux_emul.h>
67 #include <compat/linux/linux_ipc.h>
68 #include <compat/linux/linux_misc.h>
69 #include <compat/linux/linux_mmap.h>
70 #include <compat/linux/linux_signal.h>
71 #include <compat/linux/linux_util.h>
72 
73 #include <i386/include/pcb.h>			/* needed for pcb definition in linux_set_thread_area */
74 
75 #include "opt_posix.h"
76 
77 extern struct sysentvec elf32_freebsd_sysvec;	/* defined in i386/i386/elf_machdep.c */
78 
79 struct l_descriptor {
80 	l_uint		entry_number;
81 	l_ulong		base_addr;
82 	l_uint		limit;
83 	l_uint		seg_32bit:1;
84 	l_uint		contents:2;
85 	l_uint		read_exec_only:1;
86 	l_uint		limit_in_pages:1;
87 	l_uint		seg_not_present:1;
88 	l_uint		useable:1;
89 };
90 
91 struct l_old_select_argv {
92 	l_int		nfds;
93 	l_fd_set	*readfds;
94 	l_fd_set	*writefds;
95 	l_fd_set	*exceptfds;
96 	struct l_timeval	*timeout;
97 };
98 
99 
100 int
101 linux_execve(struct thread *td, struct linux_execve_args *args)
102 {
103 	struct image_args eargs;
104 	char *newpath;
105 	int error;
106 
107 	LCONVPATHEXIST(td, args->path, &newpath);
108 
109 	error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE,
110 	    args->argp, args->envp);
111 	free(newpath, M_TEMP);
112 	if (error == 0)
113 		error = linux_common_execve(td, &eargs);
114 	return (error);
115 }
116 
117 struct l_ipc_kludge {
118 	struct l_msgbuf *msgp;
119 	l_long msgtyp;
120 };
121 
122 int
123 linux_ipc(struct thread *td, struct linux_ipc_args *args)
124 {
125 
126 	switch (args->what & 0xFFFF) {
127 	case LINUX_SEMOP: {
128 		struct linux_semop_args a;
129 
130 		a.semid = args->arg1;
131 		a.tsops = PTRIN(args->ptr);
132 		a.nsops = args->arg2;
133 		return (linux_semop(td, &a));
134 	}
135 	case LINUX_SEMGET: {
136 		struct linux_semget_args a;
137 
138 		a.key = args->arg1;
139 		a.nsems = args->arg2;
140 		a.semflg = args->arg3;
141 		return (linux_semget(td, &a));
142 	}
143 	case LINUX_SEMCTL: {
144 		struct linux_semctl_args a;
145 		int error;
146 
147 		a.semid = args->arg1;
148 		a.semnum = args->arg2;
149 		a.cmd = args->arg3;
150 		error = copyin(PTRIN(args->ptr), &a.arg, sizeof(a.arg));
151 		if (error)
152 			return (error);
153 		return (linux_semctl(td, &a));
154 	}
155 	case LINUX_MSGSND: {
156 		struct linux_msgsnd_args a;
157 
158 		a.msqid = args->arg1;
159 		a.msgp = PTRIN(args->ptr);
160 		a.msgsz = args->arg2;
161 		a.msgflg = args->arg3;
162 		return (linux_msgsnd(td, &a));
163 	}
164 	case LINUX_MSGRCV: {
165 		struct linux_msgrcv_args a;
166 
167 		a.msqid = args->arg1;
168 		a.msgsz = args->arg2;
169 		a.msgflg = args->arg3;
170 		if ((args->what >> 16) == 0) {
171 			struct l_ipc_kludge tmp;
172 			int error;
173 
174 			if (args->ptr == 0)
175 				return (EINVAL);
176 			error = copyin(PTRIN(args->ptr), &tmp, sizeof(tmp));
177 			if (error)
178 				return (error);
179 			a.msgp = PTRIN(tmp.msgp);
180 			a.msgtyp = tmp.msgtyp;
181 		} else {
182 			a.msgp = PTRIN(args->ptr);
183 			a.msgtyp = args->arg5;
184 		}
185 		return (linux_msgrcv(td, &a));
186 	}
187 	case LINUX_MSGGET: {
188 		struct linux_msgget_args a;
189 
190 		a.key = args->arg1;
191 		a.msgflg = args->arg2;
192 		return (linux_msgget(td, &a));
193 	}
194 	case LINUX_MSGCTL: {
195 		struct linux_msgctl_args a;
196 
197 		a.msqid = args->arg1;
198 		a.cmd = args->arg2;
199 		a.buf = PTRIN(args->ptr);
200 		return (linux_msgctl(td, &a));
201 	}
202 	case LINUX_SHMAT: {
203 		struct linux_shmat_args a;
204 		l_uintptr_t addr;
205 		int error;
206 
207 		a.shmid = args->arg1;
208 		a.shmaddr = PTRIN(args->ptr);
209 		a.shmflg = args->arg2;
210 		error = linux_shmat(td, &a);
211 		if (error != 0)
212 			return (error);
213 		addr = td->td_retval[0];
214 		error = copyout(&addr, PTRIN(args->arg3), sizeof(addr));
215 		td->td_retval[0] = 0;
216 		return (error);
217 	}
218 	case LINUX_SHMDT: {
219 		struct linux_shmdt_args a;
220 
221 		a.shmaddr = PTRIN(args->ptr);
222 		return (linux_shmdt(td, &a));
223 	}
224 	case LINUX_SHMGET: {
225 		struct linux_shmget_args a;
226 
227 		a.key = args->arg1;
228 		a.size = args->arg2;
229 		a.shmflg = args->arg3;
230 		return (linux_shmget(td, &a));
231 	}
232 	case LINUX_SHMCTL: {
233 		struct linux_shmctl_args a;
234 
235 		a.shmid = args->arg1;
236 		a.cmd = args->arg2;
237 		a.buf = PTRIN(args->ptr);
238 		return (linux_shmctl(td, &a));
239 	}
240 	default:
241 		break;
242 	}
243 
244 	return (EINVAL);
245 }
246 
247 int
248 linux_old_select(struct thread *td, struct linux_old_select_args *args)
249 {
250 	struct l_old_select_argv linux_args;
251 	struct linux_select_args newsel;
252 	int error;
253 
254 	error = copyin(args->ptr, &linux_args, sizeof(linux_args));
255 	if (error)
256 		return (error);
257 
258 	newsel.nfds = linux_args.nfds;
259 	newsel.readfds = linux_args.readfds;
260 	newsel.writefds = linux_args.writefds;
261 	newsel.exceptfds = linux_args.exceptfds;
262 	newsel.timeout = linux_args.timeout;
263 	return (linux_select(td, &newsel));
264 }
265 
266 int
267 linux_set_cloned_tls(struct thread *td, void *desc)
268 {
269 	struct segment_descriptor sd;
270 	struct l_user_desc info;
271 	int idx, error;
272 	int a[2];
273 
274 	error = copyin(desc, &info, sizeof(struct l_user_desc));
275 	if (error) {
276 		linux_msg(td, "set_cloned_tls copyin failed!");
277 	} else {
278 		idx = info.entry_number;
279 
280 		/*
281 		 * looks like we're getting the idx we returned
282 		 * in the set_thread_area() syscall
283 		 */
284 		if (idx != 6 && idx != 3) {
285 			linux_msg(td, "set_cloned_tls resetting idx!");
286 			idx = 3;
287 		}
288 
289 		/* this doesnt happen in practice */
290 		if (idx == 6) {
291 			/* we might copy out the entry_number as 3 */
292 			info.entry_number = 3;
293 			error = copyout(&info, desc, sizeof(struct l_user_desc));
294 			if (error)
295 				linux_msg(td, "set_cloned_tls copyout failed!");
296 		}
297 
298 		a[0] = LINUX_LDT_entry_a(&info);
299 		a[1] = LINUX_LDT_entry_b(&info);
300 
301 		memcpy(&sd, &a, sizeof(a));
302 		/* set %gs */
303 		td->td_pcb->pcb_gsd = sd;
304 		td->td_pcb->pcb_gs = GSEL(GUGS_SEL, SEL_UPL);
305 	}
306 
307 	return (error);
308 }
309 
310 int
311 linux_set_upcall_kse(struct thread *td, register_t stack)
312 {
313 
314 	if (stack)
315 		td->td_frame->tf_esp = stack;
316 
317 	/*
318 	 * The newly created Linux thread returns
319 	 * to the user space by the same path that a parent do.
320 	 */
321 	td->td_frame->tf_eax = 0;
322 	return (0);
323 }
324 
325 int
326 linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
327 {
328 
329 	return (linux_mmap_common(td, args->addr, args->len, args->prot,
330 		args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
331 		PAGE_SIZE));
332 }
333 
334 int
335 linux_mmap(struct thread *td, struct linux_mmap_args *args)
336 {
337 	int error;
338 	struct l_mmap_argv linux_args;
339 
340 	error = copyin(args->ptr, &linux_args, sizeof(linux_args));
341 	if (error)
342 		return (error);
343 
344 	return (linux_mmap_common(td, linux_args.addr, linux_args.len,
345 	    linux_args.prot, linux_args.flags, linux_args.fd,
346 	    (uint32_t)linux_args.pgoff));
347 }
348 
349 int
350 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
351 {
352 
353 	return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len, uap->prot));
354 }
355 
356 int
357 linux_madvise(struct thread *td, struct linux_madvise_args *uap)
358 {
359 
360 	return (linux_madvise_common(td, PTROUT(uap->addr), uap->len, uap->behav));
361 }
362 
363 int
364 linux_ioperm(struct thread *td, struct linux_ioperm_args *args)
365 {
366 	int error;
367 	struct i386_ioperm_args iia;
368 
369 	iia.start = args->start;
370 	iia.length = args->length;
371 	iia.enable = args->enable;
372 	error = i386_set_ioperm(td, &iia);
373 	return (error);
374 }
375 
376 int
377 linux_iopl(struct thread *td, struct linux_iopl_args *args)
378 {
379 	int error;
380 
381 	if (args->level < 0 || args->level > 3)
382 		return (EINVAL);
383 	if ((error = priv_check(td, PRIV_IO)) != 0)
384 		return (error);
385 	if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
386 		return (error);
387 	td->td_frame->tf_eflags = (td->td_frame->tf_eflags & ~PSL_IOPL) |
388 	    (args->level * (PSL_IOPL / 3));
389 	return (0);
390 }
391 
392 int
393 linux_modify_ldt(struct thread *td, struct linux_modify_ldt_args *uap)
394 {
395 	int error;
396 	struct i386_ldt_args ldt;
397 	struct l_descriptor ld;
398 	union descriptor desc;
399 	int size, written;
400 
401 	switch (uap->func) {
402 	case 0x00: /* read_ldt */
403 		ldt.start = 0;
404 		ldt.descs = uap->ptr;
405 		ldt.num = uap->bytecount / sizeof(union descriptor);
406 		error = i386_get_ldt(td, &ldt);
407 		td->td_retval[0] *= sizeof(union descriptor);
408 		break;
409 	case 0x02: /* read_default_ldt = 0 */
410 		size = 5*sizeof(struct l_desc_struct);
411 		if (size > uap->bytecount)
412 			size = uap->bytecount;
413 		for (written = error = 0; written < size && error == 0; written++)
414 			error = subyte((char *)uap->ptr + written, 0);
415 		td->td_retval[0] = written;
416 		break;
417 	case 0x01: /* write_ldt */
418 	case 0x11: /* write_ldt */
419 		if (uap->bytecount != sizeof(ld))
420 			return (EINVAL);
421 
422 		error = copyin(uap->ptr, &ld, sizeof(ld));
423 		if (error)
424 			return (error);
425 
426 		ldt.start = ld.entry_number;
427 		ldt.descs = &desc;
428 		ldt.num = 1;
429 		desc.sd.sd_lolimit = (ld.limit & 0x0000ffff);
430 		desc.sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16;
431 		desc.sd.sd_lobase = (ld.base_addr & 0x00ffffff);
432 		desc.sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24;
433 		desc.sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) |
434 			(ld.contents << 2);
435 		desc.sd.sd_dpl = 3;
436 		desc.sd.sd_p = (ld.seg_not_present ^ 1);
437 		desc.sd.sd_xx = 0;
438 		desc.sd.sd_def32 = ld.seg_32bit;
439 		desc.sd.sd_gran = ld.limit_in_pages;
440 		error = i386_set_ldt(td, &ldt, &desc);
441 		break;
442 	default:
443 		error = ENOSYS;
444 		break;
445 	}
446 
447 	if (error == EOPNOTSUPP) {
448 		linux_msg(td, "modify_ldt needs kernel option USER_LDT");
449 		error = ENOSYS;
450 	}
451 
452 	return (error);
453 }
454 
455 int
456 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
457 {
458 	l_osigaction_t osa;
459 	l_sigaction_t act, oact;
460 	int error;
461 
462 	if (args->nsa != NULL) {
463 		error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
464 		if (error)
465 			return (error);
466 		act.lsa_handler = osa.lsa_handler;
467 		act.lsa_flags = osa.lsa_flags;
468 		act.lsa_restorer = osa.lsa_restorer;
469 		LINUX_SIGEMPTYSET(act.lsa_mask);
470 		act.lsa_mask.__mask = osa.lsa_mask;
471 	}
472 
473 	error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
474 	    args->osa ? &oact : NULL);
475 
476 	if (args->osa != NULL && !error) {
477 		osa.lsa_handler = oact.lsa_handler;
478 		osa.lsa_flags = oact.lsa_flags;
479 		osa.lsa_restorer = oact.lsa_restorer;
480 		osa.lsa_mask = oact.lsa_mask.__mask;
481 		error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
482 	}
483 
484 	return (error);
485 }
486 
487 /*
488  * Linux has two extra args, restart and oldmask.  We dont use these,
489  * but it seems that "restart" is actually a context pointer that
490  * enables the signal to happen with a different register set.
491  */
492 int
493 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
494 {
495 	sigset_t sigmask;
496 	l_sigset_t mask;
497 
498 	LINUX_SIGEMPTYSET(mask);
499 	mask.__mask = args->mask;
500 	linux_to_bsd_sigset(&mask, &sigmask);
501 	return (kern_sigsuspend(td, sigmask));
502 }
503 
504 int
505 linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
506 {
507 	l_sigset_t lmask;
508 	sigset_t sigmask;
509 	int error;
510 
511 	if (uap->sigsetsize != sizeof(l_sigset_t))
512 		return (EINVAL);
513 
514 	error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
515 	if (error)
516 		return (error);
517 
518 	linux_to_bsd_sigset(&lmask, &sigmask);
519 	return (kern_sigsuspend(td, sigmask));
520 }
521 
522 int
523 linux_pause(struct thread *td, struct linux_pause_args *args)
524 {
525 	struct proc *p = td->td_proc;
526 	sigset_t sigmask;
527 
528 	PROC_LOCK(p);
529 	sigmask = td->td_sigmask;
530 	PROC_UNLOCK(p);
531 	return (kern_sigsuspend(td, sigmask));
532 }
533 
534 int
535 linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
536 {
537 	stack_t ss, oss;
538 	l_stack_t lss;
539 	int error;
540 
541 	if (uap->uss != NULL) {
542 		error = copyin(uap->uss, &lss, sizeof(l_stack_t));
543 		if (error)
544 			return (error);
545 
546 		ss.ss_sp = lss.ss_sp;
547 		ss.ss_size = lss.ss_size;
548 		ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
549 	}
550 	error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL,
551 	    (uap->uoss != NULL) ? &oss : NULL);
552 	if (!error && uap->uoss != NULL) {
553 		lss.ss_sp = oss.ss_sp;
554 		lss.ss_size = oss.ss_size;
555 		lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
556 		error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
557 	}
558 
559 	return (error);
560 }
561 
562 int
563 linux_set_thread_area(struct thread *td, struct linux_set_thread_area_args *args)
564 {
565 	struct l_user_desc info;
566 	int error;
567 	int idx;
568 	int a[2];
569 	struct segment_descriptor sd;
570 
571 	error = copyin(args->desc, &info, sizeof(struct l_user_desc));
572 	if (error)
573 		return (error);
574 
575 	idx = info.entry_number;
576 	/*
577 	 * Semantics of Linux version: every thread in the system has array of
578 	 * 3 tls descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. This
579 	 * syscall loads one of the selected tls decriptors with a value and
580 	 * also loads GDT descriptors 6, 7 and 8 with the content of the
581 	 * per-thread descriptors.
582 	 *
583 	 * Semantics of FreeBSD version: I think we can ignore that Linux has 3
584 	 * per-thread descriptors and use just the 1st one. The tls_array[]
585 	 * is used only in set/get-thread_area() syscalls and for loading the
586 	 * GDT descriptors. In FreeBSD we use just one GDT descriptor for TLS
587 	 * so we will load just one.
588 	 *
589 	 * XXX: this doesn't work when a user space process tries to use more
590 	 * than 1 TLS segment. Comment in the Linux sources says wine might do
591 	 * this.
592 	 */
593 
594 	/*
595 	 * we support just GLIBC TLS now
596 	 * we should let 3 proceed as well because we use this segment so
597 	 * if code does two subsequent calls it should succeed
598 	 */
599 	if (idx != 6 && idx != -1 && idx != 3)
600 		return (EINVAL);
601 
602 	/*
603 	 * we have to copy out the GDT entry we use
604 	 * FreeBSD uses GDT entry #3 for storing %gs so load that
605 	 *
606 	 * XXX: what if a user space program doesn't check this value and tries
607 	 * to use 6, 7 or 8?
608 	 */
609 	idx = info.entry_number = 3;
610 	error = copyout(&info, args->desc, sizeof(struct l_user_desc));
611 	if (error)
612 		return (error);
613 
614 	if (LINUX_LDT_empty(&info)) {
615 		a[0] = 0;
616 		a[1] = 0;
617 	} else {
618 		a[0] = LINUX_LDT_entry_a(&info);
619 		a[1] = LINUX_LDT_entry_b(&info);
620 	}
621 
622 	memcpy(&sd, &a, sizeof(a));
623 	/* this is taken from i386 version of cpu_set_user_tls() */
624 	critical_enter();
625 	/* set %gs */
626 	td->td_pcb->pcb_gsd = sd;
627 	PCPU_GET(fsgs_gdt)[1] = sd;
628 	load_gs(GSEL(GUGS_SEL, SEL_UPL));
629 	critical_exit();
630 
631 	return (0);
632 }
633 
634 int
635 linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args)
636 {
637 
638 	struct l_user_desc info;
639 	int error;
640 	int idx;
641 	struct l_desc_struct desc;
642 	struct segment_descriptor sd;
643 
644 	error = copyin(args->desc, &info, sizeof(struct l_user_desc));
645 	if (error)
646 		return (error);
647 
648 	idx = info.entry_number;
649 	/* XXX: I am not sure if we want 3 to be allowed too. */
650 	if (idx != 6 && idx != 3)
651 		return (EINVAL);
652 
653 	idx = 3;
654 
655 	memset(&info, 0, sizeof(info));
656 
657 	sd = PCPU_GET(fsgs_gdt)[1];
658 
659 	memcpy(&desc, &sd, sizeof(desc));
660 
661 	info.entry_number = idx;
662 	info.base_addr = LINUX_GET_BASE(&desc);
663 	info.limit = LINUX_GET_LIMIT(&desc);
664 	info.seg_32bit = LINUX_GET_32BIT(&desc);
665 	info.contents = LINUX_GET_CONTENTS(&desc);
666 	info.read_exec_only = !LINUX_GET_WRITABLE(&desc);
667 	info.limit_in_pages = LINUX_GET_LIMIT_PAGES(&desc);
668 	info.seg_not_present = !LINUX_GET_PRESENT(&desc);
669 	info.useable = LINUX_GET_USEABLE(&desc);
670 
671 	error = copyout(&info, args->desc, sizeof(struct l_user_desc));
672 	if (error)
673 		return (EFAULT);
674 
675 	return (0);
676 }
677 
678 /* XXX: this wont work with module - convert it */
679 int
680 linux_mq_open(struct thread *td, struct linux_mq_open_args *args)
681 {
682 #ifdef P1003_1B_MQUEUE
683 	return (sys_kmq_open(td, (struct kmq_open_args *)args));
684 #else
685 	return (ENOSYS);
686 #endif
687 }
688 
689 int
690 linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args)
691 {
692 #ifdef P1003_1B_MQUEUE
693 	return (sys_kmq_unlink(td, (struct kmq_unlink_args *)args));
694 #else
695 	return (ENOSYS);
696 #endif
697 }
698 
699 int
700 linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args)
701 {
702 #ifdef P1003_1B_MQUEUE
703 	return (sys_kmq_timedsend(td, (struct kmq_timedsend_args *)args));
704 #else
705 	return (ENOSYS);
706 #endif
707 }
708 
709 int
710 linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args)
711 {
712 #ifdef P1003_1B_MQUEUE
713 	return (sys_kmq_timedreceive(td, (struct kmq_timedreceive_args *)args));
714 #else
715 	return (ENOSYS);
716 #endif
717 }
718 
719 int
720 linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args)
721 {
722 #ifdef P1003_1B_MQUEUE
723 	return (sys_kmq_notify(td, (struct kmq_notify_args *)args));
724 #else
725 	return (ENOSYS);
726 #endif
727 }
728 
729 int
730 linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args)
731 {
732 #ifdef P1003_1B_MQUEUE
733 	return (sys_kmq_setattr(td, (struct kmq_setattr_args *)args));
734 #else
735 	return (ENOSYS);
736 #endif
737 }
738