1 | /* $Id: stacksup-vcc.cpp 95832 2022-07-26 11:53:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - No-CRT - Basic allocators, Windows.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.alldomusa.eu.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include "internal/iprt.h"
|
---|
32 | #include <iprt/assert.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*********************************************************************************************************************************
|
---|
36 | * Structures and Typedefs *
|
---|
37 | *********************************************************************************************************************************/
|
---|
38 | /** Variable descriptor. */
|
---|
39 | typedef struct RTC_VAR_DESC_T
|
---|
40 | {
|
---|
41 | int32_t offFrame;
|
---|
42 | uint32_t cbVar;
|
---|
43 | const char *pszName;
|
---|
44 | } RTC_VAR_DESC_T;
|
---|
45 |
|
---|
46 | /** Frame descriptor. */
|
---|
47 | typedef struct RTC_FRAME_DESC_T
|
---|
48 | {
|
---|
49 | uint32_t cVars;
|
---|
50 | RTC_VAR_DESC_T const *paVars;
|
---|
51 | } RTC_FRAME_DESC_T;
|
---|
52 |
|
---|
53 | #define VARIABLE_MARKER_PRE 0xcccccccc
|
---|
54 | #define VARIABLE_MARKER_POST 0xcccccccc
|
---|
55 |
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Alloca allocation entry.
|
---|
59 | * @note For whatever reason the pNext and cb members are misaligned on 64-bit
|
---|
60 | * targets. 32-bit targets OTOH adds padding to keep the structure size
|
---|
61 | * and pNext + cb offsets the same.
|
---|
62 | */
|
---|
63 | #pragma pack(4)
|
---|
64 | typedef struct RTC_ALLOC_ENTRY
|
---|
65 | {
|
---|
66 | uint32_t uGuard1;
|
---|
67 | RTC_ALLOC_ENTRY *pNext;
|
---|
68 | #if ARCH_BITS == 32
|
---|
69 | uint32_t pNextPad;
|
---|
70 | #endif
|
---|
71 | size_t cb;
|
---|
72 | #if ARCH_BITS == 32
|
---|
73 | uint32_t cbPad;
|
---|
74 | #endif
|
---|
75 | uint32_t auGuard2[3];
|
---|
76 | } RTC_ALLOC_ENTRY;
|
---|
77 | #pragma pack()
|
---|
78 |
|
---|
79 | #define ALLOCA_FILLER_BYTE 0xcc
|
---|
80 | #define ALLOCA_FILLER_32 0xcccccccc
|
---|
81 |
|
---|
82 |
|
---|
83 | /*********************************************************************************************************************************
|
---|
84 | * External Symbols *
|
---|
85 | *********************************************************************************************************************************/
|
---|
86 | extern "C" void __fastcall _RTC_CheckStackVars(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar); /* nocrt-stack.asm */
|
---|
87 | extern "C" uintptr_t __security_cookie;
|
---|
88 |
|
---|
89 |
|
---|
90 | DECLASM(void) _RTC_StackVarCorrupted(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar)
|
---|
91 | {
|
---|
92 | RTAssertMsg2("\n\n!!Stack corruption!!\n\n"
|
---|
93 | "%p LB %#x - %s\n",
|
---|
94 | pbFrame + pVar->offFrame, pVar->cbVar, pVar->pszName);
|
---|
95 | RT_BREAKPOINT();
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | DECLASM(void) _RTC_SecurityCookieMismatch(uintptr_t uCookie)
|
---|
100 | {
|
---|
101 | RTAssertMsg2("\n\n!!Stack cookie corruption!!\n\n"
|
---|
102 | "expected %p, found %p\n",
|
---|
103 | __security_cookie, uCookie);
|
---|
104 | RT_BREAKPOINT();
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | /** @todo reimplement in assembly (feeling too lazy right now). */
|
---|
109 | extern "C" void __fastcall _RTC_CheckStackVars2(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar, RTC_ALLOC_ENTRY *pHead)
|
---|
110 | {
|
---|
111 | while (pHead)
|
---|
112 | {
|
---|
113 | if ( pHead->uGuard1 == ALLOCA_FILLER_32
|
---|
114 | #if 1 && ARCH_BITS == 32
|
---|
115 | && pHead->pNextPad == ALLOCA_FILLER_32
|
---|
116 | && pHead->cbPad == ALLOCA_FILLER_32
|
---|
117 | #endif
|
---|
118 | && pHead->auGuard2[0] == ALLOCA_FILLER_32
|
---|
119 | && pHead->auGuard2[1] == ALLOCA_FILLER_32
|
---|
120 | && pHead->auGuard2[2] == ALLOCA_FILLER_32
|
---|
121 | && *(uint32_t const *)((uint8_t const *)pHead + pHead->cb - sizeof(uint32_t)) == ALLOCA_FILLER_32)
|
---|
122 | { /* likely */ }
|
---|
123 | else
|
---|
124 | {
|
---|
125 | RTAssertMsg2("\n\n!!Stack corruption (alloca)!!\n\n"
|
---|
126 | "%p LB %#x\n",
|
---|
127 | pHead, pHead->cb);
|
---|
128 | RT_BREAKPOINT();
|
---|
129 | }
|
---|
130 | pHead = pHead->pNext;
|
---|
131 | }
|
---|
132 |
|
---|
133 | _RTC_CheckStackVars(pbFrame, pVar);
|
---|
134 | }
|
---|