mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
avoid the random memory barrier issue in mmap testing on Arm64
There is a new random issue on some Arm64 machines. This scene can be summarized as following: Sometimes, the content of the func() pointer is still 0 opcode. The probability of this kind of issue is very low, currently only available on some machines. After inserting a simple memory barrier, this issue was gone. The code to directly use the memory barrier is as follows: memcpy(reinterpret_cast<void*>(addr), machine_code, sizeof(machine_code)); isb() func = reinterpret_cast<uint32_t (*)(void)>(addr); Signed-off-by: Bin Lu <bin.lu@arm.com>
This commit is contained in:
@@ -589,6 +589,11 @@ TEST_F(MMapTest, ProtExec) {
|
||||
|
||||
memcpy(reinterpret_cast<void*>(addr), machine_code, sizeof(machine_code));
|
||||
|
||||
#if defined(__aarch64__)
|
||||
// We use this as a memory barrier for Arm64.
|
||||
ASSERT_THAT(Protect(addr, kPageSize, PROT_READ | PROT_EXEC), SyscallSucceeds());
|
||||
#endif
|
||||
|
||||
func = reinterpret_cast<uint32_t (*)(void)>(addr);
|
||||
|
||||
EXPECT_EQ(42, func());
|
||||
|
||||
Reference in New Issue
Block a user