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