|
23 | 23 | #error Bad build environment
|
24 | 24 | #endif
|
25 | 25 |
|
26 |
| -static inline int mips_change_prot(int prot) |
| 26 | +#define PORTABLE_TAG "mmap_portable" |
| 27 | +#include <log_portable.h> |
| 28 | + |
| 29 | +static inline int mmap_prot_pton(int portable_prot) |
27 | 30 | {
|
| 31 | + int native_prot = portable_prot; |
| 32 | + |
| 33 | + ALOGV("%s(portable_prot:0x%x) {", __func__, portable_prot); |
| 34 | + |
28 | 35 | /* Only PROT_SEM is different */
|
29 |
| - if (prot & PROT_SEM_PORTABLE) { |
30 |
| - prot &= ~PROT_SEM_PORTABLE; |
31 |
| - prot |= PROT_SEM; |
| 36 | + if (portable_prot & PROT_SEM_PORTABLE) { |
| 37 | + native_prot &= ~PROT_SEM_PORTABLE; |
| 38 | + native_prot |= PROT_SEM; |
32 | 39 | }
|
33 | 40 |
|
34 |
| - return prot; |
| 41 | + ALOGV("%s: return(native_prot:0x%x); }", __func__, native_prot); |
| 42 | + return native_prot; |
35 | 43 | }
|
36 | 44 |
|
37 |
| -static inline int mips_change_flags(int flags) |
| 45 | + |
| 46 | +static inline int mmap_flags_pton(int portable_flags) |
38 | 47 | {
|
39 |
| - int mipsflags = 0; |
40 |
| - if (flags & MAP_SHARED_PORTABLE) |
41 |
| - mipsflags |= MAP_SHARED; |
42 |
| - if (flags & MAP_PRIVATE_PORTABLE) |
43 |
| - mipsflags |= MAP_PRIVATE; |
44 |
| - if (flags & MAP_FIXED_PORTABLE) |
45 |
| - mipsflags |= MAP_FIXED; |
46 |
| - if (flags & MAP_ANONYMOUS_PORTABLE) |
47 |
| - mipsflags |= MAP_ANONYMOUS; |
48 |
| - if (flags & MAP_GROWSDOWN_PORTABLE) |
49 |
| - mipsflags |= MAP_GROWSDOWN; |
50 |
| - if (flags & MAP_DENYWRITE_PORTABLE) |
51 |
| - mipsflags |= MAP_DENYWRITE; |
52 |
| - if (flags & MAP_EXECUTABLE_PORTABLE) |
53 |
| - mipsflags |= MAP_EXECUTABLE; |
54 |
| - if (flags & MAP_LOCKED_PORTABLE) |
55 |
| - mipsflags |= MAP_LOCKED; |
56 |
| - if (flags & MAP_NORESERVE_PORTABLE) |
57 |
| - mipsflags |= MAP_NORESERVE; |
58 |
| - if (flags & MAP_POPULATE_PORTABLE) |
59 |
| - mipsflags |= MAP_POPULATE; |
60 |
| - if (flags & MAP_NONBLOCK_PORTABLE) |
61 |
| - mipsflags |= MAP_NONBLOCK; |
62 |
| - |
63 |
| - return mipsflags; |
| 48 | + int native_flags = 0; |
| 49 | + |
| 50 | + ALOGV("%s(portable_flags:0x%x) {", __func__, portable_flags); |
| 51 | + |
| 52 | + if (portable_flags & MAP_SHARED_PORTABLE) { |
| 53 | + native_flags |= MAP_SHARED; |
| 54 | + } |
| 55 | + if (portable_flags & MAP_PRIVATE_PORTABLE) { |
| 56 | + native_flags |= MAP_PRIVATE; |
| 57 | + } |
| 58 | + if (portable_flags & MAP_FIXED_PORTABLE) { |
| 59 | + native_flags |= MAP_FIXED; |
| 60 | + } |
| 61 | + if (portable_flags & MAP_ANONYMOUS_PORTABLE) { |
| 62 | + native_flags |= MAP_ANONYMOUS; |
| 63 | + } |
| 64 | + if (portable_flags & MAP_GROWSDOWN_PORTABLE) { |
| 65 | + native_flags |= MAP_GROWSDOWN; |
| 66 | + } |
| 67 | + if (portable_flags & MAP_DENYWRITE_PORTABLE) { |
| 68 | + native_flags |= MAP_DENYWRITE; |
| 69 | + } |
| 70 | + if (portable_flags & MAP_EXECUTABLE_PORTABLE) { |
| 71 | + native_flags |= MAP_EXECUTABLE; |
| 72 | + } |
| 73 | + if (portable_flags & MAP_LOCKED_PORTABLE) { |
| 74 | + native_flags |= MAP_LOCKED; |
| 75 | + } |
| 76 | + if (portable_flags & MAP_NORESERVE_PORTABLE) { |
| 77 | + native_flags |= MAP_NORESERVE; |
| 78 | + } |
| 79 | + if (portable_flags & MAP_POPULATE_PORTABLE) { |
| 80 | + native_flags |= MAP_POPULATE; |
| 81 | + } |
| 82 | + if (portable_flags & MAP_NONBLOCK_PORTABLE) { |
| 83 | + native_flags |= MAP_NONBLOCK; |
| 84 | + } |
| 85 | + |
| 86 | + ALOGV("%s: return(native_flags:0x%x); }", __func__, native_flags); |
| 87 | + return native_flags; |
64 | 88 | }
|
65 | 89 |
|
66 |
| -#define MMAP2_SHIFT 12 |
67 |
| -extern void *__mmap2(void *, size_t, int, int, int, size_t); |
68 |
| -void *mmap_portable(void *addr, size_t size, int prot, int flags, int fd, long offset) |
| 90 | + |
| 91 | +void *mmap_portable(void *addr, size_t size, int prot, int flags, int fd, long byte_offset) |
69 | 92 | {
|
70 |
| - void *ret; |
71 |
| - int mips_prot, mips_flags; |
| 93 | + int native_prot, native_flags; |
| 94 | + int saved_errno; |
| 95 | + void *ret_addr; |
72 | 96 |
|
73 |
| - if (offset & ((1UL << MMAP2_SHIFT)-1)) { |
74 |
| - errno = EINVAL; |
75 |
| - return MAP_FAILED; |
76 |
| - } |
| 97 | + ALOGV(" "); |
| 98 | + ALOGV("%s(addr:%p, size:%d, prot:0x%x, flags:0x%x, fd:%d, byte_offset:0x%lx) {", __func__, |
| 99 | + addr, size, prot, flags, fd, byte_offset); |
77 | 100 |
|
78 |
| - mips_prot = mips_change_prot(prot); |
79 |
| - mips_flags = mips_change_flags(flags); |
80 |
| - ret = __mmap2(addr, size, mips_prot, mips_flags, fd, |
81 |
| - (size_t)offset >> MMAP2_SHIFT); |
| 101 | + native_prot = mmap_prot_pton(prot); |
| 102 | + native_flags = mmap_flags_pton(flags); |
82 | 103 |
|
83 |
| - if (ret && (mips_flags & (MAP_PRIVATE | MAP_ANONYMOUS))) |
84 |
| - madvise(ret, size, MADV_MERGEABLE); |
| 104 | + ret_addr = mmap(addr, size, native_prot, native_flags, fd, byte_offset); |
85 | 105 |
|
86 |
| - return ret; |
| 106 | + ALOGV("%s: return(ret_addr:%p); }", __func__, ret_addr); |
| 107 | + return ret_addr; |
87 | 108 | }
|
88 | 109 |
|
89 |
| -extern int mprotect(const void *, size_t, int); |
90 |
| -int mprotect_portable(const void *addr, size_t size, int prot) |
| 110 | + |
| 111 | +extern int mprotect(const void *, size_t, int); |
| 112 | + |
| 113 | +int mprotect_portable(const void *addr, size_t size, int portable_prot) |
91 | 114 | {
|
92 |
| - return mprotect(addr, size, mips_change_prot(prot)); |
| 115 | + int rv; |
| 116 | + int native_prot; |
| 117 | + |
| 118 | + ALOGV(" "); |
| 119 | + ALOGV("%s(addr:%p, size:%d, portable_prot:0x%x); {", __func__, |
| 120 | + addr, size, portable_prot); |
| 121 | + |
| 122 | + native_prot = mmap_prot_pton(portable_prot); |
| 123 | + |
| 124 | + rv = mprotect(addr, size, native_prot); |
| 125 | + |
| 126 | + ALOGV("%s: return(rv:%d); }", __func__, rv); |
| 127 | + return rv; |
93 | 128 | }
|
0 commit comments