From owner-freebsd-virtualization@FreeBSD.ORG Sun Jun 30 08:54:37 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 33681EC3 for ; Sun, 30 Jun 2013 08:54:37 +0000 (UTC) (envelope-from Martin.Birgmeier@aon.at) Received: from email.aon.at (smtpout02.highway.telekom.at [195.3.96.113]) by mx1.freebsd.org (Postfix) with ESMTP id 81ECC1820 for ; Sun, 30 Jun 2013 08:54:35 +0000 (UTC) Received: (qmail 11396 invoked from network); 30 Jun 2013 08:54:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on WARSBL507.highway.telekom.at X-Spam-Level: Received: from 178-190-56-101.adsl.highway.telekom.at (HELO gandalf.xyzzy) ([178.190.56.101]) (envelope-sender ) by smarthub82.res.a1.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 30 Jun 2013 08:54:33 -0000 X-A1Mail-Track-Id: 1372582473:11383:smarthub82:178.190.56.101:1 Received: from mizar-v1.xyzzy (mizar-v1.xyzzy [192.168.1.51]) by gandalf.xyzzy (8.14.5/8.14.5) with ESMTP id r5U8sX1a013514 for ; Sun, 30 Jun 2013 10:54:33 +0200 (CEST) (envelope-from Martin.Birgmeier@aon.at) Message-ID: <51CFF24A.5010103@aon.at> Date: Sun, 30 Jun 2013 10:54:34 +0200 From: Martin Birgmeier User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130628 Thunderbird/17.0.7 MIME-Version: 1.0 To: freebsd-virtualization@freebsd.org Subject: VirtualBox GUI: Fix memory size computation (native implementation of RTSystemQueryTotalRam) X-Enigmail-Version: 1.5.1 Content-Type: multipart/mixed; boundary="------------020301080806090508080404" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jun 2013 08:54:37 -0000 This is a multi-part message in MIME format. --------------020301080806090508080404 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit VirtualBox on FreeBSD needs an implementation of RTSystemQueryTotalRam. I have put together the attached patches, comments are welcome. Regards, Martin --------------020301080806090508080404 Content-Type: text/plain; charset=ISO-8859-1; name="patch-src-VBox-Runtime-Makefile.kmk" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch-src-VBox-Runtime-Makefile.kmk" --- ./src/VBox/Runtime/Makefile.kmk.ORIG 2013-06-21 14:27:18.000000000 +0200 +++ ./src/VBox/Runtime/Makefile.kmk 2013-06-30 09:44:38.000000000 +0200 @@ -844,7 +844,7 @@ r3/posix/RTMemProtect-posix.cpp \ r3/posix/RTPathUserHome-posix.cpp \ r3/posix/RTSystemQueryOSInfo-posix.cpp \ - r3/posix/RTSystemQueryTotalRam-posix.cpp \ + r3/freebsd/RTSystemQueryTotalRam-freebsd.cpp \ r3/posix/RTTimeNow-posix.cpp \ r3/posix/RTTimeSet-posix.cpp \ r3/posix/dir-posix.cpp \ --------------020301080806090508080404 Content-Type: text/plain; charset=ISO-8859-1; name="patch-src-VBox-Runtime-r3-freebsd-RTSystemQueryTotalRam-freebsd.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="patch-src-VBox-Runtime-r3-freebsd-RTSystemQueryTotalRam-free"; filename*1="bsd.cpp" --- ./src/VBox/Runtime/r3/freebsd/RTSystemQueryTotalRam-freebsd.cpp.ORIG 2013-06-30 09:27:59.000000000 +0200 +++ ./src/VBox/Runtime/r3/freebsd/RTSystemQueryTotalRam-freebsd.cpp 2013-06-30 09:51:29.000000000 +0200 @@ -0,0 +1,80 @@ +/* $Id: RTSystemQueryTotalRam-freebsd.cpp $ */ +/** @file + * IPRT - RTSystemQueryTotalRam, FreeBSD style + */ + +/* + * Copyright (C) 2013 Martin Birgmeier, 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. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/******************************************************************************* +* Header Files * +*******************************************************************************/ +#include +#include "internal/iprt.h" + +#include +#include +#include + +/* FreeBSD */ +#include +#include +#include + +RTDECL(int) RTSystemQueryTotalRam(uint64_t *pcb) +{ + int mib[2]; + size_t pcblen = sizeof(*pcb); + + AssertPtrReturn(pcb, VERR_INVALID_POINTER); + + mib[0] = CTL_HW; + mib[1] = HW_PHYSMEM; /* HW_REALMEM is also possible, but + includes non-main memory as well */ + *pcb = 0; + if (sysctl(mib, 2, pcb, &pcblen, NULL, 0) == 0) { + if (pcblen == sizeof(*pcb)) + return VINF_SUCCESS; + else + return VERR_NO_MEMORY; /* XXX */ + } + return RTErrConvertFromErrno(errno); +} + +RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb) +{ + int mib[2]; + size_t pcblen = sizeof(*pcb); + + AssertPtrReturn(pcb, VERR_INVALID_POINTER); + + mib[0] = CTL_HW; + mib[1] = HW_USERMEM; + *pcb = 0; + if (sysctl(mib, 2, pcb, &pcblen, NULL, 0) == 0) { + if (pcblen == sizeof(*pcb)) + return VINF_SUCCESS; + else + return VERR_NO_MEMORY; /* XXX */ + } + return RTErrConvertFromErrno(errno); +} --------------020301080806090508080404--