Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / test / pyautolib / asan_stub.c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Fake Address Sanitizer run-time support.
6 // Enough for programs to link and run, but will not find any errors.
7 // Also, linking this to shared libraries voids the warranty.
8 //
9 // We need this fake thunks if we build Chrome with ASAN support because
10 // pyautolib DSO is instrumented with ASAN and is loaded to regular python
11 // process that has no ASAN runtime.
12 //
13 // We have three options here:
14 // 1) use our custom build of Python that have ASAN runtime linked in,
15 // 2) do not instrument pyautolib with ASAN support,
16 // 3) use this fake asan thunks linked to pyautolib so that instrumented code
17 //    does not complain.
18 //
19 // Note that we should not use real ASAN runtime linked with DSO because it will
20 // not have information about memory allocations made prior to DSO load.
21 //
22 // Option (2) is not easy because pyautolib uses code from Chrome
23 // (see chrome_tests.gypi, dependencies for target_name: pyautolib) that
24 // has been instrumented with ASAN. So even if we disable -sanitize=address
25 // for pyautolib own sources, ASAN instrumentation will creep in from there.
26 // To avoid ASAN instrumentation, we might force Chrome build to compile all our
27 // dependencies one more time without -fsanitize=address.
28 //
29 // Note also that using these empty stubs prevents ASAN from catching bugs in
30 // Python-pyautolib process. But we do not need it, we are interested in Chrome
31 // bugs.
32
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <sys/mman.h>
37
38 void __asan_init() {
39   static int inited = 0;
40   if (inited) return;
41   inited = 1;
42 #if __WORDSIZE == 64
43   unsigned long start = 0x100000000000;
44   unsigned long size  = 0x100000000000;
45 #else
46   unsigned long start = 0x20000000;
47   unsigned long size = 0x20000000;
48 #endif
49   void *res = mmap((void*)start, size,
50                    PROT_READ | PROT_WRITE,
51                    MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
52                    0, 0);
53   if (res == (void*)start) {
54     fprintf(stderr, "Fake AddressSanitizer run-time initialized ok at %p\n",
55             res);
56   } else {
57     fprintf(stderr, "Fake AddressSanitizer run-time failed to initialize.\n"
58             "You have been warned. Aborting.");
59     abort();
60   }
61 }
62
63 // Update the name when asan api updates.
64 void __asan_init_v1() {
65   __asan_init();
66 }
67
68 void __asan_init_v3() {
69   static int inited = 0;
70   if (inited) return;
71   inited = 1;
72 #if __WORDSIZE == 64
73   unsigned long start = 0x00007fff8000;
74   unsigned long size  = 0x100000000000;
75 #else
76   unsigned long start = 0x20000000;
77   unsigned long size = 0x20000000;
78 #endif
79   void *res = mmap((void*)start, size,
80                     PROT_READ | PROT_WRITE,
81                     MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
82                     0, 0);
83   if (res == (void*)start) {
84     fprintf(stderr, "Fake AddressSanitizer run-time initialized ok at %p\n",
85            res);
86   } else {
87     fprintf(stderr, "Fake AddressSanitizer run-time failed to initialize.\n"
88     "You have been warned. Aborting.");
89   abort();
90   }
91 }
92
93 void __asan_handle_no_return() { }
94 void __asan_register_globals() { }
95 void __asan_report_load1() { }
96 void __asan_report_load16() { }
97 void __asan_report_load2() { }
98 void __asan_report_load4() { }
99 void __asan_report_load8() { }
100 void __asan_report_load_n() { }
101 void __asan_report_store1() { }
102 void __asan_report_store16() { }
103 void __asan_report_store2() { }
104 void __asan_report_store4() { }
105 void __asan_report_store8() { }
106 void __asan_report_store_n() { }
107 void __asan_set_error_report_callback() { }
108 void __asan_unregister_globals() { }
109 void __sanitizer_sandbox_on_notify() { }
110 void __asan_before_dynamic_init(const char *module_name) { }
111 void __asan_after_dynamic_init() { }
112 int __asan_option_detect_stack_use_after_return;
113 typedef unsigned long long uptr;
114 void __asan_poison_memory_region(void const volatile *addr, uptr size) { }
115 void __asan_unpoison_memory_region(void const volatile *addr, uptr size) { }
116 uptr __asan_stack_malloc_0(uptr size, uptr real_stack) {}
117 uptr __asan_stack_malloc_1(uptr size, uptr real_stack) {}
118 uptr __asan_stack_malloc_2(uptr size, uptr real_stack) {}
119 uptr __asan_stack_malloc_3(uptr size, uptr real_stack) {}
120 uptr __asan_stack_malloc_4(uptr size, uptr real_stack) {}
121 uptr __asan_stack_malloc_5(uptr size, uptr real_stack) {}
122 uptr __asan_stack_malloc_6(uptr size, uptr real_stack) {}
123 uptr __asan_stack_malloc_7(uptr size, uptr real_stack) {}
124 uptr __asan_stack_malloc_8(uptr size, uptr real_stack) {}
125 uptr __asan_stack_malloc_9(uptr size, uptr real_stack) {}
126 uptr __asan_stack_malloc_10(uptr size, uptr real_stack) {}
127 void  __asan_stack_free_0(uptr ptr, uptr size, uptr real_stack) {}
128 void  __asan_stack_free_1(uptr ptr, uptr size, uptr real_stack) {}
129 void  __asan_stack_free_2(uptr ptr, uptr size, uptr real_stack) {}
130 void  __asan_stack_free_3(uptr ptr, uptr size, uptr real_stack) {}
131 void  __asan_stack_free_4(uptr ptr, uptr size, uptr real_stack) {}
132 void  __asan_stack_free_5(uptr ptr, uptr size, uptr real_stack) {}
133 void  __asan_stack_free_6(uptr ptr, uptr size, uptr real_stack) {}
134 void  __asan_stack_free_7(uptr ptr, uptr size, uptr real_stack) {}
135 void  __asan_stack_free_8(uptr ptr, uptr size, uptr real_stack) {}
136 void  __asan_stack_free_9(uptr ptr, uptr size, uptr real_stack) {}
137 void  __asan_stack_free_10(uptr ptr, uptr size, uptr real_stack) {}