summaryrefslogtreecommitdiff
path: root/src/VBox/Main/src-server/darwin
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-03-26 19:21:20 +0000
committer <>2014-05-08 15:03:54 +0000
commitfb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch)
treec2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Main/src-server/darwin
parent58ed4748338f9466599adfc8a9171280ed99e23f (diff)
downloadVirtualBox-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/Main/src-server/darwin')
-rw-r--r--src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp256
-rw-r--r--src/VBox/Main/src-server/darwin/HostPowerDarwin.cpp118
-rw-r--r--src/VBox/Main/src-server/darwin/NetIf-darwin.cpp23
-rw-r--r--src/VBox/Main/src-server/darwin/PerformanceDarwin.cpp67
-rw-r--r--src/VBox/Main/src-server/darwin/iokit.cpp6
-rw-r--r--src/VBox/Main/src-server/darwin/iokit.h2
6 files changed, 368 insertions, 104 deletions
diff --git a/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp b/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp
new file mode 100644
index 00000000..6e91e7e6
--- /dev/null
+++ b/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp
@@ -0,0 +1,256 @@
+/* $Id: HostDnsServiceDarwin.cpp $ */
+/** @file
+ * Darwin specific DNS information fetching.
+ */
+
+/*
+ * Copyright (C) 2004-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;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#include <VBox/com/string.h>
+#include <VBox/com/ptr.h>
+
+
+#include <iprt/err.h>
+#include <iprt/thread.h>
+#include <iprt/semaphore.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SCDynamicStore.h>
+
+#include <string>
+#include <vector>
+#include "../HostDnsService.h"
+
+
+struct HostDnsServiceDarwin::Data
+{
+ SCDynamicStoreRef m_store;
+ CFRunLoopSourceRef m_DnsWatcher;
+ CFRunLoopRef m_RunLoopRef;
+ CFRunLoopSourceRef m_Stopper;
+ bool m_fStop;
+ RTSEMEVENT m_evtStop;
+ static void performShutdownCallback(void *);
+};
+
+
+static const CFStringRef kStateNetworkGlobalDNSKey = CFSTR("State:/Network/Global/DNS");
+
+
+HostDnsServiceDarwin::HostDnsServiceDarwin():HostDnsMonitor(true),m(NULL)
+{
+ m = new HostDnsServiceDarwin::Data();
+}
+
+
+HostDnsServiceDarwin::~HostDnsServiceDarwin()
+{
+ if (!m)
+ return;
+
+ monitorThreadShutdown();
+
+ CFRelease(m->m_RunLoopRef);
+
+ CFRelease(m->m_DnsWatcher);
+
+ CFRelease(m->m_store);
+
+ RTSemEventDestroy(m->m_evtStop);
+
+ delete m;
+ m = NULL;
+}
+
+
+void HostDnsServiceDarwin::hostDnsServiceStoreCallback(void *, void *, void *info)
+{
+ HostDnsServiceDarwin *pThis = (HostDnsServiceDarwin *)info;
+
+ ALock l(pThis);
+ pThis->updateInfo();
+ pThis->notifyAll();
+}
+
+
+HRESULT HostDnsServiceDarwin::init()
+{
+ SCDynamicStoreContext ctx;
+ RT_ZERO(ctx);
+
+ ctx.info = this;
+
+ m->m_store = SCDynamicStoreCreate(NULL, CFSTR("org.virtualbox.VBoxSVC"),
+ (SCDynamicStoreCallBack)HostDnsServiceDarwin::hostDnsServiceStoreCallback,
+ &ctx);
+ AssertReturn(m->m_store, E_FAIL);
+
+ m->m_DnsWatcher = SCDynamicStoreCreateRunLoopSource(NULL, m->m_store, 0);
+ if (!m->m_DnsWatcher)
+ return E_OUTOFMEMORY;
+
+ int rc = RTSemEventCreate(&m->m_evtStop);
+ AssertRCReturn(rc, E_FAIL);
+
+ CFRunLoopSourceContext sctx;
+ RT_ZERO(sctx);
+ sctx.perform = HostDnsServiceDarwin::Data::performShutdownCallback;
+ m->m_Stopper = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &sctx);
+ AssertReturn(m->m_Stopper, E_FAIL);
+
+ HRESULT hrc = HostDnsMonitor::init();
+ AssertComRCReturn(hrc, hrc);
+
+ return updateInfo();
+}
+
+
+void HostDnsServiceDarwin::monitorThreadShutdown()
+{
+ ALock l(this);
+ if (!m->m_fStop)
+ {
+ CFRunLoopSourceSignal(m->m_Stopper);
+ CFRunLoopWakeUp(m->m_RunLoopRef);
+
+ RTSemEventWait(m->m_evtStop, RT_INDEFINITE_WAIT);
+ }
+}
+
+
+int HostDnsServiceDarwin::monitorWorker()
+{
+ m->m_RunLoopRef = CFRunLoopGetCurrent();
+ AssertReturn(m->m_RunLoopRef, VERR_INTERNAL_ERROR);
+
+ CFRetain(m->m_RunLoopRef);
+
+ CFArrayRef watchingArrayRef = CFArrayCreate(NULL,
+ (const void **)&kStateNetworkGlobalDNSKey,
+ 1, &kCFTypeArrayCallBacks);
+ if (!watchingArrayRef)
+ {
+ CFRelease(m->m_DnsWatcher);
+ return E_OUTOFMEMORY;
+ }
+
+ if(SCDynamicStoreSetNotificationKeys(m->m_store, watchingArrayRef, NULL))
+ CFRunLoopAddSource(CFRunLoopGetCurrent(), m->m_DnsWatcher, kCFRunLoopCommonModes);
+
+ CFRelease(watchingArrayRef);
+
+ monitorThreadInitializationDone();
+
+ while (!m->m_fStop)
+ {
+ CFRunLoopRun();
+ }
+
+ CFRelease(m->m_RunLoopRef);
+
+ /* We're notifying stopper thread. */
+ RTSemEventSignal(m->m_evtStop);
+
+ return VINF_SUCCESS;
+}
+
+
+HRESULT HostDnsServiceDarwin::updateInfo()
+{
+ CFPropertyListRef propertyRef = SCDynamicStoreCopyValue(m->m_store,
+ kStateNetworkGlobalDNSKey);
+ /**
+ * 0:vvl@nb-mbp-i7-2(0)# scutil
+ * > get State:/Network/Global/DNS
+ * > d.show
+ * <dictionary> {
+ * DomainName : vvl-domain
+ * SearchDomains : <array> {
+ * 0 : vvl-domain
+ * 1 : de.vvl-domain.com
+ * }
+ * ServerAddresses : <array> {
+ * 0 : 192.168.1.4
+ * 1 : 192.168.1.1
+ * 2 : 8.8.4.4
+ * }
+ * }
+ */
+
+ if (!propertyRef)
+ return S_OK;
+
+ HostDnsInformation info;
+ CFStringRef domainNameRef = (CFStringRef)CFDictionaryGetValue(
+ static_cast<CFDictionaryRef>(propertyRef), CFSTR("DomainName"));
+ if (domainNameRef)
+ {
+ const char *pszDomainName = CFStringGetCStringPtr(domainNameRef,
+ CFStringGetSystemEncoding());
+ if (pszDomainName)
+ info.domain = pszDomainName;
+ }
+
+ int i, arrayCount;
+ CFArrayRef serverArrayRef = (CFArrayRef)CFDictionaryGetValue(
+ static_cast<CFDictionaryRef>(propertyRef), CFSTR("ServerAddresses"));
+ if (serverArrayRef)
+ {
+ arrayCount = CFArrayGetCount(serverArrayRef);
+ for (i = 0; i < arrayCount; ++i)
+ {
+ CFStringRef serverAddressRef = (CFStringRef)CFArrayGetValueAtIndex(serverArrayRef, i);
+ if (!serverArrayRef)
+ continue;
+
+ const char *pszServerAddress = CFStringGetCStringPtr(serverAddressRef,
+ CFStringGetSystemEncoding());
+ if (!pszServerAddress)
+ continue;
+
+ info.servers.push_back(std::string(pszServerAddress));
+ }
+ }
+
+ CFArrayRef searchArrayRef = (CFArrayRef)CFDictionaryGetValue(
+ static_cast<CFDictionaryRef>(propertyRef), CFSTR("SearchDomains"));
+ if (searchArrayRef)
+ {
+ arrayCount = CFArrayGetCount(searchArrayRef);
+
+ for (i = 0; i < arrayCount; ++i)
+ {
+ CFStringRef searchStringRef = (CFStringRef)CFArrayGetValueAtIndex(searchArrayRef, i);
+ if (!searchArrayRef)
+ continue;
+
+ const char *pszSearchString = CFStringGetCStringPtr(searchStringRef,
+ CFStringGetSystemEncoding());
+ if (!pszSearchString)
+ continue;
+
+ info.searchList.push_back(std::string(pszSearchString));
+ }
+ }
+
+ CFRelease(propertyRef);
+
+ setInfo(info);
+
+ return S_OK;
+}
+
+void HostDnsServiceDarwin::Data::performShutdownCallback(void *info)
+{
+ HostDnsServiceDarwin::Data *pThis = static_cast<HostDnsServiceDarwin::Data *>(info);
+ pThis->m_fStop = true;
+}
diff --git a/src/VBox/Main/src-server/darwin/HostPowerDarwin.cpp b/src/VBox/Main/src-server/darwin/HostPowerDarwin.cpp
index a83297e4..5e68d02b 100644
--- a/src/VBox/Main/src-server/darwin/HostPowerDarwin.cpp
+++ b/src/VBox/Main/src-server/darwin/HostPowerDarwin.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2008 Oracle Corporation
+ * Copyright (C) 2008-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;
@@ -25,43 +25,43 @@
#define POWER_SOURCE_OUTLET 1
#define POWER_SOURCE_BATTERY 2
-HostPowerServiceDarwin::HostPowerServiceDarwin (VirtualBox *aVirtualBox)
- : HostPowerService (aVirtualBox)
- , mThread (NULL)
- , mRootPort (MACH_PORT_NULL)
- , mNotifyPort (nil)
- , mRunLoop (nil)
- , mCritical (false)
+HostPowerServiceDarwin::HostPowerServiceDarwin(VirtualBox *aVirtualBox)
+ : HostPowerService(aVirtualBox)
+ , mThread(NULL)
+ , mRootPort(MACH_PORT_NULL)
+ , mNotifyPort(nil)
+ , mRunLoop(nil)
+ , mCritical(false)
{
/* Create the new worker thread. */
- int rc = RTThreadCreate (&mThread, HostPowerServiceDarwin::powerChangeNotificationThread, this, 65536,
- RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "MainPower");
+ int rc = RTThreadCreate(&mThread, HostPowerServiceDarwin::powerChangeNotificationThread, this, 65536,
+ RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "MainPower");
if (RT_FAILURE(rc))
- LogFlow (("RTThreadCreate failed with %Rrc\n", rc));
+ LogFlow(("RTThreadCreate failed with %Rrc\n", rc));
}
HostPowerServiceDarwin::~HostPowerServiceDarwin()
{
/* Jump out of the run loop. */
- CFRunLoopStop (mRunLoop);
+ CFRunLoopStop(mRunLoop);
/* Remove the sleep notification port from the application runloop. */
- CFRunLoopRemoveSource (CFRunLoopGetCurrent(),
- IONotificationPortGetRunLoopSource (mNotifyPort),
- kCFRunLoopCommonModes);
+ CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
+ IONotificationPortGetRunLoopSource(mNotifyPort),
+ kCFRunLoopCommonModes);
/* Deregister for system sleep notifications. */
- IODeregisterForSystemPower (&mNotifierObject);
+ IODeregisterForSystemPower(&mNotifierObject);
/* IORegisterForSystemPower implicitly opens the Root Power Domain
* IOService so we close it here. */
- IOServiceClose (mRootPort);
+ IOServiceClose(mRootPort);
/* Destroy the notification port allocated by IORegisterForSystemPower */
- IONotificationPortDestroy (mNotifyPort);
+ IONotificationPortDestroy(mNotifyPort);
}
-DECLCALLBACK(int) HostPowerServiceDarwin::powerChangeNotificationThread (RTTHREAD /* ThreadSelf */, void *pInstance)
+DECLCALLBACK(int) HostPowerServiceDarwin::powerChangeNotificationThread(RTTHREAD /* ThreadSelf */, void *pInstance)
{
- HostPowerServiceDarwin *pPowerObj = static_cast<HostPowerServiceDarwin *> (pInstance);
+ HostPowerServiceDarwin *pPowerObj = static_cast<HostPowerServiceDarwin *>(pInstance);
/* We have to initial set the critical state of the battery, cause we want
* not the HostPowerService to inform about that state when a VM starts.
@@ -69,19 +69,19 @@ DECLCALLBACK(int) HostPowerServiceDarwin::powerChangeNotificationThread (RTTHREA
pPowerObj->checkBatteryCriticalLevel();
/* Register to receive system sleep notifications */
- pPowerObj->mRootPort = IORegisterForSystemPower (pPowerObj, &pPowerObj->mNotifyPort,
- HostPowerServiceDarwin::powerChangeNotificationHandler,
- &pPowerObj->mNotifierObject);
+ pPowerObj->mRootPort = IORegisterForSystemPower(pPowerObj, &pPowerObj->mNotifyPort,
+ HostPowerServiceDarwin::powerChangeNotificationHandler,
+ &pPowerObj->mNotifierObject);
if (pPowerObj->mRootPort == MACH_PORT_NULL)
{
- LogFlow (("IORegisterForSystemPower failed\n"));
+ LogFlow(("IORegisterForSystemPower failed\n"));
return VERR_NOT_SUPPORTED;
}
pPowerObj->mRunLoop = CFRunLoopGetCurrent();
/* Add the notification port to the application runloop */
- CFRunLoopAddSource (pPowerObj->mRunLoop,
- IONotificationPortGetRunLoopSource (pPowerObj->mNotifyPort),
- kCFRunLoopCommonModes);
+ CFRunLoopAddSource(pPowerObj->mRunLoop,
+ IONotificationPortGetRunLoopSource(pPowerObj->mNotifyPort),
+ kCFRunLoopCommonModes);
/* Register for all battery change events. The handler will check for low
* power events itself. */
@@ -96,10 +96,10 @@ DECLCALLBACK(int) HostPowerServiceDarwin::powerChangeNotificationThread (RTTHREA
return VINF_SUCCESS;
}
-void HostPowerServiceDarwin::powerChangeNotificationHandler (void *pvData, io_service_t /* service */, natural_t messageType, void *pMessageArgument)
+void HostPowerServiceDarwin::powerChangeNotificationHandler(void *pvData, io_service_t /* service */, natural_t messageType, void *pMessageArgument)
{
- HostPowerServiceDarwin *pPowerObj = static_cast<HostPowerServiceDarwin *> (pvData);
- Log (( "powerChangeNotificationHandler: messageType %08lx, arg %08lx\n", (long unsigned int)messageType, (long unsigned int)pMessageArgument));
+ HostPowerServiceDarwin *pPowerObj = static_cast<HostPowerServiceDarwin *>(pvData);
+ Log(( "powerChangeNotificationHandler: messageType %08lx, arg %08lx\n", (long unsigned int)messageType, (long unsigned int)pMessageArgument));
switch (messageType)
{
@@ -113,18 +113,18 @@ void HostPowerServiceDarwin::powerChangeNotificationHandler (void *pvData, io_se
* you don't acknowledge this power change by calling either
* IOAllowPowerChange or IOCancelPowerChange, the system will
* wait 30 seconds then go to sleep. */
- IOAllowPowerChange (pPowerObj->mRootPort, reinterpret_cast<long> (pMessageArgument));
+ IOAllowPowerChange(pPowerObj->mRootPort, reinterpret_cast<long>(pMessageArgument));
break;
}
case kIOMessageSystemWillSleep:
{
/* The system will go for sleep. */
- pPowerObj->notify (HostPowerEvent_Suspend);
+ pPowerObj->notify(Reason_HostSuspend);
/* If you do not call IOAllowPowerChange or IOCancelPowerChange to
* acknowledge this message, sleep will be delayed by 30 seconds.
* NOTE: If you call IOCancelPowerChange to deny sleep it returns
* kIOReturnSuccess, however the system WILL still go to sleep. */
- IOAllowPowerChange (pPowerObj->mRootPort, reinterpret_cast<long> (pMessageArgument));
+ IOAllowPowerChange(pPowerObj->mRootPort, reinterpret_cast<long>(pMessageArgument));
break;
}
case kIOMessageSystemWillPowerOn:
@@ -135,7 +135,7 @@ void HostPowerServiceDarwin::powerChangeNotificationHandler (void *pvData, io_se
case kIOMessageSystemHasPoweredOn:
{
/* System has finished the wake up process. */
- pPowerObj->notify (HostPowerEvent_Resume);
+ pPowerObj->notify(Reason_HostResume);
break;
}
default:
@@ -143,11 +143,11 @@ void HostPowerServiceDarwin::powerChangeNotificationHandler (void *pvData, io_se
}
}
-void HostPowerServiceDarwin::lowPowerHandler (void *pvData)
+void HostPowerServiceDarwin::lowPowerHandler(void *pvData)
{
- HostPowerServiceDarwin *pPowerObj = static_cast<HostPowerServiceDarwin *> (pvData);
+ HostPowerServiceDarwin *pPowerObj = static_cast<HostPowerServiceDarwin *>(pvData);
- /* Following role for sending the BatteryLow event (5% is critical):
+ /* Following role for sending the BatteryLow event(5% is critical):
* - Not at VM start even if the battery is in an critical state already.
* - When the power cord is removed so the power supply change from AC to
* battery & the battery is in an critical state nothing is triggered.
@@ -156,15 +156,15 @@ void HostPowerServiceDarwin::lowPowerHandler (void *pvData)
* changed from normal to critical. The state transition from critical to
* normal triggers nothing. */
bool fCriticalStateChanged = false;
- pPowerObj->checkBatteryCriticalLevel (&fCriticalStateChanged);
+ pPowerObj->checkBatteryCriticalLevel(&fCriticalStateChanged);
if (fCriticalStateChanged)
- pPowerObj->notify (HostPowerEvent_BatteryLow);
+ pPowerObj->notify(Reason_HostBatteryLow);
}
-void HostPowerServiceDarwin::checkBatteryCriticalLevel (bool *pfCriticalChanged)
+void HostPowerServiceDarwin::checkBatteryCriticalLevel(bool *pfCriticalChanged)
{
CFTypeRef pBlob = IOPSCopyPowerSourcesInfo();
- CFArrayRef pSources = IOPSCopyPowerSourcesList (pBlob);
+ CFArrayRef pSources = IOPSCopyPowerSourcesList(pBlob);
CFDictionaryRef pSource = NULL;
const void *psValue;
@@ -172,30 +172,30 @@ void HostPowerServiceDarwin::checkBatteryCriticalLevel (bool *pfCriticalChanged)
int powerSource = POWER_SOURCE_OUTLET;
bool critical = false;
- if (CFArrayGetCount (pSources) > 0)
+ if (CFArrayGetCount(pSources) > 0)
{
- for (int i = 0; i < CFArrayGetCount (pSources); ++i)
+ for (int i = 0; i < CFArrayGetCount(pSources); ++i)
{
- pSource = IOPSGetPowerSourceDescription (pBlob, CFArrayGetValueAtIndex (pSources, i));
+ pSource = IOPSGetPowerSourceDescription(pBlob, CFArrayGetValueAtIndex(pSources, i));
/* If the source is empty skip over to the next one. */
if (!pSource)
continue;
/* Skip all power sources which are currently not present like a
* second battery. */
- if (CFDictionaryGetValue (pSource, CFSTR (kIOPSIsPresentKey)) == kCFBooleanFalse)
+ if (CFDictionaryGetValue(pSource, CFSTR(kIOPSIsPresentKey)) == kCFBooleanFalse)
continue;
/* Only internal power types are of interest. */
- result = CFDictionaryGetValueIfPresent (pSource, CFSTR (kIOPSTransportTypeKey), &psValue);
+ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSTransportTypeKey), &psValue);
if (result &&
- CFStringCompare ((CFStringRef)psValue, CFSTR (kIOPSInternalType), 0) == kCFCompareEqualTo)
+ CFStringCompare((CFStringRef)psValue, CFSTR(kIOPSInternalType), 0) == kCFCompareEqualTo)
{
/* First check which power source we are connect on. */
- result = CFDictionaryGetValueIfPresent (pSource, CFSTR (kIOPSPowerSourceStateKey), &psValue);
+ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSPowerSourceStateKey), &psValue);
if (result &&
- CFStringCompare ((CFStringRef)psValue, CFSTR (kIOPSACPowerValue), 0) == kCFCompareEqualTo)
+ CFStringCompare((CFStringRef)psValue, CFSTR(kIOPSACPowerValue), 0) == kCFCompareEqualTo)
powerSource = POWER_SOURCE_OUTLET;
else if (result &&
- CFStringCompare ((CFStringRef)psValue, CFSTR (kIOPSBatteryPowerValue), 0) == kCFCompareEqualTo)
+ CFStringCompare((CFStringRef)psValue, CFSTR(kIOPSBatteryPowerValue), 0) == kCFCompareEqualTo)
powerSource = POWER_SOURCE_BATTERY;
int curCapacity = 0;
@@ -203,22 +203,22 @@ void HostPowerServiceDarwin::checkBatteryCriticalLevel (bool *pfCriticalChanged)
float remCapacity = 0.0f;
/* Fetch the current capacity value of the power source */
- result = CFDictionaryGetValueIfPresent (pSource, CFSTR (kIOPSCurrentCapacityKey), &psValue);
+ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSCurrentCapacityKey), &psValue);
if (result)
- CFNumberGetValue ((CFNumberRef)psValue, kCFNumberSInt32Type, &curCapacity);
+ CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &curCapacity);
/* Fetch the maximum capacity value of the power source */
- result = CFDictionaryGetValueIfPresent (pSource, CFSTR (kIOPSMaxCapacityKey), &psValue);
+ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSMaxCapacityKey), &psValue);
if (result)
- CFNumberGetValue ((CFNumberRef)psValue, kCFNumberSInt32Type, &maxCapacity);
+ CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &maxCapacity);
/* Calculate the remaining capacity in percent */
remCapacity = ((float)curCapacity/(float)maxCapacity * 100.0);
/* Check for critical. 5 percent is default. */
int criticalValue = 5;
- result = CFDictionaryGetValueIfPresent (pSource, CFSTR (kIOPSDeadWarnLevelKey), &psValue);
+ result = CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSDeadWarnLevelKey), &psValue);
if (result)
- CFNumberGetValue ((CFNumberRef)psValue, kCFNumberSInt32Type, &criticalValue);
+ CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &criticalValue);
critical = (remCapacity < criticalValue);
/* We have to take action only if we are on battery, the
* previous state wasn't critical, the state has changed & the
@@ -228,14 +228,14 @@ void HostPowerServiceDarwin::checkBatteryCriticalLevel (bool *pfCriticalChanged)
mCritical != critical &&
pfCriticalChanged)
*pfCriticalChanged = true;
- Log (("checkBatteryCriticalLevel: Remains: %d.%d%% Critical: %d Critical State Changed: %d\n", (int)remCapacity, (int)(remCapacity * 10) % 10, critical, pfCriticalChanged?*pfCriticalChanged:-1));
+ Log(("checkBatteryCriticalLevel: Remains: %d.%d%% Critical: %d Critical State Changed: %d\n", (int)remCapacity, (int)(remCapacity * 10) % 10, critical, pfCriticalChanged?*pfCriticalChanged:-1));
}
}
}
/* Save the new state */
mCritical = critical;
- CFRelease (pBlob);
- CFRelease (pSources);
+ CFRelease(pBlob);
+ CFRelease(pSources);
}
diff --git a/src/VBox/Main/src-server/darwin/NetIf-darwin.cpp b/src/VBox/Main/src-server/darwin/NetIf-darwin.cpp
index 99cf52e2..cfde818e 100644
--- a/src/VBox/Main/src-server/darwin/NetIf-darwin.cpp
+++ b/src/VBox/Main/src-server/darwin/NetIf-darwin.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2008 Oracle Corporation
+ * Copyright (C) 2008-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;
@@ -85,7 +85,7 @@ int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list)
memcpy(pNew->szName, pEtherNICs->szName, cbNameLen);
struct ifreq IfReq;
- strcpy(IfReq.ifr_name, pNew->szShortName);
+ RTStrCopy(IfReq.ifr_name, sizeof(IfReq.ifr_name), pNew->szShortName);
if (ioctl(sock, SIOCGIFFLAGS, &IfReq) < 0)
{
Log(("NetIfList: ioctl(SIOCGIFFLAGS) -> %d\n", errno));
@@ -391,7 +391,7 @@ int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list)
if (pSdl->sdl_type == IFT_ETHER)
{
struct ifreq IfReq;
- strcpy(IfReq.ifr_name, pNew->szShortName);
+ RTStrCopy(IfReq.ifr_name, sizeof(IfReq.ifr_name), pNew->szShortName);
if (ioctl(sock, SIOCGIFFLAGS, &IfReq) < 0)
{
Log(("NetIfList: ioctl(SIOCGIFFLAGS) -> %d\n", errno));
@@ -401,7 +401,7 @@ int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list)
pNew->enmStatus = (IfReq.ifr_flags & IFF_UP) ? NETIF_S_UP : NETIF_S_DOWN;
HostNetworkInterfaceType_T enmType;
- if (strncmp("vboxnet", pNew->szName, 7))
+ if (strncmp(pNew->szName, RT_STR_TUPLE("vboxnet")))
enmType = HostNetworkInterfaceType_Bridged;
else
enmType = HostNetworkInterfaceType_HostOnly;
@@ -511,7 +511,7 @@ int NetIfGetConfigByName(PNETIFINFO pInfo)
pInfo->Uuid = uuid;
struct ifreq IfReq;
- strcpy(IfReq.ifr_name, pInfo->szShortName);
+ RTStrCopy(IfReq.ifr_name, sizeof(IfReq.ifr_name), pInfo->szShortName);
if (ioctl(sock, SIOCGIFFLAGS, &IfReq) < 0)
{
Log(("NetIfList: ioctl(SIOCGIFFLAGS) -> %d\n", errno));
@@ -528,4 +528,17 @@ int NetIfGetConfigByName(PNETIFINFO pInfo)
return rc;
}
+/**
+ * Retrieve the physical link speed in megabits per second. If the interface is
+ * not up or otherwise unavailable the zero speed is returned.
+ *
+ * @returns VBox status code.
+ *
+ * @param pcszIfName Interface name.
+ * @param puMbits Where to store the link speed.
+ */
+int NetIfGetLinkSpeed(const char * /*pcszIfName*/, uint32_t * /*puMbits*/)
+{
+ return VERR_NOT_IMPLEMENTED;
+}
#endif
diff --git a/src/VBox/Main/src-server/darwin/PerformanceDarwin.cpp b/src/VBox/Main/src-server/darwin/PerformanceDarwin.cpp
index e3daa585..ea040bd0 100644
--- a/src/VBox/Main/src-server/darwin/PerformanceDarwin.cpp
+++ b/src/VBox/Main/src-server/darwin/PerformanceDarwin.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2008 Oracle Corporation
+ * Copyright (C) 2008-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;
@@ -24,7 +24,9 @@
#include <sys/errno.h>
#include <iprt/err.h>
#include <iprt/log.h>
+#include <iprt/mp.h>
#include <iprt/param.h>
+#include <iprt/system.h>
#include "Performance.h"
/* The following declarations are missing in 10.4.x SDK */
@@ -63,7 +65,8 @@ public:
virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
private:
- ULONG totalRAM;
+ ULONG totalRAM;
+ uint32_t nCpus;
};
CollectorHAL *createHAL()
@@ -73,19 +76,19 @@ CollectorHAL *createHAL()
CollectorDarwin::CollectorDarwin()
{
- uint64_t hostMemory;
- int mib[2];
- size_t size;
-
- mib[0] = CTL_HW;
- mib[1] = HW_MEMSIZE;
-
- size = sizeof(hostMemory);
- if (sysctl(mib, 2, &hostMemory, &size, NULL, 0) == -1) {
- Log(("sysctl() -> %s", strerror(errno)));
- hostMemory = 0;
+ uint64_t cb;
+ int rc = RTSystemQueryTotalRam(&cb);
+ if (RT_FAILURE(rc))
+ totalRAM = 0;
+ else
+ totalRAM = (ULONG)(cb / 1024);
+ nCpus = RTMpGetOnlineCount();
+ Assert(nCpus);
+ if (nCpus == 0)
+ {
+ /* It is rather unsual to have no CPUs, but the show must go on. */
+ nCpus = 1;
}
- totalRAM = (ULONG)(hostMemory / 1024);
}
int CollectorDarwin::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle)
@@ -112,23 +115,16 @@ int CollectorDarwin::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_
int CollectorDarwin::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
{
- kern_return_t krc;
- mach_msg_type_number_t count;
- vm_statistics_data_t info;
-
- count = HOST_VM_INFO_COUNT;
-
- krc = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&info, &count);
- if (krc != KERN_SUCCESS)
+ AssertReturn(totalRAM, VERR_INTERNAL_ERROR);
+ uint64_t cb;
+ int rc = RTSystemQueryAvailableRam(&cb);
+ if (RT_SUCCESS(rc))
{
- Log(("host_statistics() -> %s", mach_error_string(krc)));
- return RTErrConvertFromDarwinKern(krc);
+ *total = totalRAM;
+ *available = cb / 1024;
+ *used = *total - *available;
}
-
- *total = totalRAM;
- *available = info.free_count * (PAGE_SIZE / 1024);
- *used = *total - *available;
- return VINF_SUCCESS;
+ return rc;
}
static int getProcessInfo(RTPROCESS process, struct proc_taskinfo *tinfo)
@@ -156,8 +152,12 @@ int CollectorDarwin::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uin
int rc = getProcessInfo(process, &tinfo);
if (RT_SUCCESS(rc))
{
- *user = tinfo.pti_total_user;
- *kernel = tinfo.pti_total_system;
+ /*
+ * Adjust user and kernel values so 100% is when ALL cores are fully
+ * utilized (see @bugref{6345}).
+ */
+ *user = tinfo.pti_total_user / nCpus;
+ *kernel = tinfo.pti_total_system / nCpus;
*total = mach_absolute_time();
}
return rc;
@@ -175,10 +175,5 @@ int CollectorDarwin::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
return rc;
}
-int getDiskListByFs(const char *name, DiskList& list)
-{
- return VERR_NOT_IMPLEMENTED;
-}
-
}
diff --git a/src/VBox/Main/src-server/darwin/iokit.cpp b/src/VBox/Main/src-server/darwin/iokit.cpp
index 0045e7c0..69c572f2 100644
--- a/src/VBox/Main/src-server/darwin/iokit.cpp
+++ b/src/VBox/Main/src-server/darwin/iokit.cpp
@@ -8,7 +8,7 @@
*/
/*
- * Copyright (C) 2006-2007 Oracle Corporation
+ * Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
@@ -373,7 +373,7 @@ static void darwinDumpDictCallback(const void *pvKey, const void *pvValue, void
double rd;
CFIndex iCF;
} u;
- memset(&u, 0, sizeof(u));
+ RT_ZERO(u);
CFNumberType NumType = CFNumberGetType((CFNumberRef)pvValue);
if (CFNumberGetValue((CFNumberRef)pvValue, NumType, &u))
{
@@ -1354,7 +1354,7 @@ PDARWINDVD DarwinGetDVDDrives(void)
if (*pszVendor && *pszProduct)
RTStrPrintf(szName, sizeof(szName), "%s %s (#%u)", pszVendor, pszProduct, i);
else
- RTStrPrintf(szName, sizeof(szName), "%s %s (#%u)", *pszVendor ? pszVendor : pszProduct, i);
+ RTStrPrintf(szName, sizeof(szName), "%s (#%u)", *pszVendor ? pszVendor : pszProduct, i);
break;
}
}
diff --git a/src/VBox/Main/src-server/darwin/iokit.h b/src/VBox/Main/src-server/darwin/iokit.h
index 8cb80a52..ff81b3c7 100644
--- a/src/VBox/Main/src-server/darwin/iokit.h
+++ b/src/VBox/Main/src-server/darwin/iokit.h
@@ -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;