1 // RUN: %clangxx -g %s -o %t 2 // RUN: %env_tool_opts=decorate_proc_maps=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%tool_name 3 // REQUIRES: stable-runtime 4 #include <errno.h> 5 #include <fcntl.h> 6 #include <pthread.h> 7 #include <stdio.h> 8 #include <sys/stat.h> 9 #include <sys/types.h> 10 #include <unistd.h> 11 12 bool CopyFdToFd(int in_fd, int out_fd) { 13 const size_t kBufSize = 0x10000; 14 static char buf[kBufSize]; 15 while (true) { 16 ssize_t got = read(in_fd, buf, kBufSize); 17 if (got > 0) { 18 write(out_fd, buf, got); 19 } else if (got == 0) { 20 break; 21 } else if (errno != EAGAIN || errno != EWOULDBLOCK || errno != EINTR) { 22 fprintf(stderr, "error reading file, errno %d\n", errno); 23 return false; 24 } 25 } 26 return true; 27 } 28 29 void *ThreadFn(void *arg) { 30 (void)arg; 31 int fd = open("/proc/self/maps", O_RDONLY); 32 bool res = CopyFdToFd(fd, 2); 33 close(fd); 34 return (void *)!res; 35 } 36 37 int main(void) { 38 pthread_t t; 39 void *res; 40 pthread_create(&t, 0, ThreadFn, 0); 41 pthread_join(t, &res); 42 return (int)(size_t)res; 43 } 44 45 // CHECK-asan: rw-p {{.*}} [low shadow] 46 // CHECK-asan: ---p {{.*}} [shadow gap] 47 // CHECK-asan: rw-p {{.*}} [high shadow] 48 49 // CHECK-msan: ---p {{.*}} [invalid] 50 // CHECK-msan: rw-p {{.*}} [shadow{{.*}}] 51 // CHECK-msan: ---p {{.*}} [origin{{.*}}] 52 53 // CHECK-tsan: rw-p {{.*}} [shadow] 54 // CHECK-tsan: rw-p {{.*}} [meta shadow] 55 // CHECK-tsan: rw-p {{.*}} [trace 0] 56 // CHECK-tsan: rw-p {{.*}} [trace header 0] 57 // CHECK-tsan: rw-p {{.*}} [trace 1] 58 // CHECK-tsan: rw-p {{.*}} [trace header 1] 59 60 // Nothing interesting with standalone LSan. 61 // CHECK-lsan: decorate_proc_maps 62