1// Make sure we do not segfault when checking an address close to kLowMemEnd.
2// RUN: %clang_hwasan %s -o %t
3// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4
5// REQUIRES: aarch64-target-arch || riscv64-target-arch
6
7#include <sanitizer/hwasan_interface.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <sys/mman.h>
11
12static volatile char sink;
13extern void *__hwasan_shadow_memory_dynamic_address;
14
15int main(int argc, char **argv) {
16 void *high_addr = (char *)__hwasan_shadow_memory_dynamic_address - 0x1000;
17 void *r = mmap(addr: high_addr, len: 4096, PROT_READ, MAP_FIXED | MAP_ANON | MAP_PRIVATE,
18 fd: -1, offset: 0);
19 if (r == MAP_FAILED) {
20 fprintf(stderr, format: "Failed to mmap\n");
21 abort();
22 }
23 volatile char *x = (char *)__hwasan_tag_pointer(p: r, tag: 4);
24 sink = *x;
25}
26
27// CHECK-NOT: Failed to mmap
28// CHECK-NOT: Segmentation fault
29// CHECK-NOT: SEGV
30

source code of compiler-rt/test/hwasan/TestCases/tag-mismatch-border-address.c