ReactOS 0.4.16-dev-2104-gb84fa49
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 _NTSYSTEM_
 
#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__)

Definition at line 22 of file crt_handler.c.

◆ _NTSYSTEM_

#define _NTSYSTEM_

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 14 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}
#define NULL
Definition: types.h:112
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3330
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 1591 of file math.c.

1592{
1593#if (defined(__GNUC__) || defined(__clang__)) && defined(__i386__)
1594 const unsigned int x86_cw = 0x27f;
1595 __asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
1596 if (sse2_supported)
1597 {
1598 unsigned int cw = _MCW_EM, sw = 0;
1599 _setfp_sse(&cw, ~0, &sw, ~0);
1600 }
1601#else
1602 unsigned int cw = _MCW_EM, sw = 0;
1603 _setfp(&cw, ~0, &sw, ~0);
1604#endif
1605}
#define _MCW_EM
Definition: float.h:64
BOOL sse2_supported
Definition: math.c:71
static void _setfp(unsigned int *cw, unsigned int cw_mask, unsigned int *sw, unsigned int sw_mask)
Definition: math.c:842
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")

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}
LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler
Definition: crt_handler.c:188
void __cdecl _fpreset(void)
Definition: math.c:1591
#define GCC_MAGIC
Definition: crt_handler.c:193
int signal
Definition: except.c:539
#define SIG_DFL
Definition: signal.h:41
#define SIGILL
Definition: signal.h:26
#define SIGFPE
Definition: signal.h:27
#define SIG_IGN
Definition: signal.h:42
#define SIGSEGV
Definition: signal.h:28
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
action
Definition: namespace.c:707
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:91
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:92
#define EXCEPTION_FLT_STACK_CHECK
Definition: minwinbase.h:54
#define EXCEPTION_INT_DIVIDE_BY_ZERO
Definition: minwinbase.h:56
#define EXCEPTION_FLT_UNDERFLOW
Definition: minwinbase.h:55
#define EXCEPTION_INT_OVERFLOW
Definition: minwinbase.h:57
#define EXCEPTION_INVALID_HANDLE
Definition: minwinbase.h:65
#define EXCEPTION_FLT_OVERFLOW
Definition: minwinbase.h:53
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
Definition: minwinbase.h:48
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: minwinbase.h:45
#define EXCEPTION_FLT_DENORMAL_OPERAND
Definition: minwinbase.h:49
#define EXCEPTION_FLT_INEXACT_RESULT
Definition: minwinbase.h:51
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: minwinbase.h:60
#define EXCEPTION_ACCESS_VIOLATION
Definition: minwinbase.h:44
#define EXCEPTION_FLT_INVALID_OPERATION
Definition: minwinbase.h:52
#define EXCEPTION_PRIV_INSTRUCTION
Definition: minwinbase.h:58
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
Definition: minwinbase.h:50
PEXCEPTION_RECORD ExceptionRecord
Definition: rtltypes.h:200
DWORD ExceptionCode
Definition: compat.h:208
DWORD ExceptionFlags
Definition: compat.h:209
#define EXCEPTION_NONCONTINUABLE
Definition: stubs.h:23

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().