Index: lib/sanitizer_common/sanitizer_allocator_primary64.h =================================================================== --- lib/sanitizer_common/sanitizer_allocator_primary64.h +++ lib/sanitizer_common/sanitizer_allocator_primary64.h @@ -105,8 +105,16 @@ uptr class_id = GetSizeClass(p); uptr size = SizeClassMap::Size(class_id); if (!size) return nullptr; - uptr chunk_idx = GetChunkIdx((uptr)p, size); - uptr reg_beg = (uptr)p & ~(kRegionSize - 1); + uptr chunk_idx; + uptr reg_beg; + if (kUsingConstantSpaceBeg) { + reg_beg = (uptr)p & ~(kRegionSize - 1); + chunk_idx = GetChunkIdx((uptr)p, size); + } else { + reg_beg = (((uptr)p - SpaceBeg()) & ~(kRegionSize - 1)) + SpaceBeg(); + chunk_idx = GetChunkIdx((uptr)p - SpaceBeg(), size); + } + uptr beg = chunk_idx * size; uptr next_beg = beg + size; if (class_id >= kNumClasses) return nullptr; @@ -126,7 +134,11 @@ void *GetMetaData(const void *p) { uptr class_id = GetSizeClass(p); uptr size = SizeClassMap::Size(class_id); - uptr chunk_idx = GetChunkIdx(reinterpret_cast(p), size); + uptr chunk_idx; + if (kUsingConstantSpaceBeg) + chunk_idx = GetChunkIdx(reinterpret_cast(p), size); + else + chunk_idx = GetChunkIdx(reinterpret_cast(p) - SpaceBeg(), size); return reinterpret_cast(SpaceBeg() + (kRegionSize * (class_id + 1)) - (1 + chunk_idx) * kMetadataSize); Index: lib/sanitizer_common/sanitizer_win.cc =================================================================== --- lib/sanitizer_common/sanitizer_win.cc +++ lib/sanitizer_common/sanitizer_win.cc @@ -221,8 +221,13 @@ } void *MmapNoAccess(uptr size) { - // FIXME: unsupported. - return nullptr; + void *res = VirtualAlloc(nullptr, size, + MEM_RESERVE, PAGE_NOACCESS); + if (res == 0) + Report("WARNING: %s failed to " + "mprotect %p (%zd) bytes (error code: %d)\n", + SanitizerToolName, size, size, GetLastError()); + return res; } bool MprotectNoAccess(uptr addr, uptr size) { Index: lib/sanitizer_common/tests/sanitizer_allocator_test.cc =================================================================== --- lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -30,7 +30,8 @@ #if SANITIZER_CAN_USE_ALLOCATOR64 #if SANITIZER_WINDOWS -static const uptr kAllocatorSpace = 0x10000000000ULL; +// Windows 64-bit is using a dynamically allocated address space. +static const uptr kAllocatorSpace = ~(uptr)0; static const uptr kAllocatorSize = 0x10000000000ULL; // 1T. static const u64 kAddressSpaceSize = 1ULL << 40; #else @@ -41,6 +42,8 @@ typedef SizeClassAllocator64< kAllocatorSpace, kAllocatorSize, 16, DefaultSizeClassMap> Allocator64; +typedef SizeClassAllocator64< + ~(uptr)0, kAllocatorSize, 16, DefaultSizeClassMap> Allocator64Dynamic; typedef SizeClassAllocator64< kAllocatorSpace, kAllocatorSize, 16, CompactSizeClassMap> Allocator64Compact; @@ -158,6 +161,10 @@ TestSizeClassAllocator(); } +TEST(SanitizerCommon, SizeClassAllocator64Dynamic) { + TestSizeClassAllocator(); +} + TEST(SanitizerCommon, SizeClassAllocator64Compact) { TestSizeClassAllocator(); } @@ -202,6 +209,10 @@ SizeClassAllocatorMetadataStress(); } +TEST(SanitizerCommon, SizeClassAllocator64DynamicMetadataStress) { + SizeClassAllocatorMetadataStress(); +} + TEST(SanitizerCommon, SizeClassAllocator64CompactMetadataStress) { SizeClassAllocatorMetadataStress(); } @@ -238,6 +249,9 @@ TEST(SanitizerCommon, SizeClassAllocator64GetBlockBegin) { SizeClassAllocatorGetBlockBeginStress(); } +TEST(SanitizerCommon, SizeClassAllocator64DynamicGetBlockBegin) { + SizeClassAllocatorGetBlockBeginStress(); +} TEST(SanitizerCommon, SizeClassAllocator64CompactGetBlockBegin) { SizeClassAllocatorGetBlockBeginStress(); } @@ -484,6 +498,12 @@ SizeClassAllocatorLocalCache > (); } +TEST(SanitizerCommon, CombinedAllocator64Dynamic) { + TestCombinedAllocator, + SizeClassAllocatorLocalCache > (); +} + TEST(SanitizerCommon, CombinedAllocator64Compact) { TestCombinedAllocator, @@ -537,6 +557,11 @@ SizeClassAllocatorLocalCache >(); } +TEST(SanitizerCommon, SizeClassAllocator64DynamicLocalCache) { + TestSizeClassAllocatorLocalCache< + SizeClassAllocatorLocalCache >(); +} + TEST(SanitizerCommon, SizeClassAllocator64CompactLocalCache) { TestSizeClassAllocatorLocalCache< SizeClassAllocatorLocalCache >(); @@ -710,6 +735,9 @@ TEST(SanitizerCommon, SizeClassAllocator64Iteration) { TestSizeClassAllocatorIteration(); } +TEST(SanitizerCommon, SizeClassAllocator64DynamicIteration) { + TestSizeClassAllocatorIteration(); +} #endif TEST(SanitizerCommon, SizeClassAllocator32Iteration) {