[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/19] win32: wrap socket close() with an exception handler
From: |
marcandre . lureau |
Subject: |
[PULL 06/19] win32: wrap socket close() with an exception handler |
Date: |
Sun, 28 May 2023 17:20:03 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Since commit abe34282 ("win32: avoid mixing SOCKET and file descriptor
space"), we set HANDLE_FLAG_PROTECT_FROM_CLOSE on the socket FD, to
prevent closing the HANDLE with CloseHandle. This raises an exception
which under gdb is fatal, and qemu exits.
Let's catch the expected error instead.
Note: this appears to work, but the mingw64 macro is not well documented
or tested, and it's not obvious how it is meant to be used.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20230515132440.1025315-1-marcandre.lureau@redhat.com>
---
include/sysemu/os-win32.h | 4 ++++
util/oslib-win32.c | 23 +++++++++++++++++------
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 15c296e0eb..65f6c9ea57 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -259,6 +259,10 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len,
int flags);
ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *addr, socklen_t *addrlen);
+EXCEPTION_DISPOSITION
+win32_close_exception_handler(struct _EXCEPTION_RECORD*, void*,
+ struct _CONTEXT*, void*);
+
#ifdef __cplusplus
}
#endif
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index a98638729a..fafbab80b4 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -479,6 +479,13 @@ int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
return ret;
}
+EXCEPTION_DISPOSITION
+win32_close_exception_handler(struct _EXCEPTION_RECORD*,
+ void*, struct _CONTEXT*, void*)
+{
+ return EXCEPTION_EXECUTE_HANDLER;
+}
+
#undef close
int qemu_close_socket_osfhandle(int fd)
{
@@ -504,12 +511,16 @@ int qemu_close_socket_osfhandle(int fd)
return -1;
}
- /*
- * close() returns EBADF since we PROTECT_FROM_CLOSE the underlying handle,
- * but the FD is actually freed
- */
- if (close(fd) < 0 && errno != EBADF) {
- return -1;
+ __try1(win32_close_exception_handler) {
+ /*
+ * close() returns EBADF since we PROTECT_FROM_CLOSE the underlying
+ * handle, but the FD is actually freed
+ */
+ if (close(fd) < 0 && errno != EBADF) {
+ return -1;
+ }
+ }
+ __except1 {
}
if (!SetHandleInformation((HANDLE)s, flags, flags)) {
--
2.40.1
- [PULL 00/19] Ui patches, marcandre . lureau, 2023/05/28
- [PULL 01/19] ui/gtk: fix passing y0_top parameter to scanout, marcandre . lureau, 2023/05/28
- [PULL 03/19] ui/gtk-egl: fix scaling for cursor position in scanout mode, marcandre . lureau, 2023/05/28
- [PULL 02/19] ui/gtk: use widget size for cursor motion event, marcandre . lureau, 2023/05/28
- [PULL 04/19] ui/sdl2: fix surface_gl_update_texture: Assertion 'gls' failed, marcandre . lureau, 2023/05/28
- [PULL 05/19] ui/dbus: fix compilation when GBM && !OPENGL, marcandre . lureau, 2023/05/28
- [PULL 06/19] win32: wrap socket close() with an exception handler,
marcandre . lureau <=
- [PULL 07/19] virtio-gpu: add a FIXME for virtio_gpu_load(), marcandre . lureau, 2023/05/28
- [PULL 08/19] gtk: add gl-area support on win32, marcandre . lureau, 2023/05/28
- [PULL 09/19] ui/dbus: add a FIXME about texture/dmabuf scanout handling, marcandre . lureau, 2023/05/28
- [PULL 10/19] ui/sdl2: Grab Alt+Tab also in fullscreen mode, marcandre . lureau, 2023/05/28
- [PULL 11/19] ui/sdl2: Grab Alt+F4 also under Windows, marcandre . lureau, 2023/05/28
- [PULL 12/19] ui/sdl2: disable SDL_HINT_GRAB_KEYBOARD on Windows, marcandre . lureau, 2023/05/28
- [PULL 13/19] ui/cursor: make width/height unsigned 16-bit integer, marcandre . lureau, 2023/05/28
- [PULL 14/19] virtio-input: generalize virtio_input_key_config(), marcandre . lureau, 2023/05/28
- [PULL 15/19] ui: add the infrastructure to support MT events, marcandre . lureau, 2023/05/28
- [PULL 16/19] virtio-input: add a virtio-mulitouch device, marcandre . lureau, 2023/05/28