From 25899fcec19b92a5fc796da6cf46ee425ea79838 Mon Sep 17 00:00:00 2001 From: Chao-Ying Fu Date: Thu, 16 Aug 2012 18:46:17 -0700 Subject: [PATCH] Support all MAP flags and update mmap_portable. Change-Id: I17600e70028d35dc2f2da05ed4a1b3d7ad051a63 --- .../android/libportable/arch-mips/mmap.c | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ndk/sources/android/libportable/arch-mips/mmap.c b/ndk/sources/android/libportable/arch-mips/mmap.c index 58536b80c..4f83bdb8b 100644 --- a/ndk/sources/android/libportable/arch-mips/mmap.c +++ b/ndk/sources/android/libportable/arch-mips/mmap.c @@ -15,7 +15,6 @@ */ #include -#include #include #include #include @@ -38,37 +37,28 @@ static inline int mips_change_prot(int prot) static inline int mips_change_flags(int flags) { int mipsflags = 0; - /* These are the documented flags for mmap */ if (flags & MAP_SHARED_PORTABLE) mipsflags |= MAP_SHARED; if (flags & MAP_PRIVATE_PORTABLE) mipsflags |= MAP_PRIVATE; -#if defined(MAP_32BIT_PORTABLE) && defined(MAP_32BIT) - if (flags & MAP_32BIT_PORTABLE) - mipsflags |= MAP_32BIT; -#endif - if (flags & MAP_ANONYMOUS_PORTABLE) - mipsflags |= MAP_ANONYMOUS; if (flags & MAP_FIXED_PORTABLE) mipsflags |= MAP_FIXED; + if (flags & MAP_ANONYMOUS_PORTABLE) + mipsflags |= MAP_ANONYMOUS; if (flags & MAP_GROWSDOWN_PORTABLE) mipsflags |= MAP_GROWSDOWN; -#if defined(MAP_HUGETLB_PORTABLE) && defined(MAP_HUGETLB) - if (flags & MAP_HUGETLB_PORTABLE) - mipsflags |= MAP_HUGETLB; -#endif + if (flags & MAP_DENYWRITE_PORTABLE) + mipsflags |= MAP_DENYWRITE; + if (flags & MAP_EXECUTABLE_PORTABLE) + mipsflags |= MAP_EXECUTABLE; if (flags & MAP_LOCKED_PORTABLE) mipsflags |= MAP_LOCKED; - if (flags & MAP_NONBLOCK_PORTABLE) - mipsflags |= MAP_NONBLOCK; if (flags & MAP_NORESERVE_PORTABLE) mipsflags |= MAP_NORESERVE; if (flags & MAP_POPULATE_PORTABLE) mipsflags |= MAP_POPULATE; -#if defined(MAP_STACK_PORTABLE) && defined(MAP_STACK) - if (flags & MAP_STACK_PORTABLE) - mipsflags |= MAP_STACK; -#endif + if (flags & MAP_NONBLOCK_PORTABLE) + mipsflags |= MAP_NONBLOCK; return mipsflags; } @@ -77,11 +67,21 @@ static inline int mips_change_flags(int flags) extern void *__mmap2(void *, size_t, int, int, int, size_t); void *mmap_portable(void *addr, size_t size, int prot, int flags, int fd, long offset) { - if ( offset & ((1UL << MMAP2_SHIFT)-1) ) { + void *ret; + int mips_prot, mips_flags; + + if (offset & ((1UL << MMAP2_SHIFT)-1)) { errno = EINVAL; return MAP_FAILED; } - return __mmap2(addr, size, mips_change_prot(prot), mips_change_flags(flags), - fd, (size_t)offset >> MMAP2_SHIFT); + mips_prot = mips_change_prot(prot); + mips_flags = mips_change_flags(flags); + ret = __mmap2(addr, size, mips_prot, mips_flags, fd, + (size_t)offset >> MMAP2_SHIFT); + + if (ret && (mips_flags & (MAP_PRIVATE | MAP_ANONYMOUS))) + madvise(ret, size, MADV_MERGEABLE); + + return ret; }