2004-08-16 07:55:06 +00:00
|
|
|
/*-
|
2017-11-27 15:03:07 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2004-08-16 07:55:06 +00:00
|
|
|
* Copyright (c) 2004 Tim J. Robbins
|
|
|
|
* Copyright (c) 2002 Doug Rabson
|
|
|
|
* Copyright (c) 2000 Marcel Moolenaar
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 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.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2018-04-08 17:10:32 +00:00
|
|
|
#include "opt_compat.h"
|
|
|
|
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <sys/param.h>
|
2014-03-16 10:55:57 +00:00
|
|
|
#include <sys/capsicum.h>
|
2006-10-02 12:59:59 +00:00
|
|
|
#include <sys/clock.h>
|
2018-03-23 17:16:36 +00:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/file.h>
|
2005-02-18 18:51:59 +00:00
|
|
|
#include <sys/imgact.h>
|
2018-03-23 17:16:36 +00:00
|
|
|
#include <sys/kernel.h>
|
Add the linux 2.6.x stuff (not used by default!):
- TLS - complete
- pid/tid mangling - complete
- thread area - complete
- futexes - complete with issues
- clone() extension - complete with some possible minor issues
- mq*/timer*/clock* stuff - complete but untested and the mq* stuff is
disabled when not build as part of the kernel with native FreeBSD mq*
support (module support for this will come later)
Tested with:
- linux-firefox - works, tested
- linux-opera - works, tested
- linux-realplay - doesnt work, issue with futexes
- linux-skype - doesnt work, issue with futexes
- linux-rt2-demo - works, tested
- linux-acroread - doesnt work, unknown reason (coredump) and sometimes
issue with futexes
- various unix utilities in linux-base-gentoo3 and linux-base-fc4:
everything tried worked
On amd64 not everything is supported like on i386, the catchup is planned for
later when the remaining bugs in the new functions are fixed.
To test this new stuff, you have to run
sysctl compat.linux.osrelease=2.6.16
to switch back use
sysctl compat.linux.osrelease=2.4.2
Don't switch while running a linux program, strange things may or may not
happen.
Sponsored by: Google SoC 2006
Submitted by: rdivacky
Some suggestions/help by: jhb, kib, manu@NetBSD.org, netchild
2006-08-15 12:54:30 +00:00
|
|
|
#include <sys/limits.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/mutex.h>
|
2007-02-15 01:13:36 +00:00
|
|
|
#include <sys/priv.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/syscallsubr.h>
|
|
|
|
#include <sys/sysproto.h>
|
2018-03-23 17:16:36 +00:00
|
|
|
#include <sys/systm.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <sys/unistd.h>
|
2011-01-28 18:47:07 +00:00
|
|
|
#include <sys/wait.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
|
|
|
|
#include <machine/frame.h>
|
2018-08-07 18:29:10 +00:00
|
|
|
#include <machine/md_var.h>
|
2007-03-30 00:06:21 +00:00
|
|
|
#include <machine/pcb.h>
|
2007-02-15 01:13:36 +00:00
|
|
|
#include <machine/psl.h>
|
2007-03-30 00:06:21 +00:00
|
|
|
#include <machine/segments.h>
|
|
|
|
#include <machine/specialreg.h>
|
2018-08-07 18:29:10 +00:00
|
|
|
#include <x86/ifunc.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
|
|
|
|
#include <vm/pmap.h>
|
2018-03-23 17:16:36 +00:00
|
|
|
#include <vm/vm.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <vm/vm_map.h>
|
|
|
|
|
2020-10-26 17:30:17 +00:00
|
|
|
#include <security/audit/audit.h>
|
|
|
|
|
2010-07-23 21:30:33 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_util.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <amd64/linux32/linux.h>
|
|
|
|
#include <amd64/linux32/linux32_proto.h>
|
2018-03-23 17:16:36 +00:00
|
|
|
#include <compat/linux/linux_emul.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <compat/linux/linux_ipc.h>
|
2011-01-28 18:47:07 +00:00
|
|
|
#include <compat/linux/linux_misc.h>
|
2016-07-10 08:22:04 +00:00
|
|
|
#include <compat/linux/linux_mmap.h>
|
2004-08-16 07:55:06 +00:00
|
|
|
#include <compat/linux/linux_signal.h>
|
|
|
|
#include <compat/linux/linux_util.h>
|
|
|
|
|
2015-05-24 15:03:09 +00:00
|
|
|
static void bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru);
|
|
|
|
|
2004-08-16 07:55:06 +00:00
|
|
|
struct l_old_select_argv {
|
|
|
|
l_int nfds;
|
|
|
|
l_uintptr_t readfds;
|
|
|
|
l_uintptr_t writefds;
|
|
|
|
l_uintptr_t exceptfds;
|
|
|
|
l_uintptr_t timeout;
|
|
|
|
} __packed;
|
|
|
|
|
2011-01-29 07:22:33 +00:00
|
|
|
static void
|
|
|
|
bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru)
|
2011-01-28 18:28:06 +00:00
|
|
|
{
|
2011-01-29 07:22:33 +00:00
|
|
|
|
2011-01-28 18:28:06 +00:00
|
|
|
lru->ru_utime.tv_sec = ru->ru_utime.tv_sec;
|
|
|
|
lru->ru_utime.tv_usec = ru->ru_utime.tv_usec;
|
|
|
|
lru->ru_stime.tv_sec = ru->ru_stime.tv_sec;
|
|
|
|
lru->ru_stime.tv_usec = ru->ru_stime.tv_usec;
|
|
|
|
lru->ru_maxrss = ru->ru_maxrss;
|
|
|
|
lru->ru_ixrss = ru->ru_ixrss;
|
|
|
|
lru->ru_idrss = ru->ru_idrss;
|
|
|
|
lru->ru_isrss = ru->ru_isrss;
|
|
|
|
lru->ru_minflt = ru->ru_minflt;
|
|
|
|
lru->ru_majflt = ru->ru_majflt;
|
|
|
|
lru->ru_nswap = ru->ru_nswap;
|
|
|
|
lru->ru_inblock = ru->ru_inblock;
|
|
|
|
lru->ru_oublock = ru->ru_oublock;
|
|
|
|
lru->ru_msgsnd = ru->ru_msgsnd;
|
|
|
|
lru->ru_msgrcv = ru->ru_msgrcv;
|
|
|
|
lru->ru_nsignals = ru->ru_nsignals;
|
|
|
|
lru->ru_nvcsw = ru->ru_nvcsw;
|
|
|
|
lru->ru_nivcsw = ru->ru_nivcsw;
|
|
|
|
}
|
|
|
|
|
2015-05-24 15:03:09 +00:00
|
|
|
int
|
|
|
|
linux_copyout_rusage(struct rusage *ru, void *uaddr)
|
|
|
|
{
|
|
|
|
struct l_rusage lru;
|
|
|
|
|
|
|
|
bsd_to_linux_rusage(ru, &lru);
|
|
|
|
|
|
|
|
return (copyout(&lru, uaddr, sizeof(struct l_rusage)));
|
|
|
|
}
|
|
|
|
|
2005-02-18 18:51:59 +00:00
|
|
|
int
|
|
|
|
linux_execve(struct thread *td, struct linux_execve_args *args)
|
|
|
|
{
|
|
|
|
struct image_args eargs;
|
|
|
|
char *path;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
LCONVPATHEXIST(td, args->path, &path);
|
|
|
|
|
2010-07-23 21:30:33 +00:00
|
|
|
error = freebsd32_exec_copyin_args(&eargs, path, UIO_SYSSPACE,
|
|
|
|
args->argp, args->envp);
|
2005-02-18 18:51:59 +00:00
|
|
|
free(path, M_TEMP);
|
2015-05-24 14:53:16 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = linux_common_execve(td, &eargs);
|
2020-10-26 17:30:17 +00:00
|
|
|
AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
|
2005-02-18 18:51:59 +00:00
|
|
|
return (error);
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-29 14:55:24 +00:00
|
|
|
CTASSERT(sizeof(struct l_iovec32) == 8);
|
2004-08-16 07:55:06 +00:00
|
|
|
|
2017-02-24 20:04:02 +00:00
|
|
|
int
|
2008-11-29 14:55:24 +00:00
|
|
|
linux32_copyinuio(struct l_iovec32 *iovp, l_ulong iovcnt, struct uio **uiop)
|
2004-08-16 07:55:06 +00:00
|
|
|
{
|
2008-11-29 14:55:24 +00:00
|
|
|
struct l_iovec32 iov32;
|
2005-03-31 22:57:21 +00:00
|
|
|
struct iovec *iov;
|
|
|
|
struct uio *uio;
|
2008-11-29 14:55:24 +00:00
|
|
|
uint32_t iovlen;
|
2005-03-31 22:57:21 +00:00
|
|
|
int error, i;
|
|
|
|
|
|
|
|
*uiop = NULL;
|
|
|
|
if (iovcnt > UIO_MAXIOV)
|
2004-08-16 07:55:06 +00:00
|
|
|
return (EINVAL);
|
2005-03-31 22:57:21 +00:00
|
|
|
iovlen = iovcnt * sizeof(struct iovec);
|
2007-04-18 18:11:32 +00:00
|
|
|
uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK);
|
2005-03-31 22:57:21 +00:00
|
|
|
iov = (struct iovec *)(uio + 1);
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
2008-11-29 14:55:24 +00:00
|
|
|
error = copyin(&iovp[i], &iov32, sizeof(struct l_iovec32));
|
2005-03-31 22:57:21 +00:00
|
|
|
if (error) {
|
|
|
|
free(uio, M_IOV);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
iov[i].iov_base = PTRIN(iov32.iov_base);
|
|
|
|
iov[i].iov_len = iov32.iov_len;
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
2005-03-31 22:57:21 +00:00
|
|
|
uio->uio_iov = iov;
|
|
|
|
uio->uio_iovcnt = iovcnt;
|
|
|
|
uio->uio_segflg = UIO_USERSPACE;
|
|
|
|
uio->uio_offset = -1;
|
|
|
|
uio->uio_resid = 0;
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
if (iov->iov_len > INT_MAX - uio->uio_resid) {
|
|
|
|
free(uio, M_IOV);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
uio->uio_resid += iov->iov_len;
|
|
|
|
iov++;
|
|
|
|
}
|
|
|
|
*uiop = uio;
|
|
|
|
return (0);
|
|
|
|
}
|
2004-08-16 07:55:06 +00:00
|
|
|
|
2008-11-29 14:55:24 +00:00
|
|
|
int
|
|
|
|
linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt, struct iovec **iovp,
|
|
|
|
int error)
|
|
|
|
{
|
|
|
|
struct l_iovec32 iov32;
|
|
|
|
struct iovec *iov;
|
|
|
|
uint32_t iovlen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*iovp = NULL;
|
|
|
|
if (iovcnt > UIO_MAXIOV)
|
|
|
|
return (error);
|
|
|
|
iovlen = iovcnt * sizeof(struct iovec);
|
|
|
|
iov = malloc(iovlen, M_IOV, M_WAITOK);
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
error = copyin(&iovp32[i], &iov32, sizeof(struct l_iovec32));
|
|
|
|
if (error) {
|
|
|
|
free(iov, M_IOV);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
iov[i].iov_base = PTRIN(iov32.iov_base);
|
|
|
|
iov[i].iov_len = iov32.iov_len;
|
|
|
|
}
|
|
|
|
*iovp = iov;
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-03-31 22:57:21 +00:00
|
|
|
int
|
|
|
|
linux_readv(struct thread *td, struct linux_readv_args *uap)
|
|
|
|
{
|
|
|
|
struct uio *auio;
|
|
|
|
int error;
|
2004-08-16 07:55:06 +00:00
|
|
|
|
2005-03-31 22:57:21 +00:00
|
|
|
error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
error = kern_readv(td, uap->fd, auio);
|
|
|
|
free(auio, M_IOV);
|
2004-08-16 07:55:06 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_writev(struct thread *td, struct linux_writev_args *uap)
|
|
|
|
{
|
2005-03-31 22:57:21 +00:00
|
|
|
struct uio *auio;
|
|
|
|
int error;
|
2004-08-16 07:55:06 +00:00
|
|
|
|
2005-03-31 22:57:21 +00:00
|
|
|
error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
error = kern_writev(td, uap->fd, auio);
|
|
|
|
free(auio, M_IOV);
|
2004-08-16 07:55:06 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct l_ipc_kludge {
|
|
|
|
l_uintptr_t msgp;
|
|
|
|
l_long msgtyp;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_ipc(struct thread *td, struct linux_ipc_args *args)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (args->what & 0xFFFF) {
|
|
|
|
case LINUX_SEMOP: {
|
|
|
|
struct linux_semop_args a;
|
|
|
|
|
|
|
|
a.semid = args->arg1;
|
2019-03-24 14:44:35 +00:00
|
|
|
a.tsops = PTRIN(args->ptr);
|
2004-08-16 07:55:06 +00:00
|
|
|
a.nsops = args->arg2;
|
|
|
|
return (linux_semop(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_SEMGET: {
|
|
|
|
struct linux_semget_args a;
|
|
|
|
|
|
|
|
a.key = args->arg1;
|
|
|
|
a.nsems = args->arg2;
|
|
|
|
a.semflg = args->arg3;
|
|
|
|
return (linux_semget(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_SEMCTL: {
|
|
|
|
struct linux_semctl_args a;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
a.semid = args->arg1;
|
|
|
|
a.semnum = args->arg2;
|
|
|
|
a.cmd = args->arg3;
|
2019-03-24 14:44:35 +00:00
|
|
|
error = copyin(PTRIN(args->ptr), &a.arg, sizeof(a.arg));
|
2004-08-16 07:55:06 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
return (linux_semctl(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_MSGSND: {
|
|
|
|
struct linux_msgsnd_args a;
|
|
|
|
|
|
|
|
a.msqid = args->arg1;
|
2019-03-24 14:44:35 +00:00
|
|
|
a.msgp = PTRIN(args->ptr);
|
2004-08-16 07:55:06 +00:00
|
|
|
a.msgsz = args->arg2;
|
|
|
|
a.msgflg = args->arg3;
|
|
|
|
return (linux_msgsnd(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_MSGRCV: {
|
|
|
|
struct linux_msgrcv_args a;
|
|
|
|
|
|
|
|
a.msqid = args->arg1;
|
|
|
|
a.msgsz = args->arg2;
|
|
|
|
a.msgflg = args->arg3;
|
|
|
|
if ((args->what >> 16) == 0) {
|
|
|
|
struct l_ipc_kludge tmp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (args->ptr == 0)
|
|
|
|
return (EINVAL);
|
2019-03-24 14:44:35 +00:00
|
|
|
error = copyin(PTRIN(args->ptr), &tmp, sizeof(tmp));
|
2004-08-16 07:55:06 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
a.msgp = PTRIN(tmp.msgp);
|
|
|
|
a.msgtyp = tmp.msgtyp;
|
|
|
|
} else {
|
2019-03-24 14:44:35 +00:00
|
|
|
a.msgp = PTRIN(args->ptr);
|
2004-08-16 07:55:06 +00:00
|
|
|
a.msgtyp = args->arg5;
|
|
|
|
}
|
|
|
|
return (linux_msgrcv(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_MSGGET: {
|
|
|
|
struct linux_msgget_args a;
|
|
|
|
|
|
|
|
a.key = args->arg1;
|
|
|
|
a.msgflg = args->arg2;
|
|
|
|
return (linux_msgget(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_MSGCTL: {
|
|
|
|
struct linux_msgctl_args a;
|
|
|
|
|
|
|
|
a.msqid = args->arg1;
|
|
|
|
a.cmd = args->arg2;
|
2019-03-24 14:44:35 +00:00
|
|
|
a.buf = PTRIN(args->ptr);
|
2004-08-16 07:55:06 +00:00
|
|
|
return (linux_msgctl(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_SHMAT: {
|
|
|
|
struct linux_shmat_args a;
|
2019-03-24 14:44:35 +00:00
|
|
|
l_uintptr_t addr;
|
|
|
|
int error;
|
2004-08-16 07:55:06 +00:00
|
|
|
|
|
|
|
a.shmid = args->arg1;
|
2019-03-24 14:44:35 +00:00
|
|
|
a.shmaddr = PTRIN(args->ptr);
|
2004-08-16 07:55:06 +00:00
|
|
|
a.shmflg = args->arg2;
|
2019-03-24 14:44:35 +00:00
|
|
|
error = linux_shmat(td, &a);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
addr = td->td_retval[0];
|
|
|
|
error = copyout(&addr, PTRIN(args->arg3), sizeof(addr));
|
|
|
|
td->td_retval[0] = 0;
|
|
|
|
return (error);
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
|
|
|
case LINUX_SHMDT: {
|
|
|
|
struct linux_shmdt_args a;
|
|
|
|
|
2019-03-24 14:44:35 +00:00
|
|
|
a.shmaddr = PTRIN(args->ptr);
|
2004-08-16 07:55:06 +00:00
|
|
|
return (linux_shmdt(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_SHMGET: {
|
|
|
|
struct linux_shmget_args a;
|
|
|
|
|
|
|
|
a.key = args->arg1;
|
|
|
|
a.size = args->arg2;
|
|
|
|
a.shmflg = args->arg3;
|
|
|
|
return (linux_shmget(td, &a));
|
|
|
|
}
|
|
|
|
case LINUX_SHMCTL: {
|
|
|
|
struct linux_shmctl_args a;
|
|
|
|
|
|
|
|
a.shmid = args->arg1;
|
|
|
|
a.cmd = args->arg2;
|
2019-03-24 14:44:35 +00:00
|
|
|
a.buf = PTRIN(args->ptr);
|
2004-08-16 07:55:06 +00:00
|
|
|
return (linux_shmctl(td, &a));
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_old_select(struct thread *td, struct linux_old_select_args *args)
|
|
|
|
{
|
|
|
|
struct l_old_select_argv linux_args;
|
|
|
|
struct linux_select_args newsel;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = copyin(args->ptr, &linux_args, sizeof(linux_args));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
newsel.nfds = linux_args.nfds;
|
|
|
|
newsel.readfds = PTRIN(linux_args.readfds);
|
|
|
|
newsel.writefds = PTRIN(linux_args.writefds);
|
|
|
|
newsel.exceptfds = PTRIN(linux_args.exceptfds);
|
|
|
|
newsel.timeout = PTRIN(linux_args.timeout);
|
|
|
|
return (linux_select(td, &newsel));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-02-12 15:50:21 +00:00
|
|
|
linux_set_cloned_tls(struct thread *td, void *desc)
|
|
|
|
{
|
|
|
|
struct user_segment_descriptor sd;
|
|
|
|
struct l_user_desc info;
|
|
|
|
struct pcb *pcb;
|
|
|
|
int error;
|
|
|
|
int a[2];
|
|
|
|
|
|
|
|
error = copyin(desc, &info, sizeof(struct l_user_desc));
|
|
|
|
if (error) {
|
2019-05-13 18:24:29 +00:00
|
|
|
linux_msg(td, "set_cloned_tls copyin info failed!");
|
2011-02-12 15:50:21 +00:00
|
|
|
} else {
|
|
|
|
/* We might copy out the entry_number as GUGS32_SEL. */
|
|
|
|
info.entry_number = GUGS32_SEL;
|
|
|
|
error = copyout(&info, desc, sizeof(struct l_user_desc));
|
|
|
|
if (error)
|
2019-05-13 18:24:29 +00:00
|
|
|
linux_msg(td, "set_cloned_tls copyout info failed!");
|
2011-02-12 15:50:21 +00:00
|
|
|
|
|
|
|
a[0] = LINUX_LDT_entry_a(&info);
|
|
|
|
a[1] = LINUX_LDT_entry_b(&info);
|
|
|
|
|
|
|
|
memcpy(&sd, &a, sizeof(a));
|
|
|
|
pcb = td->td_pcb;
|
|
|
|
pcb->pcb_gsbase = (register_t)info.base_addr;
|
|
|
|
td->td_frame->tf_gs = GSEL(GUGS32_SEL, SEL_UPL);
|
2013-05-09 21:42:43 +00:00
|
|
|
set_pcb_flags(pcb, PCB_32BIT);
|
2011-02-12 15:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-12 16:33:00 +00:00
|
|
|
int
|
|
|
|
linux_set_upcall_kse(struct thread *td, register_t stack)
|
|
|
|
{
|
|
|
|
|
2015-05-24 14:53:16 +00:00
|
|
|
if (stack)
|
|
|
|
td->td_frame->tf_rsp = stack;
|
2011-02-12 16:33:00 +00:00
|
|
|
|
2015-05-24 14:53:16 +00:00
|
|
|
/*
|
|
|
|
* The newly created Linux thread returns
|
|
|
|
* to the user space by the same path that a parent do.
|
|
|
|
*/
|
|
|
|
td->td_frame->tf_rax = 0;
|
2011-02-12 16:33:00 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-08-16 07:55:06 +00:00
|
|
|
int
|
|
|
|
linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
|
|
|
|
{
|
|
|
|
|
2009-10-28 20:17:54 +00:00
|
|
|
return (linux_mmap_common(td, PTROUT(args->addr), args->len, args->prot,
|
|
|
|
args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
|
|
|
|
PAGE_SIZE));
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_mmap(struct thread *td, struct linux_mmap_args *args)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct l_mmap_argv linux_args;
|
|
|
|
|
|
|
|
error = copyin(args->ptr, &linux_args, sizeof(linux_args));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2009-10-28 20:17:54 +00:00
|
|
|
return (linux_mmap_common(td, linux_args.addr, linux_args.len,
|
|
|
|
linux_args.prot, linux_args.flags, linux_args.fd,
|
|
|
|
(uint32_t)linux_args.pgoff));
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 00:06:21 +00:00
|
|
|
int
|
|
|
|
linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
|
|
|
|
{
|
2016-07-10 08:22:04 +00:00
|
|
|
|
|
|
|
return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len, uap->prot));
|
2007-03-30 00:06:21 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 18:29:22 +00:00
|
|
|
int
|
|
|
|
linux_madvise(struct thread *td, struct linux_madvise_args *uap)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (linux_madvise_common(td, PTROUT(uap->addr), uap->len, uap->behav));
|
|
|
|
}
|
|
|
|
|
2007-02-15 01:13:36 +00:00
|
|
|
int
|
|
|
|
linux_iopl(struct thread *td, struct linux_iopl_args *args)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (args->level < 0 || args->level > 3)
|
|
|
|
return (EINVAL);
|
|
|
|
if ((error = priv_check(td, PRIV_IO)) != 0)
|
|
|
|
return (error);
|
|
|
|
if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
|
|
|
|
return (error);
|
|
|
|
td->td_frame->tf_rflags = (td->td_frame->tf_rflags & ~PSL_IOPL) |
|
|
|
|
(args->level * (PSL_IOPL / 3));
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-08-16 07:55:06 +00:00
|
|
|
int
|
|
|
|
linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
|
|
|
|
{
|
|
|
|
l_osigaction_t osa;
|
|
|
|
l_sigaction_t act, oact;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (args->nsa != NULL) {
|
|
|
|
error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
act.lsa_handler = osa.lsa_handler;
|
|
|
|
act.lsa_flags = osa.lsa_flags;
|
|
|
|
act.lsa_restorer = osa.lsa_restorer;
|
|
|
|
LINUX_SIGEMPTYSET(act.lsa_mask);
|
2015-05-24 17:47:20 +00:00
|
|
|
act.lsa_mask.__mask = osa.lsa_mask;
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
|
|
|
|
args->osa ? &oact : NULL);
|
|
|
|
|
|
|
|
if (args->osa != NULL && !error) {
|
|
|
|
osa.lsa_handler = oact.lsa_handler;
|
|
|
|
osa.lsa_flags = oact.lsa_flags;
|
|
|
|
osa.lsa_restorer = oact.lsa_restorer;
|
2015-05-24 17:47:20 +00:00
|
|
|
osa.lsa_mask = oact.lsa_mask.__mask;
|
2004-08-16 07:55:06 +00:00
|
|
|
error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-30 17:27:13 +00:00
|
|
|
* Linux has two extra args, restart and oldmask. We don't use these,
|
2004-08-16 07:55:06 +00:00
|
|
|
* but it seems that "restart" is actually a context pointer that
|
|
|
|
* enables the signal to happen with a different register set.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
|
|
|
|
{
|
|
|
|
sigset_t sigmask;
|
|
|
|
l_sigset_t mask;
|
|
|
|
|
|
|
|
LINUX_SIGEMPTYSET(mask);
|
2015-05-24 17:47:20 +00:00
|
|
|
mask.__mask = args->mask;
|
2004-08-16 07:55:06 +00:00
|
|
|
linux_to_bsd_sigset(&mask, &sigmask);
|
|
|
|
return (kern_sigsuspend(td, sigmask));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
|
|
|
|
{
|
|
|
|
l_sigset_t lmask;
|
|
|
|
sigset_t sigmask;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (uap->sigsetsize != sizeof(l_sigset_t))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
linux_to_bsd_sigset(&lmask, &sigmask);
|
|
|
|
return (kern_sigsuspend(td, sigmask));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_pause(struct thread *td, struct linux_pause_args *args)
|
|
|
|
{
|
|
|
|
struct proc *p = td->td_proc;
|
|
|
|
sigset_t sigmask;
|
|
|
|
|
|
|
|
PROC_LOCK(p);
|
|
|
|
sigmask = td->td_sigmask;
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
return (kern_sigsuspend(td, sigmask));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
|
|
|
|
{
|
|
|
|
stack_t ss, oss;
|
|
|
|
l_stack_t lss;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (uap->uss != NULL) {
|
|
|
|
error = copyin(uap->uss, &lss, sizeof(l_stack_t));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ss.ss_sp = PTRIN(lss.ss_sp);
|
|
|
|
ss.ss_size = lss.ss_size;
|
|
|
|
ss.ss_flags = linux_to_bsd_sigaltstack(lss.ss_flags);
|
|
|
|
}
|
2004-08-24 20:52:52 +00:00
|
|
|
error = kern_sigaltstack(td, (uap->uss != NULL) ? &ss : NULL,
|
|
|
|
(uap->uoss != NULL) ? &oss : NULL);
|
2004-08-16 07:55:06 +00:00
|
|
|
if (!error && uap->uoss != NULL) {
|
|
|
|
lss.ss_sp = PTROUT(oss.ss_sp);
|
|
|
|
lss.ss_size = oss.ss_size;
|
|
|
|
lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
|
|
|
|
error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_gettimeofday(struct thread *td, struct linux_gettimeofday_args *uap)
|
|
|
|
{
|
|
|
|
struct timeval atv;
|
|
|
|
l_timeval atv32;
|
|
|
|
struct timezone rtz;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (uap->tp) {
|
|
|
|
microtime(&atv);
|
|
|
|
atv32.tv_sec = atv.tv_sec;
|
|
|
|
atv32.tv_usec = atv.tv_usec;
|
2007-04-18 18:11:32 +00:00
|
|
|
error = copyout(&atv32, uap->tp, sizeof(atv32));
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
|
|
|
if (error == 0 && uap->tzp != NULL) {
|
Kill tz_minuteswest and tz_dsttime.
Research Unix, 7th Edition introduced TIMEZONE and DSTFLAG
compile-time constants in sys/param.h to communicate these values for
the machine. 4.2BSD moved from the compile-time to run-time and
introduced these variables and used for localtime() to return the
right offset from UTC (sometimes referred to as GMT, for this purpose
is the same). 4.4BSD migrated to using the tzdata code/database and
these variables were basically unused.
FreeBSD removed the real need for these with adjkerntz in
1995. However, some RTC clocks continued to use these variables,
though they were largely unused otherwise. Later, phk centeralized
most of the uses in utc_offset, but left it using both tz_minuteswest
and adjkerntz.
POSIX (IEEE Std 1003.1-2017) states in the gettimeofday specification
"If tzp is not a null pointer, the behavior is unspecified" so there's
no standards reason to retain it anymore. In fact, gettimeofday has
been marked as obsolecent, meaning it could be removed from a future
release of the standard. It is the only interface defined in POSIX
that references these two values. All other references come from the
tzdata database via tzset().
These were used to more faithfully implement early unix ABIs which
have been removed from FreeBSD. NetBSD has completely eliminated
these variables years ago. Linux has migrated to tzdata as well,
though these variables technically still exist for compatibility
with unspecified older programs.
So, there's no real reason to have them these days. They are a
historical vestige that's no longer used in any meaningful way.
Reviewed By: jhb@, brooks@
Differential Revision: https://reviews.freebsd.org/D19550
2019-03-12 04:49:47 +00:00
|
|
|
rtz.tz_minuteswest = 0;
|
|
|
|
rtz.tz_dsttime = 0;
|
2007-04-18 18:11:32 +00:00
|
|
|
error = copyout(&rtz, uap->tzp, sizeof(rtz));
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:08:12 +00:00
|
|
|
int
|
|
|
|
linux_settimeofday(struct thread *td, struct linux_settimeofday_args *uap)
|
|
|
|
{
|
|
|
|
l_timeval atv32;
|
|
|
|
struct timeval atv, *tvp;
|
|
|
|
struct timezone atz, *tzp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (uap->tp) {
|
|
|
|
error = copyin(uap->tp, &atv32, sizeof(atv32));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
atv.tv_sec = atv32.tv_sec;
|
|
|
|
atv.tv_usec = atv32.tv_usec;
|
|
|
|
tvp = &atv;
|
|
|
|
} else
|
|
|
|
tvp = NULL;
|
|
|
|
if (uap->tzp) {
|
|
|
|
error = copyin(uap->tzp, &atz, sizeof(atz));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
tzp = &atz;
|
|
|
|
} else
|
|
|
|
tzp = NULL;
|
|
|
|
return (kern_settimeofday(td, tvp, tzp));
|
|
|
|
}
|
|
|
|
|
2004-08-16 07:55:06 +00:00
|
|
|
int
|
|
|
|
linux_getrusage(struct thread *td, struct linux_getrusage_args *uap)
|
|
|
|
{
|
2004-10-05 18:51:11 +00:00
|
|
|
struct rusage s;
|
2004-08-16 07:55:06 +00:00
|
|
|
int error;
|
2004-10-05 18:51:11 +00:00
|
|
|
|
|
|
|
error = kern_getrusage(td, uap->who, &s);
|
2004-08-16 07:55:06 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2015-05-24 15:03:09 +00:00
|
|
|
if (uap->rusage != NULL)
|
|
|
|
error = linux_copyout_rusage(&s, uap->rusage);
|
2004-08-16 07:55:06 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-30 00:06:21 +00:00
|
|
|
linux_set_thread_area(struct thread *td,
|
|
|
|
struct linux_set_thread_area_args *args)
|
2004-08-16 07:55:06 +00:00
|
|
|
{
|
2007-03-30 00:06:21 +00:00
|
|
|
struct l_user_desc info;
|
|
|
|
struct user_segment_descriptor sd;
|
2010-12-22 00:18:42 +00:00
|
|
|
struct pcb *pcb;
|
2007-03-30 00:06:21 +00:00
|
|
|
int a[2];
|
|
|
|
int error;
|
2004-08-16 07:55:06 +00:00
|
|
|
|
2007-03-30 00:06:21 +00:00
|
|
|
error = copyin(args->desc, &info, sizeof(struct l_user_desc));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Semantics of Linux version: every thread in the system has array
|
|
|
|
* of three TLS descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown.
|
|
|
|
* This syscall loads one of the selected TLS decriptors with a value
|
|
|
|
* and also loads GDT descriptors 6, 7 and 8 with the content of
|
|
|
|
* the per-thread descriptors.
|
|
|
|
*
|
|
|
|
* Semantics of FreeBSD version: I think we can ignore that Linux has
|
|
|
|
* three per-thread descriptors and use just the first one.
|
|
|
|
* The tls_array[] is used only in [gs]et_thread_area() syscalls and
|
|
|
|
* for loading the GDT descriptors. We use just one GDT descriptor
|
|
|
|
* for TLS, so we will load just one.
|
2007-04-18 20:12:05 +00:00
|
|
|
*
|
|
|
|
* XXX: This doesn't work when a user space process tries to use more
|
2007-03-30 00:06:21 +00:00
|
|
|
* than one TLS segment. Comment in the Linux source says wine might
|
2007-04-18 20:12:05 +00:00
|
|
|
* do this.
|
2007-03-30 00:06:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GLIBC reads current %gs and call set_thread_area() with it.
|
|
|
|
* We should let GUDATA_SEL and GUGS32_SEL proceed as well because
|
|
|
|
* we use these segments.
|
|
|
|
*/
|
|
|
|
switch (info.entry_number) {
|
|
|
|
case GUGS32_SEL:
|
|
|
|
case GUDATA_SEL:
|
|
|
|
case 6:
|
|
|
|
case -1:
|
|
|
|
info.entry_number = GUGS32_SEL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to copy out the GDT entry we use.
|
2007-04-18 20:12:05 +00:00
|
|
|
*
|
|
|
|
* XXX: What if a user space program does not check the return value
|
|
|
|
* and tries to use 6, 7 or 8?
|
2007-03-30 00:06:21 +00:00
|
|
|
*/
|
|
|
|
error = copyout(&info, args->desc, sizeof(struct l_user_desc));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (LINUX_LDT_empty(&info)) {
|
|
|
|
a[0] = 0;
|
|
|
|
a[1] = 0;
|
|
|
|
} else {
|
|
|
|
a[0] = LINUX_LDT_entry_a(&info);
|
|
|
|
a[1] = LINUX_LDT_entry_b(&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&sd, &a, sizeof(a));
|
2010-12-22 00:18:42 +00:00
|
|
|
pcb = td->td_pcb;
|
|
|
|
pcb->pcb_gsbase = (register_t)info.base_addr;
|
2013-05-09 21:42:43 +00:00
|
|
|
set_pcb_flags(pcb, PCB_32BIT);
|
2009-04-01 13:09:26 +00:00
|
|
|
update_gdt_gsbase(td, info.base_addr);
|
2007-03-30 00:06:21 +00:00
|
|
|
|
|
|
|
return (0);
|
2004-08-16 07:55:06 +00:00
|
|
|
}
|
2018-08-07 18:29:10 +00:00
|
|
|
|
|
|
|
int futex_xchgl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
|
|
|
|
int futex_xchgl_smap(int oparg, uint32_t *uaddr, int *oldval);
|
2019-05-16 22:20:54 +00:00
|
|
|
DEFINE_IFUNC(, int, futex_xchgl, (int, uint32_t *, int *))
|
2018-08-07 18:29:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
|
|
|
|
futex_xchgl_smap : futex_xchgl_nosmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
int futex_addl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
|
|
|
|
int futex_addl_smap(int oparg, uint32_t *uaddr, int *oldval);
|
2019-05-16 22:20:54 +00:00
|
|
|
DEFINE_IFUNC(, int, futex_addl, (int, uint32_t *, int *))
|
2018-08-07 18:29:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
|
|
|
|
futex_addl_smap : futex_addl_nosmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
int futex_orl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
|
|
|
|
int futex_orl_smap(int oparg, uint32_t *uaddr, int *oldval);
|
2019-05-16 22:20:54 +00:00
|
|
|
DEFINE_IFUNC(, int, futex_orl, (int, uint32_t *, int *))
|
2018-08-07 18:29:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
|
|
|
|
futex_orl_smap : futex_orl_nosmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
int futex_andl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
|
|
|
|
int futex_andl_smap(int oparg, uint32_t *uaddr, int *oldval);
|
2019-05-16 22:20:54 +00:00
|
|
|
DEFINE_IFUNC(, int, futex_andl, (int, uint32_t *, int *))
|
2018-08-07 18:29:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
|
|
|
|
futex_andl_smap : futex_andl_nosmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
int futex_xorl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
|
|
|
|
int futex_xorl_smap(int oparg, uint32_t *uaddr, int *oldval);
|
2019-05-16 22:20:54 +00:00
|
|
|
DEFINE_IFUNC(, int, futex_xorl, (int, uint32_t *, int *))
|
2018-08-07 18:29:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
|
|
|
|
futex_xorl_smap : futex_xorl_nosmap);
|
|
|
|
}
|