From 9369532afaa2410d030b0163579ae47d89e02300 Mon Sep 17 00:00:00 2001 From: Samuel Serapion Date: Sat, 30 Aug 2008 16:50:58 +0000 Subject: [PATCH] Commit WIP. Part 2 of ?? Update mingw32 runtime to mingw-w64 trunk -Support for msvc 7.0 features -TLS support disabled because ros is not ready svn path=/branches/ros-amd64-bringup/; revision=35809 --- reactos/lib/3rdparty/mingw/CRT_fp10.c | 4 + reactos/lib/3rdparty/mingw/CRTfmode.c | 16 - reactos/lib/3rdparty/mingw/CRTglob.c | 16 - reactos/lib/3rdparty/mingw/CRTinit.c | 24 - reactos/lib/3rdparty/mingw/_newmode.c | 1 + reactos/lib/3rdparty/mingw/_wgetopt.c | 15 - reactos/lib/3rdparty/mingw/argv.c | 19 + reactos/lib/3rdparty/mingw/atonexit.c | 50 ++ reactos/lib/3rdparty/mingw/binmode.c | 7 +- reactos/lib/3rdparty/mingw/charmax.c | 9 + reactos/lib/3rdparty/mingw/cinitexe.c | 7 + reactos/lib/3rdparty/mingw/cpu_features.c | 105 ---- reactos/lib/3rdparty/mingw/cpu_features.h | 25 - reactos/lib/3rdparty/mingw/crt0_c.c | 6 + reactos/lib/3rdparty/mingw/crt0_w.c | 9 + reactos/lib/3rdparty/mingw/crt1.c | 297 ----------- reactos/lib/3rdparty/mingw/crtdll.c | 201 ++++++++ reactos/lib/3rdparty/mingw/crtexe.c | 469 ++++++++++++++++++ reactos/lib/3rdparty/mingw/dllcrt1.c | 185 ------- reactos/lib/3rdparty/mingw/dllentry.c | 8 + reactos/lib/3rdparty/mingw/dllmain.c | 9 + reactos/lib/3rdparty/mingw/gccmain.c | 52 +- reactos/lib/3rdparty/mingw/getopt.c | 137 ----- reactos/lib/3rdparty/mingw/gs_support.c | 129 +++++ reactos/lib/3rdparty/mingw/init.c | 67 --- reactos/lib/3rdparty/mingw/internal.h | 171 +++++++ reactos/lib/3rdparty/mingw/isascii.c | 21 - reactos/lib/3rdparty/mingw/iscsym.c | 20 - reactos/lib/3rdparty/mingw/iscsymf.c | 21 - reactos/lib/3rdparty/mingw/main.c | 79 --- reactos/lib/3rdparty/mingw/merr.c | 12 + reactos/lib/3rdparty/mingw/mingw.rbuild | 49 +- reactos/lib/3rdparty/mingw/mingw_helpers.c | 25 + .../lib/3rdparty/mingw/moldname-msvcrt.def | 10 - reactos/lib/3rdparty/mingw/natstart.c | 7 + reactos/lib/3rdparty/mingw/oscalls.h | 41 ++ reactos/lib/3rdparty/mingw/pesect.c | 66 +++ reactos/lib/3rdparty/mingw/strcasecmp.c | 21 - reactos/lib/3rdparty/mingw/strncasecmp.c | 21 - reactos/lib/3rdparty/mingw/tgetopt.h | 90 ---- reactos/lib/3rdparty/mingw/tlssup.c | 129 +++++ reactos/lib/3rdparty/mingw/toascii.c | 22 - reactos/lib/3rdparty/mingw/wbinmode.c | 5 - reactos/lib/3rdparty/mingw/wcrt1.c | 295 ----------- reactos/lib/3rdparty/mingw/wcscmpi.c | 21 - reactos/lib/3rdparty/mingw/wildcard.c | 1 + reactos/lib/3rdparty/mingw/winit.c | 66 --- reactos/lib/3rdparty/mingw/wmain.c | 86 ---- reactos/lib/3rdparty/mingw/xncommod.c | 1 + reactos/lib/3rdparty/mingw/xthdloc.c | 1 + reactos/lib/3rdparty/mingw/xtxtmode.c | 1 + 51 files changed, 1423 insertions(+), 1726 deletions(-) create mode 100644 reactos/lib/3rdparty/mingw/CRT_fp10.c delete mode 100644 reactos/lib/3rdparty/mingw/CRTfmode.c delete mode 100644 reactos/lib/3rdparty/mingw/CRTglob.c delete mode 100644 reactos/lib/3rdparty/mingw/CRTinit.c create mode 100644 reactos/lib/3rdparty/mingw/_newmode.c delete mode 100644 reactos/lib/3rdparty/mingw/_wgetopt.c create mode 100644 reactos/lib/3rdparty/mingw/argv.c create mode 100644 reactos/lib/3rdparty/mingw/atonexit.c create mode 100644 reactos/lib/3rdparty/mingw/charmax.c create mode 100644 reactos/lib/3rdparty/mingw/cinitexe.c delete mode 100644 reactos/lib/3rdparty/mingw/cpu_features.c delete mode 100644 reactos/lib/3rdparty/mingw/cpu_features.h create mode 100644 reactos/lib/3rdparty/mingw/crt0_c.c create mode 100644 reactos/lib/3rdparty/mingw/crt0_w.c delete mode 100644 reactos/lib/3rdparty/mingw/crt1.c create mode 100644 reactos/lib/3rdparty/mingw/crtdll.c create mode 100644 reactos/lib/3rdparty/mingw/crtexe.c delete mode 100644 reactos/lib/3rdparty/mingw/dllcrt1.c create mode 100644 reactos/lib/3rdparty/mingw/dllentry.c create mode 100644 reactos/lib/3rdparty/mingw/dllmain.c delete mode 100644 reactos/lib/3rdparty/mingw/getopt.c create mode 100644 reactos/lib/3rdparty/mingw/gs_support.c delete mode 100644 reactos/lib/3rdparty/mingw/init.c create mode 100644 reactos/lib/3rdparty/mingw/internal.h delete mode 100644 reactos/lib/3rdparty/mingw/isascii.c delete mode 100644 reactos/lib/3rdparty/mingw/iscsym.c delete mode 100644 reactos/lib/3rdparty/mingw/iscsymf.c delete mode 100644 reactos/lib/3rdparty/mingw/main.c create mode 100644 reactos/lib/3rdparty/mingw/merr.c create mode 100644 reactos/lib/3rdparty/mingw/mingw_helpers.c create mode 100644 reactos/lib/3rdparty/mingw/natstart.c create mode 100644 reactos/lib/3rdparty/mingw/oscalls.h create mode 100644 reactos/lib/3rdparty/mingw/pesect.c delete mode 100644 reactos/lib/3rdparty/mingw/strcasecmp.c delete mode 100644 reactos/lib/3rdparty/mingw/strncasecmp.c delete mode 100644 reactos/lib/3rdparty/mingw/tgetopt.h create mode 100644 reactos/lib/3rdparty/mingw/tlssup.c delete mode 100644 reactos/lib/3rdparty/mingw/toascii.c delete mode 100644 reactos/lib/3rdparty/mingw/wbinmode.c delete mode 100644 reactos/lib/3rdparty/mingw/wcrt1.c delete mode 100644 reactos/lib/3rdparty/mingw/wcscmpi.c create mode 100644 reactos/lib/3rdparty/mingw/wildcard.c delete mode 100644 reactos/lib/3rdparty/mingw/winit.c delete mode 100644 reactos/lib/3rdparty/mingw/wmain.c create mode 100644 reactos/lib/3rdparty/mingw/xncommod.c create mode 100644 reactos/lib/3rdparty/mingw/xthdloc.c create mode 100644 reactos/lib/3rdparty/mingw/xtxtmode.c diff --git a/reactos/lib/3rdparty/mingw/CRT_fp10.c b/reactos/lib/3rdparty/mingw/CRT_fp10.c new file mode 100644 index 00000000000..d12ffa7c8d9 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/CRT_fp10.c @@ -0,0 +1,4 @@ +void _fpreset (void) + { __asm__ ("fninit" ) ;} + +void __attribute__ ((alias ("_fpreset"))) fpreset(void); diff --git a/reactos/lib/3rdparty/mingw/CRTfmode.c b/reactos/lib/3rdparty/mingw/CRTfmode.c deleted file mode 100644 index 31c1f63bf21..00000000000 --- a/reactos/lib/3rdparty/mingw/CRTfmode.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * CRTfmode.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Include this object to set _CRT_fmode to a state that will cause - * _mingw32_init_fmode to leave all file modes in their default state - * (basically text mode). - * - * To use this object include the object file in your link command: - * gcc -o foo.exe foo.o CRTfmode.o - * - */ - -int _CRT_fmode = 0; diff --git a/reactos/lib/3rdparty/mingw/CRTglob.c b/reactos/lib/3rdparty/mingw/CRTglob.c deleted file mode 100644 index a4f5fe051f9..00000000000 --- a/reactos/lib/3rdparty/mingw/CRTglob.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * CRTglob.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Include this object file to set _CRT_glob to a state that will - * turn on command line globbing by default. NOTE: _CRT_glob has a default - * state of on. Specify CRT_noglob.o to turn off globbing by default. - * - * To use this object include the object file in your link command: - * gcc -o foo.exe foo.o CRTglob.o - * - */ - -int _CRT_glob = -1; diff --git a/reactos/lib/3rdparty/mingw/CRTinit.c b/reactos/lib/3rdparty/mingw/CRTinit.c deleted file mode 100644 index d0a472dbb18..00000000000 --- a/reactos/lib/3rdparty/mingw/CRTinit.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * CRTinit.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * A dummy version of _CRT_INIT for MS compatibility. Programs, or more often - * dlls, which use the static version of the MSVC run time are supposed to - * call _CRT_INIT to initialize the run time library in DllMain. This does - * not appear to be necessary when using crtdll or the dll versions of the - * MSVC runtime, so the dummy call simply does nothing. - * - * This object file is included as a standard in the link process as provided - * by the appropriate GCC frontend. - * - * To use this object include the object file in your link command: - * gcc -o foo.exe foo.o CRTinit.o - * - */ - -void -_CRT_INIT () -{ -} diff --git a/reactos/lib/3rdparty/mingw/_newmode.c b/reactos/lib/3rdparty/mingw/_newmode.c new file mode 100644 index 00000000000..fb6962135bc --- /dev/null +++ b/reactos/lib/3rdparty/mingw/_newmode.c @@ -0,0 +1 @@ +int _newmode = 0; diff --git a/reactos/lib/3rdparty/mingw/_wgetopt.c b/reactos/lib/3rdparty/mingw/_wgetopt.c deleted file mode 100644 index 91efed4d702..00000000000 --- a/reactos/lib/3rdparty/mingw/_wgetopt.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $Id$ -*/ -/* - tgetopt -- POSIX-compliant implementation of getopt() with string-type-generic - semantics - - This is public domain software -*/ - -#include - -#define _UNICODE -#include "getopt.c" - -/* EOF */ diff --git a/reactos/lib/3rdparty/mingw/argv.c b/reactos/lib/3rdparty/mingw/argv.c new file mode 100644 index 00000000000..a4a954cbe90 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/argv.c @@ -0,0 +1,19 @@ +#ifdef CRTDLL +#undef CRTDLL +#endif + +#include "internal.h" + +extern int _dowildcard; + +#ifdef WPRFLAG +int __CRTDECL +__wsetargv (void) +#else +int __CRTDECL +__setargv (void) +#endif +{ + _dowildcard = 1; + return 0; +} diff --git a/reactos/lib/3rdparty/mingw/atonexit.c b/reactos/lib/3rdparty/mingw/atonexit.c new file mode 100644 index 00000000000..1affa3b50b8 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/atonexit.c @@ -0,0 +1,50 @@ +#undef CRTDLL +#ifndef _DLL +#define _DLL +#endif + +#include "oscalls.h" +#include "internal.h" +#include +#include +#include + +#define _EXIT_LOCK1 8 + + void __cdecl _lock (int _File); + void __cdecl _unlock (int _File); + +_PVFV *__onexitbegin; +_PVFV *__onexitend; + +extern _CRTIMP _onexit_t __dllonexit (_onexit_t, _PVFV**, _PVFV**); +extern _onexit_t (__cdecl *_imp___onexit) (_onexit_t func); + +/* Choose a different name to prevent name conflicts. The CRT one works fine. */ +_onexit_t __cdecl mingw_onexit(_onexit_t func) +{ + _PVFV *onexitbegin; + _PVFV *onexitend; + _onexit_t retval; + + onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); + + if (onexitbegin == (_PVFV *) -1) + return (*_imp___onexit) (func); + _lock (_EXIT_LOCK1); + onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); + onexitend = (_PVFV *) _decode_pointer (__onexitend); + + retval = __dllonexit (func, &onexitbegin, &onexitend); + + __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin); + __onexitend = (_PVFV *) _encode_pointer (onexitend); + _unlock (_EXIT_LOCK1); + return retval; +} + +int __cdecl +atexit (_PVFV func) +{ + return (mingw_onexit((_onexit_t)func) == NULL) ? -1 : 0; +} diff --git a/reactos/lib/3rdparty/mingw/binmode.c b/reactos/lib/3rdparty/mingw/binmode.c index 747bf44551b..b5aec2461b2 100644 --- a/reactos/lib/3rdparty/mingw/binmode.c +++ b/reactos/lib/3rdparty/mingw/binmode.c @@ -1,5 +1,4 @@ +#define SPECIAL_CRTEXE + #include - -/* Set default file mode to binary */ - -int _fmode = _O_BINARY; +#include diff --git a/reactos/lib/3rdparty/mingw/charmax.c b/reactos/lib/3rdparty/mingw/charmax.c new file mode 100644 index 00000000000..c80f8a61141 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/charmax.c @@ -0,0 +1,9 @@ +#include "internal.h" + +int __lconv_init (void); + +int mingw_initcharmax = 0; + +int _charmax = 255; + +_CRTALLOC(".CRT$XIC") _PIFV __mingw_pinit = __lconv_init; diff --git a/reactos/lib/3rdparty/mingw/cinitexe.c b/reactos/lib/3rdparty/mingw/cinitexe.c new file mode 100644 index 00000000000..ac0a6a98b9a --- /dev/null +++ b/reactos/lib/3rdparty/mingw/cinitexe.c @@ -0,0 +1,7 @@ +#include +#include "internal.h" + +_CRTALLOC(".CRT$XIA") _PVFV __xi_a[] = { NULL }; +_CRTALLOC(".CRT$XIZ") _PVFV __xi_z[] = { NULL }; +_CRTALLOC(".CRT$XCA") _PVFV __xc_a[] = { NULL }; +_CRTALLOC(".CRT$XCZ") _PVFV __xc_z[] = { NULL }; diff --git a/reactos/lib/3rdparty/mingw/cpu_features.c b/reactos/lib/3rdparty/mingw/cpu_features.c deleted file mode 100644 index cc901d77f50..00000000000 --- a/reactos/lib/3rdparty/mingw/cpu_features.c +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include "cpu_features.h" - -/* level 1 edx bits */ -#define EDX_CX8 (1 << 8) /* CMPXCHG8B */ -#define EDX_CMOV (1 << 15) -#define EDX_MMX (1 << 23) -#define EDX_FXSR (1 << 24) /* FXSAVE and FXRSTOR */ -#define EDX_SSE (1 << 25) -#define EDX_SSE2 (1 << 26) - -/* level 1 ecx bits */ -#define ECX_SSE3 (1 << 0) -#define ECX_CX16 (1 << 13) /* CMPXCHG16B */ - -/* extended level 0x80000001 edx bits */ -#define EDX_3DNOW (1 << 31) -#define EDX_3DNOWP (1 << 30) -#define EDX_LM (1 << 29) /*LONG MODE */ - -#define __cpuid(level,a,b,c,d) \ - __asm__ __volatile__ ("cpuid;" \ - : "=a" (a), "=b" (b), "=c" (c), "=d" (d)\ - : "0" (level)) - -/* Combine the different cpuid flags into a single bitmap. */ - -unsigned int __cpu_features = 0; - -void __cpu_features_init (void) -{ -#ifdef __i386__ - unsigned int eax, ebx, ecx, edx; - /* Try to change the value of CPUID bit (bit 21) in EFLAGS. - If the bit can be toggled, CPUID is supported. */ - asm volatile ("pushfl; pushfl; popl %0;" - "movl %0,%1; xorl %2,%0;" - "pushl %0; popfl; pushfl; popl %0; popfl" - : "=&r" (eax), "=&r" (ebx) - : "i" (0x00200000)); - - if (((eax ^ ebx) & 0x00200000) == 0) - return; - - __cpuid (0, eax, ebx, ecx, edx); - if (eax == 0) - return; - - __cpuid (1, eax, ebx, ecx, edx); - - if (edx & EDX_CX8) - __cpu_features |= _CRT_CMPXCHG8B; - if (edx & EDX_CMOV) - __cpu_features |= _CRT_CMOV; - - if (edx & EDX_MMX) - __cpu_features |= _CRT_MMX; - if (edx & EDX_FXSR) - __cpu_features |= _CRT_FXSR; - if (edx & EDX_SSE) - __cpu_features |= _CRT_SSE; - if (edx & EDX_SSE2) - __cpu_features |= _CRT_SSE2; - - - if (ecx & ECX_SSE3) - __cpu_features |= _CRT_SSE3; - if (ecx & ECX_CX16) - __cpu_features |= _CRT_CMPXCHG16B; - - __cpuid (0x80000000, eax, ebx, ecx, edx); - if (eax < 0x80000001) - return; - __cpuid (0x80000001, eax, ebx, ecx, edx); - if (edx & EDX_3DNOW); - __cpu_features |= _CRT_3DNOW; - if (edx & EDX_3DNOWP) - __cpu_features |= _CRT_3DNOWP; -#endif -} - -#ifdef TEST - -#include -#define report(feature) \ - if ((feature) & __cpu_features) printf( #feature " found\n") - -int main() -{ - __cpu_features_init(); - - report(_CRT_CMPXCHG8B); - report(_CRT_CMOV); - report(_CRT_MMX); - report(_CRT_FXSR); - report(_CRT_SSE); - report(_CRT_SSE2); - report(_CRT_SSE3); - report(_CRT_CMPXCHG16B); - report(_CRT_3DNOW); - report(_CRT_3DNOWP); - return 0; -} - -#endif diff --git a/reactos/lib/3rdparty/mingw/cpu_features.h b/reactos/lib/3rdparty/mingw/cpu_features.h deleted file mode 100644 index 64318574776..00000000000 --- a/reactos/lib/3rdparty/mingw/cpu_features.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _CPU_FEATURES_H -#define _CPU_FEATURES_H - -#include - -#define _CRT_CMPXCHG8B 0x0001 -#define _CRT_CMOV 0x0002 -#define _CRT_MMX 0x0004 -#define _CRT_FXSR 0x0008 -#define _CRT_SSE 0x0010 -#define _CRT_SSE2 0x0020 -#define _CRT_SSE3 0x0040 -#define _CRT_CMPXCHG16B 0x0080 -#define _CRT_3DNOW 0x0100 -#define _CRT_3DNOWP 0x0200 - -extern unsigned int __cpu_features; - -/* Currently we use this in fpenv functions */ -#define __HAS_SSE __cpu_features & _CRT_SSE - -void __cpu_features_init (void); - - -#endif diff --git a/reactos/lib/3rdparty/mingw/crt0_c.c b/reactos/lib/3rdparty/mingw/crt0_c.c new file mode 100644 index 00000000000..11bcb68a1af --- /dev/null +++ b/reactos/lib/3rdparty/mingw/crt0_c.c @@ -0,0 +1,6 @@ +#include + +int main (int flags, char **cmdline, char **inst) +{ + return (int) WinMain ((HINSTANCE) inst, NULL, (LPSTR) cmdline,(DWORD) flags); +} diff --git a/reactos/lib/3rdparty/mingw/crt0_w.c b/reactos/lib/3rdparty/mingw/crt0_w.c new file mode 100644 index 00000000000..c0ae9b35d63 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/crt0_w.c @@ -0,0 +1,9 @@ +#include + +int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nShowCmd); + + +int wmain (int flags, wchar_t **cmdline, wchar_t **inst) +{ + return (int) wWinMain ((HINSTANCE) inst, NULL, (LPWSTR) cmdline,(DWORD) flags); +} diff --git a/reactos/lib/3rdparty/mingw/crt1.c b/reactos/lib/3rdparty/mingw/crt1.c deleted file mode 100644 index e5795642a8a..00000000000 --- a/reactos/lib/3rdparty/mingw/crt1.c +++ /dev/null @@ -1,297 +0,0 @@ -/* - * crt1.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Source code for the startup proceedures used by all programs. This code - * is compiled to make crt1.o, which should be located in the library path. - * - */ - -/* Hide the declaration of _fmode with dllimport attribute in stdlib.h to - avoid problems with older GCC. */ -#define __IN_MINGW_RUNTIME -#include -#include -#include -#include -#include -#define WIN32_LEAN_AND_MEAN -#include -#include - -/* NOTE: The code for initializing the _argv, _argc, and environ variables - * has been moved to a separate .c file which is included in both - * crt1.c and dllcrt1.c. This means changes in the code don't have to - * be manually synchronized, but it does lead to this not-generally- - * a-good-idea use of include. */ -#include "init.c" -#include "cpu_features.h" - -extern void _pei386_runtime_relocator (void); - -extern int main (int, char **, char **); - -/* - * Must have the correct app type for MSVCRT. - */ - -#ifdef __MSVCRT__ -#define __UNKNOWN_APP 0 -#define __CONSOLE_APP 1 -#define __GUI_APP 2 -#ifndef _M_PPC -__MINGW_IMPORT -#endif -void __set_app_type(int); -#endif /* __MSVCRT__ */ - -#ifndef __initenv -extern char ***_imp____initenv; -#define __initenv (*_imp____initenv) -#endif - -/* - * Setup the default file handles to have the _CRT_fmode mode, as well as - * any new files created by the user. - */ -extern int _CRT_fmode; - -static void -_mingw32_init_fmode (void) -{ - /* Don't set the std file mode if the user hasn't set any value for it. */ - if (_CRT_fmode) - { - *_imp___fmode = _CRT_fmode; - - /* - * This overrides the default file mode settings for stdin, - * stdout and stderr. At first I thought you would have to - * test with isatty, but it seems that the DOS console at - * least is smart enough to handle _O_BINARY stdout and - * still display correctly. - */ - if (stdin) - { - _setmode (_fileno (stdin), _CRT_fmode); - } - if (stdout) - { - _setmode (_fileno (stdout), _CRT_fmode); - } - if (stderr) - { - _setmode (_fileno (stderr), _CRT_fmode); - } - } - - /* Now sync the dll _fmode to the one for this .exe. */ -#ifdef __MSVCRT__ - *_imp___fmode = _fmode; -#else - *_imp___fmode_dll = _fmode; -#endif -} - -/* This function will be called when a trap occurs. Thanks to Jacob - Navia for his contribution. */ -static LONG CALLBACK -_gnu_exception_handler (EXCEPTION_POINTERS * exception_data) -{ - void (*old_handler) (int); - LONG action = EXCEPTION_CONTINUE_SEARCH; - int reset_fpu = 0; - - switch (exception_data->ExceptionRecord->ExceptionCode) - { - case EXCEPTION_ACCESS_VIOLATION: - /* test if the user has set SIGSEGV */ - old_handler = signal (SIGSEGV, SIG_DFL); - if (old_handler == SIG_IGN) - { - /* this is undefined if the signal was raised by anything other - than raise (). */ - signal (SIGSEGV, SIG_IGN); - action = EXCEPTION_CONTINUE_EXECUTION; - } - else if (old_handler != SIG_DFL) - { - /* This means 'old' is a user defined function. Call it */ - (*old_handler) (SIGSEGV); - action = EXCEPTION_CONTINUE_EXECUTION; - } - break; - - case EXCEPTION_ILLEGAL_INSTRUCTION: - case EXCEPTION_PRIV_INSTRUCTION: - /* test if the user has set SIGILL */ - old_handler = signal (SIGILL, SIG_DFL); - if (old_handler == SIG_IGN) - { - /* this is undefined if the signal was raised by anything other - than raise (). */ - signal (SIGILL, SIG_IGN); - action = EXCEPTION_CONTINUE_EXECUTION; - } - else if (old_handler != SIG_DFL) - { - /* This means 'old' is a user defined function. Call it */ - (*old_handler) (SIGILL); - action = EXCEPTION_CONTINUE_EXECUTION; - } - break; - - case EXCEPTION_FLT_INVALID_OPERATION: - case EXCEPTION_FLT_DIVIDE_BY_ZERO: - case EXCEPTION_FLT_DENORMAL_OPERAND: - case EXCEPTION_FLT_OVERFLOW: - case EXCEPTION_FLT_UNDERFLOW: - case EXCEPTION_FLT_INEXACT_RESULT: - reset_fpu = 1; - /* fall through. */ - - case EXCEPTION_INT_DIVIDE_BY_ZERO: - /* test if the user has set SIGFPE */ - old_handler = signal (SIGFPE, SIG_DFL); - if (old_handler == SIG_IGN) - { - signal (SIGFPE, SIG_IGN); - if (reset_fpu) - _fpreset (); - action = EXCEPTION_CONTINUE_EXECUTION; - } - else if (old_handler != SIG_DFL) - { - /* This means 'old' is a user defined function. Call it */ - (*old_handler) (SIGFPE); - action = EXCEPTION_CONTINUE_EXECUTION; - } - break; - - default: - break; - } - return action; -} - -/* - * The function mainCRTStartup is the entry point for all console programs. - */ -static void __attribute__((noreturn)) -__mingw_CRTStartup (void) -{ - int nRet; - - /* - * Set up the top-level exception handler so that signal handling - * works as expected. The mapping between ANSI/POSIX signals and - * Win32 SE is not 1-to-1, so caveat emptore. - * - */ - SetUnhandledExceptionFilter (_gnu_exception_handler); - - /* - * Initialize floating point unit. - */ - __cpu_features_init (); /* Do we have SSE, etc.*/ - _fpreset (); /* Supplied by the runtime library. */ - - /* - * Set up __argc, __argv and _environ. - */ - _mingw32_init_mainargs (); - - /* - * Sets the default file mode. - * If _CRT_fmode is set, also set mode for stdin, stdout - * and stderr, as well - * NOTE: DLLs don't do this because that would be rude! - */ - _mingw32_init_fmode (); - - /* Adust references to dllimported data that have non-zero offsets. */ -#if defined(__i386__) - _pei386_runtime_relocator (); -#endif - -#if defined(__i386__) - /* Align the stack to 16 bytes for the sake of SSE ops in main - or in functions inlined into main. */ - asm __volatile__ ("andl $-16, %%esp" : : : "%esp"); -#elif defined(__x86_64__) - /* Align the stack to 16 bytes */ - asm __volatile__ ("andq $-16, %%rsp" : : : "%rsp"); -#elif defined(__mips__) - /* Align the stack to 16 bytes */ - asm __volatile__ ("andi %sp,%sp,-16" : : : "%sp"); -#elif defined(__PowerPC__) - /* Align the stack to 16 bytes */ - asm __volatile__ ("li 0,15\n\tandc 1,1,0" : : : "r1"); -#else -#error Unsupported architecture -#endif - - /* - * Call the main function. If the user does not supply one - * the one in the 'libmingw32.a' library will be linked in, and - * that one calls WinMain. See main.c in the 'lib' dir - * for more details. - */ - nRet = main (_argc, _argv, __initenv); - - /* - * Perform exit processing for the C library. This means - * flushing output and calling 'atexit' registered functions. - */ - _cexit (); - - ExitProcess (nRet); -} - -/* - * The function mainCRTStartup is the entry point for all console programs. - */ -void -mainCRTStartup (void) -{ -#ifdef __MSVCRT__ - __set_app_type (__CONSOLE_APP); -#endif - __mingw_CRTStartup (); -} - -/* - * For now the GUI startup function is the same as the console one. - * This simply gets rid of the annoying warning about not being able - * to find WinMainCRTStartup when linking GUI applications. - */ -void -WinMainCRTStartup (void) -{ -#ifdef __MSVCRT__ - __set_app_type (__GUI_APP); -#endif - __mingw_CRTStartup (); -} - -#if 0 -/* - * We force use of library version of atexit, which is only - * visible in import lib as _imp__atexit - */ -extern int (*_imp__atexit)(void (*)(void)); -int atexit (void (* pfn )(void) ) -{ - return ( (*_imp__atexit)(pfn)); -} - -/* Likewise for non-ANSI _onexit */ -extern _onexit_t (*_imp___onexit)(_onexit_t); -_onexit_t -_onexit (_onexit_t pfn ) -{ - return (*_imp___onexit)(pfn); -} -#endif diff --git a/reactos/lib/3rdparty/mingw/crtdll.c b/reactos/lib/3rdparty/mingw/crtdll.c new file mode 100644 index 00000000000..c5bd1950c2f --- /dev/null +++ b/reactos/lib/3rdparty/mingw/crtdll.c @@ -0,0 +1,201 @@ +#ifdef CRTDLL +#undef CRTDLL +#define _DLL + +#include +#include +#include +#include +#define _DECL_DLLMAIN +#include +#include + +#ifndef _CRTIMP +#ifdef CRTDLL +#define _CRTIMP __declspec(dllexport) +#else +#ifdef _DLL +#define _CRTIMP __declspec(dllimport) +#else +#define _CRTIMP +#endif +#endif +#endif +#include +#include + +extern void __cdecl _initterm(_PVFV *,_PVFV *); +extern void __main (); +extern void _pei386_runtime_relocator (void); +extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[]; +extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[]; +extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[]; +extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[]; + +extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback; + +static int __proc_attached = 0; + +extern _PVFV *__onexitbegin; +extern _PVFV *__onexitend; + +extern int mingw_app_type; + +extern BOOL WINAPI DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved); + +extern BOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID); + +static int pre_c_init (void); + +_CRTALLOC(".CRT$XIAA") _PIFV pcinit = pre_c_init; + +static int +pre_c_init (void) +{ + _PVFV *onexitbegin; + + onexitbegin = (_PVFV *) malloc (32 * sizeof (_PVFV)); + __onexitend = __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin); + + if (onexitbegin == NULL) + return 1; + *onexitbegin = (_PVFV) NULL; + return 0; +} + +BOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + if (dwReason == DLL_PROCESS_DETACH) + { + if (__proc_attached > 0) + __proc_attached--; + else + return FALSE; + } + if (dwReason == DLL_PROCESS_ATTACH) + { + void *lock_free = NULL; + void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase; + int nested = FALSE; + + while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock, + fiberid, 0)) != 0) + { + if (lock_free == fiberid) + { + nested = TRUE; + break; + } + Sleep(1000); + } + if (__native_startup_state != __uninitialized) + { + _amsg_exit(31); + } + else + { + __native_startup_state = __initializing; + + _initterm ((_PVFV *) (void *) __xi_a, (_PVFV *) (void *) __xi_z); + _initterm (__xc_a,__xc_z); + __native_startup_state = __initialized; + } + if (! nested) + { + InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0); + } + if (__dyn_tls_init_callback != NULL && + _IsNonwritableInCurrentImage ((PBYTE) &__dyn_tls_init_callback)) + { + __dyn_tls_init_callback (hDllHandle, DLL_THREAD_ATTACH, lpreserved); + } + __proc_attached++; + } + else if (dwReason == DLL_PROCESS_DETACH) + { + void *lock_free = NULL; + while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,(PVOID) 1, 0)) != 0) + { + Sleep(1000); + } + if(__native_startup_state!=__initialized) + { + _amsg_exit (31); + } + else + { + _PVFV * onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); + if (onexitbegin) + { + _PVFV *onexitend = (_PVFV *) _decode_pointer (__onexitend); + while (--onexitend >= onexitbegin) + if (*onexitend != NULL) + (**onexitend) (); + free (onexitbegin); + __onexitbegin = __onexitend = (_PVFV *) NULL; + } + __native_startup_state = __uninitialized; + InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0); + } + } + return TRUE; +} + +static BOOL __DllMainCRTStartup (HANDLE, DWORD, LPVOID); + +BOOL WINAPI +DllMainCRTStartup(HANDLE hDllHandle,DWORD dwReason,LPVOID lpreserved) +{ + mingw_app_type = 0; + if (dwReason == DLL_PROCESS_ATTACH) + { + __security_init_cookie (); + } + return __DllMainCRTStartup (hDllHandle, dwReason, lpreserved); +} + +__declspec(noinline) BOOL +__DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + BOOL retcode = TRUE; + + __native_dllmain_reason = dwReason; + if (dwReason == DLL_PROCESS_DETACH && __proc_attached == 0) + { + retcode = FALSE; + goto i__leave; + } + if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH) + { + retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved); + if (retcode) + retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved); + if (! retcode) + goto i__leave; + } + _pei386_runtime_relocator (); + if (retcode && dwReason == DLL_PROCESS_ATTACH) + __main (); + retcode = DllMain(hDllHandle,dwReason,lpreserved); + if ((dwReason == DLL_PROCESS_ATTACH) && ! retcode) + { + DllMain (hDllHandle, DLL_PROCESS_DETACH, lpreserved); + _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved); + DllEntryPoint (hDllHandle, DLL_PROCESS_DETACH, lpreserved); + } + if (dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH) + { + if (_CRT_INIT (hDllHandle, dwReason, lpreserved) == FALSE) + { + retcode = FALSE; + } + if (retcode) + { + retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved); + } + } +i__leave: + __native_dllmain_reason = UINT_MAX; + return retcode ; +} +#endif diff --git a/reactos/lib/3rdparty/mingw/crtexe.c b/reactos/lib/3rdparty/mingw/crtexe.c new file mode 100644 index 00000000000..273fea363de --- /dev/null +++ b/reactos/lib/3rdparty/mingw/crtexe.c @@ -0,0 +1,469 @@ +#undef CRTDLL +#define _DLL + +#define SPECIAL_CRTEXE + +#include "oscalls.h" +#include "internal.h" +#include +#include +#include +#include +#include +#include + +#ifndef __winitenv +extern wchar_t ***_imp____winitenv; +#define __winitenv (*_imp____winitenv) +#endif + +#ifndef __initenv +extern char ***_imp____initenv; +#define __initenv (*_imp____initenv) +#endif + +/* Hack, for bug in ld. Will be removed soon. */ +#define __ImageBase _image_base__ +/* This symbol is defined by ld. */ +extern IMAGE_DOS_HEADER __ImageBase; + +extern void _fpreset (void); +#define SPACECHAR _T(' ') +#define DQUOTECHAR _T('\"') + +_CRTIMP void __setusermatherr(int (__cdecl *)(struct _exception *)); + +extern int *_imp___fmode; +extern int *_imp___commode; + +#undef _fmode +extern int _fmode; +extern int *_imp___commode; +#define _commode (*_imp___commode) +extern int _dowildcard; + +extern int __defaultmatherr; +extern _CRTIMP void __cdecl _initterm(_PVFV *, _PVFV *); + +static int __cdecl check_managed_app (void); + +extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[]; +extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[]; +extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[]; +extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[]; + +extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback; + +extern _PVFV *__onexitbegin; +extern _PVFV *__onexitend; + +extern int mingw_app_type; + +static int argc; +#ifdef WPRFLAG +static wchar_t **argv; +static wchar_t **envp; +#else +static char **argv; +static char **envp; +#endif + +static int argret=0; +static int mainret=0; +static int managedapp=0; +static int has_cctor = 0; +static _startupinfo startinfo; + +extern void _pei386_runtime_relocator (void); +static CALLBACK long _gnu_exception_handler (EXCEPTION_POINTERS * exception_data); +//static LONG __mingw_vex(EXCEPTION_POINTERS * exception_data); +#ifdef WPRFLAG +static void duplicate_ppstrings (int ac, wchar_t ***av); +#else +static void duplicate_ppstrings (int ac, char ***av); +#endif + +static int __cdecl pre_c_init (void); +static void __cdecl pre_cpp_init (void); + +_CRTALLOC(".CRT$XIAA") _PIFV mingw_pcinit = pre_c_init; +_CRTALLOC(".CRT$XCAA") _PVFV mingw_pcppinit = pre_cpp_init; + +static int __cdecl +pre_c_init (void) +{ + managedapp = check_managed_app (); + if (mingw_app_type) + __set_app_type(_GUI_APP); + else + __set_app_type (_CONSOLE_APP); + __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1)); + + *_imp___fmode = _fmode; + *_imp___commode = _commode; + +#ifndef WPRFLAG + _dowildcard = 1; +#endif + + if (! __defaultmatherr) + __setusermatherr (_matherr); + + if (__globallocalestatus == -1) + { + } + return 0; +} + +static void __cdecl +pre_cpp_init (void) +{ + startinfo.newmode = _newmode; +#ifdef WPRFLAG + argret = __wgetmainargs(&argc,&argv,&envp,_dowildcard,&startinfo); +#else + argret = __getmainargs(&argc,&argv,&envp,_dowildcard,&startinfo); +#endif + +} + +static int __mingw_CRTStartup (void); + +#ifdef WPRFLAG +int wWinMainCRTStartup (void) +#else +int WinMainCRTStartup (void) +#endif +{ + mingw_app_type = 1; + __security_init_cookie (); + return __mingw_CRTStartup (); +} + +#ifdef WPRFLAG +int wmainCRTStartup (void) +#else +int mainCRTStartup (void) +#endif +{ + mingw_app_type = 0; + __security_init_cookie (); + return __mingw_CRTStartup (); +} + + +__declspec(noinline) int +__mingw_CRTStartup (void) +{ + _TCHAR *lpszCommandLine = NULL; + STARTUPINFO StartupInfo; + BOOL inDoubleQuote = FALSE; + memset (&StartupInfo, 0, sizeof (STARTUPINFO)); + int nested = FALSE; + + if (mingw_app_type) + GetStartupInfo (&StartupInfo); + { +#if 0 //not ready for this yet + void *lock_free = NULL; + void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase; + while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock, + fiberid, 0)) != 0) + { + if (lock_free == fiberid) + { + nested = TRUE; + break; + } + Sleep(1000); + } +#endif + if (__native_startup_state == __initializing) + { + _amsg_exit (31); + } + else if (__native_startup_state == __uninitialized) + { + __native_startup_state = __initializing; + _initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z); + } + else + has_cctor = 1; + + if (__native_startup_state == __initializing) + { + _initterm (__xc_a, __xc_z); + __native_startup_state = __initialized; + } + _ASSERTE(__native_startup_state == __initialized); + if (! nested) + (VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0); + + if (__dyn_tls_init_callback != NULL && _IsNonwritableInCurrentImage ((PBYTE) &__dyn_tls_init_callback)) + __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL); + + _pei386_runtime_relocator (); + + #if defined(__x86_64__) + __asm__ __volatile__ ( + "xorq %rax,%rax\n\t" + "decq %rax\n\t" + "movq %rax,%gs:0" "\n"); + #elif defined(__i386__) + __asm__ __volatile__ ( + "xorl %eax,%eax\n\t" + "decl %eax\n\t" + "movl %eax,%fs:0" "\n"); + #endif + //AddVectoredExceptionHandler (0, (PVECTORED_EXCEPTION_HANDLER)__mingw_vex); + SetUnhandledExceptionFilter (_gnu_exception_handler); + + if (mingw_app_type) + { +#ifdef WPRFLAG + if (_wcmdln == NULL) + return 255; + lpszCommandLine = (_TCHAR *) _wcmdln; +#else + lpszCommandLine = (char *) _acmdln; +#endif + while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine && inDoubleQuote)) + { + if (*lpszCommandLine == DQUOTECHAR) + inDoubleQuote = TRUE; +#ifdef _MBCS + if (_ismbblead (*lpszCommandLine)) + { + if (lpszCommandLine) + lpszCommandLine++; + } +#endif + ++lpszCommandLine; + } + while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) + lpszCommandLine++; + +#ifdef WPRFLAG + mainret = wmain ( + (int) (StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT), + (wchar_t **) lpszCommandLine, (wchar_t **) (HINSTANCE) &__ImageBase); +#else + mainret = main ( + (int) (StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT), + (char **) lpszCommandLine, (char **) (HINSTANCE) &__ImageBase); +#endif + } + else + { + duplicate_ppstrings (argc, &argv); +#ifdef WPRFLAG + __winitenv = envp; + mainret = wmain (argc, argv, envp); +#else + __initenv = envp; + mainret = main (argc, argv, envp); +#endif + } + if (!managedapp) + exit (mainret); + + if (has_cctor == 0) + _cexit (); + } + return mainret; +} + +extern int mingw_initltsdrot_force; +extern int mingw_initltsdyn_force; +extern int mingw_initltssuo_force; +extern int mingw_initcharmax; + +static int __cdecl +check_managed_app (void) +{ + PIMAGE_DOS_HEADER pDOSHeader; + PIMAGE_NT_HEADERS pPEHeader; + PIMAGE_OPTIONAL_HEADER32 pNTHeader32; + PIMAGE_OPTIONAL_HEADER64 pNTHeader64; + + /* Force to be linked. */ + mingw_initltsdrot_force=1; + mingw_initltsdyn_force=1; + mingw_initltssuo_force=1; + mingw_initcharmax=1; + + pDOSHeader = (PIMAGE_DOS_HEADER) &__ImageBase; + if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE) + return 0; + + pPEHeader = (PIMAGE_NT_HEADERS)((char *)pDOSHeader + pDOSHeader->e_lfanew); + if (pPEHeader->Signature != IMAGE_NT_SIGNATURE) + return 0; + + pNTHeader32 = (PIMAGE_OPTIONAL_HEADER32) &pPEHeader->OptionalHeader; + switch (pNTHeader32->Magic) + { + case IMAGE_NT_OPTIONAL_HDR32_MAGIC: + if (pNTHeader32->NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR) + return 0; + return !! pNTHeader32->DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; + case IMAGE_NT_OPTIONAL_HDR64_MAGIC: + pNTHeader64 = (PIMAGE_OPTIONAL_HEADER64)pNTHeader32; + if (pNTHeader64->NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR) + return 0; + return !! pNTHeader64->DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; + } + return 0; +} + +int __defaultmatherr; + +static CALLBACK long +_gnu_exception_handler (EXCEPTION_POINTERS * exception_data) +{ + void (*old_handler) (int); + long action = EXCEPTION_CONTINUE_SEARCH; + int reset_fpu = 0; + + switch (exception_data->ExceptionRecord->ExceptionCode) + { + case EXCEPTION_ACCESS_VIOLATION: + /* test if the user has set SIGSEGV */ + old_handler = signal (SIGSEGV, SIG_DFL); + if (old_handler == SIG_IGN) + { + /* this is undefined if the signal was raised by anything other + than raise (). */ + signal (SIGSEGV, SIG_IGN); + action = EXCEPTION_CONTINUE_EXECUTION; + } + else if (old_handler != SIG_DFL) + { + /* This means 'old' is a user defined function. Call it */ + (*old_handler) (SIGSEGV); + action = EXCEPTION_CONTINUE_EXECUTION; + } + break; + + case EXCEPTION_ILLEGAL_INSTRUCTION: + case EXCEPTION_PRIV_INSTRUCTION: + /* test if the user has set SIGILL */ + old_handler = signal (SIGILL, SIG_DFL); + if (old_handler == SIG_IGN) + { + /* this is undefined if the signal was raised by anything other + than raise (). */ + signal (SIGILL, SIG_IGN); + action = EXCEPTION_CONTINUE_EXECUTION; + } + else if (old_handler != SIG_DFL) + { + /* This means 'old' is a user defined function. Call it */ + (*old_handler) (SIGILL); + action = EXCEPTION_CONTINUE_EXECUTION; + } + break; + + case EXCEPTION_FLT_INVALID_OPERATION: + case EXCEPTION_FLT_DIVIDE_BY_ZERO: + case EXCEPTION_FLT_DENORMAL_OPERAND: + case EXCEPTION_FLT_OVERFLOW: + case EXCEPTION_FLT_UNDERFLOW: + case EXCEPTION_FLT_INEXACT_RESULT: + reset_fpu = 1; + /* fall through. */ + + case EXCEPTION_INT_DIVIDE_BY_ZERO: + /* test if the user has set SIGFPE */ + old_handler = signal (SIGFPE, SIG_DFL); + if (old_handler == SIG_IGN) + { + signal (SIGFPE, SIG_IGN); + if (reset_fpu) + _fpreset (); + action = EXCEPTION_CONTINUE_EXECUTION; + } + else if (old_handler != SIG_DFL) + { + /* This means 'old' is a user defined function. Call it */ + (*old_handler) (SIGFPE); + action = EXCEPTION_CONTINUE_EXECUTION; + } + break; + + default: + break; + } + return action; +} + +#if 0 +static LONG __mingw_vex(EXCEPTION_POINTERS * exception_data) +{ + /* TODO this is not chainablem, therefore need rewrite. Disabled the ill code. */ + + #ifdef _WIN64 + __asm__ __volatile__ ( + "movq %gs:0,%rax" "\n\t" + "orq %rax,%rax\n\t" + "jz l1\n\t" + "jmp *8(%rax)\n\r" + "l1:\n\t" + "nop\n"); +#else + __asm__ __volatile__ ( + "movl %fs:0,%eax" "\n\t" + "orl %eax,%eax\n\t" + "jz l1\n\t" + "jmp *4(%eax)\n\r" + "l1:\n\t" + "nop\n"); +#endif + return _gnu_exception_handler(exception_data); +} +#endif + +#ifdef WPRFLAG + +static size_t wbytelen(const wchar_t *p) +{ + size_t ret = 1; + while (*p!=0) { + ret++,++p; + } + return ret*2; +} +static void duplicate_ppstrings (int ac, wchar_t ***av) +{ + wchar_t **avl; + int i; + wchar_t **n = (wchar_t **) malloc (sizeof (wchar_t *) * (ac + 1)); + + avl=*av; + for (i=0; i < ac; i++) + { + int l = wbytelen (avl[i]); + n[i] = (wchar_t *) malloc (l); + memcpy (n[i], avl[i], l); + } + n[i] = NULL; + *av = n; +} +#else +static void duplicate_ppstrings (int ac, char ***av) +{ + char **avl; + int i; + char **n = (char **) malloc (sizeof (char *) * (ac + 1)); + + avl=*av; + for (i=0; i < ac; i++) + { + int l = strlen (avl[i]) + 1; + n[i] = (char *) malloc (l); + memcpy (n[i], avl[i], l); + } + n[i] = NULL; + *av = n; +} +#endif diff --git a/reactos/lib/3rdparty/mingw/dllcrt1.c b/reactos/lib/3rdparty/mingw/dllcrt1.c deleted file mode 100644 index cff2c29a5f0..00000000000 --- a/reactos/lib/3rdparty/mingw/dllcrt1.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * dllcrt1.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Initialization code for DLLs. - * - */ -#include -#include -#include -#include -#include -#include - -/* Unlike normal crt1, I don't initialize the FPU, because the process - * should have done that already. I also don't set the file handle modes, - * because that would be rude. */ - -#ifdef __GNUC__ -extern void __main (); -extern void __do_global_dtors (); -#endif - -typedef void (* p_atexit_fn )(void); -static p_atexit_fn* first_atexit; -static p_atexit_fn* next_atexit; - -static void -__dll_exit (void); - -/* This is based on the function in the Wine project's exit.c */ -p_atexit_fn __dllonexit (p_atexit_fn, p_atexit_fn**, p_atexit_fn**); - - -extern BOOL WINAPI DllMain (HANDLE, DWORD, LPVOID); - -extern void _pei386_runtime_relocator (void); - -BOOL WINAPI -DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) -{ - BOOL bRet; - - if (dwReason == DLL_PROCESS_ATTACH) - { - -#ifdef DEBUG - printf ("%s: DLL_PROCESS_ATTACH (%d)\n", __FUNCTION__); -#endif - - /* Initialize private atexit table for this dll. - 32 is min size required by ANSI */ - - first_atexit = (p_atexit_fn*) malloc (32 * sizeof (p_atexit_fn)); - if (first_atexit == NULL ) /* can't allocate memory */ - { - errno=ENOMEM; - return FALSE; - } - *first_atexit = NULL; - next_atexit = first_atexit; - - /* Adust references to dllimported data (from other DLL's) - that have non-zero offsets. */ - _pei386_runtime_relocator (); - -#ifdef __GNUC__ - /* From libgcc.a, __main calls global class constructors, - __do_global_ctors, which registers __do_global_dtors - as the first entry of the private atexit table we - have just initialised */ - __main (); - -#endif - } - - /* - * Call the user-supplied DllMain subroutine. - * This has to come after initialization of atexit table and - * registration of global constructors. - * NOTE: DllMain is optional, so libmingw32.a includes a stub - * which will be used if the user does not supply one. - */ - - bRet = DllMain (hDll, dwReason, lpReserved); - /* Handle case where DllMain returns FALSE on attachment attempt. */ - - if ( (dwReason == DLL_PROCESS_ATTACH) && !bRet) - { -#ifdef DEBUG - printf ("%s: DLL_PROCESS_ATTACH failed, cleaning up\n", __FUNCTION__); -#endif - - __dll_exit (); /* Cleanup now. This will set first_atexit to NULL so we - know we've cleaned up */ - } - - if (dwReason == DLL_PROCESS_DETACH) - { -#ifdef DEBUG - printf ("%s: DLL_PROCESS_DETACH (%d)\n", __FUNCTION__); -#endif - /* If not attached, return FALSE. Cleanup already done above - if failed attachment attempt. */ - if (! first_atexit ) - bRet = FALSE; - else - /* - * We used to call __do_global_dtors () here. This is - * no longer necessary since __do_global_dtors is now - * registered at start (last out) of private atexit table. - */ - __dll_exit (); - } - return bRet; -} - -static -void -__dll_exit(void) -/* Run LIFO terminators registered in private atexit table */ -{ - if ( first_atexit ) - { - p_atexit_fn* __last = next_atexit - 1; - while ( __last >= first_atexit ) - { - if ( *__last != NULL ) - { -#ifdef DEBUG - printf ("%s: Calling exit function 0x%x from 0x%x\n", - __FUNCTION__, (unsigned)(*__last),(unsigned)__last); -#endif - (**__last) (); - } - __last--; - } - free ( first_atexit ) ; - first_atexit = NULL ; - } - /* - Make sure output buffers opened by DllMain or - atexit-registered functions are flushed before detaching, - otherwise we can have problems with redirected output. - */ - fflush (NULL); -} - -/* - * The atexit exported from msvcrt.dll causes problems in DLLs. - * Here, we override the exported version of atexit with one that passes the - * private table initialised in DllMainCRTStartup to __dllonexit. - * That means we have to hide the mscvrt.dll atexit because the - * atexit defined here gets __dllonexit from the same lib. - */ - -#if 0 -int -atexit (p_atexit_fn pfn ) -{ -#ifdef DEBUG - printf ("%s: registering exit function 0x%x at 0x%x\n", - __FUNCTION__, (unsigned)pfn, (unsigned)next_atexit); -#endif - return (__dllonexit (pfn, &first_atexit, &next_atexit) - == NULL ? -1 : 0 ); -} - -/* - * Likewise for non-ANSI function _onexit that may be called by - * code in the dll. - */ - -_onexit_t -_onexit (_onexit_t pfn ) -{ -#ifdef DEBUG - printf ("%s: registering exit function 0x%x at 0x%x\n", - __FUNCTION__, (unsigned)pfn, (unsigned)next_atexit); -#endif - return ((_onexit_t) __dllonexit ((p_atexit_fn)pfn, &first_atexit, &next_atexit)); -} -#endif diff --git a/reactos/lib/3rdparty/mingw/dllentry.c b/reactos/lib/3rdparty/mingw/dllentry.c new file mode 100644 index 00000000000..73f006b9068 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/dllentry.c @@ -0,0 +1,8 @@ +#define _DECL_DLLMAIN +#include +#include + +BOOL WINAPI DllEntryPoint(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + return TRUE; +} diff --git a/reactos/lib/3rdparty/mingw/dllmain.c b/reactos/lib/3rdparty/mingw/dllmain.c new file mode 100644 index 00000000000..005e24eddb2 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/dllmain.c @@ -0,0 +1,9 @@ +#define _DECL_DLLMAIN +#define _WINDOWS_ +#include +#include + +BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + return TRUE; +} diff --git a/reactos/lib/3rdparty/mingw/gccmain.c b/reactos/lib/3rdparty/mingw/gccmain.c index 0888741ff09..d46e99de72a 100644 --- a/reactos/lib/3rdparty/mingw/gccmain.c +++ b/reactos/lib/3rdparty/mingw/gccmain.c @@ -1,38 +1,32 @@ -/* - * gccmain.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * A separate version of __main, __do_global_ctors and __do_global_dtors for - * Mingw32 for use with Cygwin32 b19. Hopefully this object file will only - * be linked if the libgcc.a doesn't include __main, __do_global_dtors and - * __do_global_ctors. - * - */ - -/* Needed for the atexit prototype. */ +#include #include -#include +#include typedef void (*func_ptr) (void); extern func_ptr __CTOR_LIST__[]; extern func_ptr __DTOR_LIST__[]; +static HMODULE hMsvcrt = NULL; + +typedef void __cdecl flongjmp(jmp_buf _Buf,int _Value); + +flongjmp *fctMsvcrtLongJmp = NULL; + void __do_global_dtors (void) { static func_ptr *p = __DTOR_LIST__ + 1; - /* - * Call each destructor in the destructor list until a null pointer - * is encountered. - */ while (*p) { (*(p)) (); p++; } + if (hMsvcrt) + { + FreeLibrary (hMsvcrt); + hMsvcrt = NULL; + } } void @@ -41,27 +35,21 @@ __do_global_ctors (void) unsigned long nptrs = (unsigned long) (ptrdiff_t) __CTOR_LIST__[0]; unsigned long i; - /* - * If the first entry in the constructor list is -1 then the list - * is terminated with a null entry. Otherwise the first entry was - * the number of pointers in the list. - */ - if (nptrs == -1) + if (!hMsvcrt) { + hMsvcrt = LoadLibrary ("msvcrt.dll"); + fctMsvcrtLongJmp = (flongjmp *) GetProcAddress( hMsvcrt, "longjmp"); + } + + if (nptrs == (unsigned long) -1) { for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++); } - /* - * Go through the list backwards calling constructors. - */ for (i = nptrs; i >= 1; i--) { __CTOR_LIST__[i] (); } - /* - * Register the destructors for processing on exit. - */ atexit (__do_global_dtors); } @@ -76,5 +64,3 @@ __main (void) __do_global_ctors (); } } - - diff --git a/reactos/lib/3rdparty/mingw/getopt.c b/reactos/lib/3rdparty/mingw/getopt.c deleted file mode 100644 index 3b0bfedfec4..00000000000 --- a/reactos/lib/3rdparty/mingw/getopt.c +++ /dev/null @@ -1,137 +0,0 @@ -/* $Id$ -*/ -/* - tgetopt -- POSIX-compliant implementation of getopt() with string-type-generic - semantics - - This is public domain software -*/ - -#include -#include -#include - -#include "tgetopt.h" - -int _topterr = 1; -int _toptind = 1; -int _toptopt; -_TCHAR * _toptarg; - -int _tgetopt(int argc, _TCHAR * const argv[], const _TCHAR * optstring) -{ - static int s_nArgChar = 0; - _TCHAR * pcOptChar; - - /* we're done */ - if(_toptind >= argc) return -1; - - /* last time we reached the end of argv[_toptind] */ - if(s_nArgChar != 0 && argv[_toptind][s_nArgChar] == 0) - { - /* scan the next argument */ - ++ _toptind; - - /* we're done */ - if(_toptind >= argc) return -1; - - s_nArgChar = 0; - } - - /* first time we scan argv[_toptind] */ - if(s_nArgChar == 0) - { - /* argument is NULL - we're done */ - if(argv[_toptind] == NULL) - return (int)-1; - /* argument is empty - we're done */ - else if(argv[_toptind][0] == 0) - return (int)-1; - /* argument begins with '-' */ - else if(argv[_toptind][0] == _T('-')) - { - /* argument is "--" */ - if(argv[_toptind][1] == _T('-')) - { - /* increment optind */ - ++ _toptind; - s_nArgChar = 0; - - /* we're done */ - return (int)-1; - } - /* argument is "-" */ - else if(argv[_toptind][1] == 0) - { - /* we're done */ - return (int)-1; - } - /* possible option */ - else - ++ s_nArgChar; - } - /* argument doesn't begin with a dash - we're done */ - else - return (int)-1; - } - - /* return the current character */ - _toptopt = argv[_toptind][s_nArgChar]; - - /* advance to the next character */ - ++ s_nArgChar; - - /* unrecognized option */ - if(_toptopt == _T(':') || (pcOptChar = _tcschr(optstring, _toptopt)) == NULL) - { - /* print an error message */ - if(_topterr && optstring[0] != _T(':')) - _ftprintf(stderr, _T("%s: illegal option -- %c\n"), argv[0], _toptopt); - - /* return an error */ - return _T('?'); - } - - /* the option requires an argument */ - if(pcOptChar[1] == _T(':')) - { - /* we are at the end of the argument */ - if(argv[_toptind][s_nArgChar] == 0) - { - /* the argument of the option is the next argument */ - ++ _toptind; - s_nArgChar = 0; - - /* this is the last argument */ - if(_toptind >= argc) - { - /* print an error message */ - if(_topterr && optstring[0] != _T(':')) - { - _ftprintf - ( - stderr, - _T("%s: option requires an argument -- %c\n"), - argv[0], - _toptopt - ); - } - - /* return an error */ - return ((optstring[0] == _T(':')) ? _T(':') : _T('?')); - } - - /* return the argument */ - _toptarg = argv[_toptind]; - ++ _toptind; - } - /* the rest of the argument is the argument of the option */ - else - _toptarg = argv[_toptind] + s_nArgChar; - } - - /* success */ - return _toptopt; -} - -/* EOF */ diff --git a/reactos/lib/3rdparty/mingw/gs_support.c b/reactos/lib/3rdparty/mingw/gs_support.c new file mode 100644 index 00000000000..faa4ae171c6 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/gs_support.c @@ -0,0 +1,129 @@ +#include +#ifdef _WIN64 +#include +#endif + +#ifdef _WIN64 +#define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll +#else +#define DEFAULT_SECURITY_COOKIE 0xBB40E64E +#endif + +/* Externals. */ +#ifdef _WIN64 +PRUNTIME_FUNCTION RtlLookupFunctionEntry (ULONG64, PULONG64, PVOID); +PVOID RtlVirtualUnwind (ULONG HandlerType, ULONG64, ULONG64, PRUNTIME_FUNCTION, + PCONTEXT, PVOID *, PULONG64, PKNONVOLATILE_CONTEXT_POINTERS); +#endif + +typedef LONG NTSTATUS; + +#define STATUS_STACK_BUFFER_OVERRUN ((NTSTATUS)0xC0000409L) + +typedef union +{ + unsigned __int64 ft_scalar; + FILETIME ft_struct; +} FT; + +static EXCEPTION_RECORD GS_ExceptionRecord; +static CONTEXT GS_ContextRecord; + +static const EXCEPTION_POINTERS GS_ExceptionPointers = { + &GS_ExceptionRecord,&GS_ContextRecord +}; + +__declspec(selectany) UINT_PTR __security_cookie = DEFAULT_SECURITY_COOKIE; +__declspec(selectany) UINT_PTR __security_cookie_complement = ~(DEFAULT_SECURITY_COOKIE); + +void __cdecl +__security_init_cookie (void) +{ + UINT_PTR cookie; + FT systime = { 0, }; + LARGE_INTEGER perfctr; + + if (__security_cookie != DEFAULT_SECURITY_COOKIE) + { + __security_cookie_complement = ~__security_cookie; + return; + } + + GetSystemTimeAsFileTime (&systime.ft_struct); +#ifdef _WIN64 + cookie = systime.ft_scalar; +#else + cookie = systime.ft_struct.dwLowDateTime; + cookie ^= systime.ft_struct.dwHighDateTime; +#endif + + cookie ^= GetCurrentProcessId (); + cookie ^= GetCurrentThreadId (); + cookie ^= GetTickCount (); + + QueryPerformanceCounter (&perfctr); +#ifdef _WIN64 + cookie ^= perfctr.QuadPart; +#else + cookie ^= perfctr.LowPart; + cookie ^= perfctr.HighPart; +#endif + +#ifdef _WIN64 + cookie &= 0x0000ffffffffffffll; +#endif + + if (cookie == DEFAULT_SECURITY_COOKIE) + cookie = DEFAULT_SECURITY_COOKIE + 1; + __security_cookie = cookie; + __security_cookie_complement = ~cookie; +} + +__declspec(noreturn) void __cdecl +__report_gsfailure (ULONGLONG StackCookie) +{ + volatile UINT_PTR cookie[2]; +#ifdef _WIN64 + ULONG64 controlPC, imgBase, establisherFrame; + PRUNTIME_FUNCTION fctEntry; + PVOID hndData; +#endif + + +#ifdef _WIN64 + RtlCaptureContext (&GS_ContextRecord); + controlPC = GS_ContextRecord.Rip; + fctEntry = RtlLookupFunctionEntry (controlPC, &imgBase, NULL); + if (fctEntry != NULL) + { + RtlVirtualUnwind (UNW_FLAG_NHANDLER, imgBase, controlPC, fctEntry, + &GS_ContextRecord, &hndData, &establisherFrame, NULL); + } + else +#endif + { +#ifdef _WIN64 + GS_ContextRecord.Rip = (ULONGLONG) __builtin_return_address (0); + GS_ContextRecord.Rsp = (ULONGLONG) __builtin_frame_address (0) + 8; +#else + GS_ContextRecord.Eip = (DWORD) __builtin_return_address (0); + GS_ContextRecord.Esp = (DWORD) __builtin_frame_address (0) + 4; +#endif + } + +#ifdef _WIN64 + GS_ExceptionRecord.ExceptionAddress = (PVOID) GS_ContextRecord.Rip; + GS_ContextRecord.Rcx = StackCookie; +#else + GS_ExceptionRecord.ExceptionAddress = (PVOID) GS_ContextRecord.Eip; + GS_ContextRecord.Ecx = StackCookie; +#endif + GS_ExceptionRecord.ExceptionCode = STATUS_STACK_BUFFER_OVERRUN; + GS_ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE; + cookie[0] = __security_cookie; + cookie[1] = __security_cookie_complement; + SetUnhandledExceptionFilter (NULL); + UnhandledExceptionFilter ((EXCEPTION_POINTERS *) &GS_ExceptionPointers); + TerminateProcess (GetCurrentProcess (), STATUS_STACK_BUFFER_OVERRUN); + abort(); +} diff --git a/reactos/lib/3rdparty/mingw/init.c b/reactos/lib/3rdparty/mingw/init.c deleted file mode 100644 index b7af07c8b6a..00000000000 --- a/reactos/lib/3rdparty/mingw/init.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * init.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Code to initialize standard file handles and command line arguments. - * This file is #included in both crt1.c and dllcrt1.c. - * - */ - -/* - * Access to a standard 'main'-like argument count and list. Also included - * is a table of environment variables. - */ -int _argc = 0; -char **_argv = 0; - -/* NOTE: Thanks to Pedro A. Aranda Gutiirrez for pointing - * this out to me. GetMainArgs (used below) takes a fourth argument - * which is an int that controls the globbing of the command line. If - * _CRT_glob is non-zero the command line will be globbed (e.g. *.* - * expanded to be all files in the startup directory). In the mingw32 - * library a _CRT_glob variable is defined as being -1, enabling - * this command line globbing by default. To turn it off and do all - * command line processing yourself (and possibly escape bogons in - * MS's globbing code) include a line in one of your source modules - * defining _CRT_glob and setting it to zero, like this: - * int _CRT_glob = 0; - */ -extern int _CRT_glob; - -#ifdef __MSVCRT__ -typedef struct { - int newmode; -} _startupinfo; -extern void __getmainargs (int *, char ***, char ***, int, _startupinfo *); -#else -extern void __GetMainArgs (int *, char ***, char ***, int); -#endif - -/* - * Initialize the _argc, _argv and environ variables. - */ -static void -_mingw32_init_mainargs () -{ - /* The environ variable is provided directly in stdlib.h through - * a dll function call. */ - char **dummy_environ; -#ifdef __MSVCRT__ - _startupinfo start_info; - start_info.newmode = 0; -#endif - - /* - * Microsoft's runtime provides a function for doing just that. - */ -#ifdef __MSVCRT__ - (void) __getmainargs (&_argc, &_argv, &dummy_environ, _CRT_glob, - &start_info); -#else - /* CRTDLL version */ - (void) __GetMainArgs (&_argc, &_argv, &dummy_environ, _CRT_glob); -#endif -} - diff --git a/reactos/lib/3rdparty/mingw/internal.h b/reactos/lib/3rdparty/mingw/internal.h new file mode 100644 index 00000000000..91fe16f6ee2 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/internal.h @@ -0,0 +1,171 @@ +#ifndef _INC_INTERNAL +#define _INC_INTERNAL + +#include <_mingw.h> +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define _CRTALLOC(x) __attribute__ ((section (x) )) + +#pragma pack(push,_CRT_PACKING) + + typedef void (__cdecl *_PVFV)(void); + typedef int (__cdecl *_PIFV)(void); + typedef void (__cdecl *_PVFI)(int); + +#if defined (SPECIAL_CRTEXE) && defined (_DLL) + extern int _commode; +#else + _CRTIMP extern int _commode; +#endif + +#define __IOINFO_TM_ANSI 0 +#define __IOINFO_TM_UTF8 1 +#define __IOINFO_TM_UTF16LE 2 + + typedef struct { + intptr_t osfhnd; + char osfile; + char pipech; + int lockinitflag; + CRITICAL_SECTION lock; + char textmode : 7; + char unicode : 1; + char pipech2[2]; + } ioinfo; + +#define IOINFO_ARRAY_ELTS (1 << 5) + +#define _pioinfo(i) (__pioinfo[(i) >> 5] + ((i) & (IOINFO_ARRAY_ELTS - 1))) +#define _osfile(i) (_pioinfo(i)->osfile) +#define _pipech2(i) (_pioinfo(i)->pipech2) +#define _textmode(i) (_pioinfo(i)->textmode) +#define _tm_unicode(i) (_pioinfo(i)->unicode) +#define _pioinfo_safe(i) ((((i) != -1) && ((i) != -2)) ? _pioinfo(i) : &__badioinfo) +#define _osfhnd_safe(i) (_pioinfo_safe(i)->osfhnd) +#define _osfile_safe(i) (_pioinfo_safe(i)->osfile) +#define _pipech_safe(i) (_pioinfo_safe(i)->pipech) +#define _pipech2_safe(i) (_pioinfo_safe(i)->pipech2) +#define _textmode_safe(i) (_pioinfo_safe(i)->textmode) +#define _tm_unicode_safe(i) (_pioinfo_safe(i)->unicode) + +#ifndef __badioinfo + extern ioinfo ** _imp____badioinfo[]; +#define __badioinfo (*_imp____badioinfo) +#endif + +#ifndef __pioinfo + extern ioinfo ** _imp____pioinfo[]; +#define __pioinfo (*_imp____pioinfo) +#endif + +#define _NO_CONSOLE_FILENO (intptr_t)-2 + +#ifndef _FILE_DEFINED +#define _FILE_DEFINED + struct _iobuf { + char *_ptr; + int _cnt; + char *_base; + int _flag; + int _file; + int _charbuf; + int _bufsiz; + char *_tmpfname; + }; + typedef struct _iobuf FILE; +#endif + +#if !defined (_FILEX_DEFINED) && defined (_WINDOWS_) +#define _FILEX_DEFINED + typedef struct { + FILE f; + CRITICAL_SECTION lock; + } _FILEX; +#endif + + extern int _dowildcard; + extern int _newmode; + +#ifndef __winitenv +extern wchar_t ***_imp____winitenv; +#define __winitenv (*_imp____winitenv) +#endif + +#ifndef __initenv +extern char ***_imp____initenv; +#define __initenv (*_imp____initenv) +#endif + +#ifndef _acmdln +extern char **_imp___acmdln; +#define _acmdln (*_imp___acmdln) +/* _CRTIMP extern char *_acmdln; */ +#endif + +#ifndef _wcmdln +extern char **_imp___wcmdln; +#define _wcmdln (*_imp___wcmdln) +/* __CRTIMP extern wchar_t *_wcmdln; */ +#endif + + _CRTIMP void __cdecl _amsg_exit(int); + + int __CRTDECL _setargv(void); + int __CRTDECL __setargv(void); + int __CRTDECL _wsetargv(void); + int __CRTDECL __wsetargv(void); + + int __CRTDECL main(int _Argc, char **_Argv, char **_Env); + int __CRTDECL wmain(int _Argc, wchar_t **_Argv, wchar_t **_Env); + +#ifndef _STARTUP_INFO_DEFINED +#define _STARTUP_INFO_DEFINED + typedef struct { + int newmode; + } _startupinfo; +#endif + + _CRTIMP int __cdecl __getmainargs(int * _Argc, char *** _Argv, char ***_Env, int _DoWildCard, _startupinfo *_StartInfo); + _CRTIMP int __cdecl __wgetmainargs(int * _Argc, wchar_t ***_Argv, wchar_t ***_Env, int _DoWildCard, _startupinfo *_StartInfo); + +#define _CONSOLE_APP 1 +#define _GUI_APP 2 + + typedef enum __enative_startup_state { + __uninitialized, __initializing, __initialized + } __enative_startup_state; + + extern volatile __enative_startup_state __native_startup_state; + extern volatile void *__native_startup_lock; + + extern volatile unsigned int __native_dllmain_reason; + extern volatile unsigned int __native_vcclrit_reason; + + _CRTIMP void __cdecl __set_app_type (int); + + typedef LONG NTSTATUS; + +#include +#include + + void * __cdecl _encode_pointer(void *); + void * __cdecl _encoded_null(); + void * __cdecl _decode_pointer(void *); + + BOOL __cdecl _ValidateImageBase (PBYTE pImageBase); + PIMAGE_SECTION_HEADER __cdecl _FindPESection (PBYTE pImageBase, DWORD_PTR rva); + BOOL __cdecl _IsNonwritableInCurrentImage (PBYTE pTarget); + +#ifdef __cplusplus +} +#endif + +#pragma pack(pop) +#endif diff --git a/reactos/lib/3rdparty/mingw/isascii.c b/reactos/lib/3rdparty/mingw/isascii.c deleted file mode 100644 index 9d3385c3f01..00000000000 --- a/reactos/lib/3rdparty/mingw/isascii.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * isascii.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Oldnames from ANSI header ctype.h - * - * Some wrapper functions for those old name functions whose appropriate - * equivalents are not simply underscore prefixed. - * - */ - -#include - -int -isascii (int c) -{ - return __isascii(c); -} - diff --git a/reactos/lib/3rdparty/mingw/iscsym.c b/reactos/lib/3rdparty/mingw/iscsym.c deleted file mode 100644 index ea9a571ac18..00000000000 --- a/reactos/lib/3rdparty/mingw/iscsym.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * iscsym.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Oldnames from ANSI header ctype.h - * - * Some wrapper functions for those old name functions whose appropriate - * equivalents are not simply underscore prefixed. - * - */ - -#include - -int -iscsym (int c) -{ - return __iscsym(c); -} diff --git a/reactos/lib/3rdparty/mingw/iscsymf.c b/reactos/lib/3rdparty/mingw/iscsymf.c deleted file mode 100644 index 6afde993e6a..00000000000 --- a/reactos/lib/3rdparty/mingw/iscsymf.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * iscsymf.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Oldnames from ANSI header ctype.h - * - * Some wrapper functions for those old name functions whose appropriate - * equivalents are not simply underscore prefixed. - * - */ - -#include - -int -iscsymf (int c) -{ - return __iscsymf(c); -} - diff --git a/reactos/lib/3rdparty/mingw/main.c b/reactos/lib/3rdparty/mingw/main.c deleted file mode 100644 index f53ef06a606..00000000000 --- a/reactos/lib/3rdparty/mingw/main.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * main.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Extra startup code for applications which do not have a main function - * of their own (but do have a WinMain). Generally these are GUI - * applications, but they don't *have* to be. - * - */ - -#include -#include -#include - -#define ISSPACE(a) (a == ' ' || a == '\t') - -extern int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, - LPSTR szCmdLine, int nShow); - -int -main (int argc, const char *argv[], const char *environ[]) -{ - char *szCmd; - STARTUPINFO startinfo; - int nRet; - - /* Get the command line passed to the process. */ - szCmd = GetCommandLineA (); - GetStartupInfoA (&startinfo); - - /* Strip off the name of the application and any leading - * whitespace. */ - if (szCmd) - { - while (ISSPACE (*szCmd)) - { - szCmd++; - } - - /* On my system I always get the app name enclosed - * in quotes... */ - if (*szCmd == '\"') - { - do - { - szCmd++; - } - while (*szCmd != '\"' && *szCmd != '\0'); - - if (*szCmd == '\"') - { - szCmd++; - } - } - else - { - /* If no quotes then assume first token is program - * name. */ - while (!ISSPACE (*szCmd) && *szCmd != '\0') - { - szCmd++; - } - } - - while (ISSPACE (*szCmd)) - { - szCmd++; - } - } - - nRet = WinMain (GetModuleHandle (NULL), NULL, szCmd, - (startinfo.dwFlags & STARTF_USESHOWWINDOW) ? - startinfo.wShowWindow : SW_SHOWDEFAULT); - - return nRet; -} - diff --git a/reactos/lib/3rdparty/mingw/merr.c b/reactos/lib/3rdparty/mingw/merr.c new file mode 100644 index 00000000000..6e341b67781 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/merr.c @@ -0,0 +1,12 @@ +#include "internal.h" +#include + +int __defaultmatherr = 1; + +int __CRTDECL +_matherr (struct _exception *pexcept) +{ + /* Make compiler happy. */ + pexcept = pexcept; + return 0; +} diff --git a/reactos/lib/3rdparty/mingw/mingw.rbuild b/reactos/lib/3rdparty/mingw/mingw.rbuild index c1dbef73be1..b7ca7386fc7 100644 --- a/reactos/lib/3rdparty/mingw/mingw.rbuild +++ b/reactos/lib/3rdparty/mingw/mingw.rbuild @@ -1,41 +1,42 @@ - + include - cpu_features.c - CRTfmode.c - CRTglob.c - CRTinit.c + CRT_fp10.c + atonexit.c + charmax.c + cinitexe.c gccmain.c - getopt.c - isascii.c - iscsym.c - iscsymf.c - strcasecmp.c - strncasecmp.c - toascii.c - wcscmpi.c - _wgetopt.c - - pseudo-reloc.c - + gs_support.c + merr.c + mingw_helpers.c + natstart.c + _newmode.c + pesect.c + tlssup.c + wildcard.c + xtxtmode.c + xncommod.c + pseudo-reloc.c include - binmode.c - crt1.c - main.c + crt0_c.c + crtexe.c include - wbinmode.c - wcrt1.c - wmain.c + + + crt0_w.c + crtexe.c + include - dllcrt1.c + dllentry.c + dllmain.c diff --git a/reactos/lib/3rdparty/mingw/mingw_helpers.c b/reactos/lib/3rdparty/mingw/mingw_helpers.c new file mode 100644 index 00000000000..cccb9bf0ec0 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/mingw_helpers.c @@ -0,0 +1,25 @@ +#include "oscalls.h" +#include "internal.h" +#include +#include +#include +#include +#include + +const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback; + +void * __cdecl +_decode_pointer (void *codedptr) +{ + return (void *) codedptr; +} + +void * __cdecl +_encode_pointer (void *ptr) +{ + return ptr; +} + +/* 0:console, 1:windows. */ +int mingw_app_type = 0; + diff --git a/reactos/lib/3rdparty/mingw/moldname-msvcrt.def b/reactos/lib/3rdparty/mingw/moldname-msvcrt.def index 81049492177..b6ad6f662aa 100644 --- a/reactos/lib/3rdparty/mingw/moldname-msvcrt.def +++ b/reactos/lib/3rdparty/mingw/moldname-msvcrt.def @@ -1,5 +1,3 @@ - - ; ; moldname-msvcrt.def ; @@ -58,7 +56,6 @@ fileno ; fpreset fputchar fputwchar -fstat ftime gcvt getch @@ -98,7 +95,6 @@ spawnv spawnve spawnvp spawnvpe -stat strcmpi strdup stricmp @@ -151,9 +147,3 @@ cabs hypot logb nextafter - -; Additional definitions for ReactOS: -snwprintf -snprintf -strtoull=_strtoui64 -vsnprintf diff --git a/reactos/lib/3rdparty/mingw/natstart.c b/reactos/lib/3rdparty/mingw/natstart.c new file mode 100644 index 00000000000..733b5dc19ca --- /dev/null +++ b/reactos/lib/3rdparty/mingw/natstart.c @@ -0,0 +1,7 @@ +#include "internal.h" + +_PGLOBAL +volatile unsigned int __native_dllmain_reason = UINT_MAX; +volatile unsigned int __native_vcclrit_reason = UINT_MAX; +volatile __enative_startup_state __native_startup_state; +volatile void *__native_startup_lock; diff --git a/reactos/lib/3rdparty/mingw/oscalls.h b/reactos/lib/3rdparty/mingw/oscalls.h new file mode 100644 index 00000000000..f259ea8b97e --- /dev/null +++ b/reactos/lib/3rdparty/mingw/oscalls.h @@ -0,0 +1,41 @@ +#ifndef _INC_OSCALLS +#define _INC_OSCALLS + +#include <_mingw.h> + +#ifdef NULL +#undef NULL +#endif + +#define NOMINMAX + +#define _WIN32_FUSION 0x0100 +#include + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +typedef struct _FTIME +{ + unsigned short twosecs : 5; + unsigned short minutes : 6; + unsigned short hours : 5; +} FTIME; + +typedef FTIME *PFTIME; + +typedef struct _FDATE +{ + unsigned short day : 5; + unsigned short month : 4; + unsigned short year : 7; +} FDATE; + +typedef FDATE *PFDATE; + +#endif diff --git a/reactos/lib/3rdparty/mingw/pesect.c b/reactos/lib/3rdparty/mingw/pesect.c new file mode 100644 index 00000000000..ad85e72c145 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/pesect.c @@ -0,0 +1,66 @@ +#include + +#if defined (_WIN64) && defined (__ia64__) +#error FIXME: Unsupported __ImageBase implementation. +#else +/* Hack, for bug in ld. Will be removed soon. */ +#define __ImageBase _image_base__ +/* This symbol is defined by the linker. */ +extern IMAGE_DOS_HEADER __ImageBase; +#endif + +BOOL +_ValidateImageBase (PBYTE pImageBase) +{ + PIMAGE_DOS_HEADER pDOSHeader; + PIMAGE_NT_HEADERS pNTHeader; + PIMAGE_OPTIONAL_HEADER pOptHeader; + + pDOSHeader = (PIMAGE_DOS_HEADER) pImageBase; + if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE) + return FALSE; + pNTHeader = (PIMAGE_NT_HEADERS) ((PBYTE) pDOSHeader + pDOSHeader->e_lfanew); + if (pNTHeader->Signature != IMAGE_NT_SIGNATURE) + return FALSE; + pOptHeader = (PIMAGE_OPTIONAL_HEADER) &pNTHeader->OptionalHeader; + if (pOptHeader->Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC) + return FALSE; + return TRUE; +} + +PIMAGE_SECTION_HEADER +_FindPESection (PBYTE pImageBase, DWORD_PTR rva) +{ + PIMAGE_NT_HEADERS pNTHeader; + PIMAGE_SECTION_HEADER pSection; + unsigned int iSection; + + pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew); + + for (iSection = 0, pSection = IMAGE_FIRST_SECTION (pNTHeader); + iSection < pNTHeader->FileHeader.NumberOfSections; + ++iSection,++pSection) + { + if (rva >= pSection->VirtualAddress + && rva < pSection->VirtualAddress + pSection->Misc.VirtualSize) + return pSection; + } + return NULL; +} + +BOOL +_IsNonwritableInCurrentImage (PBYTE pTarget) +{ + PBYTE pImageBase; + DWORD_PTR rvaTarget; + PIMAGE_SECTION_HEADER pSection; + + pImageBase = (PBYTE) &__ImageBase; + if (! _ValidateImageBase (pImageBase)) + return FALSE; + rvaTarget = pTarget - pImageBase; + pSection = _FindPESection (pImageBase, rvaTarget); + if (pSection == NULL) + return FALSE; + return (pSection->Characteristics & IMAGE_SCN_MEM_WRITE) == 0; +} diff --git a/reactos/lib/3rdparty/mingw/strcasecmp.c b/reactos/lib/3rdparty/mingw/strcasecmp.c deleted file mode 100644 index a238e22f259..00000000000 --- a/reactos/lib/3rdparty/mingw/strcasecmp.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * strcasecmp.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Oldnames from ANSI header string.h - * - * Some wrapper functions for those old name functions whose appropriate - * equivalents are not simply underscore prefixed. - * - */ - -#include - -int -strcasecmp (const char *sz1, const char *sz2) -{ - return _stricmp (sz1, sz2); -} - diff --git a/reactos/lib/3rdparty/mingw/strncasecmp.c b/reactos/lib/3rdparty/mingw/strncasecmp.c deleted file mode 100644 index 7607ea1d001..00000000000 --- a/reactos/lib/3rdparty/mingw/strncasecmp.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * strncasecmp.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Oldnames from ANSI header string.h - * - * Some wrapper functions for those old name functions whose appropriate - * equivalents are not simply underscore prefixed. - * - */ - -#include - -int -strncasecmp (const char *sz1, const char *sz2, size_t sizeMaxCompare) -{ - return _strnicmp (sz1, sz2, sizeMaxCompare); -} - diff --git a/reactos/lib/3rdparty/mingw/tgetopt.h b/reactos/lib/3rdparty/mingw/tgetopt.h deleted file mode 100644 index 01e0b1ee489..00000000000 --- a/reactos/lib/3rdparty/mingw/tgetopt.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef _GETOPT_H -#define _GETOPT_H 1 - -#include - -#ifdef _UNICODE -#define _toption _woption -#define _toptarg _woptarg -#define _toptind _woptind -#define _topterr _wopterr -#define _toptopt _woptopt -#define _tgetopt _wgetopt -#define _tgetopt_long _wgetopt_long -#define _tgetopt_long_only _wgetopt_long_only -#define _tgetopt_internal _wgetopt_internal -#else -#define _toption option -#define _toptarg optarg -#define _toptind optind -#define _topterr opterr -#define _toptopt optopt -#define _tgetopt getopt -#define _tgetopt_long getopt_long -#define _tgetopt_long_only getopt_long_only -#define _tgetopt_internal _getopt_internal -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern char *optarg; -extern int optind; -extern int opterr; -extern int optopt; - -extern wchar_t *_woptarg; -extern int _woptind; -extern int _wopterr; -extern int _woptopt; - -struct option -{ - const char *name; - int has_arg; - int *flag; - int val; -}; - -struct _woption -{ - const wchar_t *name; - int has_arg; - int *flag; - int val; -}; - -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 - -extern int getopt (int argc, char *const *argv, const char *shortopts); -extern int getopt_long (int argc, char *const *argv, const char *shortopts, - const struct option *longopts, int *longind); -extern int getopt_long_only (int argc, char *const *argv, - const char *shortopts, const struct option *longopts, int *longind); - -extern int _wgetopt (int argc, wchar_t *const *argv, const wchar_t *shortopts); -extern int _wgetopt_long (int argc, wchar_t *const *argv, const wchar_t *shortopts, - const struct _woption *longopts, int *longind); -extern int _wgetopt_long_only (int argc, wchar_t *const *argv, - const wchar_t *shortopts, - const struct _woption *longopts, int *longind); - -extern int _getopt_internal (int argc, char *const *argv, - const char *shortopts, const struct option *longopts, int *longind, - int long_only); - -extern int _wgetopt_internal (int argc, wchar_t *const *argv, - const wchar_t *shortopts, - const struct _woption *longopts, int *longind, - int long_only); - -#ifdef __cplusplus -} -#endif - -#endif /* _GETOPT_H */ - diff --git a/reactos/lib/3rdparty/mingw/tlssup.c b/reactos/lib/3rdparty/mingw/tlssup.c new file mode 100644 index 00000000000..31d1daa5107 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/tlssup.c @@ -0,0 +1,129 @@ +#ifdef CRTDLL +#undef CRTDLL +#endif + +#include "internal.h" +#include +#include +#include + +#define FUNCS_PER_NODE 30 + +typedef struct TlsDtorNode { + int count; + struct TlsDtorNode *next; + _PVFV funcs[FUNCS_PER_NODE]; +} TlsDtorNode; + +ULONG _tls_index = 0; + +_CRTALLOC(".tls") char _tls_start = 0; +_CRTALLOC(".tls$ZZZ") char _tls_end = 0; + +_CRTALLOC(".CRT$XLA") PIMAGE_TLS_CALLBACK __xl_a = 0; +_CRTALLOC(".CRT$XLZ") PIMAGE_TLS_CALLBACK __xl_z = 0; + +#ifdef _WIN64 +_CRTALLOC(".rdata$T") const IMAGE_TLS_DIRECTORY64 _tls_used = { + (ULONGLONG) &_tls_start, (ULONGLONG) &_tls_end, (ULONGLONG) &_tls_index, + (ULONGLONG) (&__xl_a+1), (ULONG) 0, (ULONG) 0 +}; +#else +_CRTALLOC(".rdata$T") const IMAGE_TLS_DIRECTORY _tls_used = { + (ULONG)(ULONG_PTR) &_tls_start, (ULONG)(ULONG_PTR) &_tls_end, + (ULONG)(ULONG_PTR) &_tls_index, (ULONG)(ULONG_PTR) (&__xl_a+1), + (ULONG) 0, (ULONG) 0 +}; +#endif + +#ifndef __CRT_THREAD +#ifdef HAVE_ATTRIBUTE_THREAD +#define __CRT_THREAD __declspec(thread) +#else +#define __CRT_THREAD +#endif +#endif + +static _CRTALLOC(".CRT$XDA") _PVFV __xd_a = 0; +static _CRTALLOC(".CRT$XDZ") _PVFV __xd_z = 0; +static __CRT_THREAD TlsDtorNode *dtor_list; +static __CRT_THREAD TlsDtorNode dtor_list_head; + +BOOL WINAPI +__dyn_tls_init (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + _PVFV *pfunc; + + //DbgPrint("__dyn_tls_init: hDllHandle %p, dwReason %d\n", hDllHandle,dwReason); + if (dwReason != DLL_THREAD_ATTACH) + return TRUE; + + for (pfunc = &__xd_a + 1; pfunc != &__xd_z; ++pfunc) + { + //DbgPrint("pfunc at %p\n",pfunc); + if (*pfunc != NULL) + (*pfunc)(); + } + + return TRUE; +} + +const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback = (const PIMAGE_TLS_CALLBACK) __dyn_tls_init; +_CRTALLOC(".CRT$XLC") PIMAGE_TLS_CALLBACK __xl_c = (PIMAGE_TLS_CALLBACK) __dyn_tls_init; + +int __cdecl +__tlregdtor (_PVFV func) +{ + //DbgPrint("__tlregdtor: func %p\n",func); + + if (dtor_list == NULL) + { + dtor_list = &dtor_list_head; + dtor_list_head.count = 0; + } + else if (dtor_list->count == FUNCS_PER_NODE) + { + TlsDtorNode *pnode = (TlsDtorNode *) malloc (sizeof (TlsDtorNode)); + if (pnode == NULL) + return -1; + pnode->count = 0; + pnode->next = dtor_list; + dtor_list = pnode; + + dtor_list->count = 0; + } + dtor_list->funcs[dtor_list->count++] = func; + return 0; +} + +static BOOL WINAPI +__dyn_tls_dtor (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + + TlsDtorNode *pnode, *pnext; + int i; + + //DbgPrint("__dyn_tls_dtor: hDllHandle %p, dwReason %d\n"); + if (dwReason != DLL_THREAD_DETACH && dwReason != DLL_PROCESS_DETACH) + return TRUE; + + for (pnode = dtor_list; pnode != NULL; pnode = pnext) + { + for (i = pnode->count - 1; i >= 0; --i) + { + if (pnode->funcs[i] != NULL) + (*pnode->funcs[i])(); + } + pnext = pnode->next; + if (pnext != NULL) + free ((void *) pnode); + } + return TRUE; +} + +_CRTALLOC(".CRT$XLD") PIMAGE_TLS_CALLBACK __xl_d = (PIMAGE_TLS_CALLBACK) __dyn_tls_dtor; + + +int mingw_initltsdrot_force = 0; +int mingw_initltsdyn_force=0; +int mingw_initltssuo_force = 0; diff --git a/reactos/lib/3rdparty/mingw/toascii.c b/reactos/lib/3rdparty/mingw/toascii.c deleted file mode 100644 index be9f2f50bd5..00000000000 --- a/reactos/lib/3rdparty/mingw/toascii.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * toascii.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Oldnames from ANSI header ctype.h - * - * Some wrapper functions for those old name functions whose appropriate - * equivalents are not simply underscore prefixed. - * - */ - -#include - - -int -toascii (int c) -{ - return __toascii(c); -} - diff --git a/reactos/lib/3rdparty/mingw/wbinmode.c b/reactos/lib/3rdparty/mingw/wbinmode.c deleted file mode 100644 index 747bf44551b..00000000000 --- a/reactos/lib/3rdparty/mingw/wbinmode.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -/* Set default file mode to binary */ - -int _fmode = _O_BINARY; diff --git a/reactos/lib/3rdparty/mingw/wcrt1.c b/reactos/lib/3rdparty/mingw/wcrt1.c deleted file mode 100644 index 4edbbdcfe16..00000000000 --- a/reactos/lib/3rdparty/mingw/wcrt1.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * crt1.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Source code for the startup proceedures used by all programs. This code - * is compiled to make crt1.o, which should be located in the library path. - * - */ - -/* Hide the declaration of _fmode with dllimport attribute in stdlib.h to - avoid problems with older GCC. */ -#define __IN_MINGW_RUNTIME -#include -#include -#include -#include -#include -#include -#define WIN32_LEAN_AND_MEAN -#include -#include - -/* NOTE: The code for initializing the _argv, _argc, and environ variables - * has been moved to a separate .c file which is included in both - * crt1.c and dllcrt1.c. This means changes in the code don't have to - * be manually synchronized, but it does lead to this not-generally- - * a-good-idea use of include. */ -#include "winit.c" -#include "cpu_features.h" - -extern void _pei386_runtime_relocator (void); - -extern int wmain (int, wchar_t **, wchar_t **); - -/* - * Must have the correct app type for MSVCRT. - */ - -#ifdef __MSVCRT__ -#define __UNKNOWN_APP 0 -#define __CONSOLE_APP 1 -#define __GUI_APP 2 -__MINGW_IMPORT void __set_app_type(int); -#endif /* __MSVCRT__ */ - -#ifndef __winitenv -extern wchar_t ***_imp____winitenv; -#define __winitenv (*_imp____winitenv) -#endif - -/* - * Setup the default file handles to have the _CRT_fmode mode, as well as - * any new files created by the user. - */ -extern int _CRT_fmode; - -static void -_mingw32_init_fmode (void) -{ - /* Don't set the std file mode if the user hasn't set any value for it. */ - if (_CRT_fmode) - { - *_imp___fmode = _CRT_fmode; - - /* - * This overrides the default file mode settings for stdin, - * stdout and stderr. At first I thought you would have to - * test with isatty, but it seems that the DOS console at - * least is smart enough to handle _O_BINARY stdout and - * still display correctly. - */ - if (stdin) - { - _setmode (_fileno (stdin), _CRT_fmode); - } - if (stdout) - { - _setmode (_fileno (stdout), _CRT_fmode); - } - if (stderr) - { - _setmode (_fileno (stderr), _CRT_fmode); - } - } - - /* Now sync the dll _fmode to the one for this .exe. */ -#ifdef __MSVCRT__ - *_imp___fmode = _fmode; -#else - *_imp___fmode_dll = _fmode; -#endif -} - -/* This function will be called when a trap occurs. Thanks to Jacob - Navia for his contribution. */ -static LONG CALLBACK -_gnu_exception_handler (EXCEPTION_POINTERS * exception_data) -{ - void (*old_handler) (int); - LONG action = EXCEPTION_CONTINUE_SEARCH; - int reset_fpu = 0; - - switch (exception_data->ExceptionRecord->ExceptionCode) - { - case EXCEPTION_ACCESS_VIOLATION: - /* test if the user has set SIGSEGV */ - old_handler = signal (SIGSEGV, SIG_DFL); - if (old_handler == SIG_IGN) - { - /* this is undefined if the signal was raised by anything other - than raise (). */ - signal (SIGSEGV, SIG_IGN); - action = EXCEPTION_CONTINUE_EXECUTION; - } - else if (old_handler != SIG_DFL) - { - /* This means 'old' is a user defined function. Call it */ - (*old_handler) (SIGSEGV); - action = EXCEPTION_CONTINUE_EXECUTION; - } - break; - - case EXCEPTION_ILLEGAL_INSTRUCTION: - case EXCEPTION_PRIV_INSTRUCTION: - /* test if the user has set SIGILL */ - old_handler = signal (SIGILL, SIG_DFL); - if (old_handler == SIG_IGN) - { - /* this is undefined if the signal was raised by anything other - than raise (). */ - signal (SIGILL, SIG_IGN); - action = EXCEPTION_CONTINUE_EXECUTION; - } - else if (old_handler != SIG_DFL) - { - /* This means 'old' is a user defined function. Call it */ - (*old_handler) (SIGILL); - action = EXCEPTION_CONTINUE_EXECUTION; - } - break; - - case EXCEPTION_FLT_INVALID_OPERATION: - case EXCEPTION_FLT_DIVIDE_BY_ZERO: - case EXCEPTION_FLT_DENORMAL_OPERAND: - case EXCEPTION_FLT_OVERFLOW: - case EXCEPTION_FLT_UNDERFLOW: - case EXCEPTION_FLT_INEXACT_RESULT: - reset_fpu = 1; - /* fall through. */ - - case EXCEPTION_INT_DIVIDE_BY_ZERO: - /* test if the user has set SIGFPE */ - old_handler = signal (SIGFPE, SIG_DFL); - if (old_handler == SIG_IGN) - { - signal (SIGFPE, SIG_IGN); - if (reset_fpu) - _fpreset (); - action = EXCEPTION_CONTINUE_EXECUTION; - } - else if (old_handler != SIG_DFL) - { - /* This means 'old' is a user defined function. Call it */ - (*old_handler) (SIGFPE); - action = EXCEPTION_CONTINUE_EXECUTION; - } - break; - - default: - break; - } - return action; -} - -/* - * The function mainCRTStartup is the entry point for all console programs. - */ -static void __attribute__((noreturn)) -__mingw_wCRTStartup (void) -{ - int nRet; - - /* - * Set up the top-level exception handler so that signal handling - * works as expected. The mapping between ANSI/POSIX signals and - * Win32 SE is not 1-to-1, so caveat emptore. - * - */ - SetUnhandledExceptionFilter (_gnu_exception_handler); - - /* - * Initialize floating point unit. - */ - __cpu_features_init (); /* Do we have SSE, etc.*/ - _fpreset (); /* Supplied by the runtime library. */ - - /* - * Set up __argc, __argv and _wenviron. - */ - _mingw32_init_wmainargs (); - - /* - * Sets the default file mode. - * If _CRT_fmode is set, also set mode for stdin, stdout - * and stderr, as well - * NOTE: DLLs don't do this because that would be rude! - */ - _mingw32_init_fmode (); - - /* Adust references to dllimported data that have non-zero offsets. */ -#if defined(__i386__) - _pei386_runtime_relocator (); -#endif - -#if defined(__i386__) - /* Align the stack to 16 bytes for the sake of SSE ops in main - or in functions inlined into main. */ - asm __volatile__ ("andl $-16, %%esp" : : : "%esp"); -#elif defined(__x86_64__) - /* Align the stack to 16 bytes */ - asm __volatile__ ("andq $-16, %%rsp" : : : "%rsp"); -#elif defined(__mips__) - /* Align the stack to 16 bytes */ - asm __volatile__ ("andi %sp,%sp,-16" : : : "%sp"); -#elif defined(__PowerPC__) - /* Align the stack to 16 bytes */ - asm __volatile__ ("li 0,15\n\tandc 1,1,0" : : : "r1"); -#else -#error Unsupported architecture -#endif - - /* - * Call the main function. If the user does not supply one - * the one in the 'libmingw32.a' library will be linked in, and - * that one calls WinMain. See main.c in the 'lib' dir - * for more details. - */ - nRet = wmain (_argc, _wargv, __winitenv); - - /* - * Perform exit processing for the C library. This means - * flushing output and calling 'atexit' registered functions. - */ - _cexit (); - - ExitProcess (nRet); -} - -/* - * The function mainCRTStartup is the entry point for all console programs. - */ -void -wmainCRTStartup (void) -{ -#ifdef __MSVCRT__ - __set_app_type (__CONSOLE_APP); -#endif - __mingw_wCRTStartup (); -} - -/* - * For now the GUI startup function is the same as the console one. - * This simply gets rid of the annoying warning about not being able - * to find WinMainCRTStartup when linking GUI applications. - */ -void -wWinMainCRTStartup (void) -{ -#ifdef __MSVCRT__ - __set_app_type (__GUI_APP); -#endif - __mingw_wCRTStartup (); -} - -#if 0 -/* - * We force use of library version of atexit, which is only - * visible in import lib as _imp__atexit - */ -extern int (*_imp__atexit)(void (*)(void)); -int atexit (void (* pfn )(void) ) -{ - return ( (*_imp__atexit)(pfn)); -} - -/* Likewise for non-ANSI _onexit */ -extern _onexit_t (*_imp___onexit)(_onexit_t); -_onexit_t -_onexit (_onexit_t pfn ) -{ - return (*_imp___onexit)(pfn); -} -#endif diff --git a/reactos/lib/3rdparty/mingw/wcscmpi.c b/reactos/lib/3rdparty/mingw/wcscmpi.c deleted file mode 100644 index 497964b3964..00000000000 --- a/reactos/lib/3rdparty/mingw/wcscmpi.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * wcscmpi.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Oldnames from ANSI header string.h - * - * Some wrapper functions for those old name functions whose appropriate - * equivalents are not simply underscore prefixed. - * - */ - -#include - -int -wcscmpi (const wchar_t * ws1, const wchar_t * ws2) -{ - return _wcsicmp (ws1, ws2); -} - diff --git a/reactos/lib/3rdparty/mingw/wildcard.c b/reactos/lib/3rdparty/mingw/wildcard.c new file mode 100644 index 00000000000..b0eca486ac8 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/wildcard.c @@ -0,0 +1 @@ +int _dowildcard = 0; diff --git a/reactos/lib/3rdparty/mingw/winit.c b/reactos/lib/3rdparty/mingw/winit.c deleted file mode 100644 index ebe7ea3d15f..00000000000 --- a/reactos/lib/3rdparty/mingw/winit.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * init.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Code to initialize standard file handles and command line arguments. - * This file is #included in both crt1.c and dllcrt1.c. - * - */ - -/* - * Access to a standard 'main'-like argument count and list. Also included - * is a table of environment variables. - */ -int _argc = 0; -wchar_t **_wargv = 0; - -/* NOTE: Thanks to Pedro A. Aranda Gutiirrez for pointing - * this out to me. GetMainArgs (used below) takes a fourth argument - * which is an int that controls the globbing of the command line. If - * _CRT_glob is non-zero the command line will be globbed (e.g. *.* - * expanded to be all files in the startup directory). In the mingw32 - * library a _CRT_glob variable is defined as being -1, enabling - * this command line globbing by default. To turn it off and do all - * command line processing yourself (and possibly escape bogons in - * MS's globbing code) include a line in one of your source modules - * defining _CRT_glob and setting it to zero, like this: - * int _CRT_glob = 0; - */ -extern int _CRT_glob; - -#ifdef __MSVCRT__ -typedef struct { - int newmode; -} _startupinfo; -extern void __wgetmainargs (int *, wchar_t ***, wchar_t ***, int, _startupinfo *); -#else -#error Cannot build unicode version against crtdll -#endif - -/* - * Initialize the _argc, _argv and environ variables. - */ -static void -_mingw32_init_wmainargs () -{ - /* The environ variable is provided directly in stdlib.h through - * a dll function call. */ - wchar_t **dummy_environ; -#ifdef __MSVCRT__ - _startupinfo start_info; - start_info.newmode = 0; -#endif - - /* - * Microsoft's runtime provides a function for doing just that. - */ -#ifdef __MSVCRT__ - (void) __wgetmainargs (&_argc, &_wargv, &dummy_environ, _CRT_glob, - &start_info); -#else -#error Cannot build unicode version against crtdll -#endif -} - diff --git a/reactos/lib/3rdparty/mingw/wmain.c b/reactos/lib/3rdparty/mingw/wmain.c deleted file mode 100644 index ef363db8e79..00000000000 --- a/reactos/lib/3rdparty/mingw/wmain.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * main.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * Extra startup code for applications which do not have a main function - * of their own (but do have a WinMain). Generally these are GUI - * applications, but they don't *have* to be. - * - */ - -#include -#include -#include - -#define ISSPACE(a) (a == ' ' || a == '\t') - -extern void __main(); -extern int PASCAL wWinMain (HINSTANCE hInst, HINSTANCE hPrevInst, - LPWSTR szCmdLine, int nShow); - -int -wmain (int argc, const wchar_t *argv[], const wchar_t *environ[]) -{ - wchar_t *szCmd; - STARTUPINFOW startinfo; - int nRet; - -#ifdef __GNUC__ - /* C++ initialization. (gcc inserts this call automatically for - * a function called "main", but not for "wmain") */ - __main(); -#endif - - /* Get the command line passed to the process. */ - szCmd = GetCommandLineW (); - GetStartupInfoW (&startinfo); - - /* Strip off the name of the application and any leading - * whitespace. */ - if (szCmd) - { - while (ISSPACE (*szCmd)) - { - szCmd++; - } - - /* On my system I always get the app name enclosed - * in quotes... */ - if (*szCmd == '\"') - { - do - { - szCmd++; - } - while (*szCmd != '\"' && *szCmd != '\0'); - - if (*szCmd == '\"') - { - szCmd++; - } - } - else - { - /* If no quotes then assume first token is program - * name. */ - while (!ISSPACE (*szCmd) && *szCmd != '\0') - { - szCmd++; - } - } - - while (ISSPACE (*szCmd)) - { - szCmd++; - } - } - - nRet = wWinMain (GetModuleHandle (NULL), NULL, szCmd, - (startinfo.dwFlags & STARTF_USESHOWWINDOW) ? - startinfo.wShowWindow : SW_SHOWDEFAULT); - - return nRet; -} - diff --git a/reactos/lib/3rdparty/mingw/xncommod.c b/reactos/lib/3rdparty/mingw/xncommod.c new file mode 100644 index 00000000000..0d2a0a45ca9 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/xncommod.c @@ -0,0 +1 @@ +int _commode = 0; diff --git a/reactos/lib/3rdparty/mingw/xthdloc.c b/reactos/lib/3rdparty/mingw/xthdloc.c new file mode 100644 index 00000000000..19f4bb47810 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/xthdloc.c @@ -0,0 +1 @@ +int __globallocalestatus = ~0x1; diff --git a/reactos/lib/3rdparty/mingw/xtxtmode.c b/reactos/lib/3rdparty/mingw/xtxtmode.c new file mode 100644 index 00000000000..3cc2971326b --- /dev/null +++ b/reactos/lib/3rdparty/mingw/xtxtmode.c @@ -0,0 +1 @@ +int _fmode = 0;