-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmp_kernel.c
408 lines (359 loc) · 12.3 KB
/
dmp_kernel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/* Debugging dump procedures for the kernel. */
#include "inc.h"
#include <timers.h>
#include <assert.h>
#include <machine/interrupt.h>
#include <minix/endpoint.h>
#include <minix/sysutil.h>
#include <minix/sys_config.h>
#include "kernel/const.h"
#include "kernel/config.h"
#include "kernel/debug.h"
#include "kernel/type.h"
#include "kernel/proc.h"
#include "kernel/ipc.h"
#include "../pm/mproc.h"
#define LINES 22
#define PRINTRTS(rp) { \
char *procname = ""; \
printf(" %s", p_rts_flags_str(rp->p_rts_flags)); \
if (rp->p_rts_flags & RTS_SENDING) \
procname = proc_name(_ENDPOINT_P(rp->p_sendto_e)); \
else if (rp->p_rts_flags & RTS_RECEIVING) \
procname = proc_name(_ENDPOINT_P(rp->p_getfrom_e)); \
printf(" %-7.7s", procname); \
}
static int pagelines;
#define PROCLOOP(rp, oldrp) \
pagelines = 0; \
for (rp = oldrp; rp < END_PROC_ADDR; rp++) { \
oldrp = BEG_PROC_ADDR; \
if (isemptyp(rp)) continue; \
if (++pagelines > LINES) { oldrp = rp; printf("--more--\n"); break; }\
if (proc_nr(rp) == IDLE) printf("(%2d) ", proc_nr(rp)); \
else if (proc_nr(rp) < 0) printf("[%2d] ", proc_nr(rp)); \
else printf(" %2d ", proc_nr(rp));
#define click_to_round_k(n) \
((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))
/* Declare some local dump procedures. */
static char *proc_name(int proc_nr);
static char *s_traps_str(int flags);
static char *s_flags_str(int flags);
static char *p_rts_flags_str(int flags);
/* Some global data that is shared among several dumping procedures.
* Note that the process table copy has the same name as in the kernel
* so that most macros and definitions from proc.h also apply here.
*/
struct proc proc[NR_TASKS + NR_PROCS];
struct priv priv[NR_SYS_PROCS];
struct boot_image image[NR_BOOT_PROCS];
extern struct minix_kerninfo *_minix_kerninfo;
/*===========================================================================*
* pscount_dmp *
*===========================================================================*/
void pscount_dmp()
{
struct mproc *mp;
int i,n=0;
if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc, sizeof(mproc))!=OK){
printf("Error obtaining table from PM. Perhaps recompile IS?\n");
return;
}
for(i=0;i<NR_PROCS;i++){
mp=&mproc[i];
if(mp->mp_pid==0 && i!=PM_PROC_NR) continue;
n++;
}
printf("Number of running processes: %d\n",n);
}
/*===========================================================================*
* kmessages_dmp *
*===========================================================================*/
void kmessages_dmp()
{
struct kmessages *kmess; /* get copy of kernel messages */
static char print_buf[_KMESS_BUF_SIZE+1]; /* this one is used to print */
int start; /* calculate start of messages */
int r;
int size;
assert(_minix_kerninfo);
kmess = _minix_kerninfo->kmessages;
/* Try to print the kernel messages. First determine start and copy the
* buffer into a print-buffer. This is done because the messages in the
* copy may wrap (the kernel buffer is circular).
*/
start = ((kmess->km_next + _KMESS_BUF_SIZE) - kmess->km_size) % _KMESS_BUF_SIZE;
r = 0;
size = kmess->km_size;
while (size > 0) {
print_buf[r] = kmess->km_buf[(start+r) % _KMESS_BUF_SIZE];
r ++;
size--;
}
print_buf[r] = 0; /* make sure it terminates */
printf("Dump of all messages generated by the kernel.\n\n");
printf("%s", print_buf); /* print the messages */
}
/*===========================================================================*
* monparams_dmp *
*===========================================================================*/
void monparams_dmp()
{
char val[MULTIBOOT_PARAM_BUF_SIZE];
char *e;
int r;
/* Try to get a copy of the boot monitor parameters. */
if ((r = sys_getmonparams(val, sizeof(val))) != OK) {
printf("IS: warning: couldn't get copy of monitor params: %d\n", r);
return;
}
/* Append new lines to the result. */
e = val;
do {
e += strlen(e);
*e++ = '\n';
} while (*e != 0);
/* Finally, print the result. */
printf("Dump of kernel environment strings set by boot monitor.\n");
printf("\n%s\n", val);
}
/*===========================================================================*
* irqtab_dmp *
*===========================================================================*/
void irqtab_dmp()
{
int i,r;
struct irq_hook irq_hooks[NR_IRQ_HOOKS];
int irq_actids[NR_IRQ_VECTORS];
struct irq_hook *e; /* irq tab entry */
if ((r = sys_getirqhooks(irq_hooks)) != OK) {
printf("IS: warning: couldn't get copy of irq hooks: %d\n", r);
return;
}
if ((r = sys_getirqactids(irq_actids)) != OK) {
printf("IS: warning: couldn't get copy of irq mask: %d\n", r);
return;
}
#if 0
printf("irq_actids:");
for (i= 0; i<NR_IRQ_VECTORS; i++)
printf(" [%d] = 0x%08x", i, irq_actids[i]);
printf("\n");
#endif
printf("IRQ policies dump shows use of kernel's IRQ hooks.\n");
printf("-h.id- -proc.nr- -irq nr- -policy- -notify id- -masked-\n");
for (i=0; i<NR_IRQ_HOOKS; i++) {
e = &irq_hooks[i];
printf("%3d", i);
if (e->proc_nr_e==NONE) {
printf(" <unused>\n");
continue;
}
printf("%10d ", e->proc_nr_e);
printf(" (%02d) ", e->irq);
printf(" %s", (e->policy & IRQ_REENABLE) ? "reenable" : " - ");
printf(" %4lu", e->notify_id);
if (irq_actids[e->irq] & e->id)
printf(" masked");
printf("\n");
}
printf("\n");
}
/*===========================================================================*
* image_dmp *
*===========================================================================*/
void image_dmp()
{
int m, r;
struct boot_image *ip;
if ((r = sys_getimage(image)) != OK) {
printf("IS: warning: couldn't get copy of image table: %d\n", r);
return;
}
printf("Image table dump showing all processes included in system image.\n");
printf("---name- -nr- flags -stack-\n");
for (m=0; m<NR_BOOT_PROCS; m++) {
ip = &image[m];
printf("%8s %4d\n", ip->proc_name, ip->proc_nr);
}
printf("\n");
}
/*===========================================================================*
* kenv_dmp *
*===========================================================================*/
void kenv_dmp()
{
struct kinfo kinfo;
struct machine machine;
int r;
if ((r = sys_getkinfo(&kinfo)) != OK) {
printf("IS: warning: couldn't get copy of kernel info struct: %d\n", r);
return;
}
if ((r = sys_getmachine(&machine)) != OK) {
printf("IS: warning: couldn't get copy of kernel machine struct: %d\n", r);
return;
}
printf("Dump of kinfo structure.\n\n");
printf("Kernel info structure:\n");
printf("- nr_procs: %3u\n", kinfo.nr_procs);
printf("- nr_tasks: %3u\n", kinfo.nr_tasks);
printf("- release: %.6s\n", kinfo.release);
printf("- version: %.6s\n", kinfo.version);
printf("\n");
}
/*===========================================================================*
* s_flags_str *
*===========================================================================*/
static char *s_flags_str(int flags)
{
static char str[10];
str[0] = (flags & PREEMPTIBLE) ? 'P' : '-';
str[1] = (flags & BILLABLE) ? 'B' : '-';
str[2] = (flags & DYN_PRIV_ID) ? 'D' : '-';
str[3] = (flags & SYS_PROC) ? 'S' : '-';
str[4] = (flags & CHECK_IO_PORT) ? 'I' : '-';
str[5] = (flags & CHECK_IRQ) ? 'Q' : '-';
str[6] = (flags & CHECK_MEM) ? 'M' : '-';
str[7] = '\0';
return str;
}
/*===========================================================================*
* s_traps_str *
*===========================================================================*/
static char *s_traps_str(int flags)
{
static char str[10];
str[0] = (flags & (1 << SEND)) ? 'S' : '-';
str[1] = (flags & (1 << SENDA)) ? 'A' : '-';
str[2] = (flags & (1 << RECEIVE)) ? 'R' : '-';
str[3] = (flags & (1 << SENDREC)) ? 'B' : '-';
str[4] = (flags & (1 << NOTIFY)) ? 'N' : '-';
str[5] = '\0';
return str;
}
/*===========================================================================*
* privileges_dmp *
*===========================================================================*/
void privileges_dmp()
{
register struct proc *rp;
static struct proc *oldrp = BEG_PROC_ADDR;
register struct priv *sp;
int r, i;
/* First obtain a fresh copy of the current process and system table. */
if ((r = sys_getprivtab(priv)) != OK) {
printf("IS: warning: couldn't get copy of system privileges table: %d\n", r);
return;
}
if ((r = sys_getproctab(proc)) != OK) {
printf("IS: warning: couldn't get copy of process table: %d\n", r);
return;
}
printf("-nr- -id- -name-- -flags- traps grants -ipc_to--"
" -kernel calls-\n");
PROCLOOP(rp, oldrp)
r = -1;
for (sp = &priv[0]; sp < &priv[NR_SYS_PROCS]; sp++)
if (sp->s_proc_nr == rp->p_nr) { r ++; break; }
if (r == -1 && !isemptyp(rp)) {
sp = &priv[USER_PRIV_ID];
}
printf("(%02u) %-7.7s %s %s %6d",
sp->s_id, rp->p_name,
s_flags_str(sp->s_flags), s_traps_str(sp->s_trap_mask),
sp->s_grant_entries);
for (i=0; i < NR_SYS_PROCS; i += BITCHUNK_BITS) {
printf(" %08x", get_sys_bits(sp->s_ipc_to, i));
}
printf(" ");
for (i=0; i < NR_SYS_CALLS; i += BITCHUNK_BITS) {
printf(" %08x", sp->s_k_call_mask[i/BITCHUNK_BITS]);
}
printf("\n");
}
}
/*===========================================================================*
* p_rts_flags_str *
*===========================================================================*/
static char *p_rts_flags_str(int flags)
{
static char str[10];
str[0] = (flags & RTS_PROC_STOP) ? 's' : '-';
str[1] = (flags & RTS_SENDING) ? 'S' : '-';
str[2] = (flags & RTS_RECEIVING) ? 'R' : '-';
str[3] = (flags & RTS_SIGNALED) ? 'I' : '-';
str[4] = (flags & RTS_SIG_PENDING) ? 'P' : '-';
str[5] = (flags & RTS_P_STOP) ? 'T' : '-';
str[6] = (flags & RTS_NO_PRIV) ? 'p' : '-';
str[7] = '\0';
return str;
}
/*===========================================================================*
* proctab_dmp *
*===========================================================================*/
#if defined(__i386__)
void proctab_dmp(void)
{
/* Proc table dump */
register struct proc *rp;
static struct proc *oldrp = BEG_PROC_ADDR;
int r;
/* First obtain a fresh copy of the current process table. */
if ((r = sys_getproctab(proc)) != OK) {
printf("IS: warning: couldn't get copy of process table: %d\n", r);
return;
}
printf("\n-nr-----gen---endpoint-name--- -prior-quant- -user----sys-rtsflags-from/to-\n");
PROCLOOP(rp, oldrp)
printf(" %5d %10d ", _ENDPOINT_G(rp->p_endpoint), rp->p_endpoint);
printf("%-8.8s %5u %5u %6u %6u ",
rp->p_name,
rp->p_priority,
rp->p_quantum_size_ms,
rp->p_user_time, rp->p_sys_time);
PRINTRTS(rp);
printf("\n");
}
}
#endif /* defined(__i386__) */
#if defined(__arm__)
void proctab_dmp(void)
{
/* LSC FIXME: Not implemented for arm */
}
#endif /* defined(__arm__) */
/*===========================================================================*
* procstack_dmp *
*===========================================================================*/
void procstack_dmp()
{
/* Proc table dump, with stack */
register struct proc *rp;
static struct proc *oldrp = BEG_PROC_ADDR;
int r;
/* First obtain a fresh copy of the current process table. */
if ((r = sys_getproctab(proc)) != OK) {
printf("IS: warning: couldn't get copy of process table: %d\n", r);
return;
}
printf("\n-nr-rts flags-- --stack--\n");
PROCLOOP(rp, oldrp)
PRINTRTS(rp);
sys_sysctl_stacktrace(rp->p_endpoint);
}
}
/*===========================================================================*
* proc_name *
*===========================================================================*/
static char *proc_name(proc_nr)
int proc_nr;
{
struct proc *p;
if (proc_nr == ANY) return "ANY";
if (proc_nr == NONE) return "NONE"; /* bogus */
if (proc_nr < -NR_TASKS || proc_nr >= NR_PROCS) return "BOGUS";
p = proc_addr(proc_nr);
if (isemptyp(p)) return "EMPTY"; /* bogus */
return p->p_name;
}