[Spice-devel] [spice-gtk v3 4/7] Add os_is_64bit utility function
Frediano Ziglio
fziglio at redhat.com
Sat Sep 3 16:10:04 UTC 2016
Allow to know if the system is 64 bit or not.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
src/spice-util-priv.h | 3 +++
src/spice-util.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/src/spice-util-priv.h b/src/spice-util-priv.h
index 38b0deb..790cc06 100644
--- a/src/spice-util-priv.h
+++ b/src/spice-util-priv.h
@@ -32,6 +32,9 @@ gchar* spice_unix2dos(const gchar *str, gssize len);
gchar* spice_dos2unix(const gchar *str, gssize len);
void spice_mono_edge_highlight(unsigned width, unsigned hight,
const guint8 *and, const guint8 *xor, guint8 *dest);
+#ifdef G_OS_WIN32
+G_GNUC_INTERNAL gboolean os_is_64bit(void);
+#endif
G_END_DECLS
diff --git a/src/spice-util.c b/src/spice-util.c
index 86377b6..7f66d51 100644
--- a/src/spice-util.c
+++ b/src/spice-util.c
@@ -23,6 +23,9 @@
#include <string.h>
#include <glib.h>
#include <glib-object.h>
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
#include <spice/macros.h>
#include "spice-util-priv.h"
#include "spice-util.h"
@@ -477,3 +480,42 @@ void spice_mono_edge_highlight(unsigned width, unsigned height,
xor += bpl;
}
}
+
+#ifdef G_OS_WIN32
+/*
+ * Check if current process is running in Wow64 mode
+ * (32 bit on a 64 system)
+ */
+#ifndef _WIN64
+static BOOL is_wow64(void)
+{
+ BOOL bIsWow64 = FALSE;
+
+ typedef BOOL WINAPI IsWow64Process_t(HANDLE, PBOOL);
+ IsWow64Process_t *pIsWow64Process =
+ (IsWow64Process_t *) GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
+
+ if (pIsWow64Process)
+ pIsWow64Process(GetCurrentProcess(), &bIsWow64);
+
+ return bIsWow64;
+}
+#else
+static inline BOOL is_wow64(void)
+{
+ return FALSE;
+}
+#endif
+
+/*
+ * Check if OS is 64 bit
+ */
+gboolean os_is_64bit(void)
+{
+#ifdef _WIN64
+ return TRUE;
+#else
+ return is_wow64() != FALSE;
+#endif
+}
+#endif
--
2.7.4
More information about the Spice-devel
mailing list