1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-19 08:13:21 +00:00

- Fix overflow in host memory size calculation.

- Catch up with PG_CACHE removal on head.

PR:		211432
This commit is contained in:
Jung-uk Kim 2017-09-08 01:12:56 +00:00
parent a20fae9f56
commit 3b388c46e9
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=449436
4 changed files with 65 additions and 0 deletions

View File

@ -3,6 +3,7 @@
PORTNAME= virtualbox-ose
PORTVERSION= 5.1.26
PORTREVISION= 1
CATEGORIES= emulators
MASTER_SITES= http://download.virtualbox.org/virtualbox/${PORTVERSION}/
PKGNAMESUFFIX?= -additions

View File

@ -3,6 +3,7 @@
PORTNAME= virtualbox-ose
PORTVERSION= 5.1.26
PORTREVISION= 1
CATEGORIES= emulators
MASTER_SITES= http://download.virtualbox.org/virtualbox/${PORTVERSION}/
DISTFILES= VirtualBox-${PORTVERSION}${EXTRACT_SUFX} ${GUESTADDITIONS}

View File

@ -0,0 +1,24 @@
--- src/VBox/Main/src-server/freebsd/PerformanceFreeBSD.cpp.orig 2017-07-27 13:18:27 UTC
+++ src/VBox/Main/src-server/freebsd/PerformanceFreeBSD.cpp
@@ -80,8 +80,10 @@ int CollectorFreeBSD::getHostMemoryUsage(ULONG *total,
cbParameter = sizeof(cPagesMemInactive);
if (!sysctlbyname("vm.stats.vm.v_inactive_count", &cPagesMemInactive, &cbParameter, NULL, 0))
cProcessed++;
+#if __FreeBSD_version < 1200016
cbParameter = sizeof(cPagesMemCached);
if (!sysctlbyname("vm.stats.vm.v_cache_count", &cPagesMemCached, &cbParameter, NULL, 0))
+#endif
cProcessed++;
cbParameter = sizeof(cbPage);
if (!sysctlbyname("hw.pagesize", &cbPage, &cbParameter, NULL, 0))
@@ -90,8 +92,8 @@ int CollectorFreeBSD::getHostMemoryUsage(ULONG *total,
if (cProcessed == 6)
{
*total = cbMemPhys / _1K;
- *used = cPagesMemUsed * (cbPage / _1K);
- *available = (cPagesMemFree + cPagesMemInactive + cPagesMemCached ) * (cbPage / _1K);
+ *used = (uint64_t)cPagesMemUsed * (cbPage / _1K);
+ *available = ((uint64_t)cPagesMemFree + cPagesMemInactive + cPagesMemCached) * (cbPage / _1K);
}
else
rc = VERR_NOT_SUPPORTED;

View File

@ -0,0 +1,39 @@
--- src/VBox/Runtime/r3/freebsd/systemmem-freebsd.cpp.orig 2017-07-27 13:18:46 UTC
+++ src/VBox/Runtime/r3/freebsd/systemmem-freebsd.cpp
@@ -65,7 +65,6 @@ RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb)
u_int cPagesMemFree = 0;
u_int cPagesMemInactive = 0;
u_int cPagesMemCached = 0;
- u_int cPagesMemUsed = 0;
int cbPage = 0;
size_t cbParameter;
int cProcessed = 0;
@@ -73,25 +72,23 @@ RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb)
cbParameter = sizeof(cPagesMemFree);
if (sysctlbyname("vm.stats.vm.v_free_count", &cPagesMemFree, &cbParameter, NULL, 0))
rc = RTErrConvertFromErrno(errno);
- cbParameter = sizeof(cPagesMemUsed);
- if ( RT_SUCCESS(rc)
- && sysctlbyname("vm.stats.vm.v_active_count", &cPagesMemUsed, &cbParameter, NULL, 0))
- rc = RTErrConvertFromErrno(errno);
cbParameter = sizeof(cPagesMemInactive);
if ( RT_SUCCESS(rc)
&& sysctlbyname("vm.stats.vm.v_inactive_count", &cPagesMemInactive, &cbParameter, NULL, 0))
rc = RTErrConvertFromErrno(errno);
+#if __FreeBSD_version < 1200016
cbParameter = sizeof(cPagesMemCached);
if ( RT_SUCCESS(rc)
&& sysctlbyname("vm.stats.vm.v_cache_count", &cPagesMemCached, &cbParameter, NULL, 0))
rc = RTErrConvertFromErrno(errno);
+#endif
cbParameter = sizeof(cbPage);
if ( RT_SUCCESS(rc)
&& sysctlbyname("hw.pagesize", &cbPage, &cbParameter, NULL, 0))
rc = RTErrConvertFromErrno(errno);
if (RT_SUCCESS(rc))
- *pcb = (cPagesMemFree + cPagesMemInactive + cPagesMemCached ) * cbPage;
+ *pcb = ((uint64_t)cPagesMemFree + cPagesMemInactive + cPagesMemCached) * cbPage;
return rc;
}