xref: /titanic_51/usr/src/cmd/mdb/common/mdb/mdb_gcore.h (revision 69a119caa6570c7077699161b7c28b6ee9f8b0f4)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 /*
12  * Copyright (c) 2013 by Delphix. All rights reserved.
13  */
14 
15 #ifndef	_MDB_GCORE_H
16 #define	_MDB_GCORE_H
17 
18 /*
19  * The kernel has its own definition of exit which has a different signature
20  * than the user space definition.  This seems to be the standard way to deal
21  * with this.
22  */
23 #define	exit kern_exit
24 
25 #include <sys/cpuvar.h>
26 #include <sys/cred_impl.h>
27 #include <sys/procfs.h>
28 #include <vm/anon.h>
29 
30 #undef exit
31 
32 /* mdb versions of kernel structures used for ctf read calls */
33 typedef struct mdb_proc {
34 	uintptr_t	p_as;
35 	uintptr_t	p_brkbase;
36 	size_t		p_brksize;
37 	uintptr_t	p_usrstack;
38 	size_t		p_stksize;
39 	user_t		p_user;
40 	uintptr_t	p_agenttp;
41 	uintptr_t	p_tlist;
42 	uintptr_t	p_zone;
43 	uintptr_t	p_ldt;
44 	kcondvar_t	p_holdlwps;
45 	int		p_lwpcnt;
46 	uintptr_t	p_lwpdir;
47 	uint_t		p_lwpdir_sz;
48 	uintptr_t	p_cred;
49 	uint_t		p_flag;
50 	int		p_zombcnt;
51 	uintptr_t	p_pidp;
52 	pid_t		p_ppid;
53 	uintptr_t	p_pgidp;
54 	uintptr_t	p_sessp;
55 	uintptr_t	p_task;
56 	uintptr_t	p_pool;
57 	model_t		p_model;
58 	char		p_wcode;
59 	ushort_t	p_ldtlimit;
60 	uintptr_t	p_exec;
61 	uint_t		p_proc_flag;
62 	ushort_t	p_pidflag;
63 	k_sigset_t	p_ignore;
64 	k_sigset_t	p_siginfo;
65 	k_sigset_t	p_sig;
66 	k_sigset_t	p_sigmask;
67 	k_fltset_t	p_fltmask;
68 	int		p_wdata;
69 } mdb_proc_t;
70 
71 typedef struct mdb_kthread {
72 	ushort_t	t_proc_flag;
73 	uint_t		t_state;
74 	lwpchan_t	t_lwpchan;
75 	ushort_t	t_whystop;
76 	uint8_t		t_dtrace_stop;
77 	uintptr_t	t_forw;
78 	uintptr_t	t_lwp;
79 	id_t		t_tid;
80 	short		t_sysnum;
81 	pri_t		t_pri;
82 	time_t		t_start;
83 	id_t		t_cid;
84 	uintptr_t	t_cpu;
85 	int		t_bind_pset;
86 	short		t_bind_cpu;
87 	uintptr_t	t_lpl;
88 	ushort_t	t_schedflag;
89 	ushort_t	t_whatstop;
90 	k_sigset_t	t_sig;
91 	uintptr_t	t_schedctl;
92 	k_sigset_t	t_hold;
93 	hrtime_t	t_stoptime;
94 } mdb_kthread_t;
95 
96 typedef struct mdb_seg {
97 	uintptr_t	s_base;
98 	size_t		s_size;
99 	uintptr_t	s_ops;
100 	uintptr_t	s_data;
101 	uintptr_t	s_as;
102 } mdb_seg_t;
103 
104 typedef struct mdb_as {
105 	uintptr_t	a_proc;
106 } mdb_as_t;
107 
108 typedef struct mdb_segvn_data {
109 	uintptr_t	vp;
110 	uint64_t	offset;
111 	uint16_t	flags;
112 	uint8_t		pageprot;
113 	uint8_t		prot;
114 	uintptr_t	amp;
115 	struct vpage	*vpage;
116 	uint64_t	anon_index;
117 	uint8_t		type;
118 } mdb_segvn_data_t;
119 
120 typedef struct mdb_vnode {
121 	enum vtype	v_type;
122 	uintptr_t	v_data;
123 	uintptr_t	v_op;
124 	uintptr_t	v_path;
125 } mdb_vnode_t;
126 
127 typedef struct mdb_znode {
128 	uint64_t	z_size;
129 } mdb_znode_t;
130 
131 typedef struct mdb_tmpnode {
132 	vattr_t		tn_attr;
133 } mdb_tmpnode_t;
134 
135 typedef struct mdb_vnodeops {
136 	uintptr_t	vnop_name;
137 } mdb_vnodeops_t;
138 
139 typedef struct mdb_shm_data {
140 	uintptr_t	shm_sptseg;
141 } mdb_shm_data_t;
142 
143 typedef struct mdb_watched_page {
144 	uintptr_t	wp_vaddr;
145 	uint8_t		wp_oprot;
146 } mdb_watched_page_t;
147 
148 typedef struct mdb_pid {
149 	pid_t		pid_id;
150 } mdb_pid_t;
151 
152 typedef struct mdb_sess {
153 	uintptr_t	s_sidp;
154 } mdb_sess_t;
155 
156 typedef struct mdb_task {
157 	taskid_t	tk_tkid;
158 	uintptr_t	tk_proj;
159 } mdb_task_t;
160 
161 typedef struct mdb_kproject {
162 	projid_t	kpj_id;
163 } mdb_kproject_t;
164 
165 typedef struct mdb_zone {
166 	zoneid_t	zone_id;
167 	uintptr_t	zone_name;
168 } mdb_zone_t;
169 
170 typedef struct mdb_sc_shared {
171 	char		sc_sigblock;
172 } mdb_sc_shared_t;
173 
174 typedef struct mdb_klwp {
175 	uintptr_t	lwp_regs;
176 	struct pcb	lwp_pcb;
177 	uchar_t		lwp_asleep;
178 	uchar_t		lwp_cursig;
179 	uintptr_t	lwp_curinfo;
180 	k_siginfo_t	lwp_siginfo;
181 	stack_t		lwp_sigaltstack;
182 	uintptr_t	lwp_oldcontext;
183 	short		lwp_badpriv;
184 	uintptr_t	lwp_ustack;
185 	char		lwp_eosys;
186 } mdb_klwp_t;
187 
188 typedef struct mdb_cpu {
189 	processorid_t	cpu_id;
190 } mdb_cpu_t;
191 
192 typedef struct mdb_lpl {
193 	lgrp_id_t	lpl_lgrpid;
194 } mdb_lpl_t;
195 
196 typedef struct mdb_sigqueue {
197 	k_siginfo_t	sq_info;
198 } mdb_sigqueue_t;
199 
200 typedef struct mdb_pool {
201 	poolid_t	pool_id;
202 } mdb_pool_t;
203 
204 typedef struct mdb_amp {
205 	uintptr_t	ahp;
206 } mdb_amp_t;
207 
208 typedef struct mdb_anon_hdr {
209 	pgcnt_t		size;
210 	uintptr_t	array_chunk;
211 	int		flags;
212 } mdb_anon_hdr_t;
213 
214 typedef struct mdb_anon {
215 	uintptr_t	an_vp;
216 	anoff_t		an_off;
217 } mdb_anon_t;
218 
219 /* Used to construct a linked list of prmap_ts */
220 typedef struct prmap_node {
221 	struct prmap_node *next;
222 	prmap_t		m;
223 } prmap_node_t;
224 
225 /* Fields common to psinfo_t and pstatus_t */
226 typedef struct pcommon {
227 	int		pc_nlwp;
228 	int		pc_nzomb;
229 	pid_t		pc_pid;
230 	pid_t		pc_ppid;
231 	pid_t		pc_pgid;
232 	pid_t		pc_sid;
233 	taskid_t	pc_taskid;
234 	projid_t	pc_projid;
235 	zoneid_t	pc_zoneid;
236 	char		pc_dmodel;
237 } pcommon_t;
238 
239 /* AVL walk callback structures */
240 typedef struct read_maps_cbarg {
241 	mdb_proc_t	*p;
242 	uintptr_t	brkseg;
243 	uintptr_t	stkseg;
244 	prmap_node_t	*map_head;
245 	prmap_node_t	*map_tail;
246 	int		map_len;
247 } read_maps_cbarg_t;
248 
249 typedef struct as_segat_cbarg {
250 	uintptr_t	addr;
251 	uintptr_t	res;
252 } as_segat_cbarg_t;
253 
254 typedef struct getwatchprot_cbarg {
255 	uintptr_t	wp_vaddr;
256 	mdb_watched_page_t wp;
257 	boolean_t	found;
258 } getwatchprot_cbarg_t;
259 
260 struct gcore_segops;
261 typedef struct gcore_seg {
262 	mdb_seg_t	*gs_seg;
263 	void		*gs_data;
264 	struct gcore_segops *gs_ops;
265 } gcore_seg_t;
266 
267 /*
268  * These are the ISA-dependent functions that need to be
269  * implemented for ::gcore.
270  */
271 extern uintptr_t gcore_prgetstackbase(mdb_proc_t *);
272 extern int gcore_prfetchinstr(mdb_klwp_t *, ulong_t *);
273 extern int gcore_prisstep(mdb_klwp_t *);
274 extern void gcore_getgregs(mdb_klwp_t *, gregset_t);
275 extern int gcore_prgetrvals(mdb_klwp_t *, long *, long *);
276 
277 #endif	/* _MDB_GCORE_H */
278