ReactOS 0.4.15-dev-5669-g09dde2c
crt_handler.c File Reference
#include <excpt.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <signal.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
Include dependency graph for crt_handler.c:

Go to the source code of this file.

Classes

struct  _UNWIND_INFO
 

Macros

#define __ImageBase   __MINGW_LSYMBOL(_image_base__)
 
#define GCC_MAGIC   (('G' << 16) | ('C' << 8) | 'C' | (1U << 29))
 

Typedefs

typedef struct _UNWIND_INFO UNWIND_INFO
 
typedef struct _UNWIND_INFOPUNWIND_INFO
 

Functions

PIMAGE_SECTION_HEADER _FindPESectionByName (const char *)
 
PIMAGE_SECTION_HEADER _FindPESectionExec (size_t)
 
PBYTE _GetPEImageBase (void)
 
int __mingw_init_ehandler (void)
 
void __cdecl _fpreset (void)
 
long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS *exception_data)
 

Variables

IMAGE_DOS_HEADER __ImageBase
 
LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler = NULL
 

Macro Definition Documentation

◆ __ImageBase

#define __ImageBase   __MINGW_LSYMBOL(_image_base__)

This file has no copyright assigned and is placed in the Public Domain. This file is part of the w64 mingw-runtime package. No warranty is given; refer to the file DISCLAIMER.PD within this package.

Definition at line 22 of file crt_handler.c.

◆ GCC_MAGIC

#define GCC_MAGIC   (('G' << 16) | ('C' << 8) | 'C' | (1U << 29))

Definition at line 193 of file crt_handler.c.

Typedef Documentation

◆ PUNWIND_INFO

◆ UNWIND_INFO

Function Documentation

◆ __mingw_init_ehandler()

int __mingw_init_ehandler ( void  )

Definition at line 27 of file mscmain.c.

28{
29 /* Nothing to do */
30 return 1;
31}

◆ _FindPESectionByName()

PIMAGE_SECTION_HEADER _FindPESectionByName ( const char pName)

Definition at line 70 of file pesect.c.

71{
72 PBYTE pImageBase;
73 PIMAGE_NT_HEADERS pNTHeader;
74 PIMAGE_SECTION_HEADER pSection;
75 unsigned int iSection;
76
77 /* Long names aren't supported. */
79 return NULL;
80
81 pImageBase = (PBYTE) &__ImageBase;
82 if (! _ValidateImageBase (pImageBase))
83 return NULL;
84
85 pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew);
86
87 for (iSection = 0, pSection = IMAGE_FIRST_SECTION (pNTHeader);
88 iSection < pNTHeader->FileHeader.NumberOfSections;
89 ++iSection,++pSection)
90 {
91 if (!strncmp ((char *) &pSection->Name[0], pName, IMAGE_SIZEOF_SHORT_NAME))
92 return pSection;
93 }
94 return NULL;
95}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define NULL
Definition: types.h:112
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
static LPSTR pName
Definition: security.c:75
DWORD e_lfanew
Definition: crypt.c:1156
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
BYTE * PBYTE
Definition: pedump.c:66
#define IMAGE_SIZEOF_SHORT_NAME
Definition: pedump.c:277
WINBOOL _ValidateImageBase(PBYTE)
Definition: pesect.c:27
IMAGE_DOS_HEADER __ImageBase
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281

◆ _FindPESectionExec()

PIMAGE_SECTION_HEADER _FindPESectionExec ( size_t  eNo)

Definition at line 133 of file pesect.c.

134{
135 PBYTE pImageBase;
136 PIMAGE_NT_HEADERS pNTHeader;
137 PIMAGE_SECTION_HEADER pSection;
138 unsigned int iSection;
139
140 pImageBase = (PBYTE) &__ImageBase;
141 if (! _ValidateImageBase (pImageBase))
142 return NULL;
143
144 pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew);
145
146 for (iSection = 0, pSection = IMAGE_FIRST_SECTION (pNTHeader);
147 iSection < pNTHeader->FileHeader.NumberOfSections;
148 ++iSection,++pSection)
149 {
150 if ((pSection->Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0)
151 {
152 if (!eNo)
153 return pSection;
154 --eNo;
155 }
156 }
157 return NULL;
158}
@ eNo
Definition: precomp.h:73
#define IMAGE_SCN_MEM_EXECUTE
Definition: ntimage.h:239

◆ _fpreset()

void __cdecl _fpreset ( void  )

Definition at line 10 of file _fpreset.c.

11{
12 /* Mask everything */
14}
void _mm_setcsr(unsigned int a)
Definition: xmmintrin.h:542
#define _MM_MASK_MASK
Definition: xmmintrin.h:101

Referenced by _gnu_exception_handler().

◆ _GetPEImageBase()

PBYTE _GetPEImageBase ( void  )

Definition at line 163 of file pesect.c.

164{
165 PBYTE pImageBase;
166 pImageBase = (PBYTE) &__ImageBase;
167 if (! _ValidateImageBase (pImageBase))
168 return NULL;
169 return pImageBase;
170}

◆ _gnu_exception_handler()

long CALLBACK _gnu_exception_handler ( EXCEPTION_POINTERS exception_data)

Definition at line 196 of file crt_handler.c.

197{
198 void (*old_handler) (int);
200 int reset_fpu = 0;
201
202#ifdef __SEH__
203 if ((exception_data->ExceptionRecord->ExceptionCode & 0x20ffffff) == GCC_MAGIC)
204 {
205 if ((exception_data->ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE) == 0)
207 }
208#endif
209
210 switch (exception_data->ExceptionRecord->ExceptionCode)
211 {
213 /* test if the user has set SIGSEGV */
214 old_handler = signal (SIGSEGV, SIG_DFL);
215 if (old_handler == SIG_IGN)
216 {
217 /* this is undefined if the signal was raised by anything other
218 than raise (). */
221 }
222 else if (old_handler != SIG_DFL)
223 {
224 /* This means 'old' is a user defined function. Call it */
225 (*old_handler) (SIGSEGV);
227 }
228 break;
229
232 /* test if the user has set SIGILL */
233 old_handler = signal (SIGILL, SIG_DFL);
234 if (old_handler == SIG_IGN)
235 {
236 /* this is undefined if the signal was raised by anything other
237 than raise (). */
240 }
241 else if (old_handler != SIG_DFL)
242 {
243 /* This means 'old' is a user defined function. Call it */
244 (*old_handler) (SIGILL);
246 }
247 break;
248
255 reset_fpu = 1;
256 /* fall through. */
257
259 /* test if the user has set SIGFPE */
260 old_handler = signal (SIGFPE, SIG_DFL);
261 if (old_handler == SIG_IGN)
262 {
264 if (reset_fpu)
265 _fpreset ();
267 }
268 else if (old_handler != SIG_DFL)
269 {
270 /* This means 'old' is a user defined function. Call it */
271 (*old_handler) (SIGFPE);
273 }
274 break;
275#ifdef _WIN64
281 /*case EXCEPTION_POSSIBLE_DEADLOCK: */
283 break;
284#endif
285 default:
286 break;
287 }
288
290 action = (*__mingw_oldexcpt_handler)(exception_data);
291 return action;
292}
#define SIG_DFL
Definition: signal.h:47
#define SIGILL
Definition: signal.h:25
#define SIGFPE
Definition: signal.h:30
#define SIG_IGN
Definition: signal.h:48
#define SIGSEGV
Definition: signal.h:33
LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler
Definition: crt_handler.c:188
void __cdecl _fpreset(void)
Definition: _fpreset.c:10
#define GCC_MAGIC
Definition: crt_handler.c:193
const WCHAR * action
Definition: action.c:7479
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87
int signal
Definition: except.c:82
PEXCEPTION_RECORD ExceptionRecord
Definition: rtltypes.h:200
DWORD ExceptionCode
Definition: compat.h:208
DWORD ExceptionFlags
Definition: compat.h:209
#define EXCEPTION_FLT_STACK_CHECK
Definition: winbase.h:321
#define EXCEPTION_INT_DIVIDE_BY_ZERO
Definition: winbase.h:323
#define EXCEPTION_FLT_UNDERFLOW
Definition: winbase.h:322
#define EXCEPTION_INT_OVERFLOW
Definition: winbase.h:324
#define EXCEPTION_INVALID_HANDLE
Definition: winbase.h:332
#define EXCEPTION_FLT_OVERFLOW
Definition: winbase.h:320
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
Definition: winbase.h:315
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:312
#define EXCEPTION_FLT_DENORMAL_OPERAND
Definition: winbase.h:316
#define EXCEPTION_FLT_INEXACT_RESULT
Definition: winbase.h:318
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: winbase.h:327
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:311
#define EXCEPTION_FLT_INVALID_OPERATION
Definition: winbase.h:319
#define EXCEPTION_PRIV_INSTRUCTION
Definition: winbase.h:325
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
Definition: winbase.h:317
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:154

Variable Documentation

◆ __ImageBase

IMAGE_DOS_HEADER __ImageBase
extern

◆ __mingw_oldexcpt_handler

LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler = NULL

Definition at line 188 of file crt_handler.c.

Referenced by _gnu_exception_handler().