mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 07:43:12 +00:00
[CRT]
Sync startup code with mingw-w64, reduce difference a bit, remaining changes were passed upstream svn path=/trunk/; revision=56359
This commit is contained in:
parent
45aa7bfa9d
commit
8b5d4fe0e3
12 changed files with 153 additions and 87 deletions
|
@ -16,6 +16,13 @@ extern "C" {
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
#ifdef __REACTOS__
|
||||||
|
#include "malloc.h"
|
||||||
|
__declspec(dllimport) void __setusermatherr(int (__cdecl *)(struct _exception *));
|
||||||
|
#define __mingw_fprintf fprintf
|
||||||
|
#define __mingw_vfprintf vfprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma pack(push,_CRT_PACKING)
|
#pragma pack(push,_CRT_PACKING)
|
||||||
|
|
||||||
#ifndef __INTERNAL_FUNC_DEFINED
|
#ifndef __INTERNAL_FUNC_DEFINED
|
||||||
|
@ -155,7 +162,7 @@ extern char ** __MINGW_IMP_SYMBOL(_wcmdln);
|
||||||
#define _GUI_APP 2
|
#define _GUI_APP 2
|
||||||
|
|
||||||
typedef enum __enative_startup_state {
|
typedef enum __enative_startup_state {
|
||||||
__uninitialized, __initializing, __initialized
|
__uninitialized = 0, __initializing, __initialized
|
||||||
} __enative_startup_state;
|
} __enative_startup_state;
|
||||||
|
|
||||||
extern volatile __enative_startup_state __native_startup_state;
|
extern volatile __enative_startup_state __native_startup_state;
|
||||||
|
|
|
@ -34,6 +34,7 @@ list(APPEND MSVCRTEX_SOURCE
|
||||||
startup/crt0_c.c
|
startup/crt0_c.c
|
||||||
startup/crt0_w.c
|
startup/crt0_w.c
|
||||||
startup/dllentry.c
|
startup/dllentry.c
|
||||||
|
startup/reactos.c
|
||||||
misc/fltused.c
|
misc/fltused.c
|
||||||
misc/ofmt_stub.c
|
misc/ofmt_stub.c
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,12 +33,8 @@
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
extern void __cdecl _initterm(_PVFV *,_PVFV *);
|
extern void __cdecl _initterm(_PVFV *,_PVFV *);
|
||||||
|
extern void __main ();
|
||||||
#if defined(__GNUC__)
|
|
||||||
extern void __main (void);
|
|
||||||
extern void _pei386_runtime_relocator (void);
|
extern void _pei386_runtime_relocator (void);
|
||||||
#endif
|
|
||||||
|
|
||||||
extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[];
|
extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[];
|
||||||
extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[];
|
extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[];
|
||||||
extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[];
|
extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[];
|
||||||
|
@ -101,15 +97,18 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
|
||||||
}
|
}
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
}
|
}
|
||||||
if (__native_startup_state != __uninitialized)
|
if (__native_startup_state == __initializing)
|
||||||
{
|
{
|
||||||
_amsg_exit (31);
|
_amsg_exit (31);
|
||||||
}
|
}
|
||||||
else
|
else if (__native_startup_state == __uninitialized)
|
||||||
{
|
{
|
||||||
__native_startup_state = __initializing;
|
__native_startup_state = __initializing;
|
||||||
|
|
||||||
_initterm ((_PVFV *) (void *) __xi_a, (_PVFV *) (void *) __xi_z);
|
_initterm ((_PVFV *) (void *) __xi_a, (_PVFV *) (void *) __xi_z);
|
||||||
|
}
|
||||||
|
if (__native_startup_state == __initializing)
|
||||||
|
{
|
||||||
_initterm (__xc_a, __xc_z);
|
_initterm (__xc_a, __xc_z);
|
||||||
__native_startup_state = __initialized;
|
__native_startup_state = __initialized;
|
||||||
}
|
}
|
||||||
|
@ -183,9 +182,7 @@ __DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
|
||||||
retcode = FALSE;
|
retcode = FALSE;
|
||||||
goto i__leave;
|
goto i__leave;
|
||||||
}
|
}
|
||||||
#if defined(__GNUC__)
|
|
||||||
_pei386_runtime_relocator ();
|
_pei386_runtime_relocator ();
|
||||||
#endif
|
|
||||||
if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
|
if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
|
||||||
{
|
{
|
||||||
retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
|
retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
|
||||||
|
@ -199,10 +196,8 @@ __DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
|
||||||
goto i__leave;
|
goto i__leave;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(__GNUC__)
|
|
||||||
if (dwReason == DLL_PROCESS_ATTACH)
|
if (dwReason == DLL_PROCESS_ATTACH)
|
||||||
__main ();
|
__main ();
|
||||||
#endif
|
|
||||||
retcode = DllMain(hDllHandle,dwReason,lpreserved);
|
retcode = DllMain(hDllHandle,dwReason,lpreserved);
|
||||||
if (dwReason == DLL_PROCESS_ATTACH && ! retcode)
|
if (dwReason == DLL_PROCESS_ATTACH && ! retcode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <sect_attribs.h>
|
#include <sect_attribs.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <malloc.h>
|
|
||||||
|
|
||||||
#ifndef __winitenv
|
#ifndef __winitenv
|
||||||
extern wchar_t *** __MINGW_IMP_SYMBOL(__winitenv);
|
extern wchar_t *** __MINGW_IMP_SYMBOL(__winitenv);
|
||||||
|
@ -44,8 +43,6 @@ extern void _fpreset (void);
|
||||||
#define SPACECHAR _T(' ')
|
#define SPACECHAR _T(' ')
|
||||||
#define DQUOTECHAR _T('\"')
|
#define DQUOTECHAR _T('\"')
|
||||||
|
|
||||||
__declspec(dllimport) void __setusermatherr(int (__cdecl *)(struct _exception *));
|
|
||||||
|
|
||||||
extern int * __MINGW_IMP_SYMBOL(_fmode);
|
extern int * __MINGW_IMP_SYMBOL(_fmode);
|
||||||
extern int * __MINGW_IMP_SYMBOL(_commode);
|
extern int * __MINGW_IMP_SYMBOL(_commode);
|
||||||
|
|
||||||
|
@ -55,14 +52,6 @@ extern int * __MINGW_IMP_SYMBOL(_commode);
|
||||||
#define _commode (* __MINGW_IMP_SYMBOL(_commode))
|
#define _commode (* __MINGW_IMP_SYMBOL(_commode))
|
||||||
extern int _dowildcard;
|
extern int _dowildcard;
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
int _MINGW_INSTALL_DEBUG_MATHERR __attribute__((weak)) = 0;
|
|
||||||
#else
|
|
||||||
int __declspec(selectany) _MINGW_INSTALL_DEBUG_MATHERR = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern int __defaultmatherr;
|
|
||||||
|
|
||||||
extern _CRTIMP void __cdecl _initterm(_PVFV *, _PVFV *);
|
extern _CRTIMP void __cdecl _initterm(_PVFV *, _PVFV *);
|
||||||
|
|
||||||
static int __cdecl check_managed_app (void);
|
static int __cdecl check_managed_app (void);
|
||||||
|
@ -85,12 +74,7 @@ _TCHAR *__mingw_winmain_lpCmdLine;
|
||||||
DWORD __mingw_winmain_nShowCmd;
|
DWORD __mingw_winmain_nShowCmd;
|
||||||
|
|
||||||
static int argc;
|
static int argc;
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
extern void __main(void);
|
extern void __main(void);
|
||||||
extern void _pei386_runtime_relocator (void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WPRFLAG
|
#ifdef WPRFLAG
|
||||||
static wchar_t **argv;
|
static wchar_t **argv;
|
||||||
static wchar_t **envp;
|
static wchar_t **envp;
|
||||||
|
@ -106,7 +90,7 @@ static int has_cctor = 0;
|
||||||
static _startupinfo startinfo;
|
static _startupinfo startinfo;
|
||||||
extern LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler;
|
extern LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler;
|
||||||
|
|
||||||
|
extern void _pei386_runtime_relocator (void);
|
||||||
long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS * exception_data);
|
long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS * exception_data);
|
||||||
#ifdef WPRFLAG
|
#ifdef WPRFLAG
|
||||||
static void duplicate_ppstrings (int ac, wchar_t ***av);
|
static void duplicate_ppstrings (int ac, wchar_t ***av);
|
||||||
|
@ -117,8 +101,10 @@ static void duplicate_ppstrings (int ac, char ***av);
|
||||||
static int __cdecl pre_c_init (void);
|
static int __cdecl pre_c_init (void);
|
||||||
static void __cdecl pre_cpp_init (void);
|
static void __cdecl pre_cpp_init (void);
|
||||||
static void __cdecl __mingw_prepare_except_for_msvcr80_and_higher (void);
|
static void __cdecl __mingw_prepare_except_for_msvcr80_and_higher (void);
|
||||||
_CRTALLOC(".CRT$XIAA") _PIFV __declspec(selectany) mingw_pcinit = pre_c_init;
|
_CRTALLOC(".CRT$XIAA") _PIFV mingw_pcinit = pre_c_init;
|
||||||
_CRTALLOC(".CRT$XCAA") _PVFV __declspec(selectany) mingw_pcppinit = pre_cpp_init;
|
_CRTALLOC(".CRT$XCAA") _PVFV mingw_pcppinit = pre_cpp_init;
|
||||||
|
|
||||||
|
extern int _MINGW_INSTALL_DEBUG_MATHERR;
|
||||||
|
|
||||||
static int __cdecl
|
static int __cdecl
|
||||||
pre_c_init (void)
|
pre_c_init (void)
|
||||||
|
@ -138,7 +124,7 @@ pre_c_init (void)
|
||||||
#else
|
#else
|
||||||
_setargv();
|
_setargv();
|
||||||
#endif
|
#endif
|
||||||
if (_MINGW_INSTALL_DEBUG_MATHERR)
|
if (_MINGW_INSTALL_DEBUG_MATHERR == 1)
|
||||||
{
|
{
|
||||||
__setusermatherr (_matherr);
|
__setusermatherr (_matherr);
|
||||||
}
|
}
|
||||||
|
@ -224,13 +210,15 @@ __tmainCRTStartup (void)
|
||||||
WINBOOL inDoubleQuote = FALSE;
|
WINBOOL inDoubleQuote = FALSE;
|
||||||
memset (&StartupInfo, 0, sizeof (STARTUPINFO));
|
memset (&StartupInfo, 0, sizeof (STARTUPINFO));
|
||||||
|
|
||||||
#if !defined(_WIN64) && defined(__GNUC__)
|
#ifndef _WIN64
|
||||||
/* We need to make sure that this function is build with frame-pointer
|
/* We need to make sure that this function is build with frame-pointer
|
||||||
and that we align the stack to 16 bytes for the sake of SSE ops in main
|
and that we align the stack to 16 bytes for the sake of SSE ops in main
|
||||||
or in functions inlined into main. */
|
or in functions inlined into main. */
|
||||||
lpszCommandLine = (_TCHAR *) alloca (32);
|
lpszCommandLine = (_TCHAR *) alloca (32);
|
||||||
memset (lpszCommandLine, 0xcc, 32);
|
memset (lpszCommandLine, 0xcc, 32);
|
||||||
|
#ifdef __GNUC__
|
||||||
asm __volatile__ ("andl $-16, %%esp" : : : "%esp");
|
asm __volatile__ ("andl $-16, %%esp" : : : "%esp");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mingw_app_type)
|
if (mingw_app_type)
|
||||||
|
@ -273,11 +261,9 @@ __tmainCRTStartup (void)
|
||||||
if (__dyn_tls_init_callback != NULL)
|
if (__dyn_tls_init_callback != NULL)
|
||||||
__dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);
|
__dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
_pei386_runtime_relocator ();
|
_pei386_runtime_relocator ();
|
||||||
#endif
|
|
||||||
__mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler);
|
__mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler);
|
||||||
#if defined(_WIN64) && !defined(_MSC_VER)
|
#ifdef _WIN64
|
||||||
__mingw_init_ehandler ();
|
__mingw_init_ehandler ();
|
||||||
#endif
|
#endif
|
||||||
__mingw_prepare_except_for_msvcr80_and_higher ();
|
__mingw_prepare_except_for_msvcr80_and_higher ();
|
||||||
|
@ -313,9 +299,7 @@ __tmainCRTStartup (void)
|
||||||
StartupInfo.wShowWindow : SW_SHOWDEFAULT;
|
StartupInfo.wShowWindow : SW_SHOWDEFAULT;
|
||||||
}
|
}
|
||||||
duplicate_ppstrings (argc, &argv);
|
duplicate_ppstrings (argc, &argv);
|
||||||
#if defined(__GNUC__)
|
|
||||||
__main ();
|
__main ();
|
||||||
#endif
|
|
||||||
#ifdef WPRFLAG
|
#ifdef WPRFLAG
|
||||||
__winitenv = envp;
|
__winitenv = envp;
|
||||||
/* C++ initialization.
|
/* C++ initialization.
|
||||||
|
@ -395,7 +379,7 @@ static void duplicate_ppstrings (int ac, wchar_t ***av)
|
||||||
avl=*av;
|
avl=*av;
|
||||||
for (i=0; i < ac; i++)
|
for (i=0; i < ac; i++)
|
||||||
{
|
{
|
||||||
int l = wbytelen (avl[i]);
|
size_t l = wbytelen (avl[i]);
|
||||||
n[i] = (wchar_t *) malloc (l);
|
n[i] = (wchar_t *) malloc (l);
|
||||||
memcpy (n[i], avl[i], l);
|
memcpy (n[i], avl[i], l);
|
||||||
}
|
}
|
||||||
|
@ -412,7 +396,7 @@ static void duplicate_ppstrings (int ac, char ***av)
|
||||||
avl=*av;
|
avl=*av;
|
||||||
for (i=0; i < ac; i++)
|
for (i=0; i < ac; i++)
|
||||||
{
|
{
|
||||||
int l = strlen (avl[i]) + 1;
|
size_t l = strlen (avl[i]) + 1;
|
||||||
n[i] = (char *) malloc (l);
|
n[i] = (char *) malloc (l);
|
||||||
memcpy (n[i], avl[i], l);
|
memcpy (n[i], avl[i], l);
|
||||||
}
|
}
|
||||||
|
@ -439,21 +423,14 @@ __mingw_invalidParameterHandler (const wchar_t * __UNUSED_PARAM_1(expression),
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HANDLE __mingw_get_msvcrt_handle(void);
|
||||||
|
|
||||||
static void __cdecl
|
static void __cdecl
|
||||||
__mingw_prepare_except_for_msvcr80_and_higher (void)
|
__mingw_prepare_except_for_msvcr80_and_higher (void)
|
||||||
{
|
{
|
||||||
_invalid_parameter_handler (*fIPH)(_invalid_parameter_handler) = NULL;
|
_invalid_parameter_handler (*fIPH)(_invalid_parameter_handler) = NULL;
|
||||||
HMODULE hmsv = GetModuleHandleA ("msvcr80.dll");
|
|
||||||
if(!hmsv)
|
fIPH = (void*)GetProcAddress (__mingw_get_msvcrt_handle(), "_set_invalid_parameter_handler");
|
||||||
hmsv = GetModuleHandleA ("msvcr70.dll");
|
|
||||||
if (!hmsv)
|
|
||||||
hmsv = GetModuleHandleA ("msvcrt.dll");
|
|
||||||
if (!hmsv)
|
|
||||||
hmsv = LoadLibraryA ("msvcrt.dll");
|
|
||||||
if (!hmsv)
|
|
||||||
return;
|
|
||||||
fIPH = (_invalid_parameter_handler (*)(_invalid_parameter_handler))
|
|
||||||
GetProcAddress (hmsv, "_set_invalid_parameter_handler");
|
|
||||||
if (fIPH)
|
if (fIPH)
|
||||||
(*fIPH)(__mingw_invalidParameterHandler);
|
(*fIPH)(__mingw_invalidParameterHandler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,10 +97,10 @@ __security_init_cookie (void)
|
||||||
#define _AddressOfReturnAddress() __builtin_frame_address (0)
|
#define _AddressOfReturnAddress() __builtin_frame_address (0)
|
||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
__declspec(noreturn) void __cdecl __report_gsfailure (ULONGLONG);
|
__declspec(noreturn) void __cdecl __report_gsfailure (ULONG_PTR);
|
||||||
|
|
||||||
__declspec(noreturn) void __cdecl
|
__declspec(noreturn) void __cdecl
|
||||||
__report_gsfailure (ULONGLONG StackCookie)
|
__report_gsfailure (ULONG_PTR StackCookie)
|
||||||
{
|
{
|
||||||
volatile UINT_PTR cookie[2] __MINGW_ATTRIB_UNUSED;
|
volatile UINT_PTR cookie[2] __MINGW_ATTRIB_UNUSED;
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int __defaultmatherr = 0;
|
|
||||||
|
|
||||||
typedef int (__cdecl *fUserMathErr)(struct _exception *);
|
typedef int (__cdecl *fUserMathErr)(struct _exception *);
|
||||||
static fUserMathErr stUserMathErr;
|
static fUserMathErr stUserMathErr;
|
||||||
|
|
||||||
|
@ -20,7 +18,7 @@ void __mingw_raise_matherr (int typ, const char *name, double a1, double a2,
|
||||||
if (!stUserMathErr)
|
if (!stUserMathErr)
|
||||||
return;
|
return;
|
||||||
ex.type = typ;
|
ex.type = typ;
|
||||||
ex.name = name;
|
ex.name = (char*)name;
|
||||||
ex.arg1 = a1;
|
ex.arg1 = a1;
|
||||||
ex.arg2 = a2;
|
ex.arg2 = a2;
|
||||||
ex.retval = rslt;
|
ex.retval = rslt;
|
||||||
|
@ -71,7 +69,7 @@ _matherr (struct _exception *pexcept)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "_matherr(): %s in %s(%g, %g) (retval=%g)\n",
|
__mingw_fprintf (stderr, "_matherr(): %s in %s(%g, %g) (retval=%g)\n",
|
||||||
type, pexcept->name, pexcept->arg1, pexcept->arg2, pexcept->retval);
|
type, pexcept->name, pexcept->arg1, pexcept->arg2, pexcept->retval);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void _pei386_runtime_relocator(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int __mingw_init_ehandler(void)
|
int __mingw_init_ehandler(void)
|
||||||
{
|
{
|
||||||
/* Nothing to do */
|
/* Nothing to do */
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
#if defined (_WIN64) && defined (__ia64__)
|
#if defined (_WIN64) && defined (__ia64__)
|
||||||
#error FIXME: Unsupported __ImageBase implementation.
|
#error FIXME: Unsupported __ImageBase implementation.
|
||||||
#else
|
#else
|
||||||
|
#ifdef __GNUC__
|
||||||
/* Hack, for bug in ld. Will be removed soon. */
|
/* Hack, for bug in ld. Will be removed soon. */
|
||||||
#ifndef _MSC_VER
|
|
||||||
#define __ImageBase __MINGW_LSYMBOL(_image_base__)
|
#define __ImageBase __MINGW_LSYMBOL(_image_base__)
|
||||||
#endif
|
#endif
|
||||||
/* This symbol is defined by the linker. */
|
/* This symbol is defined by the linker. */
|
||||||
|
@ -184,3 +184,75 @@ _IsNonwritableInCurrentImage (PBYTE pTarget)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return (pSection->Characteristics & IMAGE_SCN_MEM_WRITE) == 0;
|
return (pSection->Characteristics & IMAGE_SCN_MEM_WRITE) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
__mingw_enum_import_library_names (int);
|
||||||
|
|
||||||
|
const char *
|
||||||
|
__mingw_enum_import_library_names (int i)
|
||||||
|
{
|
||||||
|
PBYTE pImageBase;
|
||||||
|
PIMAGE_NT_HEADERS pNTHeader;
|
||||||
|
PIMAGE_IMPORT_DESCRIPTOR importDesc;
|
||||||
|
PIMAGE_SECTION_HEADER pSection;
|
||||||
|
DWORD importsStartRVA;
|
||||||
|
|
||||||
|
pImageBase = (PBYTE) &__ImageBase;
|
||||||
|
if (! _ValidateImageBase (pImageBase))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew);
|
||||||
|
|
||||||
|
importsStartRVA = pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
|
||||||
|
if (!importsStartRVA)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
pSection = _FindPESection (pImageBase, importsStartRVA);
|
||||||
|
if (!pSection)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
importDesc = (PIMAGE_IMPORT_DESCRIPTOR) (pImageBase + importsStartRVA);
|
||||||
|
if (!importDesc)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (importDesc->TimeDateStamp == 0 && importDesc->Name == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (i <= 0)
|
||||||
|
return (char *) (pImageBase + importDesc->Name);
|
||||||
|
--i;
|
||||||
|
importDesc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
HMODULE __mingw_get_msvcrt_handle(void);
|
||||||
|
HMODULE __mingw_get_msvcrt_handle(void)
|
||||||
|
{
|
||||||
|
static HANDLE msvcrt_handle;
|
||||||
|
|
||||||
|
if(!msvcrt_handle) {
|
||||||
|
const char *lib_name;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while ((lib_name = __mingw_enum_import_library_names (i++))) {
|
||||||
|
if((lib_name[0] == 'm' || lib_name[0] == 'M')
|
||||||
|
&& (lib_name[1] == 's' || lib_name[1] == 'S')
|
||||||
|
&& (lib_name[2] == 'v' || lib_name[2] == 'V')
|
||||||
|
&& (lib_name[3] == 'c' || lib_name[3] == 'C')
|
||||||
|
&& (lib_name[4] == 'r' || lib_name[4] == 'R')
|
||||||
|
&& (lib_name[5] == 't' || lib_name[5] == 'T' || ('0' <= lib_name[5] && lib_name[5] <= '9')))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lib_name)
|
||||||
|
msvcrt_handle = GetModuleHandleA(lib_name);
|
||||||
|
if(!msvcrt_handle)
|
||||||
|
msvcrt_handle = LoadLibraryW(L"msvcrt.dll");
|
||||||
|
}
|
||||||
|
|
||||||
|
return msvcrt_handle;
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <malloc.h>
|
#include <internal.h>
|
||||||
|
|
||||||
#if defined(__CYGWIN__)
|
#if defined(__CYGWIN__)
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
@ -146,11 +146,12 @@ __report_error (const char *msg, ...)
|
||||||
va_list argp;
|
va_list argp;
|
||||||
va_start (argp, msg);
|
va_start (argp, msg);
|
||||||
# ifdef __MINGW64_VERSION_MAJOR
|
# ifdef __MINGW64_VERSION_MAJOR
|
||||||
fprintf (stderr, "Mingw-w64 runtime failure:\n");
|
__mingw_fprintf (stderr, "Mingw-w64 runtime failure:\n");
|
||||||
|
__mingw_vfprintf (stderr, msg, argp);
|
||||||
# else
|
# else
|
||||||
fprintf (stderr, "Mingw runtime failure:\n");
|
fprintf (stderr, "Mingw runtime failure:\n");
|
||||||
# endif
|
|
||||||
vfprintf (stderr, msg, argp);
|
vfprintf (stderr, msg, argp);
|
||||||
|
#endif
|
||||||
va_end (argp);
|
va_end (argp);
|
||||||
abort ();
|
abort ();
|
||||||
#endif
|
#endif
|
||||||
|
@ -206,8 +207,13 @@ mark_section_writable (LPVOID addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
|
if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
|
||||||
VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE,
|
{
|
||||||
&the_secs[i].old_protect);
|
if (!VirtualProtect (b.BaseAddress, b.RegionSize,
|
||||||
|
PAGE_EXECUTE_READWRITE,
|
||||||
|
&the_secs[i].old_protect))
|
||||||
|
__report_error (" VirtualProtect failed with code 0x%x",
|
||||||
|
(int) GetLastError ());
|
||||||
|
}
|
||||||
++maxSections;
|
++maxSections;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -253,15 +259,17 @@ restore_modified_sections (void)
|
||||||
static void
|
static void
|
||||||
__write_memory (void *addr, const void *src, size_t len)
|
__write_memory (void *addr, const void *src, size_t len)
|
||||||
{
|
{
|
||||||
#ifndef __MINGW64_VERSION_MAJOR
|
|
||||||
MEMORY_BASIC_INFORMATION b;
|
MEMORY_BASIC_INFORMATION b;
|
||||||
DWORD oldprot;
|
DWORD oldprot;
|
||||||
#endif /* ! __MINGW64_VERSION_MAJOR */
|
int call_unprotect = 0;
|
||||||
|
|
||||||
if (!len)
|
if (!len)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifndef __MINGW64_VERSION_MAJOR
|
#ifdef __MINGW64_VERSION_MAJOR
|
||||||
|
mark_section_writable ((LPVOID) addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!VirtualQuery (addr, &b, sizeof(b)))
|
if (!VirtualQuery (addr, &b, sizeof(b)))
|
||||||
{
|
{
|
||||||
__report_error (" VirtualQuery failed for %d bytes at address %p",
|
__report_error (" VirtualQuery failed for %d bytes at address %p",
|
||||||
|
@ -270,19 +278,17 @@ __write_memory (void *addr, const void *src, size_t len)
|
||||||
|
|
||||||
/* Temporarily allow write access to read-only protected memory. */
|
/* Temporarily allow write access to read-only protected memory. */
|
||||||
if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
|
if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
|
||||||
|
{
|
||||||
|
call_unprotect = 1;
|
||||||
VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE,
|
VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE,
|
||||||
&oldprot);
|
&oldprot);
|
||||||
#else /* ! __MINGW64_VERSION_MAJOR */
|
}
|
||||||
mark_section_writable ((LPVOID) addr);
|
|
||||||
#endif /* __MINGW64_VERSION_MAJOR */
|
|
||||||
|
|
||||||
/* write the data. */
|
/* write the data. */
|
||||||
memcpy (addr, src, len);
|
memcpy (addr, src, len);
|
||||||
/* Restore original protection. */
|
/* Restore original protection. */
|
||||||
#ifndef __MINGW64_VERSION_MAJOR
|
if (call_unprotect && b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
|
||||||
if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
|
|
||||||
VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot);
|
VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot);
|
||||||
#endif /* !__MINGW64_VERSION_MAJOR */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RP_VERSION_V1 0
|
#define RP_VERSION_V1 0
|
||||||
|
|
3
reactos/lib/sdk/crt/startup/reactos.c
Normal file
3
reactos/lib/sdk/crt/startup/reactos.c
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
int _MINGW_INSTALL_DEBUG_MATHERR = 0;
|
||||||
|
|
|
@ -10,3 +10,4 @@
|
||||||
otherwise
|
otherwise
|
||||||
we do tls cleanup in runtime and _CRT_MT has value 2. */
|
we do tls cleanup in runtime and _CRT_MT has value 2. */
|
||||||
int _CRT_MT = 2;
|
int _CRT_MT = 2;
|
||||||
|
|
||||||
|
|
|
@ -9,5 +9,7 @@
|
||||||
#define _UNICODE
|
#define _UNICODE
|
||||||
#define mainCRTStartup wmainCRTStartup
|
#define mainCRTStartup wmainCRTStartup
|
||||||
#define WinMainCRTStartup wWinMainCRTStartup
|
#define WinMainCRTStartup wWinMainCRTStartup
|
||||||
|
#define mingw_pcinit mingw_pwcinit
|
||||||
|
#define mingw_pcppinit mingw_pwcppinit
|
||||||
|
|
||||||
#include "crtexe.c"
|
#include "crtexe.c"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue