Changeset 2941
- Timestamp:
- Jan 8, 2007, 12:28:02 AM (19 years ago)
- Location:
- trunk/libc
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/include/klibc/backend.h
r2935 r2941 76 76 * Called when a frontend shuts down. 77 77 * 78 * @returns 0 on success, non-zero on failure.79 78 * @param hmod The handle of the module that's causing the frontend to shut down. 79 * When invoked via _exit() it's 0. 80 80 * @param pvOS OS specific argument. 81 * When invoked via _exit() it's NULL. 81 82 * @param fFlags Termination flags. 82 */ 83 int __libc_Back_term(uintptr_t hmod, void *pvOS, unsigned fFlags); 83 * When invoked via _exit() it's 0. 84 */ 85 void __libc_Back_term(uintptr_t hmod, void *pvOS, unsigned fFlags); 84 86 85 87 /** -
trunk/libc/include/klibc/initterm.h
r2915 r2941 51 51 int __libc_InitDll(uintptr_t hmod, void *pvOS, unsigned fFlags); 52 52 void __libc_TermDll(uintptr_t hmod, void *pvOS, unsigned fFlags); 53 void __libc_TermProcess(void); 53 54 54 55 extern char ** _org_environ; -
trunk/libc/src/kNIX/b_initterm.c
r2937 r2941 153 153 * Called when a frontend shuts down. 154 154 * 155 * @returns 0 on success, non-zero on failure.156 155 * @param hmod The handle of the module that's causing the frontend to shut down. 156 * When invoked via _exit() it's 0. 157 157 * @param pvOS OS specific argument. 158 * When invoked via _exit() it's NULL. 158 159 * @param fFlags Termination flags. 159 */ 160 int __libc_Back_term(uintptr_t hmod, void *pvOS, unsigned fFlags) 161 { 162 /** @todo */ 163 return 0; 164 } 160 * When invoked via _exit() it's 0. 161 */ 162 static void __libc_back_term(uintptr_t hmod, void *pvOS, unsigned fFlags) 163 { 164 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags); 165 166 /** @todo more! */ 167 168 /* 169 * OS specific termination. 170 */ 171 __libc_back_termOS(hmod, pvOS, fFlags); 172 173 LIBCLOG_RETURN_VOID(); 174 } 175 176 177 /** 178 * Terminates the backend. 179 * Called when a frontend shuts down. 180 * 181 * @param hmod The handle of the module that's causing the frontend to shut down. 182 * When invoked via _exit() it's 0. 183 * @param pvOS OS specific argument. 184 * When invoked via _exit() it's NULL. 185 * @param fFlags Termination flags. 186 * When invoked via _exit() it's 0. 187 */ 188 void __libc_Back_term(uintptr_t hmod, void *pvOS, unsigned fFlags) 189 { 190 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags); 191 192 /* 193 * Don't do anything until the last time we're called. 194 */ 195 const int32_t cRefs = __atomic_decrement_s32(&g_ckNIXUsers); 196 if (cRefs == 0) 197 __libc_back_term(hmod, pvOS, fFlags); 198 199 LIBCLOG_RETURN_MSG_VOID("ret void (g_ckNIXUsers=%d)\n", cRefs); 200 } 201 -
trunk/libc/src/kNIX/os2/b_initterm-os2.c
r2937 r2941 103 103 { 104 104 __libc_spmRelease(pSelf); 105 106 /* 107 * If we're residing in a DLL, we will add a dynamic load reference 108 * to the DLL to avoid DosFreeModule trouble caused by our exit list handler. 109 */ 110 if (hmod != 0 && fibGetExeHandle() != hmod) 111 { 112 char szDllName[CCHMAXPATH]; 113 int rc2 = DosQueryModuleName(hmod, sizeof(szDllName), szDllName); 114 if (!rc2) 115 { 116 HMODULE hmodDll = NULLHANDLE; 117 rc2 = DosLoadModule(NULL, 0, szDllName, &hmodDll); 118 LIBC_ASSERTM(rc2 == NO_ERROR, "rc2=%d szDllName='%s'\n", rc, szDllName); 119 } 120 } 105 121 106 122 /* -
trunk/libc/src/kNIX/os2/libcfork.c
r2937 r2941 355 355 pProcess = __libc_spmSelf(1 /* auto init */); 356 356 if (!pProcess) 357 { 358 static char szMsg[] = "LIBC Error: Couldn't register process in shared memory!\r\n"; 359 ULONG ul; 360 LIBC_ASSERTM_FAILED("couldn't register process!\n"); 361 362 DosWrite(2, szMsg, sizeof(szMsg), &ul); 363 while (fExecutable) 364 { 365 LIBCLOG_MSG("Calling DosExit(EXIT_PROCESS, 0xffff)...\n"); 366 DosExit(EXIT_PROCESS, /*fixme*/0xffff); 367 } 368 pTib->tib_pexchain = XcptRegRec.Core.prev_structure; 369 LIBCLOG_RETURN_INT(-1); 370 } 357 __libc_Back_panic(0, NULL, "kLIBC fork: Couldn't register process in shared memory!\r\n"); 371 358 372 359 /* … … 500 487 /* 501 488 * Don't deregister modules which has already been deregistered. 502 * Don't deregister if we're in shutting down the process (waste of time and SPM might already be shut down). 489 * Don't deregister if we're in shutting down the process (waste 490 * of time and SPM will already be shut down). 503 491 */ 504 492 if (pModule->fFlags & __LIBC_FORKMODULE_FLAGS_DEREGISTERED) … … 3184 3172 * Exit process. 3185 3173 */ 3186 __libc_Back_panic(__LIBC_PANIC_NO_SPM_TERM, pvCtx, " LIBC fork: Child aborting fork()! rc=%x\n", rc);3174 __libc_Back_panic(__LIBC_PANIC_NO_SPM_TERM, pvCtx, "kLIBC fork: Child aborting fork()! rc=%x\n", rc); 3187 3175 } 3188 3176 -
trunk/libc/src/libc/libc.def
r2937 r2941 1963 1963 "__std_getrusage" @1959 1964 1964 "__std_ttyname_r" @1960 1965 "___libc_Back_gcArgs" @1961 1966 "___libc_Back_gpapszArgs" @1962 1967 "___libc_Back_init" @1963 1968 "___libc_Back_term" @1964 1969 "___libc_Back_initArgv" @1965 1970 "___libc_Back_fhImport" @1966 1971 "___libc_Back_fhValidate" @1967 1972 "___libc_Back_fsUMask" @1968 1973 "___libc_Back_ioClose" @1969 1974 "___libc_Back_ioControl" @1970 1975 "___libc_Back_ioDuplicate" @1971 1976 "___libc_Back_ioRead" @1972 1977 "___libc_Back_ioSync" @1973 1978 "___libc_Back_ioTTYName" @1974 1979 "___libc_Back_ioWrite" @1975 1980 "___libc_Back_mmanBrk" @1976 1981 "___libc_Back_mmanSBrk" @1977 1982 "___libc_Back_mmanSBrkGetModel" @1978 1983 "___libc_Back_mmanSBrkSetModel" @1979 1984 "___libc_Back_processGetResourceLimit" @1980 1985 "___libc_Back_processSetResourceLimit" @1981 1986 "___libc_FHFree" @1982 1987 "___libc_FHImportFile" @1983 1988 "___libc_Back_initDllLoadException" @1984 1989 "___libc_Back_ioPipe" @1985 1990 "___libc_Back_ldrExeName" @1986 1991 "___libc_Back_miscConsoleSize" @1987 1992 "___libc_Back_processExit" @1988 1993 "___libc_Back_processGetResourceUsage" @1989 1994 "___libc_Back_timeAdjust" @1990 1995 "___libc_Back_timeGet" @1991 1996 "___libc_Back_timeSet" @1992 1997 "___libc_InitDll" @1993 1998 "___libc_InitExe" @1994 1999 "___libc_TermDll" @1995 2000 "___libc_TermProcess" @1996 -
trunk/libc/src/libc/startup/exit.c
r2254 r2941 83 83 * Terminate the CRT and do the real exit. 84 84 */ 85 _ CRT_term();85 __libc_TermProcess(); 86 86 LIBCLOG_MSG("calling _exit(%d)\n", ret); 87 87 _exit(ret); -
trunk/libc/src/libc/startup/initterm.c
r2937 r2941 26 26 27 27 28 /** @page pg_init 29 * 30 */ 31 32 33 /** @page pg_term 34 * 35 */ 36 28 /** @page pg_initterm Initialization and Termination 29 * 30 * kLIBC tries to provides a well defined, portable and hopefully relativly stable 31 * interface for initialization and termination of it's operation. The dll0 and 32 * crt0 objects are considered mere users of this interface. The days where the 33 * __init() function did cool stuff to ESP is over. 34 * 35 * The general event flow is as follows: 36 * -# dll0/crt0 calls __libc_InitDll()/__libc_initExe(). 37 * -# kLIBC initializes the backend (__libc_Back_init()). 38 * -# kLIBC initializes the frontend (__libc_init()). 39 * -# If __libc_InitExe() was invoked, the argument vector is initialized. 40 * -# exit() is called. 41 * 42 * Both the backend and the frontend performs usage accounting most of the work 43 * is done on the first call. Likewise for termination. 44 * 45 */ 37 46 38 47 /******************************************************************************* … … 52 61 /** Kind of CRT usage count. Used to figure out when we should terminate. */ 53 62 static int32_t g_cCrtUsers = 0; 63 /** Times __libc_InitExe was called. This is used to guard against early exit() calls. */ 64 static int32_t g_cExecUsers = 0; 54 65 55 66 … … 80 91 81 92 /** 82 * LIBC termination entry point used by a DLL in the process of being unloaded.83 *84 * This must be exactly paried with a previous __libc_InitDll() call.85 *86 * @param hmod The native module handle of the DLL.87 * @param pvOS OS specific argument.88 * @param fFlags Initialization flags, a combination of the __LIBC_INIT_FLAGS_* \#defines.89 */90 void __libc_TermDll(uintptr_t hmod, void *pvOS, unsigned fFlags)91 {92 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags);93 94 /*95 * Invalidate or free any registered atexit or on_exit callbacks residing in this module96 */97 __libc_atexit_unload(hmod);98 99 /*100 * Do normal LIBC termination.101 */102 __libc_term(hmod, pvOS, fFlags);103 104 LIBCLOG_RETURN_VOID();105 }106 107 108 /**109 93 * LIBC initialization entry point used by an EXE. 110 94 * … … 119 103 { 120 104 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x pArgs=%p\n", hmod, pvOS, fFlags, (void *)pArgs); 105 106 /* Flag that we've been called. */ 107 const int32_t cRefs = __atomic_increment_s32(&g_cExecUsers); (void)cRefs; 108 LIBC_ASSERTM(cRefs == 1, "cRefs=%d\n", cRefs); 121 109 122 110 /* … … 135 123 pArgs->envp = _org_environ; 136 124 137 LIBCLOG_RETURN_ VOID();125 LIBCLOG_RETURN_MSG_VOID("ret void (g_cExecUsers=%d)\n", cRefs); 138 126 } 139 127 … … 196 184 197 185 /** 186 * LIBC termination entry point used by a DLL in the process of being unloaded. 187 * 188 * This must be exactly paired with a previous __libc_InitDll() call. 189 * 190 * @param hmod The native module handle of the DLL. 191 * @param pvOS OS specific argument. 192 * @param fFlags Initialization flags, a combination of the __LIBC_INIT_FLAGS_* \#defines. 193 */ 194 void __libc_TermDll(uintptr_t hmod, void *pvOS, unsigned fFlags) 195 { 196 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags); 197 198 /* 199 * Invalidate or free any registered atexit or on_exit callbacks residing in this module 200 */ 201 __libc_atexit_unload(hmod); 202 203 /* 204 * Do normal LIBC termination. 205 */ 206 __libc_term(hmod, pvOS, fFlags); 207 208 LIBCLOG_RETURN_VOID(); 209 } 210 211 212 /** 213 * LIBC termination entry point used by an 'exit' function. 214 * 215 * This call is 'paired' with the __libc_InitExe call. 216 */ 217 void __libc_TermProcess(void) 218 { 219 LIBCLOG_ENTER("\n"); 220 221 /* 222 * Do normal LIBC termination. 223 */ 224 const int32_t cRefs = __atomic_decrement_s32(&g_cExecUsers); 225 LIBC_ASSERTM(cRefs >= 0, "cRefs=%d\n", cRefs); 226 if (cRefs >= 0) 227 __libc_term(0, NULL, 0); 228 229 LIBCLOG_RETURN_MSG_VOID("ret void (g_cExecUsers=%d)\n", cRefs); 230 } 231 232 233 234 /** 198 235 * LIBC termination worker. 199 236 * … … 201 238 * 202 239 * @param hmod The native module handle of the DLL/EXE. 203 * @param pvOS OS specific argument. 204 * @param fFlags Initialization flags, a combination of the __LIBC_INIT_FLAGS_* \#defines. 240 * When invoked via _exit() it's 0. 241 * @param pvOS OS specific argument. 242 * When invoked via _exit() it's NULL. 243 * @param fFlags Initialization flags, a combination of the __LIBC_INIT_FLAGS_* \#defines. 244 * When invoked via _exit() it's 0. 205 245 */ 206 246 static void __libc_term(uintptr_t hmod, void *pvOS, unsigned fFlags) … … 215 255 */ 216 256 const int32_t cRefs = __atomic_decrement_s32(&g_cCrtUsers); 217 if (cRefs != 1)257 if (cRefs != 0) 218 258 LIBCLOG_RETURN_MSG_VOID("ret void (g_cCrtUsers=%d)\n", cRefs); 219 259 -
trunk/libc/src/libc/startup/os2/dllinit-os2.c
r2717 r2941 4 4 */ 5 5 6 #include < emx/startup.h>6 #include <klibc/initterm.h> 7 7 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_INITTERM 8 8 #include <InnoTekLIBC/logstrict.h> -
trunk/libc/src/libc/startup/os2/x86/crt0.s
r2806 r2941 61 61 mov %esp, %fs:0 62 62 63 andl 0xfffffff0, %esp /* make sure it'saligned. */63 andl $0xfffffff0, %esp /* make sure it's properly aligned. */ 64 64 subl $0x10, %esp 65 65 … … 109 109 pushl %eax /* hmod */ 110 110 call ___libc_InitExe 111 addl $0x 0c, %esp111 addl $0x10, %esp 112 112 113 113 /* -
trunk/libc/src/libc/startup/os2/x86/dll0.s
r2937 r2941 194 194 movl $g_ForkModule, (%esp) 195 195 movb $0, g_fCalledForkRegisterModule 196 call ___libc_Fork RegisterModule196 call ___libc_ForkDeregisterModule 197 197 198 198 dll0_term_done:
Note:
See TracChangeset
for help on using the changeset viewer.