diff --git a/sys/compat/linux/linux_dummy.c b/sys/compat/linux/linux_dummy.c index 46596aa4a92a..861482b67d8f 100644 --- a/sys/compat/linux/linux_dummy.c +++ b/sys/compat/linux/linux_dummy.c @@ -1,169 +1,148 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2013 Dmitry Chagin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include /* * Including linux vs linux32 here is arbitrary -- the syscall args structures * (proto.h) are not dereferenced by the DUMMY stub implementations, and * suitable for use by both native and compat32 entrypoints. */ #include #include #include #include /* DTrace init */ LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); UNIMPLEMENTED(afs_syscall); UNIMPLEMENTED(create_module); /* Added in Linux 1.0 removed in 2.6. */ UNIMPLEMENTED(epoll_ctl_old); UNIMPLEMENTED(epoll_wait_old); UNIMPLEMENTED(get_kernel_syms); /* Added in Linux 1.0 removed in 2.6. */ UNIMPLEMENTED(getpmsg); UNIMPLEMENTED(nfsservctl); /* Added in Linux 2.2 removed in 3.1. */ UNIMPLEMENTED(putpmsg); UNIMPLEMENTED(query_module); /* Added in Linux 2.2 removed in 2.6. */ UNIMPLEMENTED(security); UNIMPLEMENTED(vserver); DUMMY(setfsuid); DUMMY(setfsgid); DUMMY(vhangup); DUMMY(pivot_root); DUMMY(adjtimex); DUMMY(swapoff); DUMMY(init_module); DUMMY(delete_module); DUMMY(lookup_dcookie); DUMMY(remap_file_pages); DUMMY(mbind); DUMMY(get_mempolicy); DUMMY(set_mempolicy); DUMMY(kexec_load); /* Linux 2.6.11: */ DUMMY(add_key); DUMMY(request_key); DUMMY(keyctl); /* Linux 2.6.13: */ DUMMY(ioprio_set); DUMMY(ioprio_get); DUMMY(inotify_add_watch); DUMMY(inotify_rm_watch); /* Linux 2.6.16: */ DUMMY(migrate_pages); DUMMY(unshare); /* Linux 2.6.17: */ DUMMY(tee); DUMMY(vmsplice); /* Linux 2.6.18: */ DUMMY(move_pages); /* Linux 2.6.27: */ DUMMY(signalfd4); DUMMY(inotify_init1); /* Linux 2.6.31: */ DUMMY(perf_event_open); /* Linux 2.6.36: */ DUMMY(fanotify_init); DUMMY(fanotify_mark); /* Linux 2.6.39: */ DUMMY(clock_adjtime); /* Linux 3.0: */ DUMMY(setns); /* Linux 3.2: */ DUMMY(process_vm_readv); DUMMY(process_vm_writev); /* Linux 3.5: */ DUMMY(kcmp); /* Linux 3.8: */ DUMMY(finit_module); DUMMY(sched_setattr); DUMMY(sched_getattr); /* Linux 3.18: */ DUMMY(bpf); /* Linux 3.19: */ DUMMY(execveat); /* Linux 4.2: */ DUMMY(userfaultfd); /* Linux 4.3: */ DUMMY(membarrier); /* Linux 4.4: */ DUMMY(mlock2); /* Linux 4.6: */ DUMMY(preadv2); DUMMY(pwritev2); /* Linux 4.8: */ DUMMY(pkey_mprotect); DUMMY(pkey_alloc); DUMMY(pkey_free); DUMMY(open_tree); DUMMY(move_mount); DUMMY(fsopen); DUMMY(fsconfig); DUMMY(fsmount); DUMMY(fspick); DUMMY(pidfd_open); DUMMY(openat2); DUMMY(pidfd_getfd); DUMMY(process_madvise); DUMMY(mount_setattr); /* Linux 4.18: */ DUMMY(io_pgetevents); /* Linux 5.0: */ DUMMY(pidfd_send_signal); DUMMY(io_uring_setup); DUMMY(io_uring_enter); DUMMY(io_uring_register); - -#define DUMMY_XATTR(s) \ -int \ -linux_ ## s ## xattr( \ - struct thread *td, struct linux_ ## s ## xattr_args *arg) \ -{ \ - \ - return (EOPNOTSUPP); \ -} -DUMMY_XATTR(set); -DUMMY_XATTR(lset); -DUMMY_XATTR(fset); -DUMMY_XATTR(get); -DUMMY_XATTR(lget); -DUMMY_XATTR(fget); -DUMMY_XATTR(list); -DUMMY_XATTR(llist); -DUMMY_XATTR(flist); -DUMMY_XATTR(remove); -DUMMY_XATTR(lremove); -DUMMY_XATTR(fremove); diff --git a/sys/compat/linux/linux_xattr.c b/sys/compat/linux/linux_xattr.c new file mode 100644 index 000000000000..60c4c8ddf4c9 --- /dev/null +++ b/sys/compat/linux/linux_xattr.c @@ -0,0 +1,399 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Dmitry Chagin + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#ifdef COMPAT_LINUX32 +#include +#include +#else +#include +#include +#endif + +#include + +#define LINUX_XATTR_SIZE_MAX 65536 +#define LINUX_XATTR_LIST_MAX 65536 +#define LINUX_XATTR_NAME_MAX 255 + +#define LINUX_XATTR_CREATE 0x1 +#define LINUX_XATTR_REPLACE 0x2 +#define LINUX_XATTR_FLAGS LINUX_XATTR_CREATE|LINUX_XATTR_REPLACE + +struct listxattr_args { + int fd; + const char *path; + char *list; + l_size_t size; + int follow; +}; + +struct setxattr_args { + int fd; + const char *path; + const char *name; + void *value; + l_size_t size; + l_int flags; + int follow; +}; + +static char *extattr_namespace_names[] = EXTATTR_NAMESPACE_NAMES; + + +static int +xatrr_to_extattr(const char *uattrname, int *attrnamespace, char *attrname) +{ + char uname[LINUX_XATTR_NAME_MAX + 1], *dot; + size_t len, cplen; + int error; + + error = copyinstr(uattrname, uname, sizeof(uname), &cplen); + if (error != 0) + return (error); + if (cplen == sizeof(uname)) + return (ERANGE); + dot = strchr(uname, '.'); + if (dot == NULL) + return (ENOTSUP); + *dot = '\0'; + for (*attrnamespace = EXTATTR_NAMESPACE_USER; + *attrnamespace < nitems(extattr_namespace_names); + (*attrnamespace)++) { + if (bcmp(uname, extattr_namespace_names[*attrnamespace], + dot - uname + 1) == 0) { + dot++; + len = strlen(dot) + 1; + bcopy(dot, attrname, len); + return (0); + } + } + return (ENOTSUP); +} + +static int +listxattr(struct thread *td, struct listxattr_args *args) +{ + char attrname[LINUX_XATTR_NAME_MAX + 1]; + char *data, *prefix, *key; + struct uio auio; + struct iovec aiov; + unsigned char keylen; + size_t sz, cnt, rs, prefixlen, pairlen; + int attrnamespace, error; + + if (args->size != 0) + sz = min(LINUX_XATTR_LIST_MAX, args->size); + else + sz = LINUX_XATTR_LIST_MAX; + + data = malloc(sz, M_LINUX, M_WAITOK); + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_rw = UIO_READ; + auio.uio_segflg = UIO_SYSSPACE; + auio.uio_td = td; + cnt = 0; + for (attrnamespace = EXTATTR_NAMESPACE_USER; + attrnamespace < nitems(extattr_namespace_names); + attrnamespace++) { + aiov.iov_base = data; + aiov.iov_len = sz; + auio.uio_resid = sz; + auio.uio_offset = 0; + + if (args->path != NULL) + error = kern_extattr_list_path(td, args->path, + attrnamespace, &auio, args->follow, UIO_USERSPACE); + else + error = kern_extattr_list_fd(td, args->fd, + attrnamespace, &auio); + rs = sz - auio.uio_resid; + if (error != 0 || rs == 0) + continue; + prefix = extattr_namespace_names[attrnamespace]; + prefixlen = strlen(prefix); + key = data; + while (rs > 0) { + keylen = (unsigned char)key[0]; + pairlen = prefixlen + 1 + keylen + 1; + if (cnt + pairlen > LINUX_XATTR_LIST_MAX) { + error = E2BIG; + break; + } + if ((args->list != NULL && cnt > args->size) || + pairlen >= sizeof(attrname)) { + error = ERANGE; + break; + } + ++key; + if (args->list != NULL) { + sprintf(attrname, "%s.%.*s", prefix, keylen, key); + error = copyout(attrname, args->list, pairlen); + if (error != 0) + break; + args->list += pairlen; + } + cnt += pairlen; + key += keylen; + rs -= (keylen + 1); + } + } + if (error == 0) + td->td_retval[0] = cnt; + free(data, M_LINUX); + return (error); +} + +int +linux_listxattr(struct thread *td, struct linux_listxattr_args *args) +{ + struct listxattr_args eargs = { + .fd = -1, + .path = args->path, + .list = args->list, + .size = args->size, + .follow = FOLLOW, + }; + + return (listxattr(td, &eargs)); +} + +int +linux_llistxattr(struct thread *td, struct linux_llistxattr_args *args) +{ + struct listxattr_args eargs = { + .fd = -1, + .path = args->path, + .list = args->list, + .size = args->size, + .follow = NOFOLLOW, + }; + + return (listxattr(td, &eargs)); +} + +int +linux_flistxattr(struct thread *td, struct linux_flistxattr_args *args) +{ + struct listxattr_args eargs = { + .fd = args->fd, + .path = NULL, + .list = args->list, + .size = args->size, + .follow = 0, + }; + + return (listxattr(td, &eargs)); +} + +static int +linux_path_removexattr(struct thread *td, const char *upath, const char *uname, + int follow) +{ + char attrname[LINUX_XATTR_NAME_MAX + 1]; + int attrnamespace, error; + + error = xatrr_to_extattr(uname, &attrnamespace, attrname); + if (error != 0) + return (error); + + return (kern_extattr_delete_path(td, upath, attrnamespace, + attrname, follow, UIO_USERSPACE)); +} + +int +linux_removexattr(struct thread *td, struct linux_removexattr_args *args) +{ + + return (linux_path_removexattr(td, args->path, args->name, + FOLLOW)); +} + +int +linux_lremovexattr(struct thread *td, struct linux_lremovexattr_args *args) +{ + + return (linux_path_removexattr(td, args->path, args->name, + NOFOLLOW)); +} + +int +linux_fremovexattr(struct thread *td, struct linux_fremovexattr_args *args) +{ + char attrname[LINUX_XATTR_NAME_MAX + 1]; + int attrnamespace, error; + + error = xatrr_to_extattr(args->name, &attrnamespace, attrname); + if (error != 0) + return (error); + return (kern_extattr_delete_fd(td, args->fd, attrnamespace, + attrname)); +} + +static int +linux_path_getxattr(struct thread *td, const char *upath, const char *uname, + void *value, l_size_t size, int follow) +{ + char attrname[LINUX_XATTR_NAME_MAX + 1]; + int attrnamespace, error; + + error = xatrr_to_extattr(uname, &attrnamespace, attrname); + if (error != 0) + return (error); + + return (kern_extattr_get_path(td, upath, attrnamespace, + attrname, value, size, follow, UIO_USERSPACE)); +} + +int +linux_getxattr(struct thread *td, struct linux_getxattr_args *args) +{ + + return (linux_path_getxattr(td, args->path, args->name, + args->value, args->size, FOLLOW)); +} + +int +linux_lgetxattr(struct thread *td, struct linux_lgetxattr_args *args) +{ + + return (linux_path_getxattr(td, args->path, args->name, + args->value, args->size, NOFOLLOW)); +} + +int +linux_fgetxattr(struct thread *td, struct linux_fgetxattr_args *args) +{ + char attrname[LINUX_XATTR_NAME_MAX + 1]; + int attrnamespace, error; + + error = xatrr_to_extattr(args->name, &attrnamespace, attrname); + if (error != 0) + return (error); + return (kern_extattr_get_fd(td, args->fd, attrnamespace, + attrname, args->value, args->size)); +} + +static int +setxattr(struct thread *td, struct setxattr_args *args) +{ + char attrname[LINUX_XATTR_NAME_MAX + 1]; + int attrnamespace, error; + + if ((args->flags & ~(LINUX_XATTR_FLAGS)) != 0 || + args->flags == (LINUX_XATTR_FLAGS)) + return (EINVAL); + error = xatrr_to_extattr(args->name, &attrnamespace, attrname); + if (error != 0) + return (error); + + if ((args->flags & (LINUX_XATTR_FLAGS)) != 0 ) { + if (args->path != NULL) + error = kern_extattr_get_path(td, args->path, + attrnamespace, attrname, NULL, args->size, + args->follow, UIO_USERSPACE); + else + error = kern_extattr_get_fd(td, args->fd, + attrnamespace, attrname, NULL, args->size); + if ((args->flags & LINUX_XATTR_CREATE) != 0) { + if (error == 0) + error = EEXIST; + else if (error == ENOATTR) + error = 0; + } + if (error != 0) + goto out; + } + if (args->path != NULL) + error = kern_extattr_set_path(td, args->path, attrnamespace, + attrname, args->value, args->size, args->follow, + UIO_USERSPACE); + else + error = kern_extattr_set_fd(td, args->fd, attrnamespace, + attrname, args->value, args->size); +out: + td->td_retval[0] = 0; + return (error); +} + +int +linux_setxattr(struct thread *td, struct linux_setxattr_args *args) +{ + struct setxattr_args eargs = { + .fd = -1, + .path = args->path, + .name = args->name, + .value = args->value, + .size = args->size, + .flags = args->flags, + .follow = FOLLOW, + }; + + return (setxattr(td, &eargs)); +} + +int +linux_lsetxattr(struct thread *td, struct linux_lsetxattr_args *args) +{ + struct setxattr_args eargs = { + .fd = -1, + .path = args->path, + .name = args->name, + .value = args->value, + .size = args->size, + .flags = args->flags, + .follow = NOFOLLOW, + }; + + return (setxattr(td, &eargs)); +} + +int +linux_fsetxattr(struct thread *td, struct linux_fsetxattr_args *args) +{ + struct setxattr_args eargs = { + .fd = args->fd, + .path = NULL, + .name = args->name, + .value = args->value, + .size = args->size, + .flags = args->flags, + .follow = 0, + }; + + return (setxattr(td, &eargs)); +} diff --git a/sys/modules/linux/Makefile b/sys/modules/linux/Makefile index 294a7d595cc6..42ce6607dfc2 100644 --- a/sys/modules/linux/Makefile +++ b/sys/modules/linux/Makefile @@ -1,147 +1,148 @@ # $FreeBSD$ .if ${MACHINE_CPUARCH} == "amd64" SFX= 32 CFLAGS+=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32 .endif .PATH: ${SRCTOP}/sys/compat/linux ${SRCTOP}/sys/${MACHINE_CPUARCH}/linux${SFX} .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" .PATH: ${SRCTOP}/sys/x86/linux .endif KMOD= linux SRCS= linux${SFX}_dummy_machdep.c \ linux_elf32.c \ linux_event.c \ linux_file.c \ linux_fork.c \ linux_futex.c \ linux_getcwd.c \ linux_ioctl.c \ linux_ipc.c \ linux${SFX}_machdep.c \ linux_misc.c \ linux_rseq.c \ linux_signal.c \ linux_socket.c \ linux_stats.c \ linux${SFX}_syscalls.c \ linux_sysctl.c \ linux${SFX}_sysent.c \ linux${SFX}_sysvec.c \ linux_time.c \ linux_timer.c \ linux_uid16.c \ linux_vdso.c \ + linux_xattr.c \ opt_inet6.h \ opt_ktrace.h \ opt_posix.h \ bus_if.h \ device_if.h \ vnode_if.h .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" SRCS+= linux_dummy_x86.c VDSODEPS=linux_vdso_gettc_x86.inc .endif .if ${MACHINE_CPUARCH} == "amd64" SRCS+= linux${SFX}_support.S .endif DPSRCS= assym.inc linux${SFX}_genassym.c # XXX: for assym.inc SRCS+= opt_kstack_pages.h opt_nfs.h opt_hwpmc_hooks.h .if ${MACHINE_CPUARCH} == "i386" SRCS+= opt_apic.h opt_cpu.h .endif OBJS= linux${SFX}_vdso.so .if ${MACHINE_CPUARCH} == "i386" SRCS+= imgact_linux.c \ linux.c \ linux_dummy.c \ linux_emul.c \ linux_errno.c \ linux_mib.c \ linux_mmap.c \ linux_ptrace_machdep.c \ linux_util.c \ linux_vdso_selector_x86.c \ linux_x86.c \ linux_copyout.c \ linux_netlink.c \ opt_netlink.h .endif .if ${MACHINE_CPUARCH} == "i386" EXPORT_SYMS= EXPORT_SYMS+= linux_get_osname EXPORT_SYMS+= linux_get_osrelease EXPORT_SYMS+= linux_ioctl_register_handler EXPORT_SYMS+= linux_ioctl_unregister_handler .endif CLEANFILES= linux${SFX}_assym.h linux${SFX}_genassym.o linux${SFX}_locore.o \ genassym.o linux${SFX}_vdso_gtod.o linux${SFX}_vdso.so.o linux${SFX}_assym.h: linux${SFX}_genassym.o sh ${SYSDIR}/kern/genassym.sh linux${SFX}_genassym.o > ${.TARGET} .if ${MACHINE_CPUARCH} == "amd64" VDSOFLAGS=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32 -m32 .else VDSOFLAGS=-mregparm=0 .endif linux${SFX}_locore.o: linux${SFX}_assym.h assym.inc ${CC} -c -x assembler-with-cpp -DLOCORE -fPIC -pipe -O2 -Werror \ -msoft-float \ -fno-common -nostdinc -fasynchronous-unwind-tables \ -fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \ -fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \ ${.IMPSRC} -o ${.TARGET} linux${SFX}_vdso_gtod.o: linux_vdso_gtod.inc ${VDSODEPS} ${CC} -c -fPIC -pipe -O2 -Werror -msoft-float \ -fno-common -nostdinc -fasynchronous-unwind-tables \ -fno-omit-frame-pointer -foptimize-sibling-calls ${VDSOFLAGS} \ -fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \ ${.IMPSRC} -o ${.TARGET} linux${SFX}_vdso.so.o: linux${SFX}_locore.o linux${SFX}_vdso_gtod.o ${LD} -m elf_i386 --shared --eh-frame-hdr -soname=linux-gate.so.1 \ --no-undefined --hash-style=both -warn-common -nostdlib \ --strip-debug -s --build-id=sha1 --Bsymbolic \ -T${SRCTOP}/sys/${MACHINE}/linux${SFX}/linux${SFX}_vdso.lds.s \ -o ${.TARGET} ${.ALLSRC:M*.o} .if ${MACHINE_CPUARCH} == "amd64" OBJCOPY_TARGET=--output-target elf64-x86-64-freebsd --binary-architecture i386 .elif ${MACHINE_CPUARCH} == "i386" OBJCOPY_TARGET=--output-target elf32-i386-freebsd --binary-architecture i386 .else .error ${MACHINE_CPUARCH} not yet supported by linux .endif linux${SFX}_vdso.so: linux${SFX}_vdso.so.o ${OBJCOPY} --input-target binary ${OBJCOPY_TARGET} \ linux${SFX}_vdso.so.o ${.TARGET} ${STRIPBIN} -N _binary_linux${SFX}_vdso_so_o_size ${.TARGET} .if ${MACHINE_CPUARCH} == "amd64" linux${SFX}_support.o: linux${SFX}_support.S linux${SFX}_assym.h assym.inc ${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \ ${.ALLSRC:M*.S:u} -o ${.TARGET} .endif linux${SFX}_genassym.o: offset.inc ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon ${.IMPSRC} .if !defined(KERNBUILDDIR) .warning Building Linuxulator outside of a kernel does not make sense .endif EXPORT_SYMS= YES .include diff --git a/sys/modules/linux64/Makefile b/sys/modules/linux64/Makefile index 4fe9ccd576c1..0a133e6e79b4 100644 --- a/sys/modules/linux64/Makefile +++ b/sys/modules/linux64/Makefile @@ -1,112 +1,113 @@ # $FreeBSD$ .PATH: ${SRCTOP}/sys/compat/linux ${SRCTOP}/sys/${MACHINE}/linux .if ${MACHINE_CPUARCH} == "amd64" .PATH: ${SRCTOP}/sys/x86/linux .endif KMOD= linux64 SRCS= linux_dummy_machdep.c \ linux_elf64.c \ linux_event.c \ linux_file.c \ linux_fork.c \ linux_futex.c \ linux_getcwd.c \ linux_ioctl.c \ linux_ipc.c \ linux_machdep.c \ linux_misc.c \ linux_ptrace.c \ linux_rseq.c \ linux_signal.c \ linux_socket.c \ linux_stats.c \ linux_syscalls.c \ linux_sysctl.c \ linux_sysent.c \ linux_sysvec.c \ linux_time.c \ linux_vdso.c \ linux_timer.c \ + linux_xattr.c \ opt_ktrace.h \ opt_inet6.h \ opt_posix.h \ bus_if.h \ device_if.h \ vnode_if.h \ linux_support.S .if ${MACHINE_CPUARCH} == "amd64" SRCS+= linux_dummy_x86.c .endif DPSRCS= assym.inc linux_genassym.c # XXX: for assym.inc SRCS+= opt_kstack_pages.h opt_nfs.h opt_hwpmc_hooks.h CLEANFILES= linux_assym.h linux_genassym.o linux_locore.o \ genassym.o linux_vdso_gtod.o linux_vdso.so.o OBJS= linux_vdso.so linux_assym.h: linux_genassym.o sh ${SYSDIR}/kern/genassym.sh linux_genassym.o > ${.TARGET} .if ${MACHINE_CPUARCH} == "amd64" VDSOFLAGS=-mcmodel=small -msoft-float VDSODEPS=linux_vdso_gettc_x86.inc .elif ${MACHINE_CPUARCH} == "aarch64" # The Linux uses tiny memory model, but our ld does not know about # some of relocation types which is generated by cc VDSOFLAGS=-mgeneral-regs-only -mcmodel=small -ffixed-x18 .endif linux_locore.o: linux_assym.h assym.inc ${CC} -c -x assembler-with-cpp -DLOCORE \ -fPIC -pipe -O2 -Werror ${VDSOFLAGS} \ -nostdinc -fasynchronous-unwind-tables \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \ ${.IMPSRC} -o ${.TARGET} linux_vdso_gtod.o: linux_vdso_gtod.inc ${VDSODEPS} ${CC} -c -fPIC -pipe -O2 -Werror ${VDSOFLAGS} \ -nostdinc -fasynchronous-unwind-tables \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -fno-stack-protector -I. -I${SYSDIR} -I${SRCTOP}/include \ ${.IMPSRC} -o ${.TARGET} linux_vdso.so.o: linux_locore.o linux_vdso_gtod.o ${LD} --shared --eh-frame-hdr -soname=linux-vdso.so.1 \ --no-undefined --hash-style=both -warn-common -nostdlib \ --strip-debug -s --build-id=sha1 -Bsymbolic \ -T${SRCTOP}/sys/${MACHINE}/linux/linux_vdso.lds.s \ -o ${.TARGET} ${.ALLSRC:M*.o} .if ${MACHINE_CPUARCH} == "aarch64" OBJCOPY_TARGET=--output-target elf64-littleaarch64 --binary-architecture aarch64 .elif ${MACHINE_CPUARCH} == "amd64" OBJCOPY_TARGET=--output-target elf64-x86-64 --binary-architecture i386:x86-64 .else .error ${MACHINE_CPUARCH} not yet supported by linux64 .endif linux_vdso.so: linux_vdso.so.o ${OBJCOPY} --input-target binary ${OBJCOPY_TARGET} \ linux_vdso.so.o ${.TARGET} ${STRIPBIN} -N _binary_linux_vdso_so_o_size ${.TARGET} linux_support.o: linux_support.S assym.inc linux_assym.h ${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \ ${.ALLSRC:M*.S:u} -o ${.TARGET} linux_genassym.o: offset.inc ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon ${.IMPSRC} .if !defined(KERNBUILDDIR) .warning Building Linuxulator outside of a kernel does not make sense .endif EXPORT_SYMS= YES .include