+++ /dev/null
-
-include_directories(${REACTOS_SOURCE_DIR}/include/reactos/mingw-w64)
-
-add_definitions(-D_CRTBLD)
-
-if(NOT MSVC)
- add_compile_flags("-Wno-main")
-endif()
-
-list(APPEND MINGW_COMMON_SOURCE
- _newmode.c
- atonexit.c
- binmode.c
- charmax.c
- cinitexe.c
- CRT_glob.c
- crt_handler.c
- dllentry.c
- gs_support.c
- merr.c
- mingw_helpers.c
- natstart.c
- pesect.c
- pseudo-reloc.c
- pseudo-reloc-list.c
- tlsmcrt.c
- tlsmthread.c
- tlssup.c
- tlsthrd.c
- txtmode.c
- wildcard.c
- xncommod.c
- xthdloc.c
- xtxtmode.c
- ofmt_stub.c
- cxa_pure_virtual.c)
-
-if(MSVC)
- list(APPEND MINGW_COMMON_SOURCE mscmain.c)
-else()
- list(APPEND MINGW_COMMON_SOURCE gccmain.c)
-endif()
-
-add_library(mingw_common ${MINGW_COMMON_SOURCE})
-
-if(NOT MSVC)
- target_link_libraries(mingw_common oldnames)
-endif()
-
-add_target_compile_definitions(mingw_common _M_CEE_PURE)
-add_dependencies(mingw_common psdk)
-
-add_library(mingw_main crt0_c.c crtexe.c dllargv.c)
-add_target_compile_definitions(mingw_main _DLL __USE_CRTIMP)
-add_dependencies(mingw_main psdk)
-
-add_library(mingw_wmain crt0_w.c crtexe.c dllargv.c)
-add_target_compile_definitions(mingw_wmain WPRFLAG UNICODE _UNICODE)
-add_dependencies(mingw_wmain psdk)
-
-add_library(mingw_dllmain crtdll.c dllargv.c)
-add_target_compile_definitions(mingw_dllmain CRTDLL _WINDOWS_)
-add_dependencies(mingw_dllmain psdk)
-
-if(NOT MSVC)
- add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
- COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_SOURCE_DIR}/moldname-msvcrt.def --kill-at --output-lib ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a)
-
- set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a PROPERTIES GENERATED TRUE)
-
- add_custom_target(oldnames ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a)
-endif()
-
-add_library(getopt getopt.c)
-add_target_compile_definitions(getopt _DLL __USE_CRTIMP)
-add_dependencies(getopt psdk)
+++ /dev/null
-/**
- * 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.
- */
-
-void _fpreset (void);
-
-void _fpreset (void)
-{
-#ifdef __GNUC__
- __asm__ ("fninit");
-#else /* msvc: */
- __asm fninit;
-#endif
-}
-
-#ifdef __GNUC__
-void __attribute__ ((alias ("_fpreset"))) fpreset(void);
-#else
-void fpreset(void) {
- _fpreset();
-}
-#endif
+++ /dev/null
-/**
- * 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 <_mingw.h>
-
-extern void (* __MINGW_IMP_SYMBOL(_fpreset))(void);
-void _fpreset (void);
-
-void _fpreset (void)
-{
- (* __MINGW_IMP_SYMBOL(_fpreset))();
-}
-
-#ifdef __GNUC__
-void __attribute__ ((alias ("_fpreset"))) fpreset(void);
-#else
-void fpreset(void) {
- _fpreset();
-}
-#endif
+++ /dev/null
-/*
- * 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.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
- * has a default state of off.)
- *
- * To use this object include the object file in your link command:
- * gcc -o foo.exe foo.o CRT_glob.o
- *
- */
-
-int _dowildcard = -1;
-
+++ /dev/null
-/*
- * 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;
-
+++ /dev/null
-/**
- * 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.
- */
-
-int _newmode = 0;
+++ /dev/null
-/**
- * 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.
- */
-
-#undef CRTDLL
-#ifndef _DLL
-#define _DLL
-#endif
-
-#include <oscalls.h>
-#include <internal.h>
-#include <stdlib.h>
-#include <crtdefs.h>
-#include <limits.h>
-#include <windows.h>
-
-#define _EXIT_LOCK1 8
-
- void __cdecl _lock (int _File);
- void __cdecl _unlock (int _File);
-
-_PVFV *__onexitbegin;
-_PVFV *__onexitend;
-
-extern _CRTIMP _onexit_t __dllonexit (_onexit_t, _PVFV**, _PVFV**);
-extern _onexit_t (__cdecl * __MINGW_IMP_SYMBOL(_onexit)) (_onexit_t func);
-
-/* Choose a different name to prevent name conflicts. The CRT one works fine. */
-_onexit_t __cdecl mingw_onexit(_onexit_t func);
-
-_onexit_t __cdecl mingw_onexit(_onexit_t func)
-{
- _PVFV *onexitbegin;
- _PVFV *onexitend;
- _onexit_t retval;
-
- onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
-
- if (onexitbegin == (_PVFV *) -1)
- return (* __MINGW_IMP_SYMBOL(_onexit)) (func);
- _lock (_EXIT_LOCK1);
- onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
- onexitend = (_PVFV *) _decode_pointer (__onexitend);
-
- retval = __dllonexit (func, &onexitbegin, &onexitend);
-
- __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin);
- __onexitend = (_PVFV *) _encode_pointer (onexitend);
- _unlock (_EXIT_LOCK1);
- return retval;
-}
-
-int __cdecl
-atexit (_PVFV func)
-{
- return (mingw_onexit((_onexit_t)func) == NULL) ? -1 : 0;
-}
+++ /dev/null
-/**
- * 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 SPECIAL_CRTEXE
-
-#include <fcntl.h>
-#include <stdlib.h>
+++ /dev/null
-/**
- * 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 <sect_attribs.h>
-#include <internal.h>
-
-__declspec(dllimport) int __lconv_init (void);
-
-int mingw_initcharmax = 0;
-
-int _charmax = 255;
-
-static int my_lconv_init(void)
-{
- return __lconv_init();
-}
-
-_CRTALLOC(".CRT$XIC") _PIFV __mingw_pinit = my_lconv_init;
+++ /dev/null
-#include <stdio.h>
-#include <internal.h>
-#include <sect_attribs.h>
-
-#ifdef _MSC_VER
-#pragma comment(linker, "/merge:.CRT=.rdata")
-#endif
-
-_CRTALLOC(".CRT$XIA") _PVFV __xi_a[] = { NULL };
-_CRTALLOC(".CRT$XIZ") _PVFV __xi_z[] = { NULL };
-_CRTALLOC(".CRT$XCA") _PVFV __xc_a[] = { NULL };
-_CRTALLOC(".CRT$XCZ") _PVFV __xc_z[] = { NULL };
+++ /dev/null
-/**
- * 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 <windows.h>
-
-extern HINSTANCE __mingw_winmain_hInstance;
-extern LPSTR __mingw_winmain_lpCmdLine;
-extern DWORD __mingw_winmain_nShowCmd;
-
-/*ARGSUSED*/
-int main (int __UNUSED_PARAM(flags),
- char ** __UNUSED_PARAM(cmdline),
- char ** __UNUSED_PARAM(inst))
-{
- return (int) WinMain (__mingw_winmain_hInstance, NULL,
- __mingw_winmain_lpCmdLine, __mingw_winmain_nShowCmd);
-}
+++ /dev/null
-/**
- * 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 <windows.h>
-
-/* Do the UNICODE prototyping of WinMain. Be aware that in winbase.h WinMain is a macro
- defined to wWinMain. */
-int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nShowCmd);
-
-extern HINSTANCE __mingw_winmain_hInstance;
-extern LPWSTR __mingw_winmain_lpCmdLine;
-extern DWORD __mingw_winmain_nShowCmd;
-
-int wmain (int, wchar_t **, wchar_t **);
-
-/*ARGSUSED*/
-int wmain (int __UNUSED_PARAM(flags),
- wchar_t ** __UNUSED_PARAM(cmdline),
- wchar_t ** __UNUSED_PARAM(inst))
-{
- return (int) wWinMain (__mingw_winmain_hInstance, NULL,
- __mingw_winmain_lpCmdLine, __mingw_winmain_nShowCmd);
-}
+++ /dev/null
-/**
- * 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 <windows.h>
-#include <excpt.h>
-#include <string.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <memory.h>
-#include <signal.h>
-#include <stdio.h>
-
-#if defined (_WIN64) && defined (__ia64__)
-#error FIXME: Unsupported __ImageBase implementation.
-#else
-#ifndef _MSC_VER
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-/* This symbol is defined by the linker. */
-extern IMAGE_DOS_HEADER __ImageBase;
-#endif
-
-#pragma pack(push,1)
-typedef struct _UNWIND_INFO {
- BYTE VersionAndFlags;
- BYTE PrologSize;
- BYTE CountOfUnwindCodes;
- BYTE FrameRegisterAndOffset;
- ULONG AddressOfExceptionHandler;
-} UNWIND_INFO,*PUNWIND_INFO;
-#pragma pack(pop)
-
-PIMAGE_SECTION_HEADER _FindPESectionByName (const char *);
-PIMAGE_SECTION_HEADER _FindPESectionExec (size_t);
-PBYTE _GetPEImageBase (void);
-
-int __mingw_init_ehandler (void);
-
-#ifdef _WIN64
-EXCEPTION_DISPOSITION __mingw_SEH_error_handler(struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *);
-
-#define MAX_PDATA_ENTRIES 32
-static RUNTIME_FUNCTION emu_pdata[MAX_PDATA_ENTRIES];
-static UNWIND_INFO emu_xdata[MAX_PDATA_ENTRIES];
-
-int
-__mingw_init_ehandler (void)
-{
- static int was_here = 0;
- size_t e = 0;
- PIMAGE_SECTION_HEADER pSec;
- PBYTE _ImageBase = _GetPEImageBase ();
-
- if (was_here || !_ImageBase)
- return was_here;
- was_here = 1;
- if (_FindPESectionByName (".pdata") != NULL)
- return 1;
-
- /* Allocate # of e tables and entries. */
- memset (emu_pdata, 0, sizeof (RUNTIME_FUNCTION) * MAX_PDATA_ENTRIES);
- memset (emu_xdata, 0, sizeof (UNWIND_INFO) * MAX_PDATA_ENTRIES);
-
- e = 0;
- /* Fill tables and entries. */
- while (e < MAX_PDATA_ENTRIES && (pSec = _FindPESectionExec (e)) != NULL)
- {
- emu_xdata[e].VersionAndFlags = 9; /* UNW_FLAG_EHANDLER | UNW_VERSION */
- emu_xdata[e].AddressOfExceptionHandler =
- (DWORD)(size_t) ((LPBYTE)__mingw_SEH_error_handler - _ImageBase);
- emu_pdata[e].BeginAddress = pSec->VirtualAddress;
- emu_pdata[e].EndAddress = pSec->VirtualAddress + pSec->Misc.VirtualSize;
- emu_pdata[e].UnwindData =
- (DWORD)(size_t)((LPBYTE)&emu_xdata[e] - _ImageBase);
- ++e;
- }
-#ifdef _DEBUG_CRT
- if (!e || e > MAX_PDATA_ENTRIES)
- abort ();
-#endif
- /* RtlAddFunctionTable. */
- if (e != 0)
- RtlAddFunctionTable (emu_pdata, e, (DWORD64)_ImageBase);
- return 1;
-}
-
-extern void _fpreset (void);
-
-EXCEPTION_DISPOSITION
-__mingw_SEH_error_handler (struct _EXCEPTION_RECORD* ExceptionRecord,
- void *EstablisherFrame __attribute__ ((unused)),
- struct _CONTEXT* ContextRecord __attribute__ ((unused)),
- void *DispatcherContext __attribute__ ((unused)))
-{
- EXCEPTION_DISPOSITION action = EXCEPTION_CONTINUE_SEARCH;
- void (*old_handler) (int);
- int reset_fpu = 0;
-
- switch (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;
- }
- else
- action = EXCEPTION_EXECUTE_HANDLER;
- 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;
- }
- else
- action = EXCEPTION_EXECUTE_HANDLER;
- 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;
- case EXCEPTION_DATATYPE_MISALIGNMENT:
- case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
- case EXCEPTION_FLT_STACK_CHECK:
- case EXCEPTION_INT_OVERFLOW:
- case EXCEPTION_INVALID_HANDLE:
- /*case EXCEPTION_POSSIBLE_DEADLOCK: */
- action = EXCEPTION_CONTINUE_EXECUTION;
- break;
- default:
- break;
- }
- return action;
-}
-
-#endif
+++ /dev/null
-/**
- * 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.
- */
-
+++ /dev/null
-/**
- * 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.
- */
-
-#ifdef CRTDLL
-#undef CRTDLL
-#ifndef _DLL
-#define _DLL
-#endif
-
-#include <oscalls.h>
-#include <internal.h>
-#include <stdlib.h>
-#include <windows.h>
-#define _DECL_DLLMAIN
-#include <process.h>
-#include <crtdbg.h>
-
-#ifndef _CRTIMP
-#ifdef CRTDLL
-#define _CRTIMP __declspec(dllexport)
-#else
-#ifdef _DLL
-#define _CRTIMP __declspec(dllimport)
-#else
-#define _CRTIMP
-#endif
-#endif
-#endif
-#include <sect_attribs.h>
-#include <locale.h>
-
-extern void __cdecl _initterm(_PVFV *,_PVFV *);
-extern void __main ();
-extern void _pei386_runtime_relocator (void);
-extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[];
-extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[];
-extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[];
-extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[];
-
-/* TLS initialization hook. */
-extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
-
-static int __proc_attached = 0;
-
-extern _PVFV *__onexitbegin;
-extern _PVFV *__onexitend;
-
-extern int mingw_app_type;
-
-extern WINBOOL WINAPI DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved);
-
-extern WINBOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID);
-
-static int pre_c_init (void);
-
-_CRTALLOC(".CRT$XIAA") _PIFV pcinit = pre_c_init;
-
-static int
-pre_c_init (void)
-{
- _PVFV *onexitbegin;
-
- onexitbegin = (_PVFV *) malloc (32 * sizeof (_PVFV));
- __onexitend = __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin);
-
- if (onexitbegin == NULL)
- return 1;
- *onexitbegin = (_PVFV) NULL;
- return 0;
-}
-
-WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
-{
- if (dwReason == DLL_PROCESS_DETACH)
- {
- if (__proc_attached > 0)
- __proc_attached--;
- else
- return FALSE;
- }
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- void *lock_free = NULL;
- void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase;
- int nested = FALSE;
-
- while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
- fiberid, 0)) != 0)
- {
- if (lock_free == fiberid)
- {
- nested = TRUE;
- break;
- }
- Sleep(1000);
- }
- if (__native_startup_state != __uninitialized)
- {
- _amsg_exit(31);
- }
- else
- {
- __native_startup_state = __initializing;
-
- _initterm ((_PVFV *) (void *) __xi_a, (_PVFV *) (void *) __xi_z);
- _initterm (__xc_a,__xc_z);
- __native_startup_state = __initialized;
- }
- if (! nested)
- {
- (void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
- }
- if (__dyn_tls_init_callback != NULL)
- {
- __dyn_tls_init_callback (hDllHandle, DLL_THREAD_ATTACH, lpreserved);
- }
- __proc_attached++;
- }
- else if (dwReason == DLL_PROCESS_DETACH)
- {
- void *lock_free = NULL;
- while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,(PVOID) 1, 0)) != 0)
- {
- Sleep(1000);
- }
- if(__native_startup_state!=__initialized)
- {
- _amsg_exit (31);
- }
- else
- {
- _PVFV * onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
- if (onexitbegin)
- {
- _PVFV *onexitend = (_PVFV *) _decode_pointer (__onexitend);
- while (--onexitend >= onexitbegin)
- if (*onexitend != NULL)
- (**onexitend) ();
- free (onexitbegin);
- __onexitbegin = __onexitend = (_PVFV *) NULL;
- }
- __native_startup_state = __uninitialized;
- (void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
- }
- }
- return TRUE;
-}
-
-static WINBOOL __DllMainCRTStartup (HANDLE, DWORD, LPVOID);
-
-WINBOOL WINAPI DllMainCRTStartup (HANDLE, DWORD, LPVOID);
-int __mingw_init_ehandler (void);
-
-WINBOOL WINAPI
-DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
-{
- mingw_app_type = 0;
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- __security_init_cookie ();
-#ifdef _WIN64
- __mingw_init_ehandler ();
-#endif
- }
- return __DllMainCRTStartup (hDllHandle, dwReason, lpreserved);
-}
-
-__declspec(noinline) WINBOOL
-__DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
-{
- WINBOOL retcode = TRUE;
-
- __native_dllmain_reason = dwReason;
- if (dwReason == DLL_PROCESS_DETACH && __proc_attached == 0)
- {
- retcode = FALSE;
- goto i__leave;
- }
- _pei386_runtime_relocator ();
- if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
- {
- retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
- if (!retcode)
- goto i__leave;
- retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
- if (! retcode)
- {
- if (dwReason == DLL_PROCESS_ATTACH)
- _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
- goto i__leave;
- }
- }
- if (dwReason == DLL_PROCESS_ATTACH)
- __main ();
- retcode = DllMain(hDllHandle,dwReason,lpreserved);
- if (dwReason == DLL_PROCESS_ATTACH && ! retcode)
- {
- DllMain (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
- DllEntryPoint (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
- _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
- }
- if (dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH)
- {
- retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
- if (_CRT_INIT (hDllHandle, dwReason, lpreserved) == FALSE)
- retcode = FALSE;
- }
-i__leave:
- __native_dllmain_reason = UINT_MAX;
- return retcode ;
-}
-#endif
+++ /dev/null
-/**
- * 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.
- */
-
+++ /dev/null
-/**
- * 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.
- */
-
-#undef CRTDLL
-#ifndef _DLL
-#define _DLL
-#endif
-
-#define SPECIAL_CRTEXE
-
-#include <oscalls.h>
-#include <internal.h>
-#include <process.h>
-#include <signal.h>
-#include <math.h>
-#include <stdlib.h>
-#include <tchar.h>
-#include <sect_attribs.h>
-#include <locale.h>
-#include <intrin.h>
-
-#ifndef __winitenv
-extern wchar_t *** __MINGW_IMP_SYMBOL(__winitenv);
-#define __winitenv (* __MINGW_IMP_SYMBOL(__winitenv))
-#endif
-
-#ifndef __initenv
-extern char *** __MINGW_IMP_SYMBOL(__initenv);
-#define __initenv (* __MINGW_IMP_SYMBOL(__initenv))
-#endif
-
-/* Hack, for bug in ld. Will be removed soon. */
-#ifndef _MSC_VER
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-
-/* This symbol is defined by ld. */
-extern IMAGE_DOS_HEADER __ImageBase;
-
-extern void _fpreset (void);
-#define SPACECHAR _T(' ')
-#define DQUOTECHAR _T('\"')
-
-__declspec(dllimport) void __setusermatherr(int (__cdecl *)(struct _exception *));
-
-extern int * __MINGW_IMP_SYMBOL(_fmode);
-extern int * __MINGW_IMP_SYMBOL(_commode);
-
-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 *);
-
-static int __cdecl check_managed_app (void);
-
-extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[];
-extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[];
-extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[];
-extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[];
-
-/* TLS initialization hook. */
-extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
-
-extern _PVFV *__onexitbegin;
-extern _PVFV *__onexitend;
-
-extern int mingw_app_type;
-
-HINSTANCE __mingw_winmain_hInstance;
-_TCHAR *__mingw_winmain_lpCmdLine;
-DWORD __mingw_winmain_nShowCmd;
-
-static int argc;
-#ifdef WPRFLAG
-extern void __main(void);
-static wchar_t **argv;
-static wchar_t **envp;
-#else
-static char **argv;
-static char **envp;
-#endif
-
-static int argret;
-static int mainret=0;
-static int managedapp;
-static int has_cctor = 0;
-static _startupinfo startinfo;
-static LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler = NULL;
-
-extern void _pei386_runtime_relocator (void);
-static long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS * exception_data);
-#ifdef WPRFLAG
-static void duplicate_ppstrings (int ac, wchar_t ***av);
-#else
-static void duplicate_ppstrings (int ac, char ***av);
-#endif
-
-static int __cdecl pre_c_init (void);
-static void __cdecl pre_cpp_init (void);
-static void __cdecl __mingw_prepare_except_for_msvcr80_and_higher (void);
-_CRTALLOC(".CRT$XIAA") _PIFV mingw_pcinit = pre_c_init;
-_CRTALLOC(".CRT$XCAA") _PVFV mingw_pcppinit = pre_cpp_init;
-
-static int __cdecl
-pre_c_init (void)
-{
- managedapp = check_managed_app ();
- if (mingw_app_type)
- __set_app_type(_GUI_APP);
- else
- __set_app_type (_CONSOLE_APP);
- __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1));
-
- * __MINGW_IMP_SYMBOL(_fmode) = _fmode;
- * __MINGW_IMP_SYMBOL(_commode) = _commode;
-
-#ifdef WPRFLAG
- _wsetargv();
-#else
- _setargv();
-#endif
- if (_MINGW_INSTALL_DEBUG_MATHERR)
- {
- if (! __defaultmatherr)
- {
- __setusermatherr (_matherr);
- __defaultmatherr = 1;
- }
- }
-
- if (__globallocalestatus == -1)
- {
- }
- return 0;
-}
-
-static void __cdecl
-pre_cpp_init (void)
-{
- startinfo.newmode = _newmode;
-
-#ifdef WPRFLAG
- argret = __wgetmainargs(&argc,&argv,&envp,_dowildcard,&startinfo);
-#else
- argret = __getmainargs(&argc,&argv,&envp,_dowildcard,&startinfo);
-#endif
-}
-
-static int __tmainCRTStartup (void);
-
-int WinMainCRTStartup (void);
-
-int WinMainCRTStartup (void)
-{
- mingw_app_type = 1;
- __security_init_cookie ();
- return __tmainCRTStartup ();
-}
-
-int mainCRTStartup (void);
-
-#ifdef _WIN64
-int __mingw_init_ehandler (void);
-#endif
-
-int mainCRTStartup (void)
-{
- mingw_app_type = 0;
- __security_init_cookie ();
- return __tmainCRTStartup ();
-}
-
-static
-__declspec(noinline) int
-__tmainCRTStartup (void)
-{
- _TCHAR *lpszCommandLine = NULL;
- STARTUPINFO StartupInfo;
- WINBOOL inDoubleQuote = FALSE;
- memset (&StartupInfo, 0, sizeof (STARTUPINFO));
-
- if (mingw_app_type)
- GetStartupInfo (&StartupInfo);
- {
- void *lock_free = NULL;
- void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase;
- int nested = FALSE;
- while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
- fiberid, 0)) != 0)
- {
- if (lock_free == fiberid)
- {
- nested = TRUE;
- break;
- }
- Sleep(1000);
- }
- if (__native_startup_state == __initializing)
- {
- _amsg_exit (31);
- }
- else if (__native_startup_state == __uninitialized)
- {
- __native_startup_state = __initializing;
- _initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z);
- }
- else
- has_cctor = 1;
-
- if (__native_startup_state == __initializing)
- {
- _initterm (__xc_a, __xc_z);
- __native_startup_state = __initialized;
- }
- _ASSERTE(__native_startup_state == __initialized);
- if (! nested)
- (VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
-
- if (__dyn_tls_init_callback != NULL)
- __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);
-
- _pei386_runtime_relocator ();
- __mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler);
-#ifdef _WIN64
- __mingw_init_ehandler ();
-#endif
- __mingw_prepare_except_for_msvcr80_and_higher ();
-
- _fpreset ();
-
- if (mingw_app_type)
- {
-#ifdef WPRFLAG
- lpszCommandLine = (_TCHAR *) _wcmdln;
-#else
- lpszCommandLine = (char *) _acmdln;
-#endif
- while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine&&inDoubleQuote))
- {
- if (*lpszCommandLine == DQUOTECHAR)
- inDoubleQuote = !inDoubleQuote;
-#ifdef _MBCS
- if (_ismbblead (*lpszCommandLine))
- {
- if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */
- lpszCommandLine++;
- }
-#endif
- ++lpszCommandLine;
- }
- while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
- lpszCommandLine++;
-
- __mingw_winmain_hInstance = (HINSTANCE) &__ImageBase;
- __mingw_winmain_lpCmdLine = lpszCommandLine;
- __mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ?
- StartupInfo.wShowWindow : SW_SHOWDEFAULT;
- }
- duplicate_ppstrings (argc, &argv);
-#ifdef WPRFLAG
- __winitenv = envp;
- /* C++ initialization.
- gcc inserts this call automatically for a function called main, but not for wmain. */
- __main ();
- mainret = wmain (argc, argv, envp);
-#else
- __initenv = envp;
- mainret = main (argc, argv, envp);
-#endif
- if (!managedapp)
- exit (mainret);
-
- if (has_cctor == 0)
- _cexit ();
- }
- return mainret;
-}
-
-extern int mingw_initltsdrot_force;
-extern int mingw_initltsdyn_force;
-extern int mingw_initltssuo_force;
-extern int mingw_initcharmax;
-
-static int __cdecl
-check_managed_app (void)
-{
- PIMAGE_DOS_HEADER pDOSHeader;
- PIMAGE_NT_HEADERS pPEHeader;
- PIMAGE_OPTIONAL_HEADER32 pNTHeader32;
- PIMAGE_OPTIONAL_HEADER64 pNTHeader64;
-
- /* Force to be linked. */
- mingw_initltsdrot_force=1;
- mingw_initltsdyn_force=1;
- mingw_initltssuo_force=1;
- mingw_initcharmax=1;
-
- pDOSHeader = (PIMAGE_DOS_HEADER) &__ImageBase;
- if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE)
- return 0;
-
- pPEHeader = (PIMAGE_NT_HEADERS)((char *)pDOSHeader + pDOSHeader->e_lfanew);
- if (pPEHeader->Signature != IMAGE_NT_SIGNATURE)
- return 0;
-
- pNTHeader32 = (PIMAGE_OPTIONAL_HEADER32) &pPEHeader->OptionalHeader;
- switch (pNTHeader32->Magic)
- {
- case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
- if (pNTHeader32->NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR)
- return 0;
- return !! pNTHeader32->DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
- case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
- pNTHeader64 = (PIMAGE_OPTIONAL_HEADER64)pNTHeader32;
- if (pNTHeader64->NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR)
- return 0;
- return !! pNTHeader64->DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
- }
- return 0;
-}
-
-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;
-#ifdef _WIN64
- case EXCEPTION_DATATYPE_MISALIGNMENT:
- case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
- case EXCEPTION_FLT_STACK_CHECK:
- case EXCEPTION_INT_OVERFLOW:
- case EXCEPTION_INVALID_HANDLE:
- /*case EXCEPTION_POSSIBLE_DEADLOCK: */
- action = EXCEPTION_CONTINUE_EXECUTION;
- break;
-#endif
- default:
- break;
- }
-
- if (action == EXCEPTION_CONTINUE_SEARCH && __mingw_oldexcpt_handler)
- action = (*__mingw_oldexcpt_handler)(exception_data);
- return action;
-}
-
-#ifdef WPRFLAG
-static size_t wbytelen(const wchar_t *p)
-{
- size_t ret = 1;
- while (*p!=0) {
- ret++,++p;
- }
- return ret*2;
-}
-static void duplicate_ppstrings (int ac, wchar_t ***av)
-{
- wchar_t **avl;
- int i;
- wchar_t **n = (wchar_t **) malloc (sizeof (wchar_t *) * (ac + 1));
-
- avl=*av;
- for (i=0; i < ac; i++)
- {
- int l = wbytelen (avl[i]);
- n[i] = (wchar_t *) malloc (l);
- memcpy (n[i], avl[i], l);
- }
- n[i] = NULL;
- *av = n;
-}
-#else
-static void duplicate_ppstrings (int ac, char ***av)
-{
- char **avl;
- int i;
- char **n = (char **) malloc (sizeof (char *) * (ac + 1));
-
- avl=*av;
- for (i=0; i < ac; i++)
- {
- int l = strlen (avl[i]) + 1;
- n[i] = (char *) malloc (l);
- memcpy (n[i], avl[i], l);
- }
- n[i] = NULL;
- *av = n;
-}
-#endif
-
-#ifdef __MINGW_SHOW_INVALID_PARAMETER_EXCEPTION
-#define __UNUSED_PARAM_1(x) x
-#else
-#define __UNUSED_PARAM_1 __UNUSED_PARAM
-#endif
-static void
-__mingw_invalidParameterHandler (const wchar_t * __UNUSED_PARAM_1(expression),
- const wchar_t * __UNUSED_PARAM_1(function),
- const wchar_t * __UNUSED_PARAM_1(file),
- unsigned int __UNUSED_PARAM_1(line),
- uintptr_t __UNUSED_PARAM(pReserved))
-{
-#ifdef __MINGW_SHOW_INVALID_PARAMETER_EXCEPTION
- wprintf(L"Invalid parameter detected in function %s. File: %s Line: %d\n", function, file, line);
- wprintf(L"Expression: %s\n", expression);
-#endif
-}
-
-static void __cdecl
-__mingw_prepare_except_for_msvcr80_and_higher (void)
-{
- _invalid_parameter_handler (*fIPH)(_invalid_parameter_handler) = NULL;
- HMODULE hmsv = GetModuleHandleA ("msvcr80.dll");
- if(!hmsv)
- hmsv = GetModuleHandleA ("msvcr70.dll");
- if (!hmsv)
- hmsv = GetModuleHandleA ("msvcrt.dll");
- if (!hmsv)
- hmsv = LoadLibraryA ("msvcrt.dll");
- if (!hmsv)
- return;
- fIPH = (_invalid_parameter_handler (*)(_invalid_parameter_handler))
- GetProcAddress (hmsv, "_set_invalid_parameter_handler");
- if (fIPH)
- (*fIPH)(__mingw_invalidParameterHandler);
-}
+++ /dev/null
-
-void _assert(int);
-
-void __cxa_pure_virtual()
-{
- _assert(0);
-}
+++ /dev/null
-/**
- * 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.
- */
-
-#ifdef CRTDLL
-#undef CRTDLL
-#endif
-
-#include <internal.h>
-
-extern int _dowildcard;
-
-#ifdef WPRFLAG
-int __CRTDECL
-__wsetargv (void)
-#else
-int __CRTDECL
-__setargv (void)
-#endif
-{
- _dowildcard = 1;
- return 0;
-}
+++ /dev/null
-/**
- * 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.
- */
-
-#ifdef CRTDLL
-#undef CRTDLL
-#endif
-
-#include <internal.h>
-
-#ifdef WPRFLAG
-int __CRTDECL
-_wsetargv (void)
-#else
-int __CRTDECL
-_setargv (void)
-#endif
-{
- return 0;
-}
+++ /dev/null
-/**
- * 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 <oscalls.h>
-#define _DECL_DLLMAIN
-#include <process.h>
-
-BOOL WINAPI DllEntryPoint (HANDLE, DWORD, LPVOID);
-
-BOOL WINAPI DllEntryPoint (HANDLE __UNUSED_PARAM(hDllHandle),
- DWORD __UNUSED_PARAM(dwReason),
- LPVOID __UNUSED_PARAM(lpreserved))
-{
- return TRUE;
-}
+++ /dev/null
-#include <oscalls.h>
-#define _DECL_DLLMAIN
-#include <process.h>
-
-BOOL WINAPI DllMain (HANDLE __UNUSED_PARAM(hDllHandle),
- DWORD __UNUSED_PARAM(dwReason),
- LPVOID __UNUSED_PARAM(lpreserved))
-{
- return TRUE;
-}
+++ /dev/null
-/**
- * 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 <windows.h>
-#include <stdlib.h>
-#include <setjmp.h>
-
-typedef void (*func_ptr) (void);
-extern func_ptr __CTOR_LIST__[];
-extern func_ptr __DTOR_LIST__[];
-
-static HMODULE hMsvcrt = NULL;
-static int free_Msvcrt = 0;
-
-typedef void __cdecl flongjmp(jmp_buf _Buf,int _Value);
-
-flongjmp *fctMsvcrtLongJmp = NULL;
-
-void __do_global_dtors (void);
-void __do_global_ctors (void);
-void __main (void);
-
-void
-__do_global_dtors (void)
-{
- static func_ptr *p = __DTOR_LIST__ + 1;
-
- while (*p)
- {
- (*(p)) ();
- p++;
- }
- if (free_Msvcrt && hMsvcrt)
- {
- free_Msvcrt = 0;
- FreeLibrary (hMsvcrt);
- hMsvcrt = NULL;
- }
-}
-
-void
-__do_global_ctors (void)
-{
- unsigned long nptrs = (unsigned long) (ptrdiff_t) __CTOR_LIST__[0];
- unsigned long i;
-
- if (!hMsvcrt) {
- hMsvcrt = GetModuleHandleA ("msvcr80.dll");
- if (!hMsvcrt)
- hMsvcrt = GetModuleHandleA ("msvcr70.dll");
- if (!hMsvcrt)
- hMsvcrt = GetModuleHandleA ("msvcrt.dll");
- if (!hMsvcrt) {
- hMsvcrt = LoadLibraryA ("msvcrt.dll");
- free_Msvcrt = 1;
- }
- fctMsvcrtLongJmp = (flongjmp *) GetProcAddress( hMsvcrt, "longjmp");
- }
-
- if (nptrs == (unsigned long) -1)
- {
- for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
- }
-
- for (i = nptrs; i >= 1; i--)
- {
- __CTOR_LIST__[i] ();
- }
-
- atexit (__do_global_dtors);
-}
-
-static int initialized = 0;
-
-void
-__main (void)
-{
- if (!initialized)
- {
- initialized = 1;
- __do_global_ctors ();
- }
-}
+++ /dev/null
-#include <assert.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-#include <stdarg.h>
-#include <stdio.h>
-
-#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;
-}
+++ /dev/null
-/**
- * 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 WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#define WIN32_NO_STATUS
-#include <stdlib.h> /* abort () */
-#include <windows.h>
-#undef WIN32_NO_STATUS
-#include <ntstatus.h> /* STATUS macros */
-#ifdef _WIN64
-#include <intrin.h>
-#endif
-
-#ifdef _WIN64
-#define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll
-#else
-#define DEFAULT_SECURITY_COOKIE 0xBB40E64E
-#endif
-
-/* Externals. */
-#ifdef _WIN64
-PRUNTIME_FUNCTION RtlLookupFunctionEntry (ULONG64, PULONG64, PVOID);
-PVOID RtlVirtualUnwind (ULONG HandlerType, ULONG64, ULONG64, PRUNTIME_FUNCTION,
- PCONTEXT, PVOID *, PULONG64, PVOID);
-#endif
-
-typedef LONG NTSTATUS; /* same as in ntdef.h / winternl.h */
-
-#define UNW_FLAG_NHANDLER 0x00
-
-typedef union
-{
- unsigned __int64 ft_scalar;
- FILETIME ft_struct;
-} FT;
-
-static EXCEPTION_RECORD GS_ExceptionRecord;
-static CONTEXT GS_ContextRecord;
-
-static const EXCEPTION_POINTERS GS_ExceptionPointers = {
- &GS_ExceptionRecord,&GS_ContextRecord
-};
-
-DECLSPEC_SELECTANY UINT_PTR __security_cookie = DEFAULT_SECURITY_COOKIE;
-DECLSPEC_SELECTANY UINT_PTR __security_cookie_complement = ~(DEFAULT_SECURITY_COOKIE);
-
-void __cdecl __security_init_cookie (void);
-
-void __cdecl
-__security_init_cookie (void)
-{
- UINT_PTR cookie;
- FT systime = { 0, };
- LARGE_INTEGER perfctr;
-
- if (__security_cookie != DEFAULT_SECURITY_COOKIE)
- {
- __security_cookie_complement = ~__security_cookie;
- return;
- }
-
- GetSystemTimeAsFileTime (&systime.ft_struct);
-#ifdef _WIN64
- cookie = systime.ft_scalar;
-#else
- cookie = systime.ft_struct.dwLowDateTime;
- cookie ^= systime.ft_struct.dwHighDateTime;
-#endif
-
- cookie ^= GetCurrentProcessId ();
- cookie ^= GetCurrentThreadId ();
- cookie ^= GetTickCount ();
-
- QueryPerformanceCounter (&perfctr);
-#ifdef _WIN64
- cookie ^= perfctr.QuadPart;
-#else
- cookie ^= perfctr.LowPart;
- cookie ^= perfctr.HighPart;
-#endif
-
-#ifdef _WIN64
- cookie &= 0x0000ffffffffffffll;
-#endif
-
- if (cookie == DEFAULT_SECURITY_COOKIE)
- cookie = DEFAULT_SECURITY_COOKIE + 1;
- __security_cookie = cookie;
- __security_cookie_complement = ~cookie;
-}
-
-
-#if defined(__GNUC__) /* wrap msvc intrinsics onto gcc builtins */
-#undef _ReturnAddress
-#undef _AddressOfReturnAddress
-#define _ReturnAddress() __builtin_return_address(0)
-#define _AddressOfReturnAddress() __builtin_frame_address (0)
-#endif /* __GNUC__ */
-
-__declspec(noreturn) void __cdecl __report_gsfailure (ULONGLONG);
-
-__declspec(noreturn) void __cdecl
-__report_gsfailure (ULONGLONG StackCookie)
-{
- volatile UINT_PTR cookie[2] __MINGW_ATTRIB_UNUSED;
-#ifdef _WIN64
- ULONG64 controlPC, imgBase, establisherFrame;
- PRUNTIME_FUNCTION fctEntry;
- PVOID hndData;
-
- RtlCaptureContext (&GS_ContextRecord);
- controlPC = GS_ContextRecord.Rip;
- fctEntry = RtlLookupFunctionEntry (controlPC, &imgBase, NULL);
- if (fctEntry != NULL)
- {
- RtlVirtualUnwind (UNW_FLAG_NHANDLER, imgBase, controlPC, fctEntry,
- &GS_ContextRecord, &hndData, &establisherFrame, NULL);
- }
- else
-#endif /* _WIN64 */
- {
-#ifdef _WIN64
- GS_ContextRecord.Rip = (ULONGLONG) _ReturnAddress();
- GS_ContextRecord.Rsp = (ULONGLONG) _AddressOfReturnAddress() + 8;
-#else
- GS_ContextRecord.Eip = (DWORD) _ReturnAddress();
- GS_ContextRecord.Esp = (DWORD) _AddressOfReturnAddress() + 4;
-#endif /* _WIN64 */
- }
-
-#ifdef _WIN64
- GS_ExceptionRecord.ExceptionAddress = (PVOID) GS_ContextRecord.Rip;
- GS_ContextRecord.Rcx = StackCookie;
-#else
- GS_ExceptionRecord.ExceptionAddress = (PVOID) GS_ContextRecord.Eip;
- GS_ContextRecord.Ecx = StackCookie;
-#endif /* _WIN64 */
- GS_ExceptionRecord.ExceptionCode = STATUS_STACK_BUFFER_OVERRUN;
- GS_ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
- cookie[0] = __security_cookie;
- cookie[1] = __security_cookie_complement;
- SetUnhandledExceptionFilter (NULL);
- UnhandledExceptionFilter ((EXCEPTION_POINTERS *) &GS_ExceptionPointers);
- TerminateProcess (GetCurrentProcess (), STATUS_STACK_BUFFER_OVERRUN);
- abort();
-}
-
+++ /dev/null
-/**
- * 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 <ctype.h>
-
-#undef isascii
-int isascii (int);
-
-int
-isascii (int c)
-{
- return __isascii(c);
-}
+++ /dev/null
-/**
- * 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 <ctype.h>
-#undef iscsym
-
-int iscsym (int);
-
-int
-iscsym (int c)
-{
- return __iscsym(c);
-}
+++ /dev/null
-/**
- * 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 <ctype.h>
-#undef iscsymf
-
-int iscsymf (int);
-
-int
-iscsymf (int c)
-{
- return __iscsymf(c);
-}
+++ /dev/null
-/**
- * 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 <internal.h>
-#include <math.h>
-#include <stdio.h>
-
-int __defaultmatherr = 0;
-
-int __CRTDECL
-_matherr (struct _exception *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;
-}
+++ /dev/null
-/**
- * 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 <_mingw.h>
-#include "../revstamp.h"
-
-const char *__mingw_get_crt_info (void)
-{
- return "MinGW-W64 Runtime " __MINGW64_VERSION_STR " ("
- __MINGW64_VERSION_STATE " - "
- "rev. " __MINGW_W64_REV ") " __MINGW_W64_REV_STAMP;
-}
-
+++ /dev/null
-/**
- * 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 <oscalls.h>
-#include <internal.h>
-#include <process.h>
-#include <math.h>
-#include <stdlib.h>
-#include <tchar.h>
-#include <sect_attribs.h>
-#include <locale.h>
-
-extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
-
-void * __cdecl
-_decode_pointer (void *codedptr)
-{
- return (void *) codedptr;
-}
-
-void * __cdecl
-_encode_pointer (void *ptr)
-{
- return ptr;
-}
-
-/* 0:console, 1:windows. */
-int mingw_app_type = 0;
+++ /dev/null
-LIBRARY msvcrt.dll
-
-EXPORTS
-access==_access
-chdir==_chdir
-chmod==_chmod
-chsize==_chsize
-close==_close
-creat==_creat
-cwait==_cwait
-daylight==_daylight
-dup==_dup
-dup2==_dup2
-ecvt==_ecvt
-eof==_eof
-execl==_execl
-execle==_execle
-execlp==_execlp
-execlpe==_execlpe
-execv==_execv
-execve==_execve
-execvp==_execvp
-execvpe==_execvpe
-fcvt==_fcvt
-fdopen==_fdopen
-fgetchar==_fgetchar
-fgetwchar==_fgetwchar
-filelength==_filelength
-fileno==_fileno
-fpreset==_fpreset
-fputchar==_fputchar
-fputwchar==_fputwchar
-fstat==_fstat
-ftime==_ftime
-gcvt==_gcvt
-getch==_getch
-getche==_getche
-getcwd==_getcwd
-getpid==_getpid
-getw==_getw
-heapwalk==_heapwalk
-isatty==_isatty
-itoa==_itoa
-kbhit==_kbhit
-lfind==_lfind
-lsearch==_lsearch
-lseek==_lseek
-ltoa==_ltoa
-memccpy==_memccpy
-memicmp==_memicmp
-mkdir==_mkdir
-mktemp==_mktemp
-open==_open
-pclose==_pclose
-popen==_popen
-putch==_putch
-putenv==_putenv
-putw==_putw
-read==_read
-rmdir==_rmdir
-rmtmp==_rmtmp
-searchenv==_searchenv
-setmode==_setmode
-snprintf=_snprintf
-sopen==_sopen
-spawnl==_spawnl
-spawnle==_spawnle
-spawnlp==_spawnlp
-spawnlpe==_spawnlpe
-spawnv==_spawnv
-spawnve==_spawnve
-spawnvp==_spawnvp
-spawnvpe==_spawnvpe
-stat==_stat
-strcmpi==_strcmpi
-strdup==_strdup
-stricmp==_stricmp
-stricoll==_stricoll
-strlwr==_strlwr
-strnicmp==_strnicmp
-strnset==_strnset
-strrev==_strrev
-strset==_strset
-strupr==_strupr
-swab==_swab
-tell==_tell
-tempnam==_tempnam
-timezone==_timezone
-tzname==_tzname
-tzset==_tzset
-umask==_umask
-ungetch==_ungetch
-unlink==_unlink
-utime==_utime
-wcsdup==_wcsdup
-wcsicmp==_wcsicmp
-wcsicoll==_wcsicoll
-wcslwr==_wcslwr
-wcsnicmp==_wcsnicmp
-wcsnset==_wcsnset
-wcsrev==_wcsrev
-wcsset==_wcsset
-wcsupr==_wcsupr
-wpopen==_wpopen
-write==_write
-; non-ANSI functions declared in math.h
-j0==_j0
-j1==_j1
-jn==_jn
-y0==_y0
-y1==_y1
-yn==_yn
-chgsign==_chgsign
-scalb==_scalb
-finite==_finite
-fpclass==_fpclass
-; C99 functions
-cabs==_cabs
-hypot==_hypot
-logb==_logb
-nextafter==_nextafter
+++ /dev/null
-/**
- * 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 <windows.h>
-#include <stdlib.h>
-
-int _fltused;
-
-void
-__do_global_dtors (void)
-{
-
-}
-
-void
-__do_global_ctors (void)
-{
-
-}
-
-BOOL
-WINAPI
-_CRT_INIT0(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
-{
- return TRUE;
-}
-
-static int initialized = 0;
-
-void
-__main (void)
-{
- if (!initialized)
- {
- initialized = 1;
- __do_global_ctors ();
- }
-}
-
-
+++ /dev/null
-/**
- * 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 <crtdefs.h>
-#include <internal.h>
-
-_PGLOBAL
-volatile unsigned int __native_dllmain_reason = UINT_MAX;
-volatile unsigned int __native_vcclrit_reason = UINT_MAX;
-volatile __enative_startup_state __native_startup_state;
-volatile void *__native_startup_lock;
+++ /dev/null
-
-int _get_output_format(void)
-{
- return 0;
-}
-
+++ /dev/null
-/**
- * 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 <windows.h>
-#include <string.h>
-
-#if defined (_WIN64) && defined (__ia64__)
-#error FIXME: Unsupported __ImageBase implementation.
-#else
-/* Hack, for bug in ld. Will be removed soon. */
-#ifndef _MSC_VER
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-/* This symbol is defined by the linker. */
-extern IMAGE_DOS_HEADER __ImageBase;
-#endif
-
-WINBOOL _ValidateImageBase (PBYTE);
-
-WINBOOL
-_ValidateImageBase (PBYTE pImageBase)
-{
- PIMAGE_DOS_HEADER pDOSHeader;
- PIMAGE_NT_HEADERS pNTHeader;
- PIMAGE_OPTIONAL_HEADER pOptHeader;
-
- pDOSHeader = (PIMAGE_DOS_HEADER) pImageBase;
- if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE)
- return FALSE;
- pNTHeader = (PIMAGE_NT_HEADERS) ((PBYTE) pDOSHeader + pDOSHeader->e_lfanew);
- if (pNTHeader->Signature != IMAGE_NT_SIGNATURE)
- return FALSE;
- pOptHeader = (PIMAGE_OPTIONAL_HEADER) &pNTHeader->OptionalHeader;
- if (pOptHeader->Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC)
- return FALSE;
- return TRUE;
-}
-
-PIMAGE_SECTION_HEADER _FindPESection (PBYTE, DWORD_PTR);
-
-PIMAGE_SECTION_HEADER
-_FindPESection (PBYTE pImageBase, DWORD_PTR rva)
-{
- PIMAGE_NT_HEADERS pNTHeader;
- PIMAGE_SECTION_HEADER pSection;
- unsigned int iSection;
-
- pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew);
-
- for (iSection = 0, pSection = IMAGE_FIRST_SECTION (pNTHeader);
- iSection < pNTHeader->FileHeader.NumberOfSections;
- ++iSection,++pSection)
- {
- if (rva >= pSection->VirtualAddress
- && rva < pSection->VirtualAddress + pSection->Misc.VirtualSize)
- return pSection;
- }
- return NULL;
-}
-
-PIMAGE_SECTION_HEADER _FindPESectionByName (const char *);
-
-PIMAGE_SECTION_HEADER
-_FindPESectionByName (const char *pName)
-{
- PBYTE pImageBase;
- PIMAGE_NT_HEADERS pNTHeader;
- PIMAGE_SECTION_HEADER pSection;
- unsigned int iSection;
-
- /* Long names aren't supported. */
- if (strlen (pName) > IMAGE_SIZEOF_SHORT_NAME)
- return NULL;
-
- pImageBase = (PBYTE) &__ImageBase;
- if (! _ValidateImageBase (pImageBase))
- return NULL;
-
- pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew);
-
- for (iSection = 0, pSection = IMAGE_FIRST_SECTION (pNTHeader);
- iSection < pNTHeader->FileHeader.NumberOfSections;
- ++iSection,++pSection)
- {
- if (!strncmp ((char *) &pSection->Name[0], pName, IMAGE_SIZEOF_SHORT_NAME))
- return pSection;
- }
- return NULL;
-}
-
-PIMAGE_SECTION_HEADER _FindPESectionExec (size_t);
-
-PIMAGE_SECTION_HEADER
-_FindPESectionExec (size_t eNo)
-{
- PBYTE pImageBase;
- PIMAGE_NT_HEADERS pNTHeader;
- PIMAGE_SECTION_HEADER pSection;
- unsigned int iSection;
-
- pImageBase = (PBYTE) &__ImageBase;
- if (! _ValidateImageBase (pImageBase))
- return NULL;
-
- pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew);
-
- for (iSection = 0, pSection = IMAGE_FIRST_SECTION (pNTHeader);
- iSection < pNTHeader->FileHeader.NumberOfSections;
- ++iSection,++pSection)
- {
- if ((pSection->Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0)
- {
- if (!eNo)
- return pSection;
- --eNo;
- }
- }
- return NULL;
-}
-
-PBYTE _GetPEImageBase (void);
-
-PBYTE
-_GetPEImageBase (void)
-{
- PBYTE pImageBase;
- pImageBase = (PBYTE) &__ImageBase;
- if (! _ValidateImageBase (pImageBase))
- return NULL;
- return pImageBase;
-}
-
-WINBOOL _IsNonwritableInCurrentImage (PBYTE);
-
-WINBOOL
-_IsNonwritableInCurrentImage (PBYTE pTarget)
-{
- PBYTE pImageBase;
- DWORD_PTR rvaTarget;
- PIMAGE_SECTION_HEADER pSection;
-
- pImageBase = (PBYTE) &__ImageBase;
- if (! _ValidateImageBase (pImageBase))
- return FALSE;
- rvaTarget = pTarget - pImageBase;
- pSection = _FindPESection (pImageBase, rvaTarget);
- if (pSection == NULL)
- return FALSE;
- return (pSection->Characteristics & IMAGE_SCN_MEM_WRITE) == 0;
-}
+++ /dev/null
-/**
- * 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.
- */
-
-char __RUNTIME_PSEUDO_RELOC_LIST_END__ = 0;
-char __RUNTIME_PSEUDO_RELOC_LIST__ = 0;
+++ /dev/null
-/* pseudo-reloc.c
-
- Contributed by Egor Duda <deo@logos-m.ru>
- Modified by addition of runtime_pseudo_reloc version 2
- by Kai Tietz <kai.tietz@onevision.com>
-
- 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 <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <memory.h>
-
-#if defined(__CYGWIN__)
-#include <wchar.h>
-#include <ntdef.h>
-#include <sys/cygwin.h>
-/* 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__;
-#ifndef _MSC_VER
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-extern char __ImageBase;
-
-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;
- DWORD flags;
-} runtime_pseudo_reloc_item_v2;
-
-typedef struct {
- 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[] = "<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;
-
- 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);
-}
-
-#define RP_VERSION_V1 0
-#define RP_VERSION_V2 1
-
-static void
-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 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)
- {
- /*************************
- * 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)
- {
- __report_error (" Unknown pseudo relocation protocol version %d.\n",
- (int) v2_hdr->version);
- return;
- }
-
- /*************************
- * 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);
-
- /* 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)
- reldata |= ~((ptrdiff_t) 0xff);
- break;
- case 16:
- reldata = (ptrdiff_t) (*((unsigned short *)reloc_target));
- if ((reldata & 0x8000) != 0)
- reldata |= ~((ptrdiff_t) 0xffff);
- break;
- case 32:
- reldata = (ptrdiff_t) (*((unsigned int *)reloc_target));
-#ifdef _WIN64
- if ((reldata & 0x80000000) != 0)
- reldata |= ~((ptrdiff_t) 0xffffffff);
-#endif
- break;
-#ifdef _WIN64
- case 64:
- reldata = (ptrdiff_t) (*((unsigned long long *)reloc_target));
- break;
-#endif
- default:
- reldata=0;
- __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;
- case 16:
- __write_memory ((void *) reloc_target, &reldata, 2);
- break;
- case 32:
- __write_memory ((void *) reloc_target, &reldata, 4);
- break;
-#ifdef _WIN64
- case 64:
- __write_memory ((void *) reloc_target, &reldata, 8);
- break;
-#endif
- }
- }
-}
-
-void
-_pei386_runtime_relocator (void)
-{
- 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);
-}
+++ /dev/null
-Index: crtexe.c
-===================================================================
---- crtexe.c (Revision 43956)
-+++ crtexe.c (Arbeitskopie)
-@@ -20,6 +20,7 @@
- #include <tchar.h>
- #include <sect_attribs.h>
- #include <locale.h>
-+#include <intrin.h>
-
- #ifndef __winitenv
- extern wchar_t *** __MINGW_IMP_SYMBOL(__winitenv);
+++ /dev/null
-/**
- * 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 <string.h>
-
-#undef strcasecmp
-int strcasecmp (const char *, const char *);
-int
-strcasecmp (const char *sz1, const char *sz2)
-{
- return _stricmp (sz1,sz2);
-}
+++ /dev/null
-/**
- * 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 <string.h>
-
-#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);
-}
+++ /dev/null
-/**
- * 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 <kai.tietz@onevision.com>
- */
-
-/* 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;
-
-// HACK around broken imports from libmingwex, until RosBE64 is updated
-#ifdef _M_AMD64
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#include <stdlib.h>
-
-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;
-}
-#endif
-
+++ /dev/null
-/**
- * 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 <kai.tietz@onevision.com>
- */
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#include <stdlib.h>
-
-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;
-}
+++ /dev/null
-/**
- * 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 <kai.tietz@onevision.com>
- */
-
-#ifdef CRTDLL
-#undef CRTDLL
-#endif
-
-#include <sect_attribs.h>
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-
-#include <stdio.h>
-#include <memory.h>
-#include <malloc.h>
-#ifndef _WIN64
-#include <stdlib.h> /* for _winmajor */
-#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
-
-typedef struct TlsDtorNode {
- int count;
- struct TlsDtorNode *next;
- _PVFV funcs[FUNCS_PER_NODE];
-} TlsDtorNode;
-
-ULONG _tls_index = 0;
-
-/* TLS raw template data start and end. */
-_CRTALLOC(".tls$AAA") char _tls_start = 0;
-_CRTALLOC(".tls$ZZZ") char _tls_end = 0;
-
-_CRTALLOC(".CRT$XLA") PIMAGE_TLS_CALLBACK __xl_a = 0;
-_CRTALLOC(".CRT$XLZ") PIMAGE_TLS_CALLBACK __xl_z = 0;
-
-#ifdef _WIN64
-_CRTALLOC(".tls") const IMAGE_TLS_DIRECTORY64 _tls_used = {
- (ULONGLONG) &_tls_start+1, (ULONGLONG) &_tls_end, (ULONGLONG) &_tls_index,
- (ULONGLONG) (&__xl_a+1), (ULONG) 0, (ULONG) 0
-};
-#else
-_CRTALLOC(".tls") const IMAGE_TLS_DIRECTORY _tls_used = {
- (ULONG)(ULONG_PTR) &_tls_start+1, (ULONG)(ULONG_PTR) &_tls_end,
- (ULONG)(ULONG_PTR) &_tls_index, (ULONG)(ULONG_PTR) (&__xl_a+1),
- (ULONG) 0, (ULONG) 0
-};
-#endif
-
-#ifndef __CRT_THREAD
-#ifdef HAVE_ATTRIBUTE_THREAD
-#define __CRT_THREAD __declspec(thread)
-#else
-#define __CRT_THREAD __thread
-#endif
-#endif
-
-#define DISABLE_MS_TLS 1
-
-static _CRTALLOC(".CRT$XDA") _PVFV __xd_a = 0;
-static _CRTALLOC(".CRT$XDZ") _PVFV __xd_z = 0;
-
-#if !defined (DISABLE_MS_TLS)
-static __CRT_THREAD TlsDtorNode *dtor_list;
-static __CRT_THREAD TlsDtorNode dtor_list_head;
-#endif
-
-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
-__dyn_tls_init (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
-{
- _PVFV *pfunc;
- uintptr_t ps;
-
-#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;
-
- if (dwReason != DLL_THREAD_ATTACH)
- {
- if (dwReason == DLL_PROCESS_ATTACH)
- __mingw_TLScallback (hDllHandle, dwReason, lpreserved);
- return TRUE;
- }
-
- ps = (uintptr_t) &__xd_a;
- ps += sizeof (uintptr_t);
- for ( ; ps != (uintptr_t) &__xd_z; ps += sizeof (uintptr_t))
- {
- pfunc = (_PVFV *) ps;
- if (*pfunc != NULL)
- (*pfunc)();
- }
- return TRUE;
-}
-
-const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback = (const PIMAGE_TLS_CALLBACK) __dyn_tls_init;
-_CRTALLOC(".CRT$XLC") PIMAGE_TLS_CALLBACK __xl_c = (PIMAGE_TLS_CALLBACK) __dyn_tls_init;
-
-int __cdecl __tlregdtor (_PVFV);
-
-int __cdecl
-__tlregdtor (_PVFV func)
-{
- if (!func)
- return 0;
-#if !defined (DISABLE_MS_TLS)
- if (dtor_list == NULL)
- {
- dtor_list = &dtor_list_head;
- dtor_list_head.count = 0;
- }
- else if (dtor_list->count == FUNCS_PER_NODE)
- {
- TlsDtorNode *pnode = (TlsDtorNode *) malloc (sizeof (TlsDtorNode));
- if (pnode == NULL)
- return -1;
- pnode->count = 0;
- pnode->next = dtor_list;
- dtor_list = pnode;
-
- dtor_list->count = 0;
- }
- dtor_list->funcs[dtor_list->count++] = func;
-#endif
- return 0;
-}
-
-static BOOL WINAPI
-__dyn_tls_dtor (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
-{
-#if !defined (DISABLE_MS_TLS)
- TlsDtorNode *pnode, *pnext;
- int i;
-#endif
-
- if (dwReason != DLL_THREAD_DETACH && dwReason != DLL_PROCESS_DETACH)
- return TRUE;
- /* As TLS variables are detroyed already by DLL_THREAD_DETACH
- call, we have to avoid access on the possible DLL_PROCESS_DETACH
- call the already destroyed TLS vars.
- TODO: The used local thread based variables have to be handled
- manually, so that we can control their lifetime here. */
-#if !defined (DISABLE_MS_TLS)
- if (dwReason != DLL_PROCESS_DETACH)
- {
- for (pnode = dtor_list; pnode != NULL; pnode = pnext)
- {
- for (i = pnode->count - 1; i >= 0; --i)
- {
- if (pnode->funcs[i] != NULL)
- (*pnode->funcs[i])();
- }
- pnext = pnode->next;
- if (pnext != NULL)
- free ((void *) pnode);
- }
- }
-#endif
- __mingw_TLScallback (hDllHandle, dwReason, lpreserved);
- return TRUE;
-}
-
-_CRTALLOC(".CRT$XLD") PIMAGE_TLS_CALLBACK __xl_d = (PIMAGE_TLS_CALLBACK) __dyn_tls_dtor;
-
-
-int mingw_initltsdrot_force = 0;
-int mingw_initltsdyn_force = 0;
-int mingw_initltssuo_force = 0;
+++ /dev/null
-/**
- * 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 <kai.tietz@onevision.com>
- *
- * This file is used by if gcc is built with --enable-threads=win32.
- *
- * Based on version created by Mumit Khan <khan@nanotech.wisc.edu>
- *
- */
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#include <stdlib.h>
-
-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 *));
-
-/* To protect the thread/key association data structure modifications. */
-static CRITICAL_SECTION __mingwthr_cs;
-static volatile int __mingwthr_cs_init = 0;
-
-typedef struct __mingwthr_key __mingwthr_key_t;
-
-/* The list of threads active with key/dtor pairs. */
-struct __mingwthr_key {
- DWORD key;
- void (*dtor)(void *);
- __mingwthr_key_t volatile *next;
-};
-
-
-static __mingwthr_key_t volatile *key_dtor_list;
-
-int
-___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *))
-{
- __mingwthr_key_t *new_key;
-
- if (__mingwthr_cs_init == 0)
- return 0;
- new_key = (__mingwthr_key_t *) calloc (1, sizeof (__mingwthr_key_t));
- if (new_key == NULL)
- return -1;
-
- new_key->key = key;
- new_key->dtor = dtor;
-
- EnterCriticalSection (&__mingwthr_cs);
-
- new_key->next = key_dtor_list;
- key_dtor_list = new_key;
-
- LeaveCriticalSection (&__mingwthr_cs);
- return 0;
-}
-
-int
-___w64_mingwthr_remove_key_dtor (DWORD key)
-{
- __mingwthr_key_t volatile *prev_key;
- __mingwthr_key_t volatile *cur_key;
-
- if (__mingwthr_cs_init == 0)
- return 0;
-
- EnterCriticalSection (&__mingwthr_cs);
-
- prev_key = NULL;
- cur_key = key_dtor_list;
-
- while (cur_key != NULL)
- {
- if ( cur_key->key == key)
- {
- if (prev_key == NULL)
- key_dtor_list = cur_key->next;
- else
- prev_key->next = cur_key->next;
-
- free ((void*)cur_key);
- break;
- }
- prev_key = cur_key;
- cur_key = cur_key->next;
- }
-
- LeaveCriticalSection (&__mingwthr_cs);
- return 0;
-}
-
-static void
-__mingwthr_run_key_dtors (void)
-{
- __mingwthr_key_t volatile *keyp;
-
- if (__mingwthr_cs_init == 0)
- return;
- EnterCriticalSection (&__mingwthr_cs);
-
- for (keyp = key_dtor_list; keyp; )
- {
- LPVOID value = TlsGetValue (keyp->key);
- if (GetLastError () == ERROR_SUCCESS)
- {
- if (value)
- (*keyp->dtor) (value);
- }
- keyp = keyp->next;
- }
-
- LeaveCriticalSection (&__mingwthr_cs);
-}
-
-WINBOOL
-__mingw_TLScallback (HANDLE __UNUSED_PARAM(hDllHandle),
- DWORD reason,
- LPVOID __UNUSED_PARAM(reserved))
-{
- switch (reason)
- {
- case DLL_PROCESS_ATTACH:
- if (__mingwthr_cs_init == 0)
- InitializeCriticalSection (&__mingwthr_cs);
- __mingwthr_cs_init = 1;
- break;
- case DLL_PROCESS_DETACH:
- __mingwthr_run_key_dtors();
- if (__mingwthr_cs_init == 1)
- {
- __mingwthr_cs_init = 0;
- DeleteCriticalSection (&__mingwthr_cs);
- }
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- __mingwthr_run_key_dtors();
- break;
- }
- return TRUE;
-}
-
+++ /dev/null
-/**
- * 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 <ctype.h>
-
-#undef toascii
-
-int toascii (int);
-
-int
-toascii (int c)
-{
- return __toascii(c);
-}
+++ /dev/null
-/**
- * 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 <fcntl.h>
-
-/* Set default file mode to text */
-
-/* Is this correct? Default value of _fmode in msvcrt.dll is 0. */
-
-int _fmode = _O_TEXT;
+++ /dev/null
-/**
- * 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"
-
+++ /dev/null
-/**
- * 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"
-
+++ /dev/null
-/**
- * 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"
-
+++ /dev/null
-/**
- * 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 <string.h>
-
-#undef wcscmpi
-int wcscmpi (const wchar_t *, const wchar_t *);
-
-int
-wcscmpi (const wchar_t * ws1,const wchar_t * ws2)
-{
- return _wcsicmp (ws1,ws2);
-}
+++ /dev/null
-/**
- * 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.
- */
-
-/* _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.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifndef __ENABLE_GLOBBING
-#define __ENABLE_GLOBBING 0 /* -1 */
-#endif
-
-int _dowildcard = __ENABLE_GLOBBING;
-
+++ /dev/null
-/**
- * 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.
- */
-
-int _commode = 0;
+++ /dev/null
-/**
- * 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.
- */
-
-int __globallocalestatus = ~0x1;
+++ /dev/null
-/**
- * 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.
- */
-
-int _fmode = 0;