ReactOS 0.4.15-dev-7889-g76290a6
gs_support.c
Go to the documentation of this file.
1
6#define _NTSYSTEM_
7#ifndef WIN32_LEAN_AND_MEAN
8#define WIN32_LEAN_AND_MEAN
9#endif
10#define WIN32_NO_STATUS
11#include <stdlib.h> /* abort () */
12//#include <windows.h>
13#include <stdarg.h>
14#include <windef.h>
15#include <winbase.h>
16#undef WIN32_NO_STATUS
17#include <ntstatus.h> /* STATUS macros */
18#ifdef _WIN64
19#include <intrin.h>
20#endif
21
22#ifdef _WIN64
23#define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll
24#else
25#define DEFAULT_SECURITY_COOKIE 0xBB40E64E
26#endif
27
28/* Externals. */
29
30typedef LONG NTSTATUS; /* same as in ntdef.h / winternl.h */
31
32#define UNW_FLAG_NHANDLER 0x00
33
34typedef union
35{
38} FT;
39
40#ifndef _MSC_VER
43
46};
47#endif
48
51
53
54void __cdecl
56{
58 FT systime = { 0, };
59 LARGE_INTEGER perfctr;
60
62 {
63 __security_cookie_complement = ~__security_cookie;
64 return;
65 }
66
68#ifdef _WIN64
69 cookie = systime.ft_scalar;
70#else
73#endif
74
77 cookie ^= GetTickCount ();
78
79 QueryPerformanceCounter (&perfctr);
80#ifdef _WIN64
81 cookie ^= perfctr.QuadPart;
82#else
83 cookie ^= perfctr.LowPart;
84 cookie ^= perfctr.HighPart;
85#endif
86
87#ifdef _WIN64
88 cookie &= 0x0000ffffffffffffll;
89#endif
90
95}
96
97
98#if defined(__GNUC__) /* wrap msvc intrinsics onto gcc builtins */
99#undef _ReturnAddress
100#undef _AddressOfReturnAddress
101#define _ReturnAddress() __builtin_return_address(0)
102#define _AddressOfReturnAddress() __builtin_frame_address (0)
103#endif /* __GNUC__ */
104
105__declspec(noreturn) void __cdecl __report_gsfailure (ULONG_PTR);
106
107#ifndef _MSC_VER
108__declspec(noreturn) void __cdecl
109__report_gsfailure (ULONG_PTR StackCookie)
110{
112#ifdef _WIN64
113 ULONG64 controlPC, imgBase, establisherFrame;
114 PRUNTIME_FUNCTION fctEntry;
115 PVOID hndData;
116
118 controlPC = GS_ContextRecord.Rip;
119 fctEntry = RtlLookupFunctionEntry(controlPC, &imgBase, NULL);
120 if (fctEntry != NULL)
121 {
122 RtlVirtualUnwind (UNW_FLAG_NHANDLER, imgBase, controlPC, fctEntry,
123 &GS_ContextRecord, &hndData, &establisherFrame, NULL);
124 }
125 else
126#endif /* _WIN64 */
127 {
128#ifdef _WIN64
131#else
134#endif /* _WIN64 */
135 }
136
137#ifdef _WIN64
139 GS_ContextRecord.Rcx = StackCookie;
140#else
142 GS_ContextRecord.Ecx = StackCookie;
143#endif /* _WIN64 */
151 abort();
152}
153#endif /* !_MSC_VER */
#define __MINGW_ATTRIB_UNUSED
Definition: _mingw.h:124
#define __cdecl
Definition: accygwin.h:79
#define __int64
Definition: basetyps.h:16
#define NULL
Definition: types.h:112
#define GetCurrentProcess()
Definition: compat.h:759
LONG WINAPI UnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: except.c:269
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI DECLSPEC_HOTPATCH SetUnhandledExceptionFilter(IN LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
Definition: except.c:790
BOOL WINAPI QueryPerformanceCounter(OUT PLARGE_INTEGER lpPerformanceCount)
Definition: perfcnt.c:23
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
#define UNW_FLAG_NHANDLER
Definition: gs_support.c:32
static EXCEPTION_RECORD GS_ExceptionRecord
Definition: gs_support.c:41
static CONTEXT GS_ContextRecord
Definition: gs_support.c:42
#define DEFAULT_SECURITY_COOKIE
Definition: gs_support.c:25
LONG NTSTATUS
Definition: gs_support.c:30
__declspec(noreturn)
Definition: gs_support.c:105
void __cdecl __security_init_cookie(void)
Definition: gs_support.c:55
DECLSPEC_SELECTANY UINT_PTR __security_cookie_complement
Definition: gs_support.c:50
DECLSPEC_SELECTANY UINT_PTR __security_cookie
Definition: gs_support.c:49
static const EXCEPTION_POINTERS GS_ExceptionPointers
Definition: gs_support.c:44
#define abort()
Definition: i386-dis.c:34
#define _ReturnAddress()
Definition: intrin_arm.h:35
#define _AddressOfReturnAddress()
Definition: intrin_ppc.h:40
unsigned __int64 ULONG64
Definition: imports.h:198
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
NTSYSAPI VOID NTAPI RtlCaptureContext(_Out_ PCONTEXT ContextRecord)
#define DWORD
Definition: nt_native.h:44
#define STATUS_STACK_BUFFER_OVERRUN
Definition: ntstatus.h:946
long LONG
Definition: pedump.c:60
#define DECLSPEC_SELECTANY
Definition: guiddef.h:40
ULONG Esp
Definition: nt_native.h:1479
ULONG Ecx
Definition: nt_native.h:1467
ULONG Eip
Definition: nt_native.h:1476
DWORD ExceptionCode
Definition: compat.h:208
DWORD ExceptionFlags
Definition: compat.h:209
PVOID ExceptionAddress
Definition: compat.h:211
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
Definition: cookie.c:34
#define EXCEPTION_NONCONTINUABLE
Definition: stubs.h:23
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint64_t ULONGLONG
Definition: typedefs.h:67
Definition: gs_support.c:35
unsigned __int64 ft_scalar
Definition: gs_support.c:36
FILETIME ft_struct
Definition: gs_support.c:37
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
PEXCEPTION_ROUTINE NTAPI RtlVirtualUnwind(_In_ ULONG HandlerType, _In_ ULONG64 ImageBase, _In_ ULONG64 ControlPc, _In_ PRUNTIME_FUNCTION FunctionEntry, _Inout_ PCONTEXT Context, _Outptr_ PVOID *HandlerData, _Out_ PULONG64 EstablisherFrame, _Inout_opt_ PKNONVOLATILE_CONTEXT_POINTERS ContextPointers)
Definition: unwind.c:478
PRUNTIME_FUNCTION NTAPI RtlLookupFunctionEntry(IN DWORD64 ControlPc, OUT PDWORD64 ImageBase, OUT PUNWIND_HISTORY_TABLE HistoryTable)
Locates the RUNTIME_FUNCTION entry corresponding to a code address. http://msdn.microsoft....
Definition: unwind.c:124
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158