Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd4ef87e authored by Steven Moreland's avatar Steven Moreland
Browse files

RefBase: test for stack check

Surprised this isn't breaking anything, so wanted to
make sure it worked.

Bug: 232557259
Test: libutils_test
Change-Id: Iaec47d644c02dc190e397c6f84dcfab4cc76f566
parent 51e98b83
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -149,8 +149,8 @@ namespace android {
// Same for weak counts.
// Same for weak counts.
#define BAD_WEAK(c) ((c) == 0 || ((c) & (~MAX_COUNT)) != 0)
#define BAD_WEAK(c) ((c) == 0 || ((c) & (~MAX_COUNT)) != 0)


// see utils/StrongPointer.h - declared there for legacy reasons
// name kept because prebuilts used to use it from inlining sp<> code
void sp_report_stack_pointer();
void sp_report_stack_pointer() { LOG_ALWAYS_FATAL("RefBase used with stack pointer argument"); }


// Check whether address is definitely on the calling stack.  We actually check whether it is on
// Check whether address is definitely on the calling stack.  We actually check whether it is on
// the same 4K page as the frame pointer.
// the same 4K page as the frame pointer.
+5 −0
Original line number Original line Diff line number Diff line
@@ -275,6 +275,11 @@ TEST(RefBase, DoubleOwnershipDeath) {
    EXPECT_FALSE(isDeleted);
    EXPECT_FALSE(isDeleted);
}
}


TEST(RefBase, StackOwnershipDeath) {
    bool isDeleted;
    EXPECT_DEATH({ Foo foo(&isDeleted); foo.incStrong(nullptr); }, "");
}

// Set up a situation in which we race with visit2AndRremove() to delete
// Set up a situation in which we race with visit2AndRremove() to delete
// 2 strong references.  Bar destructor checks that there are no early
// 2 strong references.  Bar destructor checks that there are no early
// deletions and prior updates are visible to destructor.
// deletions and prior updates are visible to destructor.
+0 −3
Original line number Original line Diff line number Diff line
@@ -21,7 +21,4 @@
namespace android {
namespace android {


void sp_report_race() { LOG_ALWAYS_FATAL("sp<> assignment detected data race"); }
void sp_report_race() { LOG_ALWAYS_FATAL("sp<> assignment detected data race"); }

void sp_report_stack_pointer() { LOG_ALWAYS_FATAL("sp<> constructed with stack pointer argument"); }

}
}
+0 −1
Original line number Original line Diff line number Diff line
@@ -184,7 +184,6 @@ COMPARE_STRONG_FUNCTIONAL(>=, std::greater_equal)


// For code size reasons, we do not want these inlined or templated.
// For code size reasons, we do not want these inlined or templated.
void sp_report_race();
void sp_report_race();
void sp_report_stack_pointer();


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// No user serviceable parts below here.
// No user serviceable parts below here.