brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · f162685 Raw
55 lines · cpp
1// RUN: %clangxx_asan -std=c++11 -O0 %s -o %t2 3// MallocNanoZone=0 disables initialization of the Nano MallocZone on Darwin.4// Initialization of this zone can interfere with this test because the zone5// might log which opens another file descriptor,6// e.g. failing to setup the zone due to ASan taking the memory region it wants.7// RUN: env MallocNanoZone=0 %run %t 2>&1 | FileCheck %s8// RUN: env MallocNanoZone=0 %env_asan_opts=debug=1,verbosity=2 %run %t 2>&1 | FileCheck %s9 10// Test ASan initialization11 12// This test closes the 0, 1, and 2 file descriptors before an exec() and relies13// on them remaining closed across an execve(). This is not the case on newer14// versions of Android. On PPC with ASLR turned on, this fails when linked with15// lld - see https://bugs.llvm.org/show_bug.cgi?id=45076.16// UNSUPPORTED: android, target=powerpc{{.*}}17 18#include <assert.h>19#include <stdio.h>20#include <stdlib.h>21#include <unistd.h>22 23extern "C" const char *__asan_default_options() {24  return "test_only_emulate_no_memorymap=1";25}26 27void parent(int argc, char **argv) {28  fprintf(stderr, "hello\n");29  // CHECK: hello30  close(0);31  close(1);32  dup2(2, 3);33  close(2);34  char *const newargv[] = {argv[0], (char *)"x", nullptr};35  execv(argv[0], newargv);36  perror("execve");37  exit(1);38}39 40void child() {41  assert(dup(3) == 0);42  assert(dup(3) == 1);43  assert(dup(3) == 2);44  fprintf(stderr, "world\n");45  // CHECK: world46}47 48int main(int argc, char **argv) {49  if (argc == 1) {50    parent(argc, argv);51  } else {52    child();53  }54}55