From 8d291610ee804189f0065ff951bd0ed89c1ffe09 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Sat, 14 Mar 2009 00:50:23 +0000 Subject: [PATCH] - Sync the common mingw stuff with mingw-w64 HEAD Only few modifications were necessary to get it to work flawlessy with our tree: -> getopt.c, which should rather be a part of "mingwex" (if we need the two Unix apps using it at all..) -> Adding an 'extern int __globallocalestatus;' to the "internal.h" -> Disabling the custom __mingw_get_crt_info, which depends on defines inside the mingw-w64 tree -> Small warning fixes, which will be submitted to mingw-w64 - Add an include directory "include/reactos/mingw-w64" for their header stuff to make synchronizations easier. - Remove remainders of our previous initialization routines, which still co-existed beside the new ones - Remove misleading and unnecessary files (i.e. "binmode.c") svn path=/trunk/; revision=40006 --- .../reactos/mingw-w64}/internal.h | 11 +- .../reactos/mingw-w64}/oscalls.h | 12 +- .../include/reactos/mingw-w64/sect_attribs.h | 60 ++ reactos/lib/3rdparty/mingw/CRT_fp10.c | 6 + reactos/lib/3rdparty/mingw/CRT_fp8.c | 6 + reactos/lib/3rdparty/mingw/_newmode.c | 6 + reactos/lib/3rdparty/mingw/_wgetopt.c | 15 - reactos/lib/3rdparty/mingw/atonexit.c | 11 +- reactos/lib/3rdparty/mingw/binmode.c | 4 - reactos/lib/3rdparty/mingw/charmax.c | 18 +- reactos/lib/3rdparty/mingw/cinitexe.c | 3 +- reactos/lib/3rdparty/mingw/crt0_c.c | 6 + reactos/lib/3rdparty/mingw/crt0_w.c | 13 +- reactos/lib/3rdparty/mingw/crtdll.c | 6 + reactos/lib/3rdparty/mingw/crtexe.c | 50 +- reactos/lib/3rdparty/mingw/dllargv.c | 22 +- reactos/lib/3rdparty/mingw/dllentry.c | 8 +- reactos/lib/3rdparty/mingw/dllmain.c | 3 +- reactos/lib/3rdparty/mingw/gccmain.c | 14 +- reactos/lib/3rdparty/mingw/getopt.c | 515 +++++++++++++----- reactos/lib/3rdparty/mingw/gs_support.c | 14 +- reactos/lib/3rdparty/mingw/isascii.c | 25 - reactos/lib/3rdparty/mingw/iscsym.c | 24 - reactos/lib/3rdparty/mingw/iscsymf.c | 25 - reactos/lib/3rdparty/mingw/merr.c | 51 +- reactos/lib/3rdparty/mingw/mingw.rbuild | 18 +- reactos/lib/3rdparty/mingw/mingw_helpers.c | 22 +- .../lib/3rdparty/mingw/moldname-msvcrt.def | 37 +- reactos/lib/3rdparty/mingw/natstart.c | 9 +- reactos/lib/3rdparty/mingw/pesect.c | 6 + .../lib/3rdparty/mingw/pseudo-reloc-list.c | 6 + reactos/lib/3rdparty/mingw/pseudo-reloc.c | 45 +- reactos/lib/3rdparty/mingw/tgetopt.h | 90 --- reactos/lib/3rdparty/mingw/tlssup.c | 17 +- reactos/lib/3rdparty/mingw/toascii.c | 25 - reactos/lib/3rdparty/mingw/wcrt1.c | 308 ----------- reactos/lib/3rdparty/mingw/wildcard.c | 6 + reactos/lib/3rdparty/mingw/xncommod.c | 6 + reactos/lib/3rdparty/mingw/xthdloc.c | 6 + reactos/lib/3rdparty/mingw/xtxtmode.c | 6 + 40 files changed, 757 insertions(+), 778 deletions(-) rename reactos/{lib/3rdparty/mingw => include/reactos/mingw-w64}/internal.h (94%) rename reactos/{lib/3rdparty/mingw => include/reactos/mingw-w64}/oscalls.h (62%) create mode 100644 reactos/include/reactos/mingw-w64/sect_attribs.h delete mode 100644 reactos/lib/3rdparty/mingw/_wgetopt.c delete mode 100644 reactos/lib/3rdparty/mingw/binmode.c 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/tgetopt.h delete mode 100644 reactos/lib/3rdparty/mingw/toascii.c delete mode 100644 reactos/lib/3rdparty/mingw/wcrt1.c diff --git a/reactos/lib/3rdparty/mingw/internal.h b/reactos/include/reactos/mingw-w64/internal.h similarity index 94% rename from reactos/lib/3rdparty/mingw/internal.h rename to reactos/include/reactos/mingw-w64/internal.h index 6c17f24232e..8786e25bbc6 100644 --- a/reactos/lib/3rdparty/mingw/internal.h +++ b/reactos/include/reactos/mingw-w64/internal.h @@ -1,8 +1,13 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #ifndef _INC_INTERNAL #define _INC_INTERNAL -#include <_mingw.h> -#include +#include #ifdef __cplusplus extern "C" { @@ -11,8 +16,6 @@ extern "C" { #include #include -#define _CRTALLOC(x) __attribute__ ((section (x) )) - #pragma pack(push,_CRT_PACKING) typedef void (__cdecl *_PVFV)(void); diff --git a/reactos/lib/3rdparty/mingw/oscalls.h b/reactos/include/reactos/mingw-w64/oscalls.h similarity index 62% rename from reactos/lib/3rdparty/mingw/oscalls.h rename to reactos/include/reactos/mingw-w64/oscalls.h index f259ea8b97e..cdcb23e51db 100644 --- a/reactos/lib/3rdparty/mingw/oscalls.h +++ b/reactos/include/reactos/mingw-w64/oscalls.h @@ -1,7 +1,17 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #ifndef _INC_OSCALLS #define _INC_OSCALLS -#include <_mingw.h> +#ifndef _CRTBLD +#error ERROR: Use of C runtime library internal header file. +#endif + +#include #ifdef NULL #undef NULL diff --git a/reactos/include/reactos/mingw-w64/sect_attribs.h b/reactos/include/reactos/mingw-w64/sect_attribs.h new file mode 100644 index 00000000000..681b0cb3197 --- /dev/null +++ b/reactos/include/reactos/mingw-w64/sect_attribs.h @@ -0,0 +1,60 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#if defined (__ia64__) || defined (__x86_64) +#define _ATTRIBUTES +#else +#define _ATTRIBUTES shared +#endif + +#if 0 +/* Reference list of existing section for msvcrt. */ +#pragma section(".CRTMP$XCA",long,_ATTRIBUTES) +#pragma section(".CRTMP$XCZ",long,_ATTRIBUTES) +#pragma section(".CRTMP$XIA",long,_ATTRIBUTES) +#pragma section(".CRTMP$XIZ",long,_ATTRIBUTES) + +#pragma section(".CRTMA$XCA",long,_ATTRIBUTES) +#pragma section(".CRTMA$XCZ",long,_ATTRIBUTES) +#pragma section(".CRTMA$XIA",long,_ATTRIBUTES) +#pragma section(".CRTMA$XIZ",long,_ATTRIBUTES) + +#pragma section(".CRTVT$XCA",long,_ATTRIBUTES) +#pragma section(".CRTVT$XCZ",long,_ATTRIBUTES) + +#pragma section(".CRT$XCA",long,_ATTRIBUTES) +#pragma section(".CRT$XCAA",long,_ATTRIBUTES) +#pragma section(".CRT$XCC",long,_ATTRIBUTES) +#pragma section(".CRT$XCZ",long,_ATTRIBUTES) +#pragma section(".CRT$XDA",long,_ATTRIBUTES) +#pragma section(".CRT$XDC",long,_ATTRIBUTES) +#pragma section(".CRT$XDZ",long,_ATTRIBUTES) +#pragma section(".CRT$XIA",long,_ATTRIBUTES) +#pragma section(".CRT$XIAA",long,_ATTRIBUTES) +#pragma section(".CRT$XIC",long,_ATTRIBUTES) +#pragma section(".CRT$XID",long,_ATTRIBUTES) +#pragma section(".CRT$XIY",long,_ATTRIBUTES) +#pragma section(".CRT$XIZ",long,_ATTRIBUTES) +#pragma section(".CRT$XLA",long,_ATTRIBUTES) +#pragma section(".CRT$XLC",long,_ATTRIBUTES) +#pragma section(".CRT$XLD",long,_ATTRIBUTES) +#pragma section(".CRT$XLZ",long,_ATTRIBUTES) +#pragma section(".CRT$XPA",long,_ATTRIBUTES) +#pragma section(".CRT$XPX",long,_ATTRIBUTES) +#pragma section(".CRT$XPXA",long,_ATTRIBUTES) +#pragma section(".CRT$XPZ",long,_ATTRIBUTES) +#pragma section(".CRT$XTA",long,_ATTRIBUTES) +#pragma section(".CRT$XTB",long,_ATTRIBUTES) +#pragma section(".CRT$XTX",long,_ATTRIBUTES) +#pragma section(".CRT$XTZ",long,_ATTRIBUTES) +#pragma section(".rdata$T",long,read) +#pragma section(".rtc$IAA",long,read) +#pragma section(".rtc$IZZ",long,read) +#pragma section(".rtc$TAA",long,read) +#pragma section(".rtc$TZZ",long,read) +#endif + +#define _CRTALLOC(x) __attribute__ ((section (x) )) diff --git a/reactos/lib/3rdparty/mingw/CRT_fp10.c b/reactos/lib/3rdparty/mingw/CRT_fp10.c index d12ffa7c8d9..2c78afb7d7e 100644 --- a/reactos/lib/3rdparty/mingw/CRT_fp10.c +++ b/reactos/lib/3rdparty/mingw/CRT_fp10.c @@ -1,3 +1,9 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + void _fpreset (void) { __asm__ ("fninit" ) ;} diff --git a/reactos/lib/3rdparty/mingw/CRT_fp8.c b/reactos/lib/3rdparty/mingw/CRT_fp8.c index 789e71c73d5..49f8a1b5725 100644 --- a/reactos/lib/3rdparty/mingw/CRT_fp8.c +++ b/reactos/lib/3rdparty/mingw/CRT_fp8.c @@ -1,3 +1,9 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + extern void (*_imp___fpreset)(void) ; void _fpreset (void) { (*_imp___fpreset)(); } diff --git a/reactos/lib/3rdparty/mingw/_newmode.c b/reactos/lib/3rdparty/mingw/_newmode.c index fb6962135bc..e154284c3bf 100644 --- a/reactos/lib/3rdparty/mingw/_newmode.c +++ b/reactos/lib/3rdparty/mingw/_newmode.c @@ -1 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + 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/atonexit.c b/reactos/lib/3rdparty/mingw/atonexit.c index 1affa3b50b8..9e4b3a5e6fa 100644 --- a/reactos/lib/3rdparty/mingw/atonexit.c +++ b/reactos/lib/3rdparty/mingw/atonexit.c @@ -1,11 +1,18 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #undef CRTDLL #ifndef _DLL #define _DLL #endif -#include "oscalls.h" -#include "internal.h" +#include +#include #include +#include #include #include diff --git a/reactos/lib/3rdparty/mingw/binmode.c b/reactos/lib/3rdparty/mingw/binmode.c deleted file mode 100644 index b5aec2461b2..00000000000 --- a/reactos/lib/3rdparty/mingw/binmode.c +++ /dev/null @@ -1,4 +0,0 @@ -#define SPECIAL_CRTEXE - -#include -#include diff --git a/reactos/lib/3rdparty/mingw/charmax.c b/reactos/lib/3rdparty/mingw/charmax.c index c80f8a61141..7442633fe6c 100644 --- a/reactos/lib/3rdparty/mingw/charmax.c +++ b/reactos/lib/3rdparty/mingw/charmax.c @@ -1,9 +1,21 @@ -#include "internal.h" +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ -int __lconv_init (void); +#include +#include + +__declspec(dllimport) int __lconv_init (void); int mingw_initcharmax = 0; int _charmax = 255; -_CRTALLOC(".CRT$XIC") _PIFV __mingw_pinit = __lconv_init; +static int my_lconv_init(void) +{ + return __lconv_init(); +} + +_CRTALLOC(".CRT$XIC") _PIFV __mingw_pinit = my_lconv_init; diff --git a/reactos/lib/3rdparty/mingw/cinitexe.c b/reactos/lib/3rdparty/mingw/cinitexe.c index ac0a6a98b9a..b69eebe7eb9 100644 --- a/reactos/lib/3rdparty/mingw/cinitexe.c +++ b/reactos/lib/3rdparty/mingw/cinitexe.c @@ -1,5 +1,6 @@ #include -#include "internal.h" +#include +#include _CRTALLOC(".CRT$XIA") _PVFV __xi_a[] = { NULL }; _CRTALLOC(".CRT$XIZ") _PVFV __xi_z[] = { NULL }; diff --git a/reactos/lib/3rdparty/mingw/crt0_c.c b/reactos/lib/3rdparty/mingw/crt0_c.c index 11bcb68a1af..577fa8772be 100644 --- a/reactos/lib/3rdparty/mingw/crt0_c.c +++ b/reactos/lib/3rdparty/mingw/crt0_c.c @@ -1,3 +1,9 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #include int main (int flags, char **cmdline, char **inst) diff --git a/reactos/lib/3rdparty/mingw/crt0_w.c b/reactos/lib/3rdparty/mingw/crt0_w.c index 79e33ea9d68..06e4afe6319 100644 --- a/reactos/lib/3rdparty/mingw/crt0_w.c +++ b/reactos/lib/3rdparty/mingw/crt0_w.c @@ -1,13 +1,20 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #include +extern void __main(void); + int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nShowCmd); -void __main(void); int wmain (int flags, wchar_t **cmdline, wchar_t **inst) { #ifdef __GNUC__ - /* C++ initialization. (gcc inserts this call automatically for - * a function called "main", but not for "wmain") */ + /* C++ initialization. + gcc inserts this call automatically for a function called main , but not for wmain. */ __main(); #endif return (int) wWinMain ((HINSTANCE) inst, NULL, (LPWSTR) cmdline,(DWORD) flags); diff --git a/reactos/lib/3rdparty/mingw/crtdll.c b/reactos/lib/3rdparty/mingw/crtdll.c index c5bd1950c2f..ef2bacd20e5 100644 --- a/reactos/lib/3rdparty/mingw/crtdll.c +++ b/reactos/lib/3rdparty/mingw/crtdll.c @@ -1,3 +1,9 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #ifdef CRTDLL #undef CRTDLL #define _DLL diff --git a/reactos/lib/3rdparty/mingw/crtexe.c b/reactos/lib/3rdparty/mingw/crtexe.c index 0e4453596b3..ae4db0dc858 100644 --- a/reactos/lib/3rdparty/mingw/crtexe.c +++ b/reactos/lib/3rdparty/mingw/crtexe.c @@ -1,15 +1,22 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #undef CRTDLL //#define _DLL #define SPECIAL_CRTEXE -#include "oscalls.h" -#include "internal.h" +#include +#include #include #include #include #include #include +#include #include #ifndef __winitenv @@ -42,6 +49,7 @@ extern int *_imp___commode; #define _commode (*_imp___commode) extern int _dowildcard; +int _MINGW_INSTALL_DEBUG_MATHERR __attribute__((weak)) = 0; extern int __defaultmatherr; extern _CRTIMP void __cdecl _initterm(_PVFV *, _PVFV *); @@ -76,7 +84,7 @@ 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); +static LONG __mingw_vex(EXCEPTION_POINTERS * exception_data); #ifdef WPRFLAG static void duplicate_ppstrings (int ac, wchar_t ***av); #else @@ -107,9 +115,14 @@ pre_c_init (void) #else _setargv(); #endif - - if (! __defaultmatherr) - __setusermatherr (_matherr); + if (_MINGW_INSTALL_DEBUG_MATHERR) + { + if (! __defaultmatherr) + { + __setusermatherr (_matherr); + __defaultmatherr = 1; + } + } if (__globallocalestatus == -1) { @@ -202,23 +215,23 @@ __tmainCRTStartup (void) if (__dyn_tls_init_callback != NULL && _IsNonwritableInCurrentImage ((PBYTE) &__dyn_tls_init_callback)) __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL); -#if defined(__i386__) || defined(__x86_64__) _pei386_runtime_relocator (); -#endif - #if defined(__x86_64__) + #ifdef _WIN64 __asm__ __volatile__ ( "xorq %rax,%rax\n\t" "decq %rax\n\t" "movq %rax,%gs:0" "\n"); - #elif defined(__i386__) + #else __asm__ __volatile__ ( "xorl %eax,%eax\n\t" "decl %eax\n\t" "movl %eax,%fs:0" "\n"); #endif - //AddVectoredExceptionHandler (0, (PVECTORED_EXCEPTION_HANDLER)__mingw_vex); + AddVectoredExceptionHandler (0, (PVECTORED_EXCEPTION_HANDLER)__mingw_vex); SetUnhandledExceptionFilter (_gnu_exception_handler); + + _fpreset (); if (mingw_app_type) { @@ -229,10 +242,10 @@ __tmainCRTStartup (void) #else lpszCommandLine = (char *) _acmdln; #endif - while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine && inDoubleQuote)) + while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine&&inDoubleQuote)) { if (*lpszCommandLine == DQUOTECHAR) - inDoubleQuote = TRUE; + inDoubleQuote = !inDoubleQuote; #ifdef _MBCS if (_ismbblead (*lpszCommandLine)) { @@ -289,10 +302,9 @@ check_managed_app (void) PIMAGE_OPTIONAL_HEADER64 pNTHeader64; /* Force to be linked. */ - //TLS sections - //mingw_initltsdrot_force=1; - //mingw_initltsdyn_force=1; - //mingw_initltssuo_force=1; + mingw_initltsdrot_force=1; + mingw_initltsdyn_force=1; + mingw_initltssuo_force=1; mingw_initcharmax=1; pDOSHeader = (PIMAGE_DOS_HEADER) &__ImageBase; @@ -319,8 +331,6 @@ check_managed_app (void) return 0; } -int __defaultmatherr; - static CALLBACK long _gnu_exception_handler (EXCEPTION_POINTERS * exception_data) { @@ -400,7 +410,6 @@ _gnu_exception_handler (EXCEPTION_POINTERS * exception_data) return action; } -#if 0 static LONG __mingw_vex(EXCEPTION_POINTERS * exception_data) { /* TODO this is not chainablem, therefore need rewrite. Disabled the ill code. */ @@ -425,7 +434,6 @@ static LONG __mingw_vex(EXCEPTION_POINTERS * exception_data) #endif return _gnu_exception_handler(exception_data); } -#endif #ifdef WPRFLAG diff --git a/reactos/lib/3rdparty/mingw/dllargv.c b/reactos/lib/3rdparty/mingw/dllargv.c index 7aa65560994..376479c4d72 100644 --- a/reactos/lib/3rdparty/mingw/dllargv.c +++ b/reactos/lib/3rdparty/mingw/dllargv.c @@ -1,10 +1,14 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #ifdef CRTDLL #undef CRTDLL #endif -#include "internal.h" - -extern int _dowildcard; +#include #ifdef WPRFLAG int __CRTDECL @@ -16,15 +20,3 @@ _setargv (void) { return 0; } - -#ifdef WPRFLAG -int __CRTDECL -__wsetargv (void) -#else -int __CRTDECL -__setargv (void) -#endif -{ - _dowildcard = 1; - return 0; -} diff --git a/reactos/lib/3rdparty/mingw/dllentry.c b/reactos/lib/3rdparty/mingw/dllentry.c index 73f006b9068..dc0aaa25fdf 100644 --- a/reactos/lib/3rdparty/mingw/dllentry.c +++ b/reactos/lib/3rdparty/mingw/dllentry.c @@ -1,5 +1,11 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include #define _DECL_DLLMAIN -#include #include BOOL WINAPI DllEntryPoint(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) diff --git a/reactos/lib/3rdparty/mingw/dllmain.c b/reactos/lib/3rdparty/mingw/dllmain.c index 005e24eddb2..1e52c8598d6 100644 --- a/reactos/lib/3rdparty/mingw/dllmain.c +++ b/reactos/lib/3rdparty/mingw/dllmain.c @@ -1,6 +1,5 @@ +#include #define _DECL_DLLMAIN -#define _WINDOWS_ -#include #include BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) diff --git a/reactos/lib/3rdparty/mingw/gccmain.c b/reactos/lib/3rdparty/mingw/gccmain.c index a450bdb9d12..b2db698c3ad 100644 --- a/reactos/lib/3rdparty/mingw/gccmain.c +++ b/reactos/lib/3rdparty/mingw/gccmain.c @@ -1,15 +1,9 @@ -/* - * 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. - * + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. */ + #include #include #include diff --git a/reactos/lib/3rdparty/mingw/getopt.c b/reactos/lib/3rdparty/mingw/getopt.c index 3b0bfedfec4..cd759b2ff6a 100644 --- a/reactos/lib/3rdparty/mingw/getopt.c +++ b/reactos/lib/3rdparty/mingw/getopt.c @@ -1,137 +1,394 @@ -/* $Id$ -*/ -/* - tgetopt -- POSIX-compliant implementation of getopt() with string-type-generic - semantics - - This is public domain software -*/ - -#include +#include +#include +#include #include +#include +#include #include -#include "tgetopt.h" +#define REPLACE_GETOPT -int _topterr = 1; -int _toptind = 1; -int _toptopt; -_TCHAR * _toptarg; +#define _DIAGASSERT(x) do {} while (0) -int _tgetopt(int argc, _TCHAR * const argv[], const _TCHAR * optstring) +#ifdef REPLACE_GETOPT +#ifdef __weak_alias +__weak_alias(getopt,_getopt) +#endif +int opterr = 1; +int optind = 1; +int optopt = '?'; +int optreset; +char *optarg; +#endif + +#ifdef __weak_alias +__weak_alias(getopt_long,_getopt_long) +#endif + +#ifndef __CYGWIN__ +#define __progname __argv[0] +#else +extern char __declspec(dllimport) *__progname; +#endif + +#define IGNORE_FIRST (*options == '-' || *options == '+') +#define PRINT_ERROR ((opterr) && ((*options != ':') || (IGNORE_FIRST && options[1] != ':'))) + +#ifndef IS_POSIXLY_CORRECT +#define IS_POSIXLY_CORRECT (getenv("POSIXLY_CORRECT") != NULL) +#endif + +#define PERMUTE (!IS_POSIXLY_CORRECT && !IGNORE_FIRST) + +#define IN_ORDER (!IS_POSIXLY_CORRECT && *options == '-') + +#define BADCH (int)'?' +#define BADARG ((IGNORE_FIRST && options[1] == ':') || (*options == ':') ? (int)':' : (int)'?') +#define INORDER (int)1 + +static char EMSG[1]; + +static int getopt_internal (int,char * const *,const char *); +static int gcd (int,int); +static void permute_args (int,int,int,char * const *); + +static char *place = EMSG; + +static int nonopt_start = -1; +static int nonopt_end = -1; + +static const char recargchar[] = "option requires an argument -- %c"; +static const char recargstring[] = "option requires an argument -- %s"; +static const char ambig[] = "ambiguous option -- %.*s"; +static const char noarg[] = "option doesn't take an argument -- %.*s"; +static const char illoptchar[] = "unknown option -- %c"; +static const char illoptstring[] = "unknown option -- %s"; + +static void +_vwarnx(const char *fmt,va_list ap) { - 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; + (void)fprintf(stderr,"%s: ",__progname); + if (fmt != NULL) + (void)vfprintf(stderr,fmt,ap); + (void)fprintf(stderr,"\n"); } -/* EOF */ +static void +warnx(const char *fmt,...) +{ + va_list ap; + va_start(ap,fmt); + _vwarnx(fmt,ap); + va_end(ap); +} + +static int +gcd(a,b) + int a; + int b; +{ + int c; + + c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + + return b; +} + +static void +permute_args(panonopt_start,panonopt_end,opt_end,nargv) + int panonopt_start; + int panonopt_end; + int opt_end; + char * const *nargv; +{ + int cstart,cyclelen,i,j,ncycle,nnonopts,nopts,pos; + char *swap; + + _DIAGASSERT(nargv != NULL); + + nnonopts = panonopt_end - panonopt_start; + nopts = opt_end - panonopt_end; + ncycle = gcd(nnonopts,nopts); + cyclelen = (opt_end - panonopt_start) / ncycle; + + for (i = 0; i < ncycle; i++) { + cstart = panonopt_end+i; + pos = cstart; + for (j = 0; j < cyclelen; j++) { + if (pos >= panonopt_end) + pos -= nnonopts; + else + pos += nopts; + swap = nargv[pos]; + + ((char **) nargv)[pos] = nargv[cstart]; + + ((char **)nargv)[cstart] = swap; + } + } +} + +static int +getopt_internal(nargc,nargv,options) + int nargc; + char * const *nargv; + const char *options; +{ + char *oli; + int optchar; + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(options != NULL); + + optarg = NULL; + + if (optind == 0) + optind = 1; + + if (optreset) + nonopt_start = nonopt_end = -1; +start: + if (optreset || !*place) { + optreset = 0; + if (optind >= nargc) { + place = EMSG; + if (nonopt_end != -1) { + + permute_args(nonopt_start,nonopt_end,optind,nargv); + optind -= nonopt_end - nonopt_start; + } + else if (nonopt_start != -1) { + + optind = nonopt_start; + } + nonopt_start = nonopt_end = -1; + return -1; + } + if ((*(place = nargv[optind]) != '-') + || (place[1] == '\0')) { + place = EMSG; + if (IN_ORDER) { + + optarg = nargv[optind++]; + return INORDER; + } + if (!PERMUTE) { + + return -1; + } + + if (nonopt_start == -1) + nonopt_start = optind; + else if (nonopt_end != -1) { + permute_args(nonopt_start,nonopt_end,optind,nargv); + nonopt_start = optind - + (nonopt_end - nonopt_start); + nonopt_end = -1; + } + optind++; + + goto start; + } + if (nonopt_start != -1 && nonopt_end == -1) + nonopt_end = optind; + if (place[1] && *++place == '-') { + place++; + return -2; + } + } + if ((optchar = (int)*place++) == (int)':' || + (oli = strchr(options + (IGNORE_FIRST ? 1 : 0),optchar)) == NULL) { + + if (!*place) + ++optind; + if (PRINT_ERROR) + warnx(illoptchar,optchar); + optopt = optchar; + return BADCH; + } + if (optchar == 'W' && oli[1] == ';') { + + if (*place) + return -2; + + if (++optind >= nargc) { + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar,optchar); + optopt = optchar; + return BADARG; + } else + place = nargv[optind]; + + return -2; + } + if (*++oli != ':') { + if (!*place) + ++optind; + } else { + optarg = NULL; + if (*place) + optarg = place; + + else if (oli[1] != ':') { + if (++optind >= nargc) { + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar,optchar); + optopt = optchar; + return BADARG; + } else + optarg = nargv[optind]; + } + place = EMSG; + ++optind; + } + + return optchar; +} + +#ifdef REPLACE_GETOPT + +int +getopt(nargc,nargv,options) + int nargc; + char * const *nargv; + const char *options; +{ + int retval; + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(options != NULL); + + if ((retval = getopt_internal(nargc,nargv,options)) == -2) { + ++optind; + + if (nonopt_end != -1) { + permute_args(nonopt_start,nonopt_end,optind,nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + retval = -1; + } + return retval; +} +#endif + +int +getopt_long(nargc,nargv,options,long_options,idx) + int nargc; + char * const *nargv; + const char *options; + const struct option *long_options; + int *idx; +{ + int retval; + + _DIAGASSERT(nargv != NULL); + _DIAGASSERT(options != NULL); + _DIAGASSERT(long_options != NULL); + + if ((retval = getopt_internal(nargc,nargv,options)) == -2) { + char *current_argv,*has_equal; + size_t current_argv_len; + int i,match; + + current_argv = place; + match = -1; + + optind++; + place = EMSG; + + if (*current_argv == '\0') { + + if (nonopt_end != -1) { + permute_args(nonopt_start,nonopt_end,optind,nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + return -1; + } + if ((has_equal = strchr(current_argv,'=')) != NULL) { + + current_argv_len = has_equal - current_argv; + has_equal++; + } else + current_argv_len = strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + + if (strncmp(current_argv,long_options[i].name,current_argv_len)) + continue; + + if (strlen(long_options[i].name) == + (unsigned)current_argv_len) { + + match = i; + break; + } + if (match == -1) + match = i; + else { + + if (PRINT_ERROR) + warnx(ambig,(int)current_argv_len,current_argv); + optopt = 0; + return BADCH; + } + } + if (match != -1) { + if (long_options[match].has_arg == no_argument + && has_equal) { + if (PRINT_ERROR) + warnx(noarg,(int)current_argv_len,current_argv); + + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + return BADARG; + } + if (long_options[match].has_arg == required_argument || + long_options[match].has_arg == optional_argument) { + if (has_equal) + optarg = has_equal; + else if (long_options[match].has_arg == + required_argument) { + + optarg = nargv[optind++]; + } + } + if ((long_options[match].has_arg == required_argument) + && (optarg == NULL)) { + + if (PRINT_ERROR) + warnx(recargstring,current_argv); + + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + --optind; + return BADARG; + } + } else { + if (PRINT_ERROR) + warnx(illoptstring,current_argv); + optopt = 0; + return BADCH; + } + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + retval = 0; + } else + retval = long_options[match].val; + if (idx) + *idx = match; + } + return retval; +} diff --git a/reactos/lib/3rdparty/mingw/gs_support.c b/reactos/lib/3rdparty/mingw/gs_support.c index faa4ae171c6..f7cdf6a94ee 100644 --- a/reactos/lib/3rdparty/mingw/gs_support.c +++ b/reactos/lib/3rdparty/mingw/gs_support.c @@ -1,3 +1,9 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #include #ifdef _WIN64 #include @@ -13,11 +19,12 @@ #ifdef _WIN64 PRUNTIME_FUNCTION RtlLookupFunctionEntry (ULONG64, PULONG64, PVOID); PVOID RtlVirtualUnwind (ULONG HandlerType, ULONG64, ULONG64, PRUNTIME_FUNCTION, - PCONTEXT, PVOID *, PULONG64, PKNONVOLATILE_CONTEXT_POINTERS); + PCONTEXT, PVOID *, PULONG64, PVOID); #endif typedef LONG NTSTATUS; +#define UNW_FLAG_NHANDLER 0x00 #define STATUS_STACK_BUFFER_OVERRUN ((NTSTATUS)0xC0000409L) typedef union @@ -33,8 +40,8 @@ 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); +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) @@ -89,7 +96,6 @@ __report_gsfailure (ULONGLONG StackCookie) PVOID hndData; #endif - #ifdef _WIN64 RtlCaptureContext (&GS_ContextRecord); controlPC = GS_ContextRecord.Rip; diff --git a/reactos/lib/3rdparty/mingw/isascii.c b/reactos/lib/3rdparty/mingw/isascii.c deleted file mode 100644 index 8a0db89ac62..00000000000 --- a/reactos/lib/3rdparty/mingw/isascii.c +++ /dev/null @@ -1,25 +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 - -#ifdef isascii -#undef isascii -#endif - -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 7f3fd80eaaa..00000000000 --- a/reactos/lib/3rdparty/mingw/iscsym.c +++ /dev/null @@ -1,24 +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 - -#ifdef iscsym -#undef iscsym -#endif - -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 96a3310e5ca..00000000000 --- a/reactos/lib/3rdparty/mingw/iscsymf.c +++ /dev/null @@ -1,25 +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 - -#ifdef iscsymf -#undef iscsymf -#endif - -int -iscsymf (int c) -{ - return __iscsymf(c); -} - diff --git a/reactos/lib/3rdparty/mingw/merr.c b/reactos/lib/3rdparty/mingw/merr.c index 6e341b67781..2645e216e00 100644 --- a/reactos/lib/3rdparty/mingw/merr.c +++ b/reactos/lib/3rdparty/mingw/merr.c @@ -1,12 +1,53 @@ -#include "internal.h" -#include +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ -int __defaultmatherr = 1; +#include +#include +#include + +int __defaultmatherr = 0; int __CRTDECL _matherr (struct _exception *pexcept) { - /* Make compiler happy. */ - pexcept = pexcept; + const char * type; + + switch(pexcept->type) + { + case _DOMAIN: + type = "Argument domain error (DOMAIN)"; + break; + + case _SING: + type = "Argument singularity (SIGN)"; + break; + + case _OVERFLOW: + type = "Overflow range error (OVERFLOW)"; + break; + + case _PLOSS: + type = "Partial loss of significance (PLOSS)"; + break; + + case _TLOSS: + type = "Total loss of significance (TLOSS)"; + break; + + case _UNDERFLOW: + type = "The result is too small to be represented (UNDERFLOW)"; + break; + + default: + type = "Unknown error"; + break; + } + + fprintf(stderr, "_matherr(): %s in %s(%g, %g) (retval=%g)\n", + type, pexcept->name, pexcept->arg1, pexcept->arg2, pexcept->retval); return 0; } + diff --git a/reactos/lib/3rdparty/mingw/mingw.rbuild b/reactos/lib/3rdparty/mingw/mingw.rbuild index d32f3fee439..ad8d1e48b6b 100644 --- a/reactos/lib/3rdparty/mingw/mingw.rbuild +++ b/reactos/lib/3rdparty/mingw/mingw.rbuild @@ -2,13 +2,12 @@ + - include + include/reactos/mingw-w64 kernel32 _newmode.c - _wgetopt.c atonexit.c - binmode.c charmax.c cinitexe.c CRT_fp10.c @@ -30,21 +29,24 @@ xtxtmode.c - include + + include/reactos/mingw-w64 crt0_c.c crtexe.c dllargv.c - include - + + + include/reactos/mingw-w64 crt0_w.c crtexe.c dllargv.c - include - dllargv.c + + include/reactos/mingw-w64 crtdll.c + dllargv.c diff --git a/reactos/lib/3rdparty/mingw/mingw_helpers.c b/reactos/lib/3rdparty/mingw/mingw_helpers.c index cccb9bf0ec0..cc8671f0f89 100644 --- a/reactos/lib/3rdparty/mingw/mingw_helpers.c +++ b/reactos/lib/3rdparty/mingw/mingw_helpers.c @@ -1,10 +1,20 @@ -#include "oscalls.h" -#include "internal.h" +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include +#include #include #include #include #include +#include #include +#if 0 +#include "../revstamp.h" +#endif const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback; @@ -23,3 +33,11 @@ _encode_pointer (void *ptr) /* 0:console, 1:windows. */ int mingw_app_type = 0; +#if 0 +const char *__mingw_get_crt_info (void) +{ + return "MinGW-W64 Runtime " __MINGW64_VERSION " (" + __MINGW64_VERSION_STATE " - " + "rev. " __MINGW_W64_REV ") " __MINGW_W64_REV_STAMP; +} +#endif diff --git a/reactos/lib/3rdparty/mingw/moldname-msvcrt.def b/reactos/lib/3rdparty/mingw/moldname-msvcrt.def index b6ad6f662aa..afd7694d40a 100644 --- a/reactos/lib/3rdparty/mingw/moldname-msvcrt.def +++ b/reactos/lib/3rdparty/mingw/moldname-msvcrt.def @@ -1,28 +1,3 @@ -; -; moldname-msvcrt.def -; -; Exports from the runtime except that these exports are actually preceeded -; by a underscore in the actual DLL. These correspond to functions which -; are non-ANSI and were prefixed with an underscore to avoid name space -; clutter. However many, in fact most programs still use a few of these -; functions without the underscore. This .def file is specially processed -; to make those non-underscored name function calls call the equivalent -; underscored functions. -; -; Contributors: -; Created by Colin Peters -; Maintained by Mumit Khan -; -; THIS SOFTWARE IS NOT COPYRIGHTED -; -; This source code is offered for use in the public domain. You may -; use, modify or distribute it freely. -; -; This code is distributed in the hope that it will be useful but -; WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY -; DISCLAMED. This includes but is not limited to warrenties of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -; EXPORTS access chdir @@ -31,9 +6,7 @@ chsize close creat cwait - daylight DATA - dup dup2 ecvt @@ -52,10 +25,10 @@ fgetchar fgetwchar filelength fileno -; Alias fpreset is set in CRT_fp10,c and CRT_fp8.c. ; fpreset fputchar fputwchar +;fstat ftime gcvt getch @@ -95,6 +68,7 @@ spawnv spawnve spawnvp spawnvpe +;stat strcmpi strdup stricmp @@ -108,10 +82,7 @@ strupr swab tell tempnam - timezone DATA - -; export tzname for both. See tzname DATA tzset umask @@ -127,9 +98,7 @@ wcsnset wcsrev wcsset wcsupr - wpopen - write ; non-ANSI functions declared in math.h j0 @@ -139,7 +108,7 @@ y0 y1 yn chgsign -scalb +;scalb finite fpclass ; C99 functions diff --git a/reactos/lib/3rdparty/mingw/natstart.c b/reactos/lib/3rdparty/mingw/natstart.c index 733b5dc19ca..dfea54e4a36 100644 --- a/reactos/lib/3rdparty/mingw/natstart.c +++ b/reactos/lib/3rdparty/mingw/natstart.c @@ -1,4 +1,11 @@ -#include "internal.h" +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include +#include _PGLOBAL volatile unsigned int __native_dllmain_reason = UINT_MAX; diff --git a/reactos/lib/3rdparty/mingw/pesect.c b/reactos/lib/3rdparty/mingw/pesect.c index ad85e72c145..d9bbf55513c 100644 --- a/reactos/lib/3rdparty/mingw/pesect.c +++ b/reactos/lib/3rdparty/mingw/pesect.c @@ -1,3 +1,9 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #include #if defined (_WIN64) && defined (__ia64__) diff --git a/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c b/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c index dbb2b46801d..b723bb8cb97 100644 --- a/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c +++ b/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c @@ -1,2 +1,8 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + char __RUNTIME_PSEUDO_RELOC_LIST_END__ = 0; char __RUNTIME_PSEUDO_RELOC_LIST__ = 0; diff --git a/reactos/lib/3rdparty/mingw/pseudo-reloc.c b/reactos/lib/3rdparty/mingw/pseudo-reloc.c index 22ae14e6ea4..b107f62a68a 100644 --- a/reactos/lib/3rdparty/mingw/pseudo-reloc.c +++ b/reactos/lib/3rdparty/mingw/pseudo-reloc.c @@ -1,7 +1,13 @@ -/* Only necesary on x86 and amd64 targets */ -#if defined(__i386__) || defined(__x86_64__) +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #include #include +#include +#include extern char __RUNTIME_PSEUDO_RELOC_LIST__; extern char __RUNTIME_PSEUDO_RELOC_LIST_END__; @@ -24,6 +30,24 @@ typedef struct { DWORD version; } runtime_pseudo_reloc_v2; +static void +__write_memory (void *addr,const void *src,size_t len) +{ + MEMORY_BASIC_INFORMATION b; + DWORD oldprot; + if (!len) + return; + if (!VirtualQuery (addr, &b, sizeof(b))) + abort (); + // Protect + if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE) + VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, + &oldprot); + memcpy (addr, src, len); + if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE) + VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot); +} + #define RP_VERSION_V1 0 #define RP_VERSION_V2 1 @@ -47,8 +71,10 @@ do_pseudo_reloc (void* start,void *end,void *base) runtime_pseudo_reloc_item_v1 *o; for (o = (runtime_pseudo_reloc_item_v1 *) v2_hdr; o < (runtime_pseudo_reloc_item_v1 *)end; o++) { + DWORD newval; reloc_target = (ptrdiff_t) base + o->target; - *((DWORD*) reloc_target) += o->addend; + newval = (*((DWORD*) reloc_target)) + o->addend; + __write_memory ((void *) reloc_target, &newval, sizeof(DWORD)); } return; } @@ -102,17 +128,17 @@ do_pseudo_reloc (void* start,void *end,void *base) switch ((r->flags & 0xff)) { case 8: - *((unsigned char*)reloc_target)=(unsigned char) reldata; + __write_memory ((void *) reloc_target, &reldata, 1); break; case 16: - *((unsigned short*)reloc_target)=(unsigned short) reldata; + __write_memory ((void *) reloc_target, &reldata, 2); break; case 32: - *((unsigned int*)reloc_target)=(unsigned int) reldata; + __write_memory ((void *) reloc_target, &reldata, 4); break; #ifdef _WIN64 case 64: - *((unsigned long long*)reloc_target)=(unsigned long long) reldata; + __write_memory ((void *) reloc_target, &reldata, 8); break; #endif } @@ -122,6 +148,9 @@ do_pseudo_reloc (void* start,void *end,void *base) void _pei386_runtime_relocator () { + static int was_init = 0; + if (was_init) + return; + ++was_init; do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,&__RUNTIME_PSEUDO_RELOC_LIST_END__,&_image_base__); } -#endif 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 index 31d1daa5107..f933fa652dd 100644 --- a/reactos/lib/3rdparty/mingw/tlssup.c +++ b/reactos/lib/3rdparty/mingw/tlssup.c @@ -1,8 +1,15 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + #ifdef CRTDLL #undef CRTDLL #endif -#include "internal.h" +#include +#include #include #include #include @@ -54,13 +61,11 @@ __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)(); } @@ -74,9 +79,7 @@ _CRTALLOC(".CRT$XLC") PIMAGE_TLS_CALLBACK __xl_c = (PIMAGE_TLS_CALLBACK) __dyn_t int __cdecl __tlregdtor (_PVFV func) { - //DbgPrint("__tlregdtor: func %p\n",func); - - if (dtor_list == NULL) + if (dtor_list == NULL) { dtor_list = &dtor_list_head; dtor_list_head.count = 0; @@ -99,11 +102,9 @@ __tlregdtor (_PVFV func) 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; diff --git a/reactos/lib/3rdparty/mingw/toascii.c b/reactos/lib/3rdparty/mingw/toascii.c deleted file mode 100644 index 2253f0072ee..00000000000 --- a/reactos/lib/3rdparty/mingw/toascii.c +++ /dev/null @@ -1,25 +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 - -#ifdef toascii -#undef toascii -#endif - -int -toascii (int c) -{ - return __toascii(c); -} - diff --git a/reactos/lib/3rdparty/mingw/wcrt1.c b/reactos/lib/3rdparty/mingw/wcrt1.c deleted file mode 100644 index 59385ffb00c..00000000000 --- a/reactos/lib/3rdparty/mingw/wcrt1.c +++ /dev/null @@ -1,308 +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 -_CRTIMP void __set_app_type(int); -#endif /* __MSVCRT__ */ - -/* Global _fmode for this .exe, not the one in msvcrt.dll, - The default is set in txtmode.o in libmingw32.a */ -/* Override the dllimport'd declarations in stdlib.h */ -#undef _fmode -extern int _fmode; -#ifdef __MSVCRT__ -extern int* __p__fmode(void); /* To access the dll _fmode */ -#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) - { - _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__ - *__p__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 __declspec(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(__GNUC__) -#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(__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 -#endif - -#if defined(_MSC_VER) -#if defined(_M_IX86) - /* Align the stack to 16 bytes for the sake of SSE ops in main - or in functions inlined into main. */ - __asm and esp, 0FFFFFFF0h -#else -#error Unsupported architecture -#endif -#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, _wenviron); - - /* - * 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/wildcard.c b/reactos/lib/3rdparty/mingw/wildcard.c index b0eca486ac8..bb7ff704e94 100644 --- a/reactos/lib/3rdparty/mingw/wildcard.c +++ b/reactos/lib/3rdparty/mingw/wildcard.c @@ -1 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + int _dowildcard = 0; diff --git a/reactos/lib/3rdparty/mingw/xncommod.c b/reactos/lib/3rdparty/mingw/xncommod.c index 0d2a0a45ca9..462c8267a68 100644 --- a/reactos/lib/3rdparty/mingw/xncommod.c +++ b/reactos/lib/3rdparty/mingw/xncommod.c @@ -1 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + int _commode = 0; diff --git a/reactos/lib/3rdparty/mingw/xthdloc.c b/reactos/lib/3rdparty/mingw/xthdloc.c index 19f4bb47810..1f7e59ac31e 100644 --- a/reactos/lib/3rdparty/mingw/xthdloc.c +++ b/reactos/lib/3rdparty/mingw/xthdloc.c @@ -1 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + int __globallocalestatus = ~0x1; diff --git a/reactos/lib/3rdparty/mingw/xtxtmode.c b/reactos/lib/3rdparty/mingw/xtxtmode.c index 3cc2971326b..6f1a195a88f 100644 --- a/reactos/lib/3rdparty/mingw/xtxtmode.c +++ b/reactos/lib/3rdparty/mingw/xtxtmode.c @@ -1 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + int _fmode = 0;