Skip to content

Commit 8bdd22a

Browse files
yoneymeta-codesync[bot]
authored andcommitted
Fix CodePatcher test backing storage
Summary: Use aligned 8-byte storage for the patchpoint and verify patching preserves surrounding memory. The free-threaded x86 implementation currently accesses a full aligned 8-byte word, even for shorter patches. I’ll investigate separately whether this restriction causes issues for other callers. This change only updates the test to match the current implementation. AddressSanitizer: stack-buffer-overflow (/data/users/alperyoney/fbsource3/buck-out/v2/art/fbcode/99380b56af1146f2/cinderx/RuntimeTests/__RuntimeTests_3.14t__/RuntimeTests_3.14t+0x33f081a) (BuildId: 1ff8500db347146bd67e824898b0aca4aff0c28e) in __asan_memcpy Shadow bytes around the buggy address: 0x7b0b76b89d80: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x7b0b76b89e00: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x7b0b76b89e80: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x7b0b76b89f00: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x7b0b76b89f80: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 =>0x7b0b76b8a000: f1 f1 f1 f1 02 f2[02]f2 02 f2 02 f2 00 00 00 f2 0x7b0b76b8a080: f2 f2 f2 f2 f8 f8 f2 f2 f8 f2 f8 f2 f2 f2 f8 f2 0x7b0b76b8a100: f2 f2 00 00 f2 f2 f8 f8 f8 f8 f2 f2 f2 f2 f8 f8 0x7b0b76b8a180: f2 f2 f8 f2 f8 f2 f2 f2 f8 f2 f2 f2 00 00 f2 f2 0x7b0b76b8a200: f8 f8 f8 f8 f2 f2 f2 f2 00 00 f2 f2 f8 f8 f2 f2 0x7b0b76b8a280: f8 f2 f8 f2 f2 f2 f8 f2 f2 f2 00 00 f2 f2 f8 f8 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==1751566==ABORTING ``` Reviewed By: DinoV Differential Revision: D114631917 fbshipit-source-id: 489c4666fc1140ffd8ef9076a3ce5b44f03d2c34
1 parent 58e8651 commit 8bdd22a

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

cinderx/RuntimeTests/deopt_patcher_test.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,35 +75,44 @@ class MyDeoptPatcher : public JumpPatcher {
7575
};
7676

7777
TEST_F(CodePatcherTest, CodePatch) {
78-
// Intentionally leaving these together to catch accidental stack scribbling.
79-
uint16_t x = 123;
80-
uint16_t y = 456;
81-
uint16_t z = 789;
82-
78+
struct PatchpointMemory {
79+
uint64_t before;
80+
alignas(8) std::array<uint8_t, 8> patchpoint;
81+
uint64_t after;
82+
};
83+
84+
const std::array<uint8_t, 8> unpatched{
85+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
86+
const std::array<uint8_t, 8> patched{
87+
0xef, 0xbe, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
88+
89+
constexpr uint64_t kBefore = 0x123456789abcdef0;
90+
constexpr uint64_t kAfter = 0xfedcba9876543210;
91+
PatchpointMemory memory{kBefore, unpatched, kAfter};
8392
std::array<uint8_t, 2> bytes{0xef, 0xbe};
8493

8594
CodePatcher patcher;
8695
EXPECT_FALSE(patcher.isLinked());
8796
EXPECT_FALSE(patcher.isPatched());
8897

89-
patcher.link(reinterpret_cast<uintptr_t>(&y), bytes);
98+
patcher.link(reinterpret_cast<uintptr_t>(memory.patchpoint.data()), bytes);
9099
EXPECT_TRUE(patcher.isLinked());
91100
EXPECT_FALSE(patcher.isPatched());
92-
EXPECT_EQ(x, 123);
93-
EXPECT_EQ(y, 456);
94-
EXPECT_EQ(z, 789);
101+
EXPECT_EQ(memory.before, kBefore);
102+
EXPECT_EQ(memory.patchpoint, unpatched);
103+
EXPECT_EQ(memory.after, kAfter);
95104

96105
patcher.patch();
97106
EXPECT_TRUE(patcher.isPatched());
98-
EXPECT_EQ(x, 123);
99-
EXPECT_EQ(y, 0xbeef);
100-
EXPECT_EQ(z, 789);
107+
EXPECT_EQ(memory.before, kBefore);
108+
EXPECT_EQ(memory.patchpoint, patched);
109+
EXPECT_EQ(memory.after, kAfter);
101110

102111
patcher.unpatch();
103112
EXPECT_FALSE(patcher.isPatched());
104-
EXPECT_EQ(x, 123);
105-
EXPECT_EQ(y, 456);
106-
EXPECT_EQ(z, 789);
113+
EXPECT_EQ(memory.before, kBefore);
114+
EXPECT_EQ(memory.patchpoint, unpatched);
115+
EXPECT_EQ(memory.after, kAfter);
107116
}
108117

109118
TEST_F(CodePatcherTest, DeoptPatch) {

0 commit comments

Comments
 (0)