Merge "Add mmap64()"
This commit is contained in:
commit
f8e71bac14
@ -37,13 +37,13 @@ extern "C" void* __mmap2(void*, size_t, int, int, int, size_t);
|
|||||||
|
|
||||||
#define MMAP2_SHIFT 12 // 2**12 == 4096
|
#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)) {
|
if (offset & ((1UL << MMAP2_SHIFT)-1)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return MAP_FAILED;
|
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);
|
void* result = __mmap2(addr, size, prot, flags, fd, unsigned_offset >> MMAP2_SHIFT);
|
||||||
|
|
||||||
if (result != MAP_FAILED && (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) != 0) {
|
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;
|
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));
|
||||||
|
}
|
||||||
|
@ -45,6 +45,7 @@ __BEGIN_DECLS
|
|||||||
#define MREMAP_FIXED 2
|
#define MREMAP_FIXED 2
|
||||||
|
|
||||||
extern void* mmap(void *, size_t, int, int, int, off_t);
|
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 munmap(void *, size_t);
|
||||||
extern int msync(const void *, size_t, int);
|
extern int msync(const void *, size_t, int);
|
||||||
extern int mprotect(const void *, size_t, int);
|
extern int mprotect(const void *, size_t, int);
|
||||||
|
Loading…
Reference in New Issue
Block a user