Author: tkreuzer Date: Mon Jan 25 17:44:27 2010 New Revision: 45252
URL: http://svn.reactos.org/svn/reactos?rev=45252&view=rev Log: - delete old folders from main rbuild file, we don't need those anymore - Add debugsup, mingw, wcsfuncs - add sdk.rbuild - comment our dependency on rtl in mkhive for now - comment out buildno.h in the makefile rbuild creates makefile.auto now
Added: branches/Tree-restructure-test/sdk/libs/debugsup/ branches/Tree-restructure-test/sdk/libs/debugsup/debugsup-ntos.spec (with props) branches/Tree-restructure-test/sdk/libs/debugsup/debugsup.rbuild (with props) branches/Tree-restructure-test/sdk/libs/libs.rbuild (with props) branches/Tree-restructure-test/sdk/libs/mingw/ branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp10.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp8.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/_newmode.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/atonexit.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/charmax.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/cinitexe.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/crt0_c.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/crt0_w.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/crtdll.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/crtexe.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/dllargv.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/dllentry.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/dllmain.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/gccmain.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/getopt.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/gs_support.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/merr.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/mingw.rbuild (with props) branches/Tree-restructure-test/sdk/libs/mingw/mingw_helpers.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/moldname-msvcrt.def (with props) branches/Tree-restructure-test/sdk/libs/mingw/natstart.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/pesect.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc-list.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/tlssup.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/wildcard.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/xncommod.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/xthdloc.c (with props) branches/Tree-restructure-test/sdk/libs/mingw/xtxtmode.c (with props) branches/Tree-restructure-test/sdk/libs/wcsfuncs/ branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.c (with props) branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.rbuild (with props) branches/Tree-restructure-test/sdk/sdk.rbuild (with props) Modified: branches/Tree-restructure-test/Makefile branches/Tree-restructure-test/ReactOS-i386.rbuild branches/Tree-restructure-test/sdk/tools/mkhive/mkhive.rbuild
Modified: branches/Tree-restructure-test/Makefile URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/Makefile?r... ============================================================================== --- branches/Tree-restructure-test/Makefile [iso-8859-1] (original) +++ branches/Tree-restructure-test/Makefile [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -432,7 +432,7 @@ PREAUTO := \ $(BIN2C_TARGET) \ $(BIN2RES_TARGET) \ - $(BUILDNO_H) \ +# $(BUILDNO_H) \ $(GENDIB_DIB_FILES) \ $(NCI_SERVICE_FILES)
Modified: branches/Tree-restructure-test/ReactOS-i386.rbuild URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/ReactOS-i3... ============================================================================== --- branches/Tree-restructure-test/ReactOS-i386.rbuild [iso-8859-1] (original) +++ branches/Tree-restructure-test/ReactOS-i386.rbuild [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -35,44 +35,7 @@ <linkerflag>-file-alignment=0x1000</linkerflag> <linkerflag>-section-alignment=0x1000</linkerflag> </group> -<!-- - <directory name="base"> - <xi:include href="base/base.rbuild" /> - </directory> - <directory name="boot"> - <xi:include href="boot/boot.rbuild" /> - </directory> - <directory name="dll"> - <xi:include href="dll/dll.rbuild" /> - </directory> - <directory name="drivers"> - <xi:include href="drivers/drivers.rbuild" /> - </directory> - <directory name="hal"> - <xi:include href="hal/hal.rbuild" /> - </directory> - <directory name="include"> - <xi:include href="include/directory.rbuild" /> - </directory> - <directory name="lib"> - <xi:include href="lib/lib.rbuild" /> - </directory> - <directory name="media"> - <xi:include href="media/media.rbuild" /> - </directory> - <directory name="modules"> - <xi:include href="modules/directory.rbuild" /> - </directory> - <directory name="ntoskrnl"> - <xi:include href="ntoskrnl/ntoskrnl.rbuild" /> - <if property="BUILD_MP" value="1"> - <xi:include href="ntoskrnl/ntkrnlmp.rbuild" /> - </if> - </directory> - <directory name="subsystems"> - <xi:include href="subsystems/subsystems.rbuild" /> - </directory> - --> + <directory name="sdk"> <xi:include href="sdk/sdk.rbuild" /> </directory>
Added: branches/Tree-restructure-test/sdk/libs/debugsup/debugsup-ntos.spec URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/d... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/debugsup/debugsup-ntos.spec (added) +++ branches/Tree-restructure-test/sdk/libs/debugsup/debugsup-ntos.spec [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,8 @@ +@ stdcall DbgBreakPoint() +@ stdcall DbgBreakPointWithStatus(long) +@ varargs DbgPrint() +@ varargs DbgPrintEx() +@ stdcall DbgPrompt(ptr ptr long) +@ stdcall RtlAssert(ptr ptr long ptr) +@ stdcall RtlUnwind(ptr ptr ptr ptr) +@ stdcall vDbgPrintExWithPrefix(ptr long long ptr ptr)
Propchange: branches/Tree-restructure-test/sdk/libs/debugsup/debugsup-ntos.spec ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/debugsup/debugsup.rbuild URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/d... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/debugsup/debugsup.rbuild (added) +++ branches/Tree-restructure-test/sdk/libs/debugsup/debugsup.rbuild [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,10 @@ +<?xml version="1.0"?> +<!DOCTYPE group SYSTEM "../../tools/rbuild/project.dtd"> +<group> + <module name="debugsup_ntoskrnl" type="staticlibrary"> + <importlibrary definition="debugsup-ntos.spec" dllname="ntoskrnl.exe" /> + </module> + <module name="debugsup_ntdll" type="staticlibrary"> + <importlibrary definition="debugsup-ntos.spec" dllname="ntdll.dll" /> + </module> +</group>
Propchange: branches/Tree-restructure-test/sdk/libs/debugsup/debugsup.rbuild ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/libs.rbuild URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/l... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/libs.rbuild (added) +++ branches/Tree-restructure-test/sdk/libs/libs.rbuild [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,22 @@ +<?xml version="1.0"?> +<!DOCTYPE group SYSTEM "../tools/rbuild/project.dtd"> +<group xmlns:xi="http://www.w3.org/2001/XInclude"> +<directory name="cmlib"> + <xi:include href="cmlib/cmlib.rbuild" /> +</directory> +<directory name="debugsup"> + <xi:include href="debugsup/debugsup.rbuild" /> +</directory> +<directory name="inflib"> + <xi:include href="inflib/inflib.rbuild" /> +</directory> +<directory name="mingw"> + <xi:include href="mingw/mingw.rbuild" /> +</directory> +<directory name="wcsfuncs"> + <xi:include href="wcsfuncs/wcsfuncs.rbuild" /> +</directory> +<directory name="zlib"> + <xi:include href="zlib/zlib.rbuild" /> +</directory> +</group>
Propchange: branches/Tree-restructure-test/sdk/libs/libs.rbuild ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp10.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp10.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp10.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,20 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +void _fpreset (void) +{ +#ifdef __GNUC__ + __asm__ ("fninit" ); +#else + __asm fninit; +#endif +} + +#ifdef __GNUC__ +void __attribute__ ((alias ("_fpreset"))) fpreset(void); +#else +void fpreset(void) { _fpreset(); } +#endif
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp10.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp8.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp8.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp8.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,15 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +extern void (*_imp___fpreset)(void) ; +void _fpreset (void) +{ (*_imp___fpreset)(); } + +#ifdef __GNUC__ +void __attribute__ ((alias ("_fpreset"))) fpreset(void); +#else +void fpreset(void) { _fpreset(); } +#endif
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/CRT_fp8.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/_newmode.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/_newmode.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/_newmode.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +int _newmode = 0;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/_newmode.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/atonexit.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/atonexit.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/atonexit.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,57 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#undef CRTDLL +#ifndef _DLL +#define _DLL +#endif + +#include <oscalls.h> +#include <internal.h> +#include <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 *_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; +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/atonexit.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/charmax.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/charmax.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/charmax.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,21 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <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;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/charmax.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/cinitexe.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/cinitexe.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/cinitexe.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,8 @@ +#include <stdio.h> +#include <internal.h> +#include <sect_attribs.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 };
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/cinitexe.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/crt0_c.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/crt0_c.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/crt0_c.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,12 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <windows.h> + +int main (int flags, char **cmdline, char **inst) +{ + return (int) WinMain ((HINSTANCE) inst, NULL, (LPSTR) cmdline,(DWORD) flags); +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/crt0_c.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/crt0_w.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/crt0_w.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/crt0_w.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,16 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <windows.h> + +extern void __main(void); + +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); +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/crt0_w.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/crtdll.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/crtdll.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/crtdll.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,209 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#ifdef CRTDLL +#undef CRTDLL +#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[]; + +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
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/crtdll.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/crtexe.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/crtexe.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/crtexe.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,479 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#undef CRTDLL +#ifndef _DLL +#define _DLL +#endif + +#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 ***_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('"') + +__declspec(dllimport) 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; + +#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[]; + +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 +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; + +extern void _pei386_runtime_relocator (void); +static long CALLBACK _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; + +#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) +{ + mingw_app_type = 1; + __security_init_cookie (); + return __tmainCRTStartup (); +} + +int mainCRTStartup (void) +{ + mingw_app_type = 0; + __security_init_cookie (); + return __tmainCRTStartup (); +} + + +__declspec(noinline) int +__tmainCRTStartup (void) +{ + _TCHAR *lpszCommandLine = NULL; + STARTUPINFO StartupInfo; + BOOL 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 && _IsNonwritableInCurrentImage ((PBYTE) &__dyn_tls_init_callback)) + __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL); + + _pei386_runtime_relocator (); + +#if defined(__i386__) || defined(_M_IX86) + __writefsdword(0, 0xffffffff); +#endif + //AddVectoredExceptionHandler (0, (PVECTORED_EXCEPTION_HANDLER)__mingw_vex); + SetUnhandledExceptionFilter (_gnu_exception_handler); + + _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) + lpszCommandLine++; + } +#endif + ++lpszCommandLine; + } + while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) + lpszCommandLine++; + +#ifdef WPRFLAG + /* C++ initialization. + gcc inserts this call automatically for a function called main, but not for wmain. */ + __main (); + 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; + /* 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; + + 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. */ + #if 0 + #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 +#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
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/crtexe.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/dllargv.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/dllargv.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/dllargv.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,22 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#ifdef CRTDLL +#undef CRTDLL +#endif + +#include <internal.h> + +#ifdef WPRFLAG +int __CRTDECL +_wsetargv (void) +#else +int __CRTDECL +_setargv (void) +#endif +{ + return 0; +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/dllargv.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/dllentry.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/dllentry.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/dllentry.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,14 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <oscalls.h> +#define _DECL_DLLMAIN +#include <process.h> + +BOOL WINAPI DllEntryPoint(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + return TRUE; +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/dllentry.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/dllmain.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/dllmain.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/dllmain.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,8 @@ +#include <oscalls.h> +#define _DECL_DLLMAIN +#include <process.h> + +BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) +{ + return TRUE; +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/dllmain.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/gccmain.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/gccmain.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/gccmain.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,72 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <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; + +typedef void __cdecl flongjmp(jmp_buf _Buf,int _Value); + +flongjmp *fctMsvcrtLongJmp = NULL; + +void +__do_global_dtors (void) +{ + static func_ptr *p = __DTOR_LIST__ + 1; + + while (*p) + { + (*(p)) (); + p++; + } + if (hMsvcrt) + { + 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 = LoadLibrary ("msvcrt.dll"); + 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 (); + } +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/gccmain.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/getopt.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/getopt.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/getopt.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,394 @@ +#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; +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/getopt.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/gs_support.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/gs_support.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/gs_support.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,145 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <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, PVOID); +#endif + +typedef LONG NTSTATUS; + +#define UNW_FLAG_NHANDLER 0x00 +#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 __GNUC__ +#ifdef _WIN64 + GS_ContextRecord.Rip = (ULONGLONG) __builtin_return_address (0); + GS_ContextRecord.Rsp = (ULONGLONG) __builtin_frame_address (0) + 8; +#else + GS_ContextRecord.Eip = (DWORD) __builtin_return_address (0); + GS_ContextRecord.Esp = (DWORD) __builtin_frame_address (0) + 4; +#endif +#else +#ifdef _WIN64 + GS_ContextRecord.Rip = (ULONGLONG) _ReturnAddress(); + GS_ContextRecord.Rsp = (ULONGLONG) _AddressOfReturnAddress(); +#else + GS_ContextRecord.Eip = (DWORD) _ReturnAddress(); + GS_ContextRecord.Esp = (DWORD) _AddressOfReturnAddress(); +#endif +#endif + } + +#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(); +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/gs_support.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/merr.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/merr.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/merr.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,53 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <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; +} +
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/merr.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/mingw.rbuild URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/mingw.rbuild (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/mingw.rbuild [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,53 @@ +<?xml version="1.0"?> +<!DOCTYPE group SYSTEM "../../../tools/rbuild/project.dtd"> +<group> +<module name="mingw_common" type="staticlibrary" isstartuplib="true" crt="dll"> + <define name="_CRTBLD" /> + <include base="ReactOS">include/reactos/mingw-w64</include> + <!-- library>kernel32</library --> + <file>_newmode.c</file> + <file>atonexit.c</file> + <file>charmax.c</file> + <file>cinitexe.c</file> + <file>CRT_fp10.c</file> + <file>CRT_fp8.c</file> + <file>dllentry.c</file> + <file>gccmain.c</file> + <file>getopt.c</file> + <file>gs_support.c</file> + <file>merr.c</file> + <file>mingw_helpers.c</file> + <file>natstart.c</file> + <file>pesect.c</file> + <file>pseudo-reloc.c</file> + <file>pseudo-reloc-list.c</file> + <file>tlssup.c</file> + <file>wildcard.c</file> + <file>xncommod.c</file> + <file>xthdloc.c</file> + <file>xtxtmode.c</file> +</module> +<module name="mingw_main" type="staticlibrary" isstartuplib="true" crt="dll"> + <define name="_CRTBLD" /> + <include base="ReactOS">include/reactos/mingw-w64</include> + <compilerflag compilerset="msc">/wd4733</compilerflag> + <file>crt0_c.c</file> + <file>crtexe.c</file> + <file>dllargv.c</file> +</module> +<module name="mingw_wmain" type="staticlibrary" isstartuplib="true" unicode="yes" crt="dll"> + <define name="_CRTBLD" /> + <define name="WPRFLAG" /> + <include base="ReactOS">include/reactos/mingw-w64</include> + <compilerflag compilerset="msc">/wd4733</compilerflag> + <file>crt0_w.c</file> + <file>crtexe.c</file> + <file>dllargv.c</file> +</module> +<module name="mingw_dllmain" type="staticlibrary" isstartuplib="true" crt="dll"> + <define name="_CRTBLD" /> + <include base="ReactOS">include/reactos/mingw-w64</include> + <file>crtdll.c</file> + <file>dllargv.c</file> +</module> +</group>
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/mingw.rbuild ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/mingw_helpers.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/mingw_helpers.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/mingw_helpers.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,31 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <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;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/mingw_helpers.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/moldname-msvcrt.def URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/moldname-msvcrt.def (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/moldname-msvcrt.def [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,118 @@ +EXPORTS +access +chdir +chmod +chsize +close +creat +cwait +daylight DATA +dup +dup2 +ecvt +eof +execl +execle +execlp +execlpe +execv +execve +execvp +execvpe +fcvt +fdopen +fgetchar +fgetwchar +filelength +fileno +; fpreset +fputchar +fputwchar +;fstat +ftime +gcvt +getch +getche +getcwd +getpid +getw +heapwalk +isatty +itoa +kbhit +lfind +lsearch +lseek +ltoa +memccpy +memicmp +mkdir +mktemp +open +pclose +popen +putch +putenv +putw +read +rmdir +rmtmp +searchenv +setmode +sopen +spawnl +spawnle +spawnlp +spawnlpe +spawnv +spawnve +spawnvp +spawnvpe +;stat +strcmpi +strdup +stricmp +stricoll +strlwr +strnicmp +strnset +strrev +strset +strupr +swab +tell +tempnam +timezone DATA +tzname DATA +tzset +umask +ungetch +unlink +utime +wcsdup +wcsicmp +wcsicoll +wcslwr +wcsnicmp +wcsnset +wcsrev +wcsset +wcsupr +wpopen +write +; non-ANSI functions declared in math.h +j0 +j1 +jn +y0 +y1 +yn +chgsign +;scalb +finite +fpclass +; C99 functions +cabs +hypot +logb +nextafter
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/moldname-msvcrt.def ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/natstart.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/natstart.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/natstart.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,14 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER 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;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/natstart.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/pesect.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/pesect.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/pesect.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,72 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <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; +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/pesect.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc-list.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc-list.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc-list.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,8 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +char __RUNTIME_PSEUDO_RELOC_LIST_END__ = 0; +char __RUNTIME_PSEUDO_RELOC_LIST__ = 0;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc-list.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,156 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#include <windows.h> +#include <stdio.h> +#include <stdlib.h> +#include <memory.h> + +extern char __RUNTIME_PSEUDO_RELOC_LIST__; +extern char __RUNTIME_PSEUDO_RELOC_LIST_END__; +extern char _image_base__; + +typedef struct { + DWORD addend; + DWORD target; +} runtime_pseudo_reloc_item_v1; + +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 +__write_memory (void *addr,const void *src,size_t len) +{ + MEMORY_BASIC_INFORMATION b; + DWORD oldprot; + if (!len) + return; + if (!VirtualQuery (addr, &b, sizeof(b))) + abort (); + // Protect + if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE) + VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, + &oldprot); + memcpy (addr, src, len); + if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE) + VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot); +} + +#define RP_VERSION_V1 0 +#define RP_VERSION_V2 1 + +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; + + if (reloc_target < 8) + return; + /* Check if this is old version pseudo relocation version. */ + if (reloc_target >= 12 + && v2_hdr->magic1 == 0 && v2_hdr->magic2 == 0 + && v2_hdr->version == RP_VERSION_V1) + v2_hdr++; + if (v2_hdr->magic1 != 0 || v2_hdr->magic2 != 0) + { + runtime_pseudo_reloc_item_v1 *o; + for (o = (runtime_pseudo_reloc_item_v1 *) v2_hdr; o < (runtime_pseudo_reloc_item_v1 *)end; o++) + { + DWORD newval; + reloc_target = (ptrdiff_t) base + o->target; + newval = (*((DWORD*) reloc_target)) + o->addend; + __write_memory ((void *) reloc_target, &newval, sizeof(DWORD)); + } + return; + } + /* Check if this is a known version. */ + if (v2_hdr->version != RP_VERSION_V2) + { + fprintf (stderr, "pseudo_relocation protocol version %d is unknown to this runtime.\n", + (int) v2_hdr->version); + return; + } + /* Walk over header. */ + r = (runtime_pseudo_reloc_item_v2 *) &v2_hdr[1]; + + for (; r < (runtime_pseudo_reloc_item_v2 *) end; r++) + { + reloc_target = (ptrdiff_t) base + r->target; + addr_imp = (ptrdiff_t) base + r->sym; + addr_imp = *((ptrdiff_t *) addr_imp); + + 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; + fprintf(stderr, "Unknown pseudo relocation bit size %d\n",(int) (r->flags & 0xff)); + break; + } + reldata -= ((ptrdiff_t) base + r->sym); + reldata += addr_imp; + 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 () +{ + static int was_init = 0; + if (was_init) + return; + ++was_init; + do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,&__RUNTIME_PSEUDO_RELOC_LIST_END__,&_image_base__); +}
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/pseudo-reloc.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/tlssup.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/tlssup.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/tlssup.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,130 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +#ifdef CRTDLL +#undef CRTDLL +#endif + +#include <internal.h> +#include <sect_attribs.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; + + if (dwReason != DLL_THREAD_ATTACH) + return TRUE; + + for (pfunc = &__xd_a + 1; pfunc != &__xd_z; ++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) +{ + 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; + + 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;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/tlssup.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/wildcard.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/wildcard.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/wildcard.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +int _dowildcard = 0;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/wildcard.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/xncommod.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/xncommod.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/xncommod.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +int _commode = 0;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/xncommod.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/xthdloc.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/xthdloc.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/xthdloc.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +int __globallocalestatus = ~0x1;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/xthdloc.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/mingw/xtxtmode.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/m... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/mingw/xtxtmode.c (added) +++ branches/Tree-restructure-test/sdk/libs/mingw/xtxtmode.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,7 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + +int _fmode = 0;
Propchange: branches/Tree-restructure-test/sdk/libs/mingw/xtxtmode.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.c URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/w... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.c (added) +++ branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.c [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,48 @@ +/* + PROJECT: ReactOS + LICENSE: GPL v2 or any later version + FILE: lib/host/wcsfuncs/wcsfuncs.c + PURPOSE: Reimplemented wide-character string functions for host tools (to be independent of the host wchar_t size) + COPYRIGHT: Copyright 2008 Colin Finck mail@colinfinck.de +*/ + +#include <host/typedefs.h> + +/* Function implementations */ +SIZE_T utf16_wcslen(PCWSTR str) +{ + SIZE_T i; + + for(i = 0; str[i]; i++); + + return i; +} + +PWSTR utf16_wcschr(PWSTR str, WCHAR c) +{ + SIZE_T i; + + for(i = 0; str[i] && str[i] != c; i++); + + if(str[i]) + return &str[i]; + else + return NULL; +} + +INT utf16_wcsncmp(PCWSTR string1, PCWSTR string2, size_t count) +{ + while(count--) + { + if(*string1 != *string2) + return 1; + + if(*string1 == 0) + return 0; + + string1++; + string2++; + } + + return 0; +}
Propchange: branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.rbuild URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/libs/w... ============================================================================== --- branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.rbuild (added) +++ branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.rbuild [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,5 @@ +<?xml version="1.0"?> +<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd"> +<module name="host_wcsfuncs" type="hoststaticlibrary"> + <file>wcsfuncs.c</file> +</module>
Propchange: branches/Tree-restructure-test/sdk/libs/wcsfuncs/wcsfuncs.rbuild ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/Tree-restructure-test/sdk/sdk.rbuild URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/sdk.rb... ============================================================================== --- branches/Tree-restructure-test/sdk/sdk.rbuild (added) +++ branches/Tree-restructure-test/sdk/sdk.rbuild [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -1,0 +1,10 @@ +<?xml version="1.0"?> +<!DOCTYPE group SYSTEM "../tools/rbuild/project.dtd"> +<group xmlns:xi="http://www.w3.org/2001/XInclude"> +<directory name="libs"> + <xi:include href="libs/libs.rbuild" /> +</directory> +<directory name="tools"> + <xi:include href="tools/tools.rbuild" /> +</directory> +</group>
Propchange: branches/Tree-restructure-test/sdk/sdk.rbuild ------------------------------------------------------------------------------ svn:eol-style = native
Modified: branches/Tree-restructure-test/sdk/tools/mkhive/mkhive.rbuild URL: http://svn.reactos.org/svn/reactos/branches/Tree-restructure-test/sdk/tools/... ============================================================================== --- branches/Tree-restructure-test/sdk/tools/mkhive/mkhive.rbuild [iso-8859-1] (original) +++ branches/Tree-restructure-test/sdk/tools/mkhive/mkhive.rbuild [iso-8859-1] Mon Jan 25 17:44:27 2010 @@ -4,7 +4,7 @@ <include base="inflibhost">.</include> <include base="cmlibhost">.</include> <include base="zlibhost">.</include> - <include base="rtl">.</include> + <!-- include base="rtl">.</include --> <define name="MKHIVE_HOST" /> <compilerflag compilerset="gcc">-fshort-wchar</compilerflag> <library>inflibhost</library>