Commit 19c6708b authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 9

Allow locking nullptr if the length is 0

Summary:
Because apparently this is valid (and we test it).
This also adds a check in mmap to make sure we aren't passing an invalid handle to `MapViewOfFileEx`.

Reviewed By: yfeldblum

Differential Revision: D3772853

fbshipit-source-id: 11593997a3fb12b7b391c5e52661060b71341aef
parent 6a7f9395
......@@ -64,6 +64,13 @@ int madvise(const void* addr, size_t len, int advise) {
}
int mlock(const void* addr, size_t len) {
// For some strange reason, it's allowed to
// lock a nullptr as long as length is zero.
// VirtualLock doesn't allow it, so handle
// it specially.
if (addr == nullptr && len == 0) {
return 0;
}
if (!VirtualLock((void*)addr, len)) {
return -1;
}
......@@ -106,6 +113,9 @@ void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t off) {
(DWORD)((length >> 32) & 0xFFFFFFFF),
(DWORD)(length & 0xFFFFFFFF),
nullptr);
if (fmh == nullptr) {
return MAP_FAILED;
}
ret = MapViewOfFileEx(
fmh,
accessFlags,
......@@ -148,6 +158,10 @@ int mprotect(void* addr, size_t size, int prot) {
}
int munlock(const void* addr, size_t length) {
// See comment in mlock
if (addr == nullptr && length == 0) {
return 0;
}
if (!VirtualUnlock((void*)addr, length)) {
return -1;
}
......
......@@ -44,6 +44,7 @@
#define PROT_WRITE 2
#define PROT_EXEC 4
#define MADV_NORMAL 0
#define MADV_DONTNEED 0
#define MADV_SEQUENTIAL 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment