summaryrefslogtreecommitdiff
path: root/include/sysemu/os-win32.h
AgeCommit message (Collapse)AuthorFilesLines
2016-11-01log: Add locking to large logging blocksRichard Henderson1-0/+15
Reuse the existing locking provided by stdio to keep in_asm, cpu, op, op_opt, op_ind, and out_asm as contiguous blocks. While it isn't possible to interleave e.g. in_asm or op_opt logs because of the TB lock protecting all code generation, it is possible to interleave cpu logs, or to interleave a cpu dump with an out_asm dump. For mingw32, we appear to have no viable solution for this. The locking functions are not properly exported from the system runtime library. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Richard Henderson <rth@twiddle.net>
2016-03-10osdep: remove use of socket_error() from all codeDaniel P. Berrange1-2/+0
Now that QEMU wraps the Win32 sockets methods to automatically set errno upon failure, there is no reason for callers to use the socket_error() method. They can rely on accessing errno even on Win32. Remove all use of socket_error() from general code, leaving it as a static method in oslib-win32.c only. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10osdep: add wrappers for socket functionsDaniel P. Berrange1-0/+79
The windows socket functions look identical to the normal POSIX sockets functions, but instead of setting errno, the caller needs to call WSAGetLastError(). QEMU has tried to deal with this incompatibility by defining a socket_error() method that callers must use that abstracts the difference between WSAGetLastError() and errno. This approach is somewhat error prone though - many callers of the sockets functions are just using errno directly because it is easy to forget the need use a QEMU specific wrapper. It is not always immediately obvious that a particular function will in fact call into Windows sockets functions, so the dev may not even realize they need to use socket_error(). This introduces an alternative approach to portability inspired by the way GNULIB fixes portability problems. We use a macro to redefine the original socket function names to refer to a QEMU wrapper function. The wrapper function calls the original Win32 sockets method and then sets errno from the WSAGetLastError() value. Thus all code can simply call the normal POSIX sockets APIs are have standard errno reporting on error, even on Windows. This makes the socket_error() method obsolete. We also bring closesocket & ioctlsocket into this approach. Even though they are non-standard Win32 names, we can't wrap the normal close/ioctl methods since there's no reliable way to distinguish between a file descriptor and HANDLE in Win32. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10osdep: fix socket_error() to work with Mingw64Daniel P. Berrange1-26/+1
Historically QEMU has had a socket_error() macro that was defined to map to WSASocketError(). The os-win32.h header file would define errno constants that mapped to the WSA error constants. This worked fine with Mingw32 since its header files never defined any errno values, nor did it even provide an errno.h. So callers of socket_error() could match on traditional Exxxx constants and it would all "just work". With Mingw64 though, things work rather differently. First there is an errno.h file which defines all the traditional errno constants you'd expect from a UNIX platform. There is then a winerror.h which defined the WSA error constants. Crucially the WSAExxxx errno values in winerror.h do not match the Exxxx errno values in error.h. If QEMU had only imported winerror.h it would still work, but the qemu/osdep.h file unconditionally imports errno.h. So callers of socket_error() will get now WSAExxxx values back and compare them to the Exxx constants. This will always fail silently at runtime. To solve this QEMU needs to stop assuming the WSAExxxx constant values match the Exxx constant values. Thus the socket_error() macro is turned into a small function that re-maps WSAExxxx values into Exxx. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-02-11w32: include winsock2.h before windows.hPaolo Bonzini1-1/+1
Recent Fedora complains while compiling ui/sdl.c: /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp] And with this patch we dutifully obey. Stefan Weil: Without that patch, windows.h will include winsock.h (which conflicts with winsock2.h) when compiling sdl.c. Normally we define WIN32_LEAN_AND_MEAN, and windows.h won't include winsock.h. include/ui/sdl2.h and ui/sdl.c undefine that macro, so the order of the include files is important. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2015-11-30oslib-win32: Change return type of function getpagesizeStefan Weil1-1/+1
getpagesize on Linux returns an int. Fix QEMU's implementation for Windows to return an int (instead of size_t), too. This fixes a compiler warning which was introduced recently (commit 093e3c42). Signed-off-by: Stefan Weil <sw@weilnetz.de>
2015-09-24oslib-win32: only provide localtime_r/gmtime_r if missingDaniel P. Berrange1-0/+2
The oslib-win32 file currently provides a localtime_r and gmtime_r replacement unconditionally. Some versions of Mingw-w64 would provide crude macros for localtime_r/gmtime_r which QEMU takes care to disable. Latest versions of Mingw-w64 now provide actual functions for localtime_r/gmtime_r, but with a twist that you have to include unistd.h or pthread.h before including time.h. By luck some files in QEMU have such an include order, resulting in compile errors: CC util/osdep.o In file included from include/qemu-common.h:48:0, from util/osdep.c:48: include/sysemu/os-win32.h:77:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-decls] struct tm *gmtime_r(const time_t *timep, struct tm *result); ^ In file included from include/qemu-common.h:35:0, from util/osdep.c:48: /usr/i686-w64-mingw32/sys-root/mingw/include/time.h:272:107: note: previous definition of 'gmtime_r' was here In file included from include/qemu-common.h:48:0, from util/osdep.c:48: include/sysemu/os-win32.h:79:12: error: redundant redeclaration of 'localtime_r' [-Werror=redundant-decls] struct tm *localtime_r(const time_t *timep, struct tm *result); ^ In file included from include/qemu-common.h:35:0, from util/osdep.c:48: /usr/i686-w64-mingw32/sys-root/mingw/include/time.h:269:107: note: previous definition of 'localtime_r' was here This change adds a configure test to see if localtime_r exits, and only enables the QEMU impl if missing. We also re-arrange qemu-common.h try attempt to guarantee that all source files get unistd.h before time.h and thus see the localtime_r/gmtime_r defs. [sw: Use "official" spellings for Mingw-w64, MinGW in comments.] [sw: Terminate sentences with a dot in comments.] Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Denis V. Lunev <den@openvz.org> Signed-off-by: Stefan Weil <sw@weilnetz.de>
2015-08-19qemu-common.h: Move Win32 fixups into os-win32.hPeter Maydell1-0/+18
qemu-common.h includes some fixups for things the Win32 headers don't define or define weirdly. These really belong in os-win32.h, so move them there. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2015-04-28os-win32: drop ffs(3) prototypeStefan Hajnoczi1-3/+0
The lack of ffs(3) in the MinGW headers is a hint that we shouldn't rely on it. MinGW 4.9.2 does not make it available for linking when QEMU's ./configure --enable-debug is used (release builds are fine though). Now that all QEMU code has been switched to ctz32() there is no need for ffs(3). Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 1427124571-28598-9-git-send-email-stefanha@redhat.com Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2015-02-16utils: drop strtok_r from envlist_parseOlga Krishtal1-1/+0
The problem is that mingw 4.9.1 fails to compile the code with the following warning: /mingw/include/string.h:88:9: note: previous declaration of 'strtok_r' was here char *strtok_r(char * __restrict__ _Str, const char * __restrict__ _Delim, char ** __restrict__ __last); /include/sysemu/os-win32.h:83:7: warning: redundant redeclaration of 'strtok_r' [-Wredundant-decls] char *strtok_r(char *str, const char *delim, char **saveptr); The problem is that compiles just fine on previous versions of mingw. Compiler version check here is not a good idea. Though fortunately strtok_r is used only once in the code and we could simply rewrite the code without it. Signed-off-by: Olga Krishtal <okrishtal@parallels.com> Signed-off-by: Denis V. Lunev <den@openvz.org> CC: Eric Blake <eblake@redhat.com> CC: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2014-06-19memory: move preallocation code out of exec.cPaolo Bonzini1-0/+2
So that backends can use it. Since we need the page size for efficiency, move code to compute it out of translate-all.c and into util/oslib-win32.c. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2013-04-22Add option to mlock qemu and guest memorySatoru Moriya1-0/+5
In certain scenario, latency induced by paging is significant and memory locking is needed. Also, in the scenario with untrusted guests, latency improvement due to mlock is desired. This patch introduces a following new option to mlock guest and qemu memory: -realtime mlock=on|off Signed-off-by: Satoru Moriya <satoru.moriya@hds.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1366382526-26146-1-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-23Replace all setjmp()/longjmp() with sigsetjmp()/siglongjmp()Peter Maydell1-0/+8
The setjmp() function doesn't specify whether signal masks are saved and restored; on Linux they are not, but on BSD (including MacOSX) they are. We want to have consistent behaviour across platforms, so we should always use "don't save/restore signal mask" (this is also generally going to be faster). This also works around a bug in MacOSX where the signal-restoration on longjmp() affects the signal mask for a completely different thread, not just the mask for the thread which did the longjmp. The most visible effect of this was that ctrl-C was ignored on MacOSX because the CPU thread did a longjmp which resulted in its signal mask being applied to every thread, so that all threads had SIGINT and SIGTERM blocked. The POSIX-sanctioned portable way to do a jump without affecting signal masks is to siglongjmp() to a sigjmp_buf which was created by calling sigsetjmp() with a zero savemask parameter, so change all uses of setjmp()/longjmp() accordingly. [Technically POSIX allows sigsetjmp(buf, 0) to save the signal mask; however the following siglongjmp() must not restore the signal mask, so the pair can be effectively considered as "sigjmp/longjmp which don't touch the mask".] For Windows we provide a trivial sigsetjmp/siglongjmp in terms of setjmp/longjmp -- this is OK because no user will ever pass a non-zero savemask. The setjmp() uses in tests/tcg/test-i386.c and tests/tcg/linux-test.c are left untouched because these are self-contained singlethreaded test programs intended to be run under QEMU's Linux emulation, so they have neither the portability nor the multithreading issues to deal with. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <rth@twiddle.net> Tested-by: Stefan Weil <sw@weilnetz.de> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2013-02-02util: Fix compilation of envlist.c for MinGWStefan Weil1-0/+2
MinGW has no strtok_r, so we need a declaration in sysemu/os-win32.h. We must also fix the include statements in util/envlist.c to include that file. We currently don't need an implementation of strtok_r because the code is compiled but not linked for MinGW. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-12-19softmmu: move include files to include/sysemu/Paolo Bonzini1-0/+99
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>