linux_machdep.c revision 103216
1/*-
2 * Copyright (c) 2000 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer
10 *    in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/i386/linux/linux_machdep.c 103216 2002-09-11 08:13:56Z julian $
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/lock.h>
34#include <sys/mman.h>
35#include <sys/mutex.h>
36#include <sys/proc.h>
37#include <sys/resource.h>
38#include <sys/resourcevar.h>
39#include <sys/syscallsubr.h>
40#include <sys/sysproto.h>
41#include <sys/unistd.h>
42
43#include <machine/frame.h>
44#include <machine/psl.h>
45#include <machine/segments.h>
46#include <machine/sysarch.h>
47
48#include <vm/vm.h>
49#include <vm/pmap.h>
50#include <vm/vm_map.h>
51
52#include <i386/linux/linux.h>
53#include <i386/linux/linux_proto.h>
54#include <compat/linux/linux_ipc.h>
55#include <compat/linux/linux_signal.h>
56#include <compat/linux/linux_util.h>
57
58struct l_descriptor {
59	l_uint		entry_number;
60	l_ulong		base_addr;
61	l_uint		limit;
62	l_uint		seg_32bit:1;
63	l_uint		contents:2;
64	l_uint		read_exec_only:1;
65	l_uint		limit_in_pages:1;
66	l_uint		seg_not_present:1;
67	l_uint		useable:1;
68};
69
70struct l_old_select_argv {
71	l_int		nfds;
72	l_fd_set	*readfds;
73	l_fd_set	*writefds;
74	l_fd_set	*exceptfds;
75	struct l_timeval	*timeout;
76};
77
78int
79linux_to_bsd_sigaltstack(int lsa)
80{
81	int bsa = 0;
82
83	if (lsa & LINUX_SS_DISABLE)
84		bsa |= SS_DISABLE;
85	if (lsa & LINUX_SS_ONSTACK)
86		bsa |= SS_ONSTACK;
87	return (bsa);
88}
89
90int
91bsd_to_linux_sigaltstack(int bsa)
92{
93	int lsa = 0;
94
95	if (bsa & SS_DISABLE)
96		lsa |= LINUX_SS_DISABLE;
97	if (bsa & SS_ONSTACK)
98		lsa |= LINUX_SS_ONSTACK;
99	return (lsa);
100}
101
102int
103linux_execve(struct thread *td, struct linux_execve_args *args)
104{
105	struct execve_args bsd;
106	caddr_t sg;
107
108	sg = stackgap_init();
109	CHECKALTEXIST(td, &sg, args->path);
110
111#ifdef DEBUG
112	if (ldebug(execve))
113		printf(ARGS(execve, "%s"), args->path);
114#endif
115
116	bsd.fname = args->path;
117	bsd.argv = args->argp;
118	bsd.envv = args->envp;
119	return (execve(td, &bsd));
120}
121
122struct l_ipc_kludge {
123	struct l_msgbuf *msgp;
124	l_long msgtyp;
125};
126
127int
128linux_ipc(struct thread *td, struct linux_ipc_args *args)
129{
130
131	switch (args->what & 0xFFFF) {
132	case LINUX_SEMOP: {
133		struct linux_semop_args a;
134
135		a.semid = args->arg1;
136		a.tsops = args->ptr;
137		a.nsops = args->arg2;
138		return (linux_semop(td, &a));
139	}
140	case LINUX_SEMGET: {
141		struct linux_semget_args a;
142
143		a.key = args->arg1;
144		a.nsems = args->arg2;
145		a.semflg = args->arg3;
146		return (linux_semget(td, &a));
147	}
148	case LINUX_SEMCTL: {
149		struct linux_semctl_args a;
150		int error;
151
152		a.semid = args->arg1;
153		a.semnum = args->arg2;
154		a.cmd = args->arg3;
155		error = copyin((caddr_t)args->ptr, &a.arg, sizeof(a.arg));
156		if (error)
157			return (error);
158		return (linux_semctl(td, &a));
159	}
160	case LINUX_MSGSND: {
161		struct linux_msgsnd_args a;
162
163		a.msqid = args->arg1;
164		a.msgp = args->ptr;
165		a.msgsz = args->arg2;
166		a.msgflg = args->arg3;
167		return (linux_msgsnd(td, &a));
168	}
169	case LINUX_MSGRCV: {
170		struct linux_msgrcv_args a;
171
172		a.msqid = args->arg1;
173		a.msgsz = args->arg2;
174		a.msgflg = args->arg3;
175		if ((args->what >> 16) == 0) {
176			struct l_ipc_kludge tmp;
177			int error;
178
179			if (args->ptr == NULL)
180				return (EINVAL);
181			error = copyin((caddr_t)args->ptr, &tmp, sizeof(tmp));
182			if (error)
183				return (error);
184			a.msgp = tmp.msgp;
185			a.msgtyp = tmp.msgtyp;
186		} else {
187			a.msgp = args->ptr;
188			a.msgtyp = args->arg5;
189		}
190		return (linux_msgrcv(td, &a));
191	}
192	case LINUX_MSGGET: {
193		struct linux_msgget_args a;
194
195		a.key = args->arg1;
196		a.msgflg = args->arg2;
197		return (linux_msgget(td, &a));
198	}
199	case LINUX_MSGCTL: {
200		struct linux_msgctl_args a;
201
202		a.msqid = args->arg1;
203		a.cmd = args->arg2;
204		a.buf = args->ptr;
205		return (linux_msgctl(td, &a));
206	}
207	case LINUX_SHMAT: {
208		struct linux_shmat_args a;
209
210		a.shmid = args->arg1;
211		a.shmaddr = args->ptr;
212		a.shmflg = args->arg2;
213		a.raddr = (l_ulong *)args->arg3;
214		return (linux_shmat(td, &a));
215	}
216	case LINUX_SHMDT: {
217		struct linux_shmdt_args a;
218
219		a.shmaddr = args->ptr;
220		return (linux_shmdt(td, &a));
221	}
222	case LINUX_SHMGET: {
223		struct linux_shmget_args a;
224
225		a.key = args->arg1;
226		a.size = args->arg2;
227		a.shmflg = args->arg3;
228		return (linux_shmget(td, &a));
229	}
230	case LINUX_SHMCTL: {
231		struct linux_shmctl_args a;
232
233		a.shmid = args->arg1;
234		a.cmd = args->arg2;
235		a.buf = args->ptr;
236		return (linux_shmctl(td, &a));
237	}
238	default:
239		break;
240	}
241
242	return (EINVAL);
243}
244
245int
246linux_old_select(struct thread *td, struct linux_old_select_args *args)
247{
248	struct l_old_select_argv linux_args;
249	struct linux_select_args newsel;
250	int error;
251
252#ifdef DEBUG
253	if (ldebug(old_select))
254		printf(ARGS(old_select, "%p"), args->ptr);
255#endif
256
257	error = copyin((caddr_t)args->ptr, &linux_args, sizeof(linux_args));
258	if (error)
259		return (error);
260
261	newsel.nfds = linux_args.nfds;
262	newsel.readfds = linux_args.readfds;
263	newsel.writefds = linux_args.writefds;
264	newsel.exceptfds = linux_args.exceptfds;
265	newsel.timeout = linux_args.timeout;
266	return (linux_select(td, &newsel));
267}
268
269int
270linux_fork(struct thread *td, struct linux_fork_args *args)
271{
272	int error;
273
274#ifdef DEBUG
275	if (ldebug(fork))
276		printf(ARGS(fork, ""));
277#endif
278
279	if ((error = fork(td, (struct fork_args *)args)) != 0)
280		return (error);
281
282	if (td->td_retval[1] == 1)
283		td->td_retval[0] = 0;
284	return (0);
285}
286
287int
288linux_vfork(struct thread *td, struct linux_vfork_args *args)
289{
290	int error;
291
292#ifdef DEBUG
293	if (ldebug(vfork))
294		printf(ARGS(vfork, ""));
295#endif
296
297	if ((error = vfork(td, (struct vfork_args *)args)) != 0)
298		return (error);
299	/* Are we the child? */
300	if (td->td_retval[1] == 1)
301		td->td_retval[0] = 0;
302	return (0);
303}
304
305#define CLONE_VM	0x100
306#define CLONE_FS	0x200
307#define CLONE_FILES	0x400
308#define CLONE_SIGHAND	0x800
309#define CLONE_PID	0x1000
310
311int
312linux_clone(struct thread *td, struct linux_clone_args *args)
313{
314	int error, ff = RFPROC | RFSTOPPED;
315	struct proc *p2;
316	int exit_signal;
317
318#ifdef DEBUG
319	if (ldebug(clone)) {
320		printf(ARGS(clone, "flags %x, stack %x"),
321		    (unsigned int)args->flags, (unsigned int)args->stack);
322		if (args->flags & CLONE_PID)
323			printf(LMSG("CLONE_PID not yet supported"));
324	}
325#endif
326
327	if (!args->stack)
328		return (EINVAL);
329
330	exit_signal = args->flags & 0x000000ff;
331	if (exit_signal >= LINUX_NSIG)
332		return (EINVAL);
333
334	if (exit_signal <= LINUX_SIGTBLSZ)
335		exit_signal = linux_to_bsd_signal[_SIG_IDX(exit_signal)];
336
337	if (args->flags & CLONE_VM)
338		ff |= RFMEM;
339	if (args->flags & CLONE_SIGHAND)
340		ff |= RFSIGSHARE;
341	if (!(args->flags & CLONE_FILES))
342		ff |= RFFDG;
343
344	mtx_lock(&Giant);
345	error = fork1(td, ff, &p2);
346	if (error == 0) {
347		td->td_retval[0] = p2->p_pid;
348		td->td_retval[1] = 0;
349
350		PROC_LOCK(p2);
351		p2->p_sigparent = exit_signal;
352		FIRST_THREAD_IN_PROC(p2)->td_frame->tf_esp =
353					(unsigned int)args->stack;
354
355#ifdef DEBUG
356		if (ldebug(clone))
357			printf(LMSG("clone: successful rfork to %ld"),
358			    (long)p2->p_pid);
359#endif
360
361		/*
362		 * Make this runnable after we are finished with it.
363		 */
364		mtx_lock_spin(&sched_lock);
365		TD_SET_CAN_RUN(FIRST_THREAD_IN_PROC(p2));
366		setrunqueue(FIRST_THREAD_IN_PROC(p2));
367		mtx_unlock_spin(&sched_lock);
368		PROC_UNLOCK(p2);
369	}
370	mtx_unlock(&Giant);
371
372	return (error);
373}
374
375/* XXX move */
376struct l_mmap_argv {
377	l_caddr_t	addr;
378	l_int		len;
379	l_int		prot;
380	l_int		flags;
381	l_int		fd;
382	l_int		pos;
383};
384
385#define STACK_SIZE  (2 * 1024 * 1024)
386#define GUARD_SIZE  (4 * PAGE_SIZE)
387
388int
389linux_mmap(struct thread *td, struct linux_mmap_args *args)
390{
391	struct proc *p = td->td_proc;
392	struct mmap_args /* {
393		caddr_t addr;
394		size_t len;
395		int prot;
396		int flags;
397		int fd;
398		long pad;
399		off_t pos;
400	} */ bsd_args;
401	int error;
402	struct l_mmap_argv linux_args;
403
404	error = copyin((caddr_t)args->ptr, &linux_args, sizeof(linux_args));
405	if (error)
406		return (error);
407
408#ifdef DEBUG
409	if (ldebug(mmap))
410		printf(ARGS(mmap, "%p, %d, %d, 0x%08x, %d, %d"),
411		    (void *)linux_args.addr, linux_args.len, linux_args.prot,
412		    linux_args.flags, linux_args.fd, linux_args.pos);
413#endif
414
415	bsd_args.flags = 0;
416	if (linux_args.flags & LINUX_MAP_SHARED)
417		bsd_args.flags |= MAP_SHARED;
418	if (linux_args.flags & LINUX_MAP_PRIVATE)
419		bsd_args.flags |= MAP_PRIVATE;
420	if (linux_args.flags & LINUX_MAP_FIXED)
421		bsd_args.flags |= MAP_FIXED;
422	if (linux_args.flags & LINUX_MAP_ANON)
423		bsd_args.flags |= MAP_ANON;
424	else
425		bsd_args.flags |= MAP_NOSYNC;
426	if (linux_args.flags & LINUX_MAP_GROWSDOWN) {
427		bsd_args.flags |= MAP_STACK;
428
429		/* The linux MAP_GROWSDOWN option does not limit auto
430		 * growth of the region.  Linux mmap with this option
431		 * takes as addr the inital BOS, and as len, the initial
432		 * region size.  It can then grow down from addr without
433		 * limit.  However, linux threads has an implicit internal
434		 * limit to stack size of STACK_SIZE.  Its just not
435		 * enforced explicitly in linux.  But, here we impose
436		 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack
437		 * region, since we can do this with our mmap.
438		 *
439		 * Our mmap with MAP_STACK takes addr as the maximum
440		 * downsize limit on BOS, and as len the max size of
441		 * the region.  It them maps the top SGROWSIZ bytes,
442		 * and autgrows the region down, up to the limit
443		 * in addr.
444		 *
445		 * If we don't use the MAP_STACK option, the effect
446		 * of this code is to allocate a stack region of a
447		 * fixed size of (STACK_SIZE - GUARD_SIZE).
448		 */
449
450		/* This gives us TOS */
451		bsd_args.addr = linux_args.addr + linux_args.len;
452
453		if (bsd_args.addr > p->p_vmspace->vm_maxsaddr) {
454			/* Some linux apps will attempt to mmap
455			 * thread stacks near the top of their
456			 * address space.  If their TOS is greater
457			 * than vm_maxsaddr, vm_map_growstack()
458			 * will confuse the thread stack with the
459			 * process stack and deliver a SEGV if they
460			 * attempt to grow the thread stack past their
461			 * current stacksize rlimit.  To avoid this,
462			 * adjust vm_maxsaddr upwards to reflect
463			 * the current stacksize rlimit rather
464			 * than the maximum possible stacksize.
465			 * It would be better to adjust the
466			 * mmap'ed region, but some apps do not check
467			 * mmap's return value.
468			 */
469			mtx_assert(&Giant, MA_OWNED);
470			p->p_vmspace->vm_maxsaddr = (char *)USRSTACK -
471			    p->p_rlimit[RLIMIT_STACK].rlim_cur;
472		}
473
474		/* This gives us our maximum stack size */
475		if (linux_args.len > STACK_SIZE - GUARD_SIZE)
476			bsd_args.len = linux_args.len;
477		else
478			bsd_args.len  = STACK_SIZE - GUARD_SIZE;
479
480		/* This gives us a new BOS.  If we're using VM_STACK, then
481		 * mmap will just map the top SGROWSIZ bytes, and let
482		 * the stack grow down to the limit at BOS.  If we're
483		 * not using VM_STACK we map the full stack, since we
484		 * don't have a way to autogrow it.
485		 */
486		bsd_args.addr -= bsd_args.len;
487	} else {
488		bsd_args.addr = linux_args.addr;
489		bsd_args.len  = linux_args.len;
490	}
491
492	bsd_args.prot = linux_args.prot | PROT_READ;	/* always required */
493	if (linux_args.flags & LINUX_MAP_ANON)
494		bsd_args.fd = -1;
495	else
496		bsd_args.fd = linux_args.fd;
497	bsd_args.pos = linux_args.pos;
498	bsd_args.pad = 0;
499
500#ifdef DEBUG
501	if (ldebug(mmap))
502		printf("-> (%p, %d, %d, 0x%08x, %d, %d)\n",
503		    (void *)bsd_args.addr, bsd_args.len, bsd_args.prot,
504		    bsd_args.flags, bsd_args.fd, (int)bsd_args.pos);
505#endif
506
507	return (mmap(td, &bsd_args));
508}
509
510int
511linux_pipe(struct thread *td, struct linux_pipe_args *args)
512{
513	int error;
514	int reg_edx;
515
516#ifdef DEBUG
517	if (ldebug(pipe))
518		printf(ARGS(pipe, "*"));
519#endif
520
521	reg_edx = td->td_retval[1];
522	error = pipe(td, 0);
523	if (error) {
524		td->td_retval[1] = reg_edx;
525		return (error);
526	}
527
528	error = copyout(td->td_retval, args->pipefds, 2*sizeof(int));
529	if (error) {
530		td->td_retval[1] = reg_edx;
531		return (error);
532	}
533
534	td->td_retval[1] = reg_edx;
535	td->td_retval[0] = 0;
536	return (0);
537}
538
539int
540linux_ioperm(struct thread *td, struct linux_ioperm_args *args)
541{
542	struct sysarch_args sa;
543	struct i386_ioperm_args *iia;
544	caddr_t sg;
545
546	sg = stackgap_init();
547	iia = stackgap_alloc(&sg, sizeof(struct i386_ioperm_args));
548	iia->start = args->start;
549	iia->length = args->length;
550	iia->enable = args->enable;
551	sa.op = I386_SET_IOPERM;
552	sa.parms = (char *)iia;
553	return (sysarch(td, &sa));
554}
555
556int
557linux_iopl(struct thread *td, struct linux_iopl_args *args)
558{
559	int error;
560
561	if (args->level < 0 || args->level > 3)
562		return (EINVAL);
563	if ((error = suser(td)) != 0)
564		return (error);
565	if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
566		return (error);
567	td->td_frame->tf_eflags = (td->td_frame->tf_eflags & ~PSL_IOPL) |
568	    (args->level * (PSL_IOPL / 3));
569	return (0);
570}
571
572int
573linux_modify_ldt(td, uap)
574	struct thread *td;
575	struct linux_modify_ldt_args *uap;
576{
577	int error;
578	caddr_t sg;
579	struct sysarch_args args;
580	struct i386_ldt_args *ldt;
581	struct l_descriptor ld;
582	union descriptor *desc;
583
584	sg = stackgap_init();
585
586	if (uap->ptr == NULL)
587		return (EINVAL);
588
589	switch (uap->func) {
590	case 0x00: /* read_ldt */
591		ldt = stackgap_alloc(&sg, sizeof(*ldt));
592		ldt->start = 0;
593		ldt->descs = uap->ptr;
594		ldt->num = uap->bytecount / sizeof(union descriptor);
595		args.op = I386_GET_LDT;
596		args.parms = (char*)ldt;
597		error = sysarch(td, &args);
598		td->td_retval[0] *= sizeof(union descriptor);
599		break;
600	case 0x01: /* write_ldt */
601	case 0x11: /* write_ldt */
602		if (uap->bytecount != sizeof(ld))
603			return (EINVAL);
604
605		error = copyin(uap->ptr, &ld, sizeof(ld));
606		if (error)
607			return (error);
608
609		ldt = stackgap_alloc(&sg, sizeof(*ldt));
610		desc = stackgap_alloc(&sg, sizeof(*desc));
611		ldt->start = ld.entry_number;
612		ldt->descs = desc;
613		ldt->num = 1;
614		desc->sd.sd_lolimit = (ld.limit & 0x0000ffff);
615		desc->sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16;
616		desc->sd.sd_lobase = (ld.base_addr & 0x00ffffff);
617		desc->sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24;
618		desc->sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) |
619			(ld.contents << 2);
620		desc->sd.sd_dpl = 3;
621		desc->sd.sd_p = (ld.seg_not_present ^ 1);
622		desc->sd.sd_xx = 0;
623		desc->sd.sd_def32 = ld.seg_32bit;
624		desc->sd.sd_gran = ld.limit_in_pages;
625		args.op = I386_SET_LDT;
626		args.parms = (char*)ldt;
627		error = sysarch(td, &args);
628		break;
629	default:
630		error = EINVAL;
631		break;
632	}
633
634	if (error == EOPNOTSUPP) {
635		printf("linux: modify_ldt needs kernel option USER_LDT\n");
636		error = ENOSYS;
637	}
638
639	return (error);
640}
641
642int
643linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
644{
645	l_osigaction_t osa;
646	l_sigaction_t act, oact;
647	int error;
648
649#ifdef DEBUG
650	if (ldebug(sigaction))
651		printf(ARGS(sigaction, "%d, %p, %p"),
652		    args->sig, (void *)args->nsa, (void *)args->osa);
653#endif
654
655	if (args->nsa != NULL) {
656		error = copyin((caddr_t)args->nsa, &osa,
657		    sizeof(l_osigaction_t));
658		if (error)
659			return (error);
660		act.lsa_handler = osa.lsa_handler;
661		act.lsa_flags = osa.lsa_flags;
662		act.lsa_restorer = osa.lsa_restorer;
663		LINUX_SIGEMPTYSET(act.lsa_mask);
664		act.lsa_mask.__bits[0] = osa.lsa_mask;
665	}
666
667	error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
668	    args->osa ? &oact : NULL);
669
670	if (args->osa != NULL && !error) {
671		osa.lsa_handler = oact.lsa_handler;
672		osa.lsa_flags = oact.lsa_flags;
673		osa.lsa_restorer = oact.lsa_restorer;
674		osa.lsa_mask = oact.lsa_mask.__bits[0];
675		error = copyout(&osa, (caddr_t)args->osa,
676		    sizeof(l_osigaction_t));
677	}
678
679	return (error);
680}
681
682/*
683 * Linux has two extra args, restart and oldmask.  We dont use these,
684 * but it seems that "restart" is actually a context pointer that
685 * enables the signal to happen with a different register set.
686 */
687int
688linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
689{
690	sigset_t sigmask;
691	l_sigset_t mask;
692
693#ifdef DEBUG
694	if (ldebug(sigsuspend))
695		printf(ARGS(sigsuspend, "%08lx"), (unsigned long)args->mask);
696#endif
697
698	LINUX_SIGEMPTYSET(mask);
699	mask.__bits[0] = args->mask;
700	linux_to_bsd_sigset(&mask, &sigmask);
701	return (kern_sigsuspend(td, sigmask));
702}
703
704int
705linux_rt_sigsuspend(td, uap)
706	struct thread *td;
707	struct linux_rt_sigsuspend_args *uap;
708{
709	l_sigset_t lmask;
710	sigset_t sigmask;
711	int error;
712
713#ifdef DEBUG
714	if (ldebug(rt_sigsuspend))
715		printf(ARGS(rt_sigsuspend, "%p, %d"),
716		    (void *)uap->newset, uap->sigsetsize);
717#endif
718
719	if (uap->sigsetsize != sizeof(l_sigset_t))
720		return (EINVAL);
721
722	error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
723	if (error)
724		return (error);
725
726	linux_to_bsd_sigset(&lmask, &sigmask);
727	return (kern_sigsuspend(td, sigmask));
728}
729
730int
731linux_pause(struct thread *td, struct linux_pause_args *args)
732{
733	struct proc *p = td->td_proc;
734	sigset_t sigmask;
735
736#ifdef DEBUG
737	if (ldebug(pause))
738		printf(ARGS(pause, ""));
739#endif
740
741	PROC_LOCK(p);
742	sigmask = p->p_sigmask;
743	PROC_UNLOCK(p);
744	return (kern_sigsuspend(td, sigmask));
745}
746
747int
748linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
749{
750	stack_t ss, oss;
751	l_stack_t lss;
752	int error;
753
754#ifdef DEBUG
755	if (ldebug(sigaltstack))
756		printf(ARGS(sigaltstack, "%p, %p"), uap->uss, uap->uoss);
757#endif
758
759	if (uap->uss != NULL) {
760		error = copyin(uap->uss, &lss, sizeof(l_stack_t));
761		if (error)
762			return (error);
763
764		ss.ss_sp = lss.ss_sp;
765		ss.ss_size = lss.ss_size;
766		ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
767	}
768	error = kern_sigaltstack(td, (uap->uoss != NULL) ? &oss : NULL,
769	    (uap->uss != NULL) ? &ss : NULL);
770	if (!error && uap->uoss != NULL) {
771		lss.ss_sp = oss.ss_sp;
772		lss.ss_size = oss.ss_size;
773		lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
774		error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
775	}
776
777	return (error);
778}
779