-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakedumpfile.c
More file actions
7207 lines (6300 loc) · 179 KB
/
makedumpfile.c
File metadata and controls
7207 lines (6300 loc) · 179 KB
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.c
*
* 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.
*/
#include "makedumpfile.h"
#include "print_info.h"
#include "dwarf_info.h"
#include "elf_info.h"
#include "erase_info.h"
#include "sadump_info.h"
#include <stddef.h>
#include <sys/time.h>
struct symbol_table symbol_table;
struct size_table size_table;
struct offset_table offset_table;
struct array_table array_table;
struct number_table number_table;
struct srcfile_table srcfile_table;
struct vm_table vt = { 0 };
struct DumpInfo *info = NULL;
char filename_stdout[] = FILENAME_STDOUT;
/*
* The numbers of the excluded pages
*/
unsigned long long pfn_zero;
unsigned long long pfn_memhole;
unsigned long long pfn_cache;
unsigned long long pfn_cache_private;
unsigned long long pfn_user;
unsigned long long pfn_free;
int retcd = FAILED; /* return code */
#define INITIALIZE_LONG_TABLE(table, value) \
do { \
size_member = sizeof(long); \
num_member = sizeof(table) / size_member; \
ptr_long_table = (long *)&table; \
for (i = 0; i < num_member; i++, ptr_long_table++) \
*ptr_long_table = value; \
} while (0)
void
initialize_tables(void)
{
int i, size_member, num_member;
unsigned long long *ptr_symtable;
long *ptr_long_table;
/*
* Initialize the symbol table.
*/
size_member = sizeof(symbol_table.mem_map);
num_member = sizeof(symbol_table) / size_member;
ptr_symtable = (unsigned long long *)&symbol_table;
for (i = 0; i < num_member; i++, ptr_symtable++)
*ptr_symtable = NOT_FOUND_SYMBOL;
INITIALIZE_LONG_TABLE(size_table, NOT_FOUND_STRUCTURE);
INITIALIZE_LONG_TABLE(offset_table, NOT_FOUND_STRUCTURE);
INITIALIZE_LONG_TABLE(array_table, NOT_FOUND_STRUCTURE);
INITIALIZE_LONG_TABLE(number_table, NOT_FOUND_NUMBER);
}
/*
* Translate a domain-0's physical address to machine address.
*/
unsigned long long
ptom_xen(unsigned long long paddr)
{
unsigned long mfn;
unsigned long long maddr, pfn, mfn_idx, frame_idx;
pfn = paddr_to_pfn(paddr);
mfn_idx = pfn / MFNS_PER_FRAME;
frame_idx = pfn % MFNS_PER_FRAME;
if (mfn_idx >= info->p2m_frames) {
ERRMSG("Invalid mfn_idx(%llu).\n", mfn_idx);
return NOT_PADDR;
}
maddr = pfn_to_paddr(info->p2m_mfn_frame_list[mfn_idx])
+ sizeof(unsigned long) * frame_idx;
if (!readmem(MADDR_XEN, maddr, &mfn, sizeof(mfn))) {
ERRMSG("Can't get mfn.\n");
return NOT_PADDR;
}
maddr = pfn_to_paddr(mfn);
maddr |= PAGEOFFSET(paddr);
return maddr;
}
/*
* Get the number of the page descriptors from the ELF info.
*/
int
get_max_mapnr(void)
{
unsigned long long max_paddr;
if (info->flag_refiltering) {
info->max_mapnr = info->dh_memory->max_mapnr;
return TRUE;
}
if (info->flag_sadump) {
info->max_mapnr = sadump_get_max_mapnr();
return TRUE;
}
max_paddr = get_max_paddr();
info->max_mapnr = paddr_to_pfn(max_paddr);
DEBUG_MSG("\n");
DEBUG_MSG("max_mapnr : %llx\n", info->max_mapnr);
return TRUE;
}
/*
* Get the number of the page descriptors for Xen.
*/
int
get_dom0_mapnr()
{
unsigned long max_pfn;
if (SYMBOL(max_pfn) == NOT_FOUND_SYMBOL)
return FALSE;
if (!readmem(VADDR, SYMBOL(max_pfn), &max_pfn, sizeof max_pfn))
return FALSE;
info->dom0_mapnr = max_pfn;
return TRUE;
}
int
is_in_same_page(unsigned long vaddr1, unsigned long vaddr2)
{
if (round(vaddr1, info->page_size) == round(vaddr2, info->page_size))
return TRUE;
return FALSE;
}
#define BITMAP_SECT_LEN 4096
static inline int is_dumpable(struct dump_bitmap *, unsigned long long);
unsigned long
pfn_to_pos(unsigned long long pfn)
{
unsigned long desc_pos, i;
desc_pos = info->valid_pages[pfn / BITMAP_SECT_LEN];
for (i = round(pfn, BITMAP_SECT_LEN); i < pfn; i++)
if (is_dumpable(info->bitmap_memory, i))
desc_pos++;
return desc_pos;
}
int
read_page_desc(unsigned long long paddr, page_desc_t *pd)
{
struct disk_dump_header *dh;
unsigned long desc_pos;
unsigned long long pfn;
off_t offset;
/*
* Find page descriptor
*/
dh = info->dh_memory;
offset
= (DISKDUMP_HEADER_BLOCKS + dh->sub_hdr_size + dh->bitmap_blocks)
* dh->block_size;
pfn = paddr_to_pfn(paddr);
desc_pos = pfn_to_pos(pfn);
offset += (off_t)desc_pos * sizeof(page_desc_t);
if (lseek(info->fd_memory, offset, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n",
info->name_memory, strerror(errno));
return FALSE;
}
/*
* Read page descriptor
*/
if (read(info->fd_memory, pd, sizeof(*pd)) != sizeof(*pd)) {
ERRMSG("Can't read %s. %s\n",
info->name_memory, strerror(errno));
return FALSE;
}
/*
* Sanity check
*/
if (pd->size > dh->block_size)
return FALSE;
return TRUE;
}
int
readpmem_kdump_compressed(unsigned long long paddr, void *bufptr, size_t size)
{
page_desc_t pd;
char buf[info->page_size];
char buf2[info->page_size];
int ret;
unsigned long retlen, page_offset;
page_offset = paddr % info->page_size;
if (!is_dumpable(info->bitmap_memory, paddr_to_pfn(paddr))) {
ERRMSG("pfn(%llx) is excluded from %s.\n",
paddr_to_pfn(paddr), info->name_memory);
goto error;
}
if (!read_page_desc(paddr, &pd)) {
ERRMSG("Can't read page_desc: %llx\n", paddr);
goto error;
}
if (lseek(info->fd_memory, pd.offset, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n",
info->name_memory, strerror(errno));
goto error;
}
/*
* Read page data
*/
if (read(info->fd_memory, buf, pd.size) != pd.size) {
ERRMSG("Can't read %s. %s\n",
info->name_memory, strerror(errno));
goto error;
}
if (pd.flags & DUMP_DH_COMPRESSED_ZLIB) {
retlen = info->page_size;
ret = uncompress((unsigned char *)buf2, &retlen,
(unsigned char *)buf, pd.size);
if ((ret != Z_OK) || (retlen != info->page_size)) {
ERRMSG("Uncompress failed: %d\n", ret);
goto error;
}
memcpy(bufptr, buf2 + page_offset, size);
#ifdef USELZO
} else if (info->flag_lzo_support
&& (pd.flags & DUMP_DH_COMPRESSED_LZO)) {
retlen = info->page_size;
ret = lzo1x_decompress_safe((unsigned char *)buf, pd.size,
(unsigned char *)buf2, &retlen,
LZO1X_MEM_DECOMPRESS);
if ((ret != LZO_E_OK) || (retlen != info->page_size)) {
ERRMSG("Uncompress failed: %d\n", ret);
goto error;
}
memcpy(bufptr, buf2 + page_offset, size);
#endif
} else
memcpy(bufptr, buf + page_offset, size);
return size;
error:
ERRMSG("type_addr: %d, addr:%llx, size:%zd\n", PADDR, paddr, size);
return FALSE;
}
int
readmem(int type_addr, unsigned long long addr, void *bufptr, size_t size)
{
size_t read_size, next_size;
off_t offset = 0;
unsigned long long next_addr;
unsigned long long paddr, maddr = NOT_PADDR;
char *next_ptr;
const off_t failed = (off_t)-1;
switch (type_addr) {
case VADDR:
if ((paddr = vaddr_to_paddr(addr)) == NOT_PADDR) {
ERRMSG("Can't convert a virtual address(%llx) to physical address.\n",
addr);
goto error;
}
if (is_xen_memory()) {
if ((maddr = ptom_xen(paddr)) == NOT_PADDR) {
ERRMSG("Can't convert a physical address(%llx) to machine address.\n",
paddr);
return FALSE;
}
paddr = maddr;
}
break;
case PADDR:
paddr = addr;
if (is_xen_memory()) {
if ((maddr = ptom_xen(paddr)) == NOT_PADDR) {
ERRMSG("Can't convert a physical address(%llx) to machine address.\n",
paddr);
return FALSE;
}
paddr = maddr;
}
break;
case VADDR_XEN:
if ((paddr = kvtop_xen(addr)) == NOT_PADDR) {
ERRMSG("Can't convert a virtual address(%llx) to machine address.\n",
addr);
goto error;
}
break;
case MADDR_XEN:
paddr = addr;
break;
default:
ERRMSG("Invalid address type (%d).\n", type_addr);
goto error;
}
read_size = size;
/*
* Read each page, because pages are not necessarily continuous.
* Ex) pages in vmalloc area
*/
if (!is_in_same_page(addr, addr + size - 1)) {
read_size = info->page_size - (addr % info->page_size);
next_addr = roundup(addr + 1, info->page_size);
next_size = size - read_size;
next_ptr = (char *)bufptr + read_size;
if (!readmem(type_addr, next_addr, next_ptr, next_size))
goto error;
}
if (info->flag_refiltering)
return readpmem_kdump_compressed(paddr, bufptr, read_size);
if (info->flag_sadump)
return readpmem_sadump(paddr, bufptr, read_size);
if (!(offset = paddr_to_offset(paddr))) {
ERRMSG("Can't convert a physical address(%llx) to offset.\n",
paddr);
goto error;
}
if (lseek(info->fd_memory, offset, SEEK_SET) == failed) {
ERRMSG("Can't seek the dump memory(%s). (offset: %llx) %s\n",
info->name_memory, (unsigned long long)offset, strerror(errno));
goto error;
}
if (read(info->fd_memory, bufptr, read_size) != read_size) {
ERRMSG("Can't read the dump memory(%s). %s\n",
info->name_memory, strerror(errno));
goto error;
}
return size;
error:
ERRMSG("type_addr: %d, addr:%llx, size:%zd\n", type_addr, addr, size);
return FALSE;
}
int32_t
get_kernel_version(char *release)
{
int32_t version;
long maj, min, rel;
char *start, *end;
/*
* This method checks that vmlinux and vmcore are same kernel version.
*/
start = release;
maj = strtol(start, &end, 10);
if (maj == LONG_MAX)
return FALSE;
start = end + 1;
min = strtol(start, &end, 10);
if (min == LONG_MAX)
return FALSE;
start = end + 1;
rel = strtol(start, &end, 10);
if (rel == LONG_MAX)
return FALSE;
version = KERNEL_VERSION(maj, min, rel);
if ((version < OLDEST_VERSION) || (LATEST_VERSION < version)) {
MSG("The kernel version is not supported.\n");
MSG("The created dumpfile may be incomplete.\n");
}
return version;
}
int
is_page_size(long page_size)
{
/*
* Page size is restricted to a hamming weight of 1.
*/
if (page_size > 0 && !(page_size & (page_size - 1)))
return TRUE;
return FALSE;
}
int
set_page_size(long page_size)
{
if (!is_page_size(page_size)) {
ERRMSG("Invalid page_size: %ld", page_size);
return FALSE;
}
info->page_size = page_size;
info->page_shift = ffs(info->page_size) - 1;
DEBUG_MSG("page_size : %ld\n", info->page_size);
return TRUE;
}
int
fallback_to_current_page_size(void)
{
if (!set_page_size(sysconf(_SC_PAGE_SIZE)))
return FALSE;
DEBUG_MSG("WARNING: Cannot determine page size (no vmcoreinfo).\n");
DEBUG_MSG("Using the dump kernel page size: %ld\n",
info->page_size);
return TRUE;
}
int
check_release(void)
{
unsigned long utsname;
/*
* Get the kernel version.
*/
if (SYMBOL(system_utsname) != NOT_FOUND_SYMBOL) {
utsname = SYMBOL(system_utsname);
} else if (SYMBOL(init_uts_ns) != NOT_FOUND_SYMBOL) {
utsname = SYMBOL(init_uts_ns) + sizeof(int);
} else {
ERRMSG("Can't get the symbol of system_utsname.\n");
return FALSE;
}
if (!readmem(VADDR, utsname, &info->system_utsname,
sizeof(struct utsname))) {
ERRMSG("Can't get the address of system_utsname.\n");
return FALSE;
}
if (info->flag_read_vmcoreinfo) {
if (strcmp(info->system_utsname.release, info->release)) {
ERRMSG("%s and %s don't match.\n",
info->name_vmcoreinfo, info->name_memory);
retcd = WRONG_RELEASE;
return FALSE;
}
}
info->kernel_version = get_kernel_version(info->system_utsname.release);
if (info->kernel_version == FALSE) {
ERRMSG("Can't get the kernel version.\n");
return FALSE;
}
return TRUE;
}
int
open_vmcoreinfo(char *mode)
{
FILE *file_vmcoreinfo;
if ((file_vmcoreinfo = fopen(info->name_vmcoreinfo, mode)) == NULL) {
ERRMSG("Can't open the vmcoreinfo file(%s). %s\n",
info->name_vmcoreinfo, strerror(errno));
return FALSE;
}
info->file_vmcoreinfo = file_vmcoreinfo;
return TRUE;
}
int
open_kernel_file(void)
{
int fd;
if (info->name_vmlinux) {
if ((fd = open(info->name_vmlinux, O_RDONLY)) < 0) {
ERRMSG("Can't open the kernel file(%s). %s\n",
info->name_vmlinux, strerror(errno));
return FALSE;
}
info->fd_vmlinux = fd;
}
if (info->name_xen_syms) {
if ((fd = open(info->name_xen_syms, O_RDONLY)) < 0) {
ERRMSG("Can't open the kernel file(%s). %s\n",
info->name_xen_syms, strerror(errno));
return FALSE;
}
info->fd_xen_syms = fd;
}
return TRUE;
}
int
check_kdump_compressed(char *filename)
{
struct disk_dump_header dh;
if (!__read_disk_dump_header(&dh, filename))
return ERROR;
if (strncmp(dh.signature, KDUMP_SIGNATURE, SIG_LEN))
return FALSE;
return TRUE;
}
int
get_kdump_compressed_header_info(char *filename)
{
struct disk_dump_header dh;
struct kdump_sub_header kh;
if (!read_disk_dump_header(&dh, filename))
return FALSE;
if (!read_kdump_sub_header(&kh, filename))
return FALSE;
if (dh.header_version < 1) {
ERRMSG("header does not have dump_level member\n");
return FALSE;
}
DEBUG_MSG("diskdump main header\n");
DEBUG_MSG(" signature : %s\n", dh.signature);
DEBUG_MSG(" header_version : %d\n", dh.header_version);
DEBUG_MSG(" status : %d\n", dh.status);
DEBUG_MSG(" block_size : %d\n", dh.block_size);
DEBUG_MSG(" sub_hdr_size : %d\n", dh.sub_hdr_size);
DEBUG_MSG(" bitmap_blocks : %d\n", dh.bitmap_blocks);
DEBUG_MSG(" max_mapnr : 0x%x\n", dh.max_mapnr);
DEBUG_MSG(" total_ram_blocks : %d\n", dh.total_ram_blocks);
DEBUG_MSG(" device_blocks : %d\n", dh.device_blocks);
DEBUG_MSG(" written_blocks : %d\n", dh.written_blocks);
DEBUG_MSG(" current_cpu : %d\n", dh.current_cpu);
DEBUG_MSG(" nr_cpus : %d\n", dh.nr_cpus);
DEBUG_MSG("kdump sub header\n");
DEBUG_MSG(" phys_base : 0x%lx\n", kh.phys_base);
DEBUG_MSG(" dump_level : %d\n", kh.dump_level);
DEBUG_MSG(" split : %d\n", kh.split);
DEBUG_MSG(" start_pfn : 0x%lx\n", kh.start_pfn);
DEBUG_MSG(" end_pfn : 0x%lx\n", kh.end_pfn);
info->dh_memory = malloc(sizeof(dh));
if (info->dh_memory == NULL) {
ERRMSG("Can't allocate memory for the header. %s\n",
strerror(errno));
return FALSE;
}
memcpy(info->dh_memory, &dh, sizeof(dh));
memcpy(&info->timestamp, &dh.timestamp, sizeof(dh.timestamp));
info->kh_memory = malloc(sizeof(kh));
if (info->kh_memory == NULL) {
ERRMSG("Can't allocate memory for the sub header. %s\n",
strerror(errno));
goto error;
}
memcpy(info->kh_memory, &kh, sizeof(kh));
set_nr_cpus(dh.nr_cpus);
if (dh.header_version >= 3) {
/* A dumpfile contains vmcoreinfo data. */
set_vmcoreinfo(kh.offset_vmcoreinfo, kh.size_vmcoreinfo);
DEBUG_MSG(" offset_vmcoreinfo: 0x%llx\n",
(unsigned long long)kh.offset_vmcoreinfo);
DEBUG_MSG(" size_vmcoreinfo : 0x%ld\n", kh.size_vmcoreinfo);
}
if (dh.header_version >= 4) {
/* A dumpfile contains ELF note section. */
set_pt_note(kh.offset_note, kh.size_note);
DEBUG_MSG(" offset_note : 0x%llx\n",
(unsigned long long)kh.offset_note);
DEBUG_MSG(" size_note : 0x%ld\n", kh.size_note);
}
if (dh.header_version >= 5) {
/* A dumpfile contains erased information. */
set_eraseinfo(kh.offset_eraseinfo, kh.size_eraseinfo);
DEBUG_MSG(" offset_eraseinfo : 0x%llx\n",
(unsigned long long)kh.offset_eraseinfo);
DEBUG_MSG(" size_eraseinfo : 0x%ld\n", kh.size_eraseinfo);
}
return TRUE;
error:
free(info->dh_memory);
info->dh_memory = NULL;
return FALSE;
}
int
open_dump_memory(void)
{
int fd, status;
if ((fd = open(info->name_memory, O_RDONLY)) < 0) {
ERRMSG("Can't open the dump memory(%s). %s\n",
info->name_memory, strerror(errno));
return FALSE;
}
info->fd_memory = fd;
status = check_kdump_compressed(info->name_memory);
if (status == TRUE) {
info->flag_refiltering = TRUE;
return get_kdump_compressed_header_info(info->name_memory);
}
status = check_and_get_sadump_header_info(info->name_memory);
if (status == TRUE)
return TRUE;
if (status == ERROR)
return TRUE;
return FALSE;
}
int
open_dump_file(void)
{
int fd;
int open_flags = O_RDWR|O_CREAT|O_TRUNC;
if (!info->flag_force)
open_flags |= O_EXCL;
if (info->flag_flatten) {
fd = STDOUT_FILENO;
info->name_dumpfile = filename_stdout;
} else if ((fd = open(info->name_dumpfile, open_flags,
S_IRUSR|S_IWUSR)) < 0) {
ERRMSG("Can't open the dump file(%s). %s\n",
info->name_dumpfile, strerror(errno));
return FALSE;
}
info->fd_dumpfile = fd;
return TRUE;
}
int
open_dump_bitmap(void)
{
int i, fd;
char *tmpname;
tmpname = getenv("TMPDIR");
if (!tmpname)
tmpname = "/tmp";
if ((info->name_bitmap = (char *)malloc(sizeof(FILENAME_BITMAP) +
strlen(tmpname) + 1)) == NULL) {
ERRMSG("Can't allocate memory for the filename. %s\n",
strerror(errno));
return FALSE;
}
strcpy(info->name_bitmap, tmpname);
strcat(info->name_bitmap, "/");
strcat(info->name_bitmap, FILENAME_BITMAP);
if ((fd = mkstemp(info->name_bitmap)) < 0) {
ERRMSG("Can't open the bitmap file(%s). %s\n",
info->name_bitmap, strerror(errno));
return FALSE;
}
info->fd_bitmap = fd;
if (info->flag_split) {
/*
* Reserve file descriptors of bitmap for creating split
* dumpfiles by multiple processes, because a bitmap file will
* be unlinked just after this and it is not possible to open
* a bitmap file later.
*/
for (i = 0; i < info->num_dumpfile; i++) {
if ((fd = open(info->name_bitmap, O_RDONLY)) < 0) {
ERRMSG("Can't open the bitmap file(%s). %s\n",
info->name_bitmap, strerror(errno));
return FALSE;
}
SPLITTING_FD_BITMAP(i) = fd;
}
}
unlink(info->name_bitmap);
return TRUE;
}
/*
* Open the following files when it generates the vmcoreinfo file.
* - vmlinux
* - vmcoreinfo file
*/
int
open_files_for_generating_vmcoreinfo(void)
{
if (!open_kernel_file())
return FALSE;
if (!open_vmcoreinfo("w"))
return FALSE;
return TRUE;
}
/*
* Open the following file when it rearranges the dump data.
* - dump file
*/
int
open_files_for_rearranging_dumpdata(void)
{
if (!open_dump_file())
return FALSE;
return TRUE;
}
/*
* Open the following files when it creates the dump file.
* - dump mem
* - dump file
* - bit map
* if it reads the vmcoreinfo file
* - vmcoreinfo file
* else
* - vmlinux
*/
int
open_files_for_creating_dumpfile(void)
{
if (info->flag_read_vmcoreinfo) {
if (!open_vmcoreinfo("r"))
return FALSE;
} else {
if (!open_kernel_file())
return FALSE;
}
if (!open_dump_memory())
return FALSE;
if (!open_dump_bitmap())
return FALSE;
return TRUE;
}
int
is_kvaddr(unsigned long long addr)
{
return (addr >= (unsigned long long)(KVBASE));
}
int
get_symbol_info(void)
{
/*
* Get symbol info.
*/
SYMBOL_INIT(mem_map, "mem_map");
SYMBOL_INIT(vmem_map, "vmem_map");
SYMBOL_INIT(mem_section, "mem_section");
SYMBOL_INIT(pkmap_count, "pkmap_count");
SYMBOL_INIT_NEXT(pkmap_count_next, "pkmap_count");
SYMBOL_INIT(system_utsname, "system_utsname");
SYMBOL_INIT(init_uts_ns, "init_uts_ns");
SYMBOL_INIT(_stext, "_stext");
SYMBOL_INIT(swapper_pg_dir, "swapper_pg_dir");
SYMBOL_INIT(init_level4_pgt, "init_level4_pgt");
SYMBOL_INIT(vmlist, "vmlist");
SYMBOL_INIT(phys_base, "phys_base");
SYMBOL_INIT(node_online_map, "node_online_map");
SYMBOL_INIT(node_states, "node_states");
SYMBOL_INIT(node_memblk, "node_memblk");
SYMBOL_INIT(node_data, "node_data");
SYMBOL_INIT(pgdat_list, "pgdat_list");
SYMBOL_INIT(contig_page_data, "contig_page_data");
SYMBOL_INIT(log_buf, "log_buf");
SYMBOL_INIT(log_buf_len, "log_buf_len");
SYMBOL_INIT(log_end, "log_end");
SYMBOL_INIT(max_pfn, "max_pfn");
SYMBOL_INIT(modules, "modules");
SYMBOL_INIT(high_memory, "high_memory");
SYMBOL_INIT(linux_banner, "linux_banner");
SYMBOL_INIT(bios_cpu_apicid, "bios_cpu_apicid");
SYMBOL_INIT(x86_bios_cpu_apicid, "x86_bios_cpu_apicid");
if (SYMBOL(x86_bios_cpu_apicid) == NOT_FOUND_SYMBOL)
SYMBOL_INIT(x86_bios_cpu_apicid,
"per_cpu__x86_bios_cpu_apicid");
SYMBOL_INIT(x86_bios_cpu_apicid_early_ptr,
"x86_bios_cpu_apicid_early_ptr");
SYMBOL_INIT(x86_bios_cpu_apicid_early_map,
"x86_bios_cpu_apicid_early_map");
SYMBOL_INIT(crash_notes, "crash_notes");
SYMBOL_INIT(__per_cpu_load, "__per_cpu_load");
SYMBOL_INIT(__per_cpu_offset, "__per_cpu_offset");
SYMBOL_INIT(cpu_online_mask, "cpu_online_mask");
if (SYMBOL(cpu_online_mask) == NOT_FOUND_SYMBOL)
SYMBOL_INIT(cpu_online_mask, "cpu_online_map");
SYMBOL_INIT(kexec_crash_image, "kexec_crash_image");
SYMBOL_INIT(node_remap_start_vaddr, "node_remap_start_vaddr");
SYMBOL_INIT(node_remap_end_vaddr, "node_remap_end_vaddr");
SYMBOL_INIT(node_remap_start_pfn, "node_remap_start_pfn");
if (SYMBOL(node_data) != NOT_FOUND_SYMBOL)
SYMBOL_ARRAY_TYPE_INIT(node_data, "node_data");
if (SYMBOL(pgdat_list) != NOT_FOUND_SYMBOL)
SYMBOL_ARRAY_LENGTH_INIT(pgdat_list, "pgdat_list");
if (SYMBOL(mem_section) != NOT_FOUND_SYMBOL)
SYMBOL_ARRAY_LENGTH_INIT(mem_section, "mem_section");
if (SYMBOL(node_memblk) != NOT_FOUND_SYMBOL)
SYMBOL_ARRAY_LENGTH_INIT(node_memblk, "node_memblk");
if (SYMBOL(__per_cpu_offset) != NOT_FOUND_SYMBOL)
SYMBOL_ARRAY_LENGTH_INIT(__per_cpu_offset, "__per_cpu_offset");
if (SYMBOL(node_remap_start_pfn) != NOT_FOUND_SYMBOL)
SYMBOL_ARRAY_LENGTH_INIT(node_remap_start_pfn,
"node_remap_start_pfn");
return TRUE;
}
int
get_structure_info(void)
{
/*
* Get offsets of the page_discriptor's members.
*/
SIZE_INIT(page, "page");
OFFSET_INIT(page.flags, "page", "flags");
OFFSET_INIT(page._count, "page", "_count");
OFFSET_INIT(page.mapping, "page", "mapping");
/*
* On linux-2.6.16 or later, page.mapping is defined
* in anonymous union.
*/
if (OFFSET(page.mapping) == NOT_FOUND_STRUCTURE)
OFFSET_IN_UNION_INIT(page.mapping, "page", "mapping");
/*
* Some vmlinux(s) don't have debugging information about
* page.mapping. Then, makedumpfile assumes that there is
* "mapping" next to "private(unsigned long)" in the first
* union.
*/
if (OFFSET(page.mapping) == NOT_FOUND_STRUCTURE) {
OFFSET(page.mapping) = get_member_offset("page", NULL,
DWARF_INFO_GET_MEMBER_OFFSET_1ST_UNION);
if (OFFSET(page.mapping) == FAILED_DWARFINFO)
return FALSE;
if (OFFSET(page.mapping) != NOT_FOUND_STRUCTURE)
OFFSET(page.mapping) += sizeof(unsigned long);
}
OFFSET_INIT(page.lru, "page", "lru");
/*
* Get offsets of the mem_section's members.
*/
SIZE_INIT(mem_section, "mem_section");
OFFSET_INIT(mem_section.section_mem_map, "mem_section",
"section_mem_map");
/*
* Get offsets of the pglist_data's members.
*/
SIZE_INIT(pglist_data, "pglist_data");
OFFSET_INIT(pglist_data.node_zones, "pglist_data", "node_zones");
OFFSET_INIT(pglist_data.nr_zones, "pglist_data", "nr_zones");
OFFSET_INIT(pglist_data.node_mem_map, "pglist_data", "node_mem_map");
OFFSET_INIT(pglist_data.node_start_pfn, "pglist_data","node_start_pfn");
OFFSET_INIT(pglist_data.node_spanned_pages, "pglist_data",
"node_spanned_pages");
OFFSET_INIT(pglist_data.pgdat_next, "pglist_data", "pgdat_next");
/*
* Get offsets of the zone's members.
*/
SIZE_INIT(zone, "zone");
OFFSET_INIT(zone.free_pages, "zone", "free_pages");
OFFSET_INIT(zone.free_area, "zone", "free_area");
OFFSET_INIT(zone.vm_stat, "zone", "vm_stat");
OFFSET_INIT(zone.spanned_pages, "zone", "spanned_pages");
MEMBER_ARRAY_LENGTH_INIT(zone.free_area, "zone", "free_area");
/*
* Get offsets of the free_area's members.
*/
SIZE_INIT(free_area, "free_area");
OFFSET_INIT(free_area.free_list, "free_area", "free_list");
MEMBER_ARRAY_LENGTH_INIT(free_area.free_list, "free_area", "free_list");
/*
* Get offsets of the list_head's members.
*/
SIZE_INIT(list_head, "list_head");
OFFSET_INIT(list_head.next, "list_head", "next");
OFFSET_INIT(list_head.prev, "list_head", "prev");
/*
* Get offsets of the node_memblk_s's members.
*/
SIZE_INIT(node_memblk_s, "node_memblk_s");
OFFSET_INIT(node_memblk_s.start_paddr, "node_memblk_s", "start_paddr");
OFFSET_INIT(node_memblk_s.size, "node_memblk_s", "size");
OFFSET_INIT(node_memblk_s.nid, "node_memblk_s", "nid");
OFFSET_INIT(vm_struct.addr, "vm_struct", "addr");
/*
* Get offset of the module members.
*/
SIZE_INIT(module, "module");
OFFSET_INIT(module.strtab, "module", "strtab");
OFFSET_INIT(module.symtab, "module", "symtab");
OFFSET_INIT(module.num_symtab, "module", "num_symtab");
OFFSET_INIT(module.list, "module", "list");
OFFSET_INIT(module.name, "module", "name");
OFFSET_INIT(module.module_core, "module", "module_core");
OFFSET_INIT(module.core_size, "module", "core_size");
OFFSET_INIT(module.module_init, "module", "module_init");
OFFSET_INIT(module.init_size, "module", "init_size");
ENUM_NUMBER_INIT(NR_FREE_PAGES, "NR_FREE_PAGES");
ENUM_NUMBER_INIT(N_ONLINE, "N_ONLINE");
ENUM_NUMBER_INIT(PG_lru, "PG_lru");
ENUM_NUMBER_INIT(PG_private, "PG_private");
ENUM_NUMBER_INIT(PG_swapcache, "PG_swapcache");
TYPEDEF_SIZE_INIT(nodemask_t, "nodemask_t");
SIZE_INIT(percpu_data, "percpu_data");
/*
* Get offset of the elf_prstatus members.
*/
SIZE_INIT(elf_prstatus, "elf_prstatus");
OFFSET_INIT(elf_prstatus.pr_reg, "elf_prstatus", "pr_reg");
/*
* Get size of cpumask and cpumask_t.
*/
SIZE_INIT(cpumask, "cpumask");
TYPEDEF_SIZE_INIT(cpumask_t, "cpumask_t");
/*
* Get offset of the user_regs_struct members.
*/
SIZE_INIT(user_regs_struct, "user_regs_struct");
#ifdef __x86__