1 /** 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef _GWP_ASAN_H 17 #define _GWP_ASAN_H 18 #ifdef USE_GWP_ASAN 19 20 #include <dlfcn.h> 21 #include <stdint.h> 22 #include <stddef.h> 23 24 #define GWP_ASAN_LOG_TAG "gwp_asan" 25 #define GWP_ASAN_LOG_DIR "/data/local/tmp/" 26 27 typedef void (*printf_t)(const char *fmt, ...); 28 typedef void (*printf_backtrace_t)(uintptr_t*, size_t, printf_t); 29 typedef size_t (*segv_backtrace_t)(uintptr_t*, size_t, void*); 30 typedef size_t (*backtrace_t)(size_t*, size_t); 31 32 // Note that "compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp" in the llvm code need to be modified synchronously. 33 typedef struct gwp_asan_option { 34 bool help; 35 bool enable; 36 bool install_fork_handlers; 37 bool install_signal_handlers; 38 int sample_rate; 39 int max_simultaneous_allocations; 40 backtrace_t backtrace; 41 printf_t gwp_asan_printf; 42 printf_backtrace_t printf_backtrace; 43 segv_backtrace_t segv_backtrace; 44 } gwp_asan_option; 45 46 typedef struct unwind_info { 47 size_t fp; 48 size_t lr; 49 } unwind_info; 50 51 size_t libc_gwp_asan_unwind_fast(size_t *frame_buf, size_t max_record_stack, 52 __attribute__((unused)) void *signal_context); 53 54 bool libc_gwp_asan_has_free_mem(); 55 bool libc_gwp_asan_ptr_is_mine(void *addr); 56 bool may_init_gwp_asan(bool force_init); 57 58 #endif 59 #endif 60