-
Notifications
You must be signed in to change notification settings - Fork 273
/
kernel.c
12003 lines (10383 loc) · 329 KB
/
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* kernel.c - core analysis suite
*
* Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
* Copyright (C) 2002-2019 David Anderson
* Copyright (C) 2002-2019 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "defs.h"
#include "xen_hyper_defs.h"
#include "xen_dom0.h"
#include <elf.h>
#include <libgen.h>
#include <ctype.h>
#include <stdbool.h>
#include "xendump.h"
#if defined(GDB_7_6) || defined(GDB_10_2)
#define __CONFIG_H__ 1
#include "config.h"
#endif
#include "bfd.h"
static void do_module_cmd(ulong, char *, ulong, char *, char *);
static void show_module_taint(void);
static char *find_module_objfile(char *, char *, char *);
static char *module_objfile_search(char *, char *, char *);
static char *get_loadavg(char *);
static void get_lkcd_regs(struct bt_info *, ulong *, ulong *);
static void dump_sys_call_table(char *, int);
static int get_NR_syscalls(int *);
static ulong get_irq_desc_addr(int);
static void display_cpu_affinity(ulong *);
static void display_bh_1(void);
static void display_bh_2(void);
static void display_bh_3(void);
static void display_bh_4(void);
static void dump_hrtimer_data(const ulong *cpus);
static void dump_hrtimer_clock_base(const void *, const int);
static void dump_hrtimer_base(const void *, const int);
static void dump_active_timers(const void *, ulonglong);
static int get_expires_len(const int, const ulong *, ulonglong, const int);
static void print_timer(const void *, ulonglong);
static ulonglong ktime_to_ns(const void *);
static void dump_timer_data(const ulong *cpus);
static void dump_timer_data_tvec_bases_v1(const ulong *cpus);
static void dump_timer_data_tvec_bases_v2(const ulong *cpus);
static void dump_timer_data_tvec_bases_v3(const ulong *cpus);
static void dump_timer_data_timer_bases(const ulong *cpus);
struct tv_range;
static void init_tv_ranges(struct tv_range *, int, int, int);
static int do_timer_list(ulong,int, ulong *, void *,ulong *, ulong *, struct tv_range *, ulong);
static int do_timer_list_v3(ulong, int, ulong *, void *,ulong *, ulong *, ulong, long);
struct timer_bases_data;
static int do_timer_list_v4(struct timer_bases_data *, ulong);
static int compare_timer_data(const void *, const void *);
static void panic_this_kernel(void);
static void dump_waitq(ulong, char *);
static void reinit_modules(void);
static int verify_modules(void);
static void verify_namelist(void);
static char *debug_kernel_version(char *);
static int restore_stack(struct bt_info *);
static ulong __xen_m2p(ulonglong, ulong);
static ulong __xen_pvops_m2p_l2(ulonglong, ulong);
static ulong __xen_pvops_m2p_l3(ulonglong, ulong);
static ulong __xen_pvops_m2p_hyper(ulonglong, ulong);
static ulong __xen_pvops_m2p_domU(ulonglong, ulong);
static int read_xc_p2m(ulonglong, void *, long);
static void read_p2m(ulong, int, void *);
static int search_mapping_page(ulong, ulong *, ulong *, ulong *);
static void read_in_kernel_config_err(int, char *);
static void BUG_bytes_init(void);
static int BUG_x86(void);
static int BUG_x86_64(void);
static void cpu_maps_init(void);
static void get_xtime(struct timespec *);
static char *log_from_idx(uint32_t, char *);
static uint32_t log_next(uint32_t, char *);
static void dump_log_entry(char *, int);
static void dump_variable_length_record_log(int);
static void hypervisor_init(void);
static void dump_log_legacy(void);
static void dump_variable_length_record(void);
static int is_livepatch(void);
static void show_kernel_taints(char *, int);
static void dump_dmi_info(void);
static void list_source_code(struct gnu_request *, int);
static void source_tree_init(void);
static ulong dump_audit_skb_queue(ulong);
static ulong __dump_audit(char *);
static void dump_audit(void);
static void dump_printk_safe_seq_buf(int);
static char *vmcoreinfo_read_string(const char *);
static void check_vmcoreinfo(void);
static int is_pvops_xen(void);
static int get_linux_banner_from_vmlinux(char *, size_t);
/*
* popuplate the global kernel table (kt) with kernel version
* information parsed from UTSNAME/OSRELEASE string
*/
void
parse_kernel_version(char *str)
{
char *p1, *p2, separator;
p1 = p2 = str;
while (*p2 != '.' && *p2 != '\0')
p2++;
*p2 = NULLCHAR;
kt->kernel_version[0] = atoi(p1);
p1 = ++p2;
while (*p2 != '.' && *p2 != '-' && *p2 != '\0')
p2++;
separator = *p2;
*p2 = NULLCHAR;
kt->kernel_version[1] = atoi(p1);
if (separator == '.') {
p1 = ++p2;
while ((*p2 >= '0') && (*p2 <= '9'))
p2++;
*p2 = NULLCHAR;
kt->kernel_version[2] = atoi(p1);
}
}
/*
* Gather a few kernel basics.
*/
void
kernel_init()
{
int i, c;
char buf[BUFSIZE];
struct syment *sp1, *sp2;
char *rqstruct;
char *rq_timestamp_name = NULL;
char *irq_desc_type_name;
struct gnu_request req;
if (pc->flags & KERNEL_DEBUG_QUERY)
return;
if (!(kt->cpu_flags = (ulong *)calloc(NR_CPUS, sizeof(ulong))))
error(FATAL, "cannot malloc cpu_flags array");
STRUCT_SIZE_INIT(cpumask_t, "cpumask_t");
cpu_maps_init();
kt->stext = symbol_value("_stext");
kt->etext = symbol_value("_etext");
get_text_init_space();
if (symbol_exists("__init_begin")) {
kt->init_begin = symbol_value("__init_begin");
kt->init_end = symbol_value("__init_end");
}
kt->end = highest_bss_symbol();
if ((sp1 = kernel_symbol_search("_end")) && (sp1->value > kt->end))
kt->end = sp1->value;
check_vmcoreinfo();
/*
* For the traditional (non-pv_ops) Xen architecture, default to writable
* page tables unless:
*
* (1) it's an "xm save" CANONICAL_PAGE_TABLES dumpfile, or
* (2) the --shadow_page_tables option was explicitly entered.
*
* But if the "phys_to_maching_mapping" array does not exist, and
* it's not an "xm save" canonical dumpfile, then we have no choice
* but to presume shadow page tables.
*/
if (!PVOPS() && symbol_exists("xen_start_info")) {
kt->flags |= ARCH_XEN;
if (!(kt->xen_flags & (SHADOW_PAGE_TABLES|CANONICAL_PAGE_TABLES)))
kt->xen_flags |= WRITABLE_PAGE_TABLES;
if (symbol_exists("phys_to_machine_mapping"))
get_symbol_data("phys_to_machine_mapping", sizeof(ulong),
&kt->phys_to_machine_mapping);
else if (!(kt->xen_flags & CANONICAL_PAGE_TABLES)) {
kt->xen_flags &= ~WRITABLE_PAGE_TABLES;
kt->xen_flags |= SHADOW_PAGE_TABLES;
}
if (machine_type("X86"))
get_symbol_data("max_pfn", sizeof(ulong), &kt->p2m_table_size);
if (machine_type("X86_64")) {
/*
* kernel version < 2.6.27 => end_pfn
* kernel version >= 2.6.27 => max_pfn
*/
if (!try_get_symbol_data("end_pfn", sizeof(ulong), &kt->p2m_table_size))
get_symbol_data("max_pfn", sizeof(ulong), &kt->p2m_table_size);
}
if ((kt->m2p_page = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc m2p page.");
}
if (is_pvops_xen()) {
kt->flags |= ARCH_XEN | ARCH_PVOPS_XEN;
kt->xen_flags |= WRITABLE_PAGE_TABLES;
if (machine_type("X86"))
get_symbol_data("max_pfn", sizeof(ulong), &kt->p2m_table_size);
if (machine_type("X86_64")) {
if (!try_get_symbol_data("end_pfn", sizeof(ulong), &kt->p2m_table_size))
get_symbol_data("max_pfn", sizeof(ulong), &kt->p2m_table_size);
}
if ((kt->m2p_page = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc m2p page.");
if (symbol_exists("p2m_mid_missing")) {
kt->pvops_xen.p2m_top_entries = XEN_P2M_TOP_PER_PAGE;
get_symbol_data("p2m_top", sizeof(ulong),
&kt->pvops_xen.p2m_top);
get_symbol_data("p2m_mid_missing", sizeof(ulong),
&kt->pvops_xen.p2m_mid_missing);
get_symbol_data("p2m_missing", sizeof(ulong),
&kt->pvops_xen.p2m_missing);
} else if (!symbol_exists("xen_p2m_addr")) {
kt->pvops_xen.p2m_top_entries = get_array_length("p2m_top", NULL, 0);
kt->pvops_xen.p2m_top = symbol_value("p2m_top");
kt->pvops_xen.p2m_missing = symbol_value("p2m_missing");
}
}
if (symbol_exists("smp_num_cpus")) {
kt->flags |= SMP;
get_symbol_data("smp_num_cpus", sizeof(int), &kt->cpus);
if (kt->cpus < 1 || kt->cpus > NR_CPUS)
error(WARNING,
"invalid value: smp_num_cpus: %d\n",
kt->cpus);
} else if (symbol_exists("__per_cpu_offset")) {
kt->flags |= SMP;
kt->cpus = 1;
} else
kt->cpus = 1;
if ((sp1 = symbol_search("__per_cpu_start")) &&
(sp2 = symbol_search("__per_cpu_end")) &&
(sp1->type == 'A' || sp1->type == 'D') &&
(sp2->type == 'A' || sp2->type == 'D') &&
(sp2->value > sp1->value))
kt->flags |= SMP|PER_CPU_OFF;
MEMBER_OFFSET_INIT(timekeeper_xtime, "timekeeper", "xtime");
MEMBER_OFFSET_INIT(timekeeper_xtime_sec, "timekeeper", "xtime_sec");
get_xtime(&kt->date);
if (CRASHDEBUG(1))
fprintf(fp, "xtime timespec.tv_sec: %lx: %s\n",
kt->date.tv_sec, ctime_tz(&kt->date.tv_sec));
if (kt->flags2 & GET_TIMESTAMP) {
fprintf(fp, "%s\n\n", ctime_tz(&kt->date.tv_sec));
clean_exit(0);
}
MEMBER_OFFSET_INIT(uts_namespace_name, "uts_namespace", "name");
if (symbol_exists("system_utsname"))
readmem(symbol_value("system_utsname"), KVADDR, &kt->utsname,
sizeof(struct new_utsname), "system_utsname",
RETURN_ON_ERROR);
else if (symbol_exists("init_uts_ns")) {
long offset = sizeof(int);
if (VALID_MEMBER(uts_namespace_name))
offset = OFFSET(uts_namespace_name);
readmem(symbol_value("init_uts_ns") + offset,
KVADDR, &kt->utsname, sizeof(struct new_utsname),
"init_uts_ns", RETURN_ON_ERROR);
} else
error(INFO, "cannot access utsname information\n\n");
if (CRASHDEBUG(1)) {
fprintf(fp, "utsname:\n");
fprintf(fp, " sysname: %s\n", printable_string(kt->utsname.sysname) ?
kt->utsname.sysname : "(not printable)");
fprintf(fp, " nodename: %s\n", printable_string(kt->utsname.nodename) ?
kt->utsname.nodename : "(not printable)");
fprintf(fp, " release: %s\n", printable_string(kt->utsname.release) ?
kt->utsname.release : "(not printable)");
fprintf(fp, " version: %s\n", printable_string(kt->utsname.version) ?
kt->utsname.version : "(not printable)");
fprintf(fp, " machine: %s\n", printable_string(kt->utsname.machine) ?
kt->utsname.machine : "(not printable)");
fprintf(fp, " domainname: %s\n", printable_string(kt->utsname.domainname) ?
kt->utsname.domainname : "(not printable)");
}
strncpy(buf, kt->utsname.release, 65);
if (buf[64])
buf[64] = NULLCHAR;
if (ascii_string(kt->utsname.release)) {
parse_kernel_version(buf);
if (CRASHDEBUG(1))
fprintf(fp, "base kernel version: %d.%d.%d\n",
kt->kernel_version[0],
kt->kernel_version[1],
kt->kernel_version[2]);
} else
error(INFO, "cannot determine base kernel version\n");
verify_version();
if (symbol_exists("__per_cpu_offset")) {
if (LKCD_KERNTYPES())
i = get_cpus_possible();
else
i = get_array_length("__per_cpu_offset", NULL, 0);
get_symbol_data("__per_cpu_offset",
sizeof(long)*((i && (i <= NR_CPUS)) ? i : NR_CPUS),
&kt->__per_cpu_offset[0]);
kt->flags |= PER_CPU_OFF;
}
MEMBER_OFFSET_INIT(percpu_counter_count, "percpu_counter", "count");
MEMBER_OFFSET_INIT(percpu_counter_counters, "percpu_counter", "counters");
STRUCT_SIZE_INIT(percpu_counter, "percpu_counter");
if (STRUCT_EXISTS("runqueue")) {
rqstruct = "runqueue";
rq_timestamp_name = "timestamp_last_tick";
} else if (STRUCT_EXISTS("rq")) {
rqstruct = "rq";
if (MEMBER_EXISTS("rq", "clock"))
rq_timestamp_name = "clock";
else if (MEMBER_EXISTS("rq", "most_recent_timestamp"))
rq_timestamp_name = "most_recent_timestamp";
else if (MEMBER_EXISTS("rq", "timestamp_last_tick"))
rq_timestamp_name = "timestamp_last_tick";
} else {
rqstruct = NULL;
error(FATAL, "neither runqueue nor rq structures exist\n");
}
MEMBER_OFFSET_INIT(runqueue_cpu, rqstruct, "cpu");
/*
* 'cpu' does not exist in 'struct rq'.
*/
if (VALID_MEMBER(runqueue_cpu) &&
(get_array_length("runqueue.cpu", NULL, 0) > 0)) {
MEMBER_OFFSET_INIT(cpu_s_curr, "cpu_s", "curr");
MEMBER_OFFSET_INIT(cpu_s_idle, "cpu_s", "idle");
STRUCT_SIZE_INIT(cpu_s, "cpu_s");
kt->runq_siblings = get_array_length("runqueue.cpu",
NULL, 0);
if (symbol_exists("__cpu_idx") &&
symbol_exists("__rq_idx")) {
if (!(kt->__cpu_idx = (long *)
calloc(NR_CPUS, sizeof(long))))
error(FATAL, "cannot malloc __cpu_idx array");
if (!(kt->__rq_idx = (long *)
calloc(NR_CPUS, sizeof(long))))
error(FATAL, "cannot malloc __rq_idx array");
if (!readmem(symbol_value("__cpu_idx"), KVADDR,
&kt->__cpu_idx[0], sizeof(long) * NR_CPUS,
"__cpu_idx[NR_CPUS]", RETURN_ON_ERROR))
error(INFO,
"cannot read __cpu_idx[NR_CPUS] array\n");
if (!readmem(symbol_value("__rq_idx"), KVADDR,
&kt->__rq_idx[0], sizeof(long) * NR_CPUS,
"__rq_idx[NR_CPUS]", RETURN_ON_ERROR))
error(INFO,
"cannot read __rq_idx[NR_CPUS] array\n");
} else if (kt->runq_siblings > 1)
error(INFO,
"runq_siblings: %d: __cpu_idx and __rq_idx arrays don't exist?\n",
kt->runq_siblings);
} else {
MEMBER_OFFSET_INIT(runqueue_idle, rqstruct, "idle");
MEMBER_OFFSET_INIT(runqueue_curr, rqstruct, "curr");
ASSIGN_OFFSET(runqueue_cpu) = INVALID_OFFSET;
}
MEMBER_OFFSET_INIT(runqueue_active, rqstruct, "active");
MEMBER_OFFSET_INIT(runqueue_expired, rqstruct, "expired");
MEMBER_OFFSET_INIT(runqueue_arrays, rqstruct, "arrays");
MEMBER_OFFSET_INIT(rq_timestamp, rqstruct, rq_timestamp_name);
MEMBER_OFFSET_INIT(prio_array_queue, "prio_array", "queue");
MEMBER_OFFSET_INIT(prio_array_nr_active, "prio_array", "nr_active");
STRUCT_SIZE_INIT(runqueue, rqstruct);
STRUCT_SIZE_INIT(prio_array, "prio_array");
MEMBER_OFFSET_INIT(rq_cfs, "rq", "cfs");
MEMBER_OFFSET_INIT(task_group_cfs_rq, "task_group", "cfs_rq");
MEMBER_OFFSET_INIT(task_group_rt_rq, "task_group", "rt_rq");
MEMBER_OFFSET_INIT(task_group_parent, "task_group", "parent");
/*
* In 2.4, smp_send_stop() sets smp_num_cpus back to 1
* in some, but not all, architectures. So if a count
* of 1 is found, be suspicious, and check the
* init_tasks[NR_CPUS] array (also intro'd in 2.4),
* for idle thread addresses. For 2.2, prepare for the
* eventuality by verifying the cpu count with the machine
* dependent count.
*/
if ((kt->flags & SMP) && DUMPFILE() && (kt->cpus == 1)) {
if (symbol_exists("init_tasks")) {
ulong init_tasks[NR_CPUS];
int nr_cpus;
BZERO(&init_tasks[0], sizeof(ulong) * NR_CPUS);
nr_cpus = get_array_length("init_tasks", NULL, 0);
if ((nr_cpus < 1) || (nr_cpus > NR_CPUS))
nr_cpus = NR_CPUS;
get_idle_threads(&init_tasks[0], nr_cpus);
for (i = kt->cpus = 0; i < nr_cpus; i++)
if (init_tasks[i])
kt->cpus++;
} else
kt->cpus = machdep->get_smp_cpus();
}
if ((kt->flags & SMP) && ACTIVE() && (kt->cpus == 1) &&
(kt->flags & PER_CPU_OFF))
kt->cpus = machdep->get_smp_cpus();
if (kt->cpus_override && (c = atoi(kt->cpus_override))) {
error(WARNING, "forcing cpu count to: %d\n\n", c);
kt->cpus = c;
}
if (kt->cpus > NR_CPUS) {
error(WARNING,
"%s number of cpus (%d) greater than compiled-in NR_CPUS (%d)\n",
kt->cpus_override && atoi(kt->cpus_override) ?
"configured" : "calculated", kt->cpus, NR_CPUS);
error(FATAL, "recompile crash with larger NR_CPUS\n");
}
hypervisor_init();
STRUCT_SIZE_INIT(spinlock_t, "spinlock_t");
verify_spinlock();
if (STRUCT_EXISTS("atomic_t"))
if (MEMBER_EXISTS("atomic_t", "counter"))
MEMBER_OFFSET_INIT(atomic_t_counter,
"atomic_t", "counter");
STRUCT_SIZE_INIT(list_head, "list_head");
MEMBER_OFFSET_INIT(list_head_next, "list_head", "next");
MEMBER_OFFSET_INIT(list_head_prev, "list_head", "prev");
if (OFFSET(list_head_next) != 0)
error(WARNING,
"list_head.next offset: %ld: list command may fail\n",
OFFSET(list_head_next));
MEMBER_OFFSET_INIT(hlist_node_next, "hlist_node", "next");
MEMBER_OFFSET_INIT(hlist_node_pprev, "hlist_node", "pprev");
STRUCT_SIZE_INIT(hlist_head, "hlist_head");
STRUCT_SIZE_INIT(hlist_node, "hlist_node");
if (STRUCT_EXISTS("irq_desc_t"))
irq_desc_type_name = "irq_desc_t";
else
irq_desc_type_name = "irq_desc";
STRUCT_SIZE_INIT(irq_desc_t, irq_desc_type_name);
if (MEMBER_EXISTS(irq_desc_type_name, "irq_data"))
MEMBER_OFFSET_INIT(irq_desc_t_irq_data, irq_desc_type_name, "irq_data");
else
MEMBER_OFFSET_INIT(irq_desc_t_affinity, irq_desc_type_name, "affinity");
if (MEMBER_EXISTS(irq_desc_type_name, "kstat_irqs"))
MEMBER_OFFSET_INIT(irq_desc_t_kstat_irqs, irq_desc_type_name, "kstat_irqs");
MEMBER_OFFSET_INIT(irq_desc_t_name, irq_desc_type_name, "name");
MEMBER_OFFSET_INIT(irq_desc_t_status, irq_desc_type_name, "status");
if (MEMBER_EXISTS(irq_desc_type_name, "handler"))
MEMBER_OFFSET_INIT(irq_desc_t_handler, irq_desc_type_name, "handler");
else if (MEMBER_EXISTS(irq_desc_type_name, "chip"))
MEMBER_OFFSET_INIT(irq_desc_t_chip, irq_desc_type_name, "chip");
MEMBER_OFFSET_INIT(irq_desc_t_action, irq_desc_type_name, "action");
MEMBER_OFFSET_INIT(irq_desc_t_depth, irq_desc_type_name, "depth");
STRUCT_SIZE_INIT(kernel_stat, "kernel_stat");
MEMBER_OFFSET_INIT(kernel_stat_irqs, "kernel_stat", "irqs");
if (STRUCT_EXISTS("hw_interrupt_type")) {
MEMBER_OFFSET_INIT(hw_interrupt_type_typename,
"hw_interrupt_type", "typename");
MEMBER_OFFSET_INIT(hw_interrupt_type_startup,
"hw_interrupt_type", "startup");
MEMBER_OFFSET_INIT(hw_interrupt_type_shutdown,
"hw_interrupt_type", "shutdown");
MEMBER_OFFSET_INIT(hw_interrupt_type_handle,
"hw_interrupt_type", "handle");
MEMBER_OFFSET_INIT(hw_interrupt_type_enable,
"hw_interrupt_type", "enable");
MEMBER_OFFSET_INIT(hw_interrupt_type_disable,
"hw_interrupt_type", "disable");
MEMBER_OFFSET_INIT(hw_interrupt_type_ack,
"hw_interrupt_type", "ack");
MEMBER_OFFSET_INIT(hw_interrupt_type_end,
"hw_interrupt_type", "end");
MEMBER_OFFSET_INIT(hw_interrupt_type_set_affinity,
"hw_interrupt_type", "set_affinity");
} else { /*
* On later kernels where hw_interrupt_type was replaced
* by irq_chip
*/
MEMBER_OFFSET_INIT(irq_chip_typename,
"irq_chip", "name");
MEMBER_OFFSET_INIT(irq_chip_startup,
"irq_chip", "startup");
MEMBER_OFFSET_INIT(irq_chip_shutdown,
"irq_chip", "shutdown");
MEMBER_OFFSET_INIT(irq_chip_enable,
"irq_chip", "enable");
MEMBER_OFFSET_INIT(irq_chip_disable,
"irq_chip", "disable");
MEMBER_OFFSET_INIT(irq_chip_ack,
"irq_chip", "ack");
MEMBER_OFFSET_INIT(irq_chip_mask,
"irq_chip", "mask");
MEMBER_OFFSET_INIT(irq_chip_mask_ack,
"irq_chip", "mask_ack");
MEMBER_OFFSET_INIT(irq_chip_unmask,
"irq_chip", "unmask");
MEMBER_OFFSET_INIT(irq_chip_eoi,
"irq_chip", "eoi");
MEMBER_OFFSET_INIT(irq_chip_end,
"irq_chip", "end");
MEMBER_OFFSET_INIT(irq_chip_set_affinity,
"irq_chip", "set_affinity");
MEMBER_OFFSET_INIT(irq_chip_retrigger,
"irq_chip", "retrigger");
MEMBER_OFFSET_INIT(irq_chip_set_type,
"irq_chip", "set_type");
MEMBER_OFFSET_INIT(irq_chip_set_wake,
"irq_chip", "set_wake");
}
MEMBER_OFFSET_INIT(irqaction_handler, "irqaction", "handler");
MEMBER_OFFSET_INIT(irqaction_flags, "irqaction", "flags");
MEMBER_OFFSET_INIT(irqaction_mask, "irqaction", "mask");
MEMBER_OFFSET_INIT(irqaction_name, "irqaction", "name");
MEMBER_OFFSET_INIT(irqaction_dev_id, "irqaction", "dev_id");
MEMBER_OFFSET_INIT(irqaction_next, "irqaction", "next");
/* 6.5 and later: CONFIG_SPARSE_IRQ */
if (kernel_symbol_exists("sparse_irqs"))
kt->flags2 |= IRQ_DESC_TREE_MAPLE;
else if (kernel_symbol_exists("irq_desc_tree")) {
get_symbol_type("irq_desc_tree", NULL, &req);
if (STREQ(req.type_tag_name, "xarray")) {
kt->flags2 |= IRQ_DESC_TREE_XARRAY;
} else {
if (MEMBER_EXISTS("radix_tree_root", "xa_head"))
kt->flags2 |= IRQ_DESC_TREE_XARRAY;
else
kt->flags2 |= IRQ_DESC_TREE_RADIX;
}
}
STRUCT_SIZE_INIT(irq_data, "irq_data");
if (VALID_STRUCT(irq_data)) {
MEMBER_OFFSET_INIT(irq_data_irq, "irq_data", "irq");
MEMBER_OFFSET_INIT(irq_data_chip, "irq_data", "chip");
MEMBER_OFFSET_INIT(irq_data_affinity, "irq_data", "affinity");
MEMBER_OFFSET_INIT(irq_desc_irq_data, "irq_desc", "irq_data");
}
STRUCT_SIZE_INIT(irq_common_data, "irq_common_data");
if (VALID_STRUCT(irq_common_data)) {
MEMBER_OFFSET_INIT(irq_common_data_affinity, "irq_common_data", "affinity");
MEMBER_OFFSET_INIT(irq_desc_irq_common_data, "irq_desc", "irq_common_data");
}
STRUCT_SIZE_INIT(irq_cpustat_t, "irq_cpustat_t");
MEMBER_OFFSET_INIT(irq_cpustat_t___softirq_active,
"irq_cpustat_t", "__softirq_active");
MEMBER_OFFSET_INIT(irq_cpustat_t___softirq_mask,
"irq_cpustat_t", "__softirq_mask");
STRUCT_SIZE_INIT(timer_list, "timer_list");
MEMBER_OFFSET_INIT(timer_list_list, "timer_list", "list");
MEMBER_OFFSET_INIT(timer_list_next, "timer_list", "next");
MEMBER_OFFSET_INIT(timer_list_entry, "timer_list", "entry");
MEMBER_OFFSET_INIT(timer_list_expires, "timer_list", "expires");
MEMBER_OFFSET_INIT(timer_list_function, "timer_list", "function");
STRUCT_SIZE_INIT(timer_vec_root, "timer_vec_root");
if (VALID_STRUCT(timer_vec_root))
MEMBER_OFFSET_INIT(timer_vec_root_vec,
"timer_vec_root", "vec");
STRUCT_SIZE_INIT(timer_vec, "timer_vec");
if (VALID_STRUCT(timer_vec))
MEMBER_OFFSET_INIT(timer_vec_vec, "timer_vec", "vec");
STRUCT_SIZE_INIT(tvec_root_s, "tvec_root_s");
if (VALID_STRUCT(tvec_root_s)) {
STRUCT_SIZE_INIT(tvec_t_base_s, "tvec_t_base_s");
MEMBER_OFFSET_INIT(tvec_t_base_s_tv1,
"tvec_t_base_s", "tv1");
MEMBER_OFFSET_INIT(tvec_root_s_vec,
"tvec_root_s", "vec");
STRUCT_SIZE_INIT(tvec_s, "tvec_s");
MEMBER_OFFSET_INIT(tvec_s_vec, "tvec_s", "vec");
} else {
STRUCT_SIZE_INIT(tvec_root_s, "tvec_root");
if (VALID_STRUCT(tvec_root_s)) {
STRUCT_SIZE_INIT(tvec_t_base_s, "tvec_base");
MEMBER_OFFSET_INIT(tvec_t_base_s_tv1,
"tvec_base", "tv1");
MEMBER_OFFSET_INIT(tvec_root_s_vec,
"tvec_root", "vec");
STRUCT_SIZE_INIT(tvec_s, "tvec");
MEMBER_OFFSET_INIT(tvec_s_vec, "tvec", "vec");
}
}
if (per_cpu_symbol_search("timer_bases")) {
kt->flags2 |= TIMER_BASES;
MEMBER_OFFSET_INIT(timer_base_vectors, "timer_base", "vectors");
STRUCT_SIZE_INIT(timer_base, "timer_base");
} else if (per_cpu_symbol_search("per_cpu__tvec_bases")) {
if (MEMBER_EXISTS("tvec_base", "migration_enabled"))
kt->flags2 |= TVEC_BASES_V3;
else
kt->flags |= TVEC_BASES_V2;
} else if (symbol_exists("tvec_bases"))
kt->flags |= TVEC_BASES_V1;
STRUCT_SIZE_INIT(__wait_queue, "__wait_queue");
STRUCT_SIZE_INIT(wait_queue_entry, "wait_queue_entry");
if (VALID_STRUCT(wait_queue_entry)) {
MEMBER_OFFSET_INIT(wait_queue_entry_private,
"wait_queue_entry", "private");
MEMBER_OFFSET_INIT(wait_queue_head_head,
"wait_queue_head", "head");
MEMBER_OFFSET_INIT(wait_queue_entry_entry,
"wait_queue_entry", "entry");
} else if (VALID_STRUCT(__wait_queue)) {
if (MEMBER_EXISTS("__wait_queue", "task"))
MEMBER_OFFSET_INIT(__wait_queue_task,
"__wait_queue", "task");
else
MEMBER_OFFSET_INIT(__wait_queue_task,
"__wait_queue", "private");
MEMBER_OFFSET_INIT(__wait_queue_head_task_list,
"__wait_queue_head", "task_list");
MEMBER_OFFSET_INIT(__wait_queue_task_list,
"__wait_queue", "task_list");
} else {
STRUCT_SIZE_INIT(wait_queue, "wait_queue");
if (VALID_STRUCT(wait_queue)) {
MEMBER_OFFSET_INIT(wait_queue_task,
"wait_queue", "task");
MEMBER_OFFSET_INIT(wait_queue_next,
"wait_queue", "next");
}
}
STRUCT_SIZE_INIT(pt_regs, "pt_regs");
STRUCT_SIZE_INIT(softirq_state, "softirq_state");
STRUCT_SIZE_INIT(softirq_action, "softirq_action");
STRUCT_SIZE_INIT(desc_struct, "desc_struct");
STRUCT_SIZE_INIT(fred_frame, "fred_frame");
STRUCT_SIZE_INIT(char_device_struct, "char_device_struct");
if (VALID_STRUCT(char_device_struct)) {
MEMBER_OFFSET_INIT(char_device_struct_next,
"char_device_struct", "next");
MEMBER_OFFSET_INIT(char_device_struct_name,
"char_device_struct", "name");
MEMBER_OFFSET_INIT(char_device_struct_fops,
"char_device_struct", "fops");
MEMBER_OFFSET_INIT(char_device_struct_major,
"char_device_struct", "major");
MEMBER_OFFSET_INIT(char_device_struct_baseminor,
"char_device_struct", "baseminor");
MEMBER_OFFSET_INIT(char_device_struct_cdev,
"char_device_struct", "cdev");
}
STRUCT_SIZE_INIT(cdev, "cdev");
if (VALID_STRUCT(cdev))
MEMBER_OFFSET_INIT(cdev_ops, "cdev", "ops");
STRUCT_SIZE_INIT(probe, "probe");
if (VALID_STRUCT(probe)) {
MEMBER_OFFSET_INIT(probe_next, "probe", "next");
MEMBER_OFFSET_INIT(probe_dev, "probe", "dev");
MEMBER_OFFSET_INIT(probe_data, "probe", "data");
}
STRUCT_SIZE_INIT(kobj_map, "kobj_map");
if (VALID_STRUCT(kobj_map))
MEMBER_OFFSET_INIT(kobj_map_probes, "kobj_map", "probes");
MEMBER_OFFSET_INIT(module_kallsyms_start, "module",
"kallsyms_start");
STRUCT_SIZE_INIT(kallsyms_header, "kallsyms_header");
if (VALID_MEMBER(module_kallsyms_start) &&
VALID_SIZE(kallsyms_header)) {
MEMBER_OFFSET_INIT(kallsyms_header_sections,
"kallsyms_header", "sections");
MEMBER_OFFSET_INIT(kallsyms_header_section_off,
"kallsyms_header", "section_off");
MEMBER_OFFSET_INIT(kallsyms_header_symbols,
"kallsyms_header", "symbols");
MEMBER_OFFSET_INIT(kallsyms_header_symbol_off,
"kallsyms_header", "symbol_off");
MEMBER_OFFSET_INIT(kallsyms_header_string_off,
"kallsyms_header", "string_off");
MEMBER_OFFSET_INIT(kallsyms_symbol_section_off,
"kallsyms_symbol", "section_off");
MEMBER_OFFSET_INIT(kallsyms_symbol_symbol_addr,
"kallsyms_symbol", "symbol_addr");
MEMBER_OFFSET_INIT(kallsyms_symbol_name_off,
"kallsyms_symbol", "name_off");
MEMBER_OFFSET_INIT(kallsyms_section_start,
"kallsyms_section", "start");
MEMBER_OFFSET_INIT(kallsyms_section_size,
"kallsyms_section", "size");
MEMBER_OFFSET_INIT(kallsyms_section_name_off,
"kallsyms_section", "name_off");
STRUCT_SIZE_INIT(kallsyms_symbol, "kallsyms_symbol");
STRUCT_SIZE_INIT(kallsyms_section, "kallsyms_section");
if (!(kt->flags & NO_KALLSYMS))
kt->flags |= KALLSYMS_V1;
}
MEMBER_OFFSET_INIT(module_num_symtab, "module", "num_symtab");
if (VALID_MEMBER(module_num_symtab)) {
MEMBER_OFFSET_INIT(module_symtab, "module", "symtab");
MEMBER_OFFSET_INIT(module_strtab, "module", "strtab");
if (!(kt->flags & NO_KALLSYMS))
kt->flags |= KALLSYMS_V2;
}
if (INVALID_MEMBER(module_num_symtab) &&
MEMBER_EXISTS("module", "core_kallsyms")) {
ASSIGN_OFFSET(module_num_symtab) =
MEMBER_OFFSET("module", "core_kallsyms") +
MEMBER_OFFSET("mod_kallsyms", "num_symtab");
ASSIGN_OFFSET(module_symtab) =
MEMBER_OFFSET("module", "core_kallsyms") +
MEMBER_OFFSET("mod_kallsyms", "symtab");
ASSIGN_OFFSET(module_strtab) =
MEMBER_OFFSET("module", "core_kallsyms") +
MEMBER_OFFSET("mod_kallsyms", "strtab");
if (!(kt->flags & NO_KALLSYMS))
kt->flags |= KALLSYMS_V2;
}
if (!(kt->flags & DWARF_UNWIND))
kt->flags |= NO_DWARF_UNWIND;
/*
* OpenVZ
*/
if (kernel_symbol_exists("pcpu_info") &&
STRUCT_EXISTS("pcpu_info") && STRUCT_EXISTS("vcpu_struct")) {
MEMBER_OFFSET_INIT(pcpu_info_vcpu, "pcpu_info", "vcpu");
MEMBER_OFFSET_INIT(pcpu_info_idle, "pcpu_info", "idle");
MEMBER_OFFSET_INIT(vcpu_struct_rq, "vcpu_struct", "rq");
STRUCT_SIZE_INIT(pcpu_info, "pcpu_info");
STRUCT_SIZE_INIT(vcpu_struct, "vcpu_struct");
kt->flags |= ARCH_OPENVZ;
}
STRUCT_SIZE_INIT(mem_section, "mem_section");
BUG_bytes_init();
/*
* for hrtimer
*/
STRUCT_SIZE_INIT(hrtimer_clock_base, "hrtimer_clock_base");
if (VALID_STRUCT(hrtimer_clock_base)) {
MEMBER_OFFSET_INIT(hrtimer_clock_base_offset,
"hrtimer_clock_base", "offset");
MEMBER_OFFSET_INIT(hrtimer_clock_base_active,
"hrtimer_clock_base", "active");
MEMBER_OFFSET_INIT(hrtimer_clock_base_first,
"hrtimer_clock_base", "first");
MEMBER_OFFSET_INIT(hrtimer_clock_base_get_time,
"hrtimer_clock_base", "get_time");
}
STRUCT_SIZE_INIT(hrtimer_base, "hrtimer_base");
if (VALID_STRUCT(hrtimer_base)) {
MEMBER_OFFSET_INIT(hrtimer_base_first,
"hrtimer_base", "first");
MEMBER_OFFSET_INIT(hrtimer_base_pending,
"hrtimer_base", "pending");
MEMBER_OFFSET_INIT(hrtimer_base_get_time,
"hrtimer_base", "get_time");
}
MEMBER_OFFSET_INIT(hrtimer_cpu_base_clock_base, "hrtimer_cpu_base",
"clock_base");
MEMBER_OFFSET_INIT(hrtimer_node, "hrtimer", "node");
MEMBER_OFFSET_INIT(hrtimer_list, "hrtimer", "list");
MEMBER_OFFSET_INIT(hrtimer_expires, "hrtimer", "expires");
if (INVALID_MEMBER(hrtimer_expires))
MEMBER_OFFSET_INIT(hrtimer_expires, "hrtimer", "_expires");
if (INVALID_MEMBER(hrtimer_expires)) {
MEMBER_OFFSET_INIT(timerqueue_head_next,
"timerqueue_head", "next");
MEMBER_OFFSET_INIT(timerqueue_node_expires,
"timerqueue_node", "expires");
MEMBER_OFFSET_INIT(timerqueue_node_node,
"timerqueue_node", "node");
if (INVALID_MEMBER(timerqueue_head_next)) {
MEMBER_OFFSET_INIT(timerqueue_head_rb_root,
"timerqueue_head", "rb_root");
MEMBER_OFFSET_INIT(rb_root_cached_rb_leftmost,
"rb_root_cached", "rb_leftmost");
}
}
MEMBER_OFFSET_INIT(hrtimer_softexpires, "hrtimer", "_softexpires");
MEMBER_OFFSET_INIT(hrtimer_function, "hrtimer", "function");
MEMBER_OFFSET_INIT(ktime_t_tv64, "ktime", "tv64");
if (INVALID_MEMBER(ktime_t_tv64))
MEMBER_OFFSET_INIT(ktime_t_tv64, "ktime_t", "tv64");
MEMBER_OFFSET_INIT(ktime_t_sec, "ktime", "sec");
if (INVALID_MEMBER(ktime_t_sec))
MEMBER_OFFSET_INIT(ktime_t_sec, "ktime_t", "sec");
MEMBER_OFFSET_INIT(ktime_t_nsec, "ktime", "nsec");
if (INVALID_MEMBER(ktime_t_nsec))
MEMBER_OFFSET_INIT(ktime_t_nsec, "ktime_t", "nsec");
if (kt->source_tree)
source_tree_init();
kt->flags &= ~PRE_KERNEL_INIT;
}
/*
* Get cpu map address. Types are: possible, online, present and active.
* They exist as either:
*
* (1) cpu_<type>_map symbols, or
* (2) what is pointed to by cpu_<type>_mask
*/
ulong
cpu_map_addr(const char *type)
{
char map_symbol[32];
ulong addr;
sprintf(map_symbol, "cpu_%s_map", type);
if (kernel_symbol_exists(map_symbol))
return symbol_value(map_symbol);
sprintf(map_symbol, "cpu_%s_mask", type);
if (kernel_symbol_exists(map_symbol)) {
get_symbol_data(map_symbol, sizeof(ulong), &addr);
return addr;
}
sprintf(map_symbol, "__cpu_%s_mask", type);
if (kernel_symbol_exists(map_symbol))
return symbol_value(map_symbol);
return 0;
}
static char *
cpu_map_type(char *name)
{
char map_symbol[32];
sprintf(map_symbol, "cpu_%s_map", name);
if (kernel_symbol_exists(map_symbol))
return "map";
sprintf(map_symbol, "cpu_%s_mask", name);
if (kernel_symbol_exists(map_symbol))
return "mask";
sprintf(map_symbol, "__cpu_%s_map", name);
if (kernel_symbol_exists(map_symbol))
return "map";
sprintf(map_symbol, "__cpu_%s_mask", name);
if (kernel_symbol_exists(map_symbol))
return "mask";
return NULL;
}
/*
* Get cpu map (possible, online, etc.) size
*/
static int
cpu_map_size(const char *type)
{
int len;
char map_symbol[32];
struct gnu_request req;
if (LKCD_KERNTYPES()) {
if (INVALID_SIZE(cpumask_t))
error(FATAL, "cannot determine type cpumask_t\n");
return SIZE(cpumask_t);
}
sprintf(map_symbol, "cpu_%s_map", type);
if (kernel_symbol_exists(map_symbol)) {
len = get_symbol_type(map_symbol, NULL, &req) ==
TYPE_CODE_UNDEF ? sizeof(ulong) : req.length;
return len;
}
if (INVALID_SIZE(cpumask_t))
return sizeof(ulong);
return SIZE(cpumask_t);
}
/*
* If the cpu_present_map, cpu_online_map and cpu_possible_maps exist,
* set up the kt->cpu_flags[NR_CPUS] with their settings.
*/
static void
cpu_maps_init(void)
{
int i, c, m, cpu, len;
char *buf;
ulong *maskptr, addr, error_handle;
struct mapinfo {
ulong cpu_flag;
char *name;
} mapinfo[] = {
{ POSSIBLE_MAP, "possible" },
{ PRESENT_MAP, "present" },
{ ONLINE_MAP, "online" },
{ ACTIVE_MAP, "active" },
};
if (INVALID_SIZE(cpumask_t))
len = sizeof(ulong);
else
len = SIZE(cpumask_t);
buf = GETBUF(len);
for (m = 0; m < sizeof(mapinfo)/sizeof(struct mapinfo); m++) {
if (!(addr = cpu_map_addr(mapinfo[m].name)))
continue;
error_handle = pc->flags & DEVMEM ? RETURN_ON_ERROR|QUIET : RETURN_ON_ERROR;
if (!readmem(addr, KVADDR, buf, len,
mapinfo[m].name, error_handle)) {
error(WARNING, "cannot read cpu_%s_map\n",
mapinfo[m].name);
continue;
}
maskptr = (ulong *)buf;
for (i = 0; i < (len/sizeof(ulong)); i++, maskptr++) {
if (*maskptr == 0)
continue;
for (c = 0; c < BITS_PER_LONG; c++)
if (*maskptr & (0x1UL << c)) {
cpu = (i * BITS_PER_LONG) + c;
if (cpu >= NR_CPUS) {
error(WARNING,
"cpu_%s_%s indicates more than"
" %d (NR_CPUS) cpus\n",
mapinfo[m].name,
cpu_map_type(mapinfo[m].name),
NR_CPUS);
break;
}
kt->cpu_flags[cpu] |= mapinfo[m].cpu_flag;
}
}
if (CRASHDEBUG(1)) {
fprintf(fp, "%scpu_%s_%s: cpus: ",
space(strlen("possible")-strlen(mapinfo[m].name)),
mapinfo[m].name, cpu_map_type(mapinfo[m].name));
for (i = c = 0; i < NR_CPUS; i++) {
if (kt->cpu_flags[i] & mapinfo[m].cpu_flag) {
fprintf(fp, "%d ", i);