aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2023-09-05 18:16:39 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2023-09-05 18:16:39 +0000
commit2a1cf1b6b55c8326bbe85d0fdf17b0f2fb9b34ce (patch)
tree61b794cfc4930130303736abbfefd60d6e812530
parent553b1a4e4eb426d2c29a033b284c13bfbab30334 (diff)
downloadsrc-2a1cf1b6b55c8326bbe85d0fdf17b0f2fb9b34ce.tar.gz
src-2a1cf1b6b55c8326bbe85d0fdf17b0f2fb9b34ce.zip
linux(4): Deduplicate mmap2
To help porting the Linux emulation layer to a new platforms start using Linux names for conditional builds instead of architecture-specific ifdefs. MFC after: 1 week
-rw-r--r--sys/amd64/linux/linux_machdep.c9
-rw-r--r--sys/amd64/linux32/linux.h4
-rw-r--r--sys/amd64/linux32/linux32_machdep.c9
-rw-r--r--sys/arm64/linux/linux_machdep.c18
-rw-r--r--sys/compat/linux/linux_misc.c17
-rw-r--r--sys/i386/linux/linux.h2
-rw-r--r--sys/i386/linux/linux_machdep.c9
7 files changed, 23 insertions, 45 deletions
diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c
index 7da1dccd6b45..33ce902a45bd 100644
--- a/sys/amd64/linux/linux_machdep.c
+++ b/sys/amd64/linux/linux_machdep.c
@@ -69,7 +69,6 @@
#include <amd64/linux/linux_proto.h>
#include <compat/linux/linux_fork.h>
#include <compat/linux/linux_misc.h>
-#include <compat/linux/linux_mmap.h>
#include <compat/linux/linux_util.h>
#define LINUX_ARCH_AMD64 0xc000003e
@@ -90,14 +89,6 @@ linux_set_upcall(struct thread *td, register_t stack)
}
int
-linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
-{
-
- return (linux_mmap_common(td, args->addr, args->len, args->prot,
- args->flags, args->fd, args->pgoff));
-}
-
-int
linux_iopl(struct thread *td, struct linux_iopl_args *args)
{
int error;
diff --git a/sys/amd64/linux32/linux.h b/sys/amd64/linux32/linux.h
index 395548b3c93f..5542df1b3185 100644
--- a/sys/amd64/linux32/linux.h
+++ b/sys/amd64/linux32/linux.h
@@ -46,6 +46,10 @@
#define LINUX32_MAXSSIZ (64 * 1024 * 1024) /* 64MB */
#define LINUX32_MAXVMEM 0 /* Unlimited */
+#define LINUX_ARCHWANT_MMAP2PGOFF 1 /* 32-bit off_t want offset
+ * represented in multiples
+ * of page size. */
+
/*
* Provide a separate set of types for the Linux types.
*/
diff --git a/sys/amd64/linux32/linux32_machdep.c b/sys/amd64/linux32/linux32_machdep.c
index fb088ae37b26..e10502f9bd80 100644
--- a/sys/amd64/linux32/linux32_machdep.c
+++ b/sys/amd64/linux32/linux32_machdep.c
@@ -321,15 +321,6 @@ linux_set_upcall(struct thread *td, register_t stack)
}
int
-linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
-{
-
- return (linux_mmap_common(td, PTROUT(args->addr), args->len, args->prot,
- args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
- PAGE_SIZE));
-}
-
-int
linux_mmap(struct thread *td, struct linux_mmap_args *args)
{
int error;
diff --git a/sys/arm64/linux/linux_machdep.c b/sys/arm64/linux/linux_machdep.c
index b9548387315b..3ba5683941b5 100644
--- a/sys/arm64/linux/linux_machdep.c
+++ b/sys/arm64/linux/linux_machdep.c
@@ -32,25 +32,17 @@
#include <sys/proc.h>
#include <sys/ptrace.h>
#include <sys/reg.h>
-#include <sys/sdt.h>
#include <vm/vm_param.h>
#include <arm64/linux/linux.h>
#include <arm64/linux/linux_proto.h>
-#include <compat/linux/linux_dtrace.h>
#include <compat/linux/linux_fork.h>
#include <compat/linux/linux_misc.h>
-#include <compat/linux/linux_mmap.h>
#include <compat/linux/linux_util.h>
#define LINUX_ARCH_AARCH64 0xc00000b7
-/* DTrace init */
-LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
-
-/* DTrace probes */
-LIN_SDT_PROBE_DEFINE0(machdep, linux_mmap2, todo);
int
linux_set_upcall(struct thread *td, register_t stack)
@@ -67,16 +59,6 @@ linux_set_upcall(struct thread *td, register_t stack)
return (0);
}
-/* LINUXTODO: deduplicate arm64 linux_mmap2 */
-int
-linux_mmap2(struct thread *td, struct linux_mmap2_args *uap)
-{
-
- LIN_SDT_PROBE0(machdep, linux_mmap2, todo);
- return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot,
- uap->flags, uap->fd, uap->pgoff));
-}
-
int
linux_set_cloned_tls(struct thread *td, void *desc)
{
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index b9c67d513cd3..cb781f3bad75 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -365,6 +365,23 @@ linux_madvise(struct thread *td, struct linux_madvise_args *uap)
uap->behav));
}
+int
+linux_mmap2(struct thread *td, struct linux_mmap2_args *uap)
+{
+#if defined(LINUX_ARCHWANT_MMAP2PGOFF)
+ /*
+ * For architectures with sizeof (off_t) < sizeof (loff_t) mmap is
+ * implemented with mmap2 syscall and the offset is represented in
+ * multiples of page size.
+ */
+ return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot,
+ uap->flags, uap->fd, (uint64_t)(uint32_t)uap->pgoff * PAGE_SIZE));
+#else
+ return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot,
+ uap->flags, uap->fd, uap->pgoff));
+#endif
+}
+
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_time(struct thread *td, struct linux_time_args *args)
diff --git a/sys/i386/linux/linux.h b/sys/i386/linux/linux.h
index 643c240f8e37..914dc9c9ae84 100644
--- a/sys/i386/linux/linux.h
+++ b/sys/i386/linux/linux.h
@@ -38,6 +38,8 @@
#define LINUX_DTRACE linuxulator
+#define LINUX_ARCHWANT_MMAP2PGOFF 1
+
/*
* Provide a separate set of types for the Linux types.
*/
diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c
index 7f1738cda845..b5d42dc22162 100644
--- a/sys/i386/linux/linux_machdep.c
+++ b/sys/i386/linux/linux_machdep.c
@@ -309,15 +309,6 @@ linux_set_upcall(struct thread *td, register_t stack)
}
int
-linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
-{
-
- return (linux_mmap_common(td, args->addr, args->len, args->prot,
- args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
- PAGE_SIZE));
-}
-
-int
linux_mmap(struct thread *td, struct linux_mmap_args *args)
{
int error;