-
Notifications
You must be signed in to change notification settings - Fork 0
/
elf_info.c
867 lines (766 loc) · 18.3 KB
/
elf_info.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
/*
* elf_info.c
*
* Copyright (C) 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 <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <gelf.h>
#include <libelf.h>
#include "common.h"
#include "print_info.h"
#include "elf_info.h"
#include "makedumpfile.h"
#define ELF32 (1)
#define ELF64 (2)
#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
#define VMCOREINFO_NOTE_NAME_BYTES (sizeof(VMCOREINFO_NOTE_NAME))
#define VMCOREINFO_XEN_NOTE_NAME "VMCOREINFO_XEN"
#define VMCOREINFO_XEN_NOTE_NAME_BYTES (sizeof(VMCOREINFO_XEN_NOTE_NAME))
#define XEN_ELFNOTE_CRASH_INFO (0x1000001)
struct pt_load_segment {
off_t file_offset;
unsigned long long phys_start;
unsigned long long phys_end;
unsigned long long virt_start;
unsigned long long virt_end;
};
static int nr_cpus; /* number of cpu */
/*
* File information about /proc/vmcore:
*/
static int fd_memory;
static char *name_memory;
static int flags_memory;
#define MEMORY_ELF64 (1 << 0)
#define MEMORY_XEN (1 << 1)
/*
* PT_LOAD information about /proc/vmcore:
*/
static unsigned int num_pt_loads;
static struct pt_load_segment *pt_loads;
static off_t offset_pt_load_memory;
/*
* PT_NOTE information about /proc/vmcore:
*/
static off_t offset_pt_note_memory;
static unsigned long size_pt_note_memory;
/*
* vmcoreinfo in /proc/vmcore:
*/
static off_t offset_vmcoreinfo;
static unsigned long size_vmcoreinfo;
static off_t offset_vmcoreinfo_xen;
static unsigned long size_vmcoreinfo_xen;
/*
* erased information in /proc/vmcore:
*/
static off_t offset_eraseinfo;
static unsigned long size_eraseinfo;
/*
* Xen information:
*/
static off_t offset_xen_crash_info;
static unsigned long size_xen_crash_info;
static unsigned long xen_p2m_mfn;
/*
* Internal functions.
*/
static int
get_elf64_phdr(int fd, char *filename, int index, Elf64_Phdr *phdr)
{
off_t offset;
offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * index;
if (lseek(fd, offset, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (read(fd, phdr, sizeof(Elf64_Phdr)) != sizeof(Elf64_Phdr)) {
ERRMSG("Can't read %s. %s\n", filename, strerror(errno));
return FALSE;
}
return TRUE;
}
static int
get_elf32_phdr(int fd, char *filename, int index, Elf32_Phdr *phdr)
{
off_t offset;
offset = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * index;
if (lseek(fd, offset, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (read(fd, phdr, sizeof(Elf32_Phdr)) != sizeof(Elf32_Phdr)) {
ERRMSG("Can't read %s. %s\n", filename, strerror(errno));
return FALSE;
}
return TRUE;
}
static int
check_elf_format(int fd, char *filename, int *phnum, unsigned int *num_load)
{
int i;
Elf64_Ehdr ehdr64;
Elf64_Phdr load64;
Elf32_Ehdr ehdr32;
Elf32_Phdr load32;
if (lseek(fd, 0, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (read(fd, &ehdr64, sizeof(Elf64_Ehdr)) != sizeof(Elf64_Ehdr)) {
ERRMSG("Can't read %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (lseek(fd, 0, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (read(fd, &ehdr32, sizeof(Elf32_Ehdr)) != sizeof(Elf32_Ehdr)) {
ERRMSG("Can't read %s. %s\n", filename, strerror(errno));
return FALSE;
}
(*num_load) = 0;
if ((ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
&& (ehdr32.e_ident[EI_CLASS] != ELFCLASS32)) {
(*phnum) = ehdr64.e_phnum;
for (i = 0; i < ehdr64.e_phnum; i++) {
if (!get_elf64_phdr(fd, filename, i, &load64)) {
ERRMSG("Can't find Phdr %d.\n", i);
return FALSE;
}
if (load64.p_type == PT_LOAD)
(*num_load)++;
}
return ELF64;
} else if ((ehdr64.e_ident[EI_CLASS] != ELFCLASS64)
&& (ehdr32.e_ident[EI_CLASS] == ELFCLASS32)) {
(*phnum) = ehdr32.e_phnum;
for (i = 0; i < ehdr32.e_phnum; i++) {
if (!get_elf32_phdr(fd, filename, i, &load32)) {
ERRMSG("Can't find Phdr %d.\n", i);
return FALSE;
}
if (load32.p_type == PT_LOAD)
(*num_load)++;
}
return ELF32;
}
ERRMSG("Can't get valid ehdr.\n");
return FALSE;
}
static int
dump_Elf_load(Elf64_Phdr *prog, int num_load)
{
struct pt_load_segment *pls;
if (prog->p_type != PT_LOAD) {
ERRMSG("Not PT_LOAD.\n");
return FALSE;
}
pls = &pt_loads[num_load];
pls->phys_start = prog->p_paddr;
pls->phys_end = pls->phys_start + prog->p_filesz;
pls->virt_start = prog->p_vaddr;
pls->virt_end = pls->virt_start + prog->p_filesz;
pls->file_offset = prog->p_offset;
DEBUG_MSG("LOAD (%d)\n", num_load);
DEBUG_MSG(" phys_start : %llx\n", pls->phys_start);
DEBUG_MSG(" phys_end : %llx\n", pls->phys_end);
DEBUG_MSG(" virt_start : %llx\n", pls->virt_start);
DEBUG_MSG(" virt_end : %llx\n", pls->virt_end);
return TRUE;
}
static off_t
offset_next_note(void *note)
{
off_t offset;
Elf64_Nhdr *note64;
Elf32_Nhdr *note32;
/*
* Both name and desc in ELF Note elements are padded to
* 4 byte boundary.
*/
if (is_elf64_memory()) {
note64 = (Elf64_Nhdr *)note;
offset = sizeof(Elf64_Nhdr)
+ roundup(note64->n_namesz, 4)
+ roundup(note64->n_descsz, 4);
} else {
note32 = (Elf32_Nhdr *)note;
offset = sizeof(Elf32_Nhdr)
+ roundup(note32->n_namesz, 4)
+ roundup(note32->n_descsz, 4);
}
return offset;
}
static int
note_type(void *note)
{
int type;
Elf64_Nhdr *note64;
Elf32_Nhdr *note32;
if (is_elf64_memory()) {
note64 = (Elf64_Nhdr *)note;
type = note64->n_type;
} else {
note32 = (Elf32_Nhdr *)note;
type = note32->n_type;
}
return type;
}
static int
note_descsz(void *note)
{
int size;
Elf64_Nhdr *note64;
Elf32_Nhdr *note32;
if (is_elf64_memory()) {
note64 = (Elf64_Nhdr *)note;
size = note64->n_descsz;
} else {
note32 = (Elf32_Nhdr *)note;
size = note32->n_descsz;
}
return size;
}
static off_t
offset_note_desc(void *note)
{
off_t offset;
Elf64_Nhdr *note64;
Elf32_Nhdr *note32;
if (is_elf64_memory()) {
note64 = (Elf64_Nhdr *)note;
offset = sizeof(Elf64_Nhdr) + roundup(note64->n_namesz, 4);
} else {
note32 = (Elf32_Nhdr *)note;
offset = sizeof(Elf32_Nhdr) + roundup(note32->n_namesz, 4);
}
return offset;
}
static int
get_pt_note_info(void)
{
int n_type, size_desc;
unsigned long p2m_mfn;
off_t offset, offset_desc, off_p2m = 0;
char buf[VMCOREINFO_XEN_NOTE_NAME_BYTES];
char note[MAX_SIZE_NHDR];
nr_cpus = 0;
offset = offset_pt_note_memory;
while (offset < offset_pt_note_memory + size_pt_note_memory) {
if (lseek(fd_memory, offset, SEEK_SET) < 0) {
ERRMSG("Can't seek the dump memory(%s). %s\n",
name_memory, strerror(errno));
return FALSE;
}
if (read(fd_memory, note, sizeof(note)) != sizeof(note)) {
ERRMSG("Can't read the dump memory(%s). %s\n",
name_memory, strerror(errno));
return FALSE;
}
if (read(fd_memory, &buf, sizeof(buf)) != sizeof(buf)) {
ERRMSG("Can't read the dump memory(%s). %s\n",
name_memory, strerror(errno));
return FALSE;
}
n_type = note_type(note);
if (n_type == NT_PRSTATUS) {
nr_cpus++;
offset += offset_next_note(note);
continue;
}
offset_desc = offset + offset_note_desc(note);
size_desc = note_descsz(note);
/*
* Check whether /proc/vmcore contains vmcoreinfo,
* and get both the offset and the size.
*
* NOTE: The owner name of xen should be checked at first,
* because its name is "VMCOREINFO_XEN" and the one
* of linux is "VMCOREINFO".
*/
if (!strncmp(VMCOREINFO_XEN_NOTE_NAME, buf,
VMCOREINFO_XEN_NOTE_NAME_BYTES)) {
offset_vmcoreinfo_xen = offset_desc;
size_vmcoreinfo_xen = size_desc;
} else if (!strncmp(VMCOREINFO_NOTE_NAME, buf,
VMCOREINFO_NOTE_NAME_BYTES)) {
set_vmcoreinfo(offset_desc, size_desc);
/*
* Check whether /proc/vmcore contains xen's note.
*/
} else if (n_type == XEN_ELFNOTE_CRASH_INFO) {
flags_memory |= MEMORY_XEN;
offset_xen_crash_info = offset_desc;
size_xen_crash_info = size_desc;
off_p2m = offset + offset_next_note(note)
- sizeof(p2m_mfn);
if (lseek(fd_memory, off_p2m, SEEK_SET) < 0){
ERRMSG("Can't seek the dump memory(%s). %s\n",
name_memory, strerror(errno));
return FALSE;
}
if (read(fd_memory, &p2m_mfn, sizeof(p2m_mfn))
!= sizeof(p2m_mfn)) {
ERRMSG("Can't read the dump memory(%s). %s\n",
name_memory, strerror(errno));
return FALSE;
}
xen_p2m_mfn = p2m_mfn;
/*
* Check whether a source dumpfile contains eraseinfo.
* /proc/vmcore does not contain eraseinfo, because eraseinfo
* is added only by makedumpfile and makedumpfile does not
* create /proc/vmcore.
*/
} else if (!strncmp(ERASEINFO_NOTE_NAME, buf,
ERASEINFO_NOTE_NAME_BYTES)) {
set_eraseinfo(offset_desc, size_desc);
}
offset += offset_next_note(note);
}
if (is_xen_memory())
DEBUG_MSG("Xen kdump\n");
else
DEBUG_MSG("Linux kdump\n");
return TRUE;
}
/*
* External functions.
*/
/*
* Convert Physical Address to File Offset.
* If this function returns 0x0, File Offset isn't found.
* The File Offset 0x0 is in the ELF header.
* It is not in the memory image.
*/
off_t
paddr_to_offset(unsigned long long paddr)
{
int i;
off_t offset;
struct pt_load_segment *pls;
for (i = offset = 0; i < num_pt_loads; i++) {
pls = &pt_loads[i];
if ((paddr >= pls->phys_start)
&& (paddr < pls->phys_end)) {
offset = (off_t)(paddr - pls->phys_start) +
pls->file_offset;
break;
}
}
return offset;
}
/*
* Same as paddr_to_offset() but makes sure that the specified offset (hint)
* in the segment.
*/
off_t
paddr_to_offset2(unsigned long long paddr, off_t hint)
{
int i;
off_t offset;
unsigned long long len;
struct pt_load_segment *pls;
for (i = offset = 0; i < num_pt_loads; i++) {
pls = &pt_loads[i];
len = pls->phys_end - pls->phys_start;
if ((paddr >= pls->phys_start)
&& (paddr < pls->phys_end)
&& (hint >= pls->file_offset)
&& (hint < pls->file_offset + len)) {
offset = (off_t)(paddr - pls->phys_start) +
pls->file_offset;
break;
}
}
return offset;
}
unsigned long long
vaddr_to_paddr_general(unsigned long long vaddr)
{
int i;
unsigned long long paddr = NOT_PADDR;
struct pt_load_segment *pls;
if (pt_loads == NULL)
return NOT_PADDR;
for (i = 0; i < num_pt_loads; i++) {
pls = &pt_loads[i];
if ((vaddr >= pls->virt_start)
&& (vaddr < pls->virt_end)) {
paddr = (off_t)(vaddr - pls->virt_start) +
pls->phys_start;
break;
}
}
return paddr;
}
/*
* This function is slow because it doesn't use the memory.
* It is useful at few calls like get_str_osrelease_from_vmlinux().
*/
off_t
vaddr_to_offset_slow(int fd, char *filename, unsigned long long vaddr)
{
off_t offset = 0;
int i, phnum, flag_elf64, elf_format;
unsigned int num_load;
Elf64_Phdr load64;
Elf32_Phdr load32;
elf_format = check_elf_format(fd, filename, &phnum, &num_load);
if (elf_format == ELF64)
flag_elf64 = TRUE;
else if (elf_format == ELF32)
flag_elf64 = FALSE;
else
return 0;
for (i = 0; i < phnum; i++) {
if (flag_elf64) { /* ELF64 */
if (!get_elf64_phdr(fd, filename, i, &load64)) {
ERRMSG("Can't find Phdr %d.\n", i);
return 0;
}
if (load64.p_type != PT_LOAD)
continue;
if ((vaddr < load64.p_vaddr)
|| (load64.p_vaddr + load64.p_filesz <= vaddr))
continue;
offset = load64.p_offset + (vaddr - load64.p_vaddr);
break;
} else { /* ELF32 */
if (!get_elf32_phdr(fd, filename, i, &load32)) {
ERRMSG("Can't find Phdr %d.\n", i);
return 0;
}
if (load32.p_type != PT_LOAD)
continue;
if ((vaddr < load32.p_vaddr)
|| (load32.p_vaddr + load32.p_filesz <= vaddr))
continue;
offset = load32.p_offset + (vaddr - load32.p_vaddr);
break;
}
}
return offset;
}
unsigned long long
get_max_paddr(void)
{
int i;
unsigned long long max_paddr = 0;
struct pt_load_segment *pls;
for (i = 0; i < num_pt_loads; i++) {
pls = &pt_loads[i];
if (max_paddr < pls->phys_end)
max_paddr = pls->phys_end;
}
return max_paddr;
}
int
get_elf64_ehdr(int fd, char *filename, Elf64_Ehdr *ehdr)
{
if (lseek(fd, 0, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (read(fd, ehdr, sizeof(Elf64_Ehdr)) != sizeof(Elf64_Ehdr)) {
ERRMSG("Can't read %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (ehdr->e_ident[EI_CLASS] != ELFCLASS64) {
ERRMSG("Can't get valid e_ident.\n");
return FALSE;
}
return TRUE;
}
int
get_elf32_ehdr(int fd, char *filename, Elf32_Ehdr *ehdr)
{
if (lseek(fd, 0, SEEK_SET) < 0) {
ERRMSG("Can't seek %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (read(fd, ehdr, sizeof(Elf32_Ehdr)) != sizeof(Elf32_Ehdr)) {
ERRMSG("Can't read %s. %s\n", filename, strerror(errno));
return FALSE;
}
if (ehdr->e_ident[EI_CLASS] != ELFCLASS32) {
ERRMSG("Can't get valid e_ident.\n");
return FALSE;
}
return TRUE;
}
/*
* Get ELF information about /proc/vmcore.
*/
int
get_elf_info(int fd, char *filename)
{
int i, j, phnum, elf_format;
Elf64_Phdr phdr;
/*
* Check ELF64 or ELF32.
*/
elf_format = check_elf_format(fd, filename, &phnum, &num_pt_loads);
if (elf_format == ELF64)
flags_memory |= MEMORY_ELF64;
else if (elf_format != ELF32)
return FALSE;
if (!num_pt_loads) {
ERRMSG("Can't get the number of PT_LOAD.\n");
return FALSE;
}
/*
* The below file information will be used as /proc/vmcore.
*/
fd_memory = fd;
name_memory = filename;
pt_loads = calloc(sizeof(struct pt_load_segment), num_pt_loads);
if (pt_loads == NULL) {
ERRMSG("Can't allocate memory for the PT_LOAD. %s\n",
strerror(errno));
return FALSE;
}
for (i = 0, j = 0; i < phnum; i++) {
if (!get_phdr_memory(i, &phdr))
return FALSE;
if (phdr.p_type == PT_NOTE) {
set_pt_note(phdr.p_offset, phdr.p_filesz);
}
if (phdr.p_type != PT_LOAD)
continue;
if (j == 0) {
offset_pt_load_memory = phdr.p_offset;
if (offset_pt_load_memory == 0) {
ERRMSG("Can't get the offset of page data.\n");
return FALSE;
}
}
if (j >= num_pt_loads)
return FALSE;
if(!dump_Elf_load(&phdr, j))
return FALSE;
j++;
}
if (!has_pt_note()) {
ERRMSG("Can't find PT_NOTE Phdr.\n");
return FALSE;
}
if (!get_pt_note_info()) {
ERRMSG("Can't get PT_NOTE information.\n");
return FALSE;
}
return TRUE;
}
void
free_elf_info(void)
{
free(pt_loads);
pt_loads = NULL;
}
int
is_elf64_memory(void)
{
return (flags_memory & MEMORY_ELF64);
}
int
is_xen_memory(void)
{
return (flags_memory & MEMORY_XEN);
}
int
get_phnum_memory(void)
{
int phnum;
Elf64_Ehdr ehdr64;
Elf32_Ehdr ehdr32;
if (is_elf64_memory()) { /* ELF64 */
if (!get_elf64_ehdr(fd_memory, name_memory, &ehdr64)) {
ERRMSG("Can't get ehdr64.\n");
return FALSE;
}
phnum = ehdr64.e_phnum;
} else { /* ELF32 */
if (!get_elf32_ehdr(fd_memory, name_memory, &ehdr32)) {
ERRMSG("Can't get ehdr32.\n");
return FALSE;
}
phnum = ehdr32.e_phnum;
}
return phnum;
}
int
get_phdr_memory(int index, Elf64_Phdr *phdr)
{
Elf32_Phdr phdr32;
if (is_elf64_memory()) { /* ELF64 */
if (!get_elf64_phdr(fd_memory, name_memory, index, phdr)) {
ERRMSG("Can't find Phdr %d.\n", index);
return FALSE;
}
} else {
if (!get_elf32_phdr(fd_memory, name_memory, index, &phdr32)) {
ERRMSG("Can't find Phdr %d.\n", index);
return FALSE;
}
memset(phdr, 0, sizeof(Elf64_Phdr));
phdr->p_type = phdr32.p_type;
phdr->p_flags = phdr32.p_flags;
phdr->p_offset = phdr32.p_offset;
phdr->p_vaddr = phdr32.p_vaddr;
phdr->p_paddr = phdr32.p_paddr;
phdr->p_filesz = phdr32.p_filesz;
phdr->p_memsz = phdr32.p_memsz;
phdr->p_align = phdr32.p_align;
}
return TRUE;
}
off_t
get_offset_pt_load_memory(void)
{
return offset_pt_load_memory;
}
int
get_pt_load(int idx,
unsigned long long *phys_start,
unsigned long long *phys_end,
unsigned long long *virt_start,
unsigned long long *virt_end)
{
struct pt_load_segment *pls;
if (num_pt_loads <= idx)
return FALSE;
pls = &pt_loads[idx];
if (phys_start)
*phys_start = pls->phys_start;
if (phys_end)
*phys_end = pls->phys_end;
if (virt_start)
*virt_start = pls->virt_start;
if (virt_end)
*virt_end = pls->virt_end;
return TRUE;
}
unsigned int
get_num_pt_loads(void)
{
return num_pt_loads;
}
void
set_nr_cpus(int num)
{
nr_cpus = num;
}
int
get_nr_cpus(void)
{
return nr_cpus;
}
int
has_pt_note(void)
{
if (info->flag_sadump) {
if (size_pt_note_memory)
return TRUE;
} else if (offset_pt_note_memory && size_pt_note_memory)
return TRUE;
return FALSE;
}
void
set_pt_note(off_t offset, unsigned long size)
{
offset_pt_note_memory = offset;
size_pt_note_memory = size;
}
void
get_pt_note(off_t *offset, unsigned long *size)
{
if (offset)
*offset = offset_pt_note_memory;
if (size)
*size = size_pt_note_memory;
}
int
has_vmcoreinfo(void)
{
if (offset_vmcoreinfo && size_vmcoreinfo)
return TRUE;
return FALSE;
}
void
set_vmcoreinfo(off_t offset, unsigned long size)
{
offset_vmcoreinfo = offset;
size_vmcoreinfo = size;
}
void
get_vmcoreinfo(off_t *offset, unsigned long *size)
{
if (offset)
*offset = offset_vmcoreinfo;
if (size)
*size = size_vmcoreinfo;
}
int
has_vmcoreinfo_xen(void)
{
if (offset_vmcoreinfo_xen && size_vmcoreinfo_xen)
return TRUE;
return FALSE;
}
void
get_vmcoreinfo_xen(off_t *offset, unsigned long *size)
{
if (offset)
*offset = offset_vmcoreinfo_xen;
if (size)
*size = size_vmcoreinfo_xen;
}
void
get_xen_crash_info(off_t *offset, unsigned long *size)
{
if (offset)
*offset = offset_xen_crash_info;
if (size)
*size = size_xen_crash_info;
}
int
has_eraseinfo(void)
{
if (offset_eraseinfo && size_eraseinfo)
return TRUE;
return FALSE;
}
void
get_eraseinfo(off_t *offset, unsigned long *size)
{
if (offset)
*offset = offset_eraseinfo;
if (size)
*size = size_eraseinfo;
}
void
set_eraseinfo(off_t offset, unsigned long size)
{
offset_eraseinfo = offset;
size_eraseinfo = size;
}
unsigned long
get_xen_p2m_mfn(void)
{
return xen_p2m_mfn;
}