00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 typedef DOUBLE *
PDOUBLE;
00072
00073
#ifdef ROS_DEBUG
00074
#include "ntrtlp.h"
00075
#define READ_ULONG(addr,dest) dest = (*((PULONG)(addr)))
00076
#define READ_DOUBLE(addr,dest) dest = (*((PDOUBLE)(addr)))
00077
#endif
00078
00079
#ifdef _IMAGEHLP_SOURCE_
00080
#define FUNCTION_ENTRY_IS_IMAGE_STYLE
00081
#define NOT_IMAGEHLP(E)
00082
#else
00083 #define NOT_IMAGEHLP(E) E
00084
#endif
00085
00086
#ifdef KERNEL_DEBUGGER
00087
#define FUNCTION_ENTRY_IS_IMAGE_STYLE
00088
#define RtlVirtualUnwind VirtualUnwind
00089
#endif
00090
00091
00092
00093
00094
00095
00096 typedef enum _INSTR_CLASS {
00097
InstrIgnore,
00098
InstrMFLR,
00099
InstrMFCR,
00100
InstrSTW,
00101
InstrSTWU,
00102
InstrSTWUr12,
00103
InstrSTFD,
00104
InstrMR,
00105
InstrMRr12,
00106
InstrMRfwd,
00107
InstrADDIr12,
00108
InstrADDIfwd,
00109
InstrSaveCode,
00110
InstrRestoreCode,
00111
InstrGlue,
00112
InstrBLR,
00113
InstrTOCRestore,
00114
InstrSetEstablisher
00115 }
INSTR_CLASS;
00116
00117
00118
00119
00120
00121
00122 typedef struct _MILLICODE_INFO {
00123 ULONG
TargetPc;
00124 PRUNTIME_FUNCTION
FunctionEntry;
00125 }
MILLICODE_INFO, *
PMILLICODE_INFO;
00126
00127
00128
00129
00130
00131 typedef enum _UNWIND_INTENT {
00132
UnwindForward,
00133
UnwindR12,
00134
UnwindReverse,
00135
UnwindReverseR12
00136 }
UNWIND_INTENT;
00137
00138
00139
00140
00141
00142
00143 typedef struct _ITERATOR {
00144 ULONG
BeginPc;
00145 ULONG
EndPc;
00146 LONG
Increment;
00147 UNWIND_INTENT Intent;
00148 }
ITERATOR, *
PITERATOR;
00149
00150 #define GPR1 1 // GPR 1 in an RA, RB, RT, etc. field
00151 #define GPR2 2 // GPR 2 in an RA, RB, RT, etc. field
00152 #define GPR12 12 // GPR 12 in an RA, RB, RT, etc. field
00153 #define LINKREG 0x100 // Link Reg in a MFSPR instruction
00154 #define COUNTREG 0x120 // Count Reg in a MFSPR instruction
00155
00156
00157
00158
00159
00160
00161
00162
#ifndef _IMAGEHLP_SOURCE_
00163
00164
static NTSTATUS
00165 TryReadUlong(IN ULONG NextPc,
00166 OUT PULONG Value)
00167 {
00168
try {
00169
READ_ULONG (NextPc, *Value);
00170 } except (
EXCEPTION_EXECUTE_HANDLER) {
00171
return GetExceptionCode();
00172 }
00173
return STATUS_SUCCESS;
00174 }
00175
00176
#endif
00177
00178
static INSTR_CLASS
00179 ClassifyInstruction (PPC_INSTRUCTION *I,
00180 UNWIND_INTENT Intent,
00181 #ifdef _IMAGEHLP_SOURCE_
00182 HANDLE hProcess,
00183 PREAD_PROCESS_MEMORY_ROUTINE ReadMemory,
00184 PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccess,
00185 #endif
00186 ULONG Pc,
00187 PMILLICODE_INFO Info)
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 {
00216
00217
#define OP_INTENT(OP,INTENT) ((OP) << 2 | (INTENT))
00218
00219
#ifdef _IMAGEHLP_SOURCE_
00220
DWORD ImagehlpCb = 0;
00221
#endif
00222
00223
switch (
OP_INTENT (I->Primary_Op,
Intent)) {
00224
00225
00226
00227
00228
00229
case OP_INTENT (STW_OP,
UnwindReverseR12):
00230
if (I->Dform_RA ==
GPR12)
00231
return InstrSTW;
00232
00233
case OP_INTENT (STW_OP,
UnwindReverse):
00234
if (I->Dform_RA ==
GPR1)
00235
return InstrSTW;
00236
break;
00237
00238
00239
00240
00241
case OP_INTENT (LWZ_OP,
UnwindForward):
00242
return InstrSTW;
00243
00244
00245
00246
00247
00248
case OP_INTENT (LWZ_OP,
UnwindReverse):
00249
if (I->Dform_RA ==
GPR1 &&
00250 I->Dform_RS ==
GPR2)
00251
return InstrTOCRestore;
00252
00253
00254
00255
00256
case OP_INTENT (STWU_OP,
UnwindReverse):
00257
case OP_INTENT (STWU_OP,
UnwindReverseR12):
00258
case OP_INTENT (STWU_OP,
UnwindR12):
00259
if (I->Dform_RS ==
GPR1 &&
00260 I->Dform_RA ==
GPR1)
00261
return (
Intent ==
UnwindR12 ?
InstrSTWUr12 :
InstrSTWU);
00262
break;
00263
00264
00265
00266
00267
00268
case OP_INTENT (STFD_OP,
UnwindReverseR12):
00269
if (I->Dform_RA ==
GPR12)
00270
return InstrSTFD;
00271
00272
case OP_INTENT (STFD_OP,
UnwindReverse):
00273
if (I->Dform_RA ==
GPR1)
00274
return InstrSTFD;
00275
break;
00276
00277
00278
00279
00280
case OP_INTENT (LFD_OP,
UnwindForward):
00281
return InstrSTFD;
00282
00283
00284
00285
00286
case OP_INTENT (ADDI_OP,
UnwindR12):
00287
if (I->Dform_RS ==
GPR12 &&
00288 I->Dform_RA ==
GPR1)
00289
return InstrADDIr12;
00290
break;
00291
case OP_INTENT (ADDI_OP,
UnwindForward):
00292
return InstrADDIfwd;
00293
00294
00295
00296
00297
case OP_INTENT (B_OP,
UnwindReverse):
00298
00299
00300
00301
00302 Pc = ((LONG)(I->Iform_LI) << 2) + (I->Iform_AA ? 0 : Pc);
00303
00304
00305
00306
00307
00308
00309
if (I->Iform_LK) {
00310 PPC_INSTRUCTION TempI;
00311
READ_ULONG (Pc, TempI.Long);
00312
if (TempI.Primary_Op == X31_OP &&
00313 TempI.Xform_XO == MFSPR_OP &&
00314 TempI.XFXform_spr ==
LINKREG) {
00315
break;
00316 }
00317 }
00318
00319
00320
00321
00322
00323
00324
if ((Info->
FunctionEntry = (PRUNTIME_FUNCTION)
RtlLookupFunctionEntry(Pc)) !=
NULL
00325
#ifndef FUNCTION_ENTRY_IS_IMAGE_STYLE
00326
&& Info->
FunctionEntry->ExceptionHandler == 0
00327
#endif
00328
) {
00329 Info->
TargetPc = Pc;
00330
switch (
00331
#ifdef FUNCTION_ENTRY_IS_IMAGE_STYLE
00332
Info->
FunctionEntry->BeginAddress -
00333 Info->
FunctionEntry->PrologEndAddress
00334
#else
00335
(ULONG)Info->
FunctionEntry->HandlerData
00336
#endif
00337
) {
00338
case 1:
00339
if (I->Iform_LK)
00340
return InstrSaveCode;
00341
break;
00342
case 2:
00343
if (!I->Iform_LK)
00344
return InstrRestoreCode;
00345
break;
00346
#ifdef FUNCTION_ENTRY_IS_IMAGE_STYLE
00347
default:
00348
if ((Info->
FunctionEntry->PrologEndAddress & 3) == 1)
00349
#else
00350
case 3:
00351
#endif
00352
return InstrGlue;
00353
break;
00354 }
00355 }
00356
break;
00357
00358
00359
00360
00361
case OP_INTENT (X19_OP,
UnwindForward):
00362
00363
00364
00365
00366
if (I->Long == RETURN_INSTR)
00367
return InstrBLR;
00368
00369
break;
00370
00371
case OP_INTENT (X19_OP,
UnwindR12):
00372
case OP_INTENT (X19_OP,
UnwindReverse):
00373
case OP_INTENT (X19_OP,
UnwindReverseR12):
00374
00375
00376
00377
00378
00379
if (I->Xform_XO == RFI_OP) {
00380
return InstrSetEstablisher;
00381 }
00382
00383
break;
00384
00385
00386
00387
00388
case OP_INTENT (X31_OP,
UnwindForward):
00389
case OP_INTENT (X31_OP,
UnwindR12):
00390
case OP_INTENT (X31_OP,
UnwindReverse):
00391
case OP_INTENT (X31_OP,
UnwindReverseR12):
00392
switch (
OP_INTENT (I->Xform_XO,
Intent)) {
00393
00394
00395
00396
00397
case OP_INTENT (OR_OP,
UnwindR12):
00398
if (I->Xform_RS == I->Xform_RB &&
00399 I->Xform_RA ==
GPR12 &&
00400 I->Xform_RB ==
GPR1)
00401
return InstrMRr12;
00402
break;
00403
case OP_INTENT (OR_OP,
UnwindReverse):
00404
case OP_INTENT (OR_OP,
UnwindReverseR12):
00405
if (I->Xform_RS == I->Xform_RB &&
00406 I->Xform_RB !=
GPR1)
00407
return InstrMR;
00408
break;
00409
case OP_INTENT (OR_OP,
UnwindForward):
00410
if (I->Xform_RS == I->Xform_RB)
00411
return InstrMRfwd;
00412
break;
00413
00414
00415
00416
00417
case OP_INTENT (STWUX_OP,
UnwindReverse):
00418
case OP_INTENT (STWUX_OP,
UnwindReverseR12):
00419
case OP_INTENT (STWUX_OP,
UnwindR12):
00420
if (I->Xform_RS ==
GPR1 && I->Xform_RA ==
GPR1)
00421
return (
Intent ==
UnwindR12 ?
InstrSTWUr12 :
InstrSTWU);
00422
break;
00423
00424
00425
00426
00427
case OP_INTENT (MFSPR_OP,
UnwindReverse):
00428
case OP_INTENT (MTSPR_OP,
UnwindForward):
00429
if (I->XFXform_spr ==
LINKREG)
00430
return InstrMFLR;
00431
break;
00432
00433
00434
00435
00436
case OP_INTENT (MFCR_OP,
UnwindReverse):
00437
case OP_INTENT (MFCR_OP,
UnwindReverseR12):
00438
return InstrMFCR;
00439
00440
00441
00442
00443
case OP_INTENT (MTCRF_OP,
UnwindForward):
00444
if (I->XFXform_FXM == 255)
00445
return InstrMFCR;
00446
break;
00447
00448
default:
00449
break;
00450 }
00451
00452
default:
00453
break;
00454 }
00455
00456
00457
00458
00459
return InstrIgnore;
00460
#undef OP_INTENT
00461
}
00462
00463
#ifdef _IMAGEHLP_SOURCE_
00464
static
00465
#endif
00466
ULONG
00467 RtlVirtualUnwind (
00468
00469 #ifdef _IMAGEHLP_SOURCE_
00470 HANDLE hProcess,
00471 DWORD ControlPc,
00472 PRUNTIME_FUNCTION FunctionEntry,
00473 PCONTEXT ContextRecord,
00474 PREAD_PROCESS_MEMORY_ROUTINE ReadMemory,
00475 PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccess
00476 #define ContextPointers ((PKNONVOLATILE_CONTEXT_POINTERS)0)
00477 #
else
00478 IN ULONG ControlPc,
00479 IN PRUNTIME_FUNCTION FunctionEntry,
00480 IN OUT PCONTEXT ContextRecord,
00481 OUT PBOOLEAN InFunction,
00482 OUT PULONG EstablisherFrame,
00483 IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL,
00484 IN ULONG LowStackLimit,
00485 IN ULONG HighStackLimit
00486 #endif
00487 )
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 {
00551
ITERATOR Iterator[8];
00552
PITERATOR Piterator;
00553 ULONG Address;
00554
PDOUBLE FloatingRegister;
00555 PPC_INSTRUCTION I;
00556 PULONG IntegerRegister;
00557 ULONG NextPc, Pc;
00558 BOOLEAN RestoredLr =
FALSE;
00559 BOOLEAN RestoredSp =
FALSE;
00560 BOOLEAN ComputedSp =
FALSE;
00561 ULONG Rt;
00562
MILLICODE_INFO Info;
00563
INSTR_CLASS InstrClass;
00564
#ifdef _IMAGEHLP_SOURCE_
00565
DWORD ImagehlpCb = 0;
00566 RUNTIME_FUNCTION SavedFunctionEntry;
00567
#else
00568
ULONG EstablisherFrameValue;
00569
#endif
00570
00571
00572
00573
00574
00575 FloatingRegister = &ContextRecord->Fpr0;
00576 IntegerRegister = &ContextRecord->Gpr0;
00577
00578
00579
00580
00581
00582
if (FunctionEntry ==
NULL) {
00583
00584
00585
00586 NextPc = ContextRecord->Lr - 4;
00587
00588
00589
00590
00591
00592
if (NextPc == ControlPc)
00593
return NextPc;
00594
00595
goto CheckForGlue;
00596 }
00597
#ifdef _IMAGEHLP_SOURCE_
00598
else {
00599 SavedFunctionEntry = *FunctionEntry;
00600 FunctionEntry = &SavedFunctionEntry;
00601 }
00602
#endif
00603
00604
00605
00606
00607
00608
NOT_IMAGEHLP (*EstablisherFrame =
00609 EstablisherFrameValue = ContextRecord->Gpr1);
00610
00611
READ_ULONG (ControlPc, I.Long);
00612
if (I.Long == RETURN_INSTR) {
00613
00614
00615
00616
00617
00618
00619
NOT_IMAGEHLP(*InFunction =
FALSE);
00620 NextPc = ContextRecord->Lr;
00621
goto CheckForGlue;
00622 }
00623 InstrClass =
ClassifyInstruction(&I,
UnwindReverse,
00624 #ifdef _IMAGEHLP_SOURCE_
00625 hProcess, ReadMemory, FunctionTableAccess,
00626 #endif
00627 ControlPc, &Info);
00628
if (InstrClass ==
InstrRestoreCode) {
00629
00630
00631
00632
00633
00634
00635
00636 Iterator[0].
BeginPc = Info.
TargetPc;
00637 Iterator[0].
EndPc = Info.
FunctionEntry->EndAddress;
00638 Iterator[0].
Increment = 4;
00639 Iterator[0].
Intent =
UnwindForward;
00640
NOT_IMAGEHLP(*InFunction =
FALSE);
00641
00642 }
else if (
00643
#ifdef FUNCTION_ENTRY_IS_IMAGE_STYLE
00644
(FunctionEntry->BeginAddress -
00645 FunctionEntry->PrologEndAddress) == 2
00646
#else
00647
FunctionEntry->ExceptionHandler == 0 &&
00648 (ULONG)FunctionEntry->HandlerData == 2
00649
#endif
00650
) {
00651
00652
00653
00654
00655
00656 Iterator[0].
BeginPc = ControlPc;
00657 Iterator[0].
EndPc = FunctionEntry->EndAddress;
00658 Iterator[0].
Increment = 4;
00659 Iterator[0].
Intent =
UnwindForward;
00660
NOT_IMAGEHLP(*InFunction =
FALSE);
00661
00662 }
else {
00663
00664
00665
00666
00667
00668
00669
if (InstrClass ==
InstrTOCRestore) {
00670 PPC_INSTRUCTION Iprev;
00671
READ_ULONG (ControlPc - 4, Iprev.Long);
00672
if (
ClassifyInstruction (&Iprev,
UnwindReverse,
00673 #ifdef _IMAGEHLP_SOURCE_
00674 hProcess, ReadMemory, FunctionTableAccess,
00675 #endif
00676 ControlPc - 4, &Info) ==
InstrGlue) {
00677
00678
00679
00680
00681
00682
00683 ControlPc += 4;
00684 Address = IntegerRegister[I.Dform_RA] + I.Dform_D;
00685 Rt = I.Dform_RT;
00686
READ_ULONG (Address, IntegerRegister[Rt]);
00687
if (ARGUMENT_PRESENT (ContextPointers))
00688 ContextPointers->IntegerContext[Rt] = (PULONG) Address;
00689 }
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 Iterator[0].
EndPc = FunctionEntry->BeginAddress - 4;
00701 Iterator[0].
Increment = -4;
00702 Iterator[0].
Intent =
UnwindReverse;
00703
if ((ControlPc < FunctionEntry->BeginAddress) ||
00704 (ControlPc >= (FunctionEntry->PrologEndAddress & ~3))) {
00705
NOT_IMAGEHLP(*InFunction =
TRUE);
00706 Iterator[0].
BeginPc = ((FunctionEntry->PrologEndAddress & ~3) - 4);
00707 }
else {
00708
NOT_IMAGEHLP(*InFunction =
FALSE);
00709 Iterator[0].
BeginPc = ControlPc - 4;
00710 }
00711 }
00712
00713
00714
00715
00716
00717 NextPc = ContextRecord->Lr - 4;
00718 UnwindGlue:
00719
for (Piterator = Iterator; Piterator >= Iterator; Piterator--) {
00720
for (Pc = Piterator->
BeginPc;
00721 Pc != Piterator->
EndPc;
00722 Pc += Piterator->
Increment) {
00723
00724
READ_ULONG (Pc, I.Long);
00725 Address = IntegerRegister[I.Dform_RA] + I.Dform_D;
00726 Rt = I.Dform_RT;
00727
switch (
ClassifyInstruction (&I, Piterator->
Intent,
00728 #ifdef _IMAGEHLP_SOURCE_
00729 hProcess, ReadMemory, FunctionTableAccess,
00730 #endif
00731 Pc, &Info)) {
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
case InstrMFLR:
00751 ContextRecord->Lr = IntegerRegister[Rt];
00752
if ( RestoredLr ==
FALSE ) {
00753 NextPc = ContextRecord->Lr - 4;
00754 RestoredLr =
TRUE;
00755 }
else {
00756 NextPc += 4;
00757 }
00758
continue;
00759
00760
00761
00762
00763
case InstrBLR:
00764 NextPc = ContextRecord->Lr - 4;
00765
break;
00766
00767
00768
00769
00770
case InstrMFCR:
00771 ContextRecord->Cr = IntegerRegister[Rt];
00772
continue;
00773
00774
00775
00776
00777
case InstrSTW:
00778
00779
00780
00781
00782
00783
00784
READ_ULONG (Address, IntegerRegister[Rt]);
00785
if (ARGUMENT_PRESENT (ContextPointers))
00786 ContextPointers->IntegerContext[Rt] = (PULONG) Address;
00787
continue;
00788
00789
00790
00791
00792
00793
00794
case InstrSTWU:
00795 Address = IntegerRegister[
GPR1];
00796
READ_ULONG(Address,IntegerRegister[
GPR1]);
00797
if (RestoredSp ==
FALSE) {
00798
NOT_IMAGEHLP (*EstablisherFrame =
00799 EstablisherFrameValue = ContextRecord->Gpr1);
00800 RestoredSp =
TRUE;
00801 }
00802
if (ARGUMENT_PRESENT (ContextPointers))
00803 ContextPointers->IntegerContext[Rt] = (PULONG) Address;
00804
continue;
00805
00806
00807
00808
00809
case InstrSTFD:
00810
READ_DOUBLE (Address, FloatingRegister[Rt]);
00811
if (ARGUMENT_PRESENT (ContextPointers))
00812 ContextPointers->FloatingContext[Rt] = (
PDOUBLE) Address;
00813
continue;
00814
00815
00816
00817
00818
case InstrMR:
00819 IntegerRegister[I.Xform_RA] = IntegerRegister[Rt];
00820
continue;
00821
case InstrMRfwd:
00822 IntegerRegister[Rt] = IntegerRegister[I.Xform_RA];
00823
continue;
00824
case InstrMRr12:
00825 IntegerRegister[Rt] = IntegerRegister[I.Xform_RA];
00826
break;
00827
00828
00829
00830
00831
case InstrADDIfwd:
00832 IntegerRegister[Rt] = Address;
00833
continue;
00834
case InstrADDIr12:
00835
if (!ComputedSp) {
00836
00837
00838 IntegerRegister[Rt] = IntegerRegister[
GPR1];
00839 }
00840 IntegerRegister[Rt] += I.Dform_SI;
00841
break;
00842
00843
00844
00845
00846
case InstrSTWUr12:
00847 ComputedSp =
TRUE;
00848 Address = IntegerRegister[
GPR1];
00849
READ_ULONG(Address,IntegerRegister[
GPR12]);
00850
continue;
00851
00852
00853
00854
00855
case InstrSaveCode:
00856
00857
00858
00859
00860 Piterator++;
00861 Piterator->
BeginPc = Info.
FunctionEntry->EndAddress - 4;
00862 Piterator->
EndPc = Info.
TargetPc - 4;
00863 Piterator->
Increment = -4;
00864 Piterator->
Intent =
UnwindReverseR12;
00865
00866
00867
00868 Piterator++;
00869 Piterator->
BeginPc = Pc - 4;
00870 Piterator->
EndPc = Piterator[-2].
EndPc;
00871 Piterator->
Increment = -4;
00872 Piterator->
Intent =
UnwindR12;
00873 ComputedSp =
FALSE;
00874
00875
00876
00877
00878 Piterator[-2].
BeginPc = Pc - 4;
00879 Piterator++;
00880
break;
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
case InstrGlue:
00892
00893
00894
00895
00896
00897
00898
00899
00900
if (Piterator - Iterator + 4
00901 >
sizeof (Iterator) /
sizeof (Iterator[0]))
00902
return 0;
00903
00904
00905
00906
00907
00908
00909 Piterator++;
00910 Piterator->
BeginPc
00911 = (Info.
FunctionEntry->PrologEndAddress & ~3) - 4;
00912 Piterator->
EndPc = Info.
FunctionEntry->BeginAddress - 4;
00913 Piterator->
Increment = -4;
00914 Piterator->
Intent =
UnwindReverse;
00915
00916
00917
00918
00919 Piterator[-1].
BeginPc = Pc - 4;
00920 Piterator++;
00921
break;
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
case InstrSetEstablisher:
00932
NOT_IMAGEHLP (*EstablisherFrame =
00933 EstablisherFrameValue = ContextRecord->Gpr1);
00934
continue;
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
case InstrIgnore:
00945
default:
00946
continue;
00947 }
00948
break;
00949 }
00950 }
00951
00952 CheckForGlue:
00953
00954
00955
00956
00957
00958
00959
if (NextPc == 0 || NextPc + 4 == 0
00960
#ifdef _IMAGEHLP_SOURCE_
00961
|| NextPc == 1
00962
#else
00963
|| EstablisherFrameValue < LowStackLimit
00964 || EstablisherFrameValue > HighStackLimit
00965 || (EstablisherFrameValue & 0x7) != 0
00966
#endif
00967
)
00968
return NextPc;
00969
00970
00971
00972
00973
#ifdef _IMAGEHLP_SOURCE_
00974
READ_ULONG (NextPc, I.Long);
00975
#else
00976
if ( !
NT_SUCCESS(
TryReadUlong(NextPc, &I.Long)) ) {
00977
return NextPc;
00978 }
00979
#endif
00980
if (I.Primary_Op != B_OP)
00981
return NextPc;
00982
00983
00984
00985
00986
00987 Pc = ((LONG)(I.Iform_LI) << 2) + (I.Iform_AA ? 0 : NextPc);
00988
00989
00990
00991
00992
00993
00994
if (FunctionEntry !=
NULL
00995 && Pc >= FunctionEntry->BeginAddress
00996 && Pc < FunctionEntry->EndAddress)
00997
return NextPc;
00998
00999
01000
01001
01002
01003
01004
if ((FunctionEntry = (PRUNTIME_FUNCTION)
RtlLookupFunctionEntry(Pc)) !=
NULL) {
01005
01006
01007
01008
READ_ULONG (Pc, I.Long);
01009
if (I.Primary_Op == LWZ_OP && I.Dform_RA ==
GPR2) {
01010
01011
01012
01013
READ_ULONG (Pc + 4, I.Long);
01014
if (I.Primary_Op == B_OP && I.Iform_LK) {
01015
01016
01017
01018
01019 Pc = ((LONG)(I.Iform_LI) << 2) + (I.Iform_AA ? 0 : Pc + 4);
01020 FunctionEntry = (PRUNTIME_FUNCTION)
RtlLookupFunctionEntry(Pc);
01021 }
01022 }
01023 }
01024
01025
01026
01027
01028
if (!(FunctionEntry !=
NULL
01029
#ifndef FUNCTION_ENTRY_IS_IMAGE_STYLE
01030
&& FunctionEntry->ExceptionHandler == 0
01031 && (ULONG)FunctionEntry->HandlerData == 3
01032
#else
01033
&& (FunctionEntry->BeginAddress <
01034 FunctionEntry->PrologEndAddress)
01035 && (FunctionEntry->PrologEndAddress & 3) == 1
01036
#endif
01037
))
01038
return NextPc;
01039
01040
01041
01042
01043
01044
01045
#ifdef _IMAGEHLP_SOURCE_
01046
SavedFunctionEntry = *FunctionEntry;
01047 FunctionEntry = &SavedFunctionEntry;
01048
#endif
01049
Iterator[0].EndPc = FunctionEntry->BeginAddress - 4;
01050 Iterator[0].Increment = -4;
01051 Iterator[0].Intent =
UnwindReverse;
01052 Iterator[0].BeginPc = ((FunctionEntry->PrologEndAddress & ~3) - 4);
01053
goto UnwindGlue;
01054 }
01055
01056
#undef NOT_IMAGEHLP