diff --git a/reactos/include/reactos/mingw-w64/internal.h b/reactos/include/reactos/mingw-w64/internal.h index 235e13cbe64..581ba56f40a 100644 --- a/reactos/include/reactos/mingw-w64/internal.h +++ b/reactos/include/reactos/mingw-w64/internal.h @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #ifndef _INC_INTERNAL @@ -18,9 +18,12 @@ extern "C" { #pragma pack(push,_CRT_PACKING) +#ifndef __INTERNAL_FUNC_DEFINED +#define __INTERNAL_FUNC_DEFINED typedef void (__cdecl *_PVFV)(void); typedef int (__cdecl *_PIFV)(void); typedef void (__cdecl *_PVFI)(int); +#endif #if defined (SPECIAL_CRTEXE) && (defined (_DLL) || defined (__GNUC__)) extern int _commode; @@ -32,12 +35,6 @@ extern "C" { #define __IOINFO_TM_UTF8 1 #define __IOINFO_TM_UTF16LE 2 -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4214) -#pragma warning(disable:4820) -#endif - typedef struct { intptr_t osfhnd; char osfile; @@ -49,10 +46,6 @@ extern "C" { char pipech2[2]; } ioinfo; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - #define IOINFO_ARRAY_ELTS (1 << 5) #define _pioinfo(i) (__pioinfo[(i) >> 5] + ((i) & (IOINFO_ARRAY_ELTS - 1))) diff --git a/reactos/include/reactos/mingw-w64/oscalls.h b/reactos/include/reactos/mingw-w64/oscalls.h index 132686d15c4..4dddbbbbbdd 100644 --- a/reactos/include/reactos/mingw-w64/oscalls.h +++ b/reactos/include/reactos/mingw-w64/oscalls.h @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #ifndef _INC_OSCALLS @@ -30,11 +30,6 @@ #endif #endif -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4214) -#endif - typedef struct _FTIME { unsigned short twosecs : 5; @@ -51,10 +46,6 @@ typedef struct _FDATE unsigned short year : 7; } FDATE; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - typedef FDATE *PFDATE; #endif diff --git a/reactos/include/reactos/mingw-w64/sect_attribs.h b/reactos/include/reactos/mingw-w64/sect_attribs.h index da09e9bbad2..38f4041d161 100644 --- a/reactos/include/reactos/mingw-w64/sect_attribs.h +++ b/reactos/include/reactos/mingw-w64/sect_attribs.h @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #if defined (__ia64__) || defined (__x86_64) @@ -10,7 +10,7 @@ #define _ATTRIBUTES shared #endif -#if defined(_MSC_VER) +#if 0 /* Reference list of existing section for msvcrt. */ #pragma section(".CRTMP$XCA",long,_ATTRIBUTES) #pragma section(".CRTMP$XCZ",long,_ATTRIBUTES) @@ -55,14 +55,6 @@ #pragma section(".rtc$IZZ",long,read) #pragma section(".rtc$TAA",long,read) #pragma section(".rtc$TZZ",long,read) -#pragma section(".tls",long,read,write) -#pragma section(".tls$ZZZ",long,read,write) #endif -#if defined(_MSC_VER) -#define _CRTALLOC(x) __declspec(allocate(x)) -#elif defined(__GNUC__) #define _CRTALLOC(x) __attribute__ ((section (x) )) -#else -#error -#endif diff --git a/reactos/lib/3rdparty/mingw/CRT_fp10.c b/reactos/lib/3rdparty/mingw/CRT_fp10.c index 34384b09458..b4da7b529e3 100644 --- a/reactos/lib/3rdparty/mingw/CRT_fp10.c +++ b/reactos/lib/3rdparty/mingw/CRT_fp10.c @@ -1,22 +1,12 @@ /** * 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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ void _fpreset (void); void _fpreset (void) -{ -#ifdef __GNUC__ - __asm__ ("fninit" ); -#else - __asm fninit; -#endif -} + { __asm__ ("fninit" ) ;} -#ifdef __GNUC__ void __attribute__ ((alias ("_fpreset"))) fpreset(void); -#else -void fpreset(void) { _fpreset(); } -#endif diff --git a/reactos/lib/3rdparty/mingw/CRT_fp8.c b/reactos/lib/3rdparty/mingw/CRT_fp8.c index 7e46c15fbe9..368dbd90628 100644 --- a/reactos/lib/3rdparty/mingw/CRT_fp8.c +++ b/reactos/lib/3rdparty/mingw/CRT_fp8.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include <_mingw.h> @@ -14,8 +14,4 @@ void _fpreset (void) (* __MINGW_IMP_SYMBOL(_fpreset))(); } -#ifdef __GNUC__ void __attribute__ ((alias ("_fpreset"))) fpreset(void); -#else -void fpreset(void) { _fpreset(); } -#endif diff --git a/reactos/lib/3rdparty/mingw/CRT_glob.c b/reactos/lib/3rdparty/mingw/CRT_glob.c index 944ee815c7c..60500031403 100644 --- a/reactos/lib/3rdparty/mingw/CRT_glob.c +++ b/reactos/lib/3rdparty/mingw/CRT_glob.c @@ -2,7 +2,7 @@ * CRT_glob.c * This file has no copyright is 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 the package. + * No warranty is given; refer to the file DISCLAIMER.PD within the package. * * Include this object file to set _dowildcard to a state that will turn on * command line globbing by default. (wildcard.o which goes into libmingw32.a diff --git a/reactos/lib/3rdparty/mingw/CRT_noglob.c b/reactos/lib/3rdparty/mingw/CRT_noglob.c new file mode 100644 index 00000000000..f458db97493 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/CRT_noglob.c @@ -0,0 +1,17 @@ +/* + * CRT_noglob.c + * This file has no copyright is assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within the package. + * + * Include this object file to set _dowildcard to a state that will turn off + * command line globbing by default. (wildcard.o which goes into libmingw32.a + * has a default state of off if not configured with --enable-wildcard.) + * + * To use this object include the object file in your link command: + * gcc -o foo.exe foo.o CRT_noglob.o + * + */ + +int _dowildcard = 0; + diff --git a/reactos/lib/3rdparty/mingw/_newmode.c b/reactos/lib/3rdparty/mingw/_newmode.c index e154284c3bf..f2fa3966f70 100644 --- a/reactos/lib/3rdparty/mingw/_newmode.c +++ b/reactos/lib/3rdparty/mingw/_newmode.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ int _newmode = 0; diff --git a/reactos/lib/3rdparty/mingw/atonexit.c b/reactos/lib/3rdparty/mingw/atonexit.c index 2491e82797f..442be353d88 100644 --- a/reactos/lib/3rdparty/mingw/atonexit.c +++ b/reactos/lib/3rdparty/mingw/atonexit.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #undef CRTDLL diff --git a/reactos/lib/3rdparty/mingw/binmode.c b/reactos/lib/3rdparty/mingw/binmode.c index b9e4dc08e4e..e7b3965cd43 100644 --- a/reactos/lib/3rdparty/mingw/binmode.c +++ b/reactos/lib/3rdparty/mingw/binmode.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #define SPECIAL_CRTEXE diff --git a/reactos/lib/3rdparty/mingw/charmax.c b/reactos/lib/3rdparty/mingw/charmax.c index 7442633fe6c..fbd10c4b923 100644 --- a/reactos/lib/3rdparty/mingw/charmax.c +++ b/reactos/lib/3rdparty/mingw/charmax.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/crt0_c.c b/reactos/lib/3rdparty/mingw/crt0_c.c index 7553c6d9406..f36772ebc1e 100644 --- a/reactos/lib/3rdparty/mingw/crt0_c.c +++ b/reactos/lib/3rdparty/mingw/crt0_c.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/crt0_w.c b/reactos/lib/3rdparty/mingw/crt0_w.c index 8767e670ee0..ebd78840820 100644 --- a/reactos/lib/3rdparty/mingw/crt0_w.c +++ b/reactos/lib/3rdparty/mingw/crt0_w.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/crt_handler.c b/reactos/lib/3rdparty/mingw/crt_handler.c index 19fee7c0a42..8e47df0a6c1 100644 --- a/reactos/lib/3rdparty/mingw/crt_handler.c +++ b/reactos/lib/3rdparty/mingw/crt_handler.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include @@ -13,6 +13,14 @@ #include #include +#if defined (_WIN64) && defined (__ia64__) +#error FIXME: Unsupported __ImageBase implementation. +#else +#define __ImageBase __MINGW_LSYMBOL(_image_base__) +/* This symbol is defined by the linker. */ +extern IMAGE_DOS_HEADER __ImageBase; +#endif + #pragma pack(push,1) typedef struct _UNWIND_INFO { BYTE VersionAndFlags; @@ -107,6 +115,8 @@ __mingw_SEH_error_handler (struct _EXCEPTION_RECORD* ExceptionRecord, (*old_handler) (SIGSEGV); action = EXCEPTION_CONTINUE_EXECUTION; } + else + action = EXCEPTION_EXECUTE_HANDLER; break; case EXCEPTION_ILLEGAL_INSTRUCTION: case EXCEPTION_PRIV_INSTRUCTION: @@ -125,6 +135,8 @@ __mingw_SEH_error_handler (struct _EXCEPTION_RECORD* ExceptionRecord, (*old_handler) (SIGILL); action = EXCEPTION_CONTINUE_EXECUTION; } + else + action = EXCEPTION_EXECUTE_HANDLER; break; case EXCEPTION_FLT_INVALID_OPERATION: case EXCEPTION_FLT_DIVIDE_BY_ZERO: diff --git a/reactos/lib/3rdparty/mingw/crtbegin.c b/reactos/lib/3rdparty/mingw/crtbegin.c new file mode 100644 index 00000000000..c917f9bd42a --- /dev/null +++ b/reactos/lib/3rdparty/mingw/crtbegin.c @@ -0,0 +1,6 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + diff --git a/reactos/lib/3rdparty/mingw/crtdll.c b/reactos/lib/3rdparty/mingw/crtdll.c index 0c674169789..f930f0d6a5a 100644 --- a/reactos/lib/3rdparty/mingw/crtdll.c +++ b/reactos/lib/3rdparty/mingw/crtdll.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #ifdef CRTDLL @@ -40,6 +40,7 @@ extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[]; extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[]; extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[]; +/* TLS initialization hook. */ extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback; static int __proc_attached = 0; @@ -49,9 +50,9 @@ extern _PVFV *__onexitend; extern int mingw_app_type; -extern BOOL WINAPI DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved); +extern WINBOOL WINAPI DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved); -extern BOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID); +extern WINBOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID); static int pre_c_init (void); @@ -71,7 +72,7 @@ pre_c_init (void) return 0; } -BOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { if (dwReason == DLL_PROCESS_DETACH) { @@ -148,12 +149,12 @@ BOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) return TRUE; } -static BOOL __DllMainCRTStartup (HANDLE, DWORD, LPVOID); +static WINBOOL __DllMainCRTStartup (HANDLE, DWORD, LPVOID); -BOOL WINAPI DllMainCRTStartup (HANDLE, DWORD, LPVOID); +WINBOOL WINAPI DllMainCRTStartup (HANDLE, DWORD, LPVOID); int __mingw_init_ehandler (void); -BOOL WINAPI +WINBOOL WINAPI DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { mingw_app_type = 0; @@ -167,10 +168,10 @@ DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) return __DllMainCRTStartup (hDllHandle, dwReason, lpreserved); } -__declspec(noinline) BOOL +__declspec(noinline) WINBOOL __DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { - BOOL retcode = TRUE; + WINBOOL retcode = TRUE; __native_dllmain_reason = dwReason; if (dwReason == DLL_PROCESS_DETACH && __proc_attached == 0) diff --git a/reactos/lib/3rdparty/mingw/crtend.c b/reactos/lib/3rdparty/mingw/crtend.c new file mode 100644 index 00000000000..c917f9bd42a --- /dev/null +++ b/reactos/lib/3rdparty/mingw/crtend.c @@ -0,0 +1,6 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + diff --git a/reactos/lib/3rdparty/mingw/crtexe.c b/reactos/lib/3rdparty/mingw/crtexe.c index 9834cb29be0..981f5df7c63 100644 --- a/reactos/lib/3rdparty/mingw/crtexe.c +++ b/reactos/lib/3rdparty/mingw/crtexe.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #undef CRTDLL @@ -20,7 +20,6 @@ #include #include #include -#include #ifndef __winitenv extern wchar_t *** __MINGW_IMP_SYMBOL(__winitenv); @@ -32,6 +31,11 @@ extern char *** __MINGW_IMP_SYMBOL(__initenv); #define __initenv (* __MINGW_IMP_SYMBOL(__initenv)) #endif +/* Hack, for bug in ld. Will be removed soon. */ +#define __ImageBase __MINGW_LSYMBOL(_image_base__) +/* This symbol is defined by ld. */ +extern IMAGE_DOS_HEADER __ImageBase; + extern void _fpreset (void); #define SPACECHAR _T(' ') #define DQUOTECHAR _T('\"') @@ -47,11 +51,7 @@ extern int * __MINGW_IMP_SYMBOL(_commode); #define _commode (* __MINGW_IMP_SYMBOL(_commode)) extern int _dowildcard; -#if defined(__GNUC__) int _MINGW_INSTALL_DEBUG_MATHERR __attribute__((weak)) = 0; -#else -int _MINGW_INSTALL_DEBUG_MATHERR = 0; -#endif extern int __defaultmatherr; extern _CRTIMP void __cdecl _initterm(_PVFV *, _PVFV *); @@ -62,6 +62,7 @@ extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[]; extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[]; extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[]; +/* TLS initialization hook. */ extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback; extern _PVFV *__onexitbegin; @@ -179,7 +180,7 @@ __tmainCRTStartup (void) { _TCHAR *lpszCommandLine = NULL; STARTUPINFO StartupInfo; - BOOL inDoubleQuote = FALSE; + WINBOOL inDoubleQuote = FALSE; memset (&StartupInfo, 0, sizeof (STARTUPINFO)); if (mingw_app_type) diff --git a/reactos/lib/3rdparty/mingw/dll_argv.c b/reactos/lib/3rdparty/mingw/dll_argv.c index eb8dad6b667..06abb8dfddf 100644 --- a/reactos/lib/3rdparty/mingw/dll_argv.c +++ b/reactos/lib/3rdparty/mingw/dll_argv.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #ifdef CRTDLL diff --git a/reactos/lib/3rdparty/mingw/dllargv.c b/reactos/lib/3rdparty/mingw/dllargv.c index 376479c4d72..769b8353685 100644 --- a/reactos/lib/3rdparty/mingw/dllargv.c +++ b/reactos/lib/3rdparty/mingw/dllargv.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #ifdef CRTDLL diff --git a/reactos/lib/3rdparty/mingw/dllentry.c b/reactos/lib/3rdparty/mingw/dllentry.c index 80516860214..e7658954c19 100644 --- a/reactos/lib/3rdparty/mingw/dllentry.c +++ b/reactos/lib/3rdparty/mingw/dllentry.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/gccmain.c b/reactos/lib/3rdparty/mingw/gccmain.c index af68c48a955..c046e8d77dc 100644 --- a/reactos/lib/3rdparty/mingw/gccmain.c +++ b/reactos/lib/3rdparty/mingw/gccmain.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/getopt.c b/reactos/lib/3rdparty/mingw/getopt.c deleted file mode 100644 index cd759b2ff6a..00000000000 --- a/reactos/lib/3rdparty/mingw/getopt.c +++ /dev/null @@ -1,394 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#define REPLACE_GETOPT - -#define _DIAGASSERT(x) do {} while (0) - -#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) -{ - (void)fprintf(stderr,"%s: ",__progname); - if (fmt != NULL) - (void)vfprintf(stderr,fmt,ap); - (void)fprintf(stderr,"\n"); -} - -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 cb9ba11a700..bc456721c95 100644 --- a/reactos/lib/3rdparty/mingw/gs_support.c +++ b/reactos/lib/3rdparty/mingw/gs_support.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include @@ -112,22 +112,12 @@ __report_gsfailure (ULONGLONG StackCookie) else #endif { -#ifdef __GNUC__ #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 -#else -#ifdef _WIN64 - GS_ContextRecord.Rip = (ULONGLONG) _ReturnAddress(); - GS_ContextRecord.Rsp = (ULONGLONG) _AddressOfReturnAddress(); -#else - GS_ContextRecord.Eip = (DWORD) _ReturnAddress(); - GS_ContextRecord.Esp = (DWORD) _AddressOfReturnAddress(); -#endif #endif } diff --git a/reactos/lib/3rdparty/mingw/isascii.c b/reactos/lib/3rdparty/mingw/isascii.c new file mode 100644 index 00000000000..067b9969c8c --- /dev/null +++ b/reactos/lib/3rdparty/mingw/isascii.c @@ -0,0 +1,16 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#include + +#undef isascii +int isascii (int); + +int +isascii (int c) +{ + return __isascii(c); +} diff --git a/reactos/lib/3rdparty/mingw/iscsym.c b/reactos/lib/3rdparty/mingw/iscsym.c new file mode 100644 index 00000000000..f98e990c331 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/iscsym.c @@ -0,0 +1,16 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#include +#undef iscsym + +int iscsym (int); + +int +iscsym (int c) +{ + return __iscsym(c); +} diff --git a/reactos/lib/3rdparty/mingw/iscsymf.c b/reactos/lib/3rdparty/mingw/iscsymf.c new file mode 100644 index 00000000000..9ff88af9b2a --- /dev/null +++ b/reactos/lib/3rdparty/mingw/iscsymf.c @@ -0,0 +1,16 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#include +#undef iscsymf + +int iscsymf (int); + +int +iscsymf (int c) +{ + return __iscsymf(c); +} diff --git a/reactos/lib/3rdparty/mingw/merr.c b/reactos/lib/3rdparty/mingw/merr.c index 2645e216e00..134e10fae62 100644 --- a/reactos/lib/3rdparty/mingw/merr.c +++ b/reactos/lib/3rdparty/mingw/merr.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/mingw.rbuild b/reactos/lib/3rdparty/mingw/mingw.rbuild index b37c2817c3a..f7c70df8c08 100644 --- a/reactos/lib/3rdparty/mingw/mingw.rbuild +++ b/reactos/lib/3rdparty/mingw/mingw.rbuild @@ -3,6 +3,10 @@ + + + + include/reactos/mingw-w64 @@ -18,19 +22,18 @@ CRT_glob.c crt_handler.c dllentry.c - dummy_mingwthrd.c gccmain.c - getopt.c gs_support.c merr.c mingw_helpers.c - mingwthrd_nomt.c natstart.c pesect.c pseudo-reloc.c pseudo-reloc-list.c + tlsmcrt.c tlssup.c + tlsthrd.c txtmode.c wildcard.c xncommod.c diff --git a/reactos/lib/3rdparty/mingw/mingw_custom.c b/reactos/lib/3rdparty/mingw/mingw_custom.c index 280eab9b1c8..59201987ceb 100644 --- a/reactos/lib/3rdparty/mingw/mingw_custom.c +++ b/reactos/lib/3rdparty/mingw/mingw_custom.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include <_mingw.h> diff --git a/reactos/lib/3rdparty/mingw/mingw_helpers.c b/reactos/lib/3rdparty/mingw/mingw_helpers.c index 72103dca437..b1bafd35653 100644 --- a/reactos/lib/3rdparty/mingw/mingw_helpers.c +++ b/reactos/lib/3rdparty/mingw/mingw_helpers.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/mingwthrd_nomt.c b/reactos/lib/3rdparty/mingw/mingwthrd_nomt.c deleted file mode 100644 index 7df31f67969..00000000000 --- a/reactos/lib/3rdparty/mingw/mingwthrd_nomt.c +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#include - -/* We support TLS cleanup code in any case. If shared version of libgcc is used _CRT_MT has value 1, otherwise - we do tls cleanup in runtime and _CRT_MT has value 2. */ -int _CRT_MT = 2; - -int __mingwthr_key_dtor (DWORD key, void (*dtor)(void *)); -int __mingwthr_remove_key_dtor (DWORD key); - -extern int ___w64_mingwthr_remove_key_dtor (DWORD key); -extern int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *)); - -int -__mingwthr_remove_key_dtor (DWORD key) -{ - return ___w64_mingwthr_remove_key_dtor (key); -} - -int -__mingwthr_key_dtor (DWORD key, void (*dtor)(void *)) -{ - if (dtor) - return ___w64_mingwthr_add_key_dtor (key, dtor); - - return 0; -} diff --git a/reactos/lib/3rdparty/mingw/natstart.c b/reactos/lib/3rdparty/mingw/natstart.c index dfea54e4a36..1122d19f3de 100644 --- a/reactos/lib/3rdparty/mingw/natstart.c +++ b/reactos/lib/3rdparty/mingw/natstart.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/pesect.c b/reactos/lib/3rdparty/mingw/pesect.c index c51a6d2522d..60bbbc4c0d0 100644 --- a/reactos/lib/3rdparty/mingw/pesect.c +++ b/reactos/lib/3rdparty/mingw/pesect.c @@ -1,15 +1,24 @@ /** * 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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include #include -BOOL _ValidateImageBase (PBYTE); +#if defined (_WIN64) && defined (__ia64__) +#error FIXME: Unsupported __ImageBase implementation. +#else +/* Hack, for bug in ld. Will be removed soon. */ +#define __ImageBase __MINGW_LSYMBOL(_image_base__) +/* This symbol is defined by the linker. */ +extern IMAGE_DOS_HEADER __ImageBase; +#endif -BOOL +WINBOOL _ValidateImageBase (PBYTE); + +WINBOOL _ValidateImageBase (PBYTE pImageBase) { PIMAGE_DOS_HEADER pDOSHeader; @@ -122,9 +131,9 @@ _GetPEImageBase (void) return pImageBase; } -BOOL _IsNonwritableInCurrentImage (PBYTE); +WINBOOL _IsNonwritableInCurrentImage (PBYTE); -BOOL +WINBOOL _IsNonwritableInCurrentImage (PBYTE pTarget) { PBYTE pImageBase; diff --git a/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c b/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c index b723bb8cb97..4ce46bbb29b 100644 --- a/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c +++ b/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ char __RUNTIME_PSEUDO_RELOC_LIST_END__ = 0; diff --git a/reactos/lib/3rdparty/mingw/pseudo-reloc.c b/reactos/lib/3rdparty/mingw/pseudo-reloc.c index ea0ea8a49c3..77f041114d7 100644 --- a/reactos/lib/3rdparty/mingw/pseudo-reloc.c +++ b/reactos/lib/3rdparty/mingw/pseudo-reloc.c @@ -1,27 +1,71 @@ -/** - * 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. - * - * Contributed by Egor Duda - * Modified by addition of runtime_pseudo_reloc version 2 - * by Kai Tietz - */ +/* pseudo-reloc.c + + Contributed by Egor Duda + Modified by addition of runtime_pseudo_reloc version 2 + by Kai Tietz + + 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. +*/ #include #include #include +#include #include -#include + +#if defined(__CYGWIN__) +#include +#include +#include +/* copied from winsup.h */ +# define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))) +/* custom status code: */ +#define STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION ((NTSTATUS) 0xe0000269) +#define SHORT_MSG_BUF_SZ 128 +#else +# define NO_COPY +#endif + +#ifdef __GNUC__ +#define ATTRIBUTE_NORETURN __attribute__ ((noreturn)) +#else +#define ATTRIBUTE_NORETURN +#endif + +#ifndef __MINGW_LSYMBOL +#define __MINGW_LSYMBOL(sym) sym +#endif extern char __RUNTIME_PSEUDO_RELOC_LIST__; extern char __RUNTIME_PSEUDO_RELOC_LIST_END__; +extern char __MINGW_LSYMBOL(_image_base__); +void _pei386_runtime_relocator (void); + +/* v1 relocation is basically: + * *(base + .target) += .addend + * where (base + .target) is always assumed to point + * to a DWORD (4 bytes). + */ typedef struct { DWORD addend; DWORD target; } runtime_pseudo_reloc_item_v1; +/* v2 relocation is more complex. In effect, it is + * *(base + .target) += *(base + .sym) - (base + .sym) + * with care taken in both reading, sign extension, and writing + * because .flags may indicate that (base + .target) may point + * to a BYTE, WORD, DWORD, or QWORD (w64). + */ typedef struct { DWORD sym; DWORD target; @@ -29,24 +73,123 @@ typedef struct { } runtime_pseudo_reloc_item_v2; typedef struct { - DWORD magic1; - DWORD magic2; - DWORD version; + DWORD magic1; + DWORD magic2; + DWORD version; } runtime_pseudo_reloc_v2; +static void ATTRIBUTE_NORETURN +__report_error (const char *msg, ...) +{ +#ifdef __CYGWIN__ + /* This function is used to print short error messages + * to stderr, which may occur during DLL initialization + * while fixing up 'pseudo' relocations. This early, we + * may not be able to use cygwin stdio functions, so we + * use the win32 WriteFile api. This should work with both + * normal win32 console IO handles, redirected ones, and + * cygwin ptys. + */ + char buf[SHORT_MSG_BUF_SZ]; + wchar_t module[MAX_PATH]; + char * posix_module = NULL; + static const char UNKNOWN_MODULE[] = ": "; + static const size_t UNKNOWN_MODULE_LEN = sizeof (UNKNOWN_MODULE) - 1; + static const char CYGWIN_FAILURE_MSG[] = "Cygwin runtime failure: "; + static const size_t CYGWIN_FAILURE_MSG_LEN = sizeof (CYGWIN_FAILURE_MSG) - 1; + DWORD len; + DWORD done; + va_list args; + HANDLE errh = GetStdHandle (STD_ERROR_HANDLE); + ssize_t modulelen = GetModuleFileNameW (NULL, module, sizeof (module)); + + if (errh == INVALID_HANDLE_VALUE) + cygwin_internal (CW_EXIT_PROCESS, + STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION, + 1); + + if (modulelen > 0) + posix_module = cygwin_create_path (CCP_WIN_W_TO_POSIX, module); + + va_start (args, msg); + len = (DWORD) vsnprintf (buf, SHORT_MSG_BUF_SZ, msg, args); + va_end (args); + buf[SHORT_MSG_BUF_SZ-1] = '\0'; /* paranoia */ + + if (posix_module) + { + WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG, + CYGWIN_FAILURE_MSG_LEN, &done, NULL); + WriteFile (errh, (PCVOID)posix_module, + strlen(posix_module), &done, NULL); + WriteFile (errh, (PCVOID)": ", 2, &done, NULL); + WriteFile (errh, (PCVOID)buf, len, &done, NULL); + free (posix_module); + } + else + { + WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG, + CYGWIN_FAILURE_MSG_LEN, &done, NULL); + WriteFile (errh, (PCVOID)UNKNOWN_MODULE, + UNKNOWN_MODULE_LEN, &done, NULL); + WriteFile (errh, (PCVOID)buf, len, &done, NULL); + } + WriteFile (errh, (PCVOID)"\n", 1, &done, NULL); + + cygwin_internal (CW_EXIT_PROCESS, + STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION, + 1); + /* not reached, but silences noreturn warning */ + abort (); +#else + va_list argp; + va_start (argp, msg); +# ifdef __MINGW64_VERSION_MAJOR + fprintf (stderr, "Mingw-w64 runtime failure:\n"); +# else + fprintf (stderr, "Mingw runtime failure:\n"); +# endif + vfprintf (stderr, msg, argp); + va_end (argp); + abort (); +#endif +} + +/* This function temporarily marks the page containing addr + * writable, before copying len bytes from *src to *addr, and + * then restores the original protection settings to the page. + * + * Using this function eliminates the requirement with older + * pseudo-reloc implementations, that sections containing + * pseudo-relocs (such as .text and .rdata) be permanently + * marked writable. This older behavior sabotaged any memory + * savings achieved by shared libraries on win32 -- and was + * slower, too. However, on cygwin as of binutils 2.20 the + * .text section is still marked writable, and the .rdata section + * is folded into the (writable) .data when --enable-auto-import. + */ static void __write_memory (void *addr, const void *src, size_t len) { MEMORY_BASIC_INFORMATION b; DWORD oldprot; + if (!len) return; - assert (VirtualQuery (addr, &b, sizeof(b))); + + if (!VirtualQuery (addr, &b, sizeof(b))) + { + __report_error (" VirtualQuery failed for %d bytes at address %p", + (int) sizeof(b), addr); + } + /* Temporarily allow write access to read-only protected memory. */ if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE) VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, &oldprot); + /* write the data. */ memcpy (addr, src, len); + /* Restore original protection. */ if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE) VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot); } @@ -55,66 +198,122 @@ __write_memory (void *addr, const void *src, size_t len) #define RP_VERSION_V2 1 static void -do_pseudo_reloc (void *start, void *end, void *base) +do_pseudo_reloc (void * start, void * end, void * base) { ptrdiff_t addr_imp, reldata; ptrdiff_t reloc_target = (ptrdiff_t) ((char *)end - (char*)start); runtime_pseudo_reloc_v2 *v2_hdr = (runtime_pseudo_reloc_v2 *) start; runtime_pseudo_reloc_item_v2 *r; + /* A valid relocation list will contain at least one entry, and + * one v1 data structure (the smallest one) requires two DWORDs. + * So, if the relocation list is smaller than 8 bytes, bail. + */ if (reloc_target < 8) return; - /* Check if this is old version pseudo relocation version. */ + + /* Check if this is the old pseudo relocation version. */ + /* There are two kinds of v1 relocation lists: + * 1) With a (v2-style) version header. In this case, the + * first entry in the list is a 3-DWORD structure, with + * value: + * { 0, 0, RP_VERSION_V1 } + * In this case, we skip to the next entry in the list, + * knowing that all elements after the head item can + * be cast to runtime_pseudo_reloc_item_v1. + * 2) Without a (v2-style) version header. In this case, the + * first element in the list IS an actual v1 relocation + * record, which is two DWORDs. Because there will never + * be a case where a v1 relocation record has both + * addend == 0 and target == 0, this case will not be + * confused with the prior one. + * All current binutils, when generating a v1 relocation list, + * use the second (e.g. original) form -- that is, without the + * v2-style version header. + */ if (reloc_target >= 12 && v2_hdr->magic1 == 0 && v2_hdr->magic2 == 0 && v2_hdr->version == RP_VERSION_V1) + { + /* We have a list header item indicating that the rest + * of the list contains v1 entries. Move the pointer to + * the first true v1 relocation record. By definition, + * that v1 element will not have both addend == 0 and + * target == 0 (and thus, when interpreted as a + * runtime_pseudo_reloc_v2, it will not have both + * magic1 == 0 and magic2 == 0). + */ v2_hdr++; + } + if (v2_hdr->magic1 != 0 || v2_hdr->magic2 != 0) { - 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; + /************************* + * Handle v1 relocations * + *************************/ + 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; newval = (*((DWORD*) reloc_target)) + o->addend; __write_memory ((void *) reloc_target, &newval, sizeof(DWORD)); - } + } return; } + + /* If we got this far, then we have relocations of version 2 or newer */ + /* Check if this is a known version. */ if (v2_hdr->version != RP_VERSION_V2) { -#ifdef DEBUG - fprintf (stderr, "pseudo_relocation protocol version %d is unknown to this runtime.\n", - (int) v2_hdr->version); -#endif + __report_error (" Unknown pseudo relocation protocol version %d.\n", + (int) v2_hdr->version); return; } - /* Walk over header. */ + + /************************* + * Handle v2 relocations * + *************************/ + + /* Walk over header. */ r = (runtime_pseudo_reloc_item_v2 *) &v2_hdr[1]; for (; r < (runtime_pseudo_reloc_item_v2 *) end; r++) { + /* location where new address will be written */ reloc_target = (ptrdiff_t) base + r->target; + + /* get sym pointer. It points either to the iat entry + * of the referenced element, or to the stub function. + */ addr_imp = (ptrdiff_t) base + r->sym; addr_imp = *((ptrdiff_t *) addr_imp); - switch ((r->flags&0xff)) + /* read existing relocation value from image, casting to the + * bitsize indicated by the 8 LSBs of flags. If the value is + * negative, manually sign-extend to ptrdiff_t width. Raise an + * error if the bitsize indicated by the 8 LSBs of flags is not + * supported. + */ + switch ((r->flags & 0xff)) { case 8: reldata = (ptrdiff_t) (*((unsigned char *)reloc_target)); - if ((reldata&0x80) != 0) + if ((reldata & 0x80) != 0) reldata |= ~((ptrdiff_t) 0xff); break; case 16: reldata = (ptrdiff_t) (*((unsigned short *)reloc_target)); - if ((reldata&0x8000) != 0) + if ((reldata & 0x8000) != 0) reldata |= ~((ptrdiff_t) 0xffff); break; case 32: reldata = (ptrdiff_t) (*((unsigned int *)reloc_target)); #ifdef _WIN64 - if ((reldata&0x80000000) != 0) + if ((reldata & 0x80000000) != 0) reldata |= ~((ptrdiff_t) 0xffffffff); #endif break; @@ -125,15 +324,18 @@ do_pseudo_reloc (void *start, void *end, void *base) #endif default: reldata=0; -#ifdef DEBUG - fprintf(stderr, "Unknown pseudo relocation bit size %d\n",(int) (r->flags & 0xff)); -#endif + __report_error (" Unknown pseudo relocation bit size %d.\n", + (int) (r->flags & 0xff)); break; } + + /* Adjust the relocation value */ reldata -= ((ptrdiff_t) base + r->sym); reldata += addr_imp; + + /* Write the new relocation value back to *reloc_target */ switch ((r->flags & 0xff)) - { + { case 8: __write_memory ((void *) reloc_target, &reldata, 1); break; @@ -148,18 +350,18 @@ do_pseudo_reloc (void *start, void *end, void *base) __write_memory ((void *) reloc_target, &reldata, 8); break; #endif - } - } + } + } } -void _pei386_runtime_relocator (void); - void _pei386_runtime_relocator (void) { - static int was_init = 0; + static NO_COPY int was_init = 0; if (was_init) return; ++was_init; - do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,&__RUNTIME_PSEUDO_RELOC_LIST_END__,&__ImageBase); + do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__, + &__RUNTIME_PSEUDO_RELOC_LIST_END__, + &__MINGW_LSYMBOL(_image_base__)); } diff --git a/reactos/lib/3rdparty/mingw/strcasecmp.c b/reactos/lib/3rdparty/mingw/strcasecmp.c new file mode 100644 index 00000000000..17aba0b0b3c --- /dev/null +++ b/reactos/lib/3rdparty/mingw/strcasecmp.c @@ -0,0 +1,16 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#define __CRT__NO_INLINE +#include + +#undef strcasecmp +int strcasecmp (const char *, const char *); +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 new file mode 100644 index 00000000000..b06afdac648 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/strncasecmp.c @@ -0,0 +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.PD within this package. + */ + +#define __CRT__NO_INLINE +#include + +#undef strncasecmp +int strncasecmp (const char *, const char *, size_t); + +int +strncasecmp (const char *sz1,const char *sz2,size_t sizeMaxCompare) +{ + return _strnicmp (sz1,sz2,sizeMaxCompare); +} diff --git a/reactos/lib/3rdparty/mingw/tlsmcrt.c b/reactos/lib/3rdparty/mingw/tlsmcrt.c new file mode 100644 index 00000000000..2450b8b9216 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/tlsmcrt.c @@ -0,0 +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.PD within this package. + * + * Written by Kai Tietz + */ + +/* We support TLS cleanup code in any case. If shared version of libgcc is used _CRT_MT has value 1, + otherwise + we do tls cleanup in runtime and _CRT_MT has value 2. */ +int _CRT_MT = 2; + diff --git a/reactos/lib/3rdparty/mingw/tlsmthread.c b/reactos/lib/3rdparty/mingw/tlsmthread.c new file mode 100644 index 00000000000..c018abfd21e --- /dev/null +++ b/reactos/lib/3rdparty/mingw/tlsmthread.c @@ -0,0 +1,59 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + * + * Written by Kai Tietz + */ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#include + +int __mingwthr_key_dtor (DWORD key, void (*dtor)(void *)); +int __mingwthr_remove_key_dtor (DWORD key); + +extern int ___w64_mingwthr_remove_key_dtor (DWORD key); +extern int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *)); + + +#ifndef _WIN64 +#define MINGWM10_DLL "mingwm10.dll" +typedef int (*fMTRemoveKeyDtor)(DWORD key); +typedef int (*fMTKeyDtor)(DWORD key, void (*dtor)(void *)); +extern fMTRemoveKeyDtor __mingw_gMTRemoveKeyDtor; +extern fMTKeyDtor __mingw_gMTKeyDtor; +extern int __mingw_usemthread_dll; +#endif + +int +__mingwthr_remove_key_dtor (DWORD key) +{ +#ifndef _WIN64 + if (!__mingw_usemthread_dll) +#endif + return ___w64_mingwthr_remove_key_dtor (key); +#ifndef _WIN64 + if (__mingw_gMTRemoveKeyDtor) + return (*__mingw_gMTRemoveKeyDtor) (key); + return 0; +#endif +} + +int +__mingwthr_key_dtor (DWORD key, void (*dtor)(void *)) +{ + if (dtor) + { +#ifndef _WIN64 + if (!__mingw_usemthread_dll) +#endif + return ___w64_mingwthr_add_key_dtor (key, dtor); +#ifndef _WIN64 + if (__mingw_gMTKeyDtor) + return (*__mingw_gMTKeyDtor) (key, dtor); +#endif + } + return 0; +} diff --git a/reactos/lib/3rdparty/mingw/tlssup.c b/reactos/lib/3rdparty/mingw/tlssup.c index 0088beb2f1a..aec217dba5e 100644 --- a/reactos/lib/3rdparty/mingw/tlssup.c +++ b/reactos/lib/3rdparty/mingw/tlssup.c @@ -1,20 +1,32 @@ /** * 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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + * + * Written by Kai Tietz */ #ifdef CRTDLL #undef CRTDLL #endif -#include -#include #include +#include +#include #include -#include -extern BOOL __mingw_TLScallback (HANDLE hDllHandle, DWORD reason, LPVOID reserved); +#ifndef _CRTALLOC +#define _CRTALLOC(x) __attribute__ ((section (x) )) +#endif + +#ifndef __INTERNAL_FUNC_DEFINED +#define __INTERNAL_FUNC_DEFINED + typedef void (__cdecl *_PVFV)(void); + typedef int (__cdecl *_PIFV)(void); + typedef void (__cdecl *_PVFI)(int); +#endif + +extern WINBOOL __mingw_TLScallback (HANDLE hDllHandle, DWORD reason, LPVOID reserved); #define FUNCS_PER_NODE 30 @@ -66,6 +78,16 @@ static __CRT_THREAD TlsDtorNode dtor_list_head; extern int _CRT_MT; +#ifndef _WIN64 +#define MINGWM10_DLL "mingwm10.dll" +typedef int (*fMTRemoveKeyDtor)(DWORD key); +typedef int (*fMTKeyDtor)(DWORD key, void (*dtor)(void *)); +fMTRemoveKeyDtor __mingw_gMTRemoveKeyDtor; +fMTKeyDtor __mingw_gMTKeyDtor; +int __mingw_usemthread_dll; +static HANDLE __mingw_mthread_hdll; +#endif + BOOL WINAPI __dyn_tls_init (HANDLE, DWORD, LPVOID); BOOL WINAPI @@ -73,6 +95,30 @@ __dyn_tls_init (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { _PVFV *pfunc; +#ifndef _WIN64 + if (_winmajor < 4) + { + __mingw_usemthread_dll = 1; + __mingw_mthread_hdll = LoadLibrary (MINGWM10_DLL); + if (__mingw_mthread_hdll != NULL) + { + __mingw_gMTRemoveKeyDtor = (fMTRemoveKeyDtor) GetProcAddress (__mingw_mthread_hdll, "__mingwthr_remove_key_dtor"); + __mingw_gMTKeyDtor = (fMTKeyDtor) GetProcAddress (__mingw_mthread_hdll, "__mingwthr_key_dtor"); + } + if (__mingw_mthread_hdll == NULL || !__mingw_gMTRemoveKeyDtor || !__mingw_gMTKeyDtor) + { + __mingw_gMTKeyDtor = NULL; + __mingw_gMTRemoveKeyDtor = NULL; + if (__mingw_mthread_hdll) + FreeLibrary (__mingw_mthread_hdll); + __mingw_mthread_hdll = NULL; + _CRT_MT = 0; + return TRUE; + } + _CRT_MT = 1; + return TRUE; + } +#endif /* We don't let us trick here. */ if (_CRT_MT != 2) _CRT_MT = 2; diff --git a/reactos/lib/3rdparty/mingw/dummy_mingwthrd.c b/reactos/lib/3rdparty/mingw/tlsthrd.c similarity index 87% rename from reactos/lib/3rdparty/mingw/dummy_mingwthrd.c rename to reactos/lib/3rdparty/mingw/tlsthrd.c index 597144fc06b..2e76727d20d 100644 --- a/reactos/lib/3rdparty/mingw/dummy_mingwthrd.c +++ b/reactos/lib/3rdparty/mingw/tlsthrd.c @@ -1,9 +1,11 @@ -/* - * mthr_stub.c +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. * - * Implement Mingw-w64 thread-support. + * Written by Kai Tietz * - * This file is used by if gcc is built with --enable-threads=win32. + * This file is used by if gcc is built with --enable-threads=win32. * * Based on version created by Mumit Khan * @@ -15,7 +17,7 @@ #include #include -BOOL __mingw_TLScallback (HANDLE hDllHandle, DWORD reason, LPVOID reserved); +WINBOOL __mingw_TLScallback (HANDLE hDllHandle, DWORD reason, LPVOID reserved); int ___w64_mingwthr_remove_key_dtor (DWORD key); int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *)); @@ -42,12 +44,10 @@ ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *)) if (__mingwthr_cs_init == 0) return 0; - new_key = (__mingwthr_key_t *)malloc(sizeof (__mingwthr_key_t)); - + new_key = (__mingwthr_key_t *) calloc (1, sizeof (__mingwthr_key_t)); if (new_key == NULL) return -1; - memset(new_key, 0,sizeof (__mingwthr_key_t)); new_key->key = key; new_key->dtor = dtor; @@ -116,8 +116,8 @@ __mingwthr_run_key_dtors (void) LeaveCriticalSection (&__mingwthr_cs); } - -BOOL + +WINBOOL __mingw_TLScallback (HANDLE hDllHandle __attribute__ ((__unused__)), DWORD reason, LPVOID reserved __attribute__ ((__unused__))) diff --git a/reactos/lib/3rdparty/mingw/toascii.c b/reactos/lib/3rdparty/mingw/toascii.c new file mode 100644 index 00000000000..946b321af41 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/toascii.c @@ -0,0 +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.PD within this package. + */ + +#include + +#undef toascii + +int toascii (int); + +int +toascii (int c) +{ + return __toascii(c); +} diff --git a/reactos/lib/3rdparty/mingw/txtmode.c b/reactos/lib/3rdparty/mingw/txtmode.c index 59a960ceecf..0c700ee1a19 100644 --- a/reactos/lib/3rdparty/mingw/txtmode.c +++ b/reactos/lib/3rdparty/mingw/txtmode.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include diff --git a/reactos/lib/3rdparty/mingw/ucrtexe.c b/reactos/lib/3rdparty/mingw/ucrtexe.c new file mode 100644 index 00000000000..76e0e0cc205 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/ucrtexe.c @@ -0,0 +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.PD within this package. + */ + +#ifndef UNICODE +#define UNICODE +#endif + +#define WPRFLAG 1 + +#include "crtexe.c" + diff --git a/reactos/lib/3rdparty/mingw/udll_argv.c b/reactos/lib/3rdparty/mingw/udll_argv.c new file mode 100644 index 00000000000..3511925afa2 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/udll_argv.c @@ -0,0 +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.PD within this package. + */ + +#ifndef UNICODE +#define UNICODE +#endif + +#define WPRFLAG 1 + +#include "dll_argv.c" + diff --git a/reactos/lib/3rdparty/mingw/udllargc.c b/reactos/lib/3rdparty/mingw/udllargc.c new file mode 100644 index 00000000000..bcec7546726 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/udllargc.c @@ -0,0 +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.PD within this package. + */ + +#ifndef UNICODE +#define UNICODE +#endif + +#define WPRFLAG 1 + +#include "dllargv.c" + diff --git a/reactos/lib/3rdparty/mingw/wcscmpi.c b/reactos/lib/3rdparty/mingw/wcscmpi.c new file mode 100644 index 00000000000..2fce2b41706 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/wcscmpi.c @@ -0,0 +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.PD within this package. + */ + +#define __CRT__NO_INLINE +#include + +#undef wcscmpi +int wcscmpi (const wchar_t *, const wchar_t *); + +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 index 82085d31cec..f996577bf27 100644 --- a/reactos/lib/3rdparty/mingw/wildcard.c +++ b/reactos/lib/3rdparty/mingw/wildcard.c @@ -1,19 +1,33 @@ /** * 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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ /* _dowildcard is an int that controls the globbing of the command line. * If _dowildcard is non-zero, the command line will be globbed: *.* * will be expanded to be all files in the startup directory. + * * In the mingw-w64 library the _dowildcard variable is defined as being * 0, therefore command line globbing is DISABLED by default. To turn it * on and to leave wildcard command line processing MS's globbing code, * include a line in one of your source modules defining _dowildcard and * setting it to -1, like so: * int _dowildcard = -1; + * + * Alternatively, the mingw-w64 library can be configured using the + * --enable-wildcard option and compiled thusly upon which the resulting + * library will have _dowildcard as -1 and command line globbing will be + * enabled by default. */ -int _dowildcard = 0; +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef __ENABLE_GLOBBING +#define __ENABLE_GLOBBING 0 /* -1 */ +#endif + +int _dowildcard = __ENABLE_GLOBBING; diff --git a/reactos/lib/3rdparty/mingw/xncommod.c b/reactos/lib/3rdparty/mingw/xncommod.c index 462c8267a68..f4efddb49ea 100644 --- a/reactos/lib/3rdparty/mingw/xncommod.c +++ b/reactos/lib/3rdparty/mingw/xncommod.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ int _commode = 0; diff --git a/reactos/lib/3rdparty/mingw/xthdloc.c b/reactos/lib/3rdparty/mingw/xthdloc.c index 1f7e59ac31e..285bc958037 100644 --- a/reactos/lib/3rdparty/mingw/xthdloc.c +++ b/reactos/lib/3rdparty/mingw/xthdloc.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ int __globallocalestatus = ~0x1; diff --git a/reactos/lib/3rdparty/mingw/xtxtmode.c b/reactos/lib/3rdparty/mingw/xtxtmode.c index 6f1a195a88f..6da7d6b9d63 100644 --- a/reactos/lib/3rdparty/mingw/xtxtmode.c +++ b/reactos/lib/3rdparty/mingw/xtxtmode.c @@ -1,7 +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. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ int _fmode = 0;