1 | /* $Id: except-vcc.h 96559 2022-08-31 01:20:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Visual C++ Compiler - Exception Management.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2022 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.215389.xyz.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef IPRT_INCLUDED_SRC_common_compiler_vcc_except_vcc_h
|
---|
38 | #define IPRT_INCLUDED_SRC_common_compiler_vcc_except_vcc_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #define __C_specific_handler their___C_specific_handler
|
---|
44 | #include <iprt/win/windows.h>
|
---|
45 | #undef __C_specific_handler
|
---|
46 |
|
---|
47 | #include <iprt/types.h>
|
---|
48 | #include <iprt/assertcompile.h>
|
---|
49 |
|
---|
50 |
|
---|
51 | RT_C_DECLS_BEGIN
|
---|
52 |
|
---|
53 | #if 0
|
---|
54 | /** This is part of the AMD64 and ARM (?) exception interface, but appear to
|
---|
55 | * live in the runtime headers for some weird reason. */
|
---|
56 | typedef enum
|
---|
57 | {
|
---|
58 | ExceptionContinueExecution = 0,
|
---|
59 | ExceptionContinueSearch,
|
---|
60 | ExceptionNestedException,
|
---|
61 | ExceptionCollidedUnwind
|
---|
62 | } EXCEPTION_DISPOSITION;
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | /* The following two are borrowed from pecoff.h, as we typically want to include
|
---|
66 | winnt.h with this header and the two header cannot co-exist. */
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * An unwind code for AMD64 and ARM64.
|
---|
70 | *
|
---|
71 | * @note Also known as UNWIND_CODE or _UNWIND_CODE.
|
---|
72 | */
|
---|
73 | typedef union IMAGE_UNWIND_CODE
|
---|
74 | {
|
---|
75 | struct
|
---|
76 | {
|
---|
77 | /** The prolog offset where the change takes effect.
|
---|
78 | * This means the instruction following the one being described. */
|
---|
79 | uint8_t CodeOffset;
|
---|
80 | /** Unwind opcode.
|
---|
81 | * For AMD64 see IMAGE_AMD64_UNWIND_OP_CODES. */
|
---|
82 | RT_GCC_EXTENSION uint8_t UnwindOp : 4;
|
---|
83 | /** Opcode specific. */
|
---|
84 | RT_GCC_EXTENSION uint8_t OpInfo : 4;
|
---|
85 | } u;
|
---|
86 | uint16_t FrameOffset;
|
---|
87 | } IMAGE_UNWIND_CODE;
|
---|
88 | AssertCompileSize(IMAGE_UNWIND_CODE, 2);
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * Unwind information for AMD64 and ARM64.
|
---|
92 | *
|
---|
93 | * Pointed to by IMAGE_RUNTIME_FUNCTION_ENTRY::UnwindInfoAddress,
|
---|
94 | *
|
---|
95 | * @note Also known as UNWIND_INFO or _UNWIND_INFO.
|
---|
96 | */
|
---|
97 | typedef struct IMAGE_UNWIND_INFO
|
---|
98 | {
|
---|
99 | /** Version, currently 1 or 2. The latter if IMAGE_AMD64_UWOP_EPILOG is used. */
|
---|
100 | RT_GCC_EXTENSION uint8_t Version : 3;
|
---|
101 | /** IMAGE_UNW_FLAG_XXX */
|
---|
102 | RT_GCC_EXTENSION uint8_t Flags : 5;
|
---|
103 | /** Size of function prolog. */
|
---|
104 | uint8_t SizeOfProlog;
|
---|
105 | /** Number of opcodes in aOpcodes. */
|
---|
106 | uint8_t CountOfCodes;
|
---|
107 | /** Initial frame register. */
|
---|
108 | RT_GCC_EXTENSION uint8_t FrameRegister : 4;
|
---|
109 | /** Scaled frame register offset. */
|
---|
110 | RT_GCC_EXTENSION uint8_t FrameOffset : 4;
|
---|
111 | /** Unwind opcodes. */
|
---|
112 | RT_FLEXIBLE_ARRAY_EXTENSION
|
---|
113 | IMAGE_UNWIND_CODE aOpcodes[RT_FLEXIBLE_ARRAY];
|
---|
114 | } IMAGE_UNWIND_INFO;
|
---|
115 | AssertCompileMemberOffset(IMAGE_UNWIND_INFO, aOpcodes, 4);
|
---|
116 | typedef IMAGE_UNWIND_INFO *PIMAGE_UNWIND_INFO;
|
---|
117 | typedef IMAGE_UNWIND_INFO const *PCIMAGE_UNWIND_INFO;
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 | #ifdef RT_ARCH_AMD64
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * The Visual C++ 2019 layout of the GS_HANDLER_DATA data type for AMD64.
|
---|
125 | *
|
---|
126 | * This is pointed to by DISPATCHER_CONTEXT::HandlerData when dispatching
|
---|
127 | * exceptions. The data resides after the unwind info for the function.
|
---|
128 | */
|
---|
129 | typedef struct _GS_HANDLER_DATA
|
---|
130 | {
|
---|
131 | union
|
---|
132 | {
|
---|
133 | struct
|
---|
134 | {
|
---|
135 | uint32_t fEHandler : 1;
|
---|
136 | #define GS_HANDLER_OFF_COOKIE_IS_EHANDLER RT_BIT(0) /**< Handles exceptions. */
|
---|
137 | uint32_t fUHandler : 1;
|
---|
138 | #define GS_HANDLER_OFF_COOKIE_IS_UHANDLER RT_BIT(1) /**< Handles unwind. */
|
---|
139 | uint32_t fHasAlignment : 1;
|
---|
140 | #define GS_HANDLER_OFF_COOKIE_HAS_ALIGNMENT RT_BIT(2) /**< Has the uAlignmentMask member. */
|
---|
141 | } Bits;
|
---|
142 | #define GS_HANDLER_OFF_COOKIE_MASK UINT32_C(0xfffffff8) /**< Mask to apply to offCookie to the the value. */
|
---|
143 | uint32_t offCookie;
|
---|
144 | } u;
|
---|
145 | int32_t offAlignedBase;
|
---|
146 | /** This field is only there when GS_HANDLER_OFF_COOKIE_HAS_ALIGNMENT is set.
|
---|
147 | * it seems. */
|
---|
148 | uint32_t uAlignmentMask;
|
---|
149 | } GS_HANDLER_DATA;
|
---|
150 | typedef GS_HANDLER_DATA *PGS_HANDLER_DATA;
|
---|
151 | typedef GS_HANDLER_DATA const *PCGS_HANDLER_DATA;
|
---|
152 | #endif
|
---|
153 |
|
---|
154 | #ifdef RT_ARCH_X86
|
---|
155 | void __fastcall __security_check_cookie(uintptr_t uCookieToCheck);
|
---|
156 | #else
|
---|
157 | void __cdecl __security_check_cookie(uintptr_t uCookieToCheck);
|
---|
158 | #endif
|
---|
159 |
|
---|
160 | #if defined(RT_ARCH_AMD64)
|
---|
161 | EXCEPTION_DISPOSITION __C_specific_handler(PEXCEPTION_RECORD pXcptRec, PEXCEPTION_REGISTRATION_RECORD pXcptRegRec,
|
---|
162 | PCONTEXT pCpuCtx, PDISPATCHER_CONTEXT pDispCtx);
|
---|
163 | #endif
|
---|
164 |
|
---|
165 | RT_C_DECLS_END
|
---|
166 |
|
---|
167 | #endif /* !IPRT_INCLUDED_SRC_common_compiler_vcc_except_vcc_h */
|
---|
168 |
|
---|