[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:45:16 PDT 2024


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

>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 1/2] [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

>From 08ec6efec40a2f46983530765465ea35ceba9415 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Mon, 24 Jun 2024 10:45:05 -0700
Subject: [PATCH 2/2] reformat

---
 libc/src/sys/mman/linux/mmap.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libc/src/sys/mman/linux/mmap.cpp b/libc/src/sys/mman/linux/mmap.cpp
index e280ac42092a8..b6b68e0892cb9 100644
--- a/libc/src/sys/mman/linux/mmap.cpp
+++ b/libc/src/sys/mman/linux/mmap.cpp
@@ -39,10 +39,9 @@ LLVM_LIBC_FUNCTION(void *, mmap,
 #error "mmap or mmap2 syscalls not available."
 #endif
 
-  long ret =
-      LIBC_NAMESPACE::syscall_impl(syscall_number, reinterpret_cast<long>(addr),
-                                   size, prot, flags, fd,
-                                   static_cast<long>(offset));
+  long ret = LIBC_NAMESPACE::syscall_impl(
+      syscall_number, reinterpret_cast<long>(addr), 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