qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PULL for 2.0 5/5] w32: Replace Windows specific data types


From: Stefan Weil
Subject: [Qemu-devel] [PULL for 2.0 5/5] w32: Replace Windows specific data types in common header files
Date: Thu, 20 Mar 2014 07:25:12 +0100

These header files are used by most QEMU source files. If they
depend on windows.h, all those source files do so, too.

All Windows specific data types which are replaced use identical
definitions for the 32 and 64 bit Windows APIs. HANDLE, LONG
and CRITICAL_SECTION are replaced by the compatible types
WinHandle, WinLong and WinCriticalSection.

Add an explicit dependency on qemu/winapi.h for some files which need it.
These sources use the Windows API (see comment after include statement)
and no longer get windows.h indirectly from other header files.

A workaround which was added in the previous patch is no longer needed.

Now 175 *.o files remain which still depend on windows.h.

Cc: Anthony Liguori <address@hidden>
Cc: Stefan Hajnoczi <address@hidden>
Cc: Andreas Färber <address@hidden>
Signed-off-by: Stefan Weil <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
 cpus.c                        |    4 +++-
 hw/intc/apic.c                |    3 ++-
 include/qemu/event_notifier.h |    8 ++------
 include/qemu/main-loop.h      |    4 ++--
 include/qemu/thread-win32.h   |   29 ++++++++++++++++++++---------
 include/qom/cpu.h             |    2 +-
 include/sysemu/os-win32.h     |    7 +++++++
 ui/vnc-enc-tight.c            |    5 -----
 util/event_notifier-win32.c   |    1 +
 util/qemu-thread-win32.c      |   17 +++++++++--------
 10 files changed, 47 insertions(+), 33 deletions(-)

diff --git a/cpus.c b/cpus.c
index 1104d61..ab5d15a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -39,7 +39,9 @@
 #include "qemu/bitmap.h"
 #include "qemu/seqlock.h"
 
-#ifndef _WIN32
+#ifdef _WIN32
+#include "qemu/winapi.h" /* SuspendThread, ... */
+#else
 #include "qemu/compatfd.h"
 #endif
 
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index 361ae90..6bb2d78 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -16,12 +16,13 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>
  */
-#include "qemu/thread.h"
+
 #include "hw/i386/apic_internal.h"
 #include "hw/i386/apic.h"
 #include "hw/i386/ioapic.h"
 #include "hw/pci/msi.h"
 #include "qemu/host-utils.h"
+#include "qemu/thread.h"
 #include "trace.h"
 #include "hw/i386/pc.h"
 #include "hw/i386/apic-msidef.h"
diff --git a/include/qemu/event_notifier.h b/include/qemu/event_notifier.h
index bdca689..c5cf381 100644
--- a/include/qemu/event_notifier.h
+++ b/include/qemu/event_notifier.h
@@ -15,13 +15,9 @@
 
 #include "qemu-common.h"
 
-#ifdef _WIN32
-#include "qemu/winapi.h"
-#endif
-
 struct EventNotifier {
 #ifdef _WIN32
-    HANDLE event;
+    WinHandle event;
 #else
     int rfd;
     int wfd;
@@ -40,7 +36,7 @@ int event_notifier_set_handler(EventNotifier *, 
EventNotifierHandler *);
 void event_notifier_init_fd(EventNotifier *, int fd);
 int event_notifier_get_fd(EventNotifier *);
 #else
-HANDLE event_notifier_get_handle(EventNotifier *);
+WinHandle event_notifier_get_handle(EventNotifier *);
 #endif
 
 #endif
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index 6f0200a..aefdc94 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -152,7 +152,7 @@ typedef void WaitObjectFunc(void *opaque);
  * @func: A function to be called when @handle is in a signaled state.
  * @opaque: A pointer-size value that is passed to @func.
  */
-int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+int qemu_add_wait_object(WinHandle handle, WaitObjectFunc *func, void *opaque);
 
 /**
  * qemu_del_wait_object: Unregister a callback for a Windows handle
@@ -163,7 +163,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque);
  * @func: The function that was passed to qemu_add_wait_object.
  * @opaque: A pointer-size value that was passed to qemu_add_wait_object.
  */
-void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+void qemu_del_wait_object(WinHandle handle, WaitObjectFunc *func, void 
*opaque);
 #endif
 
 /* async I/O support */
diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h
index 7ade61a..b8b8e61 100644
--- a/include/qemu/thread-win32.h
+++ b/include/qemu/thread-win32.h
@@ -1,24 +1,35 @@
 #ifndef __QEMU_THREAD_WIN32_H
 #define __QEMU_THREAD_WIN32_H 1
-#include "qemu/winapi.h"
+
+/* WinCriticalSection is a substitute for CRITICAL_SECTION and
+ * introduced here to avoid dependencies on windows.h. */
+
+typedef struct {
+    WinHandle DebugInfo;
+    WinLong LockCount;
+    WinLong RecursionCount;
+    WinHandle OwningThread;
+    WinHandle LockSemaphore;
+    WinULong *SpinCount;
+} WinCriticalSection;
 
 struct QemuMutex {
-    CRITICAL_SECTION lock;
-    LONG owner;
+    WinCriticalSection lock;
+    WinLong owner;
 };
 
 struct QemuCond {
-    LONG waiters, target;
-    HANDLE sema;
-    HANDLE continue_event;
+    WinLong waiters, target;
+    WinHandle sema;
+    WinHandle continue_event;
 };
 
 struct QemuSemaphore {
-    HANDLE sema;
+    WinHandle sema;
 };
 
 struct QemuEvent {
-    HANDLE event;
+    WinHandle event;
 };
 
 typedef struct QemuThreadData QemuThreadData;
@@ -28,6 +39,6 @@ struct QemuThread {
 };
 
 /* Only valid for joinable threads.  */
-HANDLE qemu_thread_get_handle(QemuThread *thread);
+WinHandle qemu_thread_get_handle(QemuThread *thread);
 
 #endif
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index f99885a..1fe2ae4 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -215,7 +215,7 @@ struct CPUState {
 
     struct QemuThread *thread;
 #ifdef _WIN32
-    HANDLE hThread;
+    WinHandle hThread;
 #endif
     int thread_id;
     uint32_t host_tid;
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index d625612..a23d6aa 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -54,6 +54,13 @@
 # define EWOULDBLOCK  WSAEWOULDBLOCK
 #endif
 
+/* Define substitutes for the Win API types HANDLE, LONG, ULONG.
+ * These types are used to avoid dependencies on windows.h. */
+
+typedef void * WinHandle;
+typedef long WinLong;
+typedef unsigned long WinULong;
+
 #if defined(_WIN64)
 /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
  * If this parameter is NULL, longjump does no stack unwinding.
diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index 9b0f73d..3c5ff5a 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -27,11 +27,6 @@
  */
 
 #include "config-host.h"
-
-/* This needs to be before jpeglib.h line because of conflict with
-   INT32 definitions between jmorecfg.h (included by jpeglib.h) and
-   Win32 basetsd.h (included by windows.h). */
-#include "qemu/winapi.h" /* TODO: workaround, remove */
 #include "qemu-common.h"
 
 #ifdef CONFIG_VNC_PNG
diff --git a/util/event_notifier-win32.c b/util/event_notifier-win32.c
index 6dbb530..9f3f61d 100644
--- a/util/event_notifier-win32.c
+++ b/util/event_notifier-win32.c
@@ -13,6 +13,7 @@
 #include "qemu-common.h"
 #include "qemu/event_notifier.h"
 #include "qemu/main-loop.h"
+#include "qemu/winapi.h" /* CreateEvent, ... */
 
 int event_notifier_init(EventNotifier *e, int active)
 {
diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
index b9c957b..6c8c6f8 100644
--- a/util/qemu-thread-win32.c
+++ b/util/qemu-thread-win32.c
@@ -10,11 +10,10 @@
  * See the COPYING file in the top-level directory.
  *
  */
+
+#include "qemu/winapi.h" /* LocalFree, ... */
 #include "qemu-common.h"
 #include "qemu/thread.h"
-#include <process.h>
-#include <assert.h>
-#include <limits.h>
 
 static bool name_threads;
 
@@ -38,18 +37,20 @@ static void error_exit(int err, const char *msg)
 void qemu_mutex_init(QemuMutex *mutex)
 {
     mutex->owner = 0;
-    InitializeCriticalSection(&mutex->lock);
+    /* mutex->lock uses a data type which must fit CRITICAL_SECTION. */
+    g_assert(sizeof(mutex->lock) == sizeof(CRITICAL_SECTION));
+    InitializeCriticalSection((CRITICAL_SECTION *)&mutex->lock);
 }
 
 void qemu_mutex_destroy(QemuMutex *mutex)
 {
     assert(mutex->owner == 0);
-    DeleteCriticalSection(&mutex->lock);
+    DeleteCriticalSection((CRITICAL_SECTION *)&mutex->lock);
 }
 
 void qemu_mutex_lock(QemuMutex *mutex)
 {
-    EnterCriticalSection(&mutex->lock);
+    EnterCriticalSection((CRITICAL_SECTION *)&mutex->lock);
 
     /* Win32 CRITICAL_SECTIONs are recursive.  Assert that we're not
      * using them as such.
@@ -62,7 +63,7 @@ int qemu_mutex_trylock(QemuMutex *mutex)
 {
     int owned;
 
-    owned = TryEnterCriticalSection(&mutex->lock);
+    owned = TryEnterCriticalSection((CRITICAL_SECTION *)&mutex->lock);
     if (owned) {
         assert(mutex->owner == 0);
         mutex->owner = GetCurrentThreadId();
@@ -74,7 +75,7 @@ void qemu_mutex_unlock(QemuMutex *mutex)
 {
     assert(mutex->owner == GetCurrentThreadId());
     mutex->owner = 0;
-    LeaveCriticalSection(&mutex->lock);
+    LeaveCriticalSection((CRITICAL_SECTION *)&mutex->lock);
 }
 
 void qemu_cond_init(QemuCond *cond)
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]