Author: sserapion Date: Sun Nov 16 23:51:18 2008 New Revision: 37391
URL: http://svn.reactos.org/svn/reactos?rev=37391&view=rev Log: - call __main (C++ initialization) gcc inserts this call automatically for a function called "main", but not for "wmain" fixes explorer - support pseudo runtime relocation v2. - re-enable commented out code for security cookies. - rename entry point __tmainCRTStartup. - gccmain.c re-add comment explaining this file's purpose.
Added: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/CRT_fp8.c (with props) branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllargv.c (with props) branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c (with props) Removed: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllmain.c Modified: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crt0_w.c branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crtexe.c branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/gccmain.c branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/mingw.rbuild branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc.c
Added: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/CRT_fp8.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/CRT_fp8.c (added) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/CRT_fp8.c [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -1,0 +1,5 @@ +extern void (*_imp___fpreset)(void) ; +void _fpreset (void) +{ (*_imp___fpreset)(); } + +void __attribute__ ((alias ("_fpreset"))) fpreset(void);
Propchange: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/CRT_fp8.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crt0_w.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crt0_w.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crt0_w.c [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -2,8 +2,13 @@
int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nShowCmd);
- +void __main(void); int wmain (int flags, wchar_t **cmdline, wchar_t **inst) { +#ifdef __GNUC__ + /* C++ initialization. (gcc inserts this call automatically for + * a function called "main", but not for "wmain") */ + __main(); +#endif return (int) wWinMain ((HINSTANCE) inst, NULL, (LPWSTR) cmdline,(DWORD) flags); }
Modified: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crtexe.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crtexe.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/crtexe.c [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -1,5 +1,5 @@ #undef CRTDLL -#define _DLL +//#define _DLL
#define SPECIAL_CRTEXE
@@ -31,7 +31,7 @@ #define SPACECHAR _T(' ') #define DQUOTECHAR _T('"')
-_CRTIMP void __setusermatherr(int (__cdecl *)(struct _exception *)); +__declspec(dllimport) void __setusermatherr(int (__cdecl *)(struct _exception *));
extern int *_imp___fmode; extern int *_imp___commode; @@ -68,9 +68,9 @@ static char **envp; #endif
-static int argret=0; +static int argret; static int mainret=0; -static int managedapp=0; +static int managedapp; static int has_cctor = 0; static _startupinfo startinfo;
@@ -102,8 +102,10 @@ *_imp___fmode = _fmode; *_imp___commode = _commode;
-#ifndef WPRFLAG - _dowildcard = 1; +#ifdef WPRFLAG + _wsetargv(); +#else + _setargv(); #endif
if (! __defaultmatherr) @@ -119,15 +121,15 @@ 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); +} + +static int __tmainCRTStartup (void);
#ifdef WPRFLAG int wWinMainCRTStartup (void) @@ -136,8 +138,8 @@ #endif { mingw_app_type = 1; - //__security_init_cookie (); - return __mingw_CRTStartup (); + __security_init_cookie (); + return __tmainCRTStartup (); }
#ifdef WPRFLAG @@ -147,26 +149,25 @@ #endif { mingw_app_type = 0; - //__security_init_cookie (); - return __mingw_CRTStartup (); + __security_init_cookie (); + return __tmainCRTStartup (); }
__declspec(noinline) int -__mingw_CRTStartup (void) +__tmainCRTStartup (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; + int nested = FALSE; while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock, fiberid, 0)) != 0) { @@ -177,7 +178,6 @@ } Sleep(1000); } -#endif if (__native_startup_state == __initializing) { _amsg_exit (31); @@ -404,7 +404,7 @@ 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" @@ -421,6 +421,7 @@ "jmp *4(%eax)\n\r" "l1:\n\t" "nop\n"); +#endif #endif return _gnu_exception_handler(exception_data); }
Added: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllargv.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllargv.c (added) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllargv.c [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -1,0 +1,30 @@ +#ifdef CRTDLL +#undef CRTDLL +#endif + +#include "internal.h" + +extern int _dowildcard; + +#ifdef WPRFLAG +int __CRTDECL +_wsetargv (void) +#else +int __CRTDECL +_setargv (void) +#endif +{ + return 0; +} + +#ifdef WPRFLAG +int __CRTDECL +__wsetargv (void) +#else +int __CRTDECL +__setargv (void) +#endif +{ + _dowildcard = 1; + return 0; +}
Propchange: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllargv.c ------------------------------------------------------------------------------ svn:eol-style = native
Removed: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllmain.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllmain.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/dllmain.c (removed) @@ -1,9 +1,0 @@ -#define _DECL_DLLMAIN -#define _WINDOWS_ -#include <windows.h> -#include <process.h> - -BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) -{ - return TRUE; -}
Modified: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/gccmain.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/gccmain.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/gccmain.c [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -1,3 +1,15 @@ +/* + * 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. + * + */ #include <windows.h> #include <stdlib.h> #include <setjmp.h> @@ -6,7 +18,7 @@ extern func_ptr __CTOR_LIST__[]; extern func_ptr __DTOR_LIST__[];
-//static HMODULE hMsvcrt = NULL; +static HMODULE hMsvcrt = NULL;
typedef void __cdecl flongjmp(jmp_buf _Buf,int _Value);
@@ -22,11 +34,11 @@ (*(p)) (); p++; } - //if (hMsvcrt) - // { - // FreeLibrary (hMsvcrt); - // hMsvcrt = NULL; - // } + if (hMsvcrt) + { + FreeLibrary (hMsvcrt); + hMsvcrt = NULL; + } }
void @@ -35,10 +47,10 @@ 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 (!hMsvcrt) { + hMsvcrt = LoadLibrary ("msvcrt.dll"); + fctMsvcrtLongJmp = (flongjmp *) GetProcAddress( hMsvcrt, "longjmp"); + }
if (nptrs == (unsigned long) -1) {
Modified: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/mingw.rbuild URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/mingw.rbuild [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/mingw.rbuild [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -4,6 +4,7 @@ <module name="mingw_common" type="staticlibrary" isstartuplib="true" underscoresymbols="true" crt="dll"> <importlibrary definition="moldname-msvcrt.def" dllname="msvcrt.dll" /> <include base="mingw_common">include</include> + <library>kernel32</library> <file>_newmode.c</file> <file>_wgetopt.c</file> <file>argv.c</file> @@ -12,17 +13,17 @@ <file>charmax.c</file> <file>cinitexe.c</file> <file>CRT_fp10.c</file> - <file>crtdll.c</file> + <file>CRT_fp8.c</file> <file>dllentry.c</file> - <file>dllmain.c</file> <file>gccmain.c</file> <file>getopt.c</file> - <!-- <file>gs_support.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> @@ -33,16 +34,18 @@ <include base="mingw_common">include</include> <file>crt0_c.c</file> <file>crtexe.c</file> + <file>dllargv.c</file> </module> <module name="mingw_wmain" type="staticlibrary" isstartuplib="true" allowwarnings="true" unicode="yes" crt="dll"> <include base="mingw_common">include</include> <define name="WPRFLAG"/> <file>crt0_w.c</file> <file>crtexe.c</file> + <file>dllargv.c</file> </module> <module name="mingw_dllmain" type="staticlibrary" isstartuplib="true" crt="dll"> <include base="mingw_common">include</include> - <file>dllentry.c</file> - <file>dllmain.c</file> + <file>dllargv.c</file> + <file>crtdll.c</file> </module> </group>
Added: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c (added) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -1,0 +1,2 @@ +char __RUNTIME_PSEUDO_RELOC_LIST_END__ = 0; +char __RUNTIME_PSEUDO_RELOC_LIST__ = 0;
Propchange: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc-list.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/3r... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/3rdparty/mingw/pseudo-reloc.c [iso-8859-1] Sun Nov 16 23:51:18 2008 @@ -1,50 +1,127 @@ -/* pseudo-reloc.c - - Written by Egor Duda deo@logos-m.ru - THIS SOFTWARE IS NOT COPYRIGHTED - - This source code is offered for use in the public domain. You may - use, modify or distribute it freely. - - This code is distributed in the hope that it will be useful but - WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY - DISCLAMED. This includes but is not limited to warrenties of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -*/ - /* Only necesary on x86 and amd64 targets */ #if defined(__i386__) || defined(__x86_64__) - #include <windows.h> +#include <stdio.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; +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; + +#define RP_VERSION_V1 0 +#define RP_VERSION_V2 1
static void -do_pseudo_reloc (void* start, void* end, void* base) +do_pseudo_reloc (void* start,void *end,void *base) { - ptrdiff_t reloc_target; - runtime_pseudo_reloc* r; - for (r = (runtime_pseudo_reloc*) start; r < (runtime_pseudo_reloc*) end; r++) + 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++) + { + reloc_target = (ptrdiff_t) base + o->target; + *((DWORD*) reloc_target) += o->addend; + } + 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; - *((ptrdiff_t*) reloc_target) += r->addend; + 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: + *((unsigned char*)reloc_target)=(unsigned char) reldata; + break; + case 16: + *((unsigned short*)reloc_target)=(unsigned short) reldata; + break; + case 32: + *((unsigned int*)reloc_target)=(unsigned int) reldata; + break; +#ifdef _WIN64 + case 64: + *((unsigned long long*)reloc_target)=(unsigned long long) reldata; + break; +#endif + } } }
void _pei386_runtime_relocator () { - do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__, - &__RUNTIME_PSEUDO_RELOC_LIST_END__, - &_image_base__); + do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,&__RUNTIME_PSEUDO_RELOC_LIST_END__,&_image_base__); } #endif