Commit WIP. Part 2 of ??

Update mingw32 runtime to mingw-w64 trunk
-Support for msvc 7.0 features
-TLS support disabled because ros is not ready

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