Changeset 2936
- Timestamp:
- Dec 31, 2006, 3:54:20 AM (19 years ago)
- Location:
- trunk/libc/src
- Files:
-
- 3 added
- 1 deleted
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/src/glibc/sysdeps/os2/__spawni.c
r2935 r2936 75 75 pRAction->fdSaved = -1; 76 76 pRAction->fSavedCoE = -1; 77 if ( !__libc_FH(fdToSave))77 if (__libc_Back_fhValidate(fdToSave)) 78 78 return 0; /* no such handle. */ 79 79 … … 219 219 { 220 220 case spawn_do_close: 221 if (!__libc_FH(pAction->action.close_action.fd)) 222 rc = -1; 221 rc = __libc_Back_fhValidate(pAction->action.close_action.fd); 223 222 break; 224 223 case spawn_do_open: … … 226 225 break; 227 226 case spawn_do_dup2: 228 if (!__libc_FH(pAction->action.dup2_action.fd)) 229 rc = -1; 227 rc = __libc_Back_fhValidate(pAction->action.dup2_action.fd); 230 228 if (pAction->action.dup2_action.newfd == -1) 231 229 cOpens++; … … 276 274 continue; 277 275 /* if not closed or not being freed we cannot use it. */ 278 if (!fClosed && __libc_FH(fdMin))276 if (!fClosed && !__libc_Back_fhValidate(fdMin)) 279 277 continue; 280 278 /* it's either closed or free */ -
trunk/libc/src/kNIX/Makefile.kmk
r2935 r2936 35 35 libc_kNIX_INCS = $(PATH_LIBC_SRC)/kNIX 36 36 libc_kNIX_SOURCES = \ 37 $(PATH_LIBC_SRC)/kNIX/b_initterm.c \ 37 38 $(PATH_LIBC_SRC)/kNIX/b_fhImport.c \ 38 39 $(PATH_LIBC_SRC)/kNIX/b_fhValidate.c \ … … 79 80 80 81 libc_kNIX_SOURCES.os2 = \ 82 $(PATH_LIBC_SRC)/kNIX/os2/b_initterm-os2.c \ 83 $(PATH_LIBC_SRC)/kNIX/os2/b_initDllLoadException.c \ 84 $(PATH_LIBC_SRC)/kNIX/os2/__libc_back_envInit.c \ 85 $(PATH_LIBC_SRC)/kNIX/os2/386/__libc_back_envInitAsm.s \ 81 86 $(PATH_LIBC_SRC)/kNIX/os2/b_dir.c \ 82 87 $(PATH_LIBC_SRC)/kNIX/os2/b_fsDirChangeRoot.c \ … … 168 173 $(PATH_LIBC_SRC)/kNIX/os2/tcpipver43.c \ 169 174 $(PATH_LIBC_SRC)/kNIX/os2/timebomb.c \ 170 $(PATH_LIBC_SRC)/kNIX/os2/386/appinit.s \171 175 $(PATH_LIBC_SRC)/kNIX/os2/386/thunk0.s \ 172 176 $(PATH_LIBC_SRC)/kNIX/os2/386/thunk1.s \ 173 177 $(PATH_LIBC_SRC)/kNIX/os2/386/unwind.s \ 174 $(PATH_LIBC_SRC)/kNIX/os2/386/__init_environ.s \175 178 $(PATH_LIBC_SRC)/kNIX/os2/_os2_bad.c \ 176 179 $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \ -
trunk/libc/src/kNIX/b_initterm.c
r2929 r2936 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 3 * 4 * kNIX - Process init.4 * kNIX - Process Init/Term. 5 5 * 6 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net> … … 25 25 */ 26 26 27 28 27 /******************************************************************************* 29 28 * Header Files * 30 29 *******************************************************************************/ 30 #include "kNIX.h" 31 31 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_INITTERM 32 #include "kNIX.h"32 #include <klibc/logstrict.h> 33 33 34 /******************************************************************************* 35 * Global Variables * 36 *******************************************************************************/ 37 /** Number of backend users. */ 38 static int32_t volatile g_ckNIXUsers = 0; 34 39 35 40 … … 46 51 * @param fFlags Initialization flags, a combination of the __LIBC_INIT_FLAGS_* \#defines. 47 52 */ 48 static int __libc_ init(uintptr_t hmod, void *pvOS, unsigned fFlags)53 static int __libc_back_init(uintptr_t hmod, void *pvOS, unsigned fFlags) 49 54 { 50 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvO s, fFlags);55 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags); 51 56 int rc; 52 57 53 58 /* 54 * Do OS specific initialization of the process.59 * First up is the fast info blocks / cached process data. 55 60 */ 56 #ifdef __NT__ 57 #endif 58 #ifdef __OS2__ 59 rc = __libc_spmInit(); 60 if (rc) 61 LIBCLOG_ERROR_RETURN_INT(rc); 62 #endif 63 64 /* 65 * Initialize the thread database entering this thread as the first one. 66 */ 67 rc = __libc_back_threadInit() 61 rc = __libc_back_fibInit(0); 68 62 if (!rc) 69 63 { 70 64 /* 71 * Init the other65 * Do OS specific initialization of the process. 72 66 */ 73 74 rc = __libc_back_fsInit(); 67 rc = __libc_back_initOS(hmod, pvOS, fFlags); 75 68 if (!rc) 76 69 { 70 /* 71 * Initialize all backend mutexes residing in parts that doesn't have 72 * special initializers. 73 */ 74 75 76 if (!rc) 77 rc = __libc_back_fsInit(); 78 if (!rc) 79 { 80 /* 81 * Init file handles. 82 */ 83 rc = __libc_fhInit(); 84 if (!rc) 85 { 86 /* 87 * Init signals 88 */ 89 rc = __libc_back_signalInit(); 90 if (!rc) 91 { 92 /* 93 * Setup environment (org_environ and _STD(environ)) 94 */ 95 rc = __libc_back_envInit(); 96 if (!rc) 97 { 98 /* more? */ 99 LIBCLOG_RETURN_INT(0); 100 } 101 //__libc_back_signalTerm(); 102 } 103 104 //__libc_fhTerm(); 105 } 106 107 //__libc_back_fsTerm(); 108 } 109 __libc_back_termOS(hmod, pvOS, fFlags); 77 110 } 78 79 111 } 80 112 81 82 /* 83 * Initialize all backend mutexes residing in parts that doesn't have 84 * special initializers. 85 */ 86 87 88 if (__libc_back_fsInit()) 89 { 90 LIBC_ASSERTM_FAILED("__libc_back_fsInit() failed\n"); 91 return -1; 92 } 93 94 /* 95 * Init file handles. 96 */ 97 rc = __libc_fhInit(); 98 if (rc) 99 { 100 LIBC_ASSERTM_FAILED("__libc_fhInit() failed\n"); 101 return -1; 102 } 103 104 /* 105 * Init signals 106 */ 107 rc = __libc_back_signalInit(); 108 if (rc) 109 { 110 LIBC_ASSERTM_FAILED("__libc_back_signalInit() failed\n"); 111 return -1; 112 } 113 114 /* 115 * Setup environment (org_environ and _STD(environ)) 116 */ 117 rc = _sys_init_environ(fibGetEnv()); 118 if (rc) 119 { 120 LIBC_ASSERTM_FAILED("_sys_init_environ() failed\n"); 121 return -1; 122 } 123 124 125 LIBCLOG_RETURN_INT(0); 113 LIBCLOG_ERROR_RETURN_INT(rc); 126 114 } 127 115 … … 135 123 * @param pvUser OS specific argument. 136 124 */ 137 int __libc_Back_init(uintptr_t hmod, unsigned fFlags, void *pvUser)125 int __libc_Back_init(uintptr_t hmod, void *pvOS, unsigned fFlags) 138 126 { 139 LIBCLOG_ENTER("hmod=%tx fFlags=%#x pvUser=%p\n", hmod, fFlags, pvUser);127 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags); 140 128 141 142 143 LIBCLOG_RETURN_INT(0); 129 /* 130 * Only initialize it once. 131 * 132 * We currently IGNORE the posibility that two thread might be racing here and 133 * the loser begin able to call into LIBC while it's begin initialized. 134 */ 135 const int32_t cRefs = __atomic_increment_s32(&g_ckNIXUsers); 136 if (cRefs != 1) 137 LIBCLOG_RETURN_MSG(0, "ret 0 (g_ckNIXUsers=%d)\n", cRefs); 138 int rc = __libc_back_init(hmod, pvOS, fFlags); 139 if (!rc) 140 LIBCLOG_RETURN_INT(0); 141 __atomic_decrement_s32(&g_ckNIXUsers); 142 LIBCLOG_ERROR_RETURN_INT(rc); 144 143 } 145 144 146 -
trunk/libc/src/kNIX/kNIX.h
r2935 r2936 43 43 #endif 44 44 #include <errno.h> 45 #define _osmajor __osminor 46 #define _osminor __osminor 47 #include <stdlib.h> 48 #undef _osmajor 49 #undef _osminor 45 50 #include <io.h> 46 51 #include <malloc.h> … … 261 266 262 267 263 /** @group Init Functions268 /** @group Init & Term Functions 264 269 * @{ */ 265 extern void __init(int fFlags); 266 extern int __init_dll(int fFlags, unsigned long hmod); 267 extern void /*volatile*/_sys_init_ret(void *stack) __attribute__((__noreturn__)); 268 extern int _sys_init_environ(const char *pszEnv); 269 extern void _sys_init_largefileio(void); 270 extern int __libc_fhInit(void); 270 extern int __libc_back_initOS(uintptr_t hmod, void *pvOS, unsigned fFlags); 271 extern void __libc_back_termOS(uintptr_t hmod, void *pvOS, unsigned fFlags); 272 extern int __libc_fhInit(void); 273 extern int __libc_back_envInit(void); 271 274 /** @} */ 272 275 -
trunk/libc/src/kNIX/os2/386/__libc_back_envInitAsm.s
r2929 r2936 4 4 * 5 5 * Copyright (c) 2003 InnoTek Systemberatung GmbH 6 * Author: knut st. osmundsen <bird-src spam@anduin.net>6 * Author: knut st. osmundsen <bird-src-spam@anduin.net> 7 7 * 8 8 * … … 32 32 * Initialize __org_environ and _STD(environ). 33 33 * 34 * @cproto int __ init_dll_env(const char *pszEnv);34 * @cproto int __libc_back_envInitAsm(const char *pszzEnv); 35 35 * @sketch Assumes large amounts of stack so we can construct the a reverse array there. 36 36 * 37 37 */ 38 .globl __ sys_init_environ39 __ sys_init_environ:38 .globl ___libc_back_envInitAsm 39 ___libc_back_envInitAsm: 40 40 pushl %ebp 41 41 movl %esp, %ebp -
trunk/libc/src/kNIX/os2/kNIX-os2.h
r2929 r2936 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 3 * -
trunk/libc/src/kNIX/os2/syscalls.h
r2929 r2936 46 46 extern void __init(int fFlags); 47 47 extern int __init_dll(int fFlags, unsigned long hmod); 48 extern void /*volatile*/_sys_init_ret(void *stack) __attribute__((__noreturn__));49 extern int _sys_init_environ(const char *pszEnv);50 extern void _sys_init_largefileio(void);51 extern int __libc_fhInit(void);52 48 /** @} */ 53 49 -
trunk/libc/src/libc/libc.def
r2935 r2936 249 249 "___ibitmap" @262 250 250 ; dead "___imphandle" @263 251 "___init" @264252 "___init_app" @265253 "___init_dll" @266251 ; dead "___init" @264 252 ; dead "___init_app" @265 253 ; dead "___init_dll" @266 254 254 ; dead "___ioctl1" @267 255 255 ; dead "___ioctl2" @268 … … 1958 1958 "__std_nanf" @1956 1959 1959 "__std_nanl" @1957 1960 1960 1961 ; new stuff 0.7 1961 "_ gOS2FileOps" @19581962 "__libc_back_envInitAsm" @1958 1962 1963 "__std_adjtime" @1959 1963 1964 "__std_getrusage" @1960 -
trunk/libc/src/libc/startup/Makefile.kmk
r2901 r2936 38 38 $(PATH_LIBC_SRC)/libc/startup/exit.c \ 39 39 $(PATH_LIBC_SRC)/libc/startup/initterm.c \ 40 $(PATH_LIBC_SRC)/libc/startup/startup.c \ 40 41 $(PATH_LIBC_SRC)/libc/startup/_exit.c 41 42 -
trunk/libc/src/libc/startup/initterm.c
r2901 r2936 44 44 #include <klibc/backend.h> 45 45 #include <klibc/atexit.h> 46 #include < sys/builtin.h>46 #include <klibc/umalloc.h> 47 47 48 48 … … 153 153 154 154 /* 155 * Only initialize it once. 155 * Process the flags. 156 */ 157 __libc_HeapVote(fFlags & __LIBC_INIT_FLAGS_MEM_HIGH); 158 /*if (fFlags & __LIBC_INIT_FLAGS_NO_UNIX) 159 __libc_gfNoUnix = 1;*/ 160 161 /* 162 * The remaining bits are only done once. 156 163 * 157 164 * We currently IGNORE the posibility that two thread might be racing here and … … 175 182 */ 176 183 184 /* weak initializers. */ 185 __ctordtorTerm1(&__crtinit1__); 177 186 178 187 LIBCLOG_RETURN_INT(0); 179 188 } 189 190 __atomic_decrement_s32(&g_cCrtUsers); 180 191 LIBCLOG_ERROR_RETURN_INT(rc); 181 192 } … … 212 223 */ 213 224 225 /* weak terminators */ 226 __ctordtorTerm1(&__crtexit1__); 214 227 215 228 /* -
trunk/libc/src/libc/startup/os2/x86/dll0.s
r2806 r2936 222 222 223 223 /* 224 * Call __ libc_InitDllException and let it decide what to do.224 * Call ___libc_Back_initDllLoadException and let it decide what to do. 225 225 * It returns 0 if we should continue search the exception handler chain. 226 226 * It returns -1 if we resume execution. … … 231 231 pushl 0x0c(%ebp) 232 232 pushl 0x08(%ebp) 233 call ___libc_ InitDllException233 call ___libc_Back_initDllLoadException 234 234 orl %eax, %eax 235 235 jz dll0_xcpt_return -
trunk/libc/src/libc/startup/startup.c
r2785 r2936 2 2 /** @file 3 3 * 4 * kLIBC - CRT init and termination code.4 * kLIBC - VAC/MSC initialization and termination compatability. 5 5 * 6 * Copyright (c) 1990-1998 by Eberhard Mattes 7 * Copyright (c) 2004-2006 knut st. osmundsen <bird@innotek.de> 6 * Copyright (c) 2004-2006 knut st. osmundsen <bird-src-spam@anduin.net> 8 7 * 9 8 * … … 26 25 */ 27 26 28 29 30 /******************************************************************************* 31 * Header Files * 32 *******************************************************************************/ 27 #include <klibc/initterm.h> 33 28 #include <errno.h> 34 #include <sys/builtin.h> 35 #include <emx/startup.h> 36 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_INITTERM 37 #include <InnoTekLIBC/logstrict.h> 38 39 40 /******************************************************************************* 41 * Global Variables * 42 *******************************************************************************/ 43 /** The balance between _CRT_init and _CRT_term calls. */ 44 static volatile int32_t gcCRTReferences = 0; 29 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_INITTERM 30 #include <klibc/logstrict.h> 45 31 46 32 … … 48 34 * Initializes the C runtime library. 49 35 * 50 * A _CRT_init() call should be matched by a _CRT_term() call as we are51 * 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 36 * @returns 0 on success. -1 on failure. 37 * @remark VAC/MSC compatability stub (OS/2). 56 38 */ 57 int _CRT_init 39 int _CRT_init(void) 58 40 { 59 LIBCLOG_ENTER("\n"); 60 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__); 41 LIBCLOG_ENTER("\n"); 72 42 73 43 /* … … 77 47 * to zero before calling main(). 78 48 */ 79 errno = 0; 80 LIBCLOG_RETURN_INT(0); 49 errno = 0; 50 51 LIBCLOG_RETURN_INT(0); 81 52 } 82 53 … … 85 56 * Terminates the C runtime library. 86 57 * 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. 58 * @remark VAC/MSC compatability stub (OS/2). 91 59 */ 92 60 void _CRT_term(void) 93 61 { 94 62 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 63 LIBCLOG_RETURN_VOID(); 106 64 } 107 65 108 109 /** @page Startup Startup110 *111 * Quick description of how we startup a process which modules uses LIBC.112 *113 * The load first loads the DLLs of the process, calling their _DLL_InitTerm114 * entrypoints in order of dependencies. If you're using dynamic LIBC this115 * will be initiated first of the LIBC-based modules.116 *117 * LIBCxy.DLL:118 * - dll0.s gets control and calls __init_dll in sys/__initdll.c119 * - __init_dll calls __libc_HeapVote() to do the heap voting.120 * - __init_dll initiates the _osminor and _osmajor globals.121 * - __init_dll initiates _sys_gcbVirtualAddressLimit global.122 * - __init_dll initiates _sys_pid and _sys_ppid globals.123 * - __init_dll creates _sys_heap_fmutex, _sys_gmtxHimem and __libc_gmtxExec.124 * - __init_dll then initiates __libc_gpTLS with an allocated TLS ULONG.125 * The thread structure it self isn't initialized untill it's actually126 * referenced, and when it is there is static structure for the first127 * thread needing its per thread area.128 * - __init_dll calls _sys_init_environ() which initializes environ and _org_environ.129 * - _sys_init_environ() will call _hmalloc() thus initiating the high heap.130 * - __init_dll calls __libc_spmSelf() which checks initiates SPM and gets131 * any inherited properties.132 * - __init_dll calls _sys_init_largefileio() which checks for LFN APIs.133 * - __init_dll calls __libc_fhInit() which initiates filehandle table.134 * - __libc_fhInit() will call _hmalloc() and a number of OS/2 APIs135 * to figure out what handles was inherited.136 * - __init_dll checks for LIBC_HOOK_DLLS and calls __libc_back_hooksInit()137 * to process it if it is present in the environment.138 * - __init_dll then intializes _sys_clock0_ms with the current MS count.139 * - dll0.s calls _DLL_InitTerm in startup/dllinit.c.140 * - _DLL_InitTerm calls _CRT_init() in startup/startup.c to initialize the CRT.141 * - _CRT_init calls init_files() to initialize the file handle tables.142 * - _CRT_init then call all the crt init functions in __crtinit1__.143 * - _DLL_InitTerm calls __ctordtorInit() to initate any exception structures and144 * construct static C++ objects.145 * - dll0.s then returns to DOSCALL1.DLL and back to the kernel.146 *147 * Your.DLL:148 * - dll0.s gets control and calls __init_dll() in sys/__initdll.c149 * - __init_dll calls __libc_HeapVote() to do the heap voting.150 * - __init_dll then returns since already done during LIBCxy.DLL init.151 * - dll0.s calls _DLL_InitTerm in startup/dllinit.c.152 * - _DLL_InitTerm calls _CRT_init() in startup/startup.c to initialize the CRT.153 * - _CRT_init return at once since already done during LIBCxy.DLL init.154 * - _DLL_InitTerm calls __ctordtorInit() to initate any exception structures and155 * construct static C++ objects in _this_ DLL.156 * - dll0.s then returns to DOSCALL1.DLL and back to the kernel.157 *158 * Your.exe:159 * - crt0.s gets control and calls ___init_app in sys/386/appinit.s which forwards160 * the call to __init() in sys/__init.c.161 * - __init() calls __init_dll() to do common initiation.162 * - __init_dll calls __libc_HeapVote() to do the heap voting.163 * - __init_dll then returns since already done during LIBCxy.DLL init.164 * - __init() parse the commandline to figure out how much stack to use for array165 * and the argument copy.166 * - __init() the allocates the stack space space, adding an exception handler struct167 * and main() callframe.168 * - __init() parse the commandline creating argv and it's strings using the169 * allocated stack space.170 * - __init() calls __libc_spmInheritFree() to release the inherit data (shared)171 * associated with the current process.172 * - __init() installs the exception handler.173 * - __init() set the signal focus.174 * - __init() then 'returns' thru the hack called ___init_ret in sys/386/appinit.s175 * - crt0.s now gets control back with esp pointing to a complete callframe for main().176 * - crt0.s calls _CRT_init() in startup/startup.c to initialize the CRT which returns177 * immediately since since already done during LIBCxy.DLL init.178 * - crt0.s the calls main().179 * - crt0.s then calls exit() with the return value of main().180 * - exit() will call all the registered at_exit functions.181 * - exit() will call DosExit with the exit code and terminate the process.182 *183 * @todo update this with file handle changes!184 * @todo update this with fork and performance changes!185 */186
Note:
See TracChangeset
for help on using the changeset viewer.