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