[compiler-rt] fd9f7b9 - [lsan][test] Obtaining page size using sysconf(_SC_PAGESIZE)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 23 23:28:07 PDT 2023
Author: zhanglimin
Date: 2023-04-24T14:27:41+08:00
New Revision: fd9f7b90109b3fb9a3ac8df5eb4dd966a359c2f4
URL: https://github.com/llvm/llvm-project/commit/fd9f7b90109b3fb9a3ac8df5eb4dd966a359c2f4
DIFF: https://github.com/llvm/llvm-project/commit/fd9f7b90109b3fb9a3ac8df5eb4dd966a359c2f4.diff
LOG: [lsan][test] Obtaining page size using sysconf(_SC_PAGESIZE)
The effectiveness of the mprotect function depends on whether
the first argument is aligned to a page boundary. If mprotect
doesn't work, the kernel will not generate a SIGSEGV signal for
the process when the calling process tries to access memory in
a manner that violates the protection. If so, this test fails.
The problem for this test is that it uses a fixed 4 kB page size
and is aligned. This fails when the page size is not 4 kB. For
example, this fails on LoongArch which uses a 16 kB pagesize.
Reviewed By: SixWeining, xen0n, MaskRay, vitalybuka
Differential Revision: https://reviews.llvm.org/D148407
Added:
Modified:
compiler-rt/test/lsan/TestCases/Linux/leak_check_segv.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/lsan/TestCases/Linux/leak_check_segv.cpp b/compiler-rt/test/lsan/TestCases/Linux/leak_check_segv.cpp
index 88fb217883fcd..faa15445658be 100644
--- a/compiler-rt/test/lsan/TestCases/Linux/leak_check_segv.cpp
+++ b/compiler-rt/test/lsan/TestCases/Linux/leak_check_segv.cpp
@@ -1,18 +1,22 @@
// Test that SIGSEGV during leak checking does not crash the process.
// RUN: %clangxx_lsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: ppc
-#include <stdlib.h>
+#include <sanitizer/lsan_interface.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/mman.h>
-#include <sanitizer/lsan_interface.h>
+#include <unistd.h>
char data[10 * 1024 * 1024];
int main() {
+ long pagesize_mask = sysconf(_SC_PAGESIZE) - 1;
void *p = malloc(10 * 1024 * 1024);
// surprise-surprise!
- mprotect((void*)(((unsigned long)p + 4095) & ~4095), 16 * 1024, PROT_NONE);
- mprotect((void*)(((unsigned long)data + 4095) & ~4095), 16 * 1024, PROT_NONE);
+ mprotect((void *)(((unsigned long)p + pagesize_mask) & ~pagesize_mask),
+ 16 * 1024, PROT_NONE);
+ mprotect((void *)(((unsigned long)data + pagesize_mask) & ~pagesize_mask),
+ 16 * 1024, PROT_NONE);
__lsan_do_leak_check();
fprintf(stderr, "DONE\n");
}
More information about the llvm-commits
mailing list