Revert "[Scudo] Use GWP-ASan's aligned allocations and fixup postalloc hooks."
This reverts commit a683abe5c026cffff12a943564f4cb1b20972abf.
Broke the upstream buildbots:
https://lab.llvm.org/buildbot/#/builders/37/builds/3731/steps/16/logs/stdio
GitOrigin-RevId: 643ccf6e4b85ad1edae48e64c178bf6b00991a96
diff --git a/combined.h b/combined.h
index 4c95b87..33ae6c4 100644
--- a/combined.h
+++ b/combined.h
@@ -290,7 +290,19 @@
bool ZeroContents = false) {
initThreadMaybe();
+#ifdef GWP_ASAN_HOOKS
+ if (UNLIKELY(GuardedAlloc.shouldSample())) {
+ if (void *Ptr = GuardedAlloc.allocate(roundUpTo(Size, Alignment)))
+ return Ptr;
+ }
+#endif // GWP_ASAN_HOOKS
+
const Options Options = Primary.Options.load();
+ const FillContentsMode FillContents = ZeroContents ? ZeroFill
+ : TSDRegistry.getDisableMemInit()
+ ? NoFill
+ : Options.getFillContentsMode();
+
if (UNLIKELY(Alignment > MaxAlignment)) {
if (Options.get(OptionBit::MayReturnNull))
return nullptr;
@@ -299,22 +311,6 @@
if (Alignment < MinAlignment)
Alignment = MinAlignment;
-#ifdef GWP_ASAN_HOOKS
- if (UNLIKELY(GuardedAlloc.shouldSample())) {
- if (void *Ptr = GuardedAlloc.allocate(Size, Alignment)) {
- if (UNLIKELY(&__scudo_allocate_hook))
- __scudo_allocate_hook(Ptr, Size);
- Stats.add(StatAllocated, Size);
- return Ptr;
- }
- }
-#endif // GWP_ASAN_HOOKS
-
- const FillContentsMode FillContents = ZeroContents ? ZeroFill
- : TSDRegistry.getDisableMemInit()
- ? NoFill
- : Options.getFillContentsMode();
-
// If the requested size happens to be 0 (more common than you might think),
// allocate MinAlignment bytes on top of the header. Then add the extra
// bytes required to fulfill the alignment requirements: we allocate enough
@@ -507,20 +503,18 @@
// being destroyed properly. Any other heap operation will do a full init.
initThreadMaybe(/*MinimalInit=*/true);
+#ifdef GWP_ASAN_HOOKS
+ if (UNLIKELY(GuardedAlloc.pointerIsMine(Ptr))) {
+ GuardedAlloc.deallocate(Ptr);
+ return;
+ }
+#endif // GWP_ASAN_HOOKS
+
if (UNLIKELY(&__scudo_deallocate_hook))
__scudo_deallocate_hook(Ptr);
if (UNLIKELY(!Ptr))
return;
-
-#ifdef GWP_ASAN_HOOKS
- if (UNLIKELY(GuardedAlloc.pointerIsMine(Ptr))) {
- GuardedAlloc.deallocate(Ptr);
- Stats.add(StatFree, GuardedAlloc.getSize(Ptr));
- return;
- }
-#endif // GWP_ASAN_HOOKS
-
if (UNLIKELY(!isAligned(reinterpret_cast<uptr>(Ptr), MinAlignment)))
reportMisalignedPointer(AllocatorAction::Deallocating, Ptr);
@@ -577,7 +571,6 @@
if (NewPtr)
memcpy(NewPtr, OldPtr, (NewSize < OldSize) ? NewSize : OldSize);
GuardedAlloc.deallocate(OldPtr);
- Stats.add(StatFree, OldSize);
return NewPtr;
}
#endif // GWP_ASAN_HOOKS
diff --git a/tests/wrappers_c_test.cpp b/tests/wrappers_c_test.cpp
index eed8f03..e8872a1 100644
--- a/tests/wrappers_c_test.cpp
+++ b/tests/wrappers_c_test.cpp
@@ -94,18 +94,6 @@
EXPECT_EQ(errno, ENOMEM);
}
-TEST(ScudoWrappersCTest, SmallAlign) {
- void *P;
- for (size_t Size = 1; Size <= 0x10000; Size <<= 1) {
- for (size_t Align = 1; Align <= 0x10000; Align <<= 1) {
- for (size_t Count = 0; Count < 3; ++Count) {
- P = memalign(Align, Size);
- EXPECT_TRUE(reinterpret_cast<uintptr_t>(P) % Align == 0);
- }
- }
- }
-}
-
TEST(ScudoWrappersCTest, Memalign) {
void *P;
for (size_t I = FIRST_32_SECOND_64(2U, 3U); I <= 18U; I++) {
diff --git a/tests/wrappers_cpp_test.cpp b/tests/wrappers_cpp_test.cpp
index 9df06dc..d24b665 100644
--- a/tests/wrappers_cpp_test.cpp
+++ b/tests/wrappers_cpp_test.cpp
@@ -66,10 +66,6 @@
};
TEST(ScudoWrappersCppTest, New) {
- if (getenv("SKIP_TYPE_MISMATCH")) {
- printf("Skipped type mismatch tests.\n");
- return;
- }
testCxxNew<bool>();
testCxxNew<uint8_t>();
testCxxNew<uint16_t>();