#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_misc_notalpha.c,v 1.115 2022/05/22 11:27:34 andvar Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/mbuf.h>
#include <sys/namei.h>
#include <sys/proc.h>
#include <sys/prot.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/resourcevar.h>
#include <sys/time.h>
#include <sys/vfs_syscalls.h>
#include <sys/wait.h>
#include <sys/kauth.h>
#include <sys/syscallargs.h>
#include <compat/linux/common/linux_types.h>
#include <compat/linux/common/linux_fcntl.h>
#include <compat/linux/common/linux_misc.h>
#include <compat/linux/common/linux_mmap.h>
#include <compat/linux/common/linux_signal.h>
#include <compat/linux/common/linux_util.h>
#include <compat/linux/common/linux_ipc.h>
#include <compat/linux/common/linux_sem.h>
#include <compat/linux/common/linux_statfs.h>
#include <compat/linux/linux_syscallargs.h>
#ifdef DEBUG_LINUX
#define DPRINTF(a) uprintf a
#else
#define DPRINTF(a)
#endif
#ifndef COMPAT_LINUX32
int
linux_sys_alarm(struct lwp *l, const struct linux_sys_alarm_args *uap, register_t *retval)
{
struct proc *p = l->l_proc;
struct itimerval itv, oitv;
int error;
timerclear(&itv.it_interval);
itv.it_value.tv_sec = SCARG(uap, secs);
itv.it_value.tv_usec = 0;
if (itv.it_value.tv_sec < 0) {
return EINVAL;
}
if ((error = dogetitimer(p, ITIMER_REAL, &oitv)) != 0) {
return error;
}
if (oitv.it_value.tv_usec) {
oitv.it_value.tv_sec++;
}
if ((error = dosetitimer(p, ITIMER_REAL, &itv)) != 0) {
return error;
}
*retval = oitv.it_value.tv_sec;
return 0;
}
#endif
#if !defined(__aarch64__) && !defined(__amd64__)
int
linux_sys_nice(struct lwp *l, const struct linux_sys_nice_args *uap, register_t *retval)
{
struct proc *p = l->l_proc;
struct sys_setpriority_args bsa;
int error;
SCARG(&bsa, which) = PRIO_PROCESS;
SCARG(&bsa, who) = 0;
SCARG(&bsa, prio) = p->p_nice - NZERO + SCARG(uap, incr);
error = sys_setpriority(l, &bsa, retval);
return (error) ? EPERM : 0;
}
#endif
#ifndef COMPAT_LINUX32
#if !defined(__aarch64__) && !defined(__amd64__)
int
linux_sys_readdir(struct lwp *l, const struct linux_sys_readdir_args *uap, register_t *retval)
{
int error;
struct linux_sys_getdents_args da;
SCARG(&da, fd) = SCARG(uap, fd);
SCARG(&da, dent) = SCARG(uap, dent);
SCARG(&da, count) = 1;
error = linux_sys_getdents(l, &da, retval);
if (error == 0 && *retval > 1)
*retval = 1;
return error;
}
#endif
#if !defined(__aarch64__)
int
linux_sys_time(struct lwp *l, const struct linux_sys_time_args *uap, register_t *retval)
{
struct timeval atv;
linux_time_t tt;
int error;
microtime(&atv);
tt = atv.tv_sec;
if (SCARG(uap, t) && (error = copyout(&tt, SCARG(uap, t), sizeof tt)))
return error;
retval[0] = tt;
return 0;
}
#endif
#if !defined(__aarch64__)
int
linux_sys_utime(struct lwp *l, const struct linux_sys_utime_args *uap, register_t *retval)
{
int error;
struct timeval tv[2], *tvp;
struct linux_utimbuf lut;
if (SCARG(uap, times) != NULL) {
if ((error = copyin(SCARG(uap, times), &lut, sizeof lut)))
return error;
tv[0].tv_usec = tv[1].tv_usec = 0;
tv[0].tv_sec = lut.l_actime;
tv[1].tv_sec = lut.l_modtime;
tvp = tv;
} else
tvp = NULL;
return do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
tvp, UIO_SYSSPACE);
}
#endif
#if !defined(__aarch64__) && !defined(__amd64__)
int
linux_sys_waitpid(struct lwp *l, const struct linux_sys_waitpid_args *uap, register_t *retval)
{
struct linux_sys_wait4_args linux_w4a;
SCARG(&linux_w4a, pid) = SCARG(uap, pid);
SCARG(&linux_w4a, status) = SCARG(uap, status);
SCARG(&linux_w4a, options) = SCARG(uap, options);
SCARG(&linux_w4a, rusage) = NULL;
return linux_sys_wait4(l, &linux_w4a, retval);
}
#endif
int
linux_sys_setresgid(struct lwp *l, const struct linux_sys_setresgid_args *uap, register_t *retval)
{
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 );
}
int
linux_sys_getresgid(struct lwp *l, const struct linux_sys_getresgid_args *uap, register_t *retval)
{
kauth_cred_t pc = l->l_cred;
int error;
gid_t gid;
gid = kauth_cred_getgid(pc);
if ((error = copyout(&gid, SCARG(uap, rgid), sizeof(gid_t))) != 0)
return (error);
gid = kauth_cred_getegid(pc);
if ((error = copyout(&gid, SCARG(uap, egid), sizeof(gid_t))) != 0)
return (error);
gid = kauth_cred_getsvgid(pc);
return (copyout(&gid, SCARG(uap, sgid), sizeof(gid_t)));
}
#if !defined(__aarch64__) && !defined(__amd64__)
int
linux_sys_stime(struct lwp *l, const struct linux_sys_stime_args *uap, register_t *retval)
{
struct timespec ats;
linux_time_t tt;
int error;
if ((error = copyin(SCARG(uap, t), &tt, sizeof tt)) != 0)
return error;
ats.tv_sec = tt;
ats.tv_nsec = 0;
if ((error = settime(l->l_proc, &ats)))
return (error);
return 0;
}
int
linux_sys_statfs64(struct lwp *l, const struct linux_sys_statfs64_args *uap, register_t *retval)
{
struct statvfs *sb;
struct linux_statfs64 ltmp;
int error;
if (SCARG(uap, sz) != sizeof ltmp)
return (EINVAL);
sb = STATVFSBUF_GET();
error = do_sys_pstatvfs(l, SCARG(uap, path), ST_WAIT, sb);
if (error == 0) {
bsd_to_linux_statfs64(sb, <mp);
error = copyout(<mp, SCARG(uap, sp), sizeof ltmp);
}
STATVFSBUF_PUT(sb);
return error;
}
int
linux_sys_fstatfs64(struct lwp *l, const struct linux_sys_fstatfs64_args *uap, register_t *retval)
{
struct statvfs *sb;
struct linux_statfs64 ltmp;
int error;
if (SCARG(uap, sz) != sizeof ltmp)
return (EINVAL);
sb = STATVFSBUF_GET();
error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
if (error == 0) {
bsd_to_linux_statfs64(sb, <mp);
error = copyout(<mp, SCARG(uap, sp), sizeof ltmp);
}
STATVFSBUF_PUT(sb);
return error;
}
#endif
#endif