2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1994-1995 Søren Schmidt
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_compat.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/capsicum.h>
38 #include <sys/dirent.h>
39 #include <sys/fcntl.h>
41 #include <sys/filedesc.h>
43 #include <sys/malloc.h>
45 #include <sys/mount.h>
46 #include <sys/mutex.h>
47 #include <sys/namei.h>
51 #include <sys/syscallsubr.h>
52 #include <sys/sysproto.h>
54 #include <sys/unistd.h>
55 #include <sys/vnode.h>
58 #include <compat/freebsd32/freebsd32_misc.h>
59 #include <machine/../linux32/linux.h>
60 #include <machine/../linux32/linux32_proto.h>
62 #include <machine/../linux/linux.h>
63 #include <machine/../linux/linux_proto.h>
65 #include <compat/linux/linux_misc.h>
66 #include <compat/linux/linux_util.h>
67 #include <compat/linux/linux_file.h>
69 static int linux_common_open(struct thread *, int, const char *, int, int,
71 static int linux_getdents_error(struct thread *, int, int);
73 static struct bsd_to_linux_bitmap seal_bitmap[] = {
74 BITMAP_1t1_LINUX(F_SEAL_SEAL),
75 BITMAP_1t1_LINUX(F_SEAL_SHRINK),
76 BITMAP_1t1_LINUX(F_SEAL_GROW),
77 BITMAP_1t1_LINUX(F_SEAL_WRITE),
80 #define MFD_HUGETLB_ENTRY(_size) \
82 .bsd_value = MFD_HUGE_##_size, \
83 .linux_value = LINUX_HUGETLB_FLAG_ENCODE_##_size \
85 static struct bsd_to_linux_bitmap mfd_bitmap[] = {
86 BITMAP_1t1_LINUX(MFD_CLOEXEC),
87 BITMAP_1t1_LINUX(MFD_ALLOW_SEALING),
88 BITMAP_1t1_LINUX(MFD_HUGETLB),
89 MFD_HUGETLB_ENTRY(64KB),
90 MFD_HUGETLB_ENTRY(512KB),
91 MFD_HUGETLB_ENTRY(1MB),
92 MFD_HUGETLB_ENTRY(2MB),
93 MFD_HUGETLB_ENTRY(8MB),
94 MFD_HUGETLB_ENTRY(16MB),
95 MFD_HUGETLB_ENTRY(32MB),
96 MFD_HUGETLB_ENTRY(256MB),
97 MFD_HUGETLB_ENTRY(512MB),
98 MFD_HUGETLB_ENTRY(1GB),
99 MFD_HUGETLB_ENTRY(2GB),
100 MFD_HUGETLB_ENTRY(16GB),
102 #undef MFD_HUGETLB_ENTRY
104 #ifdef LINUX_LEGACY_SYSCALLS
106 linux_creat(struct thread *td, struct linux_creat_args *args)
111 if (!LUSECONVPATH(td)) {
112 error = kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
113 O_WRONLY | O_CREAT | O_TRUNC, args->mode);
115 LCONVPATHEXIST(td, args->path, &path);
116 error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
117 O_WRONLY | O_CREAT | O_TRUNC, args->mode);
125 linux_common_open(struct thread *td, int dirfd, const char *path, int l_flags,
126 int mode, enum uio_seg seg)
128 struct proc *p = td->td_proc;
131 int bsd_flags, error;
134 switch (l_flags & LINUX_O_ACCMODE) {
136 bsd_flags |= O_WRONLY;
142 bsd_flags |= O_RDONLY;
144 if (l_flags & LINUX_O_NDELAY)
145 bsd_flags |= O_NONBLOCK;
146 if (l_flags & LINUX_O_APPEND)
147 bsd_flags |= O_APPEND;
148 if (l_flags & LINUX_O_SYNC)
149 bsd_flags |= O_FSYNC;
150 if (l_flags & LINUX_O_CLOEXEC)
151 bsd_flags |= O_CLOEXEC;
152 if (l_flags & LINUX_O_NONBLOCK)
153 bsd_flags |= O_NONBLOCK;
154 if (l_flags & LINUX_O_ASYNC)
155 bsd_flags |= O_ASYNC;
156 if (l_flags & LINUX_O_CREAT)
157 bsd_flags |= O_CREAT;
158 if (l_flags & LINUX_O_TRUNC)
159 bsd_flags |= O_TRUNC;
160 if (l_flags & LINUX_O_EXCL)
162 if (l_flags & LINUX_O_NOCTTY)
163 bsd_flags |= O_NOCTTY;
164 if (l_flags & LINUX_O_DIRECT)
165 bsd_flags |= O_DIRECT;
166 if (l_flags & LINUX_O_NOFOLLOW)
167 bsd_flags |= O_NOFOLLOW;
168 if (l_flags & LINUX_O_DIRECTORY)
169 bsd_flags |= O_DIRECTORY;
170 /* XXX LINUX_O_NOATIME: unable to be easily implemented. */
172 error = kern_openat(td, dirfd, path, seg, bsd_flags, mode);
178 if (p->p_flag & P_CONTROLT)
180 if (bsd_flags & O_NOCTTY)
184 * XXX In between kern_openat() and fget(), another process
185 * having the same filedesc could use that fd without
188 fd = td->td_retval[0];
189 if (fget(td, fd, &cap_ioctl_rights, &fp) == 0) {
190 if (fp->f_type != DTYPE_VNODE) {
194 sx_slock(&proctree_lock);
196 if (SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
198 sx_sunlock(&proctree_lock);
199 /* XXXPJD: Verify if TIOCSCTTY is allowed. */
200 (void) fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0,
204 sx_sunlock(&proctree_lock);
214 linux_openat(struct thread *td, struct linux_openat_args *args)
219 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
220 if (!LUSECONVPATH(td)) {
221 return (linux_common_open(td, dfd, args->filename, args->flags,
222 args->mode, UIO_USERSPACE));
224 if (args->flags & LINUX_O_CREAT)
225 LCONVPATH_AT(td, args->filename, &path, 1, dfd);
227 LCONVPATH_AT(td, args->filename, &path, 0, dfd);
229 error = linux_common_open(td, dfd, path, args->flags, args->mode,
235 #ifdef LINUX_LEGACY_SYSCALLS
237 linux_open(struct thread *td, struct linux_open_args *args)
242 if (!LUSECONVPATH(td)) {
243 return (linux_common_open(td, AT_FDCWD, args->path, args->flags,
244 args->mode, UIO_USERSPACE));
246 if (args->flags & LINUX_O_CREAT)
247 LCONVPATHCREAT(td, args->path, &path);
249 LCONVPATHEXIST(td, args->path, &path);
251 error = linux_common_open(td, AT_FDCWD, path, args->flags, args->mode,
259 linux_lseek(struct thread *td, struct linux_lseek_args *args)
262 return (kern_lseek(td, args->fdes, args->off, args->whence));
265 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
267 linux_llseek(struct thread *td, struct linux_llseek_args *args)
272 off = (args->olow) | (((off_t) args->ohigh) << 32);
274 error = kern_lseek(td, args->fd, off, args->whence);
278 error = copyout(td->td_retval, args->res, sizeof(off_t));
282 td->td_retval[0] = 0;
285 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
288 * Note that linux_getdents(2) and linux_getdents64(2) have the same
289 * arguments. They only differ in the definition of struct dirent they
291 * Note that linux_readdir(2) is a special case of linux_getdents(2)
292 * where count is always equals 1, meaning that the buffer is one
293 * dirent-structure in size and that the code can't handle more anyway.
294 * Note that linux_readdir(2) can't be implemented by means of linux_getdents(2)
295 * as in case when the *dent buffer size is equal to 1 linux_getdents(2) will
300 linux_getdents_error(struct thread *td, int fd, int err)
306 /* Linux return ENOTDIR in case when fd is not a directory. */
307 error = getvnode(td, fd, &cap_read_rights, &fp);
311 if (vp->v_type != VDIR) {
323 char d_name[LINUX_NAME_MAX + 1];
331 char d_name[LINUX_NAME_MAX + 1];
335 * Linux uses the last byte in the dirent buffer to store d_type,
336 * at least glibc-2.7 requires it. That is why l_dirent is padded with 2 bytes.
338 #define LINUX_RECLEN(namlen) \
339 roundup(offsetof(struct l_dirent, d_name) + (namlen) + 2, sizeof(l_ulong))
341 #define LINUX_RECLEN64(namlen) \
342 roundup(offsetof(struct l_dirent64, d_name) + (namlen) + 1, \
345 #ifdef LINUX_LEGACY_SYSCALLS
347 linux_getdents(struct thread *td, struct linux_getdents_args *args)
350 caddr_t inp, buf; /* BSD-format */
351 int len, reclen; /* BSD-format */
352 caddr_t outp; /* Linux-format */
353 int resid, linuxreclen; /* Linux-format */
354 caddr_t lbuf; /* Linux-format */
356 struct l_dirent *linux_dirent;
360 buflen = min(args->count, MAXBSIZE);
361 buf = malloc(buflen, M_TEMP, M_WAITOK);
363 error = kern_getdirentries(td, args->fd, buf, buflen,
364 &base, NULL, UIO_SYSSPACE);
366 error = linux_getdents_error(td, args->fd, error);
370 lbuf = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
372 len = td->td_retval[0];
374 outp = (caddr_t)args->dent;
379 bdp = (struct dirent *) inp;
380 reclen = bdp->d_reclen;
381 linuxreclen = LINUX_RECLEN(bdp->d_namlen);
383 * No more space in the user supplied dirent buffer.
386 if (resid < linuxreclen) {
391 linux_dirent = (struct l_dirent*)lbuf;
392 linux_dirent->d_ino = bdp->d_fileno;
393 linux_dirent->d_off = base + reclen;
394 linux_dirent->d_reclen = linuxreclen;
396 * Copy d_type to last byte of l_dirent buffer
398 lbuf[linuxreclen - 1] = bdp->d_type;
399 strlcpy(linux_dirent->d_name, bdp->d_name,
400 linuxreclen - offsetof(struct l_dirent, d_name)-1);
401 error = copyout(linux_dirent, outp, linuxreclen);
409 retval += linuxreclen;
411 resid -= linuxreclen;
413 td->td_retval[0] = retval;
424 linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
427 caddr_t inp, buf; /* BSD-format */
428 int len, reclen; /* BSD-format */
429 caddr_t outp; /* Linux-format */
430 int resid, linuxreclen; /* Linux-format */
431 caddr_t lbuf; /* Linux-format */
433 struct l_dirent64 *linux_dirent64;
437 buflen = min(args->count, MAXBSIZE);
438 buf = malloc(buflen, M_TEMP, M_WAITOK);
440 error = kern_getdirentries(td, args->fd, buf, buflen,
441 &base, NULL, UIO_SYSSPACE);
443 error = linux_getdents_error(td, args->fd, error);
447 lbuf = malloc(LINUX_RECLEN64(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
449 len = td->td_retval[0];
451 outp = (caddr_t)args->dirent;
456 bdp = (struct dirent *) inp;
457 reclen = bdp->d_reclen;
458 linuxreclen = LINUX_RECLEN64(bdp->d_namlen);
460 * No more space in the user supplied dirent buffer.
463 if (resid < linuxreclen) {
468 linux_dirent64 = (struct l_dirent64*)lbuf;
469 linux_dirent64->d_ino = bdp->d_fileno;
470 linux_dirent64->d_off = base + reclen;
471 linux_dirent64->d_reclen = linuxreclen;
472 linux_dirent64->d_type = bdp->d_type;
473 strlcpy(linux_dirent64->d_name, bdp->d_name,
474 linuxreclen - offsetof(struct l_dirent64, d_name));
475 error = copyout(linux_dirent64, outp, linuxreclen);
483 retval += linuxreclen;
485 resid -= linuxreclen;
487 td->td_retval[0] = retval;
496 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
498 linux_readdir(struct thread *td, struct linux_readdir_args *args)
501 caddr_t buf; /* BSD-format */
502 int linuxreclen; /* Linux-format */
503 caddr_t lbuf; /* Linux-format */
505 struct l_dirent *linux_dirent;
508 buflen = LINUX_RECLEN(LINUX_NAME_MAX);
509 buf = malloc(buflen, M_TEMP, M_WAITOK);
511 error = kern_getdirentries(td, args->fd, buf, buflen,
512 &base, NULL, UIO_SYSSPACE);
514 error = linux_getdents_error(td, args->fd, error);
517 if (td->td_retval[0] == 0)
520 lbuf = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
522 bdp = (struct dirent *) buf;
523 linuxreclen = LINUX_RECLEN(bdp->d_namlen);
525 linux_dirent = (struct l_dirent*)lbuf;
526 linux_dirent->d_ino = bdp->d_fileno;
527 linux_dirent->d_off = linuxreclen;
528 linux_dirent->d_reclen = bdp->d_namlen;
529 strlcpy(linux_dirent->d_name, bdp->d_name,
530 linuxreclen - offsetof(struct l_dirent, d_name));
531 error = copyout(linux_dirent, args->dent, linuxreclen);
533 td->td_retval[0] = linuxreclen;
540 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
543 * These exist mainly for hooks for doing /compat/linux translation.
546 #ifdef LINUX_LEGACY_SYSCALLS
548 linux_access(struct thread *td, struct linux_access_args *args)
553 /* Linux convention. */
554 if (args->amode & ~(F_OK | X_OK | W_OK | R_OK))
557 if (!LUSECONVPATH(td)) {
558 error = kern_accessat(td, AT_FDCWD, args->path, UIO_USERSPACE, 0,
561 LCONVPATHEXIST(td, args->path, &path);
562 error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
572 linux_faccessat(struct thread *td, struct linux_faccessat_args *args)
577 /* Linux convention. */
578 if (args->amode & ~(F_OK | X_OK | W_OK | R_OK))
581 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
582 if (!LUSECONVPATH(td)) {
583 error = kern_accessat(td, dfd, args->filename, UIO_USERSPACE, 0, args->amode);
585 LCONVPATHEXIST_AT(td, args->filename, &path, dfd);
586 error = kern_accessat(td, dfd, path, UIO_SYSSPACE, 0, args->amode);
593 #ifdef LINUX_LEGACY_SYSCALLS
595 linux_unlink(struct thread *td, struct linux_unlink_args *args)
601 if (!LUSECONVPATH(td)) {
602 error = kern_funlinkat(td, AT_FDCWD, args->path, FD_NONE,
603 UIO_USERSPACE, 0, 0);
604 if (error == EPERM) {
605 /* Introduce POSIX noncompliant behaviour of Linux */
606 if (kern_statat(td, 0, AT_FDCWD, args->path,
607 UIO_SYSSPACE, &st, NULL) == 0) {
608 if (S_ISDIR(st.st_mode))
613 LCONVPATHEXIST(td, args->path, &path);
614 error = kern_funlinkat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0, 0);
615 if (error == EPERM) {
616 /* Introduce POSIX noncompliant behaviour of Linux */
617 if (kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st,
619 if (S_ISDIR(st.st_mode))
631 linux_unlinkat(struct thread *td, struct linux_unlinkat_args *args)
637 if (args->flag & ~LINUX_AT_REMOVEDIR)
640 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
641 LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
643 if (args->flag & LINUX_AT_REMOVEDIR)
644 error = kern_frmdirat(td, dfd, path, FD_NONE, UIO_SYSSPACE, 0);
646 error = kern_funlinkat(td, dfd, path, FD_NONE, UIO_SYSSPACE, 0,
648 if (error == EPERM && !(args->flag & LINUX_AT_REMOVEDIR)) {
649 /* Introduce POSIX noncompliant behaviour of Linux */
650 if (kern_statat(td, AT_SYMLINK_NOFOLLOW, dfd, path,
651 UIO_SYSSPACE, &st, NULL) == 0 && S_ISDIR(st.st_mode))
658 linux_chdir(struct thread *td, struct linux_chdir_args *args)
663 LCONVPATHEXIST(td, args->path, &path);
665 error = kern_chdir(td, path, UIO_SYSSPACE);
670 #ifdef LINUX_LEGACY_SYSCALLS
672 linux_chmod(struct thread *td, struct linux_chmod_args *args)
677 LCONVPATHEXIST(td, args->path, &path);
679 error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE,
687 linux_fchmodat(struct thread *td, struct linux_fchmodat_args *args)
692 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
693 LCONVPATHEXIST_AT(td, args->filename, &path, dfd);
695 error = kern_fchmodat(td, dfd, path, UIO_SYSSPACE, args->mode, 0);
700 #ifdef LINUX_LEGACY_SYSCALLS
702 linux_mkdir(struct thread *td, struct linux_mkdir_args *args)
707 LCONVPATHCREAT(td, args->path, &path);
709 error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode);
716 linux_mkdirat(struct thread *td, struct linux_mkdirat_args *args)
721 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
722 LCONVPATHCREAT_AT(td, args->pathname, &path, dfd);
724 error = kern_mkdirat(td, dfd, path, UIO_SYSSPACE, args->mode);
729 #ifdef LINUX_LEGACY_SYSCALLS
731 linux_rmdir(struct thread *td, struct linux_rmdir_args *args)
736 LCONVPATHEXIST(td, args->path, &path);
738 error = kern_frmdirat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0);
744 linux_rename(struct thread *td, struct linux_rename_args *args)
749 LCONVPATHEXIST(td, args->from, &from);
750 /* Expand LCONVPATHCREATE so that `from' can be freed on errors */
751 error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
757 error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
765 linux_renameat(struct thread *td, struct linux_renameat_args *args)
767 struct linux_renameat2_args renameat2_args = {
768 .olddfd = args->olddfd,
769 .oldname = args->oldname,
770 .newdfd = args->newdfd,
771 .newname = args->newname,
775 return (linux_renameat2(td, &renameat2_args));
779 linux_renameat2(struct thread *td, struct linux_renameat2_args *args)
782 int error, olddfd, newdfd;
784 if (args->flags != 0) {
785 if (args->flags & ~(LINUX_RENAME_EXCHANGE |
786 LINUX_RENAME_NOREPLACE | LINUX_RENAME_WHITEOUT))
788 if (args->flags & LINUX_RENAME_EXCHANGE &&
789 args->flags & (LINUX_RENAME_NOREPLACE |
790 LINUX_RENAME_WHITEOUT))
792 linux_msg(td, "renameat2 unsupported flags 0x%x",
797 olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
798 newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
799 LCONVPATHEXIST_AT(td, args->oldname, &from, olddfd);
800 /* Expand LCONVPATHCREATE so that `from' can be freed on errors */
801 error = linux_emul_convpath(td, args->newname, UIO_USERSPACE, &to, 1, newdfd);
807 error = kern_renameat(td, olddfd, from, newdfd, to, UIO_SYSSPACE);
813 #ifdef LINUX_LEGACY_SYSCALLS
815 linux_symlink(struct thread *td, struct linux_symlink_args *args)
820 LCONVPATHEXIST(td, args->path, &path);
821 /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
822 error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
828 error = kern_symlinkat(td, path, AT_FDCWD, to, UIO_SYSSPACE);
836 linux_symlinkat(struct thread *td, struct linux_symlinkat_args *args)
841 dfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
842 LCONVPATHEXIST(td, args->oldname, &path);
843 /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
844 error = linux_emul_convpath(td, args->newname, UIO_USERSPACE, &to, 1, dfd);
850 error = kern_symlinkat(td, path, dfd, to, UIO_SYSSPACE);
856 #ifdef LINUX_LEGACY_SYSCALLS
858 linux_readlink(struct thread *td, struct linux_readlink_args *args)
863 LCONVPATHEXIST(td, args->name, &name);
865 error = kern_readlinkat(td, AT_FDCWD, name, UIO_SYSSPACE,
866 args->buf, UIO_USERSPACE, args->count);
873 linux_readlinkat(struct thread *td, struct linux_readlinkat_args *args)
878 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
879 LCONVPATHEXIST_AT(td, args->path, &name, dfd);
881 error = kern_readlinkat(td, dfd, name, UIO_SYSSPACE, args->buf,
882 UIO_USERSPACE, args->bufsiz);
888 linux_truncate(struct thread *td, struct linux_truncate_args *args)
893 LCONVPATHEXIST(td, args->path, &path);
894 error = kern_truncate(td, path, UIO_SYSSPACE, args->length);
899 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
901 linux_truncate64(struct thread *td, struct linux_truncate64_args *args)
907 #if defined(__amd64__) && defined(COMPAT_LINUX32)
908 length = PAIR32TO64(off_t, args->length);
910 length = args->length;
913 LCONVPATHEXIST(td, args->path, &path);
914 error = kern_truncate(td, path, UIO_SYSSPACE, length);
918 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
921 linux_ftruncate(struct thread *td, struct linux_ftruncate_args *args)
924 return (kern_ftruncate(td, args->fd, args->length));
927 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
929 linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
933 #if defined(__amd64__) && defined(COMPAT_LINUX32)
934 length = PAIR32TO64(off_t, args->length);
936 length = args->length;
939 return (kern_ftruncate(td, args->fd, length));
943 #ifdef LINUX_LEGACY_SYSCALLS
945 linux_link(struct thread *td, struct linux_link_args *args)
950 LCONVPATHEXIST(td, args->path, &path);
951 /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
952 error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
958 error = kern_linkat(td, AT_FDCWD, AT_FDCWD, path, to, UIO_SYSSPACE,
967 linux_linkat(struct thread *td, struct linux_linkat_args *args)
970 int error, olddfd, newdfd, follow;
972 if (args->flag & ~LINUX_AT_SYMLINK_FOLLOW)
975 olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
976 newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
977 LCONVPATHEXIST_AT(td, args->oldname, &path, olddfd);
978 /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
979 error = linux_emul_convpath(td, args->newname, UIO_USERSPACE, &to, 1, newdfd);
985 follow = (args->flag & LINUX_AT_SYMLINK_FOLLOW) == 0 ? NOFOLLOW :
987 error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, follow);
994 linux_fdatasync(struct thread *td, struct linux_fdatasync_args *uap)
997 return (kern_fsync(td, uap->fd, false));
1001 linux_sync_file_range(struct thread *td, struct linux_sync_file_range_args *uap)
1003 off_t nbytes, offset;
1005 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1006 nbytes = PAIR32TO64(off_t, uap->nbytes);
1007 offset = PAIR32TO64(off_t, uap->offset);
1009 nbytes = uap->nbytes;
1010 offset = uap->offset;
1013 if (offset < 0 || nbytes < 0 ||
1014 (uap->flags & ~(LINUX_SYNC_FILE_RANGE_WAIT_BEFORE |
1015 LINUX_SYNC_FILE_RANGE_WRITE |
1016 LINUX_SYNC_FILE_RANGE_WAIT_AFTER)) != 0) {
1020 return (kern_fsync(td, uap->fd, false));
1024 linux_pread(struct thread *td, struct linux_pread_args *uap)
1030 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1031 offset = PAIR32TO64(off_t, uap->offset);
1033 offset = uap->offset;
1036 error = kern_pread(td, uap->fd, uap->buf, uap->nbyte, offset);
1038 /* This seems to violate POSIX but Linux does it. */
1039 error = fgetvp(td, uap->fd, &cap_pread_rights, &vp);
1042 if (vp->v_type == VDIR)
1050 linux_pwrite(struct thread *td, struct linux_pwrite_args *uap)
1054 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1055 offset = PAIR32TO64(off_t, uap->offset);
1057 offset = uap->offset;
1060 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, offset));
1064 linux_preadv(struct thread *td, struct linux_preadv_args *uap)
1071 * According http://man7.org/linux/man-pages/man2/preadv.2.html#NOTES
1072 * pos_l and pos_h, respectively, contain the
1073 * low order and high order 32 bits of offset.
1075 offset = (((off_t)uap->pos_h << (sizeof(offset) * 4)) <<
1076 (sizeof(offset) * 4)) | uap->pos_l;
1079 #ifdef COMPAT_LINUX32
1080 error = linux32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
1082 error = copyinuio(uap->vec, uap->vlen, &auio);
1086 error = kern_preadv(td, uap->fd, auio, offset);
1092 linux_pwritev(struct thread *td, struct linux_pwritev_args *uap)
1099 * According http://man7.org/linux/man-pages/man2/pwritev.2.html#NOTES
1100 * pos_l and pos_h, respectively, contain the
1101 * low order and high order 32 bits of offset.
1103 offset = (((off_t)uap->pos_h << (sizeof(offset) * 4)) <<
1104 (sizeof(offset) * 4)) | uap->pos_l;
1107 #ifdef COMPAT_LINUX32
1108 error = linux32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
1110 error = copyinuio(uap->vec, uap->vlen, &auio);
1114 error = kern_pwritev(td, uap->fd, auio, offset);
1120 linux_mount(struct thread *td, struct linux_mount_args *args)
1122 char fstypename[MFSNAMELEN];
1123 char *mntonname, *mntfromname;
1126 mntonname = malloc(MNAMELEN, M_TEMP, M_WAITOK);
1127 mntfromname = malloc(MNAMELEN, M_TEMP, M_WAITOK);
1128 error = copyinstr(args->filesystemtype, fstypename, MFSNAMELEN - 1,
1132 if (args->specialfile != NULL) {
1133 error = copyinstr(args->specialfile, mntfromname, MNAMELEN - 1, NULL);
1137 mntfromname[0] = '\0';
1139 error = copyinstr(args->dir, mntonname, MNAMELEN - 1, NULL);
1143 if (strcmp(fstypename, "ext2") == 0) {
1144 strcpy(fstypename, "ext2fs");
1145 } else if (strcmp(fstypename, "proc") == 0) {
1146 strcpy(fstypename, "linprocfs");
1147 } else if (strcmp(fstypename, "vfat") == 0) {
1148 strcpy(fstypename, "msdosfs");
1154 * Linux SYNC flag is not included; the closest equivalent
1155 * FreeBSD has is !ASYNC, which is our default.
1157 if (args->rwflag & LINUX_MS_RDONLY)
1158 fsflags |= MNT_RDONLY;
1159 if (args->rwflag & LINUX_MS_NOSUID)
1160 fsflags |= MNT_NOSUID;
1161 if (args->rwflag & LINUX_MS_NOEXEC)
1162 fsflags |= MNT_NOEXEC;
1163 if (args->rwflag & LINUX_MS_REMOUNT)
1164 fsflags |= MNT_UPDATE;
1166 error = kernel_vmount(fsflags,
1167 "fstype", fstypename,
1168 "fspath", mntonname,
1169 "from", mntfromname,
1172 free(mntonname, M_TEMP);
1173 free(mntfromname, M_TEMP);
1177 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
1179 linux_oldumount(struct thread *td, struct linux_oldumount_args *args)
1182 return (kern_unmount(td, args->path, 0));
1184 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
1186 #ifdef LINUX_LEGACY_SYSCALLS
1188 linux_umount(struct thread *td, struct linux_umount_args *args)
1193 if ((args->flags & LINUX_MNT_FORCE) != 0) {
1194 args->flags &= ~LINUX_MNT_FORCE;
1197 if (args->flags != 0) {
1198 linux_msg(td, "unsupported umount2 flags %#x", args->flags);
1202 return (kern_unmount(td, args->path, flags));
1207 * fcntl family of syscalls
1217 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1223 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
1225 switch (linux_flock->l_type) {
1227 bsd_flock->l_type = F_RDLCK;
1230 bsd_flock->l_type = F_WRLCK;
1233 bsd_flock->l_type = F_UNLCK;
1236 bsd_flock->l_type = -1;
1239 bsd_flock->l_whence = linux_flock->l_whence;
1240 bsd_flock->l_start = (off_t)linux_flock->l_start;
1241 bsd_flock->l_len = (off_t)linux_flock->l_len;
1242 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
1243 bsd_flock->l_sysid = 0;
1247 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
1249 switch (bsd_flock->l_type) {
1251 linux_flock->l_type = LINUX_F_RDLCK;
1254 linux_flock->l_type = LINUX_F_WRLCK;
1257 linux_flock->l_type = LINUX_F_UNLCK;
1260 linux_flock->l_whence = bsd_flock->l_whence;
1261 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
1262 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
1263 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
1266 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
1274 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1280 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
1282 switch (linux_flock->l_type) {
1284 bsd_flock->l_type = F_RDLCK;
1287 bsd_flock->l_type = F_WRLCK;
1290 bsd_flock->l_type = F_UNLCK;
1293 bsd_flock->l_type = -1;
1296 bsd_flock->l_whence = linux_flock->l_whence;
1297 bsd_flock->l_start = (off_t)linux_flock->l_start;
1298 bsd_flock->l_len = (off_t)linux_flock->l_len;
1299 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
1300 bsd_flock->l_sysid = 0;
1304 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
1306 switch (bsd_flock->l_type) {
1308 linux_flock->l_type = LINUX_F_RDLCK;
1311 linux_flock->l_type = LINUX_F_WRLCK;
1314 linux_flock->l_type = LINUX_F_UNLCK;
1317 linux_flock->l_whence = bsd_flock->l_whence;
1318 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
1319 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
1320 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
1322 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
1325 fcntl_common(struct thread *td, struct linux_fcntl_args *args)
1327 struct l_flock linux_flock;
1328 struct flock bsd_flock;
1333 switch (args->cmd) {
1335 return (kern_fcntl(td, args->fd, F_DUPFD, args->arg));
1338 return (kern_fcntl(td, args->fd, F_GETFD, 0));
1341 return (kern_fcntl(td, args->fd, F_SETFD, args->arg));
1344 error = kern_fcntl(td, args->fd, F_GETFL, 0);
1345 result = td->td_retval[0];
1346 td->td_retval[0] = 0;
1347 if (result & O_RDONLY)
1348 td->td_retval[0] |= LINUX_O_RDONLY;
1349 if (result & O_WRONLY)
1350 td->td_retval[0] |= LINUX_O_WRONLY;
1351 if (result & O_RDWR)
1352 td->td_retval[0] |= LINUX_O_RDWR;
1353 if (result & O_NDELAY)
1354 td->td_retval[0] |= LINUX_O_NONBLOCK;
1355 if (result & O_APPEND)
1356 td->td_retval[0] |= LINUX_O_APPEND;
1357 if (result & O_FSYNC)
1358 td->td_retval[0] |= LINUX_O_SYNC;
1359 if (result & O_ASYNC)
1360 td->td_retval[0] |= LINUX_O_ASYNC;
1361 #ifdef LINUX_O_NOFOLLOW
1362 if (result & O_NOFOLLOW)
1363 td->td_retval[0] |= LINUX_O_NOFOLLOW;
1365 #ifdef LINUX_O_DIRECT
1366 if (result & O_DIRECT)
1367 td->td_retval[0] |= LINUX_O_DIRECT;
1373 if (args->arg & LINUX_O_NDELAY)
1375 if (args->arg & LINUX_O_APPEND)
1377 if (args->arg & LINUX_O_SYNC)
1379 if (args->arg & LINUX_O_ASYNC)
1381 #ifdef LINUX_O_NOFOLLOW
1382 if (args->arg & LINUX_O_NOFOLLOW)
1385 #ifdef LINUX_O_DIRECT
1386 if (args->arg & LINUX_O_DIRECT)
1389 return (kern_fcntl(td, args->fd, F_SETFL, arg));
1392 error = copyin((void *)args->arg, &linux_flock,
1393 sizeof(linux_flock));
1396 linux_to_bsd_flock(&linux_flock, &bsd_flock);
1397 error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock);
1400 bsd_to_linux_flock(&bsd_flock, &linux_flock);
1401 return (copyout(&linux_flock, (void *)args->arg,
1402 sizeof(linux_flock)));
1405 error = copyin((void *)args->arg, &linux_flock,
1406 sizeof(linux_flock));
1409 linux_to_bsd_flock(&linux_flock, &bsd_flock);
1410 return (kern_fcntl(td, args->fd, F_SETLK,
1411 (intptr_t)&bsd_flock));
1413 case LINUX_F_SETLKW:
1414 error = copyin((void *)args->arg, &linux_flock,
1415 sizeof(linux_flock));
1418 linux_to_bsd_flock(&linux_flock, &bsd_flock);
1419 return (kern_fcntl(td, args->fd, F_SETLKW,
1420 (intptr_t)&bsd_flock));
1422 case LINUX_F_GETOWN:
1423 return (kern_fcntl(td, args->fd, F_GETOWN, 0));
1425 case LINUX_F_SETOWN:
1427 * XXX some Linux applications depend on F_SETOWN having no
1428 * significant effect for pipes (SIGIO is not delivered for
1429 * pipes under Linux-2.2.35 at least).
1431 error = fget(td, args->fd,
1432 &cap_fcntl_rights, &fp);
1435 if (fp->f_type == DTYPE_PIPE) {
1441 return (kern_fcntl(td, args->fd, F_SETOWN, args->arg));
1443 case LINUX_F_DUPFD_CLOEXEC:
1444 return (kern_fcntl(td, args->fd, F_DUPFD_CLOEXEC, args->arg));
1446 * Our F_SEAL_* values match Linux one for maximum compatibility. So we
1447 * only needed to account for different values for fcntl(2) commands.
1449 case LINUX_F_GET_SEALS:
1450 error = kern_fcntl(td, args->fd, F_GET_SEALS, 0);
1453 td->td_retval[0] = bsd_to_linux_bits(td->td_retval[0],
1457 case LINUX_F_ADD_SEALS:
1458 return (kern_fcntl(td, args->fd, F_ADD_SEALS,
1459 linux_to_bsd_bits(args->arg, seal_bitmap, 0)));
1461 linux_msg(td, "unsupported fcntl cmd %d\n", args->cmd);
1467 linux_fcntl(struct thread *td, struct linux_fcntl_args *args)
1470 return (fcntl_common(td, args));
1473 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
1475 linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args)
1477 struct l_flock64 linux_flock;
1478 struct flock bsd_flock;
1479 struct linux_fcntl_args fcntl_args;
1482 switch (args->cmd) {
1483 case LINUX_F_GETLK64:
1484 error = copyin((void *)args->arg, &linux_flock,
1485 sizeof(linux_flock));
1488 linux_to_bsd_flock64(&linux_flock, &bsd_flock);
1489 error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock);
1492 bsd_to_linux_flock64(&bsd_flock, &linux_flock);
1493 return (copyout(&linux_flock, (void *)args->arg,
1494 sizeof(linux_flock)));
1496 case LINUX_F_SETLK64:
1497 error = copyin((void *)args->arg, &linux_flock,
1498 sizeof(linux_flock));
1501 linux_to_bsd_flock64(&linux_flock, &bsd_flock);
1502 return (kern_fcntl(td, args->fd, F_SETLK,
1503 (intptr_t)&bsd_flock));
1505 case LINUX_F_SETLKW64:
1506 error = copyin((void *)args->arg, &linux_flock,
1507 sizeof(linux_flock));
1510 linux_to_bsd_flock64(&linux_flock, &bsd_flock);
1511 return (kern_fcntl(td, args->fd, F_SETLKW,
1512 (intptr_t)&bsd_flock));
1515 fcntl_args.fd = args->fd;
1516 fcntl_args.cmd = args->cmd;
1517 fcntl_args.arg = args->arg;
1518 return (fcntl_common(td, &fcntl_args));
1520 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
1522 #ifdef LINUX_LEGACY_SYSCALLS
1524 linux_chown(struct thread *td, struct linux_chown_args *args)
1529 LCONVPATHEXIST(td, args->path, &path);
1531 error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid,
1539 linux_fchownat(struct thread *td, struct linux_fchownat_args *args)
1542 int error, dfd, flag;
1544 if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW)
1547 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
1548 LCONVPATHEXIST_AT(td, args->filename, &path, dfd);
1550 flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) == 0 ? 0 :
1551 AT_SYMLINK_NOFOLLOW;
1552 error = kern_fchownat(td, dfd, path, UIO_SYSSPACE, args->uid, args->gid,
1558 #ifdef LINUX_LEGACY_SYSCALLS
1560 linux_lchown(struct thread *td, struct linux_lchown_args *args)
1565 LCONVPATHEXIST(td, args->path, &path);
1567 error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid,
1568 args->gid, AT_SYMLINK_NOFOLLOW);
1575 convert_fadvice(int advice)
1578 case LINUX_POSIX_FADV_NORMAL:
1579 return (POSIX_FADV_NORMAL);
1580 case LINUX_POSIX_FADV_RANDOM:
1581 return (POSIX_FADV_RANDOM);
1582 case LINUX_POSIX_FADV_SEQUENTIAL:
1583 return (POSIX_FADV_SEQUENTIAL);
1584 case LINUX_POSIX_FADV_WILLNEED:
1585 return (POSIX_FADV_WILLNEED);
1586 case LINUX_POSIX_FADV_DONTNEED:
1587 return (POSIX_FADV_DONTNEED);
1588 case LINUX_POSIX_FADV_NOREUSE:
1589 return (POSIX_FADV_NOREUSE);
1596 linux_fadvise64(struct thread *td, struct linux_fadvise64_args *args)
1601 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1602 offset = PAIR32TO64(off_t, args->offset);
1604 offset = args->offset;
1607 advice = convert_fadvice(args->advice);
1610 return (kern_posix_fadvise(td, args->fd, offset, args->len, advice));
1613 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
1615 linux_fadvise64_64(struct thread *td, struct linux_fadvise64_64_args *args)
1620 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1621 len = PAIR32TO64(off_t, args->len);
1622 offset = PAIR32TO64(off_t, args->offset);
1625 offset = args->offset;
1628 advice = convert_fadvice(args->advice);
1631 return (kern_posix_fadvise(td, args->fd, offset, len, advice));
1633 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
1635 #ifdef LINUX_LEGACY_SYSCALLS
1637 linux_pipe(struct thread *td, struct linux_pipe_args *args)
1642 error = kern_pipe(td, fildes, 0, NULL, NULL);
1646 error = copyout(fildes, args->pipefds, sizeof(fildes));
1648 (void)kern_close(td, fildes[0]);
1649 (void)kern_close(td, fildes[1]);
1657 linux_pipe2(struct thread *td, struct linux_pipe2_args *args)
1662 if ((args->flags & ~(LINUX_O_NONBLOCK | LINUX_O_CLOEXEC)) != 0)
1666 if ((args->flags & LINUX_O_NONBLOCK) != 0)
1667 flags |= O_NONBLOCK;
1668 if ((args->flags & LINUX_O_CLOEXEC) != 0)
1670 error = kern_pipe(td, fildes, flags, NULL, NULL);
1674 error = copyout(fildes, args->pipefds, sizeof(fildes));
1676 (void)kern_close(td, fildes[0]);
1677 (void)kern_close(td, fildes[1]);
1684 linux_dup3(struct thread *td, struct linux_dup3_args *args)
1689 if (args->oldfd == args->newfd)
1691 if ((args->flags & ~LINUX_O_CLOEXEC) != 0)
1693 if (args->flags & LINUX_O_CLOEXEC)
1694 cmd = F_DUP2FD_CLOEXEC;
1698 newfd = args->newfd;
1699 return (kern_fcntl(td, args->oldfd, cmd, newfd));
1703 linux_fallocate(struct thread *td, struct linux_fallocate_args *args)
1708 * We emulate only posix_fallocate system call for which
1711 if (args->mode != 0)
1712 return (EOPNOTSUPP);
1714 #if defined(__amd64__) && defined(COMPAT_LINUX32)
1715 len = PAIR32TO64(off_t, args->len);
1716 offset = PAIR32TO64(off_t, args->offset);
1719 offset = args->offset;
1722 return (kern_posix_fallocate(td, args->fd, offset, len));
1726 linux_copy_file_range(struct thread *td, struct linux_copy_file_range_args
1729 l_loff_t inoff, outoff, *inoffp, *outoffp;
1733 * copy_file_range(2) on Linux doesn't define any flags (yet), so is
1734 * the native implementation. Enforce it.
1736 if (args->flags != 0) {
1737 linux_msg(td, "copy_file_range unsupported flags 0x%x",
1742 inoffp = outoffp = NULL;
1743 if (args->off_in != NULL) {
1744 error = copyin(args->off_in, &inoff, sizeof(l_loff_t));
1749 if (args->off_out != NULL) {
1750 error = copyin(args->off_out, &outoff, sizeof(l_loff_t));
1756 error = kern_copy_file_range(td, args->fd_in, inoffp, args->fd_out,
1757 outoffp, args->len, flags);
1758 if (error == 0 && args->off_in != NULL)
1759 error = copyout(inoffp, args->off_in, sizeof(l_loff_t));
1760 if (error == 0 && args->off_out != NULL)
1761 error = copyout(outoffp, args->off_out, sizeof(l_loff_t));
1765 #define LINUX_MEMFD_PREFIX "memfd:"
1768 linux_memfd_create(struct thread *td, struct linux_memfd_create_args *args)
1770 char memfd_name[LINUX_NAME_MAX + 1];
1771 int error, flags, shmflags, oflags;
1774 * This is our clever trick to avoid the heap allocation to copy in the
1775 * uname. We don't really need to go this far out of our way, but it
1776 * does keep the rest of this function fairly clean as they don't have
1777 * to worry about cleanup on the way out.
1779 error = copyinstr(args->uname_ptr,
1780 memfd_name + sizeof(LINUX_MEMFD_PREFIX) - 1,
1781 LINUX_NAME_MAX - sizeof(LINUX_MEMFD_PREFIX) - 1, NULL);
1783 if (error == ENAMETOOLONG)
1788 memcpy(memfd_name, LINUX_MEMFD_PREFIX, sizeof(LINUX_MEMFD_PREFIX) - 1);
1789 flags = linux_to_bsd_bits(args->flags, mfd_bitmap, 0);
1790 if ((flags & ~(MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB |
1791 MFD_HUGE_MASK)) != 0)
1793 /* Size specified but no HUGETLB. */
1794 if ((flags & MFD_HUGE_MASK) != 0 && (flags & MFD_HUGETLB) == 0)
1796 /* We don't actually support HUGETLB. */
1797 if ((flags & MFD_HUGETLB) != 0)
1800 shmflags = SHM_GROW_ON_WRITE;
1801 if ((flags & MFD_CLOEXEC) != 0)
1802 oflags |= O_CLOEXEC;
1803 if ((flags & MFD_ALLOW_SEALING) != 0)
1804 shmflags |= SHM_ALLOW_SEALING;
1805 return (kern_shm_open2(td, SHM_ANON, oflags, 0, shmflags, NULL,
1810 linux_splice(struct thread *td, struct linux_splice_args *args)
1813 linux_msg(td, "syscall splice not really implemented");
1816 * splice(2) is documented to return EINVAL in various circumstances;
1817 * returning it instead of ENOSYS should hint the caller to use fallback