summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp
blob: 1e858214223ada1ec0364ef7258ce8fe61d628f9 (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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*=====================================================================
**
** Source:  dlltest2.c (exception_handling\pal_sxs\test1)
**
** Purpose: Test to make sure the PAL_EXCEPT block is executed
**          after an exception occurs in the PAL_TRY block with
**          multiple PALs in the process.
**
**
**===================================================================*/
#include <palsuite.h>

extern "C"
int InitializeDllTest2()
{
    return PAL_InitializeDLL();
}

BOOL bTry    = FALSE;
BOOL bExcept = FALSE;

extern "C"
int DllTest2()
{
    Trace("Starting pal_sxs test1 DllTest2\n");

    PAL_TRY(VOID*, unused, NULL)
    {
        volatile int* p = (volatile int *)0x22; // Invalid pointer

        bTry = TRUE;                            // Indicate we hit the PAL_TRY block
        *p = 2;                                 // Causes an access violation exception

        Fail("ERROR: code was executed after the access violation.\n");
    }
    PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
    {
        if (!bTry)
        {
            Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n");
        }

        // Validate that the faulting address is correct; the contents of "p" (0x22).
        if (ex.GetExceptionRecord()->ExceptionInformation[1] != 0x22)
        {
            Fail("ERROR: PAL_EXCEPT ExceptionInformation[1] != 0x22\n");
        }

        bExcept = TRUE;                         // Indicate we hit the PAL_EXCEPT block
    }
    PAL_ENDTRY;

    if (!bTry)
    {
        Trace("ERROR: the code in the PAL_TRY block was not executed.\n");
    }

    if (!bExcept)
    {
        Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n");
    }

    // Did we hit all the code blocks?
    if(!bTry || !bExcept)
    {
        Fail("DllTest2 FAILED\n");
    }

    Trace("DLLTest2 PASSED\n");
    return PASS;
}