diff options
author | Tom Marshall <tdm@cyngn.com> | 2015-04-28 11:20:05 -0700 |
---|---|---|
committer | Tom Marshall <tdm@cyngn.com> | 2015-04-28 11:20:05 -0700 |
commit | a989f043cfb15e8d9200488f8943ab0a5084c02b (patch) | |
tree | 775c7c65d214d1efe7af09b044898331610ceebf | |
parent | 87cfbd307bd0d2b5bd92ace4a1d94004af6697f2 (diff) | |
download | android_bionic-stable/cm-11.0-XNG3C.tar.gz android_bionic-stable/cm-11.0-XNG3C.tar.bz2 android_bionic-stable/cm-11.0-XNG3C.zip |
bionic: Provide both mmap64 and K-compatible mmapstable/cm-11.0-XNG3C
Change-Id: I555128c516deece65fbed215fc572b141abc6c0e
-rw-r--r-- | libc/bionic/mmap.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/libc/bionic/mmap.cpp b/libc/bionic/mmap.cpp index 75bea588f..651bfd0e5 100644 --- a/libc/bionic/mmap.cpp +++ b/libc/bionic/mmap.cpp @@ -55,5 +55,18 @@ void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offse } 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)); + if (offset & ((1UL << MMAP2_SHIFT)-1)) { + errno = EINVAL; + return MAP_FAILED; + } + + size_t unsigned_offset = static_cast<size_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) { + ErrnoRestorer errno_restorer; + madvise(result, size, MADV_MERGEABLE); + } + + return result; } |