forked from magneticfieldcurrency/crash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xen_hyper.c
2173 lines (1980 loc) · 62.1 KB
/
xen_hyper.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
/*
* xen_hyper.c
*
* Portions Copyright (C) 2006-2007 Fujitsu Limited
* Portions Copyright (C) 2006-2007 VA Linux Systems Japan K.K.
*
* Authors: Itsuro Oda <oda@valinux.co.jp>
* Fumihiko Kakuma <kakuma@valinux.co.jp>
*
* This file is part of Xencrash.
*
* Xencrash 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.
*
* Xencrash 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.
*
* You should have received a copy of the GNU General Public License
* along with Xencrash; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "defs.h"
#ifdef XEN_HYPERVISOR_ARCH
#include "xen_hyper_defs.h"
static void xen_hyper_schedule_init(void);
/*
* Do initialization for Xen Hyper system here.
*/
void
xen_hyper_init(void)
{
char *buf;
#if defined(X86) || defined(X86_64)
long member_offset;
#endif
#ifdef X86_64
xht->xen_virt_start = symbol_value("start");
/*
* Xen virtual mapping is aligned to 1 GiB boundary.
* Image starts no more than 1 GiB below
* beginning of virtual address space.
*/
xht->xen_virt_start &= 0xffffffffc0000000;
#endif
if (machine_type("X86_64") &&
symbol_exists("xen_phys_start") && !xen_phys_start())
error(WARNING,
"This hypervisor is relocatable; if initialization fails below, try\n"
" using the \"--xen_phys_start <address>\" command line option.\n\n");
if (symbol_exists("crashing_cpu")) {
get_symbol_data("crashing_cpu", sizeof(xht->crashing_cpu),
&xht->crashing_cpu);
} else {
xht->crashing_cpu = XEN_HYPER_PCPU_ID_INVALID;
}
machdep->get_smp_cpus();
machdep->memory_size();
if (symbol_exists("__per_cpu_offset")) {
xht->flags |= XEN_HYPER_SMP;
if((xht->__per_cpu_offset = malloc(sizeof(ulong) * XEN_HYPER_MAX_CPUS())) == NULL) {
error(FATAL, "cannot malloc __per_cpu_offset space.\n");
}
if (!readmem(symbol_value("__per_cpu_offset"), KVADDR,
xht->__per_cpu_offset, sizeof(ulong) * XEN_HYPER_MAX_CPUS(),
"__per_cpu_offset", RETURN_ON_ERROR)) {
error(FATAL, "cannot read __per_cpu_offset.\n");
}
}
#if defined(X86) || defined(X86_64)
if (symbol_exists("__per_cpu_shift")) {
xht->percpu_shift = (int)symbol_value("__per_cpu_shift");
} else if (xen_major_version() >= 3 && xen_minor_version() >= 3) {
xht->percpu_shift = 13;
} else {
xht->percpu_shift = 12;
}
member_offset = MEMBER_OFFSET("cpuinfo_x86", "x86_model_id");
buf = GETBUF(XEN_HYPER_SIZE(cpuinfo_x86));
if (xen_hyper_test_pcpu_id(XEN_HYPER_CRASHING_CPU())) {
xen_hyper_x86_fill_cpu_data(XEN_HYPER_CRASHING_CPU(), buf);
} else {
xen_hyper_x86_fill_cpu_data(xht->cpu_idxs[0], buf);
}
strncpy(xht->utsname.machine, (char *)(buf + member_offset),
sizeof(xht->utsname.machine)-1);
FREEBUF(buf);
#elif defined(IA64)
buf = GETBUF(XEN_HYPER_SIZE(cpuinfo_ia64));
if (xen_hyper_test_pcpu_id(XEN_HYPER_CRASHING_CPU())) {
xen_hyper_ia64_fill_cpu_data(XEN_HYPER_CRASHING_CPU(), buf);
} else {
xen_hyper_ia64_fill_cpu_data(xht->cpu_idxs[0], buf);
}
strncpy(xht->utsname.machine, (char *)(buf + XEN_HYPER_OFFSET(cpuinfo_ia64_vendor)),
sizeof(xht->utsname.machine)-1);
FREEBUF(buf);
#endif
#ifndef IA64
XEN_HYPER_STRUCT_SIZE_INIT(note_buf_t, "note_buf_t");
XEN_HYPER_STRUCT_SIZE_INIT(crash_note_t, "crash_note_t");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_t_core, "crash_note_t", "core");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_t_xen, "crash_note_t", "xen");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_t_xen_regs, "crash_note_t", "xen_regs");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_t_xen_info, "crash_note_t", "xen_info");
XEN_HYPER_STRUCT_SIZE_INIT(crash_note_core_t, "crash_note_core_t");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_core_t_note, "crash_note_core_t", "note");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_core_t_desc, "crash_note_core_t", "desc");
XEN_HYPER_STRUCT_SIZE_INIT(crash_note_xen_t, "crash_note_xen_t");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_xen_t_note, "crash_note_xen_t", "note");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_xen_t_desc, "crash_note_xen_t", "desc");
XEN_HYPER_STRUCT_SIZE_INIT(crash_note_xen_core_t, "crash_note_xen_core_t");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_xen_core_t_note, "crash_note_xen_core_t", "note");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_xen_core_t_desc, "crash_note_xen_core_t", "desc");
XEN_HYPER_STRUCT_SIZE_INIT(crash_note_xen_info_t, "crash_note_xen_info_t");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_xen_info_t_note, "crash_note_xen_info_t", "note");
XEN_HYPER_MEMBER_OFFSET_INIT(crash_note_xen_info_t_desc, "crash_note_xen_info_t", "desc");
XEN_HYPER_STRUCT_SIZE_INIT(crash_xen_core_t, "crash_xen_core_t");
XEN_HYPER_STRUCT_SIZE_INIT(crash_xen_info_t, "crash_xen_info_t");
XEN_HYPER_STRUCT_SIZE_INIT(xen_crash_xen_regs_t, "xen_crash_xen_regs_t");
XEN_HYPER_STRUCT_SIZE_INIT(ELF_Prstatus,"ELF_Prstatus");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_info, "ELF_Prstatus", "pr_info");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_cursig, "ELF_Prstatus", "pr_cursig");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_sigpend, "ELF_Prstatus", "pr_sigpend");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_sighold, "ELF_Prstatus", "pr_sighold");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_pid, "ELF_Prstatus", "pr_pid");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_ppid, "ELF_Prstatus", "pr_ppid");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_pgrp, "ELF_Prstatus", "pr_pgrp");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_sid, "ELF_Prstatus", "pr_sid");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_utime, "ELF_Prstatus", "pr_utime");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_stime, "ELF_Prstatus", "pr_stime");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_cutime, "ELF_Prstatus", "pr_cutime");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_cstime, "ELF_Prstatus", "pr_cstime");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_reg, "ELF_Prstatus", "pr_reg");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Prstatus_pr_fpvalid, "ELF_Prstatus", "pr_fpvalid");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Timeval_tv_sec, "ELF_Timeval", "tv_sec");
XEN_HYPER_MEMBER_OFFSET_INIT(ELF_Timeval_tv_usec, "ELF_Timeval", "tv_usec");
XEN_HYPER_STRUCT_SIZE_INIT(ELF_Signifo,"ELF_Signifo");
XEN_HYPER_STRUCT_SIZE_INIT(ELF_Gregset,"ELF_Gregset");
XEN_HYPER_STRUCT_SIZE_INIT(ELF_Timeval,"ELF_Timeval");
#endif
XEN_HYPER_STRUCT_SIZE_INIT(domain, "domain");
XEN_HYPER_STRUCT_SIZE_INIT(vcpu, "vcpu");
#ifndef IA64
XEN_HYPER_STRUCT_SIZE_INIT(cpu_info, "cpu_info");
#endif
XEN_HYPER_STRUCT_SIZE_INIT(cpu_user_regs, "cpu_user_regs");
xht->idle_vcpu_size = get_array_length("idle_vcpu", NULL, 0);
xht->idle_vcpu_array = (ulong *)malloc(xht->idle_vcpu_size * sizeof(ulong));
if (xht->idle_vcpu_array == NULL) {
error(FATAL, "cannot malloc idle_vcpu_array space.\n");
}
if (!readmem(symbol_value("idle_vcpu"), KVADDR, xht->idle_vcpu_array,
xht->idle_vcpu_size * sizeof(ulong), "idle_vcpu_array",
RETURN_ON_ERROR)) {
error(FATAL, "cannot read idle_vcpu array.\n");
}
/*
* Do some initialization.
*/
#ifndef IA64
xen_hyper_dumpinfo_init();
#endif
xhmachdep->pcpu_init();
xen_hyper_domain_init();
xen_hyper_vcpu_init();
xen_hyper_misc_init();
/*
* xen_hyper_post_init() have to be called after all initialize
* functions finished.
*/
xen_hyper_post_init();
}
/*
* Do initialization for Domain of Xen Hyper system here.
*/
void
xen_hyper_domain_init(void)
{
XEN_HYPER_MEMBER_OFFSET_INIT(domain_domain_id, "domain", "domain_id");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_tot_pages, "domain", "tot_pages");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_max_pages, "domain", "max_pages");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_xenheap_pages, "domain", "xenheap_pages");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_shared_info, "domain", "shared_info");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_sched_priv, "domain", "sched_priv");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_next_in_list, "domain", "next_in_list");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_domain_flags, "domain", "domain_flags");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_evtchn, "domain", "evtchn");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_is_hvm, "domain", "is_hvm");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_guest_type, "domain", "guest_type");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_is_privileged, "domain", "is_privileged");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_debugger_attached, "domain", "debugger_attached");
/*
* Will be removed in Xen 4.4 (hg ae9b223a675d),
* need to check that with XEN_HYPER_VALID_MEMBER() before using
*/
XEN_HYPER_MEMBER_OFFSET_INIT(domain_is_polling, "domain", "is_polling");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_is_dying, "domain", "is_dying");
/*
* With Xen 4.2.5 is_paused_by_controller changed to
* controller_pause_count.
*/
XEN_HYPER_MEMBER_OFFSET_INIT(domain_is_paused_by_controller, "domain", "is_paused_by_controller");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_controller_pause_count, "domain", "controller_pause_count");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_is_shutting_down, "domain", "is_shutting_down");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_is_shut_down, "domain", "is_shut_down");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_vcpu, "domain", "vcpu");
XEN_HYPER_MEMBER_SIZE_INIT(domain_vcpu, "domain", "vcpu");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_max_vcpus, "domain", "max_vcpus");
XEN_HYPER_MEMBER_OFFSET_INIT(domain_arch, "domain", "arch");
XEN_HYPER_STRUCT_SIZE_INIT(arch_shared_info, "arch_shared_info");
XEN_HYPER_MEMBER_OFFSET_INIT(arch_shared_info_max_pfn, "arch_shared_info", "max_pfn");
XEN_HYPER_MEMBER_OFFSET_INIT(arch_shared_info_pfn_to_mfn_frame_list_list, "arch_shared_info", "pfn_to_mfn_frame_list_list");
XEN_HYPER_MEMBER_OFFSET_INIT(arch_shared_info_nmi_reason, "arch_shared_info", "nmi_reason");
XEN_HYPER_STRUCT_SIZE_INIT(shared_info, "shared_info");
XEN_HYPER_MEMBER_OFFSET_INIT(shared_info_vcpu_info, "shared_info", "vcpu_info");
XEN_HYPER_MEMBER_OFFSET_INIT(shared_info_evtchn_pending, "shared_info", "evtchn_pending");
XEN_HYPER_MEMBER_OFFSET_INIT(shared_info_evtchn_mask, "shared_info", "evtchn_mask");
XEN_HYPER_MEMBER_OFFSET_INIT(shared_info_arch, "shared_info", "arch");
XEN_HYPER_STRUCT_SIZE_INIT(arch_domain, "arch_domain");
#ifdef IA64
XEN_HYPER_MEMBER_OFFSET_INIT(arch_domain_mm, "arch_domain", "mm");
XEN_HYPER_STRUCT_SIZE_INIT(mm_struct, "mm_struct");
XEN_HYPER_MEMBER_OFFSET_INIT(mm_struct_pgd, "mm_struct", "pgd");
#endif
if((xhdt->domain_struct = malloc(XEN_HYPER_SIZE(domain))) == NULL) {
error(FATAL, "cannot malloc domain struct space.\n");
}
if((xhdt->domain_struct_verify = malloc(XEN_HYPER_SIZE(domain))) == NULL) {
error(FATAL, "cannot malloc domain struct space to verification.\n");
}
xen_hyper_refresh_domain_context_space();
xhdt->flags |= XEN_HYPER_DOMAIN_F_INIT;
}
/*
* Do initialization for vcpu of Xen Hyper system here.
*/
void
xen_hyper_vcpu_init(void)
{
XEN_HYPER_STRUCT_SIZE_INIT(timer, "timer");
XEN_HYPER_MEMBER_OFFSET_INIT(timer_expires, "timer", "expires");
XEN_HYPER_MEMBER_OFFSET_INIT(timer_cpu, "timer", "cpu");
XEN_HYPER_MEMBER_OFFSET_INIT(timer_function, "timer", "function");
XEN_HYPER_MEMBER_OFFSET_INIT(timer_data, "timer", "data");
XEN_HYPER_MEMBER_OFFSET_INIT(timer_heap_offset, "timer", "heap_offset");
XEN_HYPER_MEMBER_OFFSET_INIT(timer_killed, "timer", "killed");
XEN_HYPER_STRUCT_SIZE_INIT(vcpu_runstate_info, "vcpu_runstate_info");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_runstate_info_state, "vcpu_runstate_info", "state");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_runstate_info_state_entry_time, "vcpu_runstate_info", "state_entry_time");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_runstate_info_time, "vcpu_runstate_info", "time");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_vcpu_id, "vcpu", "vcpu_id");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_processor, "vcpu", "processor");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_vcpu_info, "vcpu", "vcpu_info");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_domain, "vcpu", "domain");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_next_in_list, "vcpu", "next_in_list");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_timer, "vcpu", "timer");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_sleep_tick, "vcpu", "sleep_tick");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_poll_timer, "vcpu", "poll_timer");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_sched_priv, "vcpu", "sched_priv");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_runstate, "vcpu", "runstate");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_runstate_guest, "vcpu", "runstate_guest");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_vcpu_flags, "vcpu", "vcpu_flags");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_pause_count, "vcpu", "pause_count");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_virq_to_evtchn, "vcpu", "virq_to_evtchn");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_cpu_affinity, "vcpu", "cpu_affinity");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_nmi_addr, "vcpu", "nmi_addr");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_vcpu_dirty_cpumask, "vcpu", "vcpu_dirty_cpumask");
XEN_HYPER_MEMBER_OFFSET_INIT(vcpu_arch, "vcpu", "arch");
#ifdef IA64
XEN_HYPER_ASSIGN_OFFSET(vcpu_thread_ksp) =
MEMBER_OFFSET("vcpu", "arch") + MEMBER_OFFSET("arch_vcpu", "_thread") +
MEMBER_OFFSET("thread_struct", "ksp");
#endif
if((xhvct->vcpu_struct = malloc(XEN_HYPER_SIZE(vcpu))) == NULL) {
error(FATAL, "cannot malloc vcpu struct space.\n");
}
if((xhvct->vcpu_struct_verify = malloc(XEN_HYPER_SIZE(vcpu))) == NULL) {
error(FATAL, "cannot malloc vcpu struct space to verification.\n");
}
xen_hyper_refresh_vcpu_context_space();
xhvct->flags |= XEN_HYPER_VCPU_F_INIT;
xhvct->idle_vcpu = symbol_value("idle_vcpu");
}
/*
* Do initialization for pcpu of Xen Hyper system here.
*/
#if defined(X86) || defined(X86_64)
void
xen_hyper_x86_pcpu_init(void)
{
ulong cpu_info;
ulong init_tss_base, init_tss;
ulong sp;
struct xen_hyper_pcpu_context *pcc;
char *buf, *bp;
int i, cpuid;
int flag;
XEN_HYPER_MEMBER_OFFSET_INIT(cpu_info_guest_cpu_user_regs, "cpu_info", "guest_cpu_user_regs");
XEN_HYPER_MEMBER_OFFSET_INIT(cpu_info_processor_id, "cpu_info", "processor_id");
XEN_HYPER_MEMBER_OFFSET_INIT(cpu_info_current_vcpu, "cpu_info", "current_vcpu");
if((xhpct->pcpu_struct = malloc(XEN_HYPER_SIZE(cpu_info))) == NULL) {
error(FATAL, "cannot malloc pcpu struct space.\n");
}
/* get physical cpu context */
xen_hyper_alloc_pcpu_context_space(XEN_HYPER_MAX_CPUS());
if (symbol_exists("per_cpu__init_tss")) {
init_tss_base = symbol_value("per_cpu__init_tss");
flag = TRUE;
} else {
init_tss_base = symbol_value("init_tss");
flag = FALSE;
}
buf = GETBUF(XEN_HYPER_SIZE(tss_struct));
for_cpu_indexes(i, cpuid)
{
if (flag)
init_tss = xen_hyper_per_cpu(init_tss_base, cpuid);
else
init_tss = init_tss_base +
XEN_HYPER_SIZE(tss_struct) * cpuid;
if (!readmem(init_tss, KVADDR, buf,
XEN_HYPER_SIZE(tss_struct), "init_tss", RETURN_ON_ERROR)) {
error(FATAL, "cannot read init_tss.\n");
}
if (machine_type("X86")) {
sp = ULONG(buf + XEN_HYPER_OFFSET(tss_struct_esp0));
} else if (machine_type("X86_64")) {
sp = ULONG(buf + XEN_HYPER_OFFSET(tss_struct_rsp0));
} else
sp = 0;
cpu_info = XEN_HYPER_GET_CPU_INFO(sp);
if (CRASHDEBUG(1)) {
fprintf(fp, "sp=%lx, cpu_info=%lx\n", sp, cpu_info);
}
if(!(bp = xen_hyper_read_pcpu(cpu_info))) {
error(FATAL, "cannot read cpu_info.\n");
}
pcc = &xhpct->context_array[cpuid];
xen_hyper_store_pcpu_context(pcc, cpu_info, bp);
xen_hyper_store_pcpu_context_tss(pcc, init_tss, buf);
}
FREEBUF(buf);
}
#elif defined(IA64)
void
xen_hyper_ia64_pcpu_init(void)
{
struct xen_hyper_pcpu_context *pcc;
int i, cpuid;
/* get physical cpu context */
xen_hyper_alloc_pcpu_context_space(XEN_HYPER_MAX_CPUS());
for_cpu_indexes(i, cpuid)
{
pcc = &xhpct->context_array[cpuid];
pcc->processor_id = cpuid;
}
}
#endif
/*
* Do initialization for some miscellaneous thing
* of Xen Hyper system here.
*/
void
xen_hyper_misc_init(void)
{
XEN_HYPER_STRUCT_SIZE_INIT(schedule_data, "schedule_data");
XEN_HYPER_MEMBER_OFFSET_INIT(schedule_data_schedule_lock, "schedule_data", "schedule_lock");
XEN_HYPER_MEMBER_OFFSET_INIT(schedule_data_curr, "schedule_data", "curr");
if (MEMBER_EXISTS("schedule_data", "idle"))
XEN_HYPER_MEMBER_OFFSET_INIT(schedule_data_idle, "schedule_data", "idle");
XEN_HYPER_MEMBER_OFFSET_INIT(schedule_data_sched_priv, "schedule_data", "sched_priv");
XEN_HYPER_MEMBER_OFFSET_INIT(schedule_data_s_timer, "schedule_data", "s_timer");
XEN_HYPER_MEMBER_OFFSET_INIT(schedule_data_tick, "schedule_data", "tick");
XEN_HYPER_STRUCT_SIZE_INIT(scheduler, "scheduler");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_name, "scheduler", "name");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_opt_name, "scheduler", "opt_name");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_sched_id, "scheduler", "sched_id");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_init, "scheduler", "init");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_tick, "scheduler", "tick");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_init_vcpu, "scheduler", "init_vcpu");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_destroy_domain, "scheduler", "destroy_domain");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_sleep, "scheduler", "sleep");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_wake, "scheduler", "wake");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_set_affinity, "scheduler", "set_affinity");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_do_schedule, "scheduler", "do_schedule");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_adjust, "scheduler", "adjust");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_dump_settings, "scheduler", "dump_settings");
XEN_HYPER_MEMBER_OFFSET_INIT(scheduler_dump_cpu_state, "scheduler", "dump_cpu_state");
xen_hyper_schedule_init();
}
/*
* Do initialization for scheduler of Xen Hyper system here.
*/
#define XEN_HYPER_SCHEDULER_NAME 1024
static int section_size(char *start_section, char *end_section)
{
ulong sp_start, sp_end;
sp_start = symbol_value(start_section);
sp_end = symbol_value(end_section);
return (sp_end - sp_start) / sizeof(long);
}
static void
xen_hyper_schedule_init(void)
{
ulong addr, opt_sched, schedulers, opt_name;
long scheduler_opt_name;
long *schedulers_buf;
int nr_schedulers;
struct xen_hyper_sched_context *schc;
char *buf;
char opt_name_buf[XEN_HYPER_OPT_SCHED_SIZE];
int i, cpuid, flag;
char *sp_name;
/* get scheduler information */
if((xhscht->scheduler_struct =
malloc(XEN_HYPER_SIZE(scheduler))) == NULL) {
error(FATAL, "cannot malloc scheduler struct space.\n");
}
buf = GETBUF(XEN_HYPER_SCHEDULER_NAME);
scheduler_opt_name = XEN_HYPER_OFFSET(scheduler_opt_name);
if (symbol_exists("ops")) {
if (!readmem(symbol_value("ops") + scheduler_opt_name, KVADDR,
&opt_sched, sizeof(ulong), "ops.opt_name",
RETURN_ON_ERROR)) {
error(FATAL, "cannot read ops.opt_name.\n");
}
} else {
opt_sched = symbol_value("opt_sched");
}
if (!readmem(opt_sched, KVADDR, xhscht->opt_sched,
XEN_HYPER_OPT_SCHED_SIZE, "opt_sched,", RETURN_ON_ERROR)) {
error(FATAL, "cannot read opt_sched,.\n");
}
/* symbol exists since Xen 4.7 */
if (symbol_exists("__start_schedulers_array")) {
sp_name = "__start_schedulers_array";
nr_schedulers = section_size("__start_schedulers_array",
"__end_schedulers_array");
} else {
sp_name = "schedulers";
nr_schedulers = get_array_length("schedulers", 0, 0);
}
schedulers_buf = (long *)GETBUF(nr_schedulers * sizeof(long));
schedulers = symbol_value(sp_name);
addr = schedulers;
while (xhscht->name == NULL) {
if (!readmem(addr, KVADDR, schedulers_buf,
sizeof(long) * nr_schedulers,
"schedulers", RETURN_ON_ERROR)) {
error(FATAL, "cannot read schedulers.\n");
}
for (i = 0; i < nr_schedulers; i++) {
if (schedulers_buf[i] == 0) {
error(FATAL, "schedule data not found.\n");
}
if (!readmem(schedulers_buf[i], KVADDR,
xhscht->scheduler_struct, XEN_HYPER_SIZE(scheduler),
"scheduler", RETURN_ON_ERROR)) {
error(FATAL, "cannot read scheduler.\n");
}
opt_name = ULONG(xhscht->scheduler_struct +
scheduler_opt_name);
if (!readmem(opt_name, KVADDR, opt_name_buf,
XEN_HYPER_OPT_SCHED_SIZE, "opt_name", RETURN_ON_ERROR)) {
error(FATAL, "cannot read opt_name.\n");
}
if (strncmp(xhscht->opt_sched, opt_name_buf,
XEN_HYPER_OPT_SCHED_SIZE))
continue;
xhscht->scheduler = schedulers_buf[i];
xhscht->sched_id = INT(xhscht->scheduler_struct +
XEN_HYPER_OFFSET(scheduler_sched_id));
addr = ULONG(xhscht->scheduler_struct +
XEN_HYPER_OFFSET(scheduler_name));
if (!readmem(addr, KVADDR, buf, XEN_HYPER_SCHEDULER_NAME,
"scheduler_name", RETURN_ON_ERROR)) {
error(FATAL, "cannot read scheduler_name.\n");
}
if (strlen(buf) >= XEN_HYPER_SCHEDULER_NAME) {
error(FATAL, "cannot read scheduler_name.\n");
}
if((xhscht->name = malloc(strlen(buf) + 1)) == NULL) {
error(FATAL, "cannot malloc scheduler_name space.\n");
}
BZERO(xhscht->name, strlen(buf) + 1);
BCOPY(buf, xhscht->name, strlen(buf));
break;
}
addr += sizeof(long) * nr_schedulers;
}
FREEBUF(buf);
FREEBUF(schedulers_buf);
/* get schedule_data information */
if((xhscht->sched_context_array =
malloc(sizeof(struct xen_hyper_sched_context) * XEN_HYPER_MAX_CPUS())) == NULL) {
error(FATAL, "cannot malloc xen_hyper_sched_context struct space.\n");
}
BZERO(xhscht->sched_context_array,
sizeof(struct xen_hyper_sched_context) * XEN_HYPER_MAX_CPUS());
buf = GETBUF(XEN_HYPER_SIZE(schedule_data));
if (symbol_exists("per_cpu__schedule_data")) {
addr = symbol_value("per_cpu__schedule_data");
flag = TRUE;
} else {
addr = symbol_value("schedule_data");
flag = FALSE;
}
for_cpu_indexes(i, cpuid)
{
schc = &xhscht->sched_context_array[cpuid];
if (flag) {
schc->schedule_data =
xen_hyper_per_cpu(addr, i);
} else {
schc->schedule_data = addr +
XEN_HYPER_SIZE(schedule_data) * i;
}
if (!readmem(schc->schedule_data,
KVADDR, buf, XEN_HYPER_SIZE(schedule_data),
"schedule_data", RETURN_ON_ERROR)) {
error(FATAL, "cannot read schedule_data.\n");
}
schc->cpu_id = cpuid;
schc->curr = ULONG(buf + XEN_HYPER_OFFSET(schedule_data_curr));
if (MEMBER_EXISTS("schedule_data", "idle"))
schc->idle = ULONG(buf + XEN_HYPER_OFFSET(schedule_data_idle));
else
schc->idle = xht->idle_vcpu_array[cpuid];
schc->sched_priv =
ULONG(buf + XEN_HYPER_OFFSET(schedule_data_sched_priv));
if (XEN_HYPER_VALID_MEMBER(schedule_data_tick))
schc->tick = ULONG(buf + XEN_HYPER_OFFSET(schedule_data_tick));
}
FREEBUF(buf);
}
/*
* This should be called after all initailize process finished.
*/
void
xen_hyper_post_init(void)
{
struct xen_hyper_pcpu_context *pcc;
int i, cpuid;
/* set current vcpu to pcpu context */
for_cpu_indexes(i, cpuid)
{
pcc = &xhpct->context_array[cpuid];
if (!pcc->current_vcpu) {
pcc->current_vcpu =
xen_hyper_get_active_vcpu_from_pcpuid(cpuid);
}
}
/* set pcpu last */
if (!(xhpct->last =
xen_hyper_id_to_pcpu_context(XEN_HYPER_CRASHING_CPU()))) {
xhpct->last = &xhpct->context_array[xht->cpu_idxs[0]];
}
/* set vcpu last */
if (xhpct->last) {
xhvct->last =
xen_hyper_vcpu_to_vcpu_context(xhpct->last->current_vcpu);
/* set crashing vcpu */
xht->crashing_vcc = xhvct->last;
}
if (!xhvct->last) {
xhvct->last = xhvct->vcpu_context_arrays->context_array;
}
/* set domain last */
if (xhvct->last) {
xhdt->last =
xen_hyper_domain_to_domain_context(xhvct->last->domain);
}
if (!xhdt->last) {
xhdt->last = xhdt->context_array;
}
}
/*
* Do initialization for dump information here.
*/
void
xen_hyper_dumpinfo_init(void)
{
Elf32_Nhdr *note;
char *buf, *bp, *np, *upp;
char *nccp, *xccp;
ulong addr;
long size;
int i, cpuid, samp_cpuid;
/*
* NOTE kakuma: It is not clear that what kind of
* a elf note format each one of the xen uses.
* So, we decide it confirming whether a symbol exists.
*/
if (STRUCT_EXISTS("note_buf_t"))
xhdit->note_ver = XEN_HYPER_ELF_NOTE_V1;
else if (STRUCT_EXISTS("crash_note_xen_t"))
xhdit->note_ver = XEN_HYPER_ELF_NOTE_V2;
else if (STRUCT_EXISTS("crash_xen_core_t")) {
if (STRUCT_EXISTS("crash_note_xen_core_t"))
xhdit->note_ver = XEN_HYPER_ELF_NOTE_V3;
else
xhdit->note_ver = XEN_HYPER_ELF_NOTE_V4;
} else {
error(WARNING, "found unsupported elf note format while checking of xen dumpinfo.\n");
return;
}
if (!xen_hyper_test_pcpu_id(XEN_HYPER_CRASHING_CPU())) {
error(WARNING, "crashing_cpu not found.\n");
return;
}
/* allocate a context area */
size = sizeof(struct xen_hyper_dumpinfo_context) * machdep->get_smp_cpus();
if((xhdit->context_array = malloc(size)) == NULL) {
error(FATAL, "cannot malloc dumpinfo table context space.\n");
}
BZERO(xhdit->context_array, size);
size = sizeof(struct xen_hyper_dumpinfo_context_xen_core) * machdep->get_smp_cpus();
if((xhdit->context_xen_core_array = malloc(size)) == NULL) {
error(FATAL, "cannot malloc dumpinfo table context_xen_core_array space.\n");
}
BZERO(xhdit->context_xen_core_array, size);
if (symbol_exists("per_cpu__crash_notes"))
addr = symbol_value("per_cpu__crash_notes");
else
get_symbol_data("crash_notes", sizeof(ulong), &addr);
for (i = 0; i < machdep->get_smp_cpus(); i++) {
ulong addr_notes;
if (symbol_exists("per_cpu__crash_notes"))
addr_notes = xen_hyper_per_cpu(addr, i);
else
addr_notes = addr + i * STRUCT_SIZE("crash_note_range_t") +
MEMBER_OFFSET("crash_note_range_t", "start");
if (xhdit->note_ver == XEN_HYPER_ELF_NOTE_V4) {
if (!readmem(addr_notes, KVADDR, &(xhdit->context_array[i].note),
sizeof(ulong), "crash_notes", RETURN_ON_ERROR)) {
error(WARNING, "cannot read crash_notes.\n");
return;
}
} else {
xhdit->context_array[i].note = addr_notes;
}
}
if (xhdit->note_ver == XEN_HYPER_ELF_NOTE_V1) {
xhdit->note_size = XEN_HYPER_SIZE(note_buf_t);
} else if (xhdit->note_ver == XEN_HYPER_ELF_NOTE_V4) {
xhdit->note_size = XEN_HYPER_ELF_NOTE_V4_NOTE_SIZE;
} else {
xhdit->note_size = XEN_HYPER_SIZE(crash_note_t);
}
/* read a sample note */
buf = GETBUF(xhdit->note_size);
if (xhdit->note_ver == XEN_HYPER_ELF_NOTE_V4)
samp_cpuid = xht->cpu_idxs[0];
else
samp_cpuid = XEN_HYPER_CRASHING_CPU();
xhdit->xen_info_cpu = samp_cpuid;
if (!xen_hyper_fill_elf_notes(xhdit->context_array[samp_cpuid].note,
buf, XEN_HYPER_ELF_NOTE_FILL_T_NOTE)) {
error(FATAL, "cannot read crash_notes.\n");
}
bp = buf;
/* Get elf format information for each version. */
switch (xhdit->note_ver) {
case XEN_HYPER_ELF_NOTE_V1:
/* core data */
note = (Elf32_Nhdr *)bp;
np = bp + sizeof(Elf32_Nhdr);
upp = np + note->n_namesz;
upp = (char *)roundup((ulong)upp, 4);
xhdit->core_offset = (Elf_Word)((ulong)upp - (ulong)note);
note = (Elf32_Nhdr *)(upp + note->n_descsz);
/* cr3 data */
np = (char *)note + sizeof(Elf32_Nhdr);
upp = np + note->n_namesz;
upp = (char *)roundup((ulong)upp, 4);
upp = upp + note->n_descsz;
xhdit->core_size = upp - bp;
break;
case XEN_HYPER_ELF_NOTE_V2:
/* core data */
xhdit->core_offset = XEN_HYPER_OFFSET(crash_note_core_t_desc);
xhdit->core_size = XEN_HYPER_SIZE(crash_note_core_t);
/* xen core */
xhdit->xen_info_offset = XEN_HYPER_OFFSET(crash_note_xen_t_desc);
xhdit->xen_info_size = XEN_HYPER_SIZE(crash_note_xen_t);
break;
case XEN_HYPER_ELF_NOTE_V3:
/* core data */
xhdit->core_offset = XEN_HYPER_OFFSET(crash_note_core_t_desc);
xhdit->core_size = XEN_HYPER_SIZE(crash_note_core_t);
/* xen core */
xhdit->xen_core_offset = XEN_HYPER_OFFSET(crash_note_xen_core_t_desc);
xhdit->xen_core_size = XEN_HYPER_SIZE(crash_note_xen_core_t);
/* xen info */
xhdit->xen_info_offset = XEN_HYPER_OFFSET(crash_note_xen_info_t_desc);
xhdit->xen_info_size = XEN_HYPER_SIZE(crash_note_xen_info_t);
break;
case XEN_HYPER_ELF_NOTE_V4:
/* core data */
note = (Elf32_Nhdr *)bp;
np = bp + sizeof(Elf32_Nhdr);
upp = np + note->n_namesz;
upp = (char *)roundup((ulong)upp, 4);
xhdit->core_offset = (Elf_Word)((ulong)upp - (ulong)note);
upp = upp + note->n_descsz;
xhdit->core_size = (Elf_Word)((ulong)upp - (ulong)note);
if (XEN_HYPER_ELF_NOTE_V4_NOTE_SIZE < xhdit->core_size + 32) {
error(WARNING, "note size is assumed on crash is incorrect.(core data)\n");
return;
}
/* xen core */
note = (Elf32_Nhdr *)upp;
np = (char *)note + sizeof(Elf32_Nhdr);
upp = np + note->n_namesz;
upp = (char *)roundup((ulong)upp, 4);
xhdit->xen_core_offset = (Elf_Word)((ulong)upp - (ulong)note);
upp = upp + note->n_descsz;
xhdit->xen_core_size = (Elf_Word)((ulong)upp - (ulong)note);
if (XEN_HYPER_ELF_NOTE_V4_NOTE_SIZE <
xhdit->core_size + xhdit->xen_core_size + 32) {
error(WARNING, "note size is assumed on crash is incorrect.(xen core)\n");
return;
}
/* xen info */
note = (Elf32_Nhdr *)upp;
np = (char *)note + sizeof(Elf32_Nhdr);
upp = np + note->n_namesz;
upp = (char *)roundup((ulong)upp, 4);
xhdit->xen_info_offset = (Elf_Word)((ulong)upp - (ulong)note);
upp = upp + note->n_descsz;
xhdit->xen_info_size = (Elf_Word)((ulong)upp - (ulong)note);
if (XEN_HYPER_ELF_NOTE_V4_NOTE_SIZE <
xhdit->core_size + xhdit->xen_core_size + xhdit->xen_info_size) {
error(WARNING, "note size is assumed on crash is incorrect.(xen info)\n");
return;
}
xhdit->note_size = xhdit->core_size + xhdit->xen_core_size + xhdit->xen_info_size;
break;
default:
error(FATAL, "logic error in cheking elf note format occurs.\n");
}
/* fill xen info context. */
if (xhdit->note_ver >= XEN_HYPER_ELF_NOTE_V3) {
if((xhdit->crash_note_xen_info_ptr =
malloc(xhdit->xen_info_size)) == NULL) {
error(FATAL, "cannot malloc dumpinfo table "
"crash_note_xen_info_ptr space.\n");
}
memcpy(xhdit->crash_note_xen_info_ptr,
bp + xhdit->core_size + xhdit->xen_core_size,
xhdit->xen_info_size);
xhdit->context_xen_info.note =
xhdit->context_array[samp_cpuid].note +
xhdit->core_size + xhdit->xen_core_size;
xhdit->context_xen_info.pcpu_id = samp_cpuid;
xhdit->context_xen_info.crash_xen_info_ptr =
xhdit->crash_note_xen_info_ptr + xhdit->xen_info_offset;
}
/* allocate note core */
size = xhdit->core_size * XEN_HYPER_NR_PCPUS();
if(!(xhdit->crash_note_core_array = malloc(size))) {
error(FATAL, "cannot malloc crash_note_core_array space.\n");
}
nccp = xhdit->crash_note_core_array;
BZERO(nccp, size);
xccp = NULL;
/* allocate xen core */
if (xhdit->note_ver >= XEN_HYPER_ELF_NOTE_V2) {
size = xhdit->xen_core_size * XEN_HYPER_NR_PCPUS();
if(!(xhdit->crash_note_xen_core_array = malloc(size))) {
error(FATAL, "cannot malloc dumpinfo table "
"crash_note_xen_core_array space.\n");
}
xccp = xhdit->crash_note_xen_core_array;
BZERO(xccp, size);
}
/* fill a context. */
for_cpu_indexes(i, cpuid)
{
/* fill core context. */
addr = xhdit->context_array[cpuid].note;
if (!xen_hyper_fill_elf_notes(addr, nccp,
XEN_HYPER_ELF_NOTE_FILL_T_CORE)) {
error(FATAL, "cannot read elf note core.\n");
}
xhdit->context_array[cpuid].pcpu_id = cpuid;
xhdit->context_array[cpuid].ELF_Prstatus_ptr =
nccp + xhdit->core_offset;
xhdit->context_array[cpuid].pr_reg_ptr =
nccp + xhdit->core_offset +
XEN_HYPER_OFFSET(ELF_Prstatus_pr_reg);
/* Is there xen core data? */
if (xhdit->note_ver < XEN_HYPER_ELF_NOTE_V2) {
nccp += xhdit->core_size;
continue;
}
if (xhdit->note_ver == XEN_HYPER_ELF_NOTE_V2 &&
cpuid != samp_cpuid) {
xccp += xhdit->xen_core_size;
nccp += xhdit->core_size;
continue;
}
/* fill xen core context, in case of more elf note V2. */
xhdit->context_xen_core_array[cpuid].note =
xhdit->context_array[cpuid].note +
xhdit->core_size;
xhdit->context_xen_core_array[cpuid].pcpu_id = cpuid;
xhdit->context_xen_core_array[cpuid].crash_xen_core_ptr =
xccp + xhdit->xen_core_offset;
if (!xen_hyper_fill_elf_notes(xhdit->context_xen_core_array[cpuid].note,
xccp, XEN_HYPER_ELF_NOTE_FILL_T_XEN_CORE)) {
error(FATAL, "cannot read elf note xen core.\n");
}
xccp += xhdit->xen_core_size;
nccp += xhdit->core_size;
}
FREEBUF(buf);
}
/*
* Get dump information context from physical cpu id.
*/
struct xen_hyper_dumpinfo_context *
xen_hyper_id_to_dumpinfo_context(uint id)
{
if (!xen_hyper_test_pcpu_id(id))
return NULL;
return &xhdit->context_array[id];
}
/*
* Get dump information context from ELF Note address.
*/
struct xen_hyper_dumpinfo_context *
xen_hyper_note_to_dumpinfo_context(ulong note)
{
int i;
for (i = 0; i < XEN_HYPER_MAX_CPUS(); i++) {
if (note == xhdit->context_array[i].note) {
return &xhdit->context_array[i];
}
}
return NULL;
}
/*
* Fill ELF Notes header here.
* This assume that variable note has a top address of an area for
* specified type.
*/
char *
xen_hyper_fill_elf_notes(ulong note, char *note_buf, int type)
{
long size;
ulong rp = note;
if (type == XEN_HYPER_ELF_NOTE_FILL_T_NOTE)
size = xhdit->note_size;
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_CORE)
size = xhdit->core_size;
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_XEN_CORE)
size = xhdit->xen_core_size;
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_XEN_CORE_M)
size = xhdit->core_size + xhdit->xen_core_size;
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_PRS)
size = XEN_HYPER_SIZE(ELF_Prstatus);
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_XEN_REGS)
size = XEN_HYPER_SIZE(xen_crash_xen_regs_t);
else
return NULL;
if (!readmem(rp, KVADDR, note_buf, size,
"note_buf_t or crash_note_t", RETURN_ON_ERROR)) {
if (type == XEN_HYPER_ELF_NOTE_FILL_T_NOTE)
error(WARNING, "cannot fill note_buf_t or crash_note_t.\n");
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_CORE)
error(WARNING, "cannot fill note core.\n");
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_XEN_CORE)
error(WARNING, "cannot fill note xen core.\n");
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_XEN_CORE_M)
error(WARNING, "cannot fill note core & xen core.\n");
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_PRS)
error(WARNING, "cannot fill ELF_Prstatus.\n");
else if (type == XEN_HYPER_ELF_NOTE_FILL_T_XEN_REGS)
error(WARNING, "cannot fill xen_crash_xen_regs_t.\n");
return NULL;
}
return note_buf;
}
/*
* Get domain status.
*/
ulong
xen_hyper_domain_state(struct xen_hyper_domain_context *dc)
{
if (ACTIVE()) {
if (xen_hyper_read_domain_verify(dc->domain) == NULL) {
return XEN_HYPER_DOMF_ERROR;
}
}
return dc->domain_flags;
}
/*
* Allocate domain context space.
*/
void
xen_hyper_refresh_domain_context_space(void)
{
char *domain_struct;
ulong domain, next, dom_xen, dom_io, idle_vcpu;
struct xen_hyper_domain_context *dc;
struct xen_hyper_domain_context *dom0;
int i;
if ((xhdt->flags & XEN_HYPER_DOMAIN_F_INIT) && !ACTIVE()) {
return;
}
XEN_HYPER_RUNNING_DOMAINS() = XEN_HYPER_NR_DOMAINS() =
xen_hyper_get_domains();
xen_hyper_alloc_domain_context_space(XEN_HYPER_NR_DOMAINS());
dc = xhdt->context_array;