From: <ped...@us...> - 2006-10-17 18:48:05
|
Revision: 739 http://svn.sourceforge.net/cegcc/?rev=739&view=rev Author: pedroalves Date: 2006-10-17 11:47:31 -0700 (Tue, 17 Oct 2006) Log Message: ----------- * __dllonexit : Delete. Code merged into ... * atexit.c : ... this. Fix filename comment. Don't include __dllonexit.c. (__atexit_first) : New function. (__atexit_init): New function. (proc_exit_chain) : Delete. (__dllexit) : New function, copied from crt1.c. (__dllonexit) : New function. (_cexit) : Call __dllexit. * Makefile.in (dllcrt1.o, dllcrt2.o, atexit.o) : Remove dependency on __dllonexit.c. * dllcrt1.c : Don't implement a private atexit list on __COREDLL__, since the atexit implementation there is already image private. (DllMainCRTStartup) : Call __atexit_init. Use __atexit_first to get to the private first_atexit. (__dll_exit) : Hide on __COREDLL__. Don't include __dllonexit.c. * crt1.c (MainCRTStartup) : Call __atexit_init. Modified Paths: -------------- trunk/cegcc/src/mingw/ChangeLog.mingw32ce trunk/cegcc/src/mingw/Makefile.in trunk/cegcc/src/mingw/atexit.c trunk/cegcc/src/mingw/crt1.c trunk/cegcc/src/mingw/dllcrt1.c Removed Paths: ------------- trunk/cegcc/src/mingw/__dllonexit.c Modified: trunk/cegcc/src/mingw/ChangeLog.mingw32ce =================================================================== --- trunk/cegcc/src/mingw/ChangeLog.mingw32ce 2006-10-17 17:53:38 UTC (rev 738) +++ trunk/cegcc/src/mingw/ChangeLog.mingw32ce 2006-10-17 18:47:31 UTC (rev 739) @@ -1,5 +1,28 @@ 2006-10-17 Pedro Alves <ped...@po...> + * __dllonexit : Delete. Code merged into ... + * atexit.c : ... this. + Fix filename comment. + Don't include __dllonexit.c. + (__atexit_first) : New function. + (__atexit_init): New function. + (proc_exit_chain) : Delete. + (__dllexit) : New function, copied from crt1.c. + (__dllonexit) : New function. + (_cexit) : Call __dllexit. + * Makefile.in (dllcrt1.o, dllcrt2.o, atexit.o) : Remove + dependency on __dllonexit.c. + * dllcrt1.c : Don't implement a private atexit list on + __COREDLL__, since the atexit implementation there is already + image private. + (DllMainCRTStartup) : Call __atexit_init. Use __atexit_first to + get to the private first_atexit. + (__dll_exit) : Hide on __COREDLL__. + Don't include __dllonexit.c. + * crt1.c (MainCRTStartup) : Call __atexit_init. + +2006-10-17 Pedro Alves <ped...@po...> + * include/fcntl.h : Hide the file. * include/direct.h : Hide the file. Modified: trunk/cegcc/src/mingw/Makefile.in =================================================================== --- trunk/cegcc/src/mingw/Makefile.in 2006-10-17 17:53:38 UTC (rev 738) +++ trunk/cegcc/src/mingw/Makefile.in 2006-10-17 18:47:31 UTC (rev 739) @@ -503,8 +503,8 @@ crtmt.o: crtmt.c crtst.o: crtst.c ctype_old.o: ctype_old.c -dllcrt1.o: dllcrt1.c __dllonexit.c -dllcrt2.o: dllcrt1.c __dllonexit.c +dllcrt1.o: dllcrt1.c +dllcrt2.o: dllcrt1.c dllmain.o: dllmain.c main.o: main.c oldnames.o: oldnames.c @@ -512,7 +512,7 @@ CRT_fp8.o: CRT_fp8.c CRT_fp10.o: CRT_fp10.c abort.o: abort.c -atexit.o: atexit.c __dllonexit.c +atexit.o: atexit.c assert.o: assert.c Makefile: Makefile.in config.status configure Deleted: trunk/cegcc/src/mingw/__dllonexit.c =================================================================== --- trunk/cegcc/src/mingw/__dllonexit.c 2006-10-17 17:53:38 UTC (rev 738) +++ trunk/cegcc/src/mingw/__dllonexit.c 2006-10-17 18:47:31 UTC (rev 739) @@ -1,53 +0,0 @@ -/* - * __dllonexit.c - * This file has no copyright assigned and is placed in the Public Domain. - * This file is a part of the mingw-runtime package. - * No warranty is given; refer to the file DISCLAIMER within the package. - * - * - */ -#include <stdlib.h> -#include <stdio.h> -#include <windows.h> - -#ifdef DEBUG -# define TRACE(FMT, ...) \ - printf ("trace: %s:%d : " FMT, __FILE__, __LINE__, ##__VA_ARGS__) - -# define FIXME(FMT, ...) \ - printf ("fixme: %s:%d : " FMT, __FILE__, __LINE__, ##__VA_ARGS__) -#else -# define TRACE(FMT, ...) do; while (0) -# define FIXME(FMT, ...) do; while (0) -#endif - -p_atexit_fn -__dllonexit(p_atexit_fn func, p_atexit_fn **start, p_atexit_fn **end) -{ - p_atexit_fn *tmp; - int len; - - TRACE("(%p,%p,%p)\n", func, start, end); - - if (!start || !end) - { - FIXME("bad table\n"); - return NULL; - } - - len = (*end - *start); - - TRACE("table start %p-%p, %d entries\n", *start, *end, len); - - if (++len <= 0) - return NULL; - - tmp = (p_atexit_fn *)realloc(*start, len * sizeof(tmp)); - if (!tmp) - return NULL; - *start = tmp; - *end = tmp + len; - tmp[len - 1] = func; - TRACE("new table start %p-%p, %d entries\n", *start, *end, len); - return func; -} Modified: trunk/cegcc/src/mingw/atexit.c =================================================================== --- trunk/cegcc/src/mingw/atexit.c 2006-10-17 17:53:38 UTC (rev 738) +++ trunk/cegcc/src/mingw/atexit.c 2006-10-17 18:47:31 UTC (rev 739) @@ -1,5 +1,5 @@ /* - * dllcrt1.c + * atexit.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. @@ -12,15 +12,26 @@ #include <process.h> #include <windows.h> +//#define DEBUG + +#ifdef DEBUG +# define TRACE(FMT, ...) \ + printf ("trace: %s:%d : " FMT, __FILE__, __LINE__, ##__VA_ARGS__) + +# define FIXME(FMT, ...) \ + printf ("fixme: %s:%d : " FMT, __FILE__, __LINE__, ##__VA_ARGS__) +#else +# define TRACE(FMT, ...) do; while (0) +# define FIXME(FMT, ...) do; while (0) +#endif + typedef void (* p_atexit_fn )(void); static p_atexit_fn* first_atexit; static p_atexit_fn* next_atexit; /* This is based on the function in the Wine project's exit.c */ -static p_atexit_fn __dllonexit (p_atexit_fn, p_atexit_fn**, p_atexit_fn**); +p_atexit_fn __dllonexit (p_atexit_fn, p_atexit_fn**, p_atexit_fn**); -//#define DEBUG - int atexit (p_atexit_fn pfn) { @@ -42,23 +53,88 @@ return ((_onexit_t) __dllonexit ((p_atexit_fn)pfn, &first_atexit, &next_atexit)); } -static void -proc_atexit_chain (void) +p_atexit_fn* __atexit_first(void) { - size_t len = next_atexit - first_atexit; + return first_atexit; +} - p_atexit_fn* pfn = next_atexit; - if (len != 0) +BOOL __atexit_init(void) +{ + /* Initialize atexit table. + 32 is min size required by ANSI */ + first_atexit = (p_atexit_fn*) malloc (32 * sizeof (p_atexit_fn)); + if (first_atexit == NULL ) /* can't allocate memory */ + { +#ifndef __COREDLL__ + errno=ENOMEM; +#endif + return FALSE; + } + *first_atexit = NULL; + next_atexit = first_atexit; + return TRUE; +} + +void __dll_exit(void) +/* Run LIFO terminators registered in private atexit table */ +{ + if ( first_atexit ) { - do - { - --pfn; - (*pfn)(); - } - while (pfn != first_atexit); + p_atexit_fn* __last = next_atexit - 1; + while ( __last >= first_atexit ) + { + if ( *__last != NULL ) + { +#ifdef DEBUG + printf ("%s: Calling exit function 0x%x from 0x%x\n", + __FUNCTION__, (unsigned)(*__last),(unsigned)__last); +#endif + (**__last) (); + } + __last--; + } + free ( first_atexit ) ; + first_atexit = NULL ; } + /* + Make sure output buffers opened by DllMain or + atexit-registered functions are flushed before detaching, + otherwise we can have problems with redirected output. + */ + fflush (NULL); } +p_atexit_fn +__dllonexit(p_atexit_fn func, p_atexit_fn **start, p_atexit_fn **end) +{ + p_atexit_fn *tmp; + int len; + + TRACE("(%p,%p,%p)\n", func, start, end); + + if (!start || !*start || !end || !*end) + { + FIXME("bad table\n"); + return NULL; + } + + len = (*end - *start); + + TRACE("table start %p-%p, %d entries\n", *start, *end, len); + + if (++len <= 0) + return NULL; + + tmp = (p_atexit_fn *)realloc(*start, len * sizeof(tmp)); + if (!tmp) + return NULL; + *start = tmp; + *end = tmp + len; + tmp[len - 1] = func; + TRACE("new table start %p-%p, %d entries\n", *start, *end, len); + return func; +} + static void closeall_streams (void) { @@ -74,7 +150,7 @@ void _cexit (void) { - proc_atexit_chain (); + __dll_exit (); closeall_streams (); } @@ -97,5 +173,3 @@ closeall_streams (); ExitProcess (code); } - -#include "__dllonexit.c" Modified: trunk/cegcc/src/mingw/crt1.c =================================================================== --- trunk/cegcc/src/mingw/crt1.c 2006-10-17 17:53:38 UTC (rev 738) +++ trunk/cegcc/src/mingw/crt1.c 2006-10-17 18:47:31 UTC (rev 739) @@ -41,6 +41,8 @@ #else /* No environ. */ extern int main (int, char **); +/* No atexit on coredll, we must initialize our private version. */ +BOOL __atexit_init(void); #endif /* @@ -244,7 +246,14 @@ asm __volatile__ ("andl $-16, %%esp" : : : "%esp"); #endif +#ifdef __COREDLL__ /* + * Initialize the atexit table. + */ + __atexit_init(); +#endif + + /* * Call the main function. If the user does not supply one * the one in the 'libmingw32.a' library will be linked in, and * that one calls WinMain. See main.c in the 'lib' dir Modified: trunk/cegcc/src/mingw/dllcrt1.c =================================================================== --- trunk/cegcc/src/mingw/dllcrt1.c 2006-10-17 17:53:38 UTC (rev 738) +++ trunk/cegcc/src/mingw/dllcrt1.c 2006-10-17 18:47:31 UTC (rev 739) @@ -34,20 +34,20 @@ #endif typedef void (* p_atexit_fn )(void); + +#ifndef __COREDLL__ static p_atexit_fn* first_atexit; static p_atexit_fn* next_atexit; -static void -__dll_exit (void); - +static void __dll_exit (void); /* This is based on the function in the Wine project's exit.c */ -#ifdef UNDER_CE -static p_atexit_fn __dllonexit (p_atexit_fn, p_atexit_fn**, p_atexit_fn**); -#else p_atexit_fn __dllonexit (p_atexit_fn, p_atexit_fn**, p_atexit_fn**); -#endif +#else /* __COREDLL__ */ +void __dll_exit (void); +BOOL __atexit_init(void); +p_atexit_fn* __atexit_first(void); +#endif /* __COREDLL__ */ - extern BOOL WINAPI DllMain (HANDLE, DWORD, LPVOID); extern void _pei386_runtime_relocator (void); @@ -64,19 +64,22 @@ printf ("%s: DLL_PROCESS_ATTACH (%d)\n", __FUNCTION__); #endif +#ifdef __COREDLL__ + if (!__atexit_init()) + return FALSE; +#else /* Initialize private atexit table for this dll. 32 is min size required by ANSI */ first_atexit = (p_atexit_fn*) malloc (32 * sizeof (p_atexit_fn)); if (first_atexit == NULL ) /* can't allocate memory */ { -#ifndef UNDER_CE errno=ENOMEM; -#endif return FALSE; } *first_atexit = NULL; next_atexit = first_atexit; +#endif /* Adust references to dllimported data (from other DLL's) that have non-zero offsets. */ @@ -121,6 +124,9 @@ #ifdef DEBUG printf ("%s: DLL_PROCESS_DETACH (%d)\n", __FUNCTION__); #endif +#ifdef __COREDLL__ + p_atexit_fn* first_atexit = __atexit_first(); +#endif /* If not attached, return FALSE. Cleanup already done above if failed attachment attempt. */ if (! first_atexit ) @@ -136,6 +142,7 @@ return bRet; } +#ifndef __COREDLL__ static void __dll_exit(void) @@ -201,6 +208,4 @@ return ((_onexit_t) __dllonexit ((p_atexit_fn)pfn, &first_atexit, &next_atexit)); } -#ifdef UNDER_CE -#include "__dllonexit.c" #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |