1 /* 2 * Copyright 2008, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <inttypes.h> 20 #include <signal.h> 21 #include <stdarg.h> 22 #include <stdbool.h> 23 #include <sys/types.h> 24 25 #include <string> 26 27 #include <android-base/macros.h> 28 29 struct log_t { 30 // Tombstone file descriptor. 31 int tfd; 32 // Data to be sent to the Activity Manager. 33 std::string* amfd_data; 34 // The tid of the thread that crashed. 35 pid_t crashed_tid; 36 // The tid of the thread we are currently working with. 37 pid_t current_tid; 38 // logd daemon crash, can block asking for logcat data, allow suppression. 39 bool should_retrieve_logcat; 40 log_tlog_t41 log_t() 42 : tfd(-1), 43 amfd_data(nullptr), 44 crashed_tid(-1), 45 current_tid(-1), 46 should_retrieve_logcat(true) {} 47 }; 48 49 // List of types of logs to simplify the logging decision in _LOG 50 enum logtype { 51 HEADER, 52 THREAD, 53 REGISTERS, 54 FP_REGISTERS, 55 BACKTRACE, 56 MAPS, 57 MEMORY, 58 STACK, 59 LOGS, 60 OPEN_FILES 61 }; 62 63 #if defined(__LP64__) 64 #define PRIPTR "016" PRIx64 65 typedef uint64_t word_t; 66 #else 67 #define PRIPTR "08" PRIx64 68 typedef uint32_t word_t; 69 #endif 70 71 // Log information onto the tombstone. 72 void _LOG(log_t* log, logtype ltype, const char* fmt, ...) __attribute__((format(printf, 3, 4))); 73 void _VLOG(log_t* log, logtype ltype, const char* fmt, va_list ap); 74 75 namespace unwindstack { 76 class Unwinder; 77 class Memory; 78 } 79 80 void log_backtrace(log_t* log, unwindstack::Unwinder* unwinder, const char* prefix); 81 82 ssize_t dump_memory(void* out, size_t len, uint8_t* tags, size_t tags_len, uint64_t* addr, 83 unwindstack::Memory* memory); 84 void dump_memory(log_t* log, unwindstack::Memory* backtrace, uint64_t addr, const std::string&); 85 86 void drop_capabilities(); 87 88 bool signal_has_sender(const siginfo_t*, pid_t caller_pid); 89 bool signal_has_si_addr(const siginfo_t*); 90 void get_signal_sender(char* buf, size_t n, const siginfo_t*); 91 const char* get_signame(const siginfo_t*); 92 const char* get_sigcode(const siginfo_t*); 93 std::string describe_tagged_addr_ctrl(long ctrl); 94 std::string describe_pac_enabled_keys(long keys); 95 96 // Number of bytes per MTE granule. 97 constexpr size_t kTagGranuleSize = 16; 98 99 // Number of rows and columns to display in an MTE tag dump. 100 constexpr size_t kNumTagColumns = 16; 101 constexpr size_t kNumTagRows = 16; 102