[Bug] Don't enable both MAP_JIT and MAP_SHARED (#402)

This commit is contained in:
John Högberg
2023-03-06 10:51:53 +01:00
committed by GitHub
parent d38b12a2b5
commit 1098b7d887

View File

@@ -548,13 +548,17 @@ static inline bool hasMapJitSupport() noexcept {
#endif #endif
} }
// Returns either MAP_JIT or 0 based on `flags` and the host operating system. // Returns either MAP_JIT or 0 based on `memoryFlags` and the host operating system.
static inline int mmMapJitFromMemoryFlags(MemoryFlags memoryFlags) noexcept { static inline int mmMapJitFromMemoryFlags(MemoryFlags memoryFlags) noexcept {
#if defined(__APPLE__) #if defined(__APPLE__)
// Always use MAP_JIT flag if user asked for it (could be used for testing on non-hardened processes) and detect // Always use MAP_JIT flag if user asked for it (could be used for testing on non-hardened processes) and detect
// whether it must be used when the process is actually hardened (in that case it doesn't make sense to rely on // whether it must be used when the process is actually hardened (in that case it doesn't make sense to rely on
// user `memoryFlags`). // user `memoryFlags`).
bool useMapJit = Support::test(memoryFlags, MemoryFlags::kMMapEnableMapJit) || hasHardenedRuntime(); //
// MAP_JIT is not required when dual-mapping memory and is incompatible with MAP_SHARED, so it will not be
// added when the latter is enabled.
bool useMapJit = (Support::test(memoryFlags, MemoryFlags::kMMapEnableMapJit) || hasHardenedRuntime())
&& !Support::test(memoryFlags, MemoryFlags::kMapShared);
if (useMapJit) if (useMapJit)
return hasMapJitSupport() ? int(MAP_JIT) : 0; return hasMapJitSupport() ? int(MAP_JIT) : 0;
else else