diff mbox series

[v3,05/16] util/oslib-win32: add qemu_get_host_physmem implementation

Message ID 20200724064509.331-6-alex.bennee@linaro.org
State Superseded
Headers show
Series candidate fixes for 5.1-rc1 (testing, semihosting, OOM tcg, x86 fpu) | expand

Commit Message

Alex Bennée July 24, 2020, 6:44 a.m. UTC
Compile tested only.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Cc: Stefan Weil <sw@weilnetz.de>

---
v2
  - used more widely available GlobalMemoryStatusEx
  - dropped Phillipe's r-b due to the change
---
 util/oslib-win32.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

-- 
2.20.1

Comments

Stefan Weil July 24, 2020, 6:51 a.m. UTC | #1
Am 24.07.20 um 08:44 schrieb Alex Bennée:

> Compile tested only.

>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> Cc: Stefan Weil <sw@weilnetz.de>

>

> ---

> v2

>   - used more widely available GlobalMemoryStatusEx

>   - dropped Phillipe's r-b due to the change

> ---

>  util/oslib-win32.c | 7 ++++++-

>  1 file changed, 6 insertions(+), 1 deletion(-)

>

> diff --git a/util/oslib-win32.c b/util/oslib-win32.c

> index 31030463cc9..a74ee5a3aa7 100644

> --- a/util/oslib-win32.c

> +++ b/util/oslib-win32.c

> @@ -831,6 +831,11 @@ char *qemu_get_host_name(Error **errp)

>  

>  size_t qemu_get_host_physmem(void)

>  {

> -    /* currently unimplemented */

> +    MEMORYSTATUSEX statex;

> +    statex.dwLength = sizeof(statex);

> +

> +    if (!GlobalMemoryStatusEx(&statex)) {

> +        return statex.ullTotalPhys;

> +    }

>      return 0;

>  }



Thanks.

The logic must be reversed, as GlobalMemoryStatusEx returns a nonzero
value when it succeeded.

When that is fixed, you may add

Reviewed-by: Stefan Weil <sw@weilnetz.de>
diff mbox series

Patch

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 31030463cc9..a74ee5a3aa7 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -831,6 +831,11 @@  char *qemu_get_host_name(Error **errp)
 
 size_t qemu_get_host_physmem(void)
 {
-    /* currently unimplemented */
+    MEMORYSTATUSEX statex;
+    statex.dwLength = sizeof(statex);
+
+    if (!GlobalMemoryStatusEx(&statex)) {
+        return statex.ullTotalPhys;
+    }
     return 0;
 }