summaryrefslogtreecommitdiff
path: root/src/pal/src/exception/seh-unwind.cpp
blob: 24ae3c550f17601b1d9e69e479fb3e2344220925 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
//
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Geoff Norton. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

/*++



Module Name:

    seh-unwind.cpp

Abstract:

    Implementation of exception API functions based on
    the Unwind API.



--*/

#ifndef FEATURE_PAL_SXS
#error FEATURE_PAL_SXS needs to be defined for this file.
#endif // !FEATURE_PAL_SXS

#include "pal/context.h"
#include <dlfcn.h>
#include <exception>
#define UNW_LOCAL_ONLY
#include <libunwind.h>

//----------------------------------------------------------------------
// Exception Handling ABI Level I: Base ABI
//----------------------------------------------------------------------

typedef UINT_PTR _Unwind_Ptr;

struct dwarf_eh_bases
{
    _Unwind_Ptr dataRelBase, textRelBase;
};

extern "C" _Unwind_Ptr _Unwind_GetDataRelBase(_Unwind_Context *context);
extern "C" _Unwind_Ptr _Unwind_GetTextRelBase(_Unwind_Context *context);

typedef BYTE fde;
extern "C" const fde *_Unwind_Find_FDE(void *ip, dwarf_eh_bases *bases);

//----------------------------------------------------------------------
// Exception Handling ABI Level II: C++ ABI
//----------------------------------------------------------------------

struct __cxa_exception
{
    std::type_info *exceptionType;
    void (*exceptionDestructor)(void *);
    std::unexpected_handler unexpectedHandler;
    std::terminate_handler terminateHandler;
    __cxa_exception *nextException;

    int handlerCount;
    int handlerSwitchValue;
    const char *actionRecord;
    const char *languageSpecificData;
    void *catchTemp;
    void *adjustedPtr;

    _Unwind_Exception unwindHeader;
};

//----------------------------------------------------------------------
// Virtual Unwinding
//----------------------------------------------------------------------

#if UNWIND_CONTEXT_IS_UCONTEXT_T
static void WinContextToUnwindContext(CONTEXT *winContext, unw_context_t *unwContext)
{
#if defined(_AMD64_)
    unwContext->uc_mcontext.gregs[REG_RIP] = winContext->Rip;
    unwContext->uc_mcontext.gregs[REG_RSP] = winContext->Rsp;
    unwContext->uc_mcontext.gregs[REG_RBP] = winContext->Rbp;
    unwContext->uc_mcontext.gregs[REG_RBX] = winContext->Rbx;
    unwContext->uc_mcontext.gregs[REG_R12] = winContext->R12;
    unwContext->uc_mcontext.gregs[REG_R13] = winContext->R13;
    unwContext->uc_mcontext.gregs[REG_R14] = winContext->R14;
    unwContext->uc_mcontext.gregs[REG_R15] = winContext->R15;
#else
#error unsupported architecture
#endif
}
#else
static void WinContextToUnwindCursor(CONTEXT *winContext, unw_cursor_t *cursor)
{
#if defined(_AMD64_)
    unw_set_reg(cursor, UNW_REG_IP, winContext->Rip);
    unw_set_reg(cursor, UNW_REG_SP, winContext->Rsp);
    unw_set_reg(cursor, UNW_X86_64_RBP, winContext->Rbp);
    unw_set_reg(cursor, UNW_X86_64_RBX, winContext->Rbx);
    unw_set_reg(cursor, UNW_X86_64_R12, winContext->R12);
    unw_set_reg(cursor, UNW_X86_64_R13, winContext->R13);
    unw_set_reg(cursor, UNW_X86_64_R14, winContext->R14);
    unw_set_reg(cursor, UNW_X86_64_R15, winContext->R15);
#else
#error unsupported architecture
#endif
}
#endif

static void UnwindContextToWinContext(unw_cursor_t *cursor, CONTEXT *winContext)
{
#if defined(_AMD64_)
    unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Rip);
    unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->Rsp);
    unw_get_reg(cursor, UNW_X86_64_RBP, (unw_word_t *) &winContext->Rbp);
    unw_get_reg(cursor, UNW_X86_64_RBX, (unw_word_t *) &winContext->Rbx);
    unw_get_reg(cursor, UNW_X86_64_R12, (unw_word_t *) &winContext->R12);
    unw_get_reg(cursor, UNW_X86_64_R13, (unw_word_t *) &winContext->R13);
    unw_get_reg(cursor, UNW_X86_64_R14, (unw_word_t *) &winContext->R14);
    unw_get_reg(cursor, UNW_X86_64_R15, (unw_word_t *) &winContext->R15);
#else
#error unsupported architecture
#endif
}

static void GetContextPointer(unw_cursor_t *cursor, int reg, PDWORD64 *contextPointer)
{
#if defined(__APPLE__)
    //OSXTODO
#else
    unw_save_loc_t saveLoc;
    unw_get_save_loc(cursor, reg, &saveLoc);
    if (saveLoc.type == UNW_SLT_MEMORY)
    {
        *contextPointer = (PDWORD64)saveLoc.u.addr;
    }
#endif
}

static void GetContextPointers(unw_cursor_t *cursor, KNONVOLATILE_CONTEXT_POINTERS *contextPointers)
{
#if defined(_AMD64_)
    GetContextPointer(cursor, UNW_X86_64_RBP, &contextPointers->Rbp);
    GetContextPointer(cursor, UNW_X86_64_RBX, &contextPointers->Rbx);
    GetContextPointer(cursor, UNW_X86_64_R12, &contextPointers->R12);
    GetContextPointer(cursor, UNW_X86_64_R13, &contextPointers->R13);
    GetContextPointer(cursor, UNW_X86_64_R14, &contextPointers->R14);
    GetContextPointer(cursor, UNW_X86_64_R15, &contextPointers->R15);
#else
#error unsupported architecture
#endif
}

BOOL VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers)
{
    int st;
    unw_context_t unwContext;
    unw_cursor_t cursor;

#if UNWIND_CONTEXT_IS_UCONTEXT_T
    WinContextToUnwindContext(context, &unwContext);
#else
    st = unw_getcontext(&unwContext);
    if (st < 0)
    {
        return FALSE;
    }
#endif

    st = unw_init_local(&cursor, &unwContext);
    if (st < 0)
    {
        return FALSE;
    }

#if !UNWIND_CONTEXT_IS_UCONTEXT_T
    // Set the unwind context to the specified windows context
    WinContextToUnwindCursor(context, &cursor);
#endif

    st = unw_step(&cursor);
    if (st < 0)
    {
        return FALSE;
    }

    // Update the passed in windows context to reflect the unwind
    UnwindContextToWinContext(&cursor, context);

    if (contextPointers != NULL)
    {
        GetContextPointers(&cursor, contextPointers);
    }

    return TRUE;
}

#if _DEBUG
//----------------------------------------------------------------------
// Virtual Unwinding Debugging Assertions
//----------------------------------------------------------------------

// Print a trace of virtually unwinding the stack.
// This helps us diagnose non-unwindable stacks.
// Unfortunately, calling this function from gdb will not be very useful,
// since gdb makes it look like it had been called directly from "start"
// (whose unwind info says we reached the end of the stack).
// You can still call it from, say, RaiseTheExceptionInternalOnly.

// (non-static to ease debugging)
void DisplayContext(_Unwind_Context *context)
{
    fprintf(stderr, "  ip =%p", _Unwind_GetIP(context));
    fprintf(stderr, "  cfa=%p", _Unwind_GetCFA(context));
#if defined(_X86_)
    // TODO: display more registers
#elif defined(_PPC_)
    fprintf(stderr, "  ra =0x%p", _Unwind_GetGR(context, 0x41));
    fprintf(stderr, "  r11=0x%p\n", _Unwind_GetGR(context, 0x46));
    for (int i = 13; i < 32; i++)
    {
        fprintf(stderr, "  r%02d=0x%p", i, _Unwind_GetGR(context, i));
        if ((i - 13) % 4 == 3)
            fprintf(stderr, "\n");
    }
#endif
    fprintf(stderr, "\n");
}

static _Unwind_Reason_Code PrintVirtualUnwindCallback(_Unwind_Context *context, void *pvParam)
{
    int *pFrameNumber = (int *) pvParam;

    void *ip = _Unwind_GetIP(context);
    const char *module = NULL;
    const char *name = 0;
    int offset = 0;

    Dl_info dl_info;
    if (dladdr(ip, &dl_info))
    {
        module = dl_info.dli_fname;
        if (dl_info.dli_sname)
        {
            name = dl_info.dli_sname;
            offset = (char *) ip - (char *) dl_info.dli_saddr;
        }
        else
        {
            name = "<img-base>";
            offset = (char *) ip - (char *) dl_info.dli_fbase;
        }
    }

    if (module)
        fprintf(stderr, "#%-3d  %s!%s+%d\n", *pFrameNumber, module, name, offset);
    else
        fprintf(stderr, "#%-3d  ??\n", *pFrameNumber);
    DisplayContext(context);
    (*pFrameNumber)++;
    return _URC_NO_REASON;
}

extern "C" void PAL_PrintVirtualUnwind()
{
    BOOL fEntered = PAL_ReenterForEH();

    fprintf(stderr, "\nVirtual unwind of PAL thread %p\n", InternalGetCurrentThread());
    int frameNumber = 0;
    _Unwind_Reason_Code urc = _Unwind_Backtrace(PrintVirtualUnwindCallback, &frameNumber);
    fprintf(stderr, "End of stack (return code=%d).\n", urc);

    if (fEntered)
    {
        PAL_Leave(PAL_BoundaryEH);
    }
}

static const char *PAL_CHECK_UNWINDABLE_STACKS = "PAL_CheckUnwindableStacks";

enum CheckUnwindableStacksMode
{
    // special value to indicate we've not initialized yet
    CheckUnwindableStacks_Uninitialized = -1,

    CheckUnwindableStacks_Off           = 0,
    CheckUnwindableStacks_On            = 1,
    CheckUnwindableStacks_Thorough      = 2,

    CheckUnwindableStacks_Default       = CheckUnwindableStacks_On
};

static CheckUnwindableStacksMode s_mode = CheckUnwindableStacks_Uninitialized;

// A variant of the above.  This one's not meant for CLR developers to use for tracing,
// but implements debug checks to assert stack consistency.
static _Unwind_Reason_Code CheckVirtualUnwindCallback(_Unwind_Context *context, void *pvParam)
{
    void *ip = _Unwind_GetIP(context);

    // If we reach an IP that we cannot find a module for,
    // then we ended up in dynamically-generated code and
    // the stack will not be unwindable past this point.
    Dl_info dl_info;
    if (dladdr(ip, &dl_info) == 0 ||
        ((s_mode == CheckUnwindableStacks_Thorough) &&
        ( dl_info.dli_sname == NULL ||
          ( _Unwind_Find_FDE(ip, NULL) == NULL &&
            strcmp(dl_info.dli_sname, "start") &&
            strcmp(dl_info.dli_sname, "_thread_create_running")))))
    {
        *(BOOL *) pvParam = FALSE;
    }

    return _URC_NO_REASON;
}

extern "C" void PAL_CheckVirtualUnwind()
{
    if (s_mode == CheckUnwindableStacks_Uninitialized)
    {
        const char *checkUnwindableStacks = getenv(PAL_CHECK_UNWINDABLE_STACKS);
        s_mode = checkUnwindableStacks ?
            (CheckUnwindableStacksMode) atoi(checkUnwindableStacks) : CheckUnwindableStacks_Default;
    }

    if (s_mode != CheckUnwindableStacks_Off)
    {
        BOOL fUnwindable = TRUE;
        _ASSERTE(_Unwind_Backtrace(CheckVirtualUnwindCallback, &fUnwindable) == _URC_END_OF_STACK);
        if (!fUnwindable)
        {
            PAL_PrintVirtualUnwind();
            ASSERT("Stack not unwindable.  Throwing may terminate the process.\n");
        }
    }
}
#endif // _DEBUG

//----------------------------------------------------------------------
// Registering Vectored Handlers
//----------------------------------------------------------------------

static PVECTORED_EXCEPTION_HANDLER VectoredExceptionHandler = NULL;
static PVECTORED_EXCEPTION_HANDLER VectoredContinueHandler = NULL;

void SetVectoredExceptionHandler(PVECTORED_EXCEPTION_HANDLER pHandler)
{
    PERF_ENTRY(SetVectoredExceptionHandler);
    ENTRY("SetVectoredExceptionHandler(pHandler=%p)\n", pHandler);

    _ASSERTE(VectoredExceptionHandler == NULL);
    VectoredExceptionHandler = pHandler;

    LOGEXIT("SetVectoredExceptionHandler returns\n");
    PERF_EXIT(SetVectoredExceptionHandler);

}

void SetVectoredContinueHandler(PVECTORED_EXCEPTION_HANDLER pHandler)
{
    PERF_ENTRY(SetVectoredContinueHandler);
    ENTRY("SetVectoredContinueHandler(pHandler=%p)\n", pHandler);

    _ASSERTE(VectoredContinueHandler == NULL);
    VectoredContinueHandler = pHandler;

    LOGEXIT("SetVectoredContinueHandler returns\n");
    PERF_EXIT(SetVectoredContinueHandler);
}

//----------------------------------------------------------------------
// Representation of an SEH Exception as a C++ object
//----------------------------------------------------------------------

struct PAL_SEHException
{
public:
    // Note that the following two are actually embedded in this heap-allocated
    // instance - in contrast to Win32, where the exception record would usually
    // be allocated on the stack.  This is needed because foreign cleanup handlers
    // partially unwind the stack on the second pass.
    EXCEPTION_POINTERS ExceptionPointers;
    EXCEPTION_RECORD ExceptionRecord;
    CONTEXT ContextRecord;

    PAL_SEHException(EXCEPTION_RECORD *pExceptionRecord, CONTEXT *pContextRecord)
    {
        ExceptionPointers.ExceptionRecord = &ExceptionRecord;
        ExceptionPointers.ContextRecord = &ContextRecord;
        ExceptionRecord = *pExceptionRecord;
        ContextRecord = *pContextRecord;
        nestedExceptionEstablisherFrame = NULL;
    }

    static PAL_SEHException *FromExceptionObject(_Unwind_Exception *exceptionObject)
    {
        if (exceptionObject->exception_class == Class)
        {
            if (*((__cxa_exception *) (exceptionObject + 1) - 1)->exceptionType == typeid(PAL_SEHException))
            {
                return (PAL_SEHException *) (exceptionObject + 1);
            }
        }
        return NULL;
    }

    void NestedIn(_Unwind_Context *context)
    {
        nestedExceptionEstablisherFrame = _Unwind_GetCFA(context);
        ExceptionRecord.ExceptionFlags |= EXCEPTION_NESTED_CALL;
    }

    void RanThroughFilter(_Unwind_Context *context)
    {
        if (nestedExceptionEstablisherFrame == _Unwind_GetCFA(context))
        {
            // We were processing a nested exception, and we have repeated
            // the search phase past the filter that threw the nested exception.
            // Thus, clear the corresponding flag now.
            ExceptionRecord.ExceptionFlags &= ~EXCEPTION_NESTED_CALL;
        }
    }

private:
#ifdef __GNUC__
    static const __uint64_t Class = 0x474e5543432b2b00ULL; // vendor = GNUC, language = C++\0
#else
#error Vendor code not defined for this platform.
#endif

    // If we encountered a nested exception, the EXCEPTION_NESTED_CALL flag must
    // remain set on the exception while unwinding to the frame with the CFA
    // stored below.  Note that this will always be a PAL_TryExcept frame.
    void *nestedExceptionEstablisherFrame;
};

EXCEPTION_POINTERS *
PALAPI
PAL_GetExceptionPointers(_Unwind_Exception *exceptionObject)
{
    PAL_SEHException *pSEHException = PAL_SEHException::FromExceptionObject(exceptionObject);
    if (pSEHException)
    {
        return &pSEHException->ExceptionPointers;
    }
    return NULL;
}

//----------------------------------------------------------------------
// Raising Exceptions
//----------------------------------------------------------------------

static void DeleteThrownException(_Unwind_Exception *exceptionObject)
{
    // The argument exception has been thrown.
    _ASSERTE(std::uncaught_exception());

    // Deleting it in this way will adjust the uncaught exceptions count.
    __cxa_begin_catch(exceptionObject);
    __cxa_end_catch();
}

static void RunVectoredHandler(EXCEPTION_POINTERS *pExceptionPointers, _Unwind_Exception *exceptionObject, PVECTORED_EXCEPTION_HANDLER pHandler)
{
    if (pHandler != NULL)
    {
        EXCEPTION_DISPOSITION disposition = pHandler(pExceptionPointers);
        switch (disposition)
        {
        case EXCEPTION_CONTINUE_EXECUTION:
            {
                BOOL fNonContinuable = pExceptionPointers->ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE;
                CONTEXT *context = pExceptionPointers->ContextRecord;
                if (fNonContinuable)
                {
                    RaiseException(EXCEPTION_NONCONTINUABLE_EXCEPTION,
                                   EXCEPTION_NONCONTINUABLE, 0, NULL);
                }
                else
                {
                    SetThreadContext(PAL_GetCurrentThread(), context);
                }
            }
            abort(); // should never reach here
        case EXCEPTION_CONTINUE_SEARCH:
            break;
        default:
            DeleteThrownException(exceptionObject);
            RaiseException(EXCEPTION_INVALID_DISPOSITION,
                           EXCEPTION_NONCONTINUABLE, 0, NULL);
            abort(); // should never reach here
        }
    }
}

PAL_NORETURN
static void RtlpRaiseException(EXCEPTION_RECORD *ExceptionRecord)
{
    // Capture the context of RtlpRaiseException.
    CONTEXT ContextRecord;
    ZeroMemory(&ContextRecord, sizeof(CONTEXT));
    ContextRecord.ContextFlags = CONTEXT_FULL;
    CONTEXT_CaptureContext(&ContextRecord);

    // Find the caller of RtlpRaiseException.  This provides the exact context
    // that handlers expect to see, which is the one they would want to fix up
    // to resume after a continuable exception.
    VirtualUnwind(&ContextRecord, NULL);

    // The frame we're looking at now is either RaiseException or PAL_TryExcept.
    // If it's RaiseException, we have to unwind one level further to get the
    // actual context user code could be resumed at.
#if defined(_PPC_)
    void *pc = (void *) ContextRecord.Iar;
#elif defined(_X86_)
    void *pc = (void *) ContextRecord.Eip;
#elif defined(_AMD64_)
    void *pc = (void *) ContextRecord.Rip;
#else
#error unsupported architecture
#endif
    if ((SIZE_T) pc - (SIZE_T) RaiseException < (SIZE_T) pc - (SIZE_T) PAL_TryExcept)
    {
        VirtualUnwind(&ContextRecord, NULL);
#if defined(_PPC_)
        pc = (void *) ContextRecord.Iar;
#elif defined(_X86_)
        pc = (void *) ContextRecord.Eip;
#elif defined(_AMD64_)
        pc = (void *) ContextRecord.Rip;
#else
#error unsupported architecture
#endif
    }
    ExceptionRecord->ExceptionAddress = pc;

    EXCEPTION_POINTERS pointers;
    pointers.ExceptionRecord = ExceptionRecord;
    pointers.ContextRecord = &ContextRecord;

    SEHRaiseException(InternalGetCurrentThread(), &pointers, 0);
}

PAL_NORETURN
static void RaiseExceptionObject(_Unwind_Exception *exceptionObject)
{
    // Dummy exception record for use by foreign exceptions.
    EXCEPTION_RECORD ForeignExceptionRecord = { EXCEPTION_FOREIGN, EXCEPTION_NONCONTINUABLE, NULL, NULL, 0 };
    EXCEPTION_POINTERS ForeignExceptionPointers = { &ForeignExceptionRecord, NULL };

    bool fSkipVEH = false;

    EXCEPTION_POINTERS *pExceptionPointers = PAL_GetExceptionPointers(exceptionObject);
    if (!pExceptionPointers)
    {
        pExceptionPointers = &ForeignExceptionPointers;
    }
    else
    {
        fSkipVEH =(pExceptionPointers->ExceptionRecord->ExceptionFlags & EXCEPTION_SKIP_VEH)?true:false;
        if (!fSkipVEH)
        {
            // For exceptions that we know about, keep a reference in the corresponding
            // EXCEPTION_RECORD incase this turns out to be an async exception in managed code.
            pExceptionPointers->ExceptionRecord->ExceptionInformation[NATIVE_EXCEPTION_ASYNC_SLOT] = (ULONG_PTR)exceptionObject;
        }
    }

    if (!fSkipVEH)
    {
        RunVectoredHandler(pExceptionPointers, exceptionObject, VectoredExceptionHandler);
    }

    _Unwind_Reason_Code urc;
    PAL_Leave(PAL_BoundaryEH);
    urc = _Unwind_RaiseException(exceptionObject);

    // _Unwind_RaiseException is supposed to return an _Unwind_Reason_Code.
    // However, it's not implemented according to spec.  So we always have
    // to assume that we got _URC_END_OF_STACK.
    if (urc == (_Unwind_Reason_Code) (UINT_PTR) exceptionObject)
    {
        urc = _URC_END_OF_STACK;
    }
    _ASSERTE(urc == _URC_END_OF_STACK);

    PAL_Reenter(PAL_BoundaryEH);
    RunVectoredHandler(pExceptionPointers, exceptionObject, VectoredContinueHandler);

    DeleteThrownException(exceptionObject);

    WARN("unhandled exception; terminating self\n");

    abort();
    // unreached
}

static void ThrowHelper(void *pvParam)
{
    PEXCEPTION_POINTERS lpExceptionPointers = (PEXCEPTION_POINTERS) pvParam;
    PAL_Leave(PAL_BoundaryEH);
    throw PAL_SEHException(lpExceptionPointers->ExceptionRecord, lpExceptionPointers->ContextRecord);
}

static void RethrowHelper(void *pvParam)
{
    PAL_Leave(PAL_BoundaryEH);
    throw;
}

static EXCEPTION_DISPOSITION ThrowFilter(
    EXCEPTION_POINTERS *ExceptionPointers,
    PAL_DISPATCHER_CONTEXT *DispatcherContext,
    void *pvParam)
{
    return EXCEPTION_EXECUTE_HANDLER;
}

PAL_NORETURN
VOID
PALAPI
PAL_CppRethrow()
{
    // Throw the exception using C++ throw, but intercept the exception so that
    // we can raise it using our runtime, which supported vectored handlers.
    BOOL fExecuteHandler;
    _Unwind_Exception *exceptionObject =
        PAL_TryExcept(RethrowHelper, ThrowFilter, NULL, &fExecuteHandler);
    _ASSERTE(exceptionObject != NULL);
    PAL_CheckVirtualUnwind();
    RaiseExceptionObject(exceptionObject);
}

PAL_NORETURN
void SEHRaiseException(CPalThread *pthrCurrent,
                       PEXCEPTION_POINTERS lpExceptionPointers,
                       int signal_code)
{
    _Unwind_Exception *exceptionObject = NULL;

    if (lpExceptionPointers->ExceptionRecord->ExceptionFlags & EXCEPTION_SKIP_VEH)
    {
        // If we are going to skip VEH, then it implies we are going to dispatch
        // an async exception in managed code. For this case, extract the
        // native exception object from the ExceptionInformation array that was saved there
        // when PAL_DispatchException had initially raised the exception.
        exceptionObject = (_Unwind_Exception *)lpExceptionPointers->ExceptionRecord->ExceptionInformation[NATIVE_EXCEPTION_ASYNC_SLOT];
        lpExceptionPointers->ExceptionRecord->ExceptionInformation[NATIVE_EXCEPTION_ASYNC_SLOT] = (ULONG_PTR)NULL;
    }

    if (exceptionObject == NULL)
    {
        // Throw the exception using C++ throw, but intercept the exception so that
        // we can raise it using our runtime, which supported vectored handlers.
        BOOL fExecuteHandler;
        exceptionObject = PAL_TryExcept(ThrowHelper, ThrowFilter, lpExceptionPointers, &fExecuteHandler);
    }

    _ASSERTE(exceptionObject != NULL);

    // Note: We cannot call PAL_CheckVirtualUnwind here, since we this function
    // may be called for a fault in dynamically-generated code.

#if defined(_AMD64_)
    // When PAL_TryExcept returns, it has executed the second pass for handling the exception
    // that was raised by ThrowHelper. As part of processing the second pass, PAL_RunHandler
    // would have set the EXCEPTION_UNWINDING flag (and possibly, even the EXCEPTION_TARGET_UNWIND flag)
    // in the ExceptionRecord contained inside the exception object.
    //
    // When this exception object is passed to the RunVectoredExceptionHandler, the exception pointers
    // passed to the vectored handler would be the one extracted from the exception object. Since that
    // would have the unwinding flag set, any code that checks for the flag to conditional process the
    // exception would go awry.
    //
    // To fix this problem, we will fetch the ExceptionPointers from the exception object and clear off
    // any such flags.
    //
    // Note 1: This problem is also present when the exception object is seen by the various native
    //         personality routines (e.g. UnwindThunkPersonality). However, stack frame based handling
    //         of exceptions is not affected by this problem since all of our native personality routines
    //         clear off the existing flags and reset them again based upon the active phase (first or second)
    //         of exception dispatch before passing the exception record to CLR's managed personality routines.
    //
    // Note 2: This problem is also applicable to Mac X86. TODO: Fix this problem for MacX86.
    EXCEPTION_POINTERS *pExceptionPointers = PAL_GetExceptionPointers(exceptionObject);
    _ASSERTE(pExceptionPointers != NULL);

    // Clear of the EXCEPTION_UNWINDING/EXCEPTION_TARGET_UNWIND flags
    pExceptionPointers->ExceptionRecord->ExceptionFlags =
    (pExceptionPointers->ExceptionRecord->ExceptionFlags & ~(EXCEPTION_UNWINDING|EXCEPTION_TARGET_UNWIND));
#endif // defined(_AMD64_)

    RaiseExceptionObject(exceptionObject);
}

/*++
Function:
  RaiseException

See MSDN doc.
--*/
// no PAL_NORETURN, as callers must assume this can return for continuable exceptions.
VOID
PALAPI
RaiseException(IN DWORD dwExceptionCode,
               IN DWORD dwExceptionFlags,
               IN DWORD nNumberOfArguments,
               IN CONST ULONG_PTR *lpArguments)
{
    // PERF_ENTRY_ONLY is used here because RaiseException may or may not
    // return. We can not get latency data without PERF_EXIT. For this reason,
    // PERF_ENTRY_ONLY is used to profile frequency only.
    PERF_ENTRY_ONLY(RaiseException);
    ENTRY("RaiseException(dwCode=%#x, dwFlags=%#x, nArgs=%u, lpArguments=%p)\n",
          dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments);

    /* Validate parameters */
    if (dwExceptionCode & RESERVED_SEH_BIT)
    {
        WARN("Exception code %08x has bit 28 set; clearing it.\n", dwExceptionCode);
        dwExceptionCode ^= RESERVED_SEH_BIT;
    }

    PAL_CheckVirtualUnwind();

    EXCEPTION_RECORD exceptionRecord;
    ZeroMemory(&exceptionRecord, sizeof(EXCEPTION_RECORD));

    exceptionRecord.ExceptionCode = dwExceptionCode;
    exceptionRecord.ExceptionFlags = dwExceptionFlags;
    exceptionRecord.ExceptionRecord = NULL;
    exceptionRecord.ExceptionAddress = NULL; // will be set by RtlpRaiseException
    exceptionRecord.NumberParameters = nNumberOfArguments;
    if (nNumberOfArguments)
    {
        if (nNumberOfArguments > EXCEPTION_MAXIMUM_PARAMETERS)
        {
            WARN("Number of arguments (%d) exceeds the limit "
                 "EXCEPTION_MAXIMUM_PARAMETERS (%d); ignoring extra parameters.\n",
                  nNumberOfArguments, EXCEPTION_MAXIMUM_PARAMETERS);
            nNumberOfArguments = EXCEPTION_MAXIMUM_PARAMETERS;
        }
        CopyMemory(exceptionRecord.ExceptionInformation, lpArguments,
                   nNumberOfArguments * sizeof(ULONG_PTR));
    }
    RtlpRaiseException(&exceptionRecord);

    LOGEXIT("RaiseException returns\n");
}

PAL_NORETURN
VOID
PALAPI
PAL_RaiseException(
           IN PEXCEPTION_POINTERS ExceptionPointers)
{
    PAL_CheckVirtualUnwind();
    ExceptionPointers->ExceptionRecord->ExceptionFlags |= EXCEPTION_NONCONTINUABLE;
    SEHRaiseException(InternalGetCurrentThread(), ExceptionPointers, 0);
}

//----------------------------------------------------------------------
// SEH Personality
//----------------------------------------------------------------------

#if defined(__LINUX__) || defined(__APPLE__)
// TODO: Enable these routines for Linux.
EXCEPTION_DISPOSITION
PAL_RunFilter(
    PEXCEPTION_POINTERS ExceptionPointers,
    PAL_DISPATCHER_CONTEXT *DispatcherContext,
    void *pvParam,
    PFN_PAL_EXCEPTION_FILTER Filter)
{
    _ASSERT(FALSE);
    return 0;
}

void PAL_CallRunHandler()
{
    _ASSERT(FALSE);
}

extern "C"
PALAPI
struct _Unwind_Exception *PAL_TryExcept(
    PFN_PAL_BODY pfnBody,
    PFN_PAL_EXCEPTION_FILTER pfnFilter,
    void *pvParam,
    BOOL *pfExecuteHandler)
{
    // UNIXTODO: Exception handling
    pfnBody(pvParam);
    *pfExecuteHandler = FALSE;
    return NULL;
}
#else
// from runfilter.s
extern "C"
EXCEPTION_DISPOSITION
PAL_RunFilter(PEXCEPTION_POINTERS ExceptionPointers,
              PAL_DISPATCHER_CONTEXT *DispatcherContext,
              void *pvParam,
              PFN_PAL_EXCEPTION_FILTER Filter);
extern "C" void PAL_CallRunHandler();
#endif // __LINUX__

extern "C"
_Unwind_Reason_Code PAL_SEHPersonalityRoutine(
    int version,
    _Unwind_Action actions,
    __uint64_t exceptionClass,
    _Unwind_Exception *exceptionObject,
    _Unwind_Context *context)
{
    _Unwind_Reason_Code urc = _URC_NO_REASON;
    PAL_Reenter(PAL_BoundaryEH);

    TRACE("actions=%x\n", actions);
    _ASSERTE(version == 1);

    // Determine what state the frame is in for which this personality routine
    // was invoked.  The only function this personality routine is affiliated
    // with is PAL_TryExcept, which is assembly code.  That function contains
    // two calls: one to run the try block, one to run a handler.  The
    // PAL_CallRunHandler label sits in-between these two, thus we can
    // use it to make the distinction which call the exception escaped from.
    if (_Unwind_GetIP(context) > (void *) PAL_CallRunHandler)
    {
        // This personality routine had invoked the handler associated
        // with this frame, and the handler raised an exception.
        // This is called a "collided unwind".
        TRACE("collided unwind\n");
        PAL_SEHException *pSEHException = PAL_SEHException::FromExceptionObject(exceptionObject);
        if (pSEHException)
        {
            pSEHException->ExceptionRecord.ExceptionFlags |= EXCEPTION_COLLIDED_UNWIND;
        }
        urc = _URC_CONTINUE_UNWIND;
        goto exit;
    }

    if ((actions & _UA_PHASE_MASK) == _UA_SEARCH_PHASE)
    {
        // Determine whether this is an SEH exception or a foreign exception.
        PAL_SEHException *pSEHException = PAL_SEHException::FromExceptionObject(exceptionObject);
        if (pSEHException)
        {
            pSEHException->ExceptionRecord.ExceptionFlags &= ~EXCEPTION_UNWIND;
        }

        // Obtain the filter and parameter from the original frame.
        PFN_PAL_EXCEPTION_FILTER pfnFilter;
        void *pvParam;
#if defined(_PPC_)
        pfnFilter = (PFN_PAL_EXCEPTION_FILTER) _Unwind_GetGR(context, 28);
        pvParam = _Unwind_GetGR(context, 29);
#elif defined(_X86_)
        pfnFilter = ((PFN_PAL_EXCEPTION_FILTER *) _Unwind_GetGR(context, 4))[3]; // [ebp+12]
        pvParam = ((void **) _Unwind_GetGR(context, 4))[4]; // [ebp+16]
#elif defined(_AMD64_)
        // Filter address is stored at RSP+8
        // pvParam is stored at RSP+16
        // Refer to PAL_TryExcept implementation for details.
        pfnFilter = ((PFN_PAL_EXCEPTION_FILTER *) _Unwind_GetCFA(context))[1];
        pvParam = ((void **) _Unwind_GetCFA(context))[2];
#else
#error unsupported architecture
#endif

        // Make some of our state available to the filter.
        PAL_DISPATCHER_CONTEXT dispatcherContext;
        dispatcherContext.actions = actions;
        dispatcherContext.exception_object = exceptionObject;
        dispatcherContext.context = context;

        // Dummy exception record for use by foreign exceptions.
        EXCEPTION_RECORD ForeignExceptionRecord = { EXCEPTION_FOREIGN, EXCEPTION_NONCONTINUABLE, NULL, NULL, 0 };
        EXCEPTION_POINTERS ForeignExceptionPointers = { &ForeignExceptionRecord, NULL };

        // Run the filter.  If this throws, the PAL_SEHFilterPersonalityRoutine
        // will be invoked.
        EXCEPTION_DISPOSITION disposition =
            PAL_RunFilter(pSEHException ? &pSEHException->ExceptionPointers : &ForeignExceptionPointers,
                          &dispatcherContext,
                          pvParam, pfnFilter);
        TRACE("filter returned %d\n", disposition);

        if (pSEHException)
        {
            pSEHException->RanThroughFilter(context);
        }

        switch (disposition)
        {
        case EXCEPTION_CONTINUE_EXECUTION:
            if (!pSEHException || // foreign exceptions are never continuable
                (pSEHException->ExceptionRecord.ExceptionFlags & EXCEPTION_NONCONTINUABLE))
            {
                DeleteThrownException(exceptionObject);
                RaiseException(EXCEPTION_NONCONTINUABLE_EXCEPTION,
                               EXCEPTION_NONCONTINUABLE, 0, NULL);
            }
            else
            {
                CONTEXT *newContext = pSEHException->ExceptionPointers.ContextRecord;
                DeleteThrownException(exceptionObject);
                SetThreadContext(PAL_GetCurrentThread(), newContext);
            }
            abort(); // should never reach here
        case EXCEPTION_EXECUTE_HANDLER:
            urc = _URC_HANDLER_FOUND;
            goto exit;
        case EXCEPTION_CONTINUE_SEARCH:
            urc = _URC_CONTINUE_UNWIND;
            goto exit;
        default:
            DeleteThrownException(exceptionObject);
            RaiseException(EXCEPTION_INVALID_DISPOSITION,
                           EXCEPTION_NONCONTINUABLE, 0, NULL);
            // The above call should never return, but the compiler doesn't know that.
            urc = _URC_FATAL_PHASE1_ERROR;
            goto exit;
        }
    }
    else
    {
        _ASSERTE((actions & _UA_PHASE_MASK)  == _UA_CLEANUP_PHASE);

        // There is a cleanup to run.  Here we behave differently from
        // Windows SEH:  We unwind the stack up to the frame that installed
        // this personality routine, and run the handler from there.
        // The advantage is that this is consistent with C++ on this
        // platform, wich unwinds the stack also to run destructors for
        // objects allocated on the stack.  By behaving in the same way,
        // we can deal with C++ exceptions colliding with SEH unwinds.
#if defined(_PPC_)
        _Unwind_SetGR(context, 3, (void *) actions);
        _Unwind_SetGR(context, 4, exceptionObject);
#elif defined(_X86_)
        void **args = (void **) _Unwind_GetCFA(context);
        args[0] = (void *) actions;
        args[1] = exceptionObject;
#elif defined(_AMD64_)
        // We have allocated two slots on the stack for preserving these two.
        // They are beyond the locations where we spilled the args to PAL_TryExcept
        // and hence, are at RSP+32 and RSP+40 respectively.
        void **args = (void **) _Unwind_GetCFA(context);
        args[4] = (void *) actions;
        args[5] = exceptionObject;
#else
#error unsupported architecture
#endif
        TRACE("unwinding to ip=%p, cfa=%p\n", _Unwind_GetIP(context), _Unwind_GetCFA(context));

        // Fix the context to invoke PAL_CallRunHandler
        _Unwind_SetIP(context, (void *) PAL_CallRunHandler);
        urc = _URC_INSTALL_CONTEXT;
        goto exit;
    }

exit:
    _ASSERTE(urc != _URC_NO_REASON);
    if (urc != _URC_INSTALL_CONTEXT)
    {
        // If we're installing a context, it's because we want to run
        // code that depends on the PAL.  Otherwise, bye-bye.
        PAL_Leave(PAL_BoundaryEH);
    }
    return urc;
}

extern "C"
_Unwind_Exception *PAL_RunHandler(
    _Unwind_Action actions,
    _Unwind_Exception *exceptionObject,
    PFN_PAL_EXCEPTION_FILTER pfnFilter,
    void *pvParam,
    BOOL *pfExecuteHandler)
{
    _ASSERTE((actions & _UA_PHASE_MASK) == _UA_CLEANUP_PHASE);

    PAL_SEHException *pSEHException = PAL_SEHException::FromExceptionObject(exceptionObject);

    PAL_DISPATCHER_CONTEXT dispatcherContext;
    dispatcherContext.actions = actions;
    dispatcherContext.exception_object = exceptionObject;
    dispatcherContext.context = NULL;

    // Dummy exception record for use by foreign exceptions.
    EXCEPTION_RECORD ForeignExceptionRecord = { EXCEPTION_FOREIGN, EXCEPTION_NONCONTINUABLE, NULL, NULL, 0 };
    EXCEPTION_POINTERS ForeignExceptionPointers = { &ForeignExceptionRecord, NULL };
    EXCEPTION_RECORD *pExceptionRecord = &ForeignExceptionRecord;
    if (pSEHException)
    {
        pExceptionRecord = &pSEHException->ExceptionRecord;
    }

    pExceptionRecord->ExceptionFlags =
            (pExceptionRecord->ExceptionFlags & ~(EXCEPTION_UNWINDING|EXCEPTION_TARGET_UNWIND)) |
            EXCEPTION_UNWINDING | ((actions & _UA_HANDLER_FRAME) ? EXCEPTION_TARGET_UNWIND : 0);

    EXCEPTION_DISPOSITION disposition;
    PAL_CPP_TRY
    {
        // MACTODO: Why do we invoke the PAL_EXCEPT macro's filter in the
        // unwind pass when it simply returns with the original disposition that
        // was provided in the first pass?
        disposition = pfnFilter(pSEHException ? &pSEHException->ExceptionPointers : &ForeignExceptionPointers,
                                &dispatcherContext, pvParam);
    }
    PAL_CPP_CATCH_ALL
    {
        // In case of a collided unwind, delete the original exception
        // and propagate the new one instead.
        _Unwind_DeleteException(exceptionObject);
        PAL_CPP_RETHROW;
    }
    PAL_CPP_ENDTRY

    if ((actions & _UA_HANDLER_FRAME) && disposition == EXCEPTION_EXECUTE_HANDLER)
    {
        // Return to PAL_TryExcept, which will return the exception that
        // occurred, so that the PAL_EXCEPT/PAL_FINALLY body will be run.
        *pfExecuteHandler = TRUE;
        return exceptionObject;
    }
    else if (~(actions & _UA_HANDLER_FRAME) && disposition == EXCEPTION_CONTINUE_SEARCH)
    {
        // Cleanups have been run for this frame; continue running cleanups
        // up the stack.
        *pfExecuteHandler = FALSE;
        return exceptionObject;
    }
    else
    {
        // This filter misbehaved; it claimed it would handle/not handle
        // the exception, but it didn't/did.
        DeleteThrownException(exceptionObject);
        RaiseException(EXCEPTION_INVALID_DISPOSITION,
                       EXCEPTION_NONCONTINUABLE, 0, NULL);
        // The above call should never return, but the compiler doesn't know that.
        return NULL;
    }
}

//----------------------------------------------------------------------
// SEH Filter Personality
//----------------------------------------------------------------------

extern "C"
_Unwind_Reason_Code PAL_SEHFilterPersonalityRoutine(
    int version,
    _Unwind_Action actions,
    __uint64_t exceptionClass,
    _Unwind_Exception *exceptionObject,
    _Unwind_Context *context)
{
    PAL_Reenter(PAL_BoundaryEH);

    _ASSERTE(version == 1);

    // When this personality routine runs, we have two activations
    // of _Unwind_RaiseException: The outer _Unwind_RaiseException
    // was running a filter in the search phase, and that filter
    // threw an exception.  This is called a "nested exception".
    // The inner _Unwind_RaiseException activation is dispatching
    // the nested exception, and called this routine.
    TRACE("actions=%x\n", actions);

    // Retrieve the dispatcher context of the outer _Unwind_RaiseException.
    PAL_DISPATCHER_CONTEXT *outerDispatcherContext;
#if defined(_PPC_)
    outerDispatcherContext = (PAL_DISPATCHER_CONTEXT *) _Unwind_GetGR(context, 29);
#elif defined(_X86_)
    outerDispatcherContext = (PAL_DISPATCHER_CONTEXT *) ((void **) _Unwind_GetGR(context, 4))[3]; // [ebp+12]
#elif defined(_AMD64_)
    // Filter address is stored at RSP+8
    // Refer to PAL_RunFilter implementation for details.
    outerDispatcherContext = (PAL_DISPATCHER_CONTEXT *)((void **)_Unwind_GetCFA(context))[1];
#else
#error unsupported architecture
#endif
    _ASSERTE(outerDispatcherContext->actions & _UA_SEARCH_PHASE);

    if ((actions & _UA_PHASE_MASK) == _UA_SEARCH_PHASE)
    {
        TRACE("nested exception\n");
        PAL_SEHException *pSEHException = PAL_SEHException::FromExceptionObject(exceptionObject);
        if (pSEHException)
        {
            pSEHException->NestedIn(outerDispatcherContext->context);
        }
        else
        {
            // A foreign exception escaped from a filter.  This is not a
            // supported action for a filter to take (neither in our SEH
            // model, nor in the unwind library's model).  Let the system
            // execute its (unspecified) behavior.
        }
        PAL_Leave(PAL_BoundaryEH);
        return _URC_CONTINUE_UNWIND;
    }
    else
    {
        _ASSERTE((actions & _UA_PHASE_MASK) == _UA_CLEANUP_PHASE);

        // Rethrowing the exception itself from a filter is not supported.
        // (That would mess up reference counting of the exception object
        // in standard C++.)
        _ASSERT(outerDispatcherContext->exception_object != exceptionObject);

        // We're in the cleanup phase of a nested exception.  This means
        // that nobody fixed up the context of that exception and resumed
        // execution.  In other words, we'll never resume the outer unwind
        // and we have to clean up its state.
        _Unwind_DeleteException(outerDispatcherContext->exception_object);

        // No cleanup to run for a nested exception.
        PAL_Leave(PAL_BoundaryEH);
        return _URC_CONTINUE_UNWIND;
    }
}

#ifdef _PPC_
// This function does not do anything.  It ist just here to be called by
// PAL_TRY, so we can avoid the body of PAL_TRY being translated by the
// compiler into a leaf function (i.e., one that does not set up its
// own frame), because on a hardware fault in a leaf function, we would
// get a stack that would not be unwindable.
EXTERN_C VOID PALAPI PAL_DummyCall()
{
}
#endif // _PPC_