-
Notifications
You must be signed in to change notification settings - Fork 0
/
makedumpfile.h
1481 lines (1299 loc) · 38.8 KB
/
makedumpfile.h
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
/*
* makedumpfile.h
*
* Copyright (C) 2006, 2007, 2008, 2009, 2011 NEC Corporation
*
* 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.
*/
#ifndef _MAKEDUMPFILE_H
#define _MAKEDUMPFILE_H
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <gelf.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <zlib.h>
#include <libelf.h>
#include <byteswap.h>
#include <getopt.h>
#ifdef USELZO
#include <lzo/lzo1x.h>
#endif
#include "common.h"
#include "dwarf_info.h"
#include "diskdump_mod.h"
#include "sadump_mod.h"
/*
* Result of command
*/
#define COMPLETED (0)
#define FAILED (1)
#define WRONG_RELEASE (2) /* utsname.release does not match. */
#define ANALYSIS_FAILED (3) /* detected illegal page descriptor. */
#define OUTPUT_FAILED (4) /* detected an output error. */
/*
* Type of memory management
*/
enum {
NOT_FOUND_MEMTYPE,
SPARSEMEM,
SPARSEMEM_EX,
DISCONTIGMEM,
FLATMEM
};
int get_mem_type(void);
/*
* Page flags
*
* The flag values of page.flags have been defined by enum since linux-2.6.26.
* The following values are for linux-2.6.25 or former.
*/
#define PG_lru_ORIGINAL (5)
#define PG_private_ORIGINAL (11) /* Has something at ->private */
#define PG_swapcache_ORIGINAL (15) /* Swap page: swp_entry_t in private */
#define PAGE_MAPPING_ANON (1)
#define LSEEKED_BITMAP (1)
#define LSEEKED_PDESC (2)
#define LSEEKED_PDATA (3)
/*
* Memory flags
*/
#define MEMORY_PAGETABLE_4L (1 << 0)
#define MEMORY_PAGETABLE_3L (1 << 1)
#define MEMORY_X86_PAE (1 << 2)
/*
* Type of address
*/
enum {
VADDR,
PADDR,
VADDR_XEN,
MADDR_XEN
};
static inline int
test_bit(int nr, unsigned long addr)
{
int mask;
mask = 1 << (nr & 0x1f);
return ((mask & addr) != 0);
}
#define isLRU(flags) test_bit(NUMBER(PG_lru), flags)
#define isPrivate(flags) test_bit(NUMBER(PG_private), flags)
#define isSwapCache(flags) test_bit(NUMBER(PG_swapcache), flags)
static inline int
isAnon(unsigned long mapping)
{
return ((unsigned long)mapping & PAGE_MAPPING_ANON) != 0;
}
#define PAGESIZE() (info->page_size)
#define PAGESHIFT() (info->page_shift)
#define PAGEOFFSET(X) (((unsigned long)(X)) & (PAGESIZE() - 1))
#define PAGEBASE(X) (((unsigned long)(X)) & ~(PAGESIZE() - 1))
#define _2MB_PAGE_MASK (~((2*1048576)-1))
/*
* for SPARSEMEM
*/
#define SECTION_SIZE_BITS() (info->section_size_bits)
#define MAX_PHYSMEM_BITS() (info->max_physmem_bits)
#define PFN_SECTION_SHIFT() (SECTION_SIZE_BITS() - PAGESHIFT())
#define PAGES_PER_SECTION() (1UL << PFN_SECTION_SHIFT())
#define _SECTIONS_PER_ROOT() (1)
#define _SECTIONS_PER_ROOT_EXTREME() (info->page_size / SIZE(mem_section))
#define SECTIONS_PER_ROOT() (info->sections_per_root)
#define SECTION_ROOT_MASK() (SECTIONS_PER_ROOT() - 1)
#define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT())
#define SECTION_MAP_LAST_BIT (1UL<<2)
#define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1))
#define NR_SECTION_ROOTS() divideup(num_section, SECTIONS_PER_ROOT())
#define SECTION_NR_TO_PFN(sec) ((sec) << PFN_SECTION_SHIFT())
#define SECTIONS_SHIFT() (MAX_PHYSMEM_BITS() - SECTION_SIZE_BITS())
#define NR_MEM_SECTIONS() (1UL << SECTIONS_SHIFT())
/*
* Dump Level
*/
#define MIN_DUMP_LEVEL (0)
#define MAX_DUMP_LEVEL (31)
#define NUM_ARRAY_DUMP_LEVEL (MAX_DUMP_LEVEL + 1) /* enough to allocate
all the dump_level */
#define DL_EXCLUDE_ZERO (0x001) /* Exclude Pages filled with Zeros */
#define DL_EXCLUDE_CACHE (0x002) /* Exclude Cache Pages
without Private Pages */
#define DL_EXCLUDE_CACHE_PRI (0x004) /* Exclude Cache Pages
with Private Pages */
#define DL_EXCLUDE_USER_DATA (0x008) /* Exclude UserProcessData Pages */
#define DL_EXCLUDE_FREE (0x010) /* Exclude Free Pages */
/*
* For parse_line()
*/
#define NULLCHAR ('\0')
#define MAXARGS (100) /* max number of arguments to one function */
#define LASTCHAR(s) (s[strlen(s)-1])
#define BITPERBYTE (8)
#define PGMM_CACHED (512)
#define PFN_EXCLUDED (256)
#define BUFSIZE (1024)
#define BUFSIZE_FGETS (1500)
#define BUFSIZE_BITMAP (4096)
#define PFN_BUFBITMAP (BITPERBYTE*BUFSIZE_BITMAP)
#define FILENAME_BITMAP "kdump_bitmapXXXXXX"
#define FILENAME_STDOUT "STDOUT"
/*
* Minimam vmcore has 2 ProgramHeaderTables(PT_NOTE and PT_LOAD).
*/
#define MIN_ELF32_HEADER_SIZE \
sizeof(Elf32_Ehdr)+sizeof(Elf32_Phdr)+sizeof(Elf32_Phdr)
#define MIN_ELF64_HEADER_SIZE \
sizeof(Elf64_Ehdr)+sizeof(Elf64_Phdr)+sizeof(Elf64_Phdr)
#define MIN_ELF_HEADER_SIZE \
MAX(MIN_ELF32_HEADER_SIZE, MIN_ELF64_HEADER_SIZE)
#define STRNEQ(A, B) (A && B && \
(strncmp((char *)(A), (char *)(B), strlen((char *)(B))) == 0))
#define USHORT(ADDR) *((unsigned short *)(ADDR))
#define UINT(ADDR) *((unsigned int *)(ADDR))
#define ULONG(ADDR) *((unsigned long *)(ADDR))
/*
* for symbol
*/
#define INVALID_SYMBOL_DATA (ULONG_MAX)
#define SYMBOL(X) (symbol_table.X)
#define SYMBOL_INIT(symbol, str_symbol) \
do { \
SYMBOL(symbol) = get_symbol_addr(str_symbol); \
} while (0)
#define SYMBOL_INIT_NEXT(symbol, str_symbol) \
do { \
SYMBOL(symbol) = get_next_symbol_addr(str_symbol); \
} while (0)
#define WRITE_SYMBOL(str_symbol, symbol) \
do { \
if (SYMBOL(symbol) != NOT_FOUND_SYMBOL) { \
fprintf(info->file_vmcoreinfo, "%s%llx\n", \
STR_SYMBOL(str_symbol), SYMBOL(symbol)); \
} \
} while (0)
#define READ_SYMBOL(str_symbol, symbol) \
do { \
if (SYMBOL(symbol) == NOT_FOUND_SYMBOL) { \
SYMBOL(symbol) = read_vmcoreinfo_symbol(STR_SYMBOL(str_symbol)); \
if (SYMBOL(symbol) == INVALID_SYMBOL_DATA) \
return FALSE; \
} \
} while (0)
/*
* for structure
*/
#define SIZE(X) (size_table.X)
#define OFFSET(X) (offset_table.X)
#define ARRAY_LENGTH(X) (array_table.X)
#define SIZE_INIT(X, Y) \
do { \
if ((SIZE(X) = get_structure_size(Y, 0)) == FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define TYPEDEF_SIZE_INIT(X, Y) \
do { \
if ((SIZE(X) = get_structure_size(Y, 1)) == FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define OFFSET_INIT(X, Y, Z) \
do { \
if ((OFFSET(X) = get_member_offset(Y, Z, DWARF_INFO_GET_MEMBER_OFFSET)) \
== FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define OFFSET_IN_UNION_INIT(X, Y, Z) \
do { \
if ((OFFSET(X) = get_member_offset(Y, Z, DWARF_INFO_GET_MEMBER_OFFSET_IN_UNION)) \
== FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define SYMBOL_ARRAY_LENGTH_INIT(X, Y) \
do { \
if ((ARRAY_LENGTH(X) = get_array_length(Y, NULL, DWARF_INFO_GET_SYMBOL_ARRAY_LENGTH)) == FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define SYMBOL_ARRAY_TYPE_INIT(X, Y) \
do { \
if ((ARRAY_LENGTH(X) = get_array_length(Y, NULL, DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE)) == FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define MEMBER_ARRAY_LENGTH_INIT(X, Y, Z) \
do { \
if ((ARRAY_LENGTH(X) = get_array_length(Y, Z, DWARF_INFO_GET_MEMBER_ARRAY_LENGTH)) == FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define WRITE_STRUCTURE_SIZE(str_structure, structure) \
do { \
if (SIZE(structure) != NOT_FOUND_STRUCTURE) { \
fprintf(info->file_vmcoreinfo, "%s%ld\n", \
STR_SIZE(str_structure), SIZE(structure)); \
} \
} while (0)
#define WRITE_MEMBER_OFFSET(str_member, member) \
do { \
if (OFFSET(member) != NOT_FOUND_STRUCTURE) { \
fprintf(info->file_vmcoreinfo, "%s%ld\n", \
STR_OFFSET(str_member), OFFSET(member)); \
} \
} while (0)
#define WRITE_ARRAY_LENGTH(str_array, array) \
do { \
if (ARRAY_LENGTH(array) != NOT_FOUND_STRUCTURE) { \
fprintf(info->file_vmcoreinfo, "%s%ld\n", \
STR_LENGTH(str_array), ARRAY_LENGTH(array)); \
} \
} while (0)
#define READ_STRUCTURE_SIZE(str_structure, structure) \
do { \
if (SIZE(structure) == NOT_FOUND_STRUCTURE) { \
SIZE(structure) = read_vmcoreinfo_long(STR_SIZE(str_structure)); \
if (SIZE(structure) == INVALID_STRUCTURE_DATA) \
return FALSE; \
} \
} while (0)
#define READ_MEMBER_OFFSET(str_member, member) \
do { \
if (OFFSET(member) == NOT_FOUND_STRUCTURE) { \
OFFSET(member) = read_vmcoreinfo_long(STR_OFFSET(str_member)); \
if (OFFSET(member) == INVALID_STRUCTURE_DATA) \
return FALSE; \
} \
} while (0)
#define READ_ARRAY_LENGTH(str_array, array) \
do { \
if (ARRAY_LENGTH(array) == NOT_FOUND_STRUCTURE) { \
ARRAY_LENGTH(array) = read_vmcoreinfo_long(STR_LENGTH(str_array)); \
if (ARRAY_LENGTH(array) == INVALID_STRUCTURE_DATA) \
return FALSE; \
} \
} while (0)
/*
* for number
*/
#define NUMBER(X) (number_table.X)
#define ENUM_NUMBER_INIT(number, str_number) \
do {\
NUMBER(number) = get_enum_number(str_number); \
if (NUMBER(number) == FAILED_DWARFINFO) \
return FALSE; \
} while (0)
#define WRITE_NUMBER(str_number, number) \
do { \
if (NUMBER(number) != NOT_FOUND_NUMBER) { \
fprintf(info->file_vmcoreinfo, "%s%ld\n", \
STR_NUMBER(str_number), NUMBER(number)); \
} \
} while (0)
#define READ_NUMBER(str_number, number) \
do { \
if (NUMBER(number) == NOT_FOUND_NUMBER) { \
NUMBER(number) = read_vmcoreinfo_long(STR_NUMBER(str_number)); \
if (NUMBER(number) == INVALID_STRUCTURE_DATA) \
return FALSE; \
} \
} while (0)
/*
* for source file name
*/
#define SRCFILE(X) (srcfile_table.X)
#define TYPEDEF_SRCFILE_INIT(decl_name, str_decl_name) \
do { \
get_source_filename(str_decl_name, SRCFILE(decl_name), DWARF_INFO_GET_TYPEDEF_SRCNAME); \
} while (0)
#define WRITE_SRCFILE(str_decl_name, decl_name) \
do { \
if (strlen(SRCFILE(decl_name))) { \
fprintf(info->file_vmcoreinfo, "%s%s\n", \
STR_SRCFILE(str_decl_name), SRCFILE(decl_name)); \
} \
} while (0)
#define READ_SRCFILE(str_decl_name, decl_name) \
do { \
if (strlen(SRCFILE(decl_name)) == 0) { \
if (!read_vmcoreinfo_string(STR_SRCFILE(str_decl_name), SRCFILE(decl_name))) \
return FALSE; \
} \
} while (0)
/*
* Macro for getting splitting info.
*/
#define SPLITTING_DUMPFILE(i) info->splitting_info[i].name_dumpfile
#define SPLITTING_FD_BITMAP(i) info->splitting_info[i].fd_bitmap
#define SPLITTING_START_PFN(i) info->splitting_info[i].start_pfn
#define SPLITTING_END_PFN(i) info->splitting_info[i].end_pfn
#define SPLITTING_OFFSET_EI(i) info->splitting_info[i].offset_eraseinfo
#define SPLITTING_SIZE_EI(i) info->splitting_info[i].size_eraseinfo
/*
* kernel version
*
* NOTE: the format of kernel_version is as follows
* 8 bits major version
* 8 bits minor version
* 16 bits release
* so version 2.6.18 would be encoded as 0x02060012
* These macros will let us decode that easier
*/
#define KVER_MAJ_SHIFT 24
#define KVER_MIN_SHIFT 16
#define KERNEL_VERSION(x,y,z) (((x) << KVER_MAJ_SHIFT) | ((y) << KVER_MIN_SHIFT) | (z))
#define OLDEST_VERSION KERNEL_VERSION(2, 6, 15)/* linux-2.6.15 */
#define LATEST_VERSION KERNEL_VERSION(3, 2, 16)/* linux-3.2.16 */
/*
* vmcoreinfo in /proc/vmcore
*/
#define VMCOREINFO_BYTES (4096)
#define FILENAME_VMCOREINFO "/tmp/vmcoreinfoXXXXXX"
/*
* field name of vmcoreinfo file
*/
#define STR_OSRELEASE "OSRELEASE="
#define STR_PAGESIZE "PAGESIZE="
#define STR_CRASHTIME "CRASHTIME="
#define STR_SYMBOL(X) "SYMBOL("X")="
#define STR_SIZE(X) "SIZE("X")="
#define STR_OFFSET(X) "OFFSET("X")="
#define STR_LENGTH(X) "LENGTH("X")="
#define STR_NUMBER(X) "NUMBER("X")="
#define STR_SRCFILE(X) "SRCFILE("X")="
#define STR_CONFIG_X86_PAE "CONFIG_X86_PAE=y"
#define STR_CONFIG_PGTABLE_4 "CONFIG_PGTABLE_4=y"
#define STR_CONFIG_PGTABLE_3 "CONFIG_PGTABLE_3=y"
/*
* common value
*/
#define NOSPACE (-1) /* code of write-error due to nospace */
#define DEFAULT_ORDER (4)
#define TIMEOUT_STDIN (600)
#define SIZE_BUF_STDIN (4096)
#define STRLEN_OSRELEASE (65) /* same length as diskdump.h */
#define SIZE_XEN_CRASH_INFO_V2 (sizeof(unsigned long) * 10)
/*
* The value of dependence on machine
*/
#define PAGE_OFFSET (info->page_offset)
#define VMALLOC_START (info->vmalloc_start)
#define VMALLOC_END (info->vmalloc_end)
#define VMEMMAP_START (info->vmemmap_start)
#define VMEMMAP_END (info->vmemmap_end)
#ifdef __arm__
#define KVBASE_MASK (0xffff)
#define KVBASE (SYMBOL(_stext) & ~KVBASE_MASK)
#define _SECTION_SIZE_BITS (28)
#define _MAX_PHYSMEM_BITS (32)
#define ARCH_PFN_OFFSET (info->phys_base >> PAGESHIFT())
#define PTRS_PER_PTE (512)
#define PGDIR_SHIFT (21)
#define PMD_SHIFT (21)
#define PMD_SIZE (1UL << PMD_SHIFT)
#define PMD_MASK (~(PMD_SIZE - 1))
#define _PAGE_PRESENT (1 << 0)
#endif /* arm */
#ifdef __x86__
#define __PAGE_OFFSET (0xc0000000)
#define __VMALLOC_RESERVE (128 << 20)
#define MAXMEM (-PAGE_OFFSET-__VMALLOC_RESERVE)
#define KVBASE_MASK (0x7fffff)
#define KVBASE (SYMBOL(_stext) & ~KVBASE_MASK)
#define _SECTION_SIZE_BITS (26)
#define _SECTION_SIZE_BITS_PAE_ORIG (30)
#define _SECTION_SIZE_BITS_PAE_2_6_26 (29)
#define _MAX_PHYSMEM_BITS (32)
#define _MAX_PHYSMEM_BITS_PAE (36)
#define PGDIR_SHIFT_3LEVEL (30)
#define PTRS_PER_PTE_3LEVEL (512)
#define PTRS_PER_PGD_3LEVEL (4)
#define PMD_SHIFT (21) /* only used by PAE translators */
#define PTRS_PER_PMD (512) /* only used by PAE translators */
#define PTE_SHIFT (12) /* only used by PAE translators */
#define PTRS_PER_PTE (512) /* only used by PAE translators */
#define pgd_index_PAE(address) (((address) >> PGDIR_SHIFT_3LEVEL) & (PTRS_PER_PGD_3LEVEL - 1))
#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
#define pte_index(address) (((address) >> PTE_SHIFT) & (PTRS_PER_PTE - 1))
#define _PAGE_PRESENT (0x001)
#define _PAGE_PSE (0x080)
#define ENTRY_MASK (~0x8000000000000fffULL)
#endif /* x86 */
#ifdef __x86_64__
#define __PAGE_OFFSET_ORIG (0xffff810000000000) /* 2.6.26, or former */
#define __PAGE_OFFSET_2_6_27 (0xffff880000000000) /* 2.6.27, or later */
#define VMALLOC_START_ORIG (0xffffc20000000000) /* 2.6.30, or former */
#define VMALLOC_START_2_6_31 (0xffffc90000000000) /* 2.6.31, or later */
#define VMALLOC_END_ORIG (0xffffe1ffffffffff) /* 2.6.30, or former */
#define VMALLOC_END_2_6_31 (0xffffe8ffffffffff) /* 2.6.31, or later */
#define VMEMMAP_START_ORIG (0xffffe20000000000) /* 2.6.30, or former */
#define VMEMMAP_START_2_6_31 (0xffffea0000000000) /* 2.6.31, or later */
#define VMEMMAP_END_ORIG (0xffffe2ffffffffff) /* 2.6.30, or former */
#define VMEMMAP_END_2_6_31 (0xffffeaffffffffff) /* 2.6.31, or later */
#define __START_KERNEL_map (0xffffffff80000000)
#define MODULES_VADDR (0xffffffff88000000)
#define MODULES_END (0xfffffffffff00000)
#define KVBASE PAGE_OFFSET
#define _SECTION_SIZE_BITS (27)
#define _MAX_PHYSMEM_BITS_ORIG (40)
#define _MAX_PHYSMEM_BITS_2_6_26 (44)
#define _MAX_PHYSMEM_BITS_2_6_31 (46)
/*
* 4 Levels paging
*/
#define PML4_SHIFT (39)
#define PTRS_PER_PML4 (512)
#define PGDIR_SHIFT (30)
#define PTRS_PER_PGD (512)
#define PMD_SHIFT (21)
#define PTRS_PER_PMD (512)
#define PTRS_PER_PTE (512)
#define PTE_SHIFT (12)
#define pml4_index(address) (((address) >> PML4_SHIFT) & (PTRS_PER_PML4 - 1))
#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
#define pte_index(address) (((address) >> PTE_SHIFT) & (PTRS_PER_PTE - 1))
#define _PAGE_PRESENT (0x001)
#define _PAGE_PSE (0x080) /* 2MB page */
#define __PHYSICAL_MASK_SHIFT (40)
#define __PHYSICAL_MASK ((1UL << __PHYSICAL_MASK_SHIFT) - 1)
#define PHYSICAL_PAGE_MASK (~(PAGESIZE()-1) & (__PHYSICAL_MASK << PAGESHIFT()))
#endif /* x86_64 */
#ifdef __powerpc64__
#define __PAGE_OFFSET (0xc000000000000000)
#define KERNELBASE PAGE_OFFSET
#define VMALLOCBASE (0xD000000000000000)
#define KVBASE (SYMBOL(_stext))
#define _SECTION_SIZE_BITS (24)
#define _MAX_PHYSMEM_BITS (44)
#endif
#ifdef __powerpc32__
#define __PAGE_OFFSET (0xc0000000)
#define KERNELBASE PAGE_OFFSET
#define VMALL_START (info->vmalloc_start)
#define KVBASE (SYMBOL(_stext))
#define _SECTION_SIZE_BITS (24)
#define _MAX_PHYSMEM_BITS (44)
#endif
#ifdef __s390x__
#define __PAGE_OFFSET (info->page_size - 1)
#define KERNELBASE (0)
#define KVBASE KERNELBASE
#define _SECTION_SIZE_BITS (28)
#define _MAX_PHYSMEM_BITS_ORIG (42)
#define _MAX_PHYSMEM_BITS_3_3 (46)
/* Bits in the segment/region table address-space-control-element */
#define _ASCE_TYPE_MASK 0x0c
#define _ASCE_TABLE_LENGTH 0x03 /* region table length */
#define TABLE_LEVEL(x) (((x) & _ASCE_TYPE_MASK) >> 2)
#define TABLE_LENGTH(x) ((x) & _ASCE_TABLE_LENGTH)
/* Bits in the region table entry */
#define _REGION_ENTRY_ORIGIN ~0xfffUL /* region table origin*/
#define _REGION_ENTRY_TYPE_MASK 0x0c /* region table type mask */
#define _REGION_ENTRY_INVALID 0x20 /* invalid region table entry */
#define _REGION_ENTRY_LENGTH 0x03 /* region table length */
#define _REGION_OFFSET_MASK 0x7ffUL /* region/segment table offset mask */
#define RSG_TABLE_LEVEL(x) (((x) & _REGION_ENTRY_TYPE_MASK) >> 2)
#define RSG_TABLE_LENGTH(x) ((x) & _REGION_ENTRY_LENGTH)
/* Bits in the segment table entry */
#define _SEGMENT_ENTRY_ORIGIN ~0x7ffUL
#define _SEGMENT_ENTRY_LARGE 0x400
#define _SEGMENT_PAGE_SHIFT 31
#define _SEGMENT_INDEX_SHIFT 20
/* Hardware bits in the page table entry */
#define _PAGE_CO 0x100 /* HW Change-bit override */
#define _PAGE_ZERO 0x800 /* Bit pos 52 must conatin zero */
#define _PAGE_INVALID 0x400 /* HW invalid bit */
#define _PAGE_INDEX_SHIFT 12
#define _PAGE_OFFSET_MASK 0xffUL /* page table offset mask */
#endif /* __s390x__ */
#ifdef __ia64__ /* ia64 */
#define REGION_SHIFT (61)
#define KERNEL_CACHED_REGION (7)
#define KERNEL_UNCACHED_REGION (6)
#define KERNEL_VMALLOC_REGION (5)
#define USER_STACK_REGION (4)
#define USER_DATA_REGION (3)
#define USER_TEXT_REGION (2)
#define USER_SHMEM_REGION (1)
#define USER_IA32_EMUL_REGION (0)
#define KERNEL_CACHED_BASE ((unsigned long)KERNEL_CACHED_REGION << REGION_SHIFT)
#define KERNEL_UNCACHED_BASE ((unsigned long)KERNEL_UNCACHED_REGION << REGION_SHIFT)
#define KERNEL_VMALLOC_BASE ((unsigned long)KERNEL_VMALLOC_REGION << REGION_SHIFT)
#define KVBASE KERNEL_VMALLOC_BASE
#define _PAGE_SIZE_64M (26)
#define KERNEL_TR_PAGE_SIZE (1 << _PAGE_SIZE_64M)
#define KERNEL_TR_PAGE_MASK (~(KERNEL_TR_PAGE_SIZE - 1))
#define DEFAULT_PHYS_START (KERNEL_TR_PAGE_SIZE * 1)
#define _SECTION_SIZE_BITS (30)
#define _MAX_PHYSMEM_BITS (50)
/*
* 3 Levels paging
*/
#define _PAGE_PPN_MASK (((1UL << _MAX_PHYSMEM_BITS) - 1) & ~0xfffUL)
#define PTRS_PER_PTD_SHIFT (PAGESHIFT() - 3)
#define PMD_SHIFT (PAGESHIFT() + PTRS_PER_PTD_SHIFT)
#define PGDIR_SHIFT_3L (PMD_SHIFT + PTRS_PER_PTD_SHIFT)
#define MASK_POFFSET ((1UL << PAGESHIFT()) - 1)
#define MASK_PTE ((1UL << PMD_SHIFT) - 1) &~((1UL << PAGESHIFT()) - 1)
#define MASK_PMD ((1UL << PGDIR_SHIFT_3L) - 1) &~((1UL << PMD_SHIFT) - 1)
#define MASK_PGD_3L ((1UL << REGION_SHIFT) - 1) & (~((1UL << PGDIR_SHIFT_3L) - 1))
/*
* 4 Levels paging
*/
#define PUD_SHIFT (PMD_SHIFT + PTRS_PER_PTD_SHIFT)
#define PGDIR_SHIFT_4L (PUD_SHIFT + PTRS_PER_PTD_SHIFT)
#define MASK_PUD ((1UL << REGION_SHIFT) - 1) & (~((1UL << PUD_SHIFT) - 1))
#define MASK_PGD_4L ((1UL << REGION_SHIFT) - 1) & (~((1UL << PGDIR_SHIFT_4L) - 1))
/*
* Key for distinguishing PGTABLE_3L or PGTABLE_4L.
*/
#define STR_PUD_T_3L "include/asm-generic/pgtable-nopud.h"
#define STR_PUD_T_4L "include/asm/page.h"
#endif /* ia64 */
/*
* The function of dependence on machine
*/
#ifdef __arm__
int get_phys_base_arm(void);
int get_machdep_info_arm(void);
unsigned long long vaddr_to_paddr_arm(unsigned long vaddr);
#define get_phys_base() get_phys_base_arm()
#define get_machdep_info() get_machdep_info_arm()
#define get_versiondep_info() TRUE
#define vaddr_to_paddr(X) vaddr_to_paddr_arm(X)
#endif /* arm */
#ifdef __x86__
int get_machdep_info_x86(void);
int get_versiondep_info_x86(void);
unsigned long long vaddr_to_paddr_x86(unsigned long vaddr);
#define get_phys_base() TRUE
#define get_machdep_info() get_machdep_info_x86()
#define get_versiondep_info() get_versiondep_info_x86()
#define vaddr_to_paddr(X) vaddr_to_paddr_x86(X)
#endif /* x86 */
#ifdef __x86_64__
int get_phys_base_x86_64(void);
int get_machdep_info_x86_64(void);
int get_versiondep_info_x86_64(void);
unsigned long long vaddr_to_paddr_x86_64(unsigned long vaddr);
#define get_phys_base() get_phys_base_x86_64()
#define get_machdep_info() get_machdep_info_x86_64()
#define get_versiondep_info() get_versiondep_info_x86_64()
#define vaddr_to_paddr(X) vaddr_to_paddr_x86_64(X)
#endif /* x86_64 */
#ifdef __powerpc64__ /* powerpc64 */
int get_machdep_info_ppc64(void);
unsigned long long vaddr_to_paddr_ppc64(unsigned long vaddr);
#define get_phys_base() TRUE
#define get_machdep_info() get_machdep_info_ppc64()
#define get_versiondep_info() TRUE
#define vaddr_to_paddr(X) vaddr_to_paddr_ppc64(X)
#endif /* powerpc64 */
#ifdef __powerpc32__ /* powerpc32 */
int get_machdep_info_ppc(void);
unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
#define get_phys_base() TRUE
#define get_machdep_info() get_machdep_info_ppc()
#define get_versiondep_info() TRUE
#define vaddr_to_paddr(X) vaddr_to_paddr_ppc(X)
#endif /* powerpc32 */
#ifdef __s390x__ /* s390x */
int get_machdep_info_s390x(void);
unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
#define get_phys_base() TRUE
#define get_machdep_info() get_machdep_info_s390x()
#define get_versiondep_info() TRUE
#define vaddr_to_paddr(X) vaddr_to_paddr_s390x(X)
#endif /* s390x */
#ifdef __ia64__ /* ia64 */
int get_phys_base_ia64(void);
int get_machdep_info_ia64(void);
unsigned long long vaddr_to_paddr_ia64(unsigned long vaddr);
#define get_machdep_info() get_machdep_info_ia64()
#define get_phys_base() get_phys_base_ia64()
#define get_versiondep_info() TRUE
#define vaddr_to_paddr(X) vaddr_to_paddr_ia64(X)
#define VADDR_REGION(X) (((unsigned long)(X)) >> REGION_SHIFT)
#endif /* ia64 */
#ifndef ARCH_PFN_OFFSET
#define ARCH_PFN_OFFSET 0
#endif
#define paddr_to_pfn(X) \
(((unsigned long long)(X) >> PAGESHIFT()) - ARCH_PFN_OFFSET)
#define pfn_to_paddr(X) \
(((unsigned long long)(X) + ARCH_PFN_OFFSET) << PAGESHIFT())
struct mem_map_data {
unsigned long long pfn_start;
unsigned long long pfn_end;
unsigned long mem_map;
};
struct dump_bitmap {
int fd;
int no_block;
char *file_name;
char buf[BUFSIZE_BITMAP];
off_t offset;
};
struct cache_data {
int fd;
char *file_name;
char *buf;
size_t buf_size;
size_t cache_size;
off_t offset;
};
/*
* makedumpfile header
* For re-arranging the dump data on different architecture, all the
* variables are defined by 64bits. The size of signature is aligned
* to 64bits, and change the values to big endian.
*/
#define MAKEDUMPFILE_SIGNATURE "makedumpfile"
#define NUM_SIG_MDF (sizeof(MAKEDUMPFILE_SIGNATURE) - 1)
#define SIZE_SIG_MDF roundup(sizeof(char) * NUM_SIG_MDF, 8)
#define SIG_LEN_MDF (SIZE_SIG_MDF / sizeof(char))
#define MAX_SIZE_MDF_HEADER (4096) /* max size of makedumpfile_header */
#define TYPE_FLAT_HEADER (1) /* type of flattened format */
#define VERSION_FLAT_HEADER (1) /* current version of flattened format */
#define END_FLAG_FLAT_HEADER (-1)
struct makedumpfile_header {
char signature[SIG_LEN_MDF]; /* = "makedumpfile" */
int64_t type;
int64_t version;
};
struct makedumpfile_data_header {
int64_t offset;
int64_t buf_size;
};
struct splitting_info {
char *name_dumpfile;
int fd_bitmap;
unsigned long long start_pfn;
unsigned long long end_pfn;
off_t offset_eraseinfo;
unsigned long size_eraseinfo;
} splitting_info_t;
struct DumpInfo {
int32_t kernel_version; /* version of first kernel*/
struct timeval timestamp;
struct utsname system_utsname;
/*
* General info:
*/
int dump_level; /* current dump level */
int max_dump_level; /* maximum dump level */
int num_dump_level; /* number of dump level */
int array_dump_level[NUM_ARRAY_DUMP_LEVEL];
int flag_compress; /* flag of compression */
int flag_lzo_support; /* flag of LZO compression support */
int flag_elf_dumpfile; /* flag of creating ELF dumpfile */
int flag_generate_vmcoreinfo;/* flag of generating vmcoreinfo file */
int flag_read_vmcoreinfo; /* flag of reading vmcoreinfo file */
int flag_show_usage; /* flag of showing usage */
int flag_show_version; /* flag of showing version */
int flag_flatten; /* flag of outputting flattened
format to a standard out */
int flag_rearrange; /* flag of creating dumpfile from
flattened format */
int flag_split; /* splitting vmcore */
int flag_reassemble; /* reassemble multiple dumpfiles into one */
int flag_refiltering; /* refilter from kdump-compressed file */
int flag_force; /* overwrite existing stuff */
int flag_exclude_xen_dom;/* exclude Domain-U from xen-kdump */
int flag_dmesg; /* dump the dmesg log out of the vmcore file */
int flag_nospace; /* the flag of "No space on device" error */
unsigned long vaddr_for_vtop; /* virtual address for debugging */
long page_size; /* size of page */
long page_shift;
unsigned long long max_mapnr; /* number of page descriptor */
unsigned long page_offset;
unsigned long section_size_bits;
unsigned long max_physmem_bits;
unsigned long sections_per_root;
unsigned long phys_base;
unsigned long kernel_start;
unsigned long vmalloc_start;
unsigned long vmalloc_end;
unsigned long vmemmap_start;
unsigned long vmemmap_end;
/*
* Filter config file containing filter commands to filter out kernel
* data from vmcore.
*/
char *name_filterconfig;
FILE *file_filterconfig;
/*
* diskdimp info:
*/
int block_order;
off_t offset_bitmap1;
unsigned long len_bitmap; /* size of bitmap(1st and 2nd) */
struct dump_bitmap *bitmap1;
struct dump_bitmap *bitmap2;
struct disk_dump_header *dump_header;
struct kdump_sub_header sub_header;
/*
* ELF header info:
*/
unsigned int num_load_dumpfile;
size_t offset_load_dumpfile;
/*
* mem_map info:
*/
unsigned int num_mem_map;
struct mem_map_data *mem_map_data;
int fd_vmlinux;
char *name_vmlinux;
int fd_xen_syms;
char *name_xen_syms;
/*
* Dump memory image info:
*/
int fd_memory;
char *name_memory;
struct disk_dump_header *dh_memory;
struct kdump_sub_header *kh_memory;
struct dump_bitmap *bitmap_memory;
unsigned long *valid_pages;
/*
* Dump file info:
*/
int fd_dumpfile;
char *name_dumpfile;
int num_dumpfile;
struct splitting_info *splitting_info;
/*
* bitmap info:
*/
int fd_bitmap;
char *name_bitmap;
/*
* vmcoreinfo file info:
*/
FILE *file_vmcoreinfo;
char *name_vmcoreinfo; /* vmcoreinfo file */
char release[STRLEN_OSRELEASE];
/*
* ELF NOTE section in dump memory image info:
*/
off_t offset_note_dumpfile;
/*
* erased information in dump memory image info:
*/
unsigned long size_elf_eraseinfo;
/*
* for Xen extraction
*/
unsigned long long dom0_mapnr; /* The number of page in domain-0.
* Different from max_mapnr.
* max_mapnr is the number of page
* in system. */
unsigned long xen_phys_start;
unsigned long xen_heap_start; /* start mfn of xen heap area */
unsigned long xen_heap_end; /* end mfn(+1) of xen heap area */
unsigned long frame_table_vaddr;
unsigned long max_page;
unsigned long alloc_bitmap;
unsigned long dom0;
unsigned long p2m_frames;
unsigned long *p2m_mfn_frame_list;
int num_domain;
struct domain_list *domain_list;
/*
* for splitting
*/
unsigned long long split_start_pfn;
unsigned long long split_end_pfn;
/*
* sadump info:
*/
int flag_sadump_diskset;
enum sadump_format_type flag_sadump; /* sadump format type */
};
extern struct DumpInfo *info;
/*
* kernel VM-related data
*/
struct vm_table {
int numnodes;
unsigned long *node_online_map;
int node_online_map_len;
unsigned int mem_flags;
};
extern struct vm_table vt;
/*
* Loaded module symbols info.
*/
#define MOD_NAME_LEN 64
#define IN_RANGE(addr, mbase, sz) \
(((unsigned long)(addr) >= (unsigned long)mbase) \
&& ((unsigned long)addr < (unsigned long)(mbase + sz)))
struct symbol_info {
char *name;
unsigned long long value;
};
struct module_info {
char name[MOD_NAME_LEN];
unsigned int num_syms;
struct symbol_info *sym_info;
};
struct symbol_table {
unsigned long long mem_map;
unsigned long long vmem_map;
unsigned long long mem_section;
unsigned long long pkmap_count;
unsigned long long pkmap_count_next;
unsigned long long system_utsname;
unsigned long long init_uts_ns;
unsigned long long _stext;
unsigned long long swapper_pg_dir;
unsigned long long init_level4_pgt;
unsigned long long vmlist;
unsigned long long phys_base;
unsigned long long node_online_map;
unsigned long long node_states;
unsigned long long node_memblk;
unsigned long long node_data;
unsigned long long pgdat_list;
unsigned long long contig_page_data;
unsigned long long log_buf;
unsigned long long log_buf_len;
unsigned long long log_end;
unsigned long long max_pfn;
unsigned long long node_remap_start_vaddr;
unsigned long long node_remap_end_vaddr;
unsigned long long node_remap_start_pfn;
/*
* for Xen extraction
*/
unsigned long long dom_xen;
unsigned long long dom_io;
unsigned long long domain_list;
unsigned long long frame_table;
unsigned long long xen_heap_start;