vbox的更動 18997 路徑 trunk/src/VBox/Runtime/r3/init.cpp
- 時間撮記:
- 2009-4-17 下午03:22:25 (16 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/r3/init.cpp
r18989 r18997 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 28 28 * additional information or have any questions. 29 29 */ 30 31 30 32 31 … … 39 38 #else 40 39 # include <unistd.h> 40 # ifndef RT_OS_OS2 41 # include <pthread.h> 42 # endif 43 #endif 44 #ifdef RT_OS_OS2 45 # include <InnoTekLIBC/fork.h> 41 46 #endif 42 47 #include <locale.h> … … 51 56 #include <iprt/string.h> 52 57 #include <iprt/param.h> 53 #include <iprt/process.h>54 58 #if !defined(IN_GUEST) && !defined(RT_NO_GIP) 55 59 # include <iprt/file.h> … … 101 105 * The process identifier of the running process. 102 106 */ 103 RTPROCESS g_ProcessSelf = NIL_RTPROCESS;107 RTPROCESS g_ProcessSelf = NIL_RTPROCESS; 104 108 105 109 /** … … 107 111 */ 108 112 RTPROCPRIORITY g_enmProcessPriority = RTPROCPRIORITY_DEFAULT; 113 114 115 #ifndef RT_OS_WINDOWS 116 /** 117 * Fork callback, child context. 118 */ 119 static void rtR3ForkChildCallback(void) 120 { 121 g_ProcessSelf = getpid(); 122 } 123 #endif /* RT_OS_WINDOWS */ 124 125 #ifdef RT_OS_OS2 126 /** Low-level fork callback for OS/2. */ 127 int rtR3ForkOs2Child(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation) 128 { 129 if (enmOperation == __LIBC_FORK_STAGE_COMPLETION_CHILD) 130 rtR3ForkChildCallback(); 131 return 0; 132 } 133 134 _FORK_CHILD1(0, rtR3ForkOs2Child); 135 #endif /* RT_OS_OS2 */ 109 136 110 137 … … 145 172 } 146 173 147 148 /** 149 * Internal initialization worker. 150 * 151 * @returns IPRT status code. 152 * @param fInitSUPLib Whether to call SUPR3Init. 153 * @param pszProgramPath The program path, NULL if not specified. 154 */ 155 static int rtR3Init(bool fInitSUPLib, const char *pszProgramPath) 156 { 157 int rc = VINF_SUCCESS; 158 /* no entry log flow, because prefixes and thread may freak out. */ 159 160 /* 161 * Do reference counting, only initialize the first time around. 162 * 163 * We are ASSUMING that nobody will be able to race RTR3Init calls when the 164 * first one, the real init, is running (second assertion). 165 */ 166 int32_t cUsers = ASMAtomicIncS32(&g_cUsers); 167 if (cUsers != 1) 168 { 169 AssertMsg(cUsers > 1, ("%d\n", cUsers)); 170 Assert(!g_fInitializing); 171 #if !defined(IN_GUEST) && !defined(RT_NO_GIP) 172 if (fInitSUPLib) 173 SUPR3Init(NULL); 174 #endif 175 if (pszProgramPath) 176 rc = rtR3InitProgramPath(pszProgramPath); 177 return rc; 178 } 179 ASMAtomicWriteBool(&g_fInitializing, true); 174 /** 175 * rtR3Init worker. 176 */ 177 static int rtR3InitBody(bool fInitSUPLib, const char *pszProgramPath) 178 { 179 /* 180 * The Process ID. 181 */ 182 #ifdef _MSC_VER 183 g_ProcessSelf = _getpid(); /* crappy ansi compiler */ 184 #else 185 g_ProcessSelf = getpid(); 186 #endif 180 187 181 188 #if !defined(IN_GUEST) && !defined(RT_NO_GIP) … … 202 209 * without having initialized TLS entries and suchlike. 203 210 */ 204 rc = rtThreadInit(); 205 if (RT_FAILURE(rc)) 206 { 207 AssertMsgFailed(("Failed to initialize threads, rc=%Rrc!\n", rc)); 208 ASMAtomicWriteBool(&g_fInitializing, false); 209 ASMAtomicDecS32(&g_cUsers); 210 return rc; 211 } 211 int rc = rtThreadInit(); 212 AssertMsgRCReturn(rc, ("Failed to initialize threads, rc=%Rrc!\n", rc), rc); 212 213 213 214 #if !defined(IN_GUEST) && !defined(RT_NO_GIP) … … 219 220 */ 220 221 rc = SUPR3Init(NULL); 221 if (RT_FAILURE(rc)) 222 { 223 AssertMsgFailed(("Failed to initializeble the support library, rc=%Rrc!\n", rc)); 224 ASMAtomicWriteBool(&g_fInitializing, false); 225 ASMAtomicDecS32(&g_cUsers); 226 return rc; 227 } 228 } 229 #endif 230 231 /* 232 * The Process ID. 233 */ 234 /* The first call to RTProcSelf lazily initialises the cached pid, and 235 * on posix systems also sets a callback to update the cache on fork. 236 * We just do a dummy call to it here rather than duplicating 237 * initialisation code. */ 238 /** @todo since we do lazy initialisation anyway, do we really also need 239 * to do it explicitly? */ 240 RTProcSelf(); 222 AssertMsgRCReturn(rc, ("Failed to initializeble the support library, rc=%Rrc!\n", rc), rc); 223 } 224 #endif 241 225 242 226 /* … … 244 228 */ 245 229 rc = rtR3InitProgramPath(pszProgramPath); 230 AssertLogRelMsgRCReturn(rc, ("Failed to get executable directory path, rc=%Rrc!\n", rc), rc); 231 232 #if !defined(IN_GUEST) && !defined(RT_NO_GIP) 233 /* 234 * The threading is initialized we can safely sleep a bit if GIP 235 * needs some time to update itself updating. 236 */ 237 if (fInitSUPLib && g_pSUPGlobalInfoPage) 238 { 239 RTThreadSleep(20); 240 RTTimeNanoTS(); 241 } 242 #endif 243 244 /* 245 * Init the program start TSes. 246 * Do that here to be sure that the GIP time was properly updated the 1st time. 247 */ 248 g_u64ProgramStartNanoTS = RTTimeNanoTS(); 249 g_u64ProgramStartMicroTS = g_u64ProgramStartNanoTS / 1000; 250 g_u64ProgramStartMilliTS = g_u64ProgramStartNanoTS / 1000000; 251 252 /* 253 * The remainder cannot easily be undone, so it has to go last. 254 */ 255 256 /* Init C runtime locale. */ 257 setlocale(LC_CTYPE, ""); 258 259 /* Fork callbacks. */ 260 #if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2) 261 rc = pthread_atfork(NULL, NULL, rtR3ForkChildCallback); 262 AssertMsg(rc == 0, ("%d\n", rc)); 263 #endif 264 265 return VINF_SUCCESS; 266 } 267 268 269 /** 270 * Internal initialization worker. 271 * 272 * @returns IPRT status code. 273 * @param fInitSUPLib Whether to call SUPR3Init. 274 * @param pszProgramPath The program path, NULL if not specified. 275 */ 276 static int rtR3Init(bool fInitSUPLib, const char *pszProgramPath) 277 { 278 /* no entry log flow, because prefixes and thread may freak out. */ 279 280 /* 281 * Do reference counting, only initialize the first time around. 282 * 283 * We are ASSUMING that nobody will be able to race RTR3Init calls when the 284 * first one, the real init, is running (second assertion). 285 */ 286 int32_t cUsers = ASMAtomicIncS32(&g_cUsers); 287 if (cUsers != 1) 288 { 289 AssertMsg(cUsers > 1, ("%d\n", cUsers)); 290 Assert(!g_fInitializing); 291 #if !defined(IN_GUEST) && !defined(RT_NO_GIP) 292 if (fInitSUPLib) 293 SUPR3Init(NULL); 294 #endif 295 if (!pszProgramPath) 296 return VINF_SUCCESS; 297 return rtR3InitProgramPath(pszProgramPath); 298 } 299 ASMAtomicWriteBool(&g_fInitializing, true); 300 301 /* 302 * Do the initialization. 303 */ 304 int rc = rtR3InitBody(fInitSUPLib, pszProgramPath); 246 305 if (RT_FAILURE(rc)) 247 306 { 248 AssertLogRelMsgFailed(("Failed to get executable directory path, rc=%Rrc!\n", rc));307 /* failure */ 249 308 ASMAtomicWriteBool(&g_fInitializing, false); 250 309 ASMAtomicDecS32(&g_cUsers); … … 252 311 } 253 312 254 #if !defined(IN_GUEST) && !defined(RT_NO_GIP) 255 /* 256 * The threading is initialized we can safely sleep a bit if GIP 257 * needs some time to update itself updating. 258 */ 259 if (fInitSUPLib && g_pSUPGlobalInfoPage) 260 { 261 RTThreadSleep(20); 262 RTTimeNanoTS(); 263 } 264 #endif 265 266 /* 267 * Init the program start TSes. 268 * Do that here to be sure that the GIP time was properly updated the 1st time. 269 */ 270 g_u64ProgramStartNanoTS = RTTimeNanoTS(); 271 g_u64ProgramStartMicroTS = g_u64ProgramStartNanoTS / 1000; 272 g_u64ProgramStartMilliTS = g_u64ProgramStartNanoTS / 1000000; 273 274 /* 275 * Init C runtime locale 276 */ 277 setlocale(LC_CTYPE, ""); 278 279 /* 280 * More stuff to come? 281 */ 282 313 /* success */ 283 314 LogFlow(("RTR3Init: returns VINF_SUCCESS\n")); 284 315 ASMAtomicWriteBool(&g_fInitializing, false);
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器