50 lines · c
1// On x86_64, the kernel does not provide the faulting address for dereferences2// of addresses greater than the 48-bit hardware addressable range, i.e.,3// `siginfo.si_addr` is zero in ASan's SEGV signal handler. This test checks4// that ASan does not misrepresent such cases as "NULL dereferences".5 6// REQUIRES: x86_64-target-arch7// RUN: %clang_asan %s -o %t8// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE09// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE010// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE11// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR12// RUN: %env_asan_opts=print_scariness=1 not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR13 14#include <stdint.h>15#include <stdlib.h>16 17int main(int argc, const char *argv[]) {18 const char *hex = argv[1];19 uint64_t *addr = (uint64_t *)strtoull(hex, NULL, 16);20 uint64_t x = *addr; // segmentation fault21 return x;22}23 24// ZERO: SEGV on unknown address 0x000000000000 (pc25// LOW1: SEGV on unknown address 0x000000000fff (pc26// LOW2: SEGV on unknown address 0x000000001000 (pc27// HIGH: {{BUS|SEGV}} on unknown address (pc28// MAX: {{BUS|SEGV}} on unknown address (pc29 30// HINT-PAGE0-NOT: Hint: this fault was caused by a dereference of a high value address31// HINT-PAGE0: Hint: address points to the zero page.32 33// HINT-NONE-NOT: Hint: this fault was caused by a dereference of a high value address34// HINT-NONE-NOT: Hint: address points to the zero page.35 36// HINT-HIGHADDR: Hint: this fault was caused by a dereference of a high value address37// HINT-HIGHADDR-NOT: Hint: address points to the zero page.38 39// ZERO: SCARINESS: 10 (null-deref)40// LOW1: SCARINESS: 10 (null-deref)41// LOW2: SCARINESS: 20 (wild-addr-read)42// HIGH: SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}43// MAX: SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}44 45// TODO: Currently, register values are only printed on Mac. Once this changes,46// remove the 'TODO_' prefix in the following lines.47// TODO_HIGH,TODO_MAX: Register values:48// TODO_HIGH: = 0x414141414141414149// TODO_MAX: = 0xffffffffffffffff50