Changeset 32403 in vbox
- Timestamp:
- Sep 10, 2010 1:09:44 PM (14 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r32360 r32403 5412 5412 pszDumpDir = NULL; 5413 5413 5414 int vrc = VERR_GENERAL_FAILURE;5414 int vrc; 5415 5415 if ( pszDumpDir 5416 5416 && !RTDirExists(pszDumpDir)) -
trunk/src/VBox/Runtime/r3/solaris/coredumper-solaris.cpp
r32377 r32403 61 61 * Globals * 62 62 *******************************************************************************/ 63 volatile static uint64_t g_CoreDumpThread = NIL_RTTHREAD; 64 volatile static bool g_fCoreDumpSignalSetup = false; 65 volatile static bool g_fCoreDumpDeliberate = false; 66 volatile static bool g_fCoreDumpInProgress = false; 67 volatile static uint32_t g_fCoreDumpFlags = 0; 68 static char g_szCoreDumpDir[PATH_MAX] = { 0 }; 69 static char g_szCoreDumpFile[PATH_MAX] = { 0 }; 63 volatile static RTNATIVETHREAD volatile g_CoreDumpThread = NIL_RTNATIVETHREAD; 64 volatile static bool volatile g_fCoreDumpSignalSetup = false; 65 volatile static bool volatile g_fCoreDumpDeliberate = false; 66 volatile static uint32_t volatile g_fCoreDumpFlags = 0; 67 static char g_szCoreDumpDir[PATH_MAX] = { 0 }; 68 static char g_szCoreDumpFile[PATH_MAX] = { 0 }; 70 69 71 70 … … 282 281 cb += _128K; 283 282 void *pv = mmap(NULL, cb, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 /* fd */, 0 /* offset */); 284 if (pv )283 if (pv != MAP_FAILED) 285 284 { 286 285 CORELOG((CORELOG_NAME "AllocMemoryArea: memory area of %u bytes allocated.\n", cb)); … … 1152 1151 size_t cbInfoHdrAndData = u64Size < ~(size_t)0 ? u64Size : ~(size_t)0; 1153 1152 void *pvInfoHdr = mmap(NULL, cbInfoHdrAndData, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 /* fd */, 0 /* offset */); 1154 if (pvInfoHdr )1153 if (pvInfoHdr != MAP_FAILED) 1155 1154 { 1156 1155 rc = RTFileRead(hFile, pvInfoHdr, cbInfoHdrAndData, NULL); … … 2123 2122 CORELOG((CORELOG_NAME "SignalHandler Sig=%d pvArg=%p\n", Sig, pvArg)); 2124 2123 2125 int rc = VERR_GENERAL_FAILURE;2126 bool fCallSystemDump = false;2127 if (ASMAtomicUoReadBool(&g_fCoreDumpInProgress) == false)2128 {2129 ASMAtomicWriteBool(&g_fCoreDumpInProgress, true);2130 ASMAtomicWriteU64(&g_CoreDumpThread, (uint64_t)RTThreadSelf());2131 2124 RTNATIVETHREAD hCurNativeThread = RTThreadNativeSelf(); 2125 int rc = VERR_GENERAL_FAILURE; 2126 bool fCallSystemDump = false; 2127 bool fRc; 2128 ASMAtomicCmpXchgHandle(&g_CoreDumpThread, hCurNativeThread, NIL_RTNATIVETHREAD, fRc); 2129 if (fRc) 2130 { 2132 2131 rc = rtCoreDumperTakeDump((ucontext_t *)pvArg); 2133 2134 ASMAtomicWriteU64(&g_CoreDumpThread, NIL_RTTHREAD); 2135 ASMAtomicWriteBool(&g_fCoreDumpInProgress, false); 2132 ASMAtomicWriteHandle(&g_CoreDumpThread, NIL_RTNATIVETHREAD); 2136 2133 2137 2134 if (RT_FAILURE(rc)) … … 2150 2147 * Wait only when the dumping thread is not the one generating this signal. 2151 2148 */ 2152 if (ASMAtomicReadU64(&g_CoreDumpThread) == (uint64_t)RTThreadSelf()) 2149 RTNATIVETHREAD hNativeDumperThread; 2150 ASMAtomicReadHandle(&g_CoreDumpThread, &hNativeDumperThread); 2151 if (hNativeDumperThread == RTThreadNativeSelf()) 2153 2152 { 2154 2153 CORELOGRELSYS((CORELOG_NAME "SignalHandler: Core dumper (thread %u) crashed Sig=%d. Triggering system dump\n", … … 2164 2163 CORELOGRELSYS((CORELOG_NAME "SignalHandler: Core dump already in progress! Waiting a while for completion Sig=%d.\n", Sig)); 2165 2164 int64_t iTimeout = 16000; /* timeout (ms) */ 2166 while (ASMAtomicReadBool(&g_fCoreDumpInProgress) == true)2165 for (;;) 2167 2166 { 2167 ASMAtomicReadHandle(&g_CoreDumpThread, &hNativeDumperThread); 2168 if (hNativeDumperThread == NIL_RTNATIVETHREAD) 2169 break; 2168 2170 RTThreadSleep(200); 2169 2171 iTimeout -= 200; … … 2204 2206 2205 2207 2206 /**2207 * Take a core dump of the current process without terminating it.2208 *2209 * @returns IPRT status code.2210 * @param pszOutputFile Name of the core file. If NULL use the2211 * default naming scheme.2212 * @param fLiveCore When true, the process is not killed after2213 * taking a core. Otherwise it will be killed. This2214 * works in conjuction with the flags set during2215 * RTCoreDumperSetup().2216 */2217 2208 RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile, bool fLiveCore) 2218 2209 { 2210 /** @todo r=bird: No setup should be required for this call and it 2211 * shouldn't change the globals. 2212 * 2213 * Would probably be best to serialize RTCoreDumperTakeDump callers using a 2214 * lazily initialized critsect (see RTOnce) and use different globals to 2215 * communicate with the signal handlers. 2216 * 2217 * Another improvement is to use getcontext() to get the thread context and 2218 * call rtCoreDumperTakeDump directly. Extend rtCoreDumperTakeDump so that 2219 * it takes pszOutputFile as an optional argument. Mask the other fatal + 2220 * SIGUSR2 while doing this. 2221 */ 2222 2219 2223 /* 2220 2224 * Validate input. … … 2246 2250 2247 2251 2248 /**2249 * Sets up and enables the core dumper.2250 *2251 * Installs signal / unhandled exception handlers for catching fatal errors2252 * that should result in a core dump. If you wish to install your own handlers2253 * you should do that after calling this function and make sure you pass on2254 * events you don't handle.2255 *2256 * This can be called multiple times to change the settings without needing to2257 * call RTCoreDumperDisable in between.2258 *2259 * @param pszOutputDir The directory to store the cores in. If NULL2260 * the current directory will be used.2261 * @param pszBaseName Base file name, no directory. If NULL the2262 * dumper will generate an appropriate name.2263 * @param fFlags Setup flags, see RTCOREDUMPER_FLAGS_*.2264 */2265 2252 RTDECL(int) RTCoreDumperSetup(const char *pszOutputDir, uint32_t fFlags) 2266 2253 { … … 2268 2255 * Validate flags. 2269 2256 */ 2270 AssertReturn(fFlags, VERR_INVALID_PARAMETER); 2257 AssertReturn(fFlags, VERR_INVALID_PARAMETER); /** @todo r=bird: Update the function docs to reflect this. It currently reads 2258 * as if RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP was standard behavior. 2259 * The SIGUSR2/RTCOREDUMPER_FLAGS_LIVE_CORE behavior isn't mentioned at all. */ 2271 2260 AssertReturn(!(fFlags & ~( RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP 2272 2261 | RTCOREDUMPER_FLAGS_LIVE_CORE)), 2273 2262 VERR_INVALID_PARAMETER); 2274 2263 2264 /** @todo r=bird: The idea here was that we shouldn't register the handler 2265 * more than once. I.e. skip it if g_fCoreDumpSignalSetup and the 2266 * flags didn't change in any way. The rational/usecase is that that 2267 * allows the user to chain handlers before our SIGSEGV/SIGBUS/SIGTRAP 2268 * core dumping + crashing handler. Since we're registering our stuff 2269 * in Main somewhere it's important that only the first call messes with 2270 * the signal handlers. The front end could for instance do a 2271 * RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP | 2272 * RTCOREDUMPER_FLAGS_LIVE_CORE) call in it's main() before setting up 2273 * it's own SIGBUS/SIGSEGV/SIGTRAP handlers. 2274 * 2275 * Adding the conditional registration via the two flags complicates 2276 * the implementation of this use case. */ 2275 2277 /* 2276 2278 * Install core dump signal handler. … … 2279 2281 RT_ZERO(sigAct); 2280 2282 sigAct.sa_sigaction = &rtCoreDumperSignalHandler; 2281 sigemptyset(&sigAct.sa_mask); 2282 sigAct.sa_flags = SA_RESTART | SA_SIGINFO | SA_NODEFER; 2283 sigemptyset(&sigAct.sa_mask); /** @todo r=bird: We're probably better off blocking all signals here. */ 2284 sigAct.sa_flags = SA_RESTART | SA_SIGINFO | SA_NODEFER; /** @todo r=bird: SA_NODEFER doesn't make sense for SIGUSR2. For the hardware triggered ones, I don't think you can efficiently mask them, but it doesn't hurt playing safe ofc. */ 2283 2285 2284 2286 if (fFlags & RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP) … … 2286 2288 sigaction(SIGSEGV, &sigAct, NULL); 2287 2289 sigaction(SIGBUS, &sigAct, NULL); 2290 /** @todo Add SIGTRAP or release+fatal assertions. */ 2288 2291 } 2289 2292 … … 2303 2306 2304 2307 2305 /**2306 * Disables the core dumper, i.e. undoes what RTCoreDumperSetup did.2307 *2308 * @returns IPRT status code.2309 */2310 2308 RTDECL(int) RTCoreDumperDisable(void) 2311 2309 {
Note:
See TracChangeset
for help on using the changeset viewer.