ReactOS  0.4.13-dev-563-g0561610
rtcapi.c
Go to the documentation of this file.
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 #if defined(_M_IX86)
11 #pragma comment(linker, "/alternatename:__CRT_RTC_INITW=__CRT_RTC_INITW0")
12 #elif defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM)
13 #pragma comment(linker, "/alternatename:_CRT_RTC_INITW=_CRT_RTC_INITW0")
14 #else
15 #error Unsupported platform
16 #endif
17 
18 int
19 __cdecl
21  int errType,
22  const wchar_t *file,
23  int line,
24  const wchar_t *module,
25  const wchar_t *format,
26  ...)
27 {
28  /* Simple fallback function */
29  __debugbreak();
30  return 0;
31 }
32 
34 
35 /*
36  Default CRT RTC init, if we don't link to CRT
37 */
39 __cdecl
41  void *_Res0,
42  void **_Res1,
43  int _Res2,
44  int _Res3,
45  int _Res4)
46 {
47  return &_RTC_DefaultErrorFuncW;
48 }
49 
50 void
51 __cdecl
53 {
54  static char initialized = 0;
55  _RTC_error_fnW errorFunc;
56 
57  if (!initialized)
58  {
59  errorFunc = _CRT_RTC_INITW(0, 0, 0, 1, 0);
60  _RTC_SetErrorFuncW(errorFunc);
61  initialized = 1;
62  }
63 }
64 
65 void
66 __cdecl
68 {
69  __debugbreak();
70 }
71 
72 void
73 __cdecl
75 {
76  /* Usually this function would walk an array of function pointers and call
77  each of these, like done with global ctors, but since these are currently
78  only _RTC_InitBase, we simply call that function once. */
79  _RTC_InitBase();
80 }
81 
82 void
83 __cdecl
85  void* retaddr,
86  int errnum)
87 {
88  _RTC_pErrorFuncW(errnum,
89  L"unknown file",
90  -1,
91  L"unknown module",
92  L"Invalid stack pointer value caught at %p, error %d\n",
93  retaddr,
94  errnum);
95 }
96 
97 void
98 __cdecl
100  const char *_Varname)
101 {
103  L"unknown file",
104  -1,
105  L"unknown module",
106  L"Use of uninitialized variable %S!\n",
107  _Varname);
108 }
109 
110 void
113  void *_Esp,
114  _RTC_framedesc *_Fd)
115 {
116  int i, *guard1, *guard2;
117 
118  /* Loop all variables in the descriptor */
119  for (i = 0; i < _Fd->varCount; i++)
120  {
121  /* Get the 2 guards below and above the variable */
122  guard1 = (int*)((char*)_Esp + _Fd->variables[i].addr - sizeof(*guard1));
123  guard2 = (int*)((char*)_Esp + _Fd->variables[i].addr +_Fd->variables[i].size);
124 
125  /* Check if they contain the guard bytes */
126  if ((*guard1 != 0xCCCCCCCC) || (*guard2 != 0xCCCCCCCC))
127  {
129  L"unknown file",
130  -1,
131  L"unknown module",
132  L"Stack corruption near '%s'\n",
133  _Fd->variables[i].name);
134  }
135  }
136 }
137 
138 void
141  void *_Esp,
142  _RTC_framedesc *_Fd,
143  _RTC_ALLOCA_NODE *_AllocaList)
144 {
146  int *guard;
147 
148  /* Process normal variables */
149  _RTC_CheckStackVars(_Esp, _Fd);
150 
151  /* Process the alloca list */
152  for (current = _AllocaList; current != 0; current = current->next)
153  {
154  /* Get the upper guard */
155  guard = (int*)((char*)current + current->allocaSize - sizeof(*guard));
156 
157  /* Check if all guard locations are still ok */
158  if ((current->guard1 != 0xCCCCCCCC) ||
159  (current->guard2[0] != 0xCCCCCCCC) ||
160  (current->guard2[1] != 0xCCCCCCCC) ||
161  (current->guard2[2] != 0xCCCCCCCC) ||
162  (*guard != 0xCCCCCCCC))
163  {
165  L"unknown file",
166  -1,
167  L"unknown module",
168  L"Stack corruption in alloca frame\n");
169  }
170  }
171 }
172 
173 void
176  _RTC_ALLOCA_NODE *_PAllocaBase,
177  size_t _CbSize,
178  _RTC_ALLOCA_NODE **_PAllocaInfoList)
179 {
180  unsigned long i;
181 
182  /* Check if we got any allocation */
183  if ((_PAllocaBase != 0) &&
184  (_CbSize != 0) &&
185  (_PAllocaInfoList != 0))
186  {
187  /* Mark the whole range */
188  char *guard = (char*)_PAllocaBase;
189  for (i = 0; i < _CbSize; i++)
190  {
191  guard[i] = 0xCC;
192  }
193 
194  /* Initialize the alloca base frame */
195  _PAllocaBase->allocaSize = _CbSize;
196 
197  /* Insert this frame into the alloca list */
198  _PAllocaBase->next = *_PAllocaInfoList;
199  *_PAllocaInfoList = _PAllocaBase;
200  }
201 }
202 
#define __cdecl
Definition: accygwin.h:79
#define __fastcall
Definition: sync.c:41
int size
Definition: rtcapi.h:41
void __cdecl _RTC_InitBase(void)
Definition: rtcapi.c:52
void __cdecl _RTC_Shutdown(void)
Definition: rtcapi.c:67
_RTC_error_fnW _RTC_pErrorFuncW
Definition: rtcapi.c:33
int varCount
Definition: rtcapi.h:46
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
size_t allocaSize
Definition: rtcapi.h:58
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_RTC_error_fnW __cdecl _RTC_SetErrorFuncW(_RTC_error_fnW)
Definition: rtcuserapi.c:78
void __cdecl _RTC_Initialize(void)
Definition: rtcapi.c:74
void __cdecl _RTC_Failure(void *retaddr, int errnum)
Definition: rtcapi.c:84
Definition: parser.c:48
void __fastcall _RTC_CheckStackVars(void *_Esp, _RTC_framedesc *_Fd)
Definition: rtcapi.c:112
static BOOL initialized
Definition: syslog.c:39
int addr
Definition: rtcapi.h:40
char * name
Definition: rtcapi.h:42
static const WCHAR L[]
Definition: oid.c:1250
_RTC_error_fnW __cdecl _CRT_RTC_INITW0(void *_Res0, void **_Res1, int _Res2, int _Res3, int _Res4)
Definition: rtcapi.c:40
_RTC_vardesc * variables
Definition: rtcapi.h:47
int(__cdecl * _RTC_error_fnW)(int, const wchar_t *, int, const wchar_t *, const wchar_t *,...)
Definition: rtcapi.h:27
struct _RTC_ALLOCA_NODE * next
Definition: rtcapi.h:54
void __fastcall _RTC_CheckStackVars2(void *_Esp, _RTC_framedesc *_Fd, _RTC_ALLOCA_NODE *_AllocaList)
Definition: rtcapi.c:140
void __cdecl _RTC_UninitUse(const char *_Varname)
Definition: rtcapi.c:99
void __fastcall _RTC_AllocaHelper(_RTC_ALLOCA_NODE *_PAllocaBase, size_t _CbSize, _RTC_ALLOCA_NODE **_PAllocaInfoList)
Definition: rtcapi.c:175
int __cdecl _RTC_DefaultErrorFuncW(int errType, const wchar_t *file, int line, const wchar_t *module, const wchar_t *format,...)
Definition: rtcapi.c:20
struct task_struct * current
Definition: linux.c:32
_RTC_error_fnW __cdecl _CRT_RTC_INITW(void *_Res0, void **_Res1, int _Res2, int _Res3, int _Res4)
Definition: mscmain.c:65
Definition: fci.c:126