Bug 1732325 - SharedMemory::FindFreeAddressSpace should use MAP_NORESERVE r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D126510
This commit is contained in:
Petr Sumbera 2021-10-01 08:16:37 +00:00
Родитель b56ca950cf
Коммит 7ee3993e66
1 изменённых файлов: 6 добавлений и 2 удалений

Просмотреть файл

@ -489,6 +489,10 @@ bool SharedMemory::ReadOnlyCopy(SharedMemory* ro_out) {
#endif // not Android #endif // not Android
#ifndef MAP_NORESERVE
# define MAP_NORESERVE 0
#endif
bool SharedMemory::Map(size_t bytes, void* fixed_address) { bool SharedMemory::Map(size_t bytes, void* fixed_address) {
if (!mapped_file_) { if (!mapped_file_) {
return false; return false;
@ -517,8 +521,8 @@ bool SharedMemory::Map(size_t bytes, void* fixed_address) {
} }
void* SharedMemory::FindFreeAddressSpace(size_t size) { void* SharedMemory::FindFreeAddressSpace(size_t size) {
void* memory = void* memory = mmap(nullptr, size, PROT_NONE,
mmap(NULL, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE, -1, 0);
munmap(memory, size); munmap(memory, size);
return memory != MAP_FAILED ? memory : NULL; return memory != MAP_FAILED ? memory : NULL;
} }