[CMAKE/MSVC]
[reactos.git] / reactos / lib / sdk / runtmchk / rtcapi.c
1 /*
2 * PROJECT: MSVC runtime check support library
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * PURPOSE: Provides support functions for MSVC runtime checks
5 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
6 */
7
8 #include <rtcapi.h>
9
10 unsigned long
11 __cdecl
12 DbgPrint(
13 const char *fmt, ...);
14
15 void
16 _RTC_InitBase(void)
17 {
18 __debugbreak();
19 }
20
21 void
22 _RTC_Shutdown(void)
23 {
24 __debugbreak();
25 }
26
27 void
28 __cdecl
29 _RTC_Failure(
30 void* retaddr,
31 int errnum)
32 {
33 __debugbreak();
34 }
35
36 void
37 __cdecl
38 _RTC_UninitUse(
39 const char *_Varname)
40 {
41 __debugbreak();
42 }
43
44 void
45 __fastcall
46 _RTC_CheckStackVars(
47 void *_Esp,
48 _RTC_framedesc *_Fd)
49 {
50 int i, *guard1, *guard2;
51
52 /* Loop all variables in the descriptor */
53 for (i = 0; i < _Fd->varCount; i++)
54 {
55 /* Get the 2 guards below and above the variable */
56 guard1 = (int*)((char*)_Esp + _Fd->variables[i].addr - sizeof(*guard1));
57 guard2 = (int*)((char*)_Esp + _Fd->variables[i].addr +_Fd->variables[i].size);
58
59 /* Check if they contain the guard bytes */
60 if ((*guard1 != 0xCCCCCCCC) || (*guard2 != 0xCCCCCCCC))
61 {
62 __debugbreak();
63 }
64 }
65 }
66
67 void
68 __fastcall
69 _RTC_CheckStackVars2(
70 void *_Esp,
71 _RTC_framedesc *_Fd,
72 _RTC_ALLOCA_NODE *_AllocaList)
73 {
74 _RTC_ALLOCA_NODE *current;
75 int *guard;
76
77 /* Process normal variables */
78 _RTC_CheckStackVars(_Esp, _Fd);
79
80 /* Process the alloca list */
81 for (current = _AllocaList; current != 0; current = current->next)
82 {
83 /* Get the upper guard */
84 guard = (int*)((char*)current + current->allocaSize - sizeof(*guard));
85
86 /* Check if all guard locations are still ok */
87 if ((current->guard1 != 0xCCCCCCCC) ||
88 (current->guard2[0] != 0xCCCCCCCC) ||
89 (current->guard2[1] != 0xCCCCCCCC) ||
90 (current->guard2[2] != 0xCCCCCCCC) ||
91 (*guard != 0xCCCCCCCC))
92 {
93 __debugbreak();
94 }
95 }
96 }
97
98 void
99 __fastcall
100 _RTC_AllocaHelper(
101 _RTC_ALLOCA_NODE *_PAllocaBase,
102 size_t _CbSize,
103 _RTC_ALLOCA_NODE **_PAllocaInfoList)
104 {
105 unsigned long i;
106
107 /* Check if we got any allocation */
108 if ((_PAllocaBase != 0) &&
109 (_CbSize != 0) &&
110 (_PAllocaInfoList != 0))
111 {
112 /* Mark the whole range */
113 char *guard = (char*)_PAllocaBase;
114 for (i = 0; i < _CbSize; i++)
115 {
116 guard[i] = 0xCC;
117 }
118
119 /* Initialize the alloca base frame */
120 _PAllocaBase->allocaSize = _CbSize;
121
122 /* Insert this frame into the alloca list */
123 _PAllocaBase->next = *_PAllocaInfoList;
124 *_PAllocaInfoList = _PAllocaBase;
125 }
126 }