[libc-commits] [libc] [libc][mmap] force offset to long for mmap2 (PR #96522)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Jun 24 10:43:50 PDT 2024


https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/96522

llvm-libc's "Large File Support" isn't really complete.  We define off_t to be
a uint64_t always, which breaks with convention in an attempt to drop
historical baggage. We might need to revisit that decision in the future, but
for now, force off_t to long when using mmap2.

This avoids having to pass a 64b value to our syscall wrappers for 32b targets,
which we do not support on arm32.  Since we're using mmap2 rather than mmap, we
don't need a 64b value anyways.

Our mmap implementation still has further room for improvement...

>From 02a69e40ee097d021d64b25e1383af124da1ed99 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Mon, 24 Jun 2024 10:35:43 -0700
Subject: [PATCH] [libc][mmap] force offset to long for mmap2

llvm-libc's "Large File Support" isn't really complete.  We define off_t to be
a uint64_t always, which breaks with convention in an attempt to drop
historical baggage. We might need to revisit that decision in the future, but
for now, force off_t to long when using mmap2.

This avoids having to pass a 64b value to our syscall wrappers for 32b targets,
which we do not support on arm32.  Since we're using mmap2 rather than mmap, we
don't need a 64b value anyways.

Our mmap implementation still has further room for improvement...
---
 libc/src/sys/mman/linux/mmap.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libc/src/sys/mman/linux/mmap.cpp b/libc/src/sys/mman/linux/mmap.cpp
index 16111c66859f5..e280ac42092a8 100644
--- a/libc/src/sys/mman/linux/mmap.cpp
+++ b/libc/src/sys/mman/linux/mmap.cpp
@@ -41,7 +41,8 @@ LLVM_LIBC_FUNCTION(void *, mmap,
 
   long ret =
       LIBC_NAMESPACE::syscall_impl(syscall_number, reinterpret_cast<long>(addr),
-                                   size, prot, flags, fd, offset);
+                                   size, prot, flags, fd,
+                                   static_cast<long>(offset));
 
   // The mmap/mmap2 syscalls return negative values on error. These negative
   // values are actually the negative values of the error codes. So, fix them



More information about the libc-commits mailing list