- Timestamp:
- Aug 27, 2006, 4:07:16 PM (19 years ago)
- Location:
- branches/libc-0.6/src/emx/src/lib/startup
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/libc-0.6/src/emx/src/lib/startup/startup.c
r2021 r2784 1 /* startup.c (emx+gcc) -- Copyright (c) 1990-1998 by Eberhard Mattes */ 1 /** $Id: $ */ 2 /** @file 3 * 4 * kLIBC - CRT init and termination code. 5 * 6 * Copyright (c) 1990-1998 by Eberhard Mattes 7 * Copyright (c) 2004-2006 knut st. osmundsen <bird@innotek.de> 8 * 9 * 10 * This file is part of kLIBC. 11 * 12 * kLIBC is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU Lesser General Public License as published 14 * by the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * kLIBC is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU Lesser General Public License for more details. 21 * 22 * You should have received a copy of the GNU Lesser General Public License 23 * along with kLIBC; if not, write to the Free Software 24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 * 26 */ 2 27 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <fcntl.h> 28 29 30 /******************************************************************************* 31 * Header Files * 32 *******************************************************************************/ 6 33 #include <errno.h> 7 #include <sys/ioctl.h> 8 #include <emx/io.h> 9 #include <emx/syscalls.h> 34 #include <sys/builtin.h> 10 35 #include <emx/startup.h> 11 36 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_INITTERM … … 13 38 14 39 15 /* Initialize the C run-time library. This function is called from 16 crt0.s. */ 17 int _CRT_init (void) 40 /******************************************************************************* 41 * Global Variables * 42 *******************************************************************************/ 43 /** The balance between _CRT_init and _CRT_term calls. */ 44 static volatile int32_t gcCRTReferences = 0; 45 46 47 /** 48 * Initializes the C runtime library. 49 * 50 * A _CRT_init() call should be matched by a _CRT_term() call as we are 51 * keeping a count of the number of C runtime users. 52 * 53 * This function is normally called from _DLL_InitTerm and crt0.s. 54 * 55 * @returns 0 on success. -1 on failure. 56 */ 57 int _CRT_init(void) 18 58 { 19 LIBCLOG_ENTER("\n"); 20 static int startup_flag; 59 LIBCLOG_ENTER("\n"); 21 60 22 /* Protect against multiple calls (for instance, by _CRT_init() in a 23 _DLL_InitTerm() and by the application program's startup code). */ 24 if (startup_flag) 61 /* 62 * On initialize once. 63 */ 64 int32_t cRefs = __atomic_increment_s32(&gcCRTReferences); 65 if (cRefs != 1) 66 LIBCLOG_RETURN_MSG(0, "ret 0 (cRefs=%d)\n", cRefs); 67 68 /* 69 * Call the weak initializers. 70 */ 71 __ctordtorInit1(&__crtinit1__); 72 73 /* 74 * ANSI X3.159-1989, 4.1.3: "The value of errno is zero at program startup..." 75 * 76 * The above code usually sets errno to EBADF, therefore we reset errno 77 * to zero before calling main(). 78 */ 79 errno = 0; 25 80 LIBCLOG_RETURN_INT(0); 26 startup_flag = 1;27 28 /* Initialize streams etc. if required. */29 __ctordtorInit1 (&__crtinit1__);30 31 /* ANSI X3.159-1989, 4.1.3: "The value of errno is zero at program32 startup..."33 34 The above code usually sets errno to EBADF, therefore we reset35 errno to zero before calling main(). */36 errno = 0;37 38 LIBCLOG_RETURN_INT(0);39 81 } 40 82 83 84 /** 85 * Terminates the C runtime library. 86 * 87 * A _CRT_term() call must be paired with a _CRT_init() call as we're 88 * counting the number of C runtime users. 89 * 90 * This function is normally called from _DLL_InitTerm and crt0.s. 91 */ 92 void _CRT_term(void) 93 { 94 LIBCLOG_ENTER("\n"); 95 int32_t cRefs = __atomic_decrement_s32(&gcCRTReferences); 96 if (cRefs == 0) 97 { 98 /* 99 * Call the weak terminators. 100 */ 101 __ctordtorTerm1(&__crtexit1__); 102 } 103 else if (cRefs < 0) 104 LIBCLOG_ERROR_RETURN_MSG_VOID("cRefs=%d\n", cRefs); 105 LIBCLOG_RETURN_VOID(); 106 } 41 107 42 108 … … 118 184 * @todo update this with fork and performance changes! 119 185 */ 186
Note:
See TracChangeset
for help on using the changeset viewer.