/*-
* Copyright (c) 1995, 1998, 2008, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
* of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Note that we must NOT include "opt_compat_linux32.h" here,
* the maze of ifdefs below relies on COMPAT_LINUX32 only being
* defined when this file is built for linux32.
*/
/*
* This file contains routines which are used
* on every linux architecture except the Alpha.
*/
/* Used on: arm, aarch64, i386, m68k, mips, ppc, sparc, sparc64 */
/* Not used on: alpha */
#ifdef DEBUG_LINUX
#define DPRINTF(a) uprintf a
#else
#define DPRINTF(a)
#endif
#ifndef COMPAT_LINUX32
/*
* Alarm. This is a libc call which uses setitimer(2) in NetBSD.
* Do the same here.
*/
int
linux_sys_alarm(struct lwp *l, const struct linux_sys_alarm_args *uap, register_t *retval)
{
/* {
syscallarg(unsigned int) secs;
} */
struct proc *p = l->l_proc;
struct itimerval itv, oitv;
int error;
#ifndef COMPAT_LINUX32
#if !defined(__aarch64__) && !defined(__amd64__)
/*
* The old Linux readdir was only able to read one entry at a time,
* even though it had a 'count' argument. In fact, the emulation
* of the old call was better than the original, because it did handle
* the count arg properly. Don't bother with it anymore now, and use
* it to distinguish between old and new. The difference is that the
* newer one actually does multiple entries, and the reclen field
* really is the reclen, not the namelength.
*/
int
linux_sys_readdir(struct lwp *l, const struct linux_sys_readdir_args *uap, register_t *retval)
{
/* {
syscallarg(int) fd;
syscallarg(struct linux_dirent *) dent;
syscallarg(unsigned int) count;
} */
int error;
struct linux_sys_getdents_args da;
#if !defined(__aarch64__)
/*
* I wonder why Linux has gettimeofday() _and_ time().. Still, we
* need to deal with it.
*/
int
linux_sys_time(struct lwp *l, const struct linux_sys_time_args *uap, register_t *retval)
{
/* {
syscallarg(linux_time_t) *t;
} */
struct timeval atv;
linux_time_t tt;
int error;
/*
* Note: These checks are a little different than the NetBSD
* setregid(2) call performs. This precisely follows the
* behavior of the Linux kernel.
*/
return do_setresgid(l, SCARG(uap,rgid), SCARG(uap, egid),
SCARG(uap, sgid),
ID_R_EQ_R | ID_R_EQ_E | ID_R_EQ_S |
ID_E_EQ_R | ID_E_EQ_E | ID_E_EQ_S |
ID_S_EQ_R | ID_S_EQ_E | ID_S_EQ_S );
}
/*
* Linux copies these values out to userspace like so:
*
* 1. Copy out rgid.
* 2. If that succeeds, copy out egid.
* 3. If both of those succeed, copy out sgid.
*/
gid = kauth_cred_getgid(pc);
if ((error = copyout(&gid, SCARG(uap, rgid), sizeof(gid_t))) != 0)
return (error);
#if !defined(__aarch64__) && !defined(__amd64__)
/*
* I wonder why Linux has settimeofday() _and_ stime().. Still, we
* need to deal with it.
*/
int
linux_sys_stime(struct lwp *l, const struct linux_sys_stime_args *uap, register_t *retval)
{
/* {
syscallarg(linux_time_t) *t;
} */
struct timespec ats;
linux_time_t tt;
int error;