1*cda5da8dSAndroid Build Coastguard Worker /* 2*cda5da8dSAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project 3*cda5da8dSAndroid Build Coastguard Worker * All rights reserved. 4*cda5da8dSAndroid Build Coastguard Worker * 5*cda5da8dSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*cda5da8dSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 7*cda5da8dSAndroid Build Coastguard Worker * are met: 8*cda5da8dSAndroid Build Coastguard Worker * * Redistributions of source code must retain the above copyright 9*cda5da8dSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 10*cda5da8dSAndroid Build Coastguard Worker * * Redistributions in binary form must reproduce the above copyright 11*cda5da8dSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in 12*cda5da8dSAndroid Build Coastguard Worker * the documentation and/or other materials provided with the 13*cda5da8dSAndroid Build Coastguard Worker * distribution. 14*cda5da8dSAndroid Build Coastguard Worker * 15*cda5da8dSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16*cda5da8dSAndroid Build Coastguard Worker * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17*cda5da8dSAndroid Build Coastguard Worker * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18*cda5da8dSAndroid Build Coastguard Worker * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19*cda5da8dSAndroid Build Coastguard Worker * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20*cda5da8dSAndroid Build Coastguard Worker * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21*cda5da8dSAndroid Build Coastguard Worker * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22*cda5da8dSAndroid Build Coastguard Worker * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23*cda5da8dSAndroid Build Coastguard Worker * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24*cda5da8dSAndroid Build Coastguard Worker * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25*cda5da8dSAndroid Build Coastguard Worker * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*cda5da8dSAndroid Build Coastguard Worker * SUCH DAMAGE. 27*cda5da8dSAndroid Build Coastguard Worker */ 28*cda5da8dSAndroid Build Coastguard Worker #pragma once 29*cda5da8dSAndroid Build Coastguard Worker 30*cda5da8dSAndroid Build Coastguard Worker #include <sys/cdefs.h> 31*cda5da8dSAndroid Build Coastguard Worker 32*cda5da8dSAndroid Build Coastguard Worker /** 33*cda5da8dSAndroid Build Coastguard Worker * @file execinfo.h 34*cda5da8dSAndroid Build Coastguard Worker * @brief Functions to do in process backtracing. 35*cda5da8dSAndroid Build Coastguard Worker */ 36*cda5da8dSAndroid Build Coastguard Worker 37*cda5da8dSAndroid Build Coastguard Worker __BEGIN_DECLS 38*cda5da8dSAndroid Build Coastguard Worker 39*cda5da8dSAndroid Build Coastguard Worker /** 40*cda5da8dSAndroid Build Coastguard Worker * [backtrace(3)](https://man7.org/linux/man-pages/man3/backtrace.3.html) 41*cda5da8dSAndroid Build Coastguard Worker * Saves a backtrace for the current call in the array pointed to by buffer. 42*cda5da8dSAndroid Build Coastguard Worker * "size" indicates the maximum number of void* pointers that can be set. 43*cda5da8dSAndroid Build Coastguard Worker * 44*cda5da8dSAndroid Build Coastguard Worker * Returns the number of addresses stored in "buffer", which is not greater 45*cda5da8dSAndroid Build Coastguard Worker * than "size". If the return value is equal to "size" then the number of 46*cda5da8dSAndroid Build Coastguard Worker * addresses may have been truncated. 47*cda5da8dSAndroid Build Coastguard Worker * 48*cda5da8dSAndroid Build Coastguard Worker * Available since API level 33. 49*cda5da8dSAndroid Build Coastguard Worker */ 50*cda5da8dSAndroid Build Coastguard Worker 51*cda5da8dSAndroid Build Coastguard Worker #if __BIONIC_AVAILABILITY_GUARD(33) 52*cda5da8dSAndroid Build Coastguard Worker int backtrace(void* _Nonnull * _Nonnull buffer, int size) __INTRODUCED_IN(33); 53*cda5da8dSAndroid Build Coastguard Worker 54*cda5da8dSAndroid Build Coastguard Worker /** 55*cda5da8dSAndroid Build Coastguard Worker * [backtrace_symbols(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols.3.html) 56*cda5da8dSAndroid Build Coastguard Worker * Given an array of void* pointers, translate the addresses into an array 57*cda5da8dSAndroid Build Coastguard Worker * of strings that represent the backtrace. 58*cda5da8dSAndroid Build Coastguard Worker * 59*cda5da8dSAndroid Build Coastguard Worker * Returns a pointer to allocated memory, on error NULL is returned. It is 60*cda5da8dSAndroid Build Coastguard Worker * the responsibility of the caller to free the returned memory. 61*cda5da8dSAndroid Build Coastguard Worker * 62*cda5da8dSAndroid Build Coastguard Worker * Available since API level 33. 63*cda5da8dSAndroid Build Coastguard Worker */ 64*cda5da8dSAndroid Build Coastguard Worker char* _Nullable * _Nullable backtrace_symbols(void* _Nonnull const* _Nonnull buffer, int size) __INTRODUCED_IN(33); 65*cda5da8dSAndroid Build Coastguard Worker 66*cda5da8dSAndroid Build Coastguard Worker /** 67*cda5da8dSAndroid Build Coastguard Worker * [backtrace_symbols_fd(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols_fd.3.html) 68*cda5da8dSAndroid Build Coastguard Worker * Given an array of void* pointers, translate the addresses into an array 69*cda5da8dSAndroid Build Coastguard Worker * of strings that represent the backtrace and write to the file represented 70*cda5da8dSAndroid Build Coastguard Worker * by "fd". The file is written such that one line equals one void* address. 71*cda5da8dSAndroid Build Coastguard Worker * 72*cda5da8dSAndroid Build Coastguard Worker * Available since API level 33. 73*cda5da8dSAndroid Build Coastguard Worker */ 74*cda5da8dSAndroid Build Coastguard Worker void backtrace_symbols_fd(void* _Nonnull const* _Nonnull buffer, int size, int fd) __INTRODUCED_IN(33); 75*cda5da8dSAndroid Build Coastguard Worker #endif /* __BIONIC_AVAILABILITY_GUARD(33) */ 76*cda5da8dSAndroid Build Coastguard Worker 77*cda5da8dSAndroid Build Coastguard Worker 78*cda5da8dSAndroid Build Coastguard Worker __END_DECLS 79