Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010, Google Inc. | 1 // Copyright (c) 2010, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 // was originally a complete implementation using the ptrace API, but | 32 // was originally a complete implementation using the ptrace API, but |
| 33 // has been refactored to allow derived implementations supporting both | 33 // has been refactored to allow derived implementations supporting both |
| 34 // ptrace and core dump. A portion of the original implementation is now | 34 // ptrace and core dump. A portion of the original implementation is now |
| 35 // in google_breakpad::LinuxPtraceDumper (see linux_ptrace_dumper.h for | 35 // in google_breakpad::LinuxPtraceDumper (see linux_ptrace_dumper.h for |
| 36 // details). | 36 // details). |
| 37 | 37 |
| 38 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_LINUX_DUMPER_H_ | 38 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_LINUX_DUMPER_H_ |
| 39 #define CLIENT_LINUX_MINIDUMP_WRITER_LINUX_DUMPER_H_ | 39 #define CLIENT_LINUX_MINIDUMP_WRITER_LINUX_DUMPER_H_ |
| 40 | 40 |
| 41 #include <elf.h> | 41 #include <elf.h> |
| 42 #if defined(__ANDROID__) | |
| 43 #include <link.h> | |
| 44 #endif | |
| 42 #include <linux/limits.h> | 45 #include <linux/limits.h> |
| 43 #include <stdint.h> | 46 #include <stdint.h> |
| 44 #include <sys/types.h> | 47 #include <sys/types.h> |
| 45 #include <sys/user.h> | 48 #include <sys/user.h> |
| 46 | 49 |
| 47 #include "client/linux/dump_writer_common/mapping_info.h" | 50 #include "client/linux/dump_writer_common/mapping_info.h" |
| 48 #include "client/linux/dump_writer_common/thread_info.h" | 51 #include "client/linux/dump_writer_common/thread_info.h" |
| 49 #include "common/memory.h" | 52 #include "common/memory.h" |
| 50 #include "google_breakpad/common/minidump_format.h" | 53 #include "google_breakpad/common/minidump_format.h" |
| 51 | 54 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 66 // is the name we use for it when writing it to the minidump. | 69 // is the name we use for it when writing it to the minidump. |
| 67 // This should always be less than NAME_MAX! | 70 // This should always be less than NAME_MAX! |
| 68 const char kLinuxGateLibraryName[] = "linux-gate.so"; | 71 const char kLinuxGateLibraryName[] = "linux-gate.so"; |
| 69 | 72 |
| 70 class LinuxDumper { | 73 class LinuxDumper { |
| 71 public: | 74 public: |
| 72 explicit LinuxDumper(pid_t pid); | 75 explicit LinuxDumper(pid_t pid); |
| 73 | 76 |
| 74 virtual ~LinuxDumper(); | 77 virtual ~LinuxDumper(); |
| 75 | 78 |
| 76 // Parse the data for |threads| and |mappings|. | 79 // Parse the data for |threads| and |mappings|. LateInit() should be |
|
Lei Zhang
2015/06/18 21:45:38
nit: Can you separate the LateInit() comment from
simonb (inactive)
2015/06/19 12:19:28
Done.
| |
| 80 // called after all other caller's initialization is complete, and in | |
| 81 // particular after it has called ThreadsSuspend(), so that ptrace is | |
| 82 // available. | |
| 77 virtual bool Init(); | 83 virtual bool Init(); |
| 84 virtual bool LateInit(); | |
| 78 | 85 |
| 79 // Return true if the dumper performs a post-mortem dump. | 86 // Return true if the dumper performs a post-mortem dump. |
| 80 virtual bool IsPostMortem() const = 0; | 87 virtual bool IsPostMortem() const = 0; |
| 81 | 88 |
| 82 // Suspend/resume all threads in the given process. | 89 // Suspend/resume all threads in the given process. |
| 83 virtual bool ThreadsSuspend() = 0; | 90 virtual bool ThreadsSuspend() = 0; |
| 84 virtual bool ThreadsResume() = 0; | 91 virtual bool ThreadsResume() = 0; |
| 85 | 92 |
| 86 // Read information about the |index|-th thread of |threads_|. | 93 // Read information about the |index|-th thread of |threads_|. |
| 87 // Returns true on success. One must have called |ThreadsSuspend| first. | 94 // Returns true on success. One must have called |ThreadsSuspend| first. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 mutable PageAllocator allocator_; | 182 mutable PageAllocator allocator_; |
| 176 | 183 |
| 177 // IDs of all the threads. | 184 // IDs of all the threads. |
| 178 wasteful_vector<pid_t> threads_; | 185 wasteful_vector<pid_t> threads_; |
| 179 | 186 |
| 180 // Info from /proc/<pid>/maps. | 187 // Info from /proc/<pid>/maps. |
| 181 wasteful_vector<MappingInfo*> mappings_; | 188 wasteful_vector<MappingInfo*> mappings_; |
| 182 | 189 |
| 183 // Info from /proc/<pid>/auxv | 190 // Info from /proc/<pid>/auxv |
| 184 wasteful_vector<elf_aux_val_t> auxv_; | 191 wasteful_vector<elf_aux_val_t> auxv_; |
| 192 | |
| 193 #if defined(__ANDROID__) | |
| 194 private: | |
| 195 // Android M and later support packed ELF relocations in shared libraries. | |
| 196 // Packing relocations changes the vaddr of the LOAD segments, such that | |
| 197 // the effective load bias is no longer the same as the start address of | |
| 198 // the memory mapping containing the executable parts of the library. The | |
| 199 // packing is applied to the stripped library run on the target, but not to | |
| 200 // any other library, and in particular not to the library used to generate | |
| 201 // breakpad symbols. As a result, we need to adjust the start_addr value for | |
| 202 // any mapping that results from a shared library that contains Android | |
| 203 // packed relocations, so that it properly represents the effective library | |
| 204 // load bias. The following functions support this adjustment. | |
| 205 | |
| 206 // Check that a given mapping at |start_addr| is for an ELF shared library. | |
| 207 // If it is, place the ELF header in |ehdr| and return true. | |
| 208 bool GetLoadedElfHeader(uintptr_t start_addr, ElfW(Ehdr)* ehdr); | |
| 209 | |
| 210 // For the ELF file mapped at |start_addr|, find the min vaddr of all | |
| 211 // program header LOAD segments, the vaddr for the DYNAMIC segment, and | |
| 212 // a count of DYNAMIC entries. Return values in |min_vaddr_ptr|, | |
| 213 // |dyn_vaddr_ptr|, and |dyn_count_ptr|. | |
| 214 void ParseLoadedElfProgramHeaders(ElfW(Ehdr)* ehdr, | |
| 215 uintptr_t start_addr, | |
| 216 uintptr_t* min_vaddr_ptr, | |
| 217 uintptr_t* dyn_vaddr_ptr, | |
| 218 size_t* dyn_count_ptr); | |
| 219 | |
| 220 // Search the DYNAMIC tags for the ELF file with the given |load_bias|, and | |
| 221 // return true if the tags indicate that the file contains Android packed | |
| 222 // relocations. | |
| 223 bool HasAndroidPackedRelocations(uintptr_t load_bias, | |
| 224 uintptr_t dyn_vaddr, | |
| 225 size_t dyn_count); | |
| 226 | |
| 227 // If the ELF file mapped at |start_addr| contained Android packed | |
| 228 // relocations, return the load bias that the system linker (or Chromium | |
| 229 // crazy linker) will have used. If the file did not contain Android | |
| 230 // packed relocations, returns |start_addr|, indicating that no adjustment | |
| 231 // is necessary. | |
| 232 uintptr_t GetEffectiveLoadBias(ElfW(Ehdr)* ehdr, uintptr_t start_addr); | |
| 233 | |
| 234 // Called from LateInit(). Iterates mappings_ and rewrites the start_addr | |
| 235 // field of any that represent ELF shared libraries with Android packed | |
| 236 // relocations, so that start_addr is the load_bias that the system linker | |
| 237 // (or Chromium crazy linker) used. This value matches the addresses produced | |
| 238 // when the non-relocation-packed library is used for breakpad symbol | |
| 239 // generation. | |
| 240 bool LatePostprocessMappings(); | |
| 241 #endif // __ANDROID__ | |
| 185 }; | 242 }; |
| 186 | 243 |
| 187 } // namespace google_breakpad | 244 } // namespace google_breakpad |
| 188 | 245 |
| 189 #endif // CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ | 246 #endif // CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ |
| OLD | NEW |