35 lines · cpp
1// RUN: %clang_hwasan -O0 %s -o %t && %run %t 2>&12 3// REQUIRES: aarch64-target-arch || x86_64-target-arch || riscv64-target-arch4// REQUIRES: pointer-tagging5 6#include <assert.h>7#include <pthread.h>8#include <sanitizer/hwasan_interface.h>9#include <stdio.h>10#include <stdlib.h>11#include <sys/types.h>12#include <sys/wait.h>13#include <unistd.h>14 15void *volatile sink;16 17int main(int argc, char **argv) {18 pthread_atfork(nullptr, nullptr, []() {19 alarm(5);20 sink = malloc(10);21 });22 int pid = fork();23 if (pid) {24 int wstatus;25 do {26 waitpid(pid, &wstatus, 0);27 } while (!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus));28 if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus)) {29 fprintf(stderr, "abnormal exit\n");30 return 1;31 }32 }33 return 0;34}35