40 lines · cpp
1// RUN: %clangxx_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s2 3#include <sanitizer/hwasan_interface.h>4 5#include <stdio.h>6#include <stdlib.h>7#include <sys/mman.h>8#include <unistd.h>9 10int main(int argc, char **argv) {11 const size_t kPS = sysconf(_SC_PAGESIZE);12 13 void *r = nullptr;14 int res = posix_memalign(&r, kPS, 2 * kPS);15 if (res) {16 perror("Failed to mmap: ");17 abort();18 }19 20 r = __hwasan_tag_pointer(r, 0);21 __hwasan_tag_memory(r, 1, 2 * kPS);22 23 // Disable access to the page just after tag-mismatch report address.24 res = mprotect((char*)r + kPS, kPS, PROT_NONE);25 if (res) {26 perror("Failed to mprotect: ");27 abort();28 }29 30 // Trigger tag-mismatch report.31 return *((char*)r + kPS - 1);32}33 34// CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address35// CHECK: Memory tags around the buggy address36// CHECK: Tags for short granules around37 38// Check that report is complete.39// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main40