1995-06-25 17:32:43 +00:00
|
|
|
/*-
|
2018-02-16 15:00:14 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
2017-11-27 15:13:23 +00:00
|
|
|
*
|
2012-01-15 13:23:18 +00:00
|
|
|
* Copyright (c) 1994-1995 Søren Schmidt
|
1995-06-25 17:32:43 +00:00
|
|
|
* 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
|
2018-02-16 15:00:14 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
1995-06-25 17:32:43 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2018-02-16 15:00:14 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
1995-06-25 17:32:43 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-10 21:29:12 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2006-03-19 11:10:33 +00:00
|
|
|
#include "opt_compat.h"
|
1997-12-16 18:49:23 +00:00
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2014-03-16 10:55:57 +00:00
|
|
|
#include <sys/capsicum.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/dirent.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
1997-12-05 19:55:52 +00:00
|
|
|
#include <sys/lock.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
#include <sys/malloc.h>
|
2020-06-29 03:09:14 +00:00
|
|
|
#include <sys/mman.h>
|
2001-02-16 14:42:11 +00:00
|
|
|
#include <sys/mount.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/mutex.h>
|
2007-03-29 02:11:46 +00:00
|
|
|
#include <sys/namei.h>
|
2021-05-31 19:15:02 +00:00
|
|
|
#include <sys/selinfo.h>
|
|
|
|
#include <sys/pipe.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
2006-09-10 13:47:56 +00:00
|
|
|
#include <sys/stat.h>
|
2007-01-18 09:32:08 +00:00
|
|
|
#include <sys/sx.h>
|
2002-09-01 22:30:27 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/sysproto.h>
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
#include <sys/tty.h>
|
2006-09-23 19:06:54 +00:00
|
|
|
#include <sys/unistd.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/vnode.h>
|
1995-11-22 07:43:53 +00:00
|
|
|
|
2005-01-14 04:44:56 +00:00
|
|
|
#ifdef COMPAT_LINUX32
|
2020-01-21 17:28:22 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_misc.h>
|
2004-08-16 07:28:16 +00:00
|
|
|
#include <machine/../linux32/linux.h>
|
|
|
|
#include <machine/../linux32/linux32_proto.h>
|
2005-01-14 04:44:56 +00:00
|
|
|
#else
|
|
|
|
#include <machine/../linux/linux.h>
|
|
|
|
#include <machine/../linux/linux_proto.h>
|
2004-08-16 07:28:16 +00:00
|
|
|
#endif
|
2013-01-29 18:41:30 +00:00
|
|
|
#include <compat/linux/linux_misc.h>
|
2000-08-22 01:27:36 +00:00
|
|
|
#include <compat/linux/linux_util.h>
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
#include <compat/linux/linux_file.h>
|
1995-06-25 17:32:43 +00:00
|
|
|
|
2020-08-18 22:04:22 +00:00
|
|
|
static int linux_common_open(struct thread *, int, const char *, int, int,
|
|
|
|
enum uio_seg);
|
2021-08-12 08:40:42 +00:00
|
|
|
static int linux_do_accessat(struct thread *t, int, const char *, int, int);
|
2017-02-14 19:13:27 +00:00
|
|
|
static int linux_getdents_error(struct thread *, int, int);
|
|
|
|
|
2020-06-29 03:09:14 +00:00
|
|
|
static struct bsd_to_linux_bitmap seal_bitmap[] = {
|
|
|
|
BITMAP_1t1_LINUX(F_SEAL_SEAL),
|
|
|
|
BITMAP_1t1_LINUX(F_SEAL_SHRINK),
|
|
|
|
BITMAP_1t1_LINUX(F_SEAL_GROW),
|
|
|
|
BITMAP_1t1_LINUX(F_SEAL_WRITE),
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MFD_HUGETLB_ENTRY(_size) \
|
|
|
|
{ \
|
|
|
|
.bsd_value = MFD_HUGE_##_size, \
|
|
|
|
.linux_value = LINUX_HUGETLB_FLAG_ENCODE_##_size \
|
|
|
|
}
|
|
|
|
static struct bsd_to_linux_bitmap mfd_bitmap[] = {
|
|
|
|
BITMAP_1t1_LINUX(MFD_CLOEXEC),
|
|
|
|
BITMAP_1t1_LINUX(MFD_ALLOW_SEALING),
|
|
|
|
BITMAP_1t1_LINUX(MFD_HUGETLB),
|
|
|
|
MFD_HUGETLB_ENTRY(64KB),
|
|
|
|
MFD_HUGETLB_ENTRY(512KB),
|
|
|
|
MFD_HUGETLB_ENTRY(1MB),
|
|
|
|
MFD_HUGETLB_ENTRY(2MB),
|
|
|
|
MFD_HUGETLB_ENTRY(8MB),
|
|
|
|
MFD_HUGETLB_ENTRY(16MB),
|
|
|
|
MFD_HUGETLB_ENTRY(32MB),
|
|
|
|
MFD_HUGETLB_ENTRY(256MB),
|
|
|
|
MFD_HUGETLB_ENTRY(512MB),
|
|
|
|
MFD_HUGETLB_ENTRY(1GB),
|
|
|
|
MFD_HUGETLB_ENTRY(2GB),
|
|
|
|
MFD_HUGETLB_ENTRY(16GB),
|
|
|
|
};
|
|
|
|
#undef MFD_HUGETLB_ENTRY
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
1995-06-25 17:32:43 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_creat(struct thread *td, struct linux_creat_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
{
|
2016-05-22 12:26:03 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
1995-06-25 17:32:43 +00:00
|
|
|
|
2020-08-18 22:04:22 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
2020-10-26 18:02:52 +00:00
|
|
|
return (kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC, args->mode));
|
2020-08-18 22:04:22 +00:00
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2020-10-26 18:02:52 +00:00
|
|
|
error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC, args->mode);
|
|
|
|
LFREEPATH(path);
|
2016-05-22 12:26:03 +00:00
|
|
|
return (error);
|
1995-06-25 17:32:43 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
2007-03-29 02:11:46 +00:00
|
|
|
|
|
|
|
static int
|
2020-11-17 19:51:47 +00:00
|
|
|
linux_common_openflags(int l_flags)
|
1995-06-25 17:32:43 +00:00
|
|
|
{
|
2020-11-17 19:51:47 +00:00
|
|
|
int bsd_flags;
|
2016-05-22 12:26:03 +00:00
|
|
|
|
|
|
|
bsd_flags = 0;
|
|
|
|
switch (l_flags & LINUX_O_ACCMODE) {
|
|
|
|
case LINUX_O_WRONLY:
|
|
|
|
bsd_flags |= O_WRONLY;
|
|
|
|
break;
|
|
|
|
case LINUX_O_RDWR:
|
|
|
|
bsd_flags |= O_RDWR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bsd_flags |= O_RDONLY;
|
|
|
|
}
|
|
|
|
if (l_flags & LINUX_O_NDELAY)
|
|
|
|
bsd_flags |= O_NONBLOCK;
|
|
|
|
if (l_flags & LINUX_O_APPEND)
|
|
|
|
bsd_flags |= O_APPEND;
|
|
|
|
if (l_flags & LINUX_O_SYNC)
|
|
|
|
bsd_flags |= O_FSYNC;
|
2019-11-15 16:21:46 +00:00
|
|
|
if (l_flags & LINUX_O_CLOEXEC)
|
|
|
|
bsd_flags |= O_CLOEXEC;
|
2016-05-22 12:26:03 +00:00
|
|
|
if (l_flags & LINUX_O_NONBLOCK)
|
|
|
|
bsd_flags |= O_NONBLOCK;
|
2020-06-11 14:09:43 +00:00
|
|
|
if (l_flags & LINUX_O_ASYNC)
|
2016-05-22 12:26:03 +00:00
|
|
|
bsd_flags |= O_ASYNC;
|
|
|
|
if (l_flags & LINUX_O_CREAT)
|
|
|
|
bsd_flags |= O_CREAT;
|
|
|
|
if (l_flags & LINUX_O_TRUNC)
|
|
|
|
bsd_flags |= O_TRUNC;
|
|
|
|
if (l_flags & LINUX_O_EXCL)
|
|
|
|
bsd_flags |= O_EXCL;
|
|
|
|
if (l_flags & LINUX_O_NOCTTY)
|
|
|
|
bsd_flags |= O_NOCTTY;
|
|
|
|
if (l_flags & LINUX_O_DIRECT)
|
|
|
|
bsd_flags |= O_DIRECT;
|
|
|
|
if (l_flags & LINUX_O_NOFOLLOW)
|
|
|
|
bsd_flags |= O_NOFOLLOW;
|
|
|
|
if (l_flags & LINUX_O_DIRECTORY)
|
|
|
|
bsd_flags |= O_DIRECTORY;
|
2021-04-15 14:24:51 +00:00
|
|
|
if (l_flags & LINUX_O_PATH)
|
|
|
|
bsd_flags |= O_PATH;
|
2016-05-22 12:26:03 +00:00
|
|
|
/* XXX LINUX_O_NOATIME: unable to be easily implemented. */
|
2020-11-17 19:51:47 +00:00
|
|
|
return (bsd_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
linux_common_open(struct thread *td, int dirfd, const char *path, int l_flags,
|
|
|
|
int mode, enum uio_seg seg)
|
|
|
|
{
|
|
|
|
struct proc *p = td->td_proc;
|
|
|
|
struct file *fp;
|
|
|
|
int fd;
|
|
|
|
int bsd_flags, error;
|
2016-05-22 12:26:03 +00:00
|
|
|
|
2020-11-17 19:51:47 +00:00
|
|
|
bsd_flags = linux_common_openflags(l_flags);
|
2020-08-18 22:04:22 +00:00
|
|
|
error = kern_openat(td, dirfd, path, seg, bsd_flags, mode);
|
2019-11-18 10:19:16 +00:00
|
|
|
if (error != 0) {
|
|
|
|
if (error == EMLINK)
|
|
|
|
error = ELOOP;
|
2016-05-22 12:26:03 +00:00
|
|
|
goto done;
|
2019-11-18 10:19:16 +00:00
|
|
|
}
|
2019-11-20 12:06:29 +00:00
|
|
|
if (p->p_flag & P_CONTROLT)
|
|
|
|
goto done;
|
2016-05-22 12:26:03 +00:00
|
|
|
if (bsd_flags & O_NOCTTY)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
2017-10-27 16:36:05 +00:00
|
|
|
* XXX In between kern_openat() and fget(), another process
|
2016-05-22 12:26:03 +00:00
|
|
|
* having the same filedesc could use that fd without
|
|
|
|
* checking below.
|
|
|
|
*/
|
|
|
|
fd = td->td_retval[0];
|
2018-05-09 18:47:24 +00:00
|
|
|
if (fget(td, fd, &cap_ioctl_rights, &fp) == 0) {
|
2016-05-22 12:26:03 +00:00
|
|
|
if (fp->f_type != DTYPE_VNODE) {
|
|
|
|
fdrop(fp, td);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
sx_slock(&proctree_lock);
|
|
|
|
PROC_LOCK(p);
|
|
|
|
if (SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
sx_sunlock(&proctree_lock);
|
|
|
|
/* XXXPJD: Verify if TIOCSCTTY is allowed. */
|
|
|
|
(void) fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0,
|
|
|
|
td->td_ucred, td);
|
|
|
|
} else {
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
sx_sunlock(&proctree_lock);
|
|
|
|
}
|
|
|
|
fdrop(fp, td);
|
|
|
|
}
|
2007-01-18 09:32:08 +00:00
|
|
|
|
2015-04-19 07:12:16 +00:00
|
|
|
done:
|
2016-05-22 12:26:03 +00:00
|
|
|
return (error);
|
2007-03-29 02:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_openat(struct thread *td, struct linux_openat_args *args)
|
|
|
|
{
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
char *path;
|
2020-08-18 22:04:22 +00:00
|
|
|
int dfd, error;
|
2007-03-29 02:11:46 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
2020-08-18 22:04:22 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (linux_common_open(td, dfd, args->filename, args->flags,
|
|
|
|
args->mode, UIO_USERSPACE));
|
|
|
|
}
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
if (args->flags & LINUX_O_CREAT)
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATH_AT(args->filename, &path, 1, dfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
else
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATH_AT(args->filename, &path, 0, dfd);
|
2019-05-13 18:24:29 +00:00
|
|
|
|
2020-08-18 22:04:22 +00:00
|
|
|
error = linux_common_open(td, dfd, path, args->flags, args->mode,
|
|
|
|
UIO_SYSSPACE);
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
2007-03-29 02:11:46 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
2007-03-29 02:11:46 +00:00
|
|
|
int
|
|
|
|
linux_open(struct thread *td, struct linux_open_args *args)
|
|
|
|
{
|
2016-05-22 12:26:03 +00:00
|
|
|
char *path;
|
2020-08-18 22:04:22 +00:00
|
|
|
int error;
|
2007-03-29 02:11:46 +00:00
|
|
|
|
2020-08-18 22:04:22 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (linux_common_open(td, AT_FDCWD, args->path, args->flags,
|
|
|
|
args->mode, UIO_USERSPACE));
|
|
|
|
}
|
2016-05-22 12:26:03 +00:00
|
|
|
if (args->flags & LINUX_O_CREAT)
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHCREAT(args->path, &path);
|
2016-05-22 12:26:03 +00:00
|
|
|
else
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2019-05-13 18:24:29 +00:00
|
|
|
|
2020-08-18 22:04:22 +00:00
|
|
|
error = linux_common_open(td, AT_FDCWD, path, args->flags, args->mode,
|
|
|
|
UIO_SYSSPACE);
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
2007-03-29 02:11:46 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
2007-03-29 02:11:46 +00:00
|
|
|
|
2020-11-17 19:51:47 +00:00
|
|
|
int
|
|
|
|
linux_name_to_handle_at(struct thread *td,
|
|
|
|
struct linux_name_to_handle_at_args *args)
|
|
|
|
{
|
|
|
|
static const l_int valid_flags = (LINUX_AT_SYMLINK_FOLLOW |
|
|
|
|
LINUX_AT_EMPTY_PATH);
|
|
|
|
static const l_uint fh_size = sizeof(fhandle_t);
|
|
|
|
|
|
|
|
fhandle_t fh;
|
|
|
|
l_uint fh_bytes;
|
|
|
|
l_int mount_id;
|
|
|
|
int error, fd, bsd_flags;
|
|
|
|
|
|
|
|
if (args->flags & ~valid_flags)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
fd = args->dirfd;
|
|
|
|
if (fd == LINUX_AT_FDCWD)
|
|
|
|
fd = AT_FDCWD;
|
|
|
|
|
|
|
|
bsd_flags = 0;
|
|
|
|
if (!(args->flags & LINUX_AT_SYMLINK_FOLLOW))
|
|
|
|
bsd_flags |= AT_SYMLINK_NOFOLLOW;
|
2021-11-17 23:51:18 +00:00
|
|
|
if ((args->flags & LINUX_AT_EMPTY_PATH) != 0)
|
|
|
|
bsd_flags |= AT_EMPTY_PATH;
|
2020-11-17 19:51:47 +00:00
|
|
|
|
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
error = kern_getfhat(td, bsd_flags, fd, args->name,
|
|
|
|
UIO_USERSPACE, &fh, UIO_SYSSPACE);
|
|
|
|
} else {
|
|
|
|
char *path;
|
|
|
|
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATH_AT(args->name, &path, 0, fd);
|
2020-11-17 19:51:47 +00:00
|
|
|
error = kern_getfhat(td, bsd_flags, fd, path, UIO_SYSSPACE,
|
|
|
|
&fh, UIO_SYSSPACE);
|
|
|
|
LFREEPATH(path);
|
|
|
|
}
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* Emit mount_id -- required before EOVERFLOW case. */
|
|
|
|
mount_id = (fh.fh_fsid.val[0] ^ fh.fh_fsid.val[1]);
|
|
|
|
error = copyout(&mount_id, args->mnt_id, sizeof(mount_id));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* Check if there is room for handle. */
|
|
|
|
error = copyin(&args->handle->handle_bytes, &fh_bytes,
|
|
|
|
sizeof(fh_bytes));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (fh_bytes < fh_size) {
|
|
|
|
error = copyout(&fh_size, &args->handle->handle_bytes,
|
|
|
|
sizeof(fh_size));
|
|
|
|
if (error == 0)
|
|
|
|
error = EOVERFLOW;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit handle. */
|
|
|
|
mount_id = 0;
|
|
|
|
/*
|
|
|
|
* We don't use handle_type for anything yet, but initialize a known
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
error = copyout(&mount_id, &args->handle->handle_type,
|
|
|
|
sizeof(mount_id));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = copyout(&fh, &args->handle->f_handle,
|
|
|
|
sizeof(fh));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_open_by_handle_at(struct thread *td,
|
|
|
|
struct linux_open_by_handle_at_args *args)
|
|
|
|
{
|
|
|
|
l_uint fh_bytes;
|
|
|
|
int bsd_flags, error;
|
|
|
|
|
|
|
|
error = copyin(&args->handle->handle_bytes, &fh_bytes,
|
|
|
|
sizeof(fh_bytes));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (fh_bytes < sizeof(fhandle_t))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
bsd_flags = linux_common_openflags(args->flags);
|
|
|
|
return (kern_fhopen(td, (void *)&args->handle->f_handle, bsd_flags));
|
|
|
|
}
|
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_lseek(struct thread *td, struct linux_lseek_args *args)
|
1995-06-25 17:32:43 +00:00
|
|
|
{
|
|
|
|
|
2017-01-30 12:24:47 +00:00
|
|
|
return (kern_lseek(td, args->fdes, args->off, args->whence));
|
1995-06-25 17:32:43 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 15:43:53 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_llseek(struct thread *td, struct linux_llseek_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
off_t off;
|
|
|
|
|
|
|
|
off = (args->olow) | (((off_t) args->ohigh) << 32);
|
|
|
|
|
2017-01-30 12:24:47 +00:00
|
|
|
error = kern_lseek(td, args->fd, off, args->whence);
|
|
|
|
if (error != 0)
|
2016-05-22 12:26:03 +00:00
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2017-01-30 12:24:47 +00:00
|
|
|
error = copyout(td->td_retval, args->res, sizeof(off_t));
|
|
|
|
if (error != 0)
|
2016-05-22 12:26:03 +00:00
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] = 0;
|
2016-05-22 12:26:03 +00:00
|
|
|
return (0);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2015-05-24 15:43:53 +00:00
|
|
|
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2001-09-08 19:07:04 +00:00
|
|
|
/*
|
|
|
|
* Note that linux_getdents(2) and linux_getdents64(2) have the same
|
|
|
|
* arguments. They only differ in the definition of struct dirent they
|
2017-02-14 19:13:27 +00:00
|
|
|
* operate on.
|
|
|
|
* Note that linux_readdir(2) is a special case of linux_getdents(2)
|
|
|
|
* where count is always equals 1, meaning that the buffer is one
|
|
|
|
* dirent-structure in size and that the code can't handle more anyway.
|
|
|
|
* Note that linux_readdir(2) can't be implemented by means of linux_getdents(2)
|
|
|
|
* as in case when the *dent buffer size is equal to 1 linux_getdents(2) will
|
|
|
|
* trash user stack.
|
2001-09-08 19:07:04 +00:00
|
|
|
*/
|
1995-06-25 17:32:43 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
static int
|
|
|
|
linux_getdents_error(struct thread *td, int fd, int err)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct file *fp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Linux return ENOTDIR in case when fd is not a directory. */
|
2018-05-09 18:47:24 +00:00
|
|
|
error = getvnode(td, fd, &cap_read_rights, &fp);
|
2017-02-14 19:13:27 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
vp = fp->f_vnode;
|
|
|
|
if (vp->v_type != VDIR) {
|
|
|
|
fdrop(fp, td);
|
|
|
|
return (ENOTDIR);
|
|
|
|
}
|
|
|
|
fdrop(fp, td);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2001-09-08 19:07:04 +00:00
|
|
|
struct l_dirent {
|
2008-06-08 11:09:25 +00:00
|
|
|
l_ulong d_ino;
|
2001-09-08 19:07:04 +00:00
|
|
|
l_off_t d_off;
|
|
|
|
l_ushort d_reclen;
|
|
|
|
char d_name[LINUX_NAME_MAX + 1];
|
|
|
|
};
|
1995-06-25 17:32:43 +00:00
|
|
|
|
2001-09-08 19:07:04 +00:00
|
|
|
struct l_dirent64 {
|
|
|
|
uint64_t d_ino;
|
|
|
|
int64_t d_off;
|
|
|
|
l_ushort d_reclen;
|
|
|
|
u_char d_type;
|
|
|
|
char d_name[LINUX_NAME_MAX + 1];
|
|
|
|
};
|
1995-06-25 17:32:43 +00:00
|
|
|
|
2008-09-09 16:00:17 +00:00
|
|
|
/*
|
|
|
|
* Linux uses the last byte in the dirent buffer to store d_type,
|
|
|
|
* at least glibc-2.7 requires it. That is why l_dirent is padded with 2 bytes.
|
|
|
|
*/
|
|
|
|
#define LINUX_RECLEN(namlen) \
|
2016-04-22 16:57:42 +00:00
|
|
|
roundup(offsetof(struct l_dirent, d_name) + (namlen) + 2, sizeof(l_ulong))
|
2008-09-09 16:00:17 +00:00
|
|
|
|
|
|
|
#define LINUX_RECLEN64(namlen) \
|
2016-04-22 16:57:42 +00:00
|
|
|
roundup(offsetof(struct l_dirent64, d_name) + (namlen) + 1, \
|
2008-09-09 16:00:17 +00:00
|
|
|
sizeof(uint64_t))
|
1995-06-25 17:32:43 +00:00
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
2017-02-14 19:13:27 +00:00
|
|
|
int
|
|
|
|
linux_getdents(struct thread *td, struct linux_getdents_args *args)
|
2001-09-08 19:07:04 +00:00
|
|
|
{
|
2003-03-03 09:17:12 +00:00
|
|
|
struct dirent *bdp;
|
2001-09-08 19:07:04 +00:00
|
|
|
caddr_t inp, buf; /* BSD-format */
|
|
|
|
int len, reclen; /* BSD-format */
|
|
|
|
caddr_t outp; /* Linux-format */
|
2017-02-14 19:13:27 +00:00
|
|
|
int resid, linuxreclen; /* Linux-format */
|
2008-09-09 16:00:17 +00:00
|
|
|
caddr_t lbuf; /* Linux-format */
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
off_t base;
|
2008-09-09 16:00:17 +00:00
|
|
|
struct l_dirent *linux_dirent;
|
2017-02-14 19:13:27 +00:00
|
|
|
int buflen, error;
|
|
|
|
size_t retval;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-06-12 07:35:59 +00:00
|
|
|
buflen = min(args->count, MAXBSIZE);
|
2017-02-14 19:13:27 +00:00
|
|
|
buf = malloc(buflen, M_TEMP, M_WAITOK);
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
error = kern_getdirentries(td, args->fd, buf, buflen,
|
|
|
|
&base, NULL, UIO_SYSSPACE);
|
|
|
|
if (error != 0) {
|
|
|
|
error = linux_getdents_error(td, args->fd, error);
|
|
|
|
goto out1;
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
lbuf = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
len = td->td_retval[0];
|
2001-09-08 19:07:04 +00:00
|
|
|
inp = buf;
|
2017-02-14 19:13:27 +00:00
|
|
|
outp = (caddr_t)args->dent;
|
|
|
|
resid = args->count;
|
|
|
|
retval = 0;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
bdp = (struct dirent *) inp;
|
|
|
|
reclen = bdp->d_reclen;
|
2017-02-14 19:13:27 +00:00
|
|
|
linuxreclen = LINUX_RECLEN(bdp->d_namlen);
|
|
|
|
/*
|
|
|
|
* No more space in the user supplied dirent buffer.
|
|
|
|
* Return EINVAL.
|
|
|
|
*/
|
|
|
|
if (resid < linuxreclen) {
|
|
|
|
error = EINVAL;
|
2001-09-08 19:07:04 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
linux_dirent = (struct l_dirent*)lbuf;
|
|
|
|
linux_dirent->d_ino = bdp->d_fileno;
|
2022-03-31 17:50:09 +00:00
|
|
|
linux_dirent->d_off = bdp->d_off;
|
2017-02-14 19:13:27 +00:00
|
|
|
linux_dirent->d_reclen = linuxreclen;
|
|
|
|
/*
|
|
|
|
* Copy d_type to last byte of l_dirent buffer
|
|
|
|
*/
|
|
|
|
lbuf[linuxreclen - 1] = bdp->d_type;
|
|
|
|
strlcpy(linux_dirent->d_name, bdp->d_name,
|
|
|
|
linuxreclen - offsetof(struct l_dirent, d_name)-1);
|
|
|
|
error = copyout(linux_dirent, outp, linuxreclen);
|
|
|
|
if (error != 0)
|
2001-09-08 19:07:04 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
inp += reclen;
|
2017-02-14 19:13:27 +00:00
|
|
|
base += reclen;
|
|
|
|
len -= reclen;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
retval += linuxreclen;
|
2001-09-08 19:07:04 +00:00
|
|
|
outp += linuxreclen;
|
|
|
|
resid -= linuxreclen;
|
2011-01-19 12:19:25 +00:00
|
|
|
}
|
2017-02-14 19:13:27 +00:00
|
|
|
td->td_retval[0] = retval;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
1995-06-25 17:32:43 +00:00
|
|
|
out:
|
2017-06-26 09:13:25 +00:00
|
|
|
free(lbuf, M_TEMP);
|
2017-02-14 19:13:27 +00:00
|
|
|
out1:
|
2017-06-26 09:13:25 +00:00
|
|
|
free(buf, M_TEMP);
|
2001-09-08 19:07:04 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
int
|
2017-02-14 19:13:27 +00:00
|
|
|
linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
|
2001-09-08 19:07:04 +00:00
|
|
|
{
|
2017-02-14 19:13:27 +00:00
|
|
|
struct dirent *bdp;
|
|
|
|
caddr_t inp, buf; /* BSD-format */
|
|
|
|
int len, reclen; /* BSD-format */
|
|
|
|
caddr_t outp; /* Linux-format */
|
|
|
|
int resid, linuxreclen; /* Linux-format */
|
|
|
|
caddr_t lbuf; /* Linux-format */
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
off_t base;
|
2017-02-14 19:13:27 +00:00
|
|
|
struct l_dirent64 *linux_dirent64;
|
|
|
|
int buflen, error;
|
|
|
|
size_t retval;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-06-12 07:35:59 +00:00
|
|
|
buflen = min(args->count, MAXBSIZE);
|
2017-02-14 19:13:27 +00:00
|
|
|
buf = malloc(buflen, M_TEMP, M_WAITOK);
|
|
|
|
|
|
|
|
error = kern_getdirentries(td, args->fd, buf, buflen,
|
|
|
|
&base, NULL, UIO_SYSSPACE);
|
|
|
|
if (error != 0) {
|
|
|
|
error = linux_getdents_error(td, args->fd, error);
|
|
|
|
goto out1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lbuf = malloc(LINUX_RECLEN64(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
len = td->td_retval[0];
|
|
|
|
inp = buf;
|
|
|
|
outp = (caddr_t)args->dirent;
|
|
|
|
resid = args->count;
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
bdp = (struct dirent *) inp;
|
|
|
|
reclen = bdp->d_reclen;
|
|
|
|
linuxreclen = LINUX_RECLEN64(bdp->d_namlen);
|
|
|
|
/*
|
|
|
|
* No more space in the user supplied dirent buffer.
|
|
|
|
* Return EINVAL.
|
|
|
|
*/
|
|
|
|
if (resid < linuxreclen) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
linux_dirent64 = (struct l_dirent64*)lbuf;
|
|
|
|
linux_dirent64->d_ino = bdp->d_fileno;
|
2022-03-31 17:50:09 +00:00
|
|
|
linux_dirent64->d_off = bdp->d_off;
|
2017-02-14 19:13:27 +00:00
|
|
|
linux_dirent64->d_reclen = linuxreclen;
|
|
|
|
linux_dirent64->d_type = bdp->d_type;
|
|
|
|
strlcpy(linux_dirent64->d_name, bdp->d_name,
|
|
|
|
linuxreclen - offsetof(struct l_dirent64, d_name));
|
|
|
|
error = copyout(linux_dirent64, outp, linuxreclen);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
inp += reclen;
|
|
|
|
base += reclen;
|
|
|
|
len -= reclen;
|
|
|
|
|
|
|
|
retval += linuxreclen;
|
|
|
|
outp += linuxreclen;
|
|
|
|
resid -= linuxreclen;
|
|
|
|
}
|
|
|
|
td->td_retval[0] = retval;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
out:
|
|
|
|
free(lbuf, M_TEMP);
|
|
|
|
out1:
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return (error);
|
2001-09-08 19:07:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
2001-09-08 19:07:04 +00:00
|
|
|
int
|
2017-02-14 19:13:27 +00:00
|
|
|
linux_readdir(struct thread *td, struct linux_readdir_args *args)
|
2001-09-08 19:07:04 +00:00
|
|
|
{
|
2017-02-14 19:13:27 +00:00
|
|
|
struct dirent *bdp;
|
|
|
|
caddr_t buf; /* BSD-format */
|
|
|
|
int linuxreclen; /* Linux-format */
|
|
|
|
caddr_t lbuf; /* Linux-format */
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
off_t base;
|
2017-02-14 19:13:27 +00:00
|
|
|
struct l_dirent *linux_dirent;
|
|
|
|
int buflen, error;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
buflen = LINUX_RECLEN(LINUX_NAME_MAX);
|
|
|
|
buf = malloc(buflen, M_TEMP, M_WAITOK);
|
|
|
|
|
|
|
|
error = kern_getdirentries(td, args->fd, buf, buflen,
|
|
|
|
&base, NULL, UIO_SYSSPACE);
|
|
|
|
if (error != 0) {
|
|
|
|
error = linux_getdents_error(td, args->fd, error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (td->td_retval[0] == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
lbuf = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2017-02-14 19:13:27 +00:00
|
|
|
bdp = (struct dirent *) buf;
|
|
|
|
linuxreclen = LINUX_RECLEN(bdp->d_namlen);
|
|
|
|
|
|
|
|
linux_dirent = (struct l_dirent*)lbuf;
|
|
|
|
linux_dirent->d_ino = bdp->d_fileno;
|
2022-03-31 17:50:09 +00:00
|
|
|
linux_dirent->d_off = bdp->d_off;
|
2017-02-14 19:13:27 +00:00
|
|
|
linux_dirent->d_reclen = bdp->d_namlen;
|
|
|
|
strlcpy(linux_dirent->d_name, bdp->d_name,
|
|
|
|
linuxreclen - offsetof(struct l_dirent, d_name));
|
|
|
|
error = copyout(linux_dirent, args->dent, linuxreclen);
|
|
|
|
if (error == 0)
|
|
|
|
td->td_retval[0] = linuxreclen;
|
|
|
|
|
2017-06-26 09:13:25 +00:00
|
|
|
free(lbuf, M_TEMP);
|
2017-02-14 19:13:27 +00:00
|
|
|
out:
|
2017-06-26 09:13:25 +00:00
|
|
|
free(buf, M_TEMP);
|
2017-02-14 19:13:27 +00:00
|
|
|
return (error);
|
1995-06-25 17:32:43 +00:00
|
|
|
}
|
2017-02-14 19:13:27 +00:00
|
|
|
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|
|
|
|
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
/*
|
|
|
|
* These exist mainly for hooks for doing /compat/linux translation.
|
|
|
|
*/
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_access(struct thread *td, struct linux_access_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2018-02-22 02:24:17 +00:00
|
|
|
/* Linux convention. */
|
2011-11-19 06:35:15 +00:00
|
|
|
if (args->amode & ~(F_OK | X_OK | W_OK | R_OK))
|
2006-09-23 19:06:54 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
2020-08-18 22:04:22 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
error = kern_accessat(td, AT_FDCWD, args->path, UIO_USERSPACE, 0,
|
|
|
|
args->amode);
|
|
|
|
} else {
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2020-08-18 22:04:22 +00:00
|
|
|
error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
|
|
|
|
args->amode);
|
|
|
|
LFREEPATH(path);
|
|
|
|
}
|
2006-09-23 19:06:54 +00:00
|
|
|
|
2002-09-01 22:30:27 +00:00
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2021-08-12 08:40:42 +00:00
|
|
|
static int
|
|
|
|
linux_do_accessat(struct thread *td, int ldfd, const char *filename,
|
|
|
|
int amode, int flags)
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
{
|
|
|
|
char *path;
|
2015-05-24 16:18:03 +00:00
|
|
|
int error, dfd;
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
|
2018-02-22 02:24:17 +00:00
|
|
|
/* Linux convention. */
|
2021-08-12 08:40:42 +00:00
|
|
|
if (amode & ~(F_OK | X_OK | W_OK | R_OK))
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
2021-08-12 08:40:42 +00:00
|
|
|
dfd = (ldfd == LINUX_AT_FDCWD) ? AT_FDCWD : ldfd;
|
2020-08-18 22:04:22 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
2021-08-12 08:40:42 +00:00
|
|
|
error = kern_accessat(td, dfd, filename, UIO_USERSPACE, flags, amode);
|
2020-08-18 22:04:22 +00:00
|
|
|
} else {
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST_AT(filename, &path, dfd);
|
2021-08-12 08:40:42 +00:00
|
|
|
error = kern_accessat(td, dfd, path, UIO_SYSSPACE, flags, amode);
|
2020-08-18 22:04:22 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
}
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2021-08-12 08:40:42 +00:00
|
|
|
int
|
|
|
|
linux_faccessat(struct thread *td, struct linux_faccessat_args *args)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (linux_do_accessat(td, args->dfd, args->filename, args->amode,
|
|
|
|
0));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_faccessat2(struct thread *td, struct linux_faccessat2_args *args)
|
|
|
|
{
|
|
|
|
int flags, unsupported;
|
|
|
|
|
|
|
|
/* XXX. AT_SYMLINK_NOFOLLOW is not supported by kern_accessat */
|
|
|
|
unsupported = args->flags & ~(LINUX_AT_EACCESS | LINUX_AT_EMPTY_PATH);
|
|
|
|
if (unsupported != 0) {
|
|
|
|
linux_msg(td, "faccessat2 unsupported flag 0x%x", unsupported);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = (args->flags & LINUX_AT_EACCESS) == 0 ? 0 :
|
|
|
|
AT_EACCESS;
|
|
|
|
flags |= (args->flags & LINUX_AT_EMPTY_PATH) == 0 ? 0 :
|
|
|
|
AT_EMPTY_PATH;
|
|
|
|
return (linux_do_accessat(td, args->dfd, args->filename, args->amode,
|
|
|
|
flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_unlink(struct thread *td, struct linux_unlink_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
2006-09-10 13:47:56 +00:00
|
|
|
struct stat st;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-08-18 22:04:22 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
error = kern_funlinkat(td, AT_FDCWD, args->path, FD_NONE,
|
|
|
|
UIO_USERSPACE, 0, 0);
|
|
|
|
if (error == EPERM) {
|
|
|
|
/* Introduce POSIX noncompliant behaviour of Linux */
|
|
|
|
if (kern_statat(td, 0, AT_FDCWD, args->path,
|
2022-05-23 10:18:07 +00:00
|
|
|
UIO_USERSPACE, &st, NULL) == 0) {
|
2020-08-18 22:04:22 +00:00
|
|
|
if (S_ISDIR(st.st_mode))
|
|
|
|
error = EISDIR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2020-08-18 22:04:22 +00:00
|
|
|
error = kern_funlinkat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0, 0);
|
|
|
|
if (error == EPERM) {
|
|
|
|
/* Introduce POSIX noncompliant behaviour of Linux */
|
|
|
|
if (kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st,
|
|
|
|
NULL) == 0) {
|
|
|
|
if (S_ISDIR(st.st_mode))
|
|
|
|
error = EISDIR;
|
|
|
|
}
|
2014-11-13 18:01:51 +00:00
|
|
|
}
|
2020-08-18 22:04:22 +00:00
|
|
|
LFREEPATH(path);
|
2014-11-13 18:01:51 +00:00
|
|
|
}
|
2020-08-18 22:04:22 +00:00
|
|
|
|
2002-09-01 22:30:27 +00:00
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
static int
|
|
|
|
linux_unlinkat_impl(struct thread *td, enum uio_seg pathseg, const char *path,
|
|
|
|
int dfd, struct linux_unlinkat_args *args)
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
2020-10-26 18:02:52 +00:00
|
|
|
int error;
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
|
|
|
|
if (args->flag & LINUX_AT_REMOVEDIR)
|
2020-10-26 18:02:52 +00:00
|
|
|
error = kern_frmdirat(td, dfd, path, FD_NONE, pathseg, 0);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
else
|
2020-10-26 18:02:52 +00:00
|
|
|
error = kern_funlinkat(td, dfd, path, FD_NONE, pathseg, 0, 0);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
if (error == EPERM && !(args->flag & LINUX_AT_REMOVEDIR)) {
|
|
|
|
/* Introduce POSIX noncompliant behaviour of Linux */
|
|
|
|
if (kern_statat(td, AT_SYMLINK_NOFOLLOW, dfd, path,
|
2022-05-23 10:19:34 +00:00
|
|
|
pathseg, &st, NULL) == 0 && S_ISDIR(st.st_mode))
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
error = EISDIR;
|
|
|
|
}
|
2020-10-26 18:02:52 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_unlinkat(struct thread *td, struct linux_unlinkat_args *args)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
int error, dfd;
|
|
|
|
|
|
|
|
if (args->flag & ~LINUX_AT_REMOVEDIR)
|
|
|
|
return (EINVAL);
|
|
|
|
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (linux_unlinkat_impl(td, UIO_USERSPACE, args->pathname,
|
|
|
|
dfd, args));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST_AT(args->pathname, &path, dfd);
|
2020-10-26 18:02:52 +00:00
|
|
|
error = linux_unlinkat_impl(td, UIO_SYSSPACE, path, dfd, args);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_chdir(struct thread *td, struct linux_chdir_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_chdir(td, args->path, UIO_USERSPACE));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2002-09-01 22:30:27 +00:00
|
|
|
error = kern_chdir(td, path, UIO_SYSSPACE);
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_chmod(struct thread *td, struct linux_chmod_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_fchmodat(td, AT_FDCWD, args->path, UIO_USERSPACE,
|
|
|
|
args->mode, 0));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2020-10-26 18:02:52 +00:00
|
|
|
error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode, 0);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
int
|
|
|
|
linux_fchmodat(struct thread *td, struct linux_fchmodat_args *args)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
int error, dfd;
|
|
|
|
|
|
|
|
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_fchmodat(td, dfd, args->filename, UIO_USERSPACE,
|
|
|
|
args->mode, 0));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST_AT(args->filename, &path, dfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
error = kern_fchmodat(td, dfd, path, UIO_SYSSPACE, args->mode, 0);
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_mkdir(struct thread *td, struct linux_mkdir_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_mkdirat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->mode));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHCREAT(args->path, &path);
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
int
|
|
|
|
linux_mkdirat(struct thread *td, struct linux_mkdirat_args *args)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
int error, dfd;
|
|
|
|
|
|
|
|
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_mkdirat(td, dfd, args->pathname, UIO_USERSPACE, args->mode));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHCREAT_AT(args->pathname, &path, dfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
error = kern_mkdirat(td, dfd, path, UIO_SYSSPACE, args->mode);
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_rmdir(struct thread *td, struct linux_rmdir_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_frmdirat(td, AT_FDCWD, args->path, FD_NONE,
|
|
|
|
UIO_USERSPACE, 0));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2019-04-06 09:34:26 +00:00
|
|
|
error = kern_frmdirat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_rename(struct thread *td, struct linux_rename_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *from, *to;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_renameat(td, AT_FDCWD, args->from, AT_FDCWD,
|
|
|
|
args->to, UIO_USERSPACE));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->from, &from);
|
2002-09-01 22:30:27 +00:00
|
|
|
/* Expand LCONVPATHCREATE so that `from' can be freed on errors */
|
2021-11-25 21:42:13 +00:00
|
|
|
error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
|
2002-09-01 22:30:27 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
LFREEPATH(from);
|
|
|
|
return (error);
|
|
|
|
}
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(from);
|
|
|
|
LFREEPATH(to);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
int
|
|
|
|
linux_renameat(struct thread *td, struct linux_renameat_args *args)
|
2019-09-11 13:01:59 +00:00
|
|
|
{
|
|
|
|
struct linux_renameat2_args renameat2_args = {
|
|
|
|
.olddfd = args->olddfd,
|
|
|
|
.oldname = args->oldname,
|
|
|
|
.newdfd = args->newdfd,
|
|
|
|
.newname = args->newname,
|
|
|
|
.flags = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
return (linux_renameat2(td, &renameat2_args));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_renameat2(struct thread *td, struct linux_renameat2_args *args)
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
{
|
|
|
|
char *from, *to;
|
|
|
|
int error, olddfd, newdfd;
|
|
|
|
|
2019-09-11 13:01:59 +00:00
|
|
|
if (args->flags != 0) {
|
2019-11-07 15:51:44 +00:00
|
|
|
if (args->flags & ~(LINUX_RENAME_EXCHANGE |
|
|
|
|
LINUX_RENAME_NOREPLACE | LINUX_RENAME_WHITEOUT))
|
|
|
|
return (EINVAL);
|
|
|
|
if (args->flags & LINUX_RENAME_EXCHANGE &&
|
|
|
|
args->flags & (LINUX_RENAME_NOREPLACE |
|
|
|
|
LINUX_RENAME_WHITEOUT))
|
|
|
|
return (EINVAL);
|
2020-10-26 18:03:50 +00:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* This spams the console on Ubuntu Focal.
|
|
|
|
*
|
|
|
|
* What's needed here is a general mechanism to let users know
|
|
|
|
* about missing features without hogging the system.
|
|
|
|
*/
|
2019-09-30 19:05:14 +00:00
|
|
|
linux_msg(td, "renameat2 unsupported flags 0x%x",
|
2019-09-11 13:01:59 +00:00
|
|
|
args->flags);
|
2020-10-26 18:03:50 +00:00
|
|
|
#endif
|
2019-09-11 13:01:59 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
|
|
|
|
newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_renameat(td, olddfd, args->oldname, newdfd,
|
|
|
|
args->newname, UIO_USERSPACE));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST_AT(args->oldname, &from, olddfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
/* Expand LCONVPATHCREATE so that `from' can be freed on errors */
|
2021-11-25 21:42:13 +00:00
|
|
|
error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, newdfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
LFREEPATH(from);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = kern_renameat(td, olddfd, from, newdfd, to, UIO_SYSSPACE);
|
|
|
|
LFREEPATH(from);
|
|
|
|
LFREEPATH(to);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_symlink(struct thread *td, struct linux_symlink_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path, *to;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_symlinkat(td, args->path, AT_FDCWD, args->to,
|
|
|
|
UIO_USERSPACE));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2002-09-01 22:30:27 +00:00
|
|
|
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
|
2021-11-25 21:42:13 +00:00
|
|
|
error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
|
2002-09-01 22:30:27 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_symlinkat(td, path, AT_FDCWD, to, UIO_SYSSPACE);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
LFREEPATH(to);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
int
|
|
|
|
linux_symlinkat(struct thread *td, struct linux_symlinkat_args *args)
|
|
|
|
{
|
|
|
|
char *path, *to;
|
|
|
|
int error, dfd;
|
|
|
|
|
|
|
|
dfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_symlinkat(td, args->oldname, dfd, args->newname,
|
|
|
|
UIO_USERSPACE));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->oldname, &path);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
|
2021-11-25 21:42:13 +00:00
|
|
|
error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, dfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = kern_symlinkat(td, path, dfd, to, UIO_SYSSPACE);
|
|
|
|
LFREEPATH(path);
|
|
|
|
LFREEPATH(to);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_readlink(struct thread *td, struct linux_readlink_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *name;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2022-03-31 18:21:41 +00:00
|
|
|
if (args->count <= 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_readlinkat(td, AT_FDCWD, args->name, UIO_USERSPACE,
|
|
|
|
args->buf, UIO_USERSPACE, args->count));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->name, &name);
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_readlinkat(td, AT_FDCWD, name, UIO_SYSSPACE,
|
|
|
|
args->buf, UIO_USERSPACE, args->count);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(name);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
int
|
|
|
|
linux_readlinkat(struct thread *td, struct linux_readlinkat_args *args)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int error, dfd;
|
|
|
|
|
2022-03-31 18:21:41 +00:00
|
|
|
if (args->bufsiz <= 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_readlinkat(td, dfd, args->path, UIO_USERSPACE,
|
|
|
|
args->buf, UIO_USERSPACE, args->bufsiz));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST_AT(args->path, &name, dfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
error = kern_readlinkat(td, dfd, name, UIO_SYSSPACE, args->buf,
|
|
|
|
UIO_USERSPACE, args->bufsiz);
|
|
|
|
LFREEPATH(name);
|
|
|
|
return (error);
|
|
|
|
}
|
2008-04-23 15:56:33 +00:00
|
|
|
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_truncate(struct thread *td, struct linux_truncate_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_truncate(td, args->path, UIO_USERSPACE, args->length));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2002-09-01 22:30:27 +00:00
|
|
|
error = kern_truncate(td, path, UIO_SYSSPACE, args->length);
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 19:38:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 15:43:53 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
2008-04-23 15:56:33 +00:00
|
|
|
int
|
|
|
|
linux_truncate64(struct thread *td, struct linux_truncate64_args *args)
|
|
|
|
{
|
|
|
|
char *path;
|
2020-01-21 17:28:22 +00:00
|
|
|
off_t length;
|
2008-04-23 15:56:33 +00:00
|
|
|
int error;
|
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
length = PAIR32TO64(off_t, args->length);
|
|
|
|
#else
|
|
|
|
length = args->length;
|
|
|
|
#endif
|
2008-04-23 15:56:33 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_truncate(td, args->path, UIO_USERSPACE, length));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2020-01-21 17:28:22 +00:00
|
|
|
error = kern_truncate(td, path, UIO_SYSSPACE, length);
|
2008-04-23 15:56:33 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
2015-05-24 15:43:53 +00:00
|
|
|
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|
|
|
|
|
2006-03-18 18:20:17 +00:00
|
|
|
int
|
|
|
|
linux_ftruncate(struct thread *td, struct linux_ftruncate_args *args)
|
|
|
|
{
|
2016-05-22 12:26:03 +00:00
|
|
|
|
2017-01-30 11:50:54 +00:00
|
|
|
return (kern_ftruncate(td, args->fd, args->length));
|
2006-03-18 18:20:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
|
|
|
int
|
|
|
|
linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
|
|
|
|
{
|
|
|
|
off_t length;
|
|
|
|
|
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
length = PAIR32TO64(off_t, args->length);
|
|
|
|
#else
|
|
|
|
length = args->length;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (kern_ftruncate(td, args->fd, length));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
1999-08-12 19:53:33 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_link(struct thread *td, struct linux_link_args *args)
|
1999-08-12 19:53:33 +00:00
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path, *to;
|
|
|
|
int error;
|
1999-08-12 19:53:33 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_linkat(td, AT_FDCWD, AT_FDCWD, args->path, args->to,
|
2021-04-25 13:13:02 +00:00
|
|
|
UIO_USERSPACE, AT_SYMLINK_FOLLOW));
|
2020-10-26 18:02:52 +00:00
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2002-09-01 22:30:27 +00:00
|
|
|
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
|
2021-11-25 21:42:13 +00:00
|
|
|
error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
|
2002-09-01 22:30:27 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_linkat(td, AT_FDCWD, AT_FDCWD, path, to, UIO_SYSSPACE,
|
2021-04-25 13:13:02 +00:00
|
|
|
AT_SYMLINK_FOLLOW);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
LFREEPATH(to);
|
|
|
|
return (error);
|
1999-08-12 19:53:33 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
1999-08-14 18:20:44 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
int
|
|
|
|
linux_linkat(struct thread *td, struct linux_linkat_args *args)
|
|
|
|
{
|
|
|
|
char *path, *to;
|
2021-04-25 13:13:02 +00:00
|
|
|
int error, olddfd, newdfd, flag;
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
|
2021-05-04 12:09:31 +00:00
|
|
|
if (args->flag & ~(LINUX_AT_SYMLINK_FOLLOW | LINUX_AT_EMPTY_PATH))
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
2021-11-17 23:51:06 +00:00
|
|
|
flag = (args->flag & LINUX_AT_SYMLINK_FOLLOW) != 0 ? AT_SYMLINK_FOLLOW :
|
2021-04-25 13:13:02 +00:00
|
|
|
0;
|
2021-11-17 23:51:06 +00:00
|
|
|
flag |= (args->flag & LINUX_AT_EMPTY_PATH) != 0 ? AT_EMPTY_PATH : 0;
|
2021-04-25 13:13:02 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
|
|
|
|
newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_linkat(td, olddfd, newdfd, args->oldname,
|
2021-04-25 13:13:02 +00:00
|
|
|
args->newname, UIO_USERSPACE, flag));
|
2020-10-26 18:02:52 +00:00
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST_AT(args->oldname, &path, olddfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
|
2021-11-25 21:42:13 +00:00
|
|
|
error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, newdfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
2021-04-25 13:13:02 +00:00
|
|
|
error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, flag);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
LFREEPATH(to);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-11-26 10:20:10 +00:00
|
|
|
int
|
2019-12-16 17:45:15 +00:00
|
|
|
linux_fdatasync(struct thread *td, struct linux_fdatasync_args *uap)
|
1999-11-26 10:20:10 +00:00
|
|
|
{
|
|
|
|
|
2016-08-15 20:11:52 +00:00
|
|
|
return (kern_fsync(td, uap->fd, false));
|
1999-11-26 10:20:10 +00:00
|
|
|
}
|
2000-07-17 00:17:07 +00:00
|
|
|
|
2019-12-14 13:37:17 +00:00
|
|
|
int
|
2019-12-16 17:45:15 +00:00
|
|
|
linux_sync_file_range(struct thread *td, struct linux_sync_file_range_args *uap)
|
2019-12-14 13:37:17 +00:00
|
|
|
{
|
2020-01-21 17:28:22 +00:00
|
|
|
off_t nbytes, offset;
|
|
|
|
|
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
nbytes = PAIR32TO64(off_t, uap->nbytes);
|
|
|
|
offset = PAIR32TO64(off_t, uap->offset);
|
|
|
|
#else
|
|
|
|
nbytes = uap->nbytes;
|
|
|
|
offset = uap->offset;
|
|
|
|
#endif
|
2019-12-14 13:37:17 +00:00
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
if (offset < 0 || nbytes < 0 ||
|
2019-12-14 13:37:17 +00:00
|
|
|
(uap->flags & ~(LINUX_SYNC_FILE_RANGE_WAIT_BEFORE |
|
|
|
|
LINUX_SYNC_FILE_RANGE_WRITE |
|
|
|
|
LINUX_SYNC_FILE_RANGE_WAIT_AFTER)) != 0) {
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (kern_fsync(td, uap->fd, false));
|
|
|
|
}
|
|
|
|
|
2000-07-17 00:17:07 +00:00
|
|
|
int
|
2017-01-31 15:35:18 +00:00
|
|
|
linux_pread(struct thread *td, struct linux_pread_args *uap)
|
2000-07-17 00:17:07 +00:00
|
|
|
{
|
2006-09-23 19:06:54 +00:00
|
|
|
struct vnode *vp;
|
2020-01-21 17:28:22 +00:00
|
|
|
off_t offset;
|
2006-09-23 19:06:54 +00:00
|
|
|
int error;
|
2000-07-17 00:17:07 +00:00
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
offset = PAIR32TO64(off_t, uap->offset);
|
|
|
|
#else
|
|
|
|
offset = uap->offset;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
error = kern_pread(td, uap->fd, uap->buf, uap->nbyte, offset);
|
2006-09-23 19:06:54 +00:00
|
|
|
if (error == 0) {
|
2018-02-22 02:24:17 +00:00
|
|
|
/* This seems to violate POSIX but Linux does it. */
|
2018-05-09 18:47:24 +00:00
|
|
|
error = fgetvp(td, uap->fd, &cap_pread_rights, &vp);
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
if (error != 0)
|
Merge Capsicum overhaul:
- Capability is no longer separate descriptor type. Now every descriptor
has set of its own capability rights.
- The cap_new(2) system call is left, but it is no longer documented and
should not be used in new code.
- The new syscall cap_rights_limit(2) should be used instead of
cap_new(2), which limits capability rights of the given descriptor
without creating a new one.
- The cap_getrights(2) syscall is renamed to cap_rights_get(2).
- If CAP_IOCTL capability right is present we can further reduce allowed
ioctls list with the new cap_ioctls_limit(2) syscall. List of allowed
ioctls can be retrived with cap_ioctls_get(2) syscall.
- If CAP_FCNTL capability right is present we can further reduce fcntls
that can be used with the new cap_fcntls_limit(2) syscall and retrive
them with cap_fcntls_get(2).
- To support ioctl and fcntl white-listing the filedesc structure was
heavly modified.
- The audit subsystem, kdump and procstat tools were updated to
recognize new syscalls.
- Capability rights were revised and eventhough I tried hard to provide
backward API and ABI compatibility there are some incompatible changes
that are described in detail below:
CAP_CREATE old behaviour:
- Allow for openat(2)+O_CREAT.
- Allow for linkat(2).
- Allow for symlinkat(2).
CAP_CREATE new behaviour:
- Allow for openat(2)+O_CREAT.
Added CAP_LINKAT:
- Allow for linkat(2). ABI: Reuses CAP_RMDIR bit.
- Allow to be target for renameat(2).
Added CAP_SYMLINKAT:
- Allow for symlinkat(2).
Removed CAP_DELETE. Old behaviour:
- Allow for unlinkat(2) when removing non-directory object.
- Allow to be source for renameat(2).
Removed CAP_RMDIR. Old behaviour:
- Allow for unlinkat(2) when removing directory.
Added CAP_RENAMEAT:
- Required for source directory for the renameat(2) syscall.
Added CAP_UNLINKAT (effectively it replaces CAP_DELETE and CAP_RMDIR):
- Allow for unlinkat(2) on any object.
- Required if target of renameat(2) exists and will be removed by this
call.
Removed CAP_MAPEXEC.
CAP_MMAP old behaviour:
- Allow for mmap(2) with any combination of PROT_NONE, PROT_READ and
PROT_WRITE.
CAP_MMAP new behaviour:
- Allow for mmap(2)+PROT_NONE.
Added CAP_MMAP_R:
- Allow for mmap(PROT_READ).
Added CAP_MMAP_W:
- Allow for mmap(PROT_WRITE).
Added CAP_MMAP_X:
- Allow for mmap(PROT_EXEC).
Added CAP_MMAP_RW:
- Allow for mmap(PROT_READ | PROT_WRITE).
Added CAP_MMAP_RX:
- Allow for mmap(PROT_READ | PROT_EXEC).
Added CAP_MMAP_WX:
- Allow for mmap(PROT_WRITE | PROT_EXEC).
Added CAP_MMAP_RWX:
- Allow for mmap(PROT_READ | PROT_WRITE | PROT_EXEC).
Renamed CAP_MKDIR to CAP_MKDIRAT.
Renamed CAP_MKFIFO to CAP_MKFIFOAT.
Renamed CAP_MKNODE to CAP_MKNODEAT.
CAP_READ old behaviour:
- Allow pread(2).
- Disallow read(2), readv(2) (if there is no CAP_SEEK).
CAP_READ new behaviour:
- Allow read(2), readv(2).
- Disallow pread(2) (CAP_SEEK was also required).
CAP_WRITE old behaviour:
- Allow pwrite(2).
- Disallow write(2), writev(2) (if there is no CAP_SEEK).
CAP_WRITE new behaviour:
- Allow write(2), writev(2).
- Disallow pwrite(2) (CAP_SEEK was also required).
Added convinient defines:
#define CAP_PREAD (CAP_SEEK | CAP_READ)
#define CAP_PWRITE (CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_R (CAP_MMAP | CAP_SEEK | CAP_READ)
#define CAP_MMAP_W (CAP_MMAP | CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_X (CAP_MMAP | CAP_SEEK | 0x0000000000000008ULL)
#define CAP_MMAP_RW (CAP_MMAP_R | CAP_MMAP_W)
#define CAP_MMAP_RX (CAP_MMAP_R | CAP_MMAP_X)
#define CAP_MMAP_WX (CAP_MMAP_W | CAP_MMAP_X)
#define CAP_MMAP_RWX (CAP_MMAP_R | CAP_MMAP_W | CAP_MMAP_X)
#define CAP_RECV CAP_READ
#define CAP_SEND CAP_WRITE
#define CAP_SOCK_CLIENT \
(CAP_CONNECT | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT | \
CAP_PEELOFF | CAP_RECV | CAP_SEND | CAP_SETSOCKOPT | CAP_SHUTDOWN)
#define CAP_SOCK_SERVER \
(CAP_ACCEPT | CAP_BIND | CAP_GETPEERNAME | CAP_GETSOCKNAME | \
CAP_GETSOCKOPT | CAP_LISTEN | CAP_PEELOFF | CAP_RECV | CAP_SEND | \
CAP_SETSOCKOPT | CAP_SHUTDOWN)
Added defines for backward API compatibility:
#define CAP_MAPEXEC CAP_MMAP_X
#define CAP_DELETE CAP_UNLINKAT
#define CAP_MKDIR CAP_MKDIRAT
#define CAP_RMDIR CAP_UNLINKAT
#define CAP_MKFIFO CAP_MKFIFOAT
#define CAP_MKNOD CAP_MKNODAT
#define CAP_SOCK_ALL (CAP_SOCK_CLIENT | CAP_SOCK_SERVER)
Sponsored by: The FreeBSD Foundation
Reviewed by: Christoph Mallon <christoph.mallon@gmx.de>
Many aspects discussed with: rwatson, benl, jonathan
ABI compatibility discussed with: kib
2013-03-02 00:53:12 +00:00
|
|
|
return (error);
|
2020-01-21 17:28:22 +00:00
|
|
|
if (vp->v_type == VDIR)
|
|
|
|
error = EISDIR;
|
2006-09-23 19:06:54 +00:00
|
|
|
vrele(vp);
|
|
|
|
}
|
|
|
|
return (error);
|
2000-07-17 00:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-01-31 15:35:18 +00:00
|
|
|
linux_pwrite(struct thread *td, struct linux_pwrite_args *uap)
|
2000-07-17 00:17:07 +00:00
|
|
|
{
|
2020-01-21 17:28:22 +00:00
|
|
|
off_t offset;
|
|
|
|
|
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
offset = PAIR32TO64(off_t, uap->offset);
|
|
|
|
#else
|
|
|
|
offset = uap->offset;
|
|
|
|
#endif
|
2000-07-17 00:17:07 +00:00
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, offset));
|
2000-07-17 00:17:07 +00:00
|
|
|
}
|
2001-02-16 14:42:11 +00:00
|
|
|
|
2022-05-09 18:11:37 +00:00
|
|
|
#define HALF_LONG_BITS ((sizeof(l_long) * NBBY / 2))
|
|
|
|
|
|
|
|
static inline off_t
|
|
|
|
pos_from_hilo(unsigned long high, unsigned long low)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (((off_t)high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
|
|
|
|
}
|
|
|
|
|
2017-02-24 20:04:02 +00:00
|
|
|
int
|
|
|
|
linux_preadv(struct thread *td, struct linux_preadv_args *uap)
|
|
|
|
{
|
|
|
|
struct uio *auio;
|
|
|
|
int error;
|
|
|
|
off_t offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* According http://man7.org/linux/man-pages/man2/preadv.2.html#NOTES
|
|
|
|
* pos_l and pos_h, respectively, contain the
|
|
|
|
* low order and high order 32 bits of offset.
|
|
|
|
*/
|
2022-05-09 18:11:37 +00:00
|
|
|
offset = pos_from_hilo(uap->pos_h, uap->pos_l);
|
2017-02-24 20:04:02 +00:00
|
|
|
if (offset < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
#ifdef COMPAT_LINUX32
|
|
|
|
error = linux32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
|
|
|
|
#else
|
|
|
|
error = copyinuio(uap->vec, uap->vlen, &auio);
|
|
|
|
#endif
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
error = kern_preadv(td, uap->fd, auio, offset);
|
|
|
|
free(auio, M_IOV);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_pwritev(struct thread *td, struct linux_pwritev_args *uap)
|
|
|
|
{
|
|
|
|
struct uio *auio;
|
|
|
|
int error;
|
|
|
|
off_t offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* According http://man7.org/linux/man-pages/man2/pwritev.2.html#NOTES
|
|
|
|
* pos_l and pos_h, respectively, contain the
|
|
|
|
* low order and high order 32 bits of offset.
|
|
|
|
*/
|
2022-05-09 18:11:37 +00:00
|
|
|
offset = pos_from_hilo(uap->pos_h, uap->pos_l);
|
2017-02-24 20:04:02 +00:00
|
|
|
if (offset < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
#ifdef COMPAT_LINUX32
|
|
|
|
error = linux32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
|
|
|
|
#else
|
|
|
|
error = copyinuio(uap->vec, uap->vlen, &auio);
|
|
|
|
#endif
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
error = kern_pwritev(td, uap->fd, auio, offset);
|
|
|
|
free(auio, M_IOV);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2001-02-16 14:42:11 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_mount(struct thread *td, struct linux_mount_args *args)
|
2001-02-16 14:42:11 +00:00
|
|
|
{
|
2020-11-09 08:53:15 +00:00
|
|
|
struct mntarg *ma = NULL;
|
|
|
|
char *fstypename, *mntonname, *mntfromname, *data;
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
int error, fsflags;
|
2001-02-16 14:42:11 +00:00
|
|
|
|
2020-11-09 08:53:15 +00:00
|
|
|
fstypename = malloc(MNAMELEN, M_TEMP, M_WAITOK);
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
mntonname = malloc(MNAMELEN, M_TEMP, M_WAITOK);
|
|
|
|
mntfromname = malloc(MNAMELEN, M_TEMP, M_WAITOK);
|
2020-11-09 08:53:15 +00:00
|
|
|
data = NULL;
|
|
|
|
error = copyinstr(args->filesystemtype, fstypename, MNAMELEN - 1,
|
2001-03-01 21:00:17 +00:00
|
|
|
NULL);
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
2019-12-28 13:35:54 +00:00
|
|
|
if (args->specialfile != NULL) {
|
|
|
|
error = copyinstr(args->specialfile, mntfromname, MNAMELEN - 1, NULL);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
mntfromname[0] = '\0';
|
|
|
|
}
|
2004-03-16 08:37:19 +00:00
|
|
|
error = copyinstr(args->dir, mntonname, MNAMELEN - 1, NULL);
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
2001-02-16 14:42:11 +00:00
|
|
|
|
|
|
|
if (strcmp(fstypename, "ext2") == 0) {
|
2004-03-16 09:05:56 +00:00
|
|
|
strcpy(fstypename, "ext2fs");
|
2001-02-16 14:42:11 +00:00
|
|
|
} else if (strcmp(fstypename, "proc") == 0) {
|
2004-03-16 09:05:56 +00:00
|
|
|
strcpy(fstypename, "linprocfs");
|
2009-03-26 17:14:22 +00:00
|
|
|
} else if (strcmp(fstypename, "vfat") == 0) {
|
|
|
|
strcpy(fstypename, "msdosfs");
|
2021-06-07 09:43:23 +00:00
|
|
|
} else if (strcmp(fstypename, "fuse") == 0 ||
|
|
|
|
strncmp(fstypename, "fuse.", 5) == 0) {
|
2020-11-09 08:53:15 +00:00
|
|
|
char *fuse_options, *fuse_option, *fuse_name;
|
|
|
|
|
2021-06-07 09:43:23 +00:00
|
|
|
strcpy(mntfromname, "/dev/fuse");
|
2020-11-09 08:53:15 +00:00
|
|
|
strcpy(fstypename, "fusefs");
|
|
|
|
data = malloc(MNAMELEN, M_TEMP, M_WAITOK);
|
|
|
|
error = copyinstr(args->data, data, MNAMELEN - 1, NULL);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fuse_options = data;
|
|
|
|
while ((fuse_option = strsep(&fuse_options, ",")) != NULL) {
|
|
|
|
fuse_name = strsep(&fuse_option, "=");
|
|
|
|
if (fuse_name == NULL || fuse_option == NULL)
|
|
|
|
goto out;
|
|
|
|
ma = mount_arg(ma, fuse_name, fuse_option, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The FUSE server uses Linux errno values instead of FreeBSD
|
|
|
|
* ones; add a flag to tell fuse(4) to do errno translation.
|
|
|
|
*/
|
|
|
|
ma = mount_arg(ma, "linux_errnos", "1", -1);
|
2001-02-16 14:42:11 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 21:00:17 +00:00
|
|
|
fsflags = 0;
|
2001-02-16 14:42:11 +00:00
|
|
|
|
2019-12-28 13:35:54 +00:00
|
|
|
/*
|
|
|
|
* Linux SYNC flag is not included; the closest equivalent
|
|
|
|
* FreeBSD has is !ASYNC, which is our default.
|
|
|
|
*/
|
|
|
|
if (args->rwflag & LINUX_MS_RDONLY)
|
|
|
|
fsflags |= MNT_RDONLY;
|
|
|
|
if (args->rwflag & LINUX_MS_NOSUID)
|
|
|
|
fsflags |= MNT_NOSUID;
|
|
|
|
if (args->rwflag & LINUX_MS_NOEXEC)
|
|
|
|
fsflags |= MNT_NOEXEC;
|
|
|
|
if (args->rwflag & LINUX_MS_REMOUNT)
|
|
|
|
fsflags |= MNT_UPDATE;
|
2001-02-16 14:42:11 +00:00
|
|
|
|
2020-11-09 08:53:15 +00:00
|
|
|
ma = mount_arg(ma, "fstype", fstypename, -1);
|
|
|
|
ma = mount_arg(ma, "fspath", mntonname, -1);
|
|
|
|
ma = mount_arg(ma, "from", mntfromname, -1);
|
|
|
|
error = kernel_mount(ma, fsflags);
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
out:
|
2020-11-09 08:53:15 +00:00
|
|
|
free(fstypename, M_TEMP);
|
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.
ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.
Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.
Struct xvnode changed layout, no compat shims are provided.
For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.
Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.
Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).
Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 09:29:05 +00:00
|
|
|
free(mntonname, M_TEMP);
|
|
|
|
free(mntfromname, M_TEMP);
|
2020-11-09 08:53:15 +00:00
|
|
|
free(data, M_TEMP);
|
2004-03-16 09:05:56 +00:00
|
|
|
return (error);
|
2001-02-16 14:42:11 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 15:43:53 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
2001-02-16 14:42:11 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_oldumount(struct thread *td, struct linux_oldumount_args *args)
|
2001-02-16 14:42:11 +00:00
|
|
|
{
|
|
|
|
|
2020-01-24 11:57:55 +00:00
|
|
|
return (kern_unmount(td, args->path, 0));
|
2001-02-16 14:42:11 +00:00
|
|
|
}
|
2015-05-24 15:43:53 +00:00
|
|
|
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|
2001-02-16 14:42:11 +00:00
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
2001-02-16 14:42:11 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_umount(struct thread *td, struct linux_umount_args *args)
|
2001-02-16 14:42:11 +00:00
|
|
|
{
|
2020-01-20 12:16:32 +00:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
flags = 0;
|
2020-01-24 11:57:55 +00:00
|
|
|
if ((args->flags & LINUX_MNT_FORCE) != 0) {
|
|
|
|
args->flags &= ~LINUX_MNT_FORCE;
|
2020-01-20 12:16:32 +00:00
|
|
|
flags |= MNT_FORCE;
|
2020-01-24 11:57:55 +00:00
|
|
|
}
|
|
|
|
if (args->flags != 0) {
|
|
|
|
linux_msg(td, "unsupported umount2 flags %#x", args->flags);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2001-02-16 14:42:11 +00:00
|
|
|
|
2020-01-24 11:57:55 +00:00
|
|
|
return (kern_unmount(td, args->path, flags));
|
2001-02-16 14:42:11 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fcntl family of syscalls
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct l_flock {
|
|
|
|
l_short l_type;
|
|
|
|
l_short l_whence;
|
|
|
|
l_off_t l_start;
|
|
|
|
l_off_t l_len;
|
|
|
|
l_pid_t l_pid;
|
2004-08-16 07:28:16 +00:00
|
|
|
}
|
2005-01-14 04:44:56 +00:00
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
2004-08-16 07:28:16 +00:00
|
|
|
__packed
|
|
|
|
#endif
|
|
|
|
;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
|
|
|
|
{
|
|
|
|
switch (linux_flock->l_type) {
|
|
|
|
case LINUX_F_RDLCK:
|
|
|
|
bsd_flock->l_type = F_RDLCK;
|
|
|
|
break;
|
|
|
|
case LINUX_F_WRLCK:
|
|
|
|
bsd_flock->l_type = F_WRLCK;
|
|
|
|
break;
|
|
|
|
case LINUX_F_UNLCK:
|
|
|
|
bsd_flock->l_type = F_UNLCK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bsd_flock->l_type = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bsd_flock->l_whence = linux_flock->l_whence;
|
|
|
|
bsd_flock->l_start = (off_t)linux_flock->l_start;
|
|
|
|
bsd_flock->l_len = (off_t)linux_flock->l_len;
|
|
|
|
bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
|
2008-03-26 15:23:12 +00:00
|
|
|
bsd_flock->l_sysid = 0;
|
2001-09-08 19:07:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
|
|
|
|
{
|
|
|
|
switch (bsd_flock->l_type) {
|
|
|
|
case F_RDLCK:
|
|
|
|
linux_flock->l_type = LINUX_F_RDLCK;
|
|
|
|
break;
|
|
|
|
case F_WRLCK:
|
|
|
|
linux_flock->l_type = LINUX_F_WRLCK;
|
|
|
|
break;
|
|
|
|
case F_UNLCK:
|
|
|
|
linux_flock->l_type = LINUX_F_UNLCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
linux_flock->l_whence = bsd_flock->l_whence;
|
|
|
|
linux_flock->l_start = (l_off_t)bsd_flock->l_start;
|
|
|
|
linux_flock->l_len = (l_off_t)bsd_flock->l_len;
|
|
|
|
linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
|
|
|
|
}
|
|
|
|
|
2005-01-14 04:44:56 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
2001-09-08 19:07:04 +00:00
|
|
|
struct l_flock64 {
|
|
|
|
l_short l_type;
|
|
|
|
l_short l_whence;
|
|
|
|
l_loff_t l_start;
|
|
|
|
l_loff_t l_len;
|
|
|
|
l_pid_t l_pid;
|
2004-08-16 07:28:16 +00:00
|
|
|
}
|
2005-01-14 04:44:56 +00:00
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
2004-08-16 07:28:16 +00:00
|
|
|
__packed
|
|
|
|
#endif
|
|
|
|
;
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
|
|
|
|
{
|
|
|
|
switch (linux_flock->l_type) {
|
|
|
|
case LINUX_F_RDLCK:
|
|
|
|
bsd_flock->l_type = F_RDLCK;
|
|
|
|
break;
|
|
|
|
case LINUX_F_WRLCK:
|
|
|
|
bsd_flock->l_type = F_WRLCK;
|
|
|
|
break;
|
|
|
|
case LINUX_F_UNLCK:
|
|
|
|
bsd_flock->l_type = F_UNLCK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bsd_flock->l_type = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bsd_flock->l_whence = linux_flock->l_whence;
|
|
|
|
bsd_flock->l_start = (off_t)linux_flock->l_start;
|
|
|
|
bsd_flock->l_len = (off_t)linux_flock->l_len;
|
|
|
|
bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
|
2008-03-26 15:23:12 +00:00
|
|
|
bsd_flock->l_sysid = 0;
|
2001-09-08 19:07:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
|
|
|
|
{
|
|
|
|
switch (bsd_flock->l_type) {
|
|
|
|
case F_RDLCK:
|
|
|
|
linux_flock->l_type = LINUX_F_RDLCK;
|
|
|
|
break;
|
|
|
|
case F_WRLCK:
|
|
|
|
linux_flock->l_type = LINUX_F_WRLCK;
|
|
|
|
break;
|
|
|
|
case F_UNLCK:
|
|
|
|
linux_flock->l_type = LINUX_F_UNLCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
linux_flock->l_whence = bsd_flock->l_whence;
|
|
|
|
linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
|
|
|
|
linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
|
|
|
|
linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
|
|
|
|
}
|
2004-08-16 07:28:16 +00:00
|
|
|
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
static int
|
2015-05-24 15:43:53 +00:00
|
|
|
fcntl_common(struct thread *td, struct linux_fcntl_args *args)
|
2001-09-08 19:07:04 +00:00
|
|
|
{
|
2002-12-08 18:30:44 +00:00
|
|
|
struct l_flock linux_flock;
|
|
|
|
struct flock bsd_flock;
|
2021-05-31 19:15:02 +00:00
|
|
|
struct pipe *fpipe;
|
2001-09-08 19:07:04 +00:00
|
|
|
struct file *fp;
|
2002-09-02 22:46:05 +00:00
|
|
|
long arg;
|
2001-09-08 19:07:04 +00:00
|
|
|
int error, result;
|
|
|
|
|
|
|
|
switch (args->cmd) {
|
|
|
|
case LINUX_F_DUPFD:
|
2002-09-02 22:46:05 +00:00
|
|
|
return (kern_fcntl(td, args->fd, F_DUPFD, args->arg));
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
case LINUX_F_GETFD:
|
2002-09-02 22:46:05 +00:00
|
|
|
return (kern_fcntl(td, args->fd, F_GETFD, 0));
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
case LINUX_F_SETFD:
|
2002-09-02 22:46:05 +00:00
|
|
|
return (kern_fcntl(td, args->fd, F_SETFD, args->arg));
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
case LINUX_F_GETFL:
|
2002-09-02 22:46:05 +00:00
|
|
|
error = kern_fcntl(td, args->fd, F_GETFL, 0);
|
2001-09-12 08:38:13 +00:00
|
|
|
result = td->td_retval[0];
|
|
|
|
td->td_retval[0] = 0;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (result & O_RDONLY)
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] |= LINUX_O_RDONLY;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (result & O_WRONLY)
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] |= LINUX_O_WRONLY;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (result & O_RDWR)
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] |= LINUX_O_RDWR;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (result & O_NDELAY)
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] |= LINUX_O_NONBLOCK;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (result & O_APPEND)
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] |= LINUX_O_APPEND;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (result & O_FSYNC)
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] |= LINUX_O_SYNC;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (result & O_ASYNC)
|
2020-06-11 14:09:43 +00:00
|
|
|
td->td_retval[0] |= LINUX_O_ASYNC;
|
2005-04-13 04:31:43 +00:00
|
|
|
#ifdef LINUX_O_NOFOLLOW
|
|
|
|
if (result & O_NOFOLLOW)
|
|
|
|
td->td_retval[0] |= LINUX_O_NOFOLLOW;
|
|
|
|
#endif
|
|
|
|
#ifdef LINUX_O_DIRECT
|
|
|
|
if (result & O_DIRECT)
|
|
|
|
td->td_retval[0] |= LINUX_O_DIRECT;
|
|
|
|
#endif
|
2001-09-08 19:07:04 +00:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
case LINUX_F_SETFL:
|
2002-09-02 22:46:05 +00:00
|
|
|
arg = 0;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (args->arg & LINUX_O_NDELAY)
|
2002-09-02 22:46:05 +00:00
|
|
|
arg |= O_NONBLOCK;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (args->arg & LINUX_O_APPEND)
|
2002-09-02 22:46:05 +00:00
|
|
|
arg |= O_APPEND;
|
2001-09-08 19:07:04 +00:00
|
|
|
if (args->arg & LINUX_O_SYNC)
|
2002-09-02 22:46:05 +00:00
|
|
|
arg |= O_FSYNC;
|
2020-06-11 14:09:43 +00:00
|
|
|
if (args->arg & LINUX_O_ASYNC)
|
2002-09-02 22:46:05 +00:00
|
|
|
arg |= O_ASYNC;
|
2005-04-13 04:31:43 +00:00
|
|
|
#ifdef LINUX_O_NOFOLLOW
|
|
|
|
if (args->arg & LINUX_O_NOFOLLOW)
|
|
|
|
arg |= O_NOFOLLOW;
|
|
|
|
#endif
|
|
|
|
#ifdef LINUX_O_DIRECT
|
|
|
|
if (args->arg & LINUX_O_DIRECT)
|
|
|
|
arg |= O_DIRECT;
|
|
|
|
#endif
|
2002-09-02 22:46:05 +00:00
|
|
|
return (kern_fcntl(td, args->fd, F_SETFL, arg));
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2002-12-08 18:30:44 +00:00
|
|
|
case LINUX_F_GETLK:
|
2003-03-03 09:14:26 +00:00
|
|
|
error = copyin((void *)args->arg, &linux_flock,
|
2002-12-08 18:30:44 +00:00
|
|
|
sizeof(linux_flock));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
linux_to_bsd_flock(&linux_flock, &bsd_flock);
|
|
|
|
error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
bsd_to_linux_flock(&bsd_flock, &linux_flock);
|
2003-03-03 09:14:26 +00:00
|
|
|
return (copyout(&linux_flock, (void *)args->arg,
|
2002-12-08 18:30:44 +00:00
|
|
|
sizeof(linux_flock)));
|
|
|
|
|
|
|
|
case LINUX_F_SETLK:
|
2003-03-03 09:14:26 +00:00
|
|
|
error = copyin((void *)args->arg, &linux_flock,
|
2002-12-08 18:30:44 +00:00
|
|
|
sizeof(linux_flock));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
linux_to_bsd_flock(&linux_flock, &bsd_flock);
|
|
|
|
return (kern_fcntl(td, args->fd, F_SETLK,
|
|
|
|
(intptr_t)&bsd_flock));
|
|
|
|
|
|
|
|
case LINUX_F_SETLKW:
|
2003-03-03 09:14:26 +00:00
|
|
|
error = copyin((void *)args->arg, &linux_flock,
|
2002-12-08 18:30:44 +00:00
|
|
|
sizeof(linux_flock));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
linux_to_bsd_flock(&linux_flock, &bsd_flock);
|
|
|
|
return (kern_fcntl(td, args->fd, F_SETLKW,
|
|
|
|
(intptr_t)&bsd_flock));
|
|
|
|
|
2001-09-08 19:07:04 +00:00
|
|
|
case LINUX_F_GETOWN:
|
2002-09-02 22:46:05 +00:00
|
|
|
return (kern_fcntl(td, args->fd, F_GETOWN, 0));
|
2001-09-08 19:07:04 +00:00
|
|
|
|
|
|
|
case LINUX_F_SETOWN:
|
|
|
|
/*
|
|
|
|
* XXX some Linux applications depend on F_SETOWN having no
|
|
|
|
* significant effect for pipes (SIGIO is not delivered for
|
|
|
|
* pipes under Linux-2.2.35 at least).
|
|
|
|
*/
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
error = fget(td, args->fd,
|
2018-05-09 18:47:24 +00:00
|
|
|
&cap_fcntl_rights, &fp);
|
2002-01-14 00:13:45 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-01-13 11:58:06 +00:00
|
|
|
if (fp->f_type == DTYPE_PIPE) {
|
|
|
|
fdrop(fp, td);
|
2001-09-08 19:07:04 +00:00
|
|
|
return (EINVAL);
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
|
|
|
fdrop(fp, td);
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2002-09-02 22:46:05 +00:00
|
|
|
return (kern_fcntl(td, args->fd, F_SETOWN, args->arg));
|
2015-05-24 16:34:57 +00:00
|
|
|
|
|
|
|
case LINUX_F_DUPFD_CLOEXEC:
|
|
|
|
return (kern_fcntl(td, args->fd, F_DUPFD_CLOEXEC, args->arg));
|
2020-06-29 03:09:14 +00:00
|
|
|
/*
|
|
|
|
* Our F_SEAL_* values match Linux one for maximum compatibility. So we
|
|
|
|
* only needed to account for different values for fcntl(2) commands.
|
|
|
|
*/
|
|
|
|
case LINUX_F_GET_SEALS:
|
|
|
|
error = kern_fcntl(td, args->fd, F_GET_SEALS, 0);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
td->td_retval[0] = bsd_to_linux_bits(td->td_retval[0],
|
|
|
|
seal_bitmap, 0);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case LINUX_F_ADD_SEALS:
|
|
|
|
return (kern_fcntl(td, args->fd, F_ADD_SEALS,
|
|
|
|
linux_to_bsd_bits(args->arg, seal_bitmap, 0)));
|
2021-05-31 19:15:02 +00:00
|
|
|
|
|
|
|
case LINUX_F_GETPIPE_SZ:
|
|
|
|
error = fget(td, args->fd,
|
|
|
|
&cap_fcntl_rights, &fp);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (fp->f_type != DTYPE_PIPE) {
|
|
|
|
fdrop(fp, td);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
fpipe = fp->f_data;
|
|
|
|
td->td_retval[0] = fpipe->pipe_buffer.size;
|
|
|
|
fdrop(fp, td);
|
|
|
|
return (0);
|
|
|
|
|
2020-06-12 14:25:32 +00:00
|
|
|
default:
|
2021-01-14 22:48:56 +00:00
|
|
|
linux_msg(td, "unsupported fcntl cmd %d", args->cmd);
|
2020-06-12 14:25:32 +00:00
|
|
|
return (EINVAL);
|
2001-09-08 19:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_fcntl(struct thread *td, struct linux_fcntl_args *args)
|
2001-09-08 19:07:04 +00:00
|
|
|
{
|
|
|
|
|
2015-05-24 15:43:53 +00:00
|
|
|
return (fcntl_common(td, args));
|
2001-09-08 19:07:04 +00:00
|
|
|
}
|
|
|
|
|
2005-01-14 04:44:56 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
2001-09-08 19:07:04 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args)
|
2001-09-08 19:07:04 +00:00
|
|
|
{
|
|
|
|
struct l_flock64 linux_flock;
|
2002-09-02 22:46:05 +00:00
|
|
|
struct flock bsd_flock;
|
2015-05-24 15:43:53 +00:00
|
|
|
struct linux_fcntl_args fcntl_args;
|
2001-09-08 19:07:04 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (args->cmd) {
|
2002-07-09 19:25:43 +00:00
|
|
|
case LINUX_F_GETLK64:
|
2003-03-03 09:14:26 +00:00
|
|
|
error = copyin((void *)args->arg, &linux_flock,
|
2001-09-08 19:07:04 +00:00
|
|
|
sizeof(linux_flock));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-09-02 22:46:05 +00:00
|
|
|
linux_to_bsd_flock64(&linux_flock, &bsd_flock);
|
|
|
|
error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock);
|
2001-09-08 19:07:04 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-09-02 22:46:05 +00:00
|
|
|
bsd_to_linux_flock64(&bsd_flock, &linux_flock);
|
2003-03-03 09:14:26 +00:00
|
|
|
return (copyout(&linux_flock, (void *)args->arg,
|
|
|
|
sizeof(linux_flock)));
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2002-07-09 19:25:43 +00:00
|
|
|
case LINUX_F_SETLK64:
|
2003-03-03 09:14:26 +00:00
|
|
|
error = copyin((void *)args->arg, &linux_flock,
|
2001-09-08 19:07:04 +00:00
|
|
|
sizeof(linux_flock));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-09-02 22:46:05 +00:00
|
|
|
linux_to_bsd_flock64(&linux_flock, &bsd_flock);
|
|
|
|
return (kern_fcntl(td, args->fd, F_SETLK,
|
|
|
|
(intptr_t)&bsd_flock));
|
2001-09-08 19:07:04 +00:00
|
|
|
|
2002-07-09 19:25:43 +00:00
|
|
|
case LINUX_F_SETLKW64:
|
2003-03-03 09:14:26 +00:00
|
|
|
error = copyin((void *)args->arg, &linux_flock,
|
2001-09-08 19:07:04 +00:00
|
|
|
sizeof(linux_flock));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-09-02 22:46:05 +00:00
|
|
|
linux_to_bsd_flock64(&linux_flock, &bsd_flock);
|
|
|
|
return (kern_fcntl(td, args->fd, F_SETLKW,
|
|
|
|
(intptr_t)&bsd_flock));
|
2001-09-08 19:07:04 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 15:43:53 +00:00
|
|
|
fcntl_args.fd = args->fd;
|
|
|
|
fcntl_args.cmd = args->cmd;
|
|
|
|
fcntl_args.arg = args->arg;
|
|
|
|
return (fcntl_common(td, &fcntl_args));
|
2001-09-08 19:07:04 +00:00
|
|
|
}
|
2004-08-16 07:28:16 +00:00
|
|
|
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|
2001-10-16 06:15:36 +00:00
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
2001-10-16 06:15:36 +00:00
|
|
|
int
|
|
|
|
linux_chown(struct thread *td, struct linux_chown_args *args)
|
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
2001-10-16 06:15:36 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
|
|
|
|
args->uid, args->gid, 0));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2014-11-13 18:01:51 +00:00
|
|
|
error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid,
|
|
|
|
args->gid, 0);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
2001-10-16 06:15:36 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
2001-10-16 06:15:36 +00:00
|
|
|
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
int
|
|
|
|
linux_fchownat(struct thread *td, struct linux_fchownat_args *args)
|
|
|
|
{
|
|
|
|
char *path;
|
2021-06-15 09:18:04 +00:00
|
|
|
int error, dfd, flag, unsupported;
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
|
2021-06-15 09:18:04 +00:00
|
|
|
unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
|
|
|
|
if (unsupported != 0) {
|
|
|
|
linux_msg(td, "fchownat unsupported flag 0x%x", unsupported);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
return (EINVAL);
|
2021-04-16 15:26:43 +00:00
|
|
|
}
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
|
2011-11-19 07:19:37 +00:00
|
|
|
flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) == 0 ? 0 :
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
AT_SYMLINK_NOFOLLOW;
|
2021-04-16 15:26:43 +00:00
|
|
|
flag |= (args->flag & LINUX_AT_EMPTY_PATH) == 0 ? 0 :
|
|
|
|
AT_EMPTY_PATH;
|
|
|
|
|
|
|
|
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_fchownat(td, dfd, args->filename, UIO_USERSPACE,
|
|
|
|
args->uid, args->gid, flag));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST_AT(args->filename, &path, dfd);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
error = kern_fchownat(td, dfd, path, UIO_SYSSPACE, args->uid, args->gid,
|
2011-11-19 07:19:37 +00:00
|
|
|
flag);
|
Implement the linux syscalls
openat, mkdirat, mknodat, fchownat, futimesat, fstatat, unlinkat,
renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
Submitted by: rdivacky
Sponsored by: Google Summer of Code 2007
Tested by: pho
2008-04-08 09:45:49 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
2001-10-16 06:15:36 +00:00
|
|
|
int
|
|
|
|
linux_lchown(struct thread *td, struct linux_lchown_args *args)
|
|
|
|
{
|
2002-09-01 22:30:27 +00:00
|
|
|
char *path;
|
|
|
|
int error;
|
2001-10-16 06:15:36 +00:00
|
|
|
|
2020-10-26 18:02:52 +00:00
|
|
|
if (!LUSECONVPATH(td)) {
|
|
|
|
return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->uid,
|
|
|
|
args->gid, AT_SYMLINK_NOFOLLOW));
|
|
|
|
}
|
2021-11-25 21:42:13 +00:00
|
|
|
LCONVPATHEXIST(args->path, &path);
|
2020-10-26 18:02:52 +00:00
|
|
|
error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid, args->gid,
|
|
|
|
AT_SYMLINK_NOFOLLOW);
|
2002-09-01 22:30:27 +00:00
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
2001-10-16 06:15:36 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
2011-12-29 15:34:59 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
convert_fadvice(int advice)
|
|
|
|
{
|
|
|
|
switch (advice) {
|
|
|
|
case LINUX_POSIX_FADV_NORMAL:
|
|
|
|
return (POSIX_FADV_NORMAL);
|
|
|
|
case LINUX_POSIX_FADV_RANDOM:
|
|
|
|
return (POSIX_FADV_RANDOM);
|
|
|
|
case LINUX_POSIX_FADV_SEQUENTIAL:
|
|
|
|
return (POSIX_FADV_SEQUENTIAL);
|
|
|
|
case LINUX_POSIX_FADV_WILLNEED:
|
|
|
|
return (POSIX_FADV_WILLNEED);
|
|
|
|
case LINUX_POSIX_FADV_DONTNEED:
|
|
|
|
return (POSIX_FADV_DONTNEED);
|
|
|
|
case LINUX_POSIX_FADV_NOREUSE:
|
|
|
|
return (POSIX_FADV_NOREUSE);
|
|
|
|
default:
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_fadvise64(struct thread *td, struct linux_fadvise64_args *args)
|
|
|
|
{
|
2020-01-21 17:28:22 +00:00
|
|
|
off_t offset;
|
2011-12-29 15:34:59 +00:00
|
|
|
int advice;
|
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
offset = PAIR32TO64(off_t, args->offset);
|
|
|
|
#else
|
|
|
|
offset = args->offset;
|
|
|
|
#endif
|
|
|
|
|
2011-12-29 15:34:59 +00:00
|
|
|
advice = convert_fadvice(args->advice);
|
|
|
|
if (advice == -1)
|
|
|
|
return (EINVAL);
|
2020-01-21 17:28:22 +00:00
|
|
|
return (kern_posix_fadvise(td, args->fd, offset, args->len, advice));
|
2011-12-29 15:34:59 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 15:43:53 +00:00
|
|
|
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
|
2011-12-29 15:34:59 +00:00
|
|
|
int
|
|
|
|
linux_fadvise64_64(struct thread *td, struct linux_fadvise64_64_args *args)
|
|
|
|
{
|
2020-01-21 17:28:22 +00:00
|
|
|
off_t len, offset;
|
2011-12-29 15:34:59 +00:00
|
|
|
int advice;
|
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
len = PAIR32TO64(off_t, args->len);
|
|
|
|
offset = PAIR32TO64(off_t, args->offset);
|
|
|
|
#else
|
|
|
|
len = args->len;
|
|
|
|
offset = args->offset;
|
|
|
|
#endif
|
|
|
|
|
2011-12-29 15:34:59 +00:00
|
|
|
advice = convert_fadvice(args->advice);
|
|
|
|
if (advice == -1)
|
|
|
|
return (EINVAL);
|
2020-01-21 17:28:22 +00:00
|
|
|
return (kern_posix_fadvise(td, args->fd, offset, len, advice));
|
2011-12-29 15:34:59 +00:00
|
|
|
}
|
2015-05-24 15:43:53 +00:00
|
|
|
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
|
2012-04-16 21:22:02 +00:00
|
|
|
|
2018-06-15 14:41:51 +00:00
|
|
|
#ifdef LINUX_LEGACY_SYSCALLS
|
2012-04-16 21:22:02 +00:00
|
|
|
int
|
|
|
|
linux_pipe(struct thread *td, struct linux_pipe_args *args)
|
|
|
|
{
|
|
|
|
int fildes[2];
|
|
|
|
int error;
|
|
|
|
|
2015-07-29 17:18:27 +00:00
|
|
|
error = kern_pipe(td, fildes, 0, NULL, NULL);
|
2017-02-05 14:03:25 +00:00
|
|
|
if (error != 0)
|
2012-04-16 21:22:02 +00:00
|
|
|
return (error);
|
|
|
|
|
2017-02-05 14:03:25 +00:00
|
|
|
error = copyout(fildes, args->pipefds, sizeof(fildes));
|
|
|
|
if (error != 0) {
|
|
|
|
(void)kern_close(td, fildes[0]);
|
|
|
|
(void)kern_close(td, fildes[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
2012-04-16 21:22:02 +00:00
|
|
|
}
|
2018-06-15 14:41:51 +00:00
|
|
|
#endif
|
2012-04-16 21:22:02 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
linux_pipe2(struct thread *td, struct linux_pipe2_args *args)
|
|
|
|
{
|
|
|
|
int fildes[2];
|
|
|
|
int error, flags;
|
|
|
|
|
|
|
|
if ((args->flags & ~(LINUX_O_NONBLOCK | LINUX_O_CLOEXEC)) != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if ((args->flags & LINUX_O_NONBLOCK) != 0)
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
if ((args->flags & LINUX_O_CLOEXEC) != 0)
|
|
|
|
flags |= O_CLOEXEC;
|
2015-07-29 17:18:27 +00:00
|
|
|
error = kern_pipe(td, fildes, flags, NULL, NULL);
|
2017-02-05 14:03:25 +00:00
|
|
|
if (error != 0)
|
2012-04-16 21:22:02 +00:00
|
|
|
return (error);
|
|
|
|
|
2017-02-05 14:03:25 +00:00
|
|
|
error = copyout(fildes, args->pipefds, sizeof(fildes));
|
|
|
|
if (error != 0) {
|
|
|
|
(void)kern_close(td, fildes[0]);
|
|
|
|
(void)kern_close(td, fildes[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
2012-04-16 21:22:02 +00:00
|
|
|
}
|
2015-05-24 15:14:51 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
linux_dup3(struct thread *td, struct linux_dup3_args *args)
|
|
|
|
{
|
|
|
|
int cmd;
|
|
|
|
intptr_t newfd;
|
|
|
|
|
|
|
|
if (args->oldfd == args->newfd)
|
|
|
|
return (EINVAL);
|
|
|
|
if ((args->flags & ~LINUX_O_CLOEXEC) != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
if (args->flags & LINUX_O_CLOEXEC)
|
|
|
|
cmd = F_DUP2FD_CLOEXEC;
|
|
|
|
else
|
|
|
|
cmd = F_DUP2FD;
|
|
|
|
|
|
|
|
newfd = args->newfd;
|
|
|
|
return (kern_fcntl(td, args->oldfd, cmd, newfd));
|
|
|
|
}
|
2015-05-24 17:33:21 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
linux_fallocate(struct thread *td, struct linux_fallocate_args *args)
|
|
|
|
{
|
2020-01-21 17:28:22 +00:00
|
|
|
off_t len, offset;
|
2015-05-24 17:33:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We emulate only posix_fallocate system call for which
|
|
|
|
* mode should be 0.
|
|
|
|
*/
|
|
|
|
if (args->mode != 0)
|
2020-07-18 12:21:08 +00:00
|
|
|
return (EOPNOTSUPP);
|
2015-05-24 17:33:21 +00:00
|
|
|
|
2020-01-21 17:28:22 +00:00
|
|
|
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
|
|
|
len = PAIR32TO64(off_t, args->len);
|
|
|
|
offset = PAIR32TO64(off_t, args->offset);
|
|
|
|
#else
|
|
|
|
len = args->len;
|
|
|
|
offset = args->offset;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (kern_posix_fallocate(td, args->fd, offset, len));
|
2015-05-24 17:33:21 +00:00
|
|
|
}
|
2019-12-30 18:11:06 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
linux_copy_file_range(struct thread *td, struct linux_copy_file_range_args
|
|
|
|
*args)
|
|
|
|
{
|
|
|
|
l_loff_t inoff, outoff, *inoffp, *outoffp;
|
|
|
|
int error, flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy_file_range(2) on Linux doesn't define any flags (yet), so is
|
|
|
|
* the native implementation. Enforce it.
|
|
|
|
*/
|
|
|
|
if (args->flags != 0) {
|
|
|
|
linux_msg(td, "copy_file_range unsupported flags 0x%x",
|
|
|
|
args->flags);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
flags = 0;
|
|
|
|
inoffp = outoffp = NULL;
|
|
|
|
if (args->off_in != NULL) {
|
|
|
|
error = copyin(args->off_in, &inoff, sizeof(l_loff_t));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
inoffp = &inoff;
|
|
|
|
}
|
|
|
|
if (args->off_out != NULL) {
|
|
|
|
error = copyin(args->off_out, &outoff, sizeof(l_loff_t));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
outoffp = &outoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = kern_copy_file_range(td, args->fd_in, inoffp, args->fd_out,
|
|
|
|
outoffp, args->len, flags);
|
|
|
|
if (error == 0 && args->off_in != NULL)
|
|
|
|
error = copyout(inoffp, args->off_in, sizeof(l_loff_t));
|
|
|
|
if (error == 0 && args->off_out != NULL)
|
|
|
|
error = copyout(outoffp, args->off_out, sizeof(l_loff_t));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2020-06-29 03:09:14 +00:00
|
|
|
#define LINUX_MEMFD_PREFIX "memfd:"
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_memfd_create(struct thread *td, struct linux_memfd_create_args *args)
|
|
|
|
{
|
|
|
|
char memfd_name[LINUX_NAME_MAX + 1];
|
|
|
|
int error, flags, shmflags, oflags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is our clever trick to avoid the heap allocation to copy in the
|
|
|
|
* uname. We don't really need to go this far out of our way, but it
|
|
|
|
* does keep the rest of this function fairly clean as they don't have
|
|
|
|
* to worry about cleanup on the way out.
|
|
|
|
*/
|
|
|
|
error = copyinstr(args->uname_ptr,
|
|
|
|
memfd_name + sizeof(LINUX_MEMFD_PREFIX) - 1,
|
|
|
|
LINUX_NAME_MAX - sizeof(LINUX_MEMFD_PREFIX) - 1, NULL);
|
|
|
|
if (error != 0) {
|
|
|
|
if (error == ENAMETOOLONG)
|
|
|
|
error = EINVAL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(memfd_name, LINUX_MEMFD_PREFIX, sizeof(LINUX_MEMFD_PREFIX) - 1);
|
|
|
|
flags = linux_to_bsd_bits(args->flags, mfd_bitmap, 0);
|
|
|
|
if ((flags & ~(MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB |
|
|
|
|
MFD_HUGE_MASK)) != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
/* Size specified but no HUGETLB. */
|
|
|
|
if ((flags & MFD_HUGE_MASK) != 0 && (flags & MFD_HUGETLB) == 0)
|
|
|
|
return (EINVAL);
|
|
|
|
/* We don't actually support HUGETLB. */
|
|
|
|
if ((flags & MFD_HUGETLB) != 0)
|
|
|
|
return (ENOSYS);
|
|
|
|
oflags = O_RDWR;
|
2020-07-10 00:45:16 +00:00
|
|
|
shmflags = SHM_GROW_ON_WRITE;
|
2020-06-29 03:09:14 +00:00
|
|
|
if ((flags & MFD_CLOEXEC) != 0)
|
|
|
|
oflags |= O_CLOEXEC;
|
|
|
|
if ((flags & MFD_ALLOW_SEALING) != 0)
|
|
|
|
shmflags |= SHM_ALLOW_SEALING;
|
|
|
|
return (kern_shm_open2(td, SHM_ANON, oflags, 0, shmflags, NULL,
|
|
|
|
memfd_name));
|
|
|
|
}
|
2020-07-18 11:28:40 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
linux_splice(struct thread *td, struct linux_splice_args *args)
|
|
|
|
{
|
|
|
|
|
|
|
|
linux_msg(td, "syscall splice not really implemented");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* splice(2) is documented to return EINVAL in various circumstances;
|
|
|
|
* returning it instead of ENOSYS should hint the caller to use fallback
|
|
|
|
* instead.
|
|
|
|
*/
|
|
|
|
return (EINVAL);
|
|
|
|
}
|