libcasr/
constants.rs

1//! Constants for signals and stack trace filtering.
2/* Copyright 2020 Google LLC
3Modifications copyright (C) 2023 ISP RAS
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17
18/// Regular expressions for java functions to be ignored.
19pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_JAVA: &[&str] = &[
20    r"^java\.base",
21    r"^java\.lang",
22    r"^java\.beans",
23    r"^java\.time",
24    r"^java\.math",
25    r"^java\.rmi",
26    r"^java\.net",
27    r"^java\.security",
28    r"^java\.text",
29    r"^java\.awt",
30    r"^java\.n?io",
31    r"^javax\.",
32];
33
34/// Regular expressions for JS functions to be ignored.
35pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_JS: &[&str] = &[
36    // TODO
37    r"^<anonymous>$",
38];
39
40/// Regular expressions for lua functions to be ignored.
41pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_LUA: &[&str] = &[
42    // TODO
43    r"^[^.]$",
44];
45
46/// Regular expressions for python functions to be ignored.
47pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_PYTHON: &[&str] = &[
48    // TODO
49    r"^[^.]$",
50];
51
52/// Regular expressions for rust functions to be ignored.
53pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_RUST: &[&str] = &[
54    r"^rust_begin_unwind",
55    r"^rust_fuzzer_test_input",
56    r"^rust_oom",
57    r"^rust_panic",
58    r"^std::io::Write::write_fmt",
59    r"^std::panic",
60    r"^std::process::abort",
61    r"^__rust_start_panic",
62    r"^core::fmt::write",
63    r"^core::panicking",
64    r"^core::result",
65    r"^panic_abort::",
66    r"^__rust_try",
67];
68
69/// Regular expressions for Go functions to be ignored.
70pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_GO: &[&str] = &[
71    // TODO
72    r"^runtime\.",
73];
74
75/// Regular expressions for cpp functions to be ignored.
76pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_CPP: &[&str] = &[
77    // Function names (exact match).
78    r"^abort$",
79    r"^exit$",
80    r"^pthread_create$",
81    r"^pthread_kill$",
82    r"^raise$",
83    r"^tgkill$",
84    r"^__chk_fail$",
85    r"^__fortify_fail$",
86    // Function names (startswith).
87    r"^(|__)aeabi_",
88    r"^(|__)memcmp",
89    r"^(|__)memcpy",
90    r"^(|__)memmove",
91    r"^(|__)memset",
92    r"^(|__)strcmp",
93    r"^(|__)strcpy",
94    r"^(|__)strdup",
95    r"^(|__)strlen",
96    r"^(|__)strncpy",
97    r"^<null>",
98    r"^Abort\(",
99    r"^CFCrash",
100    r"^ExitCallback",
101    r"^IsSandboxedProcess",
102    r"^MSanAtExitWrapper",
103    r"^New",
104    r"^RaiseException",
105    r"^SbSystemBreakIntoDebugger",
106    r"^SignalAction",
107    r"^SignalHandler",
108    r"^TestOneProtoInput",
109    r"^WTF::",
110    r"^WTFCrash",
111    r"^X11Error",
112    r"^_L_unlock_",
113    r"^__GI_",
114    r"^__asan::",
115    r"^__asan_",
116    r"^__assert_",
117    r"^__cxa_atexit",
118    r"^__cxa_rethrow",
119    r"^__cxa_throw",
120    r"^throw_exception",
121    r"^__dump_stack",
122    r"^__hwasan::",
123    r"^__hwasan_",
124    r"^__interceptor_",
125    r"^__kasan_",
126    r"^__libc_",
127    r"^__lsan::",
128    r"^__lsan_",
129    r"^__msan::",
130    r"^__msan_",
131    r"^__pthread_kill",
132    r"^__run_exit_handlers",
133    r"^__rust_try",
134    r"^__sanitizer::",
135    r"^__sanitizer_",
136    r"^__tsan::",
137    r"^__tsan_",
138    r"^__ubsan::",
139    r"^__ubsan_",
140    r"^_asan_",
141    r"^_hwasan_",
142    r"^_lsan_",
143    r"^_msan_",
144    r"^_objc_terminate",
145    r"^_sanitizer_",
146    r"^_start",
147    r"^__libc_start_main",
148    r"^_tsan_",
149    r"^_ubsan_",
150    r"^abort",
151    r"^alloc::",
152    r"^android\.app\.ActivityManagerProxy\.",
153    r"^android\.os\.Parcel\.",
154    r"^art::Thread::CreateNativeThread",
155    r"^asan_",
156    r"^asan\.module_ctor",
157    r"^asan\.module_dtor",
158    r"^calloc",
159    r"^check_memory_region",
160    r"^common_exit",
161    r"^delete",
162    r"^demangling_terminate_handler",
163    r"^bt_terminate_handler",
164    r"^dump_backtrace",
165    r"^dump_stack",
166    r"^exit_or_terminate_process",
167    r"^fpehandler\(",
168    r"^free",
169    r"^g_log",
170    r"^generic_cpp_",
171    r"^gsignal",
172    r"^kasan_",
173    // LibFuzzer
174    r"^fuzzer::",
175    r"^libfuzzer_sys::initialize",
176    //r"^main",
177    r"^malloc",
178    r"^mozalloc_",
179    r"^new",
180    r"^object_err",
181    r"^operator",
182    r"^print_trailer",
183    r"^realloc",
184    r"^report_failure",
185    r"^scanf",
186    r"^show_stack",
187    r"^std::__terminate",
188    r"^std::terminate",
189    r"^std::sys::unix::abort",
190    r"^std::sys_common::backtrace",
191    r"^__scrt_common_main_seh",
192    // Functions names (contains).
193    r".*ASAN_OnSIGSEGV",
194    r".*BaseThreadInitThunk",
195    r".*DebugBreak",
196    r".*DefaultDcheckHandler",
197    r".*ForceCrashOnSigAbort",
198    r".*MemoryProtection::CMemoryProtector",
199    r".*PartitionAlloc",
200    r".*RtlFreeHeap",
201    r".*RtlInitializeExceptionChain",
202    r".*RtlReportCriticalFailure",
203    r".*RtlUserThreadStart",
204    r".*RtlpHeapHandleError",
205    r".*RtlpLogHeapFailure",
206    r".*SkDebugf",
207    r".*StackDumpSignalHandler",
208    r".*__android_log_assert",
209    r".*__tmainCRTStartup",
210    r".*_asan_rtl_",
211    r".*agent::asan::",
212    r".*allocator_shim",
213    r".*asan_Heap",
214    r".*asan_check_access",
215    r".*asan_osx_dynamic\.dylib",
216    r".*assert",
217    r".*base::FuzzedDataProvider",
218    r".*base::allocator",
219    r".*base::android::CheckException",
220    r".*base::debug::BreakDebugger",
221    r".*base::debug::CollectStackTrace",
222    r".*base::debug::StackTrace::StackTrace",
223    r".*ieee754\-",
224    r".*libpthread",
225    r".*logger",
226    r".*logging::CheckError",
227    r".*logging::ErrnoLogMessage",
228    r".*logging::LogMessage",
229    r".*stdext::exception::what",
230    r".*v8::base::OS::Abort",
231    // Pybindings
232    r".*pybind",
233    r"^PyCFunction",
234    r"^PyObject",
235    r"^PyEval",
236    r"^PyRun",
237    r"^Py_",
238    r"^atheris::",
239];
240
241/// Regular expressions for с# functions to be ignored.
242pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_CSHARP: &[&str] = &[
243    // TODO
244    r"^\(wrapper",
245];
246
247/// Regular expressions for paths to java files that should be ignored.
248pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_JAVA: &[&str] = &[
249    // TODO
250    r"^[^.]$",
251];
252
253/// Regular expressions for paths to JS files that should be ignored.
254pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_JS: &[&str] = &[
255    // TODO
256    // Anonymous functions
257    r"^<anonymous>$",
258    // Native locations (within V8’s libraries)
259    r"^native$",
260    // JS internal modules
261    r"^(|node:)internal/?",
262    r"^(|node:)events/?",
263    // Jazzer.js internal modules
264    r"node_modules/@jazzer.js",
265    // jsfuzz internal modules
266    r"node_modules/jsfuzz",
267];
268
269/// Regular expressions for paths to lua files that should be ignored.
270pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_LUA: &[&str] = &[
271    // TODO
272    r"^[^.]$",
273];
274
275/// Regular expressions for paths to python files that should be ignored.
276pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_PYTHON: &[&str] = &[
277    // TODO
278    r"^[^.]$",
279];
280
281/// Regular expressions for paths to rust files that should be ignored.
282pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_RUST: &[&str] = &[
283    r".*/rust(|c)/",
284    // AFL
285    r".*/afl-.*/.*\.rs",
286    r".*/libfuzzer-sys-.*/.*\.rs",
287];
288
289/// Regular expressions for paths to Go files that should be ignored.
290pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_GO: &[&str] = &[r".*go/src/runtime/"];
291
292/// Regular expressions for paths to cpp files that should be ignored.
293pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_CPP: &[&str] = &[
294    // File paths.
295    r".*/usr/include/c\+\+/",
296    r".*\-gnu/c\+\+/",
297    r".*\-gnu/bits/",
298    r".*/clang/",
299    r".*base/callback",
300    r".*/AOSP\-toolchain/",
301    r".*/bindings/ToV8\.h",
302    r".*/crosstool/",
303    r".*/gcc/",
304    r".*sysdeps/",
305    r".*/glibc\-",
306    r".*/jemalloc/",
307    r".*/libc\+\+",
308    r".*/libc/",
309    r".*/llvm\-build/",
310    r".*/minkernel/crts/",
311    r".*/sanitizer_common/",
312    r".*/tcmalloc/",
313    r".*/vc/include/",
314    r".*/vctools/crt/",
315    r".*/win_toolchain/",
316    r".*libc\+\+/",
317    r".*/cxxsupp/",
318    r".*/util/generic/",
319    // Sanitizers and LibFuzzer
320    r".*/compiler\-rt/lib/",
321    r".*/libfuzzer/lib/",
322    r".*/clang.*\-rt/lib/",
323    // Others (uncategorized).
324    r".*\+Unknown",
325    r".*<unknown module>",
326    r".*Inline Function @",
327    r"^<unknown>$",
328    r"^\[vdso\]$",
329    r"^linux-vdso.so.*$",
330    r"^linux-gate.so.*$",
331    r".*libc\.so",
332    r".*libc\+\+\.so",
333    r".*libc\+\+_shared\.so",
334    r".*libstdc\+\+\.so",
335    r".*libc-.*\.so",
336    r".*libpthread\.so",
337    r".*libasan\.so",
338    r".*libubsan\.so",
339    r".*asan_with_fuzzer\.so",
340];
341
342/// Regular expressions for paths to c# files that should be ignored.
343pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_CSHARP: &[&str] = &[
344    // TODO
345    r"^[^.]$",
346];
347
348// Signal numbers
349pub const SIGINFO_SIGILL: u32 = 4;
350pub const SIGINFO_SIGTRAP: u32 = 5;
351pub const SIGINFO_SIGABRT: u32 = 6;
352pub const SIGINFO_SIGBUS: u32 = 7;
353pub const SIGINFO_SIGFPE: u32 = 8;
354pub const SIGINFO_SIGSEGV: u32 = 11;
355pub const SIGINFO_SIGSYS: u32 = 31;
356
357pub const SI_KERNEL: u32 = 0x80;