Commit 4500c2fa by Derek Mauro Committed by Copybara-Service

DirectMmap: Use off_t instead of off64_t for the offset parameter

off_t is best for portability. Its size varies with the platform.
off64_t is non-standard, but is present in glibc and some BSDs.
It also matches the signature specified in the manual.
https://man7.org/linux/man-pages/man2/mmap.2.html

This is a re-spin of #1349, but correctly casts the type to the type
expected by the kernel for mmap2.
https://man7.org/linux/man-pages/man2/mmap2.2.html

Fixes #1473

PiperOrigin-RevId: 539656313
Change-Id: I7a30dd9d3eb6af03a99da0d93d721a86f6521b25
parent 1feab4ff
...@@ -72,7 +72,7 @@ namespace base_internal { ...@@ -72,7 +72,7 @@ namespace base_internal {
// Platform specific logic extracted from // Platform specific logic extracted from
// https://chromium.googlesource.com/linux-syscall-support/+/master/linux_syscall_support.h // https://chromium.googlesource.com/linux-syscall-support/+/master/linux_syscall_support.h
inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd, inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd,
off64_t offset) noexcept { off_t offset) noexcept {
#if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \ #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
defined(__m68k__) || defined(__sh__) || \ defined(__m68k__) || defined(__sh__) || \
(defined(__hppa__) && !defined(__LP64__)) || \ (defined(__hppa__) && !defined(__LP64__)) || \
...@@ -102,7 +102,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd, ...@@ -102,7 +102,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd,
#else #else
return reinterpret_cast<void*>( return reinterpret_cast<void*>(
syscall(SYS_mmap2, start, length, prot, flags, fd, syscall(SYS_mmap2, start, length, prot, flags, fd,
static_cast<off_t>(offset / pagesize))); static_cast<unsigned long>(offset / pagesize))); // NOLINT
#endif #endif
#elif defined(__s390x__) #elif defined(__s390x__)
// On s390x, mmap() arguments are passed in memory. // On s390x, mmap() arguments are passed in memory.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment