From 42963b39c4e35dc73faf31b7df395f42ff7bafb8 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Fri, 11 Mar 2005 09:37:29 +0000 Subject: [PATCH] - Moved data out of stdlib_data.c and into the code that references or initializes it. - The stdlib constructor now performs the CPU/FPU compatibility test. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14879 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/GNUmakefile.68k | 3 +- library/GNUmakefile.os4 | 3 +- library/changes | 5 ++ library/smakefile | 5 +- library/stdio_file_init.c | 6 ++- library/stdio_growfdtable.c | 8 +-- library/stdio_growiobtable.c | 8 +-- library/stdio_init_exit.c | 14 ++++- library/stdlib_data.c | 62 ---------------------- library/stdlib_headers.h | 5 +- library/stdlib_init_exit.c | 5 +- library/stdlib_main.c | 31 +++++++++-- library/stdlib_stack_usage.c | 94 ++++++++++++++++----------------- library/stdlib_stackextension.c | 7 ++- library/stdlib_stackoverflow.c | 6 ++- 15 files changed, 116 insertions(+), 146 deletions(-) delete mode 100644 library/stdlib_data.c diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 66c69d5..1292812 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.39 2005-03-10 09:55:03 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.40 2005-03-11 09:37:27 obarthel Exp $ # # :ts=8 # @@ -280,7 +280,6 @@ C_LIB = \ stdlib_checkdetach.o \ stdlib_constructor.o \ stdlib_constructor_begin.o \ - stdlib_data.o \ stdlib_default_pool_size.o \ stdlib_default_puddle_size.o \ stdlib_destructor.o \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index e4ea4bf..cf4b66e 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.40 2005-03-10 09:55:03 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.41 2005-03-11 09:37:28 obarthel Exp $ # # :ts=8 # @@ -279,7 +279,6 @@ C_LIB = \ stdlib_checkdetach.o \ stdlib_constructor.o \ stdlib_constructor_begin.o \ - stdlib_data.o \ stdlib_default_pool_size.o \ stdlib_default_puddle_size.o \ stdlib_destructor.o \ diff --git a/library/changes b/library/changes index 22d279b..9b1e4cd 100644 --- a/library/changes +++ b/library/changes @@ -54,6 +54,11 @@ - Added S_IREAD, S_IWRITE and S_IEXEC aliases to . +- Moved data out of stdlib_data.c and into the code that references + or initializes it. + +- The stdlib constructor now performs the CPU/FPU compatibility test. + c.lib 1.189 (5.3.2005) diff --git a/library/smakefile b/library/smakefile index b825a40..0396680 100644 --- a/library/smakefile +++ b/library/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.31 2005-03-10 09:55:03 obarthel Exp $ +# $Id: smakefile,v 1.32 2005-03-11 09:37:29 obarthel Exp $ # # :ts=8 # @@ -382,7 +382,6 @@ STDLIB_OBJ = \ stdlib_checkdetach.o \ stdlib_constructor_begin.o \ stdlib_constructor.o \ - stdlib_data.o \ stdlib_default_pool_size.o \ stdlib_default_puddle_size.o \ stdlib_destructor.o \ @@ -652,8 +651,6 @@ stdlib_swapstack.o : stdlib_swapstack.asm stdio_fdhookentry.o : stdio_fdhookentry.c stdlib_mem_debug.h -stdlib_data.o : stdlib_data.c stdlib_mem_debug.h - stdio_openiob.o : stdio_openiob.c stdlib_mem_debug.h stdlib_alloca.o : stdlib_alloca.c stdlib_mem_debug.h diff --git a/library/stdio_file_init.c b/library/stdio_file_init.c index 7335806..52a1c43 100644 --- a/library/stdio_file_init.c +++ b/library/stdio_file_init.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_file_init.c,v 1.1 2005-03-07 11:16:43 obarthel Exp $ + * $Id: stdio_file_init.c,v 1.2 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -66,6 +66,10 @@ static BPTR input; /****************************************************************************/ +struct WBStartup * __WBenchMsg; + +/****************************************************************************/ + CLIB_DESTRUCTOR(workbench_exit) { ENTER(); diff --git a/library/stdio_growfdtable.c b/library/stdio_growfdtable.c index 4513cc8..151383f 100644 --- a/library/stdio_growfdtable.c +++ b/library/stdio_growfdtable.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_growfdtable.c,v 1.5 2005-03-09 10:48:59 obarthel Exp $ + * $Id: stdio_growfdtable.c,v 1.6 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -43,12 +43,6 @@ /****************************************************************************/ -/* The file descriptor table. */ -struct fd ** __fd; -int __num_fd; - -/****************************************************************************/ - int __grow_fd_table(int max_fd) { diff --git a/library/stdio_growiobtable.c b/library/stdio_growiobtable.c index 8cd7c27..87e3447 100644 --- a/library/stdio_growiobtable.c +++ b/library/stdio_growiobtable.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_growiobtable.c,v 1.5 2005-03-09 10:48:59 obarthel Exp $ + * $Id: stdio_growiobtable.c,v 1.6 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -43,12 +43,6 @@ /****************************************************************************/ -/* The file handle table. */ -struct iob ** __iob; -int __num_iob; - -/****************************************************************************/ - int __grow_iob_table(int max_iob) { diff --git a/library/stdio_init_exit.c b/library/stdio_init_exit.c index f7aa56f..e51fdbd 100644 --- a/library/stdio_init_exit.c +++ b/library/stdio_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_init_exit.c,v 1.25 2005-03-09 16:56:05 obarthel Exp $ + * $Id: stdio_init_exit.c,v 1.26 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -47,6 +47,18 @@ /****************************************************************************/ +/* The file handle table. */ +struct iob ** __iob; +int __num_iob; + +/****************************************************************************/ + +/* The file descriptor table. */ +struct fd ** __fd; +int __num_fd; + +/****************************************************************************/ + void __close_all_files(void) { diff --git a/library/stdlib_data.c b/library/stdlib_data.c deleted file mode 100644 index 00f4877..0000000 --- a/library/stdlib_data.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * $Id: stdlib_data.c,v 1.6 2005-03-07 11:16:43 obarthel Exp $ - * - * :ts=4 - * - * Portable ISO 'C' (1994) runtime library for the Amiga computer - * Copyright (c) 2002-2005 by Olaf Barthel - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Neither the name of Olaf Barthel nor the names of contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _STDLIB_MEM_DEBUG_H -#include "stdlib_mem_debug.h" -#endif /* _STDLIB_MEM_DEBUG_H */ - -/****************************************************************************/ - -#ifndef _STDLIB_HEADERS_H -#include "stdlib_headers.h" -#endif /* _STDLIB_HEADERS_H */ - -/****************************************************************************/ - -struct WBStartup * __WBenchMsg; - -/****************************************************************************/ - -BOOL __stack_overflow; -ULONG __stk_maxsize; -ULONG __stk_extensions; - -/****************************************************************************/ - -struct Library * __UtilityBase; - -/****************************************************************************/ - -#if defined(__amigaos4__) -struct UtilityIFace * __IUtility; -#endif /* __amigaos4__ */ diff --git a/library/stdlib_headers.h b/library/stdlib_headers.h index d30ea47..d9dd97f 100644 --- a/library/stdlib_headers.h +++ b/library/stdlib_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_headers.h,v 1.13 2005-03-07 11:16:43 obarthel Exp $ + * $Id: stdlib_headers.h,v 1.14 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -221,7 +221,6 @@ extern unsigned int NOCOMMON (* __get_default_stack_size)(void); /****************************************************************************/ extern unsigned int NOCOMMON __stack_size; -extern BOOL NOCOMMON __stack_overflow; extern UBYTE * NOCOMMON __stk_limit; extern UBYTE * NOCOMMON __base; @@ -229,9 +228,7 @@ extern UBYTE * NOCOMMON __base; extern ULONG NOCOMMON __stk_argbytes; extern ULONG NOCOMMON __stk_safezone; -extern ULONG NOCOMMON __stk_maxsize; extern ULONG NOCOMMON __stk_size; -extern ULONG NOCOMMON __stk_extensions; extern ULONG NOCOMMON __stk_minframe; /****************************************************************************/ diff --git a/library/stdlib_init_exit.c b/library/stdlib_init_exit.c index 67c5d3e..48515db 100644 --- a/library/stdlib_init_exit.c +++ b/library/stdlib_init_exit.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_init_exit.c,v 1.6 2005-03-07 11:16:43 obarthel Exp $ + * $Id: stdlib_init_exit.c,v 1.7 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -76,6 +76,9 @@ __stdlib_init(void) ENTER(); + if(__machine_test() < 0) + goto out; + if(__WBenchMsg == NULL) { const size_t program_name_size = 256; diff --git a/library/stdlib_main.c b/library/stdlib_main.c index 9f52bc8..2f0196c 100644 --- a/library/stdlib_main.c +++ b/library/stdlib_main.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_main.c,v 1.13 2005-03-07 14:04:09 obarthel Exp $ + * $Id: stdlib_main.c,v 1.14 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -64,6 +64,11 @@ extern int main(int arg_c,char ** arg_v); /****************************************************************************/ +/* This will be set to TRUE in case a stack overflow was detected. */ +BOOL __stack_overflow; + +/****************************************************************************/ + /* The SAS/C profiling hooks can be used to track call chains. Neat trick, but not always necessary. Don't enable this unless you know what you're doing... */ @@ -119,7 +124,6 @@ call_main(void) __stk_init, __stdio_init, __stdio_file_init, - __machine_test, __math_init, __socket_init, __arg_init, @@ -214,7 +218,11 @@ call_main(void) } /* If necessary, print stack size usage information. */ - __stack_usage_exit(); + #ifndef NDEBUG + { + __stack_usage_exit(); + } + #endif /* NDEBUG */ SHOWMSG("invoking the destructors"); @@ -300,6 +308,17 @@ get_stack_size(void) /****************************************************************************/ +/* The global utility.library base, as required by clib2. */ +struct Library * __UtilityBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) +struct UtilityIFace * __IUtility; +#endif /* __amigaos4__ */ + +/****************************************************************************/ + int _main(void) { @@ -460,7 +479,11 @@ _main(void) stk->stk_Pointer = (APTR)(stk->stk_Upper - 32); /* If necessary, set up for stack size usage measurement. */ - __stack_usage_init(stk); + #ifndef NDEBUG + { + __stack_usage_init(stk); + } + #endif /* NDEBUG */ return_code = __swap_stack_and_call(stk,(APTR)call_main); diff --git a/library/stdlib_stack_usage.c b/library/stdlib_stack_usage.c index d95501b..b504b91 100644 --- a/library/stdlib_stack_usage.c +++ b/library/stdlib_stack_usage.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_stack_usage.c,v 1.2 2005-01-02 09:07:18 obarthel Exp $ + * $Id: stdlib_stack_usage.c,v 1.3 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -31,6 +31,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NDEBUG + +/****************************************************************************/ + #include "stdlib_headers.h" /****************************************************************************/ @@ -39,12 +43,8 @@ /****************************************************************************/ -#ifndef NDEBUG - static struct StackSwapStruct stack_swap_struct; -#endif /* NDEBUG */ - /****************************************************************************/ #define STACK_FILL_COOKIE 0xA1 @@ -52,20 +52,16 @@ static struct StackSwapStruct stack_swap_struct; /****************************************************************************/ void -__stack_usage_init(struct StackSwapStruct * UNUSED stk) +__stack_usage_init(struct StackSwapStruct * stk) { - #ifndef NDEBUG + if(stk != NULL) { - if(stk != NULL) - { - size_t stack_size = ((ULONG)stk->stk_Upper - (ULONG)stk->stk_Lower); + size_t stack_size = ((ULONG)stk->stk_Upper - (ULONG)stk->stk_Lower); - memset(stk->stk_Lower,STACK_FILL_COOKIE,stack_size); + memset(stk->stk_Lower,STACK_FILL_COOKIE,stack_size); - stack_swap_struct = (*stk); - } + stack_swap_struct = (*stk); } - #endif /* NDEBUG */ } /****************************************************************************/ @@ -73,45 +69,45 @@ __stack_usage_init(struct StackSwapStruct * UNUSED stk) void __stack_usage_exit(void) { - #ifndef NDEBUG + if(stack_swap_struct.stk_Lower != NULL && stack_swap_struct.stk_Upper != 0) { - if(stack_swap_struct.stk_Lower != NULL && stack_swap_struct.stk_Upper != 0) + const UBYTE * m = (const UBYTE *)stack_swap_struct.stk_Lower; + size_t stack_size = ((ULONG)stack_swap_struct.stk_Upper - (ULONG)stack_swap_struct.stk_Lower); + size_t total,i; + + total = 0; + + /* Figure out how much of the stack was used by checking + if the fill pattern was overwritten. */ + for(i = 0 ; i < stack_size ; i++) { - const UBYTE * m = (const UBYTE *)stack_swap_struct.stk_Lower; - size_t stack_size = ((ULONG)stack_swap_struct.stk_Upper - (ULONG)stack_swap_struct.stk_Lower); - size_t total,i; + /* Strangely, the first long word is always trashed, + even if the stack doesn't grow down this far... */ + if(i > sizeof(LONG) && m[i] != STACK_FILL_COOKIE) + break; - total = 0; - - /* Figure out how much of the stack was used by checking - if the fill pattern was overwritten. */ - for(i = 0 ; i < stack_size ; i++) - { - /* Strangely, the first long word is always trashed, - even if the stack doesn't grow down this far... */ - if(i > sizeof(LONG) && m[i] != STACK_FILL_COOKIE) - break; - - total++; - } - - kprintf("[%s] total amount of stack space used = %ld bytes\n", - __program_name,stack_size - total); - - stack_swap_struct.stk_Lower = NULL; - stack_swap_struct.stk_Upper = 0; + total++; } - if(__stk_maxsize == 0) - { - kprintf("[%s] no stack extension was performed\n", - __program_name); - } - else - { - kprintf("[%s] maximum size of extended stack = %ld bytes, stack was extended %ld times\n", - __program_name,__stk_maxsize,__stk_extensions); - } + kprintf("[%s] total amount of stack space used = %ld bytes\n", + __program_name,stack_size - total); + + stack_swap_struct.stk_Lower = NULL; + stack_swap_struct.stk_Upper = 0; + } + + if(__stk_maxsize == 0) + { + kprintf("[%s] no stack extension was performed\n", + __program_name); + } + else + { + kprintf("[%s] maximum size of extended stack = %ld bytes, stack was extended %ld times\n", + __program_name,__stk_maxsize,__stk_extensions); } - #endif /* NDEBUG */ } + +/****************************************************************************/ + +#endif /* NDEBUG */ diff --git a/library/stdlib_stackextension.c b/library/stdlib_stackextension.c index 0a79e0e..be0db89 100644 --- a/library/stdlib_stackextension.c +++ b/library/stdlib_stackextension.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_stackextension.c,v 1.6 2005-02-27 21:58:21 obarthel Exp $ + * $Id: stdlib_stackextension.c,v 1.7 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -65,6 +65,11 @@ static struct stackframe * __stk_spare; /* spare stackframes */ /****************************************************************************/ +ULONG __stk_extensions; /* number of stack extensions performed */ +ULONG __stk_maxsize; /* maximum amount of memory allocated for stack extension */ + +/****************************************************************************/ + #if defined(SMALL_DATA) #define A4(x) "a4@(" #x ":W)" #elif defined(SMALL_DATA32) diff --git a/library/stdlib_stackoverflow.c b/library/stdlib_stackoverflow.c index 51452a6..d2b9d70 100644 --- a/library/stdlib_stackoverflow.c +++ b/library/stdlib_stackoverflow.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_stackoverflow.c,v 1.2 2005-01-02 09:07:19 obarthel Exp $ + * $Id: stdlib_stackoverflow.c,v 1.3 2005-03-11 09:37:29 obarthel Exp $ * * :ts=4 * @@ -37,6 +37,10 @@ /****************************************************************************/ +extern BOOL NOCOMMON __stack_overflow; + +/****************************************************************************/ + #if defined(__GNUC__) /****************************************************************************/