Changeset 2937
- Timestamp:
- Jan 3, 2007, 3:03:12 AM (19 years ago)
- Location:
- trunk/libc
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/include/InnoTekLIBC/sharedpm.h
r2819 r2937 653 653 654 654 /** 655 * Initializes the shared process management for this process.656 *657 * This might actually initialize the SPM globally too if this is the658 * first process using it.659 *660 * @returns 0 on success.661 * @returns Negative error code (errno.h) on failure.662 */663 int __libc_spmInit(void);664 665 /**666 655 * Gets the current process. 667 656 * … … 669 658 * @returns NULL and errno on failure. 670 659 * @remark For this too __libc_spmRelease() must be called when done. 671 */ 672 __LIBC_PSPMPROCESS __libc_spmSelf(void); 660 * @param fAutoInit Set if it's ok to automatically initialize SPM. 661 */ 662 __LIBC_PSPMPROCESS __libc_spmSelf(int fAutoInit); 673 663 674 664 /** -
trunk/libc/src/kNIX/Makefile.kmk
r2936 r2937 36 36 libc_kNIX_SOURCES = \ 37 37 $(PATH_LIBC_SRC)/kNIX/b_initterm.c \ 38 $(PATH_LIBC_SRC)/kNIX/b_initArgv.c \ 38 39 $(PATH_LIBC_SRC)/kNIX/b_fhImport.c \ 39 40 $(PATH_LIBC_SRC)/kNIX/b_fhValidate.c \ … … 178 179 $(PATH_LIBC_SRC)/kNIX/os2/_os2_bad.c \ 179 180 $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \ 180 $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c 181 $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c \ 182 $(PATH_LIBC_SRC)/kNIX/os2/__select.c 181 183 TODO= \ 182 184 $(PATH_LIBC_SRC)/kNIX/os2/__init.c \ -
trunk/libc/src/kNIX/b_initterm.c
r2936 r2937 134 134 */ 135 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); 136 int rc; 137 if (cRefs == 1) 138 rc = __libc_back_init(hmod, pvOS, fFlags); 139 else 140 /* (Might later add initialization code for every module here.) */ 141 rc = 0; 139 142 if (!rc) 140 143 LIBCLOG_RETURN_INT(0); 144 145 /* failure */ 141 146 __atomic_decrement_s32(&g_ckNIXUsers); 142 147 LIBCLOG_ERROR_RETURN_INT(rc); 143 148 } 144 149 150 151 /** 152 * Terminates the backend. 153 * Called when a frontend shuts down. 154 * 155 * @returns 0 on success, non-zero on failure. 156 * @param hmod The handle of the module that's causing the frontend to shut down. 157 * @param pvOS OS specific argument. 158 * @param fFlags Termination flags. 159 */ 160 int __libc_Back_term(uintptr_t hmod, void *pvOS, unsigned fFlags) 161 { 162 /** @todo */ 163 return 0; 164 } -
trunk/libc/src/kNIX/os2/b_initterm-os2.c
r2936 r2937 70 70 { 71 71 LIBCLOG_ENTER("hmod=%tx pvOS=%p fFlags=%#x\n", hmod, pvOS, fFlags); 72 int rc = __libc_spmInit(); 72 /* 73 * Initialize _osmajor and _osminor. 74 */ 75 ULONG aul[2] = {0, 0}; 76 DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, &aul[0], sizeof(aul)); 77 _osminor = (unsigned char)aul[1]; 78 _osmajor = (unsigned char)aul[0]; 79 80 /* 81 * Check for high memory (>512MB) support. 82 */ 83 ULONG ul; 84 __libc_back_gcbVirtualAddressLimit = 512 * 1024 * 1024; 85 if ( !DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ul, sizeof(ul)) 86 && ul > 512 87 && ( (_osmajor == 20 && _osminor >= 40) 88 || _osmajor > 20 /* yeah, sure! */) ) 89 __libc_back_gcbVirtualAddressLimit = ul * 1024*1024; 90 91 /* 92 * Initialize TLS. 93 */ 94 int rc = DosAllocThreadLocalMemory(1, (PULONG*)(void*)&__libc_gpTLS); 73 95 if (!rc) 74 96 { 75 /* 76 * Initialize _osmajor and _osminor. 77 */ 78 ULONG aul[2] = {0, 0}; 79 DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, &aul[0], sizeof(aul)); 80 _osminor = (unsigned char)aul[1]; 81 _osmajor = (unsigned char)aul[0]; 82 83 /* 84 * Check for high memory (>512MB) support. 85 */ 86 ULONG ul; 87 __libc_back_gcbVirtualAddressLimit = 512 * 1024 * 1024; 88 if ( !DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ul, sizeof(ul)) 89 && ul > 512 90 && ( (_osmajor == 20 && _osminor >= 40) 91 || _osmajor > 20 /* yeah, sure! */) ) 92 __libc_back_gcbVirtualAddressLimit = ul * 1024*1024; 93 94 /* 95 * Initialize TLS. 96 */ 97 rc = DosAllocThreadLocalMemory(1, (PULONG*)(void*)&__libc_gpTLS); 97 rc = _fmutex_create2(&__libc_gmtxExec, 0, "LIBC SYS Exec Mutex"); 98 98 if (!rc) 99 99 { 100 rc = _fmutex_create2(&__libc_gmtxExec, 0, "LIBC SYS Exec Mutex"); 101 if (!rc) 100 /* Ensure that SPM is initialized. */ 101 __LIBC_PSPMPROCESS pSelf = __libc_spmSelf(1 /* auto init */); 102 if (pSelf) 102 103 { 103 __LIBC_PSPMPROCESS pSelf = __libc_spmSelf(); 104 if (!pSelf) 105 { 106 /* 107 * Done here. 108 */ 109 LIBCLOG_RETURN_INT(0); 110 } 111 else 112 { 113 LIBC_ASSERTM_FAILED("__libc_spmSelf() failed\n"); 114 rc = -ESRCH; 115 } 116 _fmutex_close(&__libc_gmtxExec); 104 __libc_spmRelease(pSelf); 105 106 /* 107 * Done here. 108 */ 109 LIBCLOG_RETURN_INT(0); 117 110 } 118 DosFreeThreadLocalMemory((PULONG)__libc_gpTLS); 119 __libc_gpTLS = NULL; 120 } 121 else 122 LIBC_ASSERTM_FAILED("DosAllocThreadLocalMemory() failed. rc=%d\n", rc); 123 } 111 else 112 { 113 LIBC_ASSERTM_FAILED("__libc_spmSelf() failed\n"); 114 rc = -ESRCH; 115 } 116 _fmutex_close(&__libc_gmtxExec); 117 } 118 DosFreeThreadLocalMemory((PULONG)__libc_gpTLS); 119 __libc_gpTLS = NULL; 120 } 121 else 122 LIBC_ASSERTM_FAILED("DosAllocThreadLocalMemory() failed. rc=%d\n", rc); 123 /** @todo terminate SPM */ 124 124 LIBCLOG_ERROR_RETURN_INT(rc); 125 125 } … … 142 142 DosFreeThreadLocalMemory((PULONG)__libc_gpTLS); 143 143 __libc_gpTLS = NULL; 144 145 /* 146 * Terminate SPM. 147 */ 148 /** @todo terminate SPM */ 144 149 145 150 LIBCLOG_RETURN_VOID(); -
trunk/libc/src/kNIX/os2/libcfork.c
r2929 r2937 350 350 __libc_Timebomb(); 351 351 #endif 352 353 352 /* 354 353 * Find the SPM process. 355 354 */ 356 pProcess = __libc_spmSelf( );355 pProcess = __libc_spmSelf(1 /* auto init */); 357 356 if (!pProcess) 358 357 { … … 417 416 { 418 417 pTib->tib_pexchain = XcptRegRec.Core.prev_structure; 418 __libc_spmRelease(pProcess); 419 419 LIBCLOG_RETURN_INT(0); 420 420 } … … 425 425 */ 426 426 pForkHandle = forkChlOpenHandle(pProcess->pvForkHandle); 427 __libc_spmRelease(pProcess); 427 428 if (!pForkHandle) 428 429 { … … 499 500 /* 500 501 * Don't deregister modules which has already been deregistered. 501 * Don't deregister if we're in shutting down the process (waste of time and 502 * SPM might already be shut down). 502 * Don't deregister if we're in shutting down the process (waste of time and SPM might already be shut down). 503 503 */ 504 504 if (pModule->fFlags & __LIBC_FORKMODULE_FLAGS_DEREGISTERED) … … 521 521 * Find the SPM process. 522 522 */ 523 __LIBC_PSPMPROCESS pProcess = __libc_spmSelf( );523 __LIBC_PSPMPROCESS pProcess = __libc_spmSelf(0 /* don't auto init */); 524 524 if (!pProcess) 525 525 { 526 526 pTib->tib_pexchain = XcptRegRec.Core.prev_structure; 527 LIBC_ASSERTM_FAILED("can't find the process! weird!\n"); 527 LIBC_ASSERTM_FAILED("can't find the process! weird!\n"); /* DLL termination order might be screwed up... */ 528 528 LIBCLOG_RETURN_VOID(); 529 529 } … … 559 559 pModule->fFlags |= __LIBC_FORKMODULE_FLAGS_DEREGISTERED; 560 560 561 __libc_spmRelease(pProcess); 561 562 pTib->tib_pexchain = XcptRegRec.Core.prev_structure; 562 563 LIBCLOG_RETURN_VOID(); … … 1566 1567 */ 1567 1568 forkBthCloseHandle(pForkHandle, __LIBC_FORK_CTX_CHILD); 1568 __LIBC_PSPMPROCESS pProcess = __libc_spmSelf( );1569 __LIBC_PSPMPROCESS pProcess = __libc_spmSelf(0 /* no init */); 1569 1570 LIBC_ASSERTM(pProcess, "No self process!!!\n"); 1570 1571 pProcess->pvForkHandle = NULL; 1571 1572 /* 1573 * The return here will go back to the inline assmebly which called us in forkChlDoFork() 1572 __libc_spmRelease(pProcess); 1573 1574 1575 /* 1576 * The return here will go back to the inline assembly which called us in forkChlDoFork() 1574 1577 * and restore the stack pointer to the __libc_Back_processFork() and jump to the fork_ret 1575 1578 * label in __libc_Back_processFork(). … … 2217 2220 { 2218 2221 __LIBC_PFORKMODULE pModules; 2219 __LIBC_PSPMPROCESS pProcessSelf = __libc_spmSelf( );2222 __LIBC_PSPMPROCESS pProcessSelf = __libc_spmSelf(0 /* no init */); 2220 2223 if (pProcessSelf) 2221 2224 { -
trunk/libc/src/kNIX/os2/sharedpm.c
r2929 r2937 93 93 static int spmRequestMutex(__LIBC_PSPMXCPTREGREC pRegRec); 94 94 static int spmReleaseMutex(__LIBC_PSPMXCPTREGREC pRegRec); 95 static int spmInit(__LIBC_PSPMXCPTREGREC pRegRec); 95 96 static VOID APIENTRY spmExitList(ULONG ulReason); 96 97 static void spmCleanup(void); … … 337 338 * 338 339 * @returns Pointer to the current process. 339 * @returns NULL and errnoon failure.340 * @returns NULL on failure. 340 341 * @remark For this too __libc_spmRelease() must be called when done. 341 */ 342 __LIBC_PSPMPROCESS __libc_spmSelf(void) 343 { 344 LIBCLOG_ENTER("\n"); 342 * @param fAutoInit Set if it's ok to automatically initialize SPM. 343 */ 344 __LIBC_PSPMPROCESS __libc_spmSelf(int fAutoInit) 345 { 346 LIBCLOG_ENTER("fAutoInit=%d\n", fAutoInit); 345 347 __LIBC_PSPMPROCESS pProcess; 346 348 … … 350 352 351 353 /* 352 * Check if we've already registered (we're allways registred).353 * If we have we'll simply return.354 * Read the cached variable. 355 * If the caller permits automatic initialization, we'll give it a shot. 354 356 */ 355 357 pProcess = gpSPMSelf; 356 if (!pProcess) 357 { 358 __LIBC_SPMXCPTREGREC RegRec; 359 if (spmRequestMutexErrno(&RegRec)) 360 LIBCLOG_RETURN_P(NULL); 361 if (!gpSPMSelf) 362 pProcess = gpSPMSelf; 358 if (!pProcess && fAutoInit) 359 { 360 /* Don't try initialize unless we're in a virgin state. */ 361 if (!gpSPMHdr && !gcNesting) 362 { 363 __LIBC_SPMXCPTREGREC RegRec; 364 int rc = spmInit(&RegRec); 365 if (!rc) 366 { 367 pProcess = gpSPMSelf; 368 spmReleaseMutex(&RegRec); 369 LIBC_ASSERT(pProcess); 370 } 371 else 372 LIBCLOG_ERROR("rc=%d\n", rc); 373 } 363 374 else 364 { 365 PTIB pTib; 366 PPIB pPib; 367 PLINFOSEG pLIS = GETLINFOSEG(); 368 FS_VAR() 369 FS_SAVE_LOAD(); 370 DosGetInfoBlocks(&pTib, &pPib); 371 pProcess = spmRegisterSelf(pPib->pib_ulpid, pPib->pib_ulppid, pLIS->sgCurrent); 372 FS_RESTORE(); 373 } 374 spmReleaseMutex(&RegRec); 375 LIBCLOG_MSG("fAutoInit=%d gpSPMHdr=%p gcNesting=%d\n", fAutoInit, gpSPMHdr, gcNesting); 375 376 } 376 377 … … 1966 1967 { 1967 1968 /* 1968 * Before exec we must ensure that we're opened 1969 * for the logic below to work.1969 * Before exec we must ensure that we're opened for the logic below to work. 1970 * (This is probably not necessary, but it doesn't hurt.) 1970 1971 */ 1971 1972 case __LIBC_FORK_OP_EXEC_CHILD: 1972 1973 if (!gpSPMSelf) 1973 __libc_spmSelf( );1974 __libc_spmSelf(1 /* auto init */); 1974 1975 LIBCLOG_RETURN_INT(0); 1975 1976 … … 2044 2045 2045 2046 /** 2046 * Requests the shared mutex semphore and checks that we're 2047 * successfully initialized.2047 * Requests the shared mutex semphore and checks that we're successfully initialized. 2048 * 2048 2049 * @returns 0 on success. 2049 2050 * @returns Negative error code (errno.h) on failure. … … 2077 2078 2078 2079 /* 2079 * Check if init atied.2080 * Check if initiated. 2080 2081 */ 2081 2082 if (!ghmtxSPM || !gpSPMHdr) 2082 2083 { 2083 LIBC_ASSERTM_FAILED("not initialized! \n");2084 LIBC_ASSERTM_FAILED("not initialized! rc=%d\n", rc); 2084 2085 DosUnsetExceptionHandler(&pRegRec->Core); 2085 2086 FS_RESTORE(); … … 2177 2178 * first process using it. 2178 2179 * 2179 * @returns 0 on success .2180 * @returns 0 on success, mutex owned. 2180 2181 * @returns Negative error code (errno.h) on failure. 2181 */ 2182 int __libc_spmInit(void) 2182 * 2183 * @param pRegRec Same as with spmRequestMutex(). 2184 */ 2185 static int spmInit(__LIBC_PSPMXCPTREGREC pRegRec) 2183 2186 { 2184 2187 LIBCLOG_ENTER("\n"); … … 2211 2214 2212 2215 /* 2216 * Install the exception handler. 2217 */ 2218 FS_SAVE_LOAD(); 2219 pRegRec->Core.prev_structure = (void *)~0; 2220 pRegRec->Core.ExceptionHandler = spmXcptHandler; 2221 DosSetExceptionHandler(&pRegRec->Core); 2222 2223 /* 2224 * Check stack. 2225 */ 2226 if (spmRequestMutexStackChecker()) 2227 { 2228 DosUnsetExceptionHandler(&pRegRec->Core); 2229 FS_RESTORE(); 2230 LIBC_ASSERTM_FAILED("Too little stack left!\n"); 2231 LIBCLOG_RETURN_INT(-EFAULT); 2232 } 2233 2234 /* 2213 2235 * Get current process id and parent process id 2214 2236 * and install the exception handler. … … 2219 2241 * Open or create mutex. 2220 2242 */ 2221 FS_SAVE_LOAD();2222 2243 rc = DosOpenMutexSem((PCSZ)SPM_MUTEX_NAME, &ghmtxSPM); 2223 2244 if (rc) … … 2230 2251 if (rc2) 2231 2252 { 2253 DosUnsetExceptionHandler(&pRegRec->Core); 2232 2254 FS_RESTORE(); 2233 2255 /* too bad, can create it for some reason. */ … … 2335 2357 */ 2336 2358 rc = DosExitList(0x9800 | EXLST_ADD, spmExitList); 2359 LIBC_ASSERTM(!rc, "DosExitList failed with rc=%d\n", rc); 2337 2360 FS_RESTORE(); 2338 DosReleaseMutexSem(ghmtxSPM);2339 DosExitMustComplete(&ul);2340 LIBC_ASSERTM(!rc, "DosExitList failed with rc=%d\n", rc);2341 2361 LIBCLOG_RETURN_INT(0); 2342 2362 } … … 2356 2376 gpSPMHdr = NULL; 2357 2377 gpSPMSelf = NULL; 2378 DosUnsetExceptionHandler(&pRegRec->Core); 2358 2379 FS_RESTORE(); 2359 2380 rc = -__libc_back_native2errno(rc); -
trunk/libc/src/libc/libc.def
r2936 r2937 1953 1953 "__std_getdirents" @1951 1954 1954 "___libc_Back_ioFileControlStandard" @1952 1955 "___libc_Back_termDll" @19531955 ; dead "___libc_Back_termDll" @1953 1956 1956 "___libc_ForkDeregisterModule" @1954 1957 1957 "__std_nan" @1955 … … 1960 1960 1961 1961 ; new stuff 0.7 1962 "__libc_back_envInitAsm" @1958 1963 "__std_adjtime" @1959 1964 "__std_getrusage" @1960 1965 "__std_ttyname_r" @1961 1962 "__std_adjtime" @1958 1963 "__std_getrusage" @1959 1964 "__std_ttyname_r" @1960 -
trunk/libc/src/libc/startup/initterm.c
r2936 r2937 160 160 161 161 /* 162 * The remaining bits are only done once.163 *164 * We currently IGNORE the posibility that two thread might be racing here and165 * the loser begin able to call into LIBC while it's begin initialized.166 */167 const int32_t cRefs = __atomic_increment_s32(&g_cCrtUsers);168 if (cRefs != 1)169 LIBCLOG_RETURN_MSG(0, "ret 0 (g_cCrtUsers=%d)\n", cRefs);170 171 /*172 162 * The backend must be initialized first. 173 163 */ … … 175 165 if (!rc) 176 166 { 167 /* 168 * The remaining bits are only done once. 169 * 170 * We currently IGNORE the posibility that two thread might be racing here and 171 * the loser begin able to call into LIBC while it's begin initialized. 172 */ 173 const int32_t cRefs = __atomic_increment_s32(&g_cCrtUsers); 174 if (cRefs != 1) 175 LIBCLOG_RETURN_MSG(0, "ret 0 (g_cCrtUsers=%d)\n", cRefs); 176 177 177 /* 178 178 * Init the frontend. … … 182 182 */ 183 183 184 /* weak initializers. */ 185 __ctordtorTerm1(&__crtinit1__); 186 187 LIBCLOG_RETURN_INT(0); 184 { 185 /* weak initializers. */ 186 __ctordtorTerm1(&__crtinit1__); 187 188 LIBCLOG_RETURN_INT(0); 189 } 190 __atomic_decrement_s32(&g_cCrtUsers); 188 191 } 189 192 190 __atomic_decrement_s32(&g_cCrtUsers);191 193 LIBCLOG_ERROR_RETURN_INT(rc); 192 194 } -
trunk/libc/src/libc/startup/os2/x86/dll0.s
r2936 r2937 69 69 * What are we in for? 70 70 */ 71 movl 8(%ebp), %eax71 movl 0xc(%ebp), %eax 72 72 orl %eax, %eax 73 73 je dll0_init
Note:
See TracChangeset
for help on using the changeset viewer.