1*b88e3e88Schristos /* Copyright (C) 2006-2020 Free Software Foundation, Inc.
2440a403fSchristos    This file is part of the GNU C Library.
3440a403fSchristos 
4440a403fSchristos    The GNU C Library is free software; you can redistribute it and/or
5440a403fSchristos    modify it under the terms of the GNU Lesser General Public
6440a403fSchristos    License as published by the Free Software Foundation; either
7440a403fSchristos    version 2.1 of the License, or (at your option) any later version.
8440a403fSchristos 
9440a403fSchristos    The GNU C Library is distributed in the hope that it will be useful,
10440a403fSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
11440a403fSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12440a403fSchristos    Lesser General Public License for more details.
13440a403fSchristos 
1406324dcfSchristos    You should have received a copy of the GNU General Public License
1506324dcfSchristos    along with this program; if not, write to the Free Software
1606324dcfSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1706324dcfSchristos    MA 02110-1301, USA.  */
18440a403fSchristos 
19440a403fSchristos /* This is somewhat modelled after the file of the same name on SVR4
20440a403fSchristos    systems.  It provides a definition of the core file format for ELF
21440a403fSchristos    used on Linux.  It doesn't have anything to do with the /proc file
22440a403fSchristos    system, even though Linux has one.
23440a403fSchristos 
24440a403fSchristos    Anyway, the whole purpose of this file is for GDB and GDB only.
25440a403fSchristos    Don't read too much into it.  Don't use it for anything other than
26440a403fSchristos    GDB unless you know what you are doing.  */
27440a403fSchristos 
28440a403fSchristos #include <features.h>
29440a403fSchristos #include <sys/time.h>
30440a403fSchristos #include <sys/types.h>
31440a403fSchristos 
32440a403fSchristos /* We define here only the symbols differing from their 64-bit variant.  */
33440a403fSchristos #include <sys/procfs.h>
34440a403fSchristos 
35440a403fSchristos #ifdef HAVE_STDINT_H
36440a403fSchristos #include <stdint.h>
37440a403fSchristos #else
38440a403fSchristos typedef unsigned int uint32_t;
39440a403fSchristos typedef unsigned long long int uint64_t;
40440a403fSchristos #endif
41440a403fSchristos 
42440a403fSchristos /* Unsigned 64-bit integer aligned to 8 bytes.  */
43440a403fSchristos typedef uint64_t __attribute__ ((__aligned__ (8))) a8_uint64_t;
44440a403fSchristos 
45440a403fSchristos #undef HAVE_PRPSINFO32_T
46440a403fSchristos #define HAVE_PRPSINFO32_T
47440a403fSchristos #undef HAVE_PRPSINFO32_T_PR_PID
48440a403fSchristos #define HAVE_PRPSINFO32_T_PR_PID
49440a403fSchristos 
50440a403fSchristos #undef HAVE_PRSTATUS32_T
51440a403fSchristos #define HAVE_PRSTATUS32_T
52440a403fSchristos 
53440a403fSchristos /* These are the 32-bit x86 structures.  */
54440a403fSchristos 
55440a403fSchristos struct user_regs32_struct
56440a403fSchristos {
57440a403fSchristos   int32_t ebx;
58440a403fSchristos   int32_t ecx;
59440a403fSchristos   int32_t edx;
60440a403fSchristos   int32_t esi;
61440a403fSchristos   int32_t edi;
62440a403fSchristos   int32_t ebp;
63440a403fSchristos   int32_t eax;
64440a403fSchristos   int32_t xds;
65440a403fSchristos   int32_t xes;
66440a403fSchristos   int32_t xfs;
67440a403fSchristos   int32_t xgs;
68440a403fSchristos   int32_t orig_eax;
69440a403fSchristos   int32_t eip;
70440a403fSchristos   int32_t xcs;
71440a403fSchristos   int32_t eflags;
72440a403fSchristos   int32_t esp;
73440a403fSchristos   int32_t xss;
74440a403fSchristos };
75440a403fSchristos 
76440a403fSchristos struct user_regs64_struct
77440a403fSchristos {
78440a403fSchristos   a8_uint64_t r15;
79440a403fSchristos   a8_uint64_t r14;
80440a403fSchristos   a8_uint64_t r13;
81440a403fSchristos   a8_uint64_t r12;
82440a403fSchristos   a8_uint64_t rbp;
83440a403fSchristos   a8_uint64_t rbx;
84440a403fSchristos   a8_uint64_t r11;
85440a403fSchristos   a8_uint64_t r10;
86440a403fSchristos   a8_uint64_t r9;
87440a403fSchristos   a8_uint64_t r8;
88440a403fSchristos   a8_uint64_t rax;
89440a403fSchristos   a8_uint64_t rcx;
90440a403fSchristos   a8_uint64_t rdx;
91440a403fSchristos   a8_uint64_t rsi;
92440a403fSchristos   a8_uint64_t rdi;
93440a403fSchristos   a8_uint64_t orig_rax;
94440a403fSchristos   a8_uint64_t rip;
95440a403fSchristos   a8_uint64_t cs;
96440a403fSchristos   a8_uint64_t eflags;
97440a403fSchristos   a8_uint64_t rsp;
98440a403fSchristos   a8_uint64_t ss;
99440a403fSchristos   a8_uint64_t fs_base;
100440a403fSchristos   a8_uint64_t gs_base;
101440a403fSchristos   a8_uint64_t ds;
102440a403fSchristos   a8_uint64_t es;
103440a403fSchristos   a8_uint64_t fs;
104440a403fSchristos   a8_uint64_t gs;
105440a403fSchristos };
106440a403fSchristos 
107440a403fSchristos /* Type for a general-purpose register.  */
108440a403fSchristos typedef uint32_t elf_greg32_t;
109440a403fSchristos typedef a8_uint64_t elf_greg64_t;
110440a403fSchristos 
111440a403fSchristos /* And the whole bunch of them.  We could have used `struct
112440a403fSchristos    user_regs_struct' directly in the typedef, but tradition says that
113440a403fSchristos    the register set is an array, which does have some peculiar
114440a403fSchristos    semantics, so leave it that way.  */
115440a403fSchristos #define ELF_NGREG32 (sizeof (struct user_regs32_struct) / sizeof(elf_greg32_t))
116440a403fSchristos typedef elf_greg32_t elf_gregset32_t[ELF_NGREG32];
117440a403fSchristos #define ELF_NGREG64 (sizeof (struct user_regs64_struct) / sizeof(elf_greg64_t))
118440a403fSchristos typedef elf_greg64_t elf_gregset64_t[ELF_NGREG64];
119440a403fSchristos 
120440a403fSchristos /* Definitions to generate Intel SVR4-like core files.  These mostly
121440a403fSchristos    have the same names as the SVR4 types with "elf_" tacked on the
122440a403fSchristos    front to prevent clashes with Linux definitions, and the typedef
123440a403fSchristos    forms have been avoided.  This is mostly like the SVR4 structure,
124440a403fSchristos    but more Linuxy, with things that Linux does not support and which
125440a403fSchristos    GDB doesn't really use excluded.  */
126440a403fSchristos 
127440a403fSchristos struct prstatus32_timeval
128440a403fSchristos   {
129440a403fSchristos     int tv_sec;
130440a403fSchristos     int tv_usec;
131440a403fSchristos   };
132440a403fSchristos 
133440a403fSchristos struct prstatus64_timeval
134440a403fSchristos   {
135440a403fSchristos     a8_uint64_t tv_sec;
136440a403fSchristos     a8_uint64_t tv_usec;
137440a403fSchristos   };
138440a403fSchristos 
139440a403fSchristos struct elf_prstatus32
140440a403fSchristos   {
141440a403fSchristos     struct elf_siginfo pr_info;		/* Info associated with signal.  */
142440a403fSchristos     short int pr_cursig;		/* Current signal.  */
143440a403fSchristos     unsigned int pr_sigpend;		/* Set of pending signals.  */
144440a403fSchristos     unsigned int pr_sighold;		/* Set of held signals.  */
145440a403fSchristos     pid_t pr_pid;
146440a403fSchristos     pid_t pr_ppid;
147440a403fSchristos     pid_t pr_pgrp;
148440a403fSchristos     pid_t pr_sid;
149440a403fSchristos     struct prstatus32_timeval pr_utime;		/* User time.  */
150440a403fSchristos     struct prstatus32_timeval pr_stime;		/* System time.  */
151440a403fSchristos     struct prstatus32_timeval pr_cutime;	/* Cumulative user time.  */
152440a403fSchristos     struct prstatus32_timeval pr_cstime;	/* Cumulative system time.  */
153440a403fSchristos     elf_gregset32_t pr_reg;		/* GP registers.  */
154440a403fSchristos     int pr_fpvalid;			/* True if math copro being used.  */
155440a403fSchristos   };
156440a403fSchristos 
157440a403fSchristos struct elf_prstatusx32
158440a403fSchristos   {
159440a403fSchristos     struct elf_siginfo pr_info;		/* Info associated with signal.  */
160440a403fSchristos     short int pr_cursig;		/* Current signal.  */
161440a403fSchristos     unsigned int pr_sigpend;		/* Set of pending signals.  */
162440a403fSchristos     unsigned int pr_sighold;		/* Set of held signals.  */
163440a403fSchristos     pid_t pr_pid;
164440a403fSchristos     pid_t pr_ppid;
165440a403fSchristos     pid_t pr_pgrp;
166440a403fSchristos     pid_t pr_sid;
167440a403fSchristos     struct prstatus32_timeval pr_utime;		/* User time.  */
168440a403fSchristos     struct prstatus32_timeval pr_stime;		/* System time.  */
169440a403fSchristos     struct prstatus32_timeval pr_cutime;	/* Cumulative user time.  */
170440a403fSchristos     struct prstatus32_timeval pr_cstime;	/* Cumulative system time.  */
171440a403fSchristos     elf_gregset64_t pr_reg;		/* GP registers.  */
172440a403fSchristos     int pr_fpvalid;			/* True if math copro being used.  */
173440a403fSchristos   };
174440a403fSchristos 
175440a403fSchristos struct elf_prstatus64
176440a403fSchristos   {
177440a403fSchristos     struct elf_siginfo pr_info;	/* Info associated with signal.  */
178440a403fSchristos     short int pr_cursig;		/* Current signal.  */
179440a403fSchristos     a8_uint64_t pr_sigpend;		/* Set of pending signals.  */
180440a403fSchristos     a8_uint64_t pr_sighold;		/* Set of held signals.  */
181440a403fSchristos     pid_t pr_pid;
182440a403fSchristos     pid_t pr_ppid;
183440a403fSchristos     pid_t pr_pgrp;
184440a403fSchristos     pid_t pr_sid;
185440a403fSchristos     struct prstatus64_timeval pr_utime;		/* User time.  */
186440a403fSchristos     struct prstatus64_timeval pr_stime;		/* System time.  */
187440a403fSchristos     struct prstatus64_timeval pr_cutime;	/* Cumulative user time.  */
188440a403fSchristos     struct prstatus64_timeval pr_cstime;	/* Cumulative system time.  */
189440a403fSchristos     elf_gregset64_t pr_reg;		/* GP registers.  */
190440a403fSchristos     int pr_fpvalid;			/* True if math copro being used.  */
191440a403fSchristos   };
192440a403fSchristos 
193440a403fSchristos struct elf_prpsinfo32
194440a403fSchristos   {
195440a403fSchristos     char pr_state;			/* Numeric process state.  */
196440a403fSchristos     char pr_sname;			/* Char for pr_state.  */
197440a403fSchristos     char pr_zomb;			/* Zombie.  */
198440a403fSchristos     char pr_nice;			/* Nice val.  */
199440a403fSchristos     unsigned int pr_flag;		/* Flags.  */
200440a403fSchristos     unsigned short int pr_uid;
201440a403fSchristos     unsigned short int pr_gid;
202440a403fSchristos     int pr_pid, pr_ppid, pr_pgrp, pr_sid;
203440a403fSchristos     /* Lots missing */
204440a403fSchristos     char pr_fname[16];			/* Filename of executable.  */
205440a403fSchristos     char pr_psargs[ELF_PRARGSZ];	/* Initial part of arg list.  */
206440a403fSchristos   };
207440a403fSchristos 
208440a403fSchristos struct elf_prpsinfo64
209440a403fSchristos   {
210440a403fSchristos     char pr_state;			/* Numeric process state.  */
211440a403fSchristos     char pr_sname;			/* Char for pr_state.  */
212440a403fSchristos     char pr_zomb;			/* Zombie.  */
213440a403fSchristos     char pr_nice;			/* Nice val.  */
214440a403fSchristos     a8_uint64_t pr_flag;		/* Flags.  */
215440a403fSchristos     unsigned int pr_uid;
216440a403fSchristos     unsigned int pr_gid;
217440a403fSchristos     int pr_pid, pr_ppid, pr_pgrp, pr_sid;
218440a403fSchristos     /* Lots missing */
219440a403fSchristos     char pr_fname[16];			/* Filename of executable.  */
220440a403fSchristos     char pr_psargs[ELF_PRARGSZ];	/* Initial part of arg list.  */
221440a403fSchristos   };
222440a403fSchristos 
223440a403fSchristos /* The rest of this file provides the types for emulation of the
224440a403fSchristos    Solaris <proc_service.h> interfaces that should be implemented by
225440a403fSchristos    users of libthread_db.  */
226440a403fSchristos 
227440a403fSchristos /* Process status and info.  In the end we do provide typedefs for them.  */
228440a403fSchristos typedef struct elf_prstatus32 prstatus32_t;
229440a403fSchristos typedef struct elf_prstatusx32 prstatusx32_t;
230440a403fSchristos typedef struct elf_prstatus64 prstatus64_t;
231440a403fSchristos typedef struct elf_prpsinfo32 prpsinfo32_t;
232440a403fSchristos typedef struct elf_prpsinfo64 prpsinfo64_t;
233