From 45221684f3e3d985f91a1a896cac616c537516e2 Mon Sep 17 00:00:00 2001 From: Bin Lu Date: Tue, 2 Jun 2020 04:25:32 -0400 Subject: [PATCH] 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(addr), machine_code, sizeof(machine_code)); isb() func = reinterpret_cast(addr); Signed-off-by: Bin Lu --- test/syscalls/linux/mmap.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/syscalls/linux/mmap.cc b/test/syscalls/linux/mmap.cc index 6d3227ab6..a523ce189 100644 --- a/test/syscalls/linux/mmap.cc +++ b/test/syscalls/linux/mmap.cc @@ -589,6 +589,11 @@ TEST_F(MMapTest, ProtExec) { memcpy(reinterpret_cast(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(addr); EXPECT_EQ(42, func());