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
This commit is contained in:
Dmitry Chagin 2023-09-05 21:16:39 +03:00
parent 553b1a4e4e
commit 2a1cf1b6b5
7 changed files with 23 additions and 45 deletions

View file

@ -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
@ -89,14 +88,6 @@ linux_set_upcall(struct thread *td, register_t stack)
return (0);
}
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)
{

View file

@ -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.
*/

View file

@ -320,15 +320,6 @@ linux_set_upcall(struct thread *td, register_t stack)
return (0);
}
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)
{

View file

@ -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)
{

View file

@ -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)

View file

@ -38,6 +38,8 @@
#define LINUX_DTRACE linuxulator
#define LINUX_ARCHWANT_MMAP2PGOFF 1
/*
* Provide a separate set of types for the Linux types.
*/

View file

@ -308,15 +308,6 @@ linux_set_upcall(struct thread *td, register_t stack)
return (0);
}
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)
{