int permissions;
FileIOResult status;
#if !defined(_WIN32)
+ int ret;
struct stat stbuf;
#endif
goto bail;
}
permissions = stbuf.st_mode;
- Posix_Unlink(tempPath);
+
+ /* Do a "cleanup" unlink in case some previous process left a temp file around */
+ ret = Posix_Unlink(tempPath);
+ if (ret != 0 && errno != ENOENT) { /* ENOENT is expected, file should not exist */
+ Log("%s: Failed to unlink temporary file, errno: %d\n",
+ __FUNCTION__, errno);
+ /* Fall through; FileIO_Create will report the actual error */
+ }
#endif
status = FileIO_Create(tempFD, tempPath,
FILEIO_ACCESS_READ | FILEIO_ACCESS_WRITE,
- FILEIO_OPEN_CREATE, permissions);
+ FILEIO_OPEN_CREATE_SAFE, permissions);
if (!FileIO_IsSuccess(status)) {
- Log("%s: Failed to create temporary file\n", __FUNCTION__);
- ASSERT_BUG_DEBUGONLY(615124, errno != EBUSY);
- ASSERT(!vmx86_server); // For APD, hosted can fall-back and write directly
+ Log("%s: Failed to create temporary file, err: %d\n", __FUNCTION__,
+ Err_Errno());
goto bail;
}
return FILEIO_SUCCESS;
bail:
+ ASSERT(!FileIO_IsSuccess(status));
if (FileIO_IsValid(tempFD)) {
FileIO_Close(tempFD);
#if defined(_WIN32)
File_UnlinkIfExists(tempPath);
#else
- Posix_Unlink(tempPath);
+ ret = Posix_Unlink(tempPath);
+ if (ret != 0) {
+ Log("%s: Failed to clean up temporary file, errno: %d\n",
+ __FUNCTION__, errno);
+ }
+ ASSERT(ret == 0);
#endif
}
Unicode_Free(tempPath);
return id0Out;
}
-
-/*
- *----------------------------------------------------------------------
- *
- * CPUIDSummary_SafeToUseMC0_CTL --
- *
- * Determines whether it is safe to write to the MCE control
- * register MC0_CTL.
- * Known safe: P4, All AMD, all family 6 model > 0x1a, except core/atom
- * Don't know: P2, P3
- *
- * Results:
- * True iff it is known to be safe.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-static INLINE Bool
-CPUIDSummary_SafeToUseMC0_CTL(CPUIDSummary* cpuidSummary)
-{
- CPUIDRegs id0;
-
- CPUIDSummary_RegsFromCpuid0(&cpuidSummary->id0, &id0);
- return CPUID_IsVendorAMD(&id0) ||
- (CPUID_IsVendorIntel(&id0) &&
- (CPUID_FAMILY_IS_PENTIUM4(cpuidSummary->id1.version) ||
- (CPUID_FAMILY_IS_P6(cpuidSummary->id1.version) &&
- (CPUID_EFFECTIVE_MODEL(cpuidSummary->id1.version) ==
- CPUID_MODEL_NEHALEM_1A ||
- CPUID_EFFECTIVE_MODEL(cpuidSummary->id1.version) >=
- CPUID_MODEL_NEHALEM_1E))));
-}
-
-
-/* The following functions return the number of cores per package
- and set *numThreadsPerCore to the number of hardware threads per core. */
-static INLINE uint32
-CPUIDSummary_VIACoresPerPackage(CPUIDSummary *cpuid,
- uint32 *numThreadsPerCore)
-{
- (void) cpuid;
- *numThreadsPerCore = 1;
- return 1;
-}
-
-static INLINE uint32
-CPUIDSummary_AMDCoresPerPackage(CPUIDSummary *cpuid,
- uint32 *numThreadsPerCore)
-{
- uint32 version = cpuid->id1.version, numEntries = cpuid->id80.numEntries;
- *numThreadsPerCore = 1;
- return CPUID_FAMILY_IS_K8STAR(version) && numEntries >= 0x80000008 ?
- CPUID_AMDCoresPerPackage(cpuid->id88.ecx) : 1;
-}
-
-static INLINE uint32
-CPUIDSummary_IntelCoresPerPackage(CPUIDSummary *cpuid,
- uint32 *numThreadsPerCore)
-{
- uint32 numCoresPerPackage;
-
- *numThreadsPerCore = numCoresPerPackage = 1;
- /*
- * Multi-core processors have the HT feature bit set even if they don't
- * support HT. The reported number of HT is the total, not per core.
- */
- if (CPUID_ISSET(1, EDX, HTT, cpuid->id1.edxFeatures)) {
- *numThreadsPerCore = CPUID_GET(1, EBX, LCPU_COUNT, cpuid->id1.ebx);
- if (cpuid->id0.numEntries >= 4) {
- numCoresPerPackage =
- CPUID_IntelCoresPerPackage(__GET_EAX_FROM_CPUID4(0));
-#ifdef ASSERT
- ASSERT(*numThreadsPerCore % numCoresPerPackage == 0);
-#endif
- *numThreadsPerCore /= numCoresPerPackage;
- }
- }
- return numCoresPerPackage;
-}
-
#endif
MXRecLockRelease(&lock->recursiveLock);
}
- /*
- * Don't screw up the reference count! When this is the last reference
- * the lock will self destruct on a release if it is the last "hold"
- * of the lock.
- */
-
- MXUserCondDestroyRecLock(lock);
+ if (Atomic_FetchAndDec(&lock->refCount) == 1) {
+ Panic("%s: Zero reference count upon exit\n", __FUNCTION__);
+ }
}
MXUserStats *stats;
if (MXUserTryAcquireFail(lock->header.name)) {
- success = FALSE;
- goto bail;
+ return FALSE;
}
success = MXRecLockTryAcquire(&lock->recursiveLock);
}
}
-bail:
-
if (Atomic_FetchAndDec(&lock->refCount) == 1) {
Panic("%s: Zero reference count upon exit\n", __FUNCTION__);
}