8354922: ZGC: Use MAP_FIXED_NOREPLACE when reserving memory

Reviewed-by: aboldtch, eosterlund
This commit is contained in:
Stefan Karlsson 2025-04-22 11:23:40 +00:00
parent 9eeb86d972
commit 0f1c448ca1
2 changed files with 10 additions and 1 deletions

View File

@ -35,6 +35,10 @@
#define MPOL_F_ADDR (1<<1)
#endif
#ifndef MAP_FIXED_NOREPLACE
#define MAP_FIXED_NOREPLACE 0x100000
#endif
class ZSyscall : public AllStatic {
public:
static int memfd_create(const char* name, unsigned int flags);

View File

@ -24,6 +24,9 @@
#include "gc/z/zAddress.inline.hpp"
#include "gc/z/zVirtualMemoryManager.hpp"
#include "logging/log.hpp"
#ifdef LINUX
#include "gc/z/zSyscall_linux.hpp"
#endif
#include <sys/mman.h>
@ -32,7 +35,9 @@ void ZVirtualMemoryReserver::pd_register_callbacks(ZVirtualMemoryRegistry* regis
}
bool ZVirtualMemoryReserver::pd_reserve(zaddress_unsafe addr, size_t size) {
void* const res = mmap((void*)untype(addr), size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
const int flags = MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE LINUX_ONLY(|MAP_FIXED_NOREPLACE);
void* const res = mmap((void*)untype(addr), size, PROT_NONE, flags, -1, 0);
if (res == MAP_FAILED) {
// Failed to reserve memory
return false;