]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/sanitizer_common/TestCases/Linux/decorate_proc_maps.cc
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / sanitizer_common / TestCases / Linux / decorate_proc_maps.cc
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-msan: ---p {{.*}} [invalid]
53 // CHECK-msan: rw-p {{.*}} [shadow{{.*}}]
54 // CHECK-msan: ---p {{.*}} [origin{{.*}}]
55
56 // CHECK-tsan: rw-p {{.*}} [shadow]
57 // CHECK-tsan: rw-p {{.*}} [meta shadow]
58 // CHECK-tsan: rw-p {{.*}} [trace 0]
59 // CHECK-tsan: rw-p {{.*}} [trace header 0]
60 // CHECK-tsan: rw-p {{.*}} [trace 1]
61 // CHECK-tsan: rw-p {{.*}} [trace header 1]
62
63 // Nothing interesting with standalone LSan and UBSan.
64 // CHECK-lsan: decorate_proc_maps
65 // CHECK-ubsan: decorate_proc_maps