Home | History | Annotate | Line # | Download | only in common
linux_misc_notalpha.c revision 1.60.2.5
      1  1.60.2.5   nathanw /*	$NetBSD: linux_misc_notalpha.c,v 1.60.2.5 2002/04/01 07:44:27 nathanw Exp $	*/
      2      1.47       erh 
      3      1.47       erh /*-
      4      1.49      fvdl  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5      1.47       erh  * All rights reserved.
      6      1.47       erh  *
      7      1.47       erh  * This code is derived from software contributed to The NetBSD Foundation
      8      1.51   thorpej  * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
      9      1.51   thorpej  * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
     10      1.47       erh  *
     11      1.47       erh  * Redistribution and use in source and binary forms, with or without
     12      1.47       erh  * modification, are permitted provided that the following conditions
     13      1.47       erh  * are met:
     14      1.47       erh  * 1. Redistributions of source code must retain the above copyright
     15      1.47       erh  *    notice, this list of conditions and the following disclaimer.
     16      1.47       erh  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.47       erh  *    notice, this list of conditions and the following disclaimer in the
     18      1.47       erh  *    documentation and/or other materials provided with the distribution.
     19      1.47       erh  * 3. All advertising materials mentioning features or use of this software
     20      1.47       erh  *    must display the following acknowledgement:
     21      1.47       erh  *	This product includes software developed by the NetBSD
     22      1.47       erh  *	Foundation, Inc. and its contributors.
     23      1.47       erh  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24      1.47       erh  *    contributors may be used to endorse or promote products derived
     25      1.47       erh  *    from this software without specific prior written permission.
     26      1.47       erh  *
     27      1.47       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28      1.47       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29      1.47       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30      1.47       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31      1.47       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32      1.47       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33      1.47       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34      1.47       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35      1.47       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36      1.47       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37      1.47       erh  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1      fvdl  */
     39  1.60.2.2   nathanw 
     40  1.60.2.2   nathanw #include <sys/cdefs.h>
     41  1.60.2.5   nathanw __KERNEL_RCSID(0, "$NetBSD: linux_misc_notalpha.c,v 1.60.2.5 2002/04/01 07:44:27 nathanw Exp $");
     42       1.1      fvdl 
     43       1.1      fvdl #include <sys/param.h>
     44       1.1      fvdl #include <sys/systm.h>
     45       1.1      fvdl #include <sys/kernel.h>
     46      1.47       erh #include <sys/mman.h>
     47      1.47       erh #include <sys/mount.h>
     48       1.1      fvdl #include <sys/malloc.h>
     49       1.1      fvdl #include <sys/mbuf.h>
     50      1.47       erh #include <sys/namei.h>
     51      1.57     itohy #include <sys/proc.h>
     52  1.60.2.4       wdk #include <sys/lwp.h>
     53       1.1      fvdl #include <sys/ptrace.h>
     54       1.1      fvdl #include <sys/resource.h>
     55       1.1      fvdl #include <sys/resourcevar.h>
     56  1.60.2.3   nathanw #include <sys/time.h>
     57       1.1      fvdl #include <sys/wait.h>
     58       1.1      fvdl 
     59       1.1      fvdl #include <sys/syscallargs.h>
     60       1.1      fvdl 
     61      1.48  christos #include <compat/linux/common/linux_types.h>
     62      1.48  christos #include <compat/linux/common/linux_fcntl.h>
     63      1.48  christos #include <compat/linux/common/linux_misc.h>
     64      1.48  christos #include <compat/linux/common/linux_mmap.h>
     65      1.48  christos #include <compat/linux/common/linux_signal.h>
     66      1.48  christos #include <compat/linux/common/linux_util.h>
     67      1.48  christos 
     68       1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     69      1.26  christos 
     70       1.1      fvdl /*
     71      1.47       erh  * This file contains routines which are used
     72      1.47       erh  * on every linux architechture except the Alpha.
     73       1.1      fvdl  */
     74      1.21   mycroft 
     75      1.47       erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
     76      1.47       erh /* Not used on: alpha */
     77       1.1      fvdl 
     78       1.1      fvdl /*
     79      1.47       erh  * Alarm. This is a libc call which uses setitimer(2) in NetBSD.
     80      1.47       erh  * Fiddle with the timers to make it work.
     81       1.1      fvdl  */
     82       1.1      fvdl int
     83  1.60.2.1   nathanw linux_sys_alarm(l, v, retval)
     84  1.60.2.1   nathanw 	struct lwp *l;
     85      1.20   thorpej 	void *v;
     86      1.20   thorpej 	register_t *retval;
     87      1.20   thorpej {
     88      1.47       erh 	struct linux_sys_alarm_args /* {
     89      1.47       erh 		syscallarg(unsigned int) secs;
     90      1.20   thorpej 	} */ *uap = v;
     91  1.60.2.1   nathanw 	struct proc *p = l->l_proc;
     92      1.47       erh 	int s;
     93      1.47       erh 	struct itimerval *itp, it;
     94       1.1      fvdl 
     95  1.60.2.3   nathanw 	if (p->p_timers && p->p_timers[0])
     96  1.60.2.3   nathanw 		itp = &p->p_timers[0]->pt_time;
     97  1.60.2.3   nathanw 	else
     98  1.60.2.3   nathanw 		itp = NULL;
     99      1.47       erh 	s = splclock();
    100      1.47       erh 	/*
    101      1.47       erh 	 * Clear any pending timer alarms.
    102      1.47       erh 	 */
    103  1.60.2.3   nathanw 	if (itp) {
    104  1.60.2.3   nathanw 		callout_stop(&p->p_timers[0]->pt_ch);
    105  1.60.2.3   nathanw 		timerclear(&itp->it_interval);
    106  1.60.2.3   nathanw 		if (timerisset(&itp->it_value) &&
    107  1.60.2.3   nathanw 		    timercmp(&itp->it_value, &time, >))
    108  1.60.2.3   nathanw 			timersub(&itp->it_value, &time, &itp->it_value);
    109  1.60.2.3   nathanw 		/*
    110  1.60.2.3   nathanw 		 * Return how many seconds were left (rounded up)
    111  1.60.2.3   nathanw 		 */
    112  1.60.2.3   nathanw 		retval[0] = itp->it_value.tv_sec;
    113  1.60.2.3   nathanw 		if (itp->it_value.tv_usec)
    114  1.60.2.3   nathanw 			retval[0]++;
    115  1.60.2.3   nathanw 	} else {
    116  1.60.2.3   nathanw 		retval[0] = 0;
    117  1.60.2.3   nathanw 	}
    118       1.1      fvdl 
    119      1.47       erh 	/*
    120      1.47       erh 	 * alarm(0) just resets the timer.
    121      1.47       erh 	 */
    122      1.47       erh 	if (SCARG(uap, secs) == 0) {
    123  1.60.2.3   nathanw 		if (itp)
    124  1.60.2.3   nathanw 			timerclear(&itp->it_value);
    125      1.47       erh 		splx(s);
    126      1.47       erh 		return 0;
    127      1.47       erh 	}
    128       1.1      fvdl 
    129      1.47       erh 	/*
    130      1.47       erh 	 * Check the new alarm time for sanity, and set it.
    131      1.47       erh 	 */
    132      1.47       erh 	timerclear(&it.it_interval);
    133      1.47       erh 	it.it_value.tv_sec = SCARG(uap, secs);
    134      1.47       erh 	it.it_value.tv_usec = 0;
    135      1.47       erh 	if (itimerfix(&it.it_value) || itimerfix(&it.it_interval)) {
    136      1.47       erh 		splx(s);
    137      1.47       erh 		return (EINVAL);
    138      1.16      fvdl 	}
    139       1.1      fvdl 
    140  1.60.2.3   nathanw 	if (p->p_timers == NULL)
    141  1.60.2.3   nathanw 		timers_alloc(p);
    142  1.60.2.3   nathanw 	if (p->p_timers[0] == NULL) {
    143  1.60.2.3   nathanw 		p->p_timers[0] = pool_get(&ptimer_pool, PR_WAITOK);
    144  1.60.2.3   nathanw 		p->p_timers[0]->pt_ev.sigev_notify = SIGEV_SIGNAL;
    145  1.60.2.3   nathanw 		p->p_timers[0]->pt_ev.sigev_signo = SIGALRM;
    146  1.60.2.3   nathanw 		p->p_timers[0]->pt_type = CLOCK_REALTIME;
    147  1.60.2.3   nathanw 		callout_init(&p->p_timers[0]->pt_ch);
    148  1.60.2.3   nathanw 	}
    149  1.60.2.3   nathanw 
    150      1.47       erh 	if (timerisset(&it.it_value)) {
    151      1.56   thorpej 		/*
    152      1.56   thorpej 		 * Don't need to check hzto() return value, here.
    153      1.56   thorpej 		 * callout_reset() does it for us.
    154      1.56   thorpej 		 */
    155      1.47       erh 		timeradd(&it.it_value, &time, &it.it_value);
    156  1.60.2.3   nathanw 		callout_reset(&p->p_timers[0]->pt_ch, hzto(&it.it_value),
    157  1.60.2.3   nathanw 		    realtimerexpire, p->p_timers[0]);
    158      1.16      fvdl 	}
    159  1.60.2.3   nathanw 	p->p_timers[0]->pt_time = it;
    160      1.47       erh 	splx(s);
    161       1.1      fvdl 
    162      1.16      fvdl 	return 0;
    163       1.1      fvdl }
    164       1.1      fvdl 
    165       1.1      fvdl int
    166  1.60.2.1   nathanw linux_sys_nice(l, v, retval)
    167  1.60.2.1   nathanw 	struct lwp *l;
    168      1.20   thorpej 	void *v;
    169      1.20   thorpej 	register_t *retval;
    170      1.20   thorpej {
    171      1.47       erh 	struct linux_sys_nice_args /* {
    172      1.47       erh 		syscallarg(int) incr;
    173      1.20   thorpej 	} */ *uap = v;
    174      1.47       erh         struct sys_setpriority_args bsa;
    175      1.20   thorpej 
    176      1.47       erh         SCARG(&bsa, which) = PRIO_PROCESS;
    177      1.47       erh         SCARG(&bsa, who) = 0;
    178      1.47       erh 	SCARG(&bsa, prio) = SCARG(uap, incr);
    179  1.60.2.1   nathanw         return sys_setpriority(l, &bsa, retval);
    180       1.1      fvdl }
    181       1.1      fvdl 
    182       1.1      fvdl /*
    183      1.47       erh  * The old Linux readdir was only able to read one entry at a time,
    184      1.47       erh  * even though it had a 'count' argument. In fact, the emulation
    185      1.47       erh  * of the old call was better than the original, because it did handle
    186      1.47       erh  * the count arg properly. Don't bother with it anymore now, and use
    187      1.47       erh  * it to distinguish between old and new. The difference is that the
    188      1.47       erh  * newer one actually does multiple entries, and the reclen field
    189      1.47       erh  * really is the reclen, not the namelength.
    190       1.1      fvdl  */
    191       1.1      fvdl int
    192  1.60.2.1   nathanw linux_sys_readdir(l, v, retval)
    193  1.60.2.1   nathanw 	struct lwp *l;
    194      1.20   thorpej 	void *v;
    195      1.20   thorpej 	register_t *retval;
    196      1.20   thorpej {
    197      1.47       erh 	struct linux_sys_readdir_args /* {
    198      1.47       erh 		syscallarg(int) fd;
    199      1.47       erh 		syscallarg(struct linux_dirent *) dent;
    200      1.47       erh 		syscallarg(unsigned int) count;
    201      1.20   thorpej 	} */ *uap = v;
    202       1.1      fvdl 
    203      1.47       erh 	SCARG(uap, count) = 1;
    204  1.60.2.1   nathanw 	return linux_sys_getdents(l, uap, retval);
    205       1.1      fvdl }
    206       1.1      fvdl 
    207       1.1      fvdl /*
    208       1.1      fvdl  * I wonder why Linux has gettimeofday() _and_ time().. Still, we
    209       1.1      fvdl  * need to deal with it.
    210       1.1      fvdl  */
    211       1.1      fvdl int
    212  1.60.2.1   nathanw linux_sys_time(l, v, retval)
    213  1.60.2.1   nathanw 	struct lwp *l;
    214      1.20   thorpej 	void *v;
    215      1.20   thorpej 	register_t *retval;
    216      1.20   thorpej {
    217      1.21   mycroft 	struct linux_sys_time_args /* {
    218       1.1      fvdl 		linux_time_t *t;
    219      1.20   thorpej 	} */ *uap = v;
    220       1.1      fvdl 	struct timeval atv;
    221       1.1      fvdl 	linux_time_t tt;
    222       1.1      fvdl 	int error;
    223       1.1      fvdl 
    224       1.1      fvdl 	microtime(&atv);
    225       1.1      fvdl 
    226       1.1      fvdl 	tt = atv.tv_sec;
    227       1.1      fvdl 	if (SCARG(uap, t) && (error = copyout(&tt, SCARG(uap, t), sizeof tt)))
    228       1.1      fvdl 		return error;
    229       1.1      fvdl 
    230       1.1      fvdl 	retval[0] = tt;
    231       1.1      fvdl 	return 0;
    232       1.1      fvdl }
    233       1.1      fvdl 
    234       1.1      fvdl /*
    235      1.47       erh  * utime(). Do conversion to things that utimes() understands,
    236      1.47       erh  * and pass it on.
    237       1.1      fvdl  */
    238       1.1      fvdl int
    239  1.60.2.1   nathanw linux_sys_utime(l, v, retval)
    240  1.60.2.1   nathanw 	struct lwp *l;
    241      1.20   thorpej 	void *v;
    242      1.20   thorpej 	register_t *retval;
    243      1.20   thorpej {
    244      1.47       erh 	struct linux_sys_utime_args /* {
    245      1.50  christos 		syscallarg(const char *) path;
    246      1.47       erh 		syscallarg(struct linux_utimbuf *)times;
    247      1.20   thorpej 	} */ *uap = v;
    248  1.60.2.1   nathanw 	struct proc *p = l->l_proc;
    249       1.2      fvdl 	caddr_t sg;
    250       1.2      fvdl 	int error;
    251      1.47       erh 	struct sys_utimes_args ua;
    252      1.47       erh 	struct timeval tv[2], *tvp;
    253      1.47       erh 	struct linux_utimbuf lut;
    254       1.2      fvdl 
    255  1.60.2.5   nathanw 	sg = stackgap_init(p, 0);
    256  1.60.2.5   nathanw 	tvp = (struct timeval *) stackgap_alloc(p, &sg, sizeof(tv));
    257      1.59  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    258       1.2      fvdl 
    259      1.47       erh 	SCARG(&ua, path) = SCARG(uap, path);
    260       1.2      fvdl 
    261      1.47       erh 	if (SCARG(uap, times) != NULL) {
    262      1.47       erh 		if ((error = copyin(SCARG(uap, times), &lut, sizeof lut)))
    263      1.47       erh 			return error;
    264      1.47       erh 		tv[0].tv_usec = tv[1].tv_usec = 0;
    265      1.47       erh 		tv[0].tv_sec = lut.l_actime;
    266      1.47       erh 		tv[1].tv_sec = lut.l_modtime;
    267      1.47       erh 		if ((error = copyout(tv, tvp, sizeof tv)))
    268      1.47       erh 			return error;
    269      1.47       erh 		SCARG(&ua, tptr) = tvp;
    270      1.47       erh 	}
    271      1.47       erh 	else
    272      1.47       erh 		SCARG(&ua, tptr) = NULL;
    273       1.2      fvdl 
    274  1.60.2.1   nathanw 	return sys_utimes(l, &ua, retval);
    275       1.1      fvdl }
    276       1.1      fvdl 
    277      1.47       erh /*
    278      1.47       erh  * waitpid(2). Passed on to the NetBSD call, surrounded by code to
    279      1.47       erh  * reserve some space for a NetBSD-style wait status, and converting
    280      1.47       erh  * it to what Linux wants.
    281      1.47       erh  */
    282       1.1      fvdl int
    283  1.60.2.1   nathanw linux_sys_waitpid(l, v, retval)
    284  1.60.2.1   nathanw 	struct lwp *l;
    285      1.20   thorpej 	void *v;
    286      1.20   thorpej 	register_t *retval;
    287      1.20   thorpej {
    288      1.47       erh 	struct linux_sys_waitpid_args /* {
    289      1.47       erh 		syscallarg(int) pid;
    290      1.47       erh 		syscallarg(int *) status;
    291      1.47       erh 		syscallarg(int) options;
    292      1.20   thorpej 	} */ *uap = v;
    293  1.60.2.1   nathanw 	struct proc *p = l->l_proc;
    294      1.47       erh 	struct sys_wait4_args w4a;
    295      1.47       erh 	int error, *status, tstat;
    296       1.2      fvdl 	caddr_t sg;
    297       1.2      fvdl 
    298      1.47       erh 	if (SCARG(uap, status) != NULL) {
    299  1.60.2.5   nathanw 		sg = stackgap_init(p, 0);
    300  1.60.2.5   nathanw 		status = (int *) stackgap_alloc(p, &sg, sizeof status);
    301      1.47       erh 	} else
    302      1.47       erh 		status = NULL;
    303       1.2      fvdl 
    304      1.47       erh 	SCARG(&w4a, pid) = SCARG(uap, pid);
    305      1.47       erh 	SCARG(&w4a, status) = status;
    306      1.47       erh 	SCARG(&w4a, options) = SCARG(uap, options);
    307      1.47       erh 	SCARG(&w4a, rusage) = NULL;
    308       1.2      fvdl 
    309  1.60.2.1   nathanw 	if ((error = sys_wait4(l, &w4a, retval)))
    310       1.2      fvdl 		return error;
    311       1.2      fvdl 
    312      1.60  jdolecek 	sigdelset(&p->p_sigctx.ps_siglist, SIGCHLD);
    313       1.2      fvdl 
    314      1.47       erh 	if (status != NULL) {
    315      1.47       erh 		if ((error = copyin(status, &tstat, sizeof tstat)))
    316      1.47       erh 			return error;
    317       1.2      fvdl 
    318      1.47       erh 		bsd_to_linux_wstat(&tstat);
    319      1.47       erh 		return copyout(&tstat, SCARG(uap, status), sizeof tstat);
    320      1.44   thorpej 	}
    321       1.1      fvdl 
    322      1.47       erh 	return 0;
    323      1.51   thorpej }
    324      1.51   thorpej 
    325      1.51   thorpej int
    326  1.60.2.1   nathanw linux_sys_setresgid(l, v, retval)
    327  1.60.2.1   nathanw 	struct lwp *l;
    328      1.51   thorpej 	void *v;
    329      1.51   thorpej 	register_t *retval;
    330      1.51   thorpej {
    331      1.51   thorpej 	struct linux_sys_setresgid_args /* {
    332      1.51   thorpej 		syscallarg(gid_t) rgid;
    333      1.51   thorpej 		syscallarg(gid_t) egid;
    334      1.51   thorpej 		syscallarg(gid_t) sgid;
    335      1.51   thorpej 	} */ *uap = v;
    336  1.60.2.1   nathanw 	struct proc *p = l->l_proc;
    337      1.51   thorpej 	struct pcred *pc = p->p_cred;
    338      1.51   thorpej 	gid_t rgid, egid, sgid;
    339      1.51   thorpej 	int error;
    340      1.51   thorpej 
    341      1.51   thorpej 	rgid = SCARG(uap, rgid);
    342      1.51   thorpej 	egid = SCARG(uap, egid);
    343      1.51   thorpej 	sgid = SCARG(uap, sgid);
    344      1.51   thorpej 
    345      1.51   thorpej 	/*
    346      1.51   thorpej 	 * Note: These checks are a little different than the NetBSD
    347      1.51   thorpej 	 * setregid(2) call performs.  This precisely follows the
    348      1.51   thorpej 	 * behavior of the Linux kernel.
    349      1.51   thorpej 	 */
    350      1.51   thorpej 	if (rgid != (gid_t)-1 &&
    351      1.51   thorpej 	    rgid != pc->p_rgid &&
    352      1.51   thorpej 	    rgid != pc->pc_ucred->cr_gid &&
    353      1.51   thorpej 	    rgid != pc->p_svgid &&
    354      1.51   thorpej 	    (error = suser(pc->pc_ucred, &p->p_acflag)))
    355      1.51   thorpej 		return (error);
    356      1.51   thorpej 
    357      1.51   thorpej 	if (egid != (gid_t)-1 &&
    358      1.51   thorpej 	    egid != pc->p_rgid &&
    359      1.51   thorpej 	    egid != pc->pc_ucred->cr_gid &&
    360      1.51   thorpej 	    egid != pc->p_svgid &&
    361      1.51   thorpej 	    (error = suser(pc->pc_ucred, &p->p_acflag)))
    362      1.51   thorpej 		return (error);
    363      1.51   thorpej 
    364      1.51   thorpej 	if (sgid != (gid_t)-1 &&
    365      1.51   thorpej 	    sgid != pc->p_rgid &&
    366      1.51   thorpej 	    sgid != pc->pc_ucred->cr_gid &&
    367      1.51   thorpej 	    sgid != pc->p_svgid &&
    368      1.51   thorpej 	    (error = suser(pc->pc_ucred, &p->p_acflag)))
    369      1.51   thorpej 		return (error);
    370      1.51   thorpej 
    371      1.51   thorpej 	/*
    372      1.51   thorpej 	 * Now assign the real, effective, and saved GIDs.
    373      1.51   thorpej 	 * Note that Linux, unlike NetBSD in setregid(2), does not
    374      1.51   thorpej 	 * set the saved UID in this call unless the user specifies
    375      1.51   thorpej 	 * it.
    376      1.51   thorpej 	 */
    377      1.51   thorpej 	if (rgid != (gid_t)-1)
    378      1.51   thorpej 		pc->p_rgid = rgid;
    379      1.51   thorpej 
    380      1.51   thorpej 	if (egid != (gid_t)-1) {
    381      1.51   thorpej 		pc->pc_ucred = crcopy(pc->pc_ucred);
    382      1.51   thorpej 		pc->pc_ucred->cr_gid = egid;
    383      1.51   thorpej 	}
    384      1.51   thorpej 
    385      1.51   thorpej 	if (sgid != (gid_t)-1)
    386      1.51   thorpej 		pc->p_svgid = sgid;
    387      1.51   thorpej 
    388      1.51   thorpej 	if (rgid != (gid_t)-1 && egid != (gid_t)-1 && sgid != (gid_t)-1)
    389      1.51   thorpej 		p->p_flag |= P_SUGID;
    390      1.51   thorpej 	return (0);
    391      1.51   thorpej }
    392      1.51   thorpej 
    393      1.51   thorpej int
    394  1.60.2.1   nathanw linux_sys_getresgid(l, v, retval)
    395  1.60.2.1   nathanw 	struct lwp *l;
    396      1.51   thorpej 	void *v;
    397      1.51   thorpej 	register_t *retval;
    398      1.51   thorpej {
    399      1.51   thorpej 	struct linux_sys_getresgid_args /* {
    400      1.51   thorpej 		syscallarg(gid_t *) rgid;
    401      1.51   thorpej 		syscallarg(gid_t *) egid;
    402      1.51   thorpej 		syscallarg(gid_t *) sgid;
    403      1.51   thorpej 	} */ *uap = v;
    404  1.60.2.1   nathanw 	struct proc *p = l->l_proc;
    405      1.51   thorpej 	struct pcred *pc = p->p_cred;
    406      1.51   thorpej 	int error;
    407      1.51   thorpej 
    408      1.51   thorpej 	/*
    409      1.51   thorpej 	 * Linux copies these values out to userspace like so:
    410      1.51   thorpej 	 *
    411      1.51   thorpej 	 *	1. Copy out rgid.
    412      1.51   thorpej 	 *	2. If that succeeds, copy out egid.
    413      1.51   thorpej 	 *	3. If both of those succeed, copy out sgid.
    414      1.51   thorpej 	 */
    415      1.51   thorpej 	if ((error = copyout(&pc->p_rgid, SCARG(uap, rgid),
    416      1.51   thorpej 			     sizeof(gid_t))) != 0)
    417      1.51   thorpej 		return (error);
    418      1.51   thorpej 
    419      1.51   thorpej 	if ((error = copyout(&pc->pc_ucred->cr_uid, SCARG(uap, egid),
    420      1.51   thorpej 			     sizeof(gid_t))) != 0)
    421      1.51   thorpej 		return (error);
    422      1.51   thorpej 
    423      1.51   thorpej 	return (copyout(&pc->p_svgid, SCARG(uap, sgid), sizeof(gid_t)));
    424      1.52      tron }
    425      1.52      tron 
    426      1.52      tron /*
    427      1.52      tron  * I wonder why Linux has settimeofday() _and_ stime().. Still, we
    428      1.52      tron  * need to deal with it.
    429      1.52      tron  */
    430      1.52      tron int
    431  1.60.2.1   nathanw linux_sys_stime(l, v, retval)
    432  1.60.2.1   nathanw 	struct lwp *l;
    433      1.52      tron 	void *v;
    434      1.52      tron 	register_t *retval;
    435      1.52      tron {
    436      1.52      tron 	struct linux_sys_time_args /* {
    437      1.52      tron 		linux_time_t *t;
    438      1.52      tron 	} */ *uap = v;
    439  1.60.2.1   nathanw 	struct proc *p = l->l_proc;
    440      1.52      tron 	struct timeval atv;
    441      1.52      tron 	linux_time_t tt;
    442      1.52      tron 	int error;
    443      1.52      tron 
    444      1.52      tron 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    445      1.52      tron 		return (error);
    446      1.52      tron 
    447      1.52      tron 	if ((error = copyin(&tt, SCARG(uap, t), sizeof tt)) != 0)
    448      1.52      tron 		return error;
    449      1.52      tron 
    450      1.52      tron 	atv.tv_sec = tt;
    451      1.52      tron 	atv.tv_usec = 0;
    452      1.52      tron 
    453      1.52      tron 	if ((error = settime(&atv)))
    454      1.52      tron 		return (error);
    455      1.52      tron 
    456      1.52      tron 	return 0;
    457       1.1      fvdl }
    458