ReactOS  0.4.14-dev-376-gaedba84
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 }

Referenced by __declspec().

◆ _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
DWORD e_lfanew
Definition: crypt.c:1156
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
WINBOOL _ValidateImageBase(PBYTE)
Definition: pesect.c:27
smooth NULL
Definition: ftsmooth.c:416
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
static LPSTR pName
Definition: security.c:75
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define IMAGE_SIZEOF_SHORT_NAME
Definition: pedump.c:277
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281
IMAGE_DOS_HEADER __ImageBase
Definition: mstscax.cpp:17
BYTE * PBYTE
Definition: pedump.c:66
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187

◆ _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 }
DWORD e_lfanew
Definition: crypt.c:1156
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
WINBOOL _ValidateImageBase(PBYTE)
Definition: pesect.c:27
smooth NULL
Definition: ftsmooth.c:416
Definition: precomp.h:73
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
IMAGE_DOS_HEADER __ImageBase
Definition: mstscax.cpp:17
BYTE * PBYTE
Definition: pedump.c:66
#define IMAGE_SCN_MEM_EXECUTE
Definition: ntimage.h:239
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187

◆ _fpreset()

void __cdecl _fpreset ( void  )

Definition at line 13 of file fpreset.c.

14 {
15  const unsigned short x86_cw = 0x27f;
16 #ifdef _MSC_VER
17  __asm { fninit }
18  __asm { fldcw [x86_cw] }
19 #else
20  __asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
21 #endif
23  {
24  const unsigned long sse2_cw = 0x1f80;
25 #ifdef _MSC_VER
26  __asm { ldmxcsr [sse2_cw] }
27 #else
28  __asm__ __volatile__( "ldmxcsr %0" : : "m" (sse2_cw) );
29 #endif
30  }
31 }
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
BOOL WINAPI IsProcessorFeaturePresent(IN DWORD ProcessorFeature)
Definition: sysinfo.c:168
#define PF_XMMI64_INSTRUCTIONS_AVAILABLE

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 }
WINBOOL _ValidateImageBase(PBYTE)
Definition: pesect.c:27
smooth NULL
Definition: ftsmooth.c:416
IMAGE_DOS_HEADER __ImageBase
Definition: mstscax.cpp:17
BYTE * PBYTE
Definition: pedump.c:66

◆ _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 (). */
238  signal (SIGILL, SIG_IGN);
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  {
263  signal (SIGFPE, SIG_IGN);
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 EXCEPTION_FLT_UNDERFLOW
Definition: winbase.h:319
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define EXCEPTION_INT_DIVIDE_BY_ZERO
Definition: winbase.h:320
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:308
#define EXCEPTION_INVALID_HANDLE
Definition: winbase.h:329
#define EXCEPTION_INT_OVERFLOW
Definition: winbase.h:321
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
#define SIGILL
Definition: signal.h:25
#define EXCEPTION_FLT_INVALID_OPERATION
Definition: winbase.h:316
#define SIG_DFL
Definition: signal.h:47
DWORD ExceptionCode
Definition: compat.h:196
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler
Definition: crt_handler.c:188
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
Definition: winbase.h:314
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
Definition: winbase.h:312
#define SIGFPE
Definition: signal.h:30
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:309
int signal
Definition: xcptfil.c:12
#define EXCEPTION_FLT_DENORMAL_OPERAND
Definition: winbase.h:313
#define SIGSEGV
Definition: signal.h:33
const WCHAR * action
Definition: action.c:7783
void __cdecl _fpreset(void)
Definition: fpreset.c:13
#define EXCEPTION_FLT_OVERFLOW
Definition: winbase.h:317
#define EXCEPTION_FLT_STACK_CHECK
Definition: winbase.h:318
#define GCC_MAGIC
Definition: crt_handler.c:193
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: winbase.h:324
DWORD ExceptionFlags
Definition: compat.h:197
PEXCEPTION_RECORD ExceptionRecord
Definition: rtltypes.h:196
#define SIG_IGN
Definition: signal.h:48
#define EXCEPTION_PRIV_INSTRUCTION
Definition: winbase.h:322
#define EXCEPTION_FLT_INEXACT_RESULT
Definition: winbase.h:315
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87

Referenced by __declspec().

Variable Documentation

◆ __ImageBase

IMAGE_DOS_HEADER __ImageBase

Definition at line 17 of file mstscax.cpp.

◆ __mingw_oldexcpt_handler

LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler = NULL

Definition at line 188 of file crt_handler.c.

Referenced by __declspec(), and _gnu_exception_handler().