Rizin
unix-like reverse engineering framework and cli tools
linux_coredump.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016 Oscar Salvador <osalvador.vilardaga@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 /* coredump api */
5 
6 #ifndef LINUX_COREDUMP_H
7 #define LINUX_COREDUMP_H
8 
9 #include "elf_specs.h"
10 #include <sys/procfs.h>
11 
12 #if __i386__ || __x86_64__
13 /*Macros for XSAVE/XRESTORE*/
14 /*
15  From: http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developers-manual.pdf
16  Bit 00: x87 state.
17  Bit 01: SSE state.
18  Bit 02: AVX state.
19  Bits 04 - 03: MPX state. (https://software.intel.com/sites/default/files/managed/9d/f6/Intel_MPX_EnablingGuide.pdf)
20  Bits 07 - 05: AVX-512 state.
21  Bit 08: Used for IA32_XSS.
22  Bit 09: PKRU state
23 */
24 #define X87_BIT (1ULL << 0)
25 #define SSE_BIT (1ULL << 1)
26 #define AVX_BIT (1ULL << 2)
27 #define BNDREGS_BIT (1ULL << 3)
28 #define BNDCSR_BIT (1ULL << 4)
29 /* From Intel MPX: "The OS should set both bits to ONE to enable Intel MPX; otherwise the processor would interpret Intel MPX instructions as NOPs" */
30 #define MPX_BIT (BNDREGS_BIT | BNDCSR_BIT)
31 /* https://software.intel.com/sites/default/files/managed/b4/3a/319433-024.pdf - Page 66
32 "Execute XGETBV and verify that XCR0[7:5] = ‘111b’ (OPMASK state, upper 256-bit of ZMM0-ZMM15 and ZMM16-ZMM31 state are enabled by OS) and that XCR0[2:1] = ‘11b’ (XMM state and YMM state are enabled by OS)" */
33 #define AVX512_k_BIT (1ULL << 5)
34 #define AVX512_ZMM0_15_BIT (1ULL << 6)
35 #define AVX512_ZMM16_31_BIT (1ULL << 7)
36 #define AVX512_FULL_BIT (AVX512_k_BIT | AVX512_ZMM0_15_BIT | AVX512_ZMM16_31_BIT)
37 #define IA32_XSS_BIT (1ULL << 8) /* ?? */
38 #define PKRU_BIT (1ULL << 9) /* ?? */
39 
40 #define NO_STATE_BIT X87_BIT
41 #define XSTATE_SSE_SIZE 576
42 #define XSTATE_AVX_SIZE 832
43 /*#define XSTATE_BNDCGR ?? */
44 #define XSTATE_MPX_SIZE 1088
45 #define XSTATE_AVX512_k_SIZE 1152
46 #define XSTATE_AVX512_ZMM0_7 1408
47 #define XSTATE_AVX512_ZMM8_15 1664
48 #define XSTATE_AVX512_ZMM16_31 2688
49 #define XSTATE_FULL_SIZE XSTATE_AVX512_ZMM16_31
50 
51 #define XSTATE_HDR_SIZE XSTATE_SSE_SIZE
52 #define XCR0_OFFSET 464
53 
54 #define XSTATE_SSE_MASK (X87_BIT | SSE_BIT)
55 #define XSTATE_AVX_MASK (XSTATE_SSE_MASK | AVX_BIT)
56 #define XSTATE_MPX_MASK (MPX_BIT | XSTATE_AVX_MASK | XSTATE_SSE_MASK)
57 #define XSTATE_AVX512_MASK (XSTATE_AVX_MASK | AVX512_FULL_BIT)
58 /*********************************/
59 #endif
60 
61 #define SIZE_PR_FNAME 16
62 
63 #define RZ_DEBUG_REG_T struct user_regs_struct
64 
65 #define SIZE_NT_FILE_DESCSZ sizeof(unsigned long) * 3 /* start_address * end_address * offset_address */
66 /*
67 NT_FILE layout:
68  [number of mappings]
69  [page size]
70  [foreach(mapping)
71  [start_address]
72  [end_address]
73  [offset_address]
74  [filenames]
75 */
76 
77 #define X_MEM 0x1
78 #define W_MEM 0x2
79 #define RZ_MEM 0x4
80 #define P_MEM 0x8
81 #define S_MEM 0x10
82 #define WRG_PERM 0x20
83 
84 #define MAP_ANON_PRIV 0x1
85 #define MAP_ANON_SHR 0x2
86 #define MAP_FILE_PRIV 0x4
87 #define MAP_FILE_SHR 0x8
88 #define MAP_ELF_HDR 0x10
89 #define MAP_HUG_PRIV 0x20
90 #define MAP_HUG_SHR 0x40
91 
92 #define SH_FLAG 0x1
93 #define IO_FLAG 0x2
94 #define DD_FLAG 0x4
95 #define HT_FLAG 0x8
96 #define PV_FLAG 0x10 /* just for us */
97 
98 typedef struct proc_per_process {
99  int pid;
100  char s_name;
103  int ppid;
104  int pgrp;
105  int sid;
107  long int nice;
108  long int num_threads;
109  unsigned char coredump_filter;
111 
112 typedef struct proc_per_thread {
113  int tid;
118  long int cutime;
119  long int cstime;
122 
123 typedef struct proc_content {
127 
128 typedef struct map_file {
132 
133 typedef struct linux_map_entry {
134  unsigned long start_addr;
135  unsigned long end_addr;
136  unsigned long offset;
138  bool anonymous;
139  bool dumpeable;
142  bool shared;
143  char *name;
146 
147 #define ADD_MAP_NODE(p) \
148  { \
149  if (me_head) { \
150  p->n = NULL; \
151  me_tail->n = p; \
152  me_tail = p; \
153  } else { \
154  me_head = p; \
155  me_tail = p; \
156  } \
157  }
158 
159 typedef struct auxv_buff {
160  void *data;
161  size_t size;
163 
164 /*NT_* thread-wide*/
165 typedef struct thread_elf_note {
166  prstatus_t *prstatus;
167  elf_fpregset_t *fp_regset;
168 #if __i386__
169  elf_fpxregset_t *fpx_regset;
170 #endif
171  siginfo_t *siginfo;
172 #if __i386__ || __x86_64__
173  void *xsave_data;
174 #elif __arm__ || __arm64__
175  void *arm_vfp_data;
176 #endif
179 
180 /*NT_* process-wide*/
181 typedef struct proc_elf_note {
182  prpsinfo_t *prpsinfo;
188 
189 typedef enum {
196 #if __i386__
197  NT_PRXFPREG_T,
198 #endif
199 #if __i386__ || __x86_64__
200  NT_X86_XSTATE_T,
201 #elif __arm__ || __arm64__
202  NT_ARM_VFP_T,
203 #endif
206 
207 typedef struct elf_note_types {
208  int size;
211  char name[8];
213 
214 typedef enum {
220  NAME
222 
223 extern ssize_t process_vm_readv(pid_t pid, const struct iovec *local_iov,
224  unsigned long liovcnt, const struct iovec *remote_iov,
225  unsigned long riovcnt, unsigned long flags);
226 
228 int linux_reg_read(RzDebug *dbg, int type, ut8 *buf, int size);
229 
230 #endif
uint32_t ut32
RzDebug * dbg
Definition: desil.c:30
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
struct map_file map_file_t
struct proc_per_thread proc_per_thread_t
struct proc_per_process proc_per_process_t
struct linux_map_entry linux_map_entry_t
int linux_reg_read(RzDebug *dbg, int type, ut8 *buf, int size)
Definition: linux_debug.c:1090
struct elf_note_types note_info_t
note_type_t
@ NT_PRSTATUS_T
@ NT_LENGHT_T
@ NT_AUXV_T
@ NT_FILE_T
@ NT_SIGINFO_T
@ NT_PRPSINFO_T
@ NT_FPREGSET_T
ssize_t process_vm_readv(pid_t pid, const struct iovec *local_iov, unsigned long liovcnt, const struct iovec *remote_iov, unsigned long riovcnt, unsigned long flags)
MAPS_FIELD
@ NAME
@ OFFSET
@ DEV
@ ADDR
@ INODE
@ PERM
struct proc_content proc_content_t
struct auxv_buff auxv_buff_t
bool linux_generate_corefile(RzDebug *dbg, RzBuffer *dest)
struct thread_elf_note thread_elf_note_t
struct proc_elf_note elf_proc_note_t
char * dest
Definition: lz4.h:697
int type
Definition: mipsasm.c:17
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
int pid_t
Definition: sftypes.h:38
int ssize_t
Definition: sftypes.h:39
Definition: sftypes.h:73
unsigned long end_addr
bool dumpeable
ut8 perms
unsigned long start_addr
bool anonymous
char * name
bool file_backed
struct linux_map_entry * n
bool shared
bool kernel_mapping
unsigned long offset
Definition: z80asm.h:102
proc_per_process_t * per_process
proc_per_thread_t * per_thread
auxv_buff_t * auxv
prpsinfo_t * prpsinfo
thread_elf_note_t * thread_note
linux_map_entry_t * maps
unsigned char coredump_filter
struct proc_per_thread * n
siginfo_t * siginfo
elf_fpregset_t * fp_regset
struct thread_elf_note * n
prstatus_t * prstatus
ut64(WINAPI *w32_GetEnabledXStateFeatures)()