xref: /aosp_15_r20/external/google-breakpad/src/client/linux/dump_writer_common/thread_info.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 // Copyright 2014 Google LLC
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //     * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //     * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //     * Neither the name of Google LLC nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #ifndef CLIENT_LINUX_DUMP_WRITER_COMMON_THREAD_INFO_H_
30 #define CLIENT_LINUX_DUMP_WRITER_COMMON_THREAD_INFO_H_
31 
32 #include <sys/ucontext.h>
33 #include <sys/user.h>
34 
35 #include "client/linux/dump_writer_common/raw_context_cpu.h"
36 #include "common/memory_allocator.h"
37 #include "google_breakpad/common/minidump_format.h"
38 
39 namespace google_breakpad {
40 
41 #if defined(__i386) || defined(__x86_64)
42 typedef __typeof__(((struct user*) 0)->u_debugreg[0]) debugreg_t;
43 #endif
44 
45 // We produce one of these structures for each thread in the crashed process.
46 struct ThreadInfo {
47   pid_t tgid;   // thread group id
48   pid_t ppid;   // parent process
49 
50   uintptr_t stack_pointer;  // thread stack pointer
51 
52 
53 #if defined(__i386) || defined(__x86_64)
54   user_regs_struct regs;
55   user_fpregs_struct fpregs;
56   static const unsigned kNumDebugRegisters = 8;
57   debugreg_t dregs[8];
58 #if defined(__i386)
59   user_fpxregs_struct fpxregs;
60 #endif  // defined(__i386)
61 
62 #elif defined(__ARM_EABI__)
63   // Mimicking how strace does this(see syscall.c, search for GETREGS)
64   struct user_regs regs;
65   struct user_fpregs fpregs;
66 #elif defined(__aarch64__)
67   // Use the structures defined in <sys/user.h>
68   struct user_regs_struct regs;
69   struct user_fpsimd_struct fpregs;
70 #elif defined(__mips__) || defined(__riscv)
71   // Use the structure defined in <sys/ucontext.h>.
72   mcontext_t mcontext;
73 #endif
74 
75   // Returns the instruction pointer (platform-dependent impl.).
76   uintptr_t GetInstructionPointer() const;
77 
78   // Fills a RawContextCPU using the context in the ThreadInfo object.
79   void FillCPUContext(RawContextCPU* out) const;
80 
81   // Returns the pointer and size of general purpose register area.
82   void GetGeneralPurposeRegisters(void** gp_regs, size_t* size);
83 
84   // Returns the pointer and size of float point register area.
85   void GetFloatingPointRegisters(void** fp_regs, size_t* size);
86 };
87 
88 }  // namespace google_breakpad
89 
90 #endif  // CLIENT_LINUX_DUMP_WRITER_COMMON_THREAD_INFO_H_
91