Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/auxv.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
Expand All @@ -17,17 +18,18 @@
const unsigned char kTag = 42;
const size_t kNumShadowPages = 1024;
const size_t kNumPages = 16 * kNumShadowPages;
const size_t kPageSize = 4096;
const size_t kMapSize = kNumPages * kPageSize;

size_t page_size, map_size;

void sync_rss() {
char *page = (char *)mmap(0, kPageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
char *page = (char *)mmap(0, page_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
// Linux kernel updates RSS counters after a set number of page faults.
for (int i = 0; i < 100; ++i) {
page[0] = 42;
madvise(page, kPageSize, MADV_DONTNEED);
madvise(page, page_size, MADV_DONTNEED);
}
munmap(page, kPageSize);
munmap(page, page_size);
}

size_t current_rss() {
Expand All @@ -45,9 +47,9 @@ size_t current_rss() {
}

int test_rss_difference(void *p) {
__hwasan_tag_memory(p, kTag, kMapSize);
__hwasan_tag_memory(p, kTag, map_size);
size_t rss_before = current_rss();
__hwasan_tag_memory(p, 0, kMapSize);
__hwasan_tag_memory(p, 0, map_size);
size_t rss_after = current_rss();
fprintf(stderr, "%zu -> %zu\n", rss_before, rss_after);
if (rss_before <= rss_after)
Expand All @@ -59,10 +61,14 @@ int test_rss_difference(void *p) {
}

int main() {
page_size = getauxval(AT_PAGESZ);
map_size = kNumPages * page_size;

fprintf(stderr, "starting rss %zu\n", current_rss());
fprintf(stderr, "shadow pages: %zu\n", kNumShadowPages);

void *p = mmap(0, kMapSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
void *p = mmap(0, map_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
fprintf(stderr, "p = %p\n", p);

size_t total_count = 10;
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ int main(int argc, char **argv) {
// CHECKm30: Cause: heap-buffer-overflow
// CHECKm30: is located 30 bytes before a 30-byte region
//
// CHECKMm30: is a large allocated heap chunk; size: 1003520 offset: -30
// CHECKMm30: is a large allocated heap chunk; size: {{[0-9]*}} offset: -30
// CHECKMm30: Cause: heap-buffer-overflow
// CHECKMm30: is located 30 bytes before a 1000000-byte region
//
// CHECKM: is a large allocated heap chunk; size: 1003520 offset: 1000000
// CHECKM: is a large allocated heap chunk; size: {{[0-9]*}} offset: 1000000
// CHECKM: Cause: heap-buffer-overflow
// CHECKM: is located 0 bytes after a 1000000-byte region
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#include <sanitizer/hwasan_interface.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/auxv.h>
#include <sys/mman.h>

static volatile char sink;
extern void *__hwasan_shadow_memory_dynamic_address;

int main(int argc, char **argv) {
void *high_addr = (char *)__hwasan_shadow_memory_dynamic_address - 0x1000;
void *r = mmap(high_addr, 4096, PROT_READ, MAP_FIXED | MAP_ANON | MAP_PRIVATE,
-1, 0);
size_t page_size = getauxval(AT_PAGESZ);
void *high_addr = (char *)__hwasan_shadow_memory_dynamic_address - page_size;
void *r = mmap(high_addr, page_size, PROT_READ,
MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0);
if (r == MAP_FAILED) {
fprintf(stderr, "Failed to mmap\n");
abort();
Expand Down
18 changes: 14 additions & 4 deletions llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ source_set("cxx_sources") {
sources = [ "hwasan_new_delete.cpp" ]
}

source_set("preinit_sources") {
configs -= [ "//llvm/utils/gn/build:llvm_code" ]
configs += [ "//llvm/utils/gn/build:crt_code" ]
defines = [ "HWASAN_WITH_INTERCEPTORS=1" ]
sources = [ "hwasan_preinit.cpp" ]
}

static_library("hwasan_static") {
output_dir = crt_current_out_dir
output_name = "clang_rt.$hwasan_name$crt_current_target_suffix"
Expand All @@ -97,7 +104,10 @@ static_library("hwasan_static") {
"//llvm/utils/gn/build:thin_archive",
]
configs += [ "//llvm/utils/gn/build:crt_code" ]
deps = [ ":sources" ]
deps = [
":preinit_sources",
":sources",
]
}

static_library("hwasan_cxx") {
Expand Down Expand Up @@ -131,22 +141,22 @@ shared_library("hwasan_shared") {

static_library("hwasan_preinit") {
output_dir = crt_current_out_dir
output_name = "clang_rt.${hwasan_name}-preinit$crt_current_target_suffix"
output_name = "clang_rt.hwasan-preinit$crt_current_target_suffix"
complete_static_lib = true
configs -= [
"//llvm/utils/gn/build:llvm_code",
"//llvm/utils/gn/build:thin_archive",
]
configs += [ "//llvm/utils/gn/build:crt_code" ]
sources = [ "hwasan_preinit.cpp" ]
deps = [ ":preinit_sources" ]
}

group("hwasan") {
deps = [
":hwasan_cxx",
":hwasan_preinit",
":hwasan_shared",
":hwasan_static",
":hwasan_cxx",
":version_script",
]
}
2 changes: 1 addition & 1 deletion llvm/utils/gn/secondary/compiler-rt/test/hwasan/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if (current_toolchain != host_toolchain) {
}

supported_toolchains = []
if (host_os == "linux" && host_cpu == "x64") {
if (host_os == "linux" && (host_cpu == "arm64" || host_cpu == "x64")) {
supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
}
if (llvm_build_AArch64 && android_ndk_path != "") {
Expand Down
Loading