aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Leung <daniel.leung@intel.com>2013-09-18 14:41:18 -0700
committerScott Mertz <scott@cyngn.com>2015-04-28 11:05:17 -0700
commit87cfbd307bd0d2b5bd92ace4a1d94004af6697f2 (patch)
treec0f6f12dcc55e10cb3cc272c67939dbb6ec9a9c3
parent1f5706c7eb8aacb76fdfa3ef03944be229510b66 (diff)
downloadandroid_bionic-87cfbd307bd0d2b5bd92ace4a1d94004af6697f2.tar.gz
android_bionic-87cfbd307bd0d2b5bd92ace4a1d94004af6697f2.tar.bz2
android_bionic-87cfbd307bd0d2b5bd92ace4a1d94004af6697f2.zip
Add mmap64()
This adds mmap64() to bionic so that it is possible to have large offset passed to kernel. However, the syscall mechanism only passes 32-bit number to kernel. So effectively, the largest offset that can be passed is about 43 bits (since offset is signed, and the number passed to kernel is number of pages (page size == 4K => 12 bits)). Change-Id: Ib54f4e9b54acb6ef8b0324f3b89c9bc810b07281 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
-rw-r--r--libc/bionic/mmap.cpp8
-rw-r--r--libc/include/sys/mman.h1
2 files changed, 7 insertions, 2 deletions
diff --git a/libc/bionic/mmap.cpp b/libc/bionic/mmap.cpp
index febc459fa..75bea588f 100644
--- a/libc/bionic/mmap.cpp
+++ b/libc/bionic/mmap.cpp
@@ -37,13 +37,13 @@ extern "C" void* __mmap2(void*, size_t, int, int, int, size_t);
#define MMAP2_SHIFT 12 // 2**12 == 4096
-void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) {
+void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offset) {
if (offset & ((1UL << MMAP2_SHIFT)-1)) {
errno = EINVAL;
return MAP_FAILED;
}
- size_t unsigned_offset = static_cast<size_t>(offset); // To avoid sign extension.
+ uint64_t unsigned_offset = static_cast<uint64_t>(offset); // To avoid sign extension.
void* result = __mmap2(addr, size, prot, flags, fd, unsigned_offset >> MMAP2_SHIFT);
if (result != MAP_FAILED && (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) != 0) {
@@ -53,3 +53,7 @@ void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) {
return result;
}
+
+void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) {
+ return mmap64(addr, size, prot, flags, fd, static_cast<off64_t>(offset));
+}
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index 7a3297430..7c5f8d774 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -45,6 +45,7 @@ __BEGIN_DECLS
#define MREMAP_FIXED 2
extern void* mmap(void *, size_t, int, int, int, off_t);
+extern void* mmap64(void *, size_t, int, int, int, off64_t);
extern int munmap(void *, size_t);
extern int msync(const void *, size_t, int);
extern int mprotect(const void *, size_t, int);