diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
---|---|---|
committer | <> | 2014-05-08 15:03:54 +0000 |
commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Runtime/r3/darwin | |
parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
download | VirtualBox-master.tar.gz |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Runtime/r3/darwin')
-rw-r--r-- | src/VBox/Runtime/r3/darwin/RTPathUserDocuments-darwin.cpp | 65 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/darwin/mp-darwin.cpp | 83 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/darwin/rtProcInitExePath-darwin.cpp | 13 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/darwin/sched-darwin.cpp | 2 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/darwin/time-darwin.cpp | 2 |
5 files changed, 134 insertions, 31 deletions
diff --git a/src/VBox/Runtime/r3/darwin/RTPathUserDocuments-darwin.cpp b/src/VBox/Runtime/r3/darwin/RTPathUserDocuments-darwin.cpp index 2b033b2f..aae99908 100644 --- a/src/VBox/Runtime/r3/darwin/RTPathUserDocuments-darwin.cpp +++ b/src/VBox/Runtime/r3/darwin/RTPathUserDocuments-darwin.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -28,10 +28,18 @@ * Header Files * *******************************************************************************/ #include <iprt/path.h> -#include <iprt/err.h> +#include "internal/iprt.h" + #include <iprt/assert.h> +#include <iprt/string.h> +#include <iprt/err.h> + +#include <NSSystemDirectories.h> +#include <sys/syslimits.h> +#ifdef IPRT_USE_CORE_SERVICE_FOR_USER_DOCUMENTS +# include <CoreServices/CoreServices.h> +#endif -#include <CoreServices/CoreServices.h> RTDECL(int) RTPathUserDocuments(char *pszPath, size_t cchPath) { @@ -41,15 +49,50 @@ RTDECL(int) RTPathUserDocuments(char *pszPath, size_t cchPath) AssertPtrReturn(pszPath, VERR_INVALID_POINTER); AssertReturn(cchPath, VERR_INVALID_PARAMETER); - FSRef ref; - OSErr err = FSFindFolder(kOnAppropriateDisk, kDocumentsFolderType, false /* createFolder */, &ref); - if (err != noErr) - return VERR_PATH_NOT_FOUND; + /* + * Try NSSystemDirectories first since that works for directories that doesn't exist. + */ + int rc = VERR_PATH_NOT_FOUND; + NSSearchPathEnumerationState EnmState = NSStartSearchPathEnumeration(NSDocumentDirectory, NSUserDomainMask); + if (EnmState != 0) + { + char szTmp[PATH_MAX]; + szTmp[0] = szTmp[PATH_MAX - 1] = '\0'; + EnmState = NSGetNextSearchPathEnumeration(EnmState, szTmp); + if (EnmState != 0) + { + size_t cchTmp = strlen(szTmp); + if (cchTmp >= cchPath) + return VERR_BUFFER_OVERFLOW; - err = FSRefMakePath(&ref, (UInt8*)pszPath, cchPath); - if (err != noErr) - return VERR_PATH_NOT_FOUND; + if (szTmp[0] == '~' && szTmp[1] == '/') + { + /* Expand tilde. */ + rc = RTPathUserHome(pszPath, cchPath - cchTmp + 2); + if (RT_FAILURE(rc)) + return rc; + rc = RTPathAppend(pszPath, cchPath, &szTmp[2]); + } + else + rc = RTStrCopy(pszPath, cchPath, szTmp); + return rc; + } + } - return VINF_SUCCESS; +#ifdef IPRT_USE_CORE_SERVICE_FOR_USER_DOCUMENTS + /* + * Fall back on FSFindFolder in case the above should fail... + */ + FSRef ref; + OSErr err = FSFindFolder(kOnAppropriateDisk, kDocumentsFolderType, false /* createFolder */, &ref); + if (err == noErr) + { + err = FSRefMakePath(&ref, (UInt8*)pszPath, cchPath); + if (err == noErr) + return VINF_SUCCESS; + } +#endif + Assert(RT_FAILURE_NP(rc)); + return rc; } diff --git a/src/VBox/Runtime/r3/darwin/mp-darwin.cpp b/src/VBox/Runtime/r3/darwin/mp-darwin.cpp index 9942686a..bfdeb0d4 100644 --- a/src/VBox/Runtime/r3/darwin/mp-darwin.cpp +++ b/src/VBox/Runtime/r3/darwin/mp-darwin.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2008 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -46,18 +46,63 @@ /** - * Internal worker that determines the max possible CPU count. + * Internal worker that determines the max possible logical CPU count (hyperthreads). * * @returns Max cpus. */ -static RTCPUID rtMpDarwinMaxCpus(void) +static RTCPUID rtMpDarwinMaxLogicalCpus(void) { - int aiMib[2]; - aiMib[0] = CTL_HW; - aiMib[1] = HW_NCPU; int cCpus = -1; size_t cb = sizeof(cCpus); - int rc = sysctl(aiMib, RT_ELEMENTS(aiMib), &cCpus, &cb, NULL, 0); + int rc = sysctlbyname("hw.logicalcpu_max", &cCpus, &cb, NULL, 0); + if (rc != -1 && cCpus >= 1) + return cCpus; + AssertFailed(); + return 1; +} + +/** + * Internal worker that determines the max possible physical core count. + * + * @returns Max cpus. + */ +static RTCPUID rtMpDarwinMaxPhysicalCpus(void) +{ + int cCpus = -1; + size_t cb = sizeof(cCpus); + int rc = sysctlbyname("hw.physicalcpu_max", &cCpus, &cb, NULL, 0); + if (rc != -1 && cCpus >= 1) + return cCpus; + AssertFailed(); + return 1; +} + +/** + * Internal worker that determines the current number of logical CPUs (hyperthreads). + * + * @returns Max cpus. + */ +static RTCPUID rtMpDarwinOnlineLogicalCpus(void) +{ + int cCpus = -1; + size_t cb = sizeof(cCpus); + int rc = sysctlbyname("hw.logicalcpu", &cCpus, &cb, NULL, 0); + if (rc != -1 && cCpus >= 1) + return cCpus; + AssertFailed(); + return 1; +} + +/** + * Internal worker that determines the current number of physical CPUs. + * + * @returns Max cpus. + */ +static RTCPUID rtMpDarwinOnlinePhysicalCpus(void) +{ + int cCpus = -1; + size_t cb = sizeof(cCpus); + int rc = sysctlbyname("hw.physicalcpu", &cCpus, &cb, NULL, 0); if (rc != -1 && cCpus >= 1) return cCpus; AssertFailed(); @@ -69,19 +114,19 @@ static RTCPUID rtMpDarwinMaxCpus(void) RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu) { - return idCpu < RTCPUSET_MAX_CPUS && idCpu < rtMpDarwinMaxCpus() ? idCpu : -1; + return idCpu < RTCPUSET_MAX_CPUS && idCpu < rtMpDarwinMaxLogicalCpus() ? idCpu : -1; } RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu) { - return (unsigned)iCpu < rtMpDarwinMaxCpus() ? iCpu : NIL_RTCPUID; + return (unsigned)iCpu < rtMpDarwinMaxLogicalCpus() ? iCpu : NIL_RTCPUID; } RTDECL(RTCPUID) RTMpGetMaxCpuId(void) { - return rtMpDarwinMaxCpus() - 1; + return rtMpDarwinMaxLogicalCpus() - 1; } @@ -97,7 +142,7 @@ RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu) kern_return_t krc = host_processor_info(mach_host_self(), PROCESSOR_BASIC_INFO, &nCpus, (processor_info_array_t*)&pinfo, &count); AssertReturn (krc == KERN_SUCCESS, true); - bool isOnline = idCpu < nCpus ? pinfo[idCpu].running : true; + bool isOnline = idCpu < nCpus ? pinfo[idCpu].running : false; vm_deallocate(mach_task_self(), (vm_address_t)pinfo, count * sizeof(*pinfo)); return isOnline; #endif @@ -107,19 +152,19 @@ RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu) RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu) { return idCpu != NIL_RTCPUID - && idCpu < rtMpDarwinMaxCpus(); + && idCpu < rtMpDarwinMaxLogicalCpus(); } RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet) { #if 0 - RTCPUID cCpus = rtMpDarwinMaxCpus(); + RTCPUID cCpus = rtMpDarwinMaxLogicalCpus(); return RTCpuSetFromU64(RT_BIT_64(cCpus) - 1); #else RTCpuSetEmpty(pSet); - RTCPUID cMax = rtMpDarwinMaxCpus(); + RTCPUID cMax = rtMpDarwinMaxLogicalCpus(); for (RTCPUID idCpu = 0; idCpu < cMax; idCpu++) if (RTMpIsCpuPossible(idCpu)) RTCpuSetAdd(pSet, idCpu); @@ -130,7 +175,13 @@ RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet) RTDECL(RTCPUID) RTMpGetCount(void) { - return rtMpDarwinMaxCpus(); + return rtMpDarwinMaxLogicalCpus(); +} + + +RTDECL(RTCPUID) RTMpGetCoreCount(void) +{ + return rtMpDarwinMaxPhysicalCpus(); } @@ -140,7 +191,7 @@ RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet) return RTMpGetSet(pSet); #else RTCpuSetEmpty(pSet); - RTCPUID cMax = rtMpDarwinMaxCpus(); + RTCPUID cMax = rtMpDarwinMaxLogicalCpus(); for (RTCPUID idCpu = 0; idCpu < cMax; idCpu++) if (RTMpIsCpuOnline(idCpu)) RTCpuSetAdd(pSet, idCpu); diff --git a/src/VBox/Runtime/r3/darwin/rtProcInitExePath-darwin.cpp b/src/VBox/Runtime/r3/darwin/rtProcInitExePath-darwin.cpp index 103e70b4..922bd41e 100644 --- a/src/VBox/Runtime/r3/darwin/rtProcInitExePath-darwin.cpp +++ b/src/VBox/Runtime/r3/darwin/rtProcInitExePath-darwin.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2008 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -32,6 +32,9 @@ # include <mach-o/dyld.h> #endif +#include <stdlib.h> +#include <limits.h> +#include <errno.h> #include <iprt/string.h> #include <iprt/assert.h> #include <iprt/err.h> @@ -48,7 +51,13 @@ DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath) const char *pszImageName = _dyld_get_image_name(0); AssertReturn(pszImageName, VERR_INTERNAL_ERROR); - int rc = rtPathFromNativeCopy(pszPath, cchPath, pszImageName, NULL); + char szTmpPath[PATH_MAX + 1]; + const char *psz = realpath(pszImageName, szTmpPath); + int rc; + if (psz) + rc = rtPathFromNativeCopy(pszPath, cchPath, szTmpPath, NULL); + else + rc = RTErrConvertFromErrno(errno); AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhxs\n", rc, pszPath, strlen(pszImageName), pszPath), rc); return VINF_SUCCESS; diff --git a/src/VBox/Runtime/r3/darwin/sched-darwin.cpp b/src/VBox/Runtime/r3/darwin/sched-darwin.cpp index ad47cdbb..3879db8c 100644 --- a/src/VBox/Runtime/r3/darwin/sched-darwin.cpp +++ b/src/VBox/Runtime/r3/darwin/sched-darwin.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2009 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/Runtime/r3/darwin/time-darwin.cpp b/src/VBox/Runtime/r3/darwin/time-darwin.cpp index 38878c63..a737d01b 100644 --- a/src/VBox/Runtime/r3/darwin/time-darwin.cpp +++ b/src/VBox/Runtime/r3/darwin/time-darwin.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; |