From e4ebcc1a37a7e66205f477a7d2805fb5d0ce3d3b Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 15 Mar 2011 14:18:22 +0100 Subject: [PATCH 01/10] cocoa: do not create a spurious window for -version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When invoked with -version, qemu will exit just after displaying the version, so there is no need to create a window. Also handles --XXX options. Signed-off-by: Tristan Gingold Signed-off-by: Andreas Färber --- ui/cocoa.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 20f91bc642..1ff1ac641f 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -865,10 +865,19 @@ int main (int argc, const char * argv[]) { /* In case we don't need to display a window, let's not do that */ for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-vnc") || - !strcmp(argv[i], "-nographic") || - !strcmp(argv[i], "-curses")) { + const char *opt = argv[i]; + + if (opt[0] == '-') { + /* Treat --foo the same as -foo. */ + if (opt[1] == '-') { + opt++; + } + if (!strcmp(opt, "-vnc") || + !strcmp(opt, "-nographic") || + !strcmp(opt, "-version") || + !strcmp(opt, "-curses")) { return qemu_main(gArgc, gArgv); + } } } From d9cbb0f3ed0e3a185a61a18de856d51cf7789bf5 Mon Sep 17 00:00:00 2001 From: Alexandre Raymond Date: Fri, 27 May 2011 13:22:28 -0400 Subject: [PATCH 02/10] Fix compilation warning due to incorrectly specified type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In audio/coreaudio.c, a variable named "str" was assigned "const char" values, which resulted in the following warnings: -----8<----- audio/coreaudio.c: In function ‘coreaudio_logstatus’: audio/coreaudio.c:59: warning: initialization discards qualifiers from pointer target type audio/coreaudio.c:63: warning: assignment discards qualifiers from pointer target type (...) -----8<----- Signed-off-by: Alexandre Raymond Acked-by: Stefan Weil Signed-off-by: Andreas Färber --- audio/coreaudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio/coreaudio.c b/audio/coreaudio.c index 0a26413d75..3bd75cdda4 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -56,7 +56,7 @@ typedef struct coreaudioVoiceOut { static void coreaudio_logstatus (OSStatus status) { - char *str = "BUG"; + const char *str = "BUG"; switch(status) { case kAudioHardwareNoError: From 9851484f3d4afea83b46cc0974758ab756edfacd Mon Sep 17 00:00:00 2001 From: Alexandre Raymond Date: Sun, 29 May 2011 18:22:49 -0400 Subject: [PATCH 03/10] Cocoa: avoid displaying window when command-line contains '-h' or '-help' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was already a check in place to avoid displaying a window in certain modes such as vnc, nographic or curses. Add a check for '-h' and '-help' to avoid displaying a window for a split- second before showing the usage information. Signed-off-by: Alexandre Raymond Signed-off-by: Andreas Färber --- ui/cocoa.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 1ff1ac641f..e1312d347a 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -872,7 +872,8 @@ int main (int argc, const char * argv[]) { if (opt[1] == '-') { opt++; } - if (!strcmp(opt, "-vnc") || + if (!strcmp(opt, "-h") || !strcmp(opt, "-help") || + !strcmp(opt, "-vnc") || !strcmp(opt, "-nographic") || !strcmp(opt, "-version") || !strcmp(opt, "-curses")) { From dfa5294fce3e035192b283fe0b6fd08be48d78da Mon Sep 17 00:00:00 2001 From: Alexandre Raymond Date: Sun, 29 May 2011 18:22:50 -0400 Subject: [PATCH 04/10] Remove warning in printf due to type mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ----8<---- qemu/target-lm32/translate.c: In function ‘gen_intermediate_code_internal’: qemu/target-lm32/translate.c:1135: warning: format ‘%zd’ expects type ‘signed size_t’, but argument 4 has type ‘int’ ----8<---- Both gen_opc_ptr and gen_opc_buf are "uint16_t *". The difference between pointers is a ptrdiff_t so printf needs '%td'. Signed-off-by: Alexandre Raymond Acked-by: Stefan Weil Signed-off-by: Andreas Färber --- target-lm32/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target-lm32/translate.c b/target-lm32/translate.c index eb2115814c..5e197258eb 100644 --- a/target-lm32/translate.c +++ b/target-lm32/translate.c @@ -1132,7 +1132,7 @@ static void gen_intermediate_code_internal(CPUState *env, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("\n"); log_target_disas(pc_start, dc->pc - pc_start, 0); - qemu_log("\nisize=%d osize=%zd\n", + qemu_log("\nisize=%d osize=%td\n", dc->pc - pc_start, gen_opc_ptr - gen_opc_buf); } #endif From d1722a27f552a22561104210e0afad4577878e53 Mon Sep 17 00:00:00 2001 From: Alexandre Raymond Date: Sun, 29 May 2011 18:22:48 -0400 Subject: [PATCH 05/10] configure: Fix check for fdatasync() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Under Darwin, a symbol exists for the fdatasync() function, so that our link test succeeds. However _POSIX_SYNCHRONIZED_IO is set to '-1'. According to POSIX:2008, a value of -1 means the feature is not supported. A value of 0 means supported at compilation time, and a value greater 0 means supported at both compilation and run time. Enable fdatasync() only if _POSIX_SYNCHRONIZED_IO is '>0'. Signed-off-by: Alexandre Raymond Signed-off-by: Andreas Färber --- configure | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/configure b/configure index c931ae860a..6101f4e491 100755 --- a/configure +++ b/configure @@ -2461,7 +2461,13 @@ fi fdatasync=no cat > $TMPC << EOF #include -int main(void) { return fdatasync(0); } +int main(void) { +#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 +return fdatasync(0); +#else +#abort Not supported +#endif +} EOF if compile_prog "" "" ; then fdatasync=yes From d3922ab5fa791ac1546140f2a8df86d632d8fd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sat, 28 May 2011 15:45:18 +0200 Subject: [PATCH 06/10] Fix libfdt warnings on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Building with libfdt results in the following warnings on Mac OS X: CC ppc-softmmu/device_tree.o In file included from /Users/andreas/QEMU/latest64/include/libfdt.h:54, from /Users/andreas/QEMU/qemu/device_tree.c:26: /Users/andreas/QEMU/qemu/libfdt_env.h:25:20: warning: endian.h: No such file or directory /Users/andreas/QEMU/qemu/libfdt_env.h:26:22: warning: byteswap.h: No such file or directory /Users/andreas/QEMU/qemu/libfdt_env.h:28:5: warning: "__BYTE_ORDER" is not defined /Users/andreas/QEMU/qemu/libfdt_env.h:28:21: warning: "__BIG_ENDIAN" is not defined Since QEMU's copy of libfdt_env.h only uses bswap_32() and bswap_64(), let QEMU's bswap.h take care of the headers and use its endianness define. Cc: Hollis Blanchard Signed-off-by: Andreas Färber Acked-by: Alexander Graf --- libfdt_env.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libfdt_env.h b/libfdt_env.h index ee0419f7ce..90d7f3b162 100644 --- a/libfdt_env.h +++ b/libfdt_env.h @@ -19,13 +19,9 @@ #ifndef _LIBFDT_ENV_H #define _LIBFDT_ENV_H -#include -#include -#include -#include -#include +#include "bswap.h" -#if __BYTE_ORDER == __BIG_ENDIAN +#ifdef HOST_WORDS_BIGENDIAN #define fdt32_to_cpu(x) (x) #define cpu_to_fdt32(x) (x) #define fdt64_to_cpu(x) (x) From 3bbbee18a4e72f92a5830d6937ec50c441ec7826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 29 May 2011 19:42:51 +0200 Subject: [PATCH 07/10] cocoa: Provide central qemu_main() prototype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a missing prototype warning in vl.c and obsoletes the prototype in cocoa.m. Adjust callers in cocoa.m to supply third argument, which is currently only used on Linux/ppc. The prototype is designed so that it could be shared with SDL and other frontends, if desired. Cc: Alexandre Raymond Signed-off-by: Andreas Färber --- qemu-common.h | 5 +++++ ui/cocoa.m | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/qemu-common.h b/qemu-common.h index 39fabc9e0f..109498dd4d 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -132,6 +132,11 @@ static inline char *realpath(const char *path, char *resolved_path) #endif /* !defined(NEED_CPU_H) */ +/* main function, renamed */ +#if defined(CONFIG_COCOA) +int qemu_main(int argc, char **argv, char **envp); +#endif + /* bottom halves */ typedef void QEMUBHFunc(void *opaque); diff --git a/ui/cocoa.m b/ui/cocoa.m index e1312d347a..1c54759775 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -23,6 +23,7 @@ */ #import +#include #include "qemu-common.h" #include "console.h" @@ -61,7 +62,6 @@ int bitsPerPixel; } QEMUScreen; -int qemu_main(int argc, char **argv); // main defined in qemu/vl.c NSWindow *normalWindow; id cocoaView; static DisplayChangeListener *dcl; @@ -794,7 +794,7 @@ - (void)startEmulationWithArgc:(int)argc argv:(char**)argv COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n"); int status; - status = qemu_main(argc, argv); + status = qemu_main(argc, argv, *_NSGetEnviron()); exit(status); } @@ -877,7 +877,7 @@ int main (int argc, const char * argv[]) { !strcmp(opt, "-nographic") || !strcmp(opt, "-version") || !strcmp(opt, "-curses")) { - return qemu_main(gArgc, gArgv); + return qemu_main(gArgc, gArgv, *_NSGetEnviron()); } } } From e949467ba6e9829be0a2fc7ec27ec544d7bd3a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 2 Jun 2011 20:51:22 +0200 Subject: [PATCH 08/10] cocoa: Revert dependency on VNC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 821601ea5b02a68ada479731a4d3d07a9876632a (Make VNC support optional) cocoa.o was moved from ui-obj-$(CONFIG_COCOA) to vnc-obj-$(CONFIG_COCOA), adding a dependency on $(CONFIG_VNC). That must've been unintentional. Cc: Jes Sorensen Cc: Anthony Liguori Signed-off-by: Andreas Färber --- Makefile.objs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.objs b/Makefile.objs index 52d8b23045..509ab39b7f 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -128,6 +128,7 @@ common-obj-y += $(addprefix audio/, $(audio-obj-y)) ui-obj-y += keymaps.o ui-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o +ui-obj-$(CONFIG_COCOA) += cocoa.o ui-obj-$(CONFIG_CURSES) += curses.o vnc-obj-y += vnc.o d3des.o vnc-obj-y += vnc-enc-zlib.o vnc-enc-hextile.o @@ -135,7 +136,6 @@ vnc-obj-y += vnc-enc-tight.o vnc-palette.o vnc-obj-y += vnc-enc-zrle.o vnc-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o -vnc-obj-$(CONFIG_COCOA) += cocoa.o ifdef CONFIG_VNC_THREAD vnc-obj-y += vnc-jobs-async.o else From 7fee199cf9704587d4ed9eb23044970f2206debc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 9 Jun 2011 20:53:32 +0200 Subject: [PATCH 09/10] cocoa: Avoid warning related to multiple handleEvent: definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid compiler confusion as to which method signature to use for the handleEvent: selector on OSX >= 10.6 by making the variable type-safe as opposed to generic 'id' type. Requires moving the variable definition to after the class definition. ----8<---- ui/cocoa.m: In function ‘cocoa_refresh’: ui/cocoa.m:997: warning: multiple methods named ‘-handleEvent:’ found /System/Library/Frameworks/AppKit.framework/Headers/NSTextInputContext.h:84: warning: using ‘-(BOOL)handleEvent:(NSEvent *)theEvent’ ui/cocoa.m:272: warning: also found ‘-(void)handleEvent:(NSEvent *)event’ ----8<--- Reported-by: Alexandre Raymond Signed-off-by: Andreas Färber Tested-by: Alexandre Raymond --- ui/cocoa.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 1c54759775..515e684dd2 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -63,7 +63,6 @@ } QEMUScreen; NSWindow *normalWindow; -id cocoaView; static DisplayChangeListener *dcl; int gArgc; @@ -278,6 +277,8 @@ - (float) cdy; - (QEMUScreen) gscreen; @end +QemuCocoaView *cocoaView; + @implementation QemuCocoaView - (id)initWithFrame:(NSRect)frameRect { From f97742d0d36810ea72a2bd40b3abb890589ea3b8 Mon Sep 17 00:00:00 2001 From: Alexandre Raymond Date: Mon, 6 Jun 2011 23:34:10 -0400 Subject: [PATCH 10/10] Darwin: Fix compilation warning regarding the deprecated daemon() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes since v1: create a wrapper function named qemu_daemon() in oslib-posix.c instead of putting the OS specific workaround in qemu-nbd.c directly. On OSX >= 10.5, daemon() is deprecated, resulting in the following warning: ----8<---- qemu-nbd.c: In function ‘main’: qemu-nbd.c:371: warning: ‘daemon’ is deprecated (declared at /usr/include/stdlib.h:289) ----8<---- The following trick, used in mDNSResponder, takes care of this warning: http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-258.18/mDNSPosix/PosixDaemon.c On OSX, it temporarily renames the daemon() function before including stdlib.h and declares it manually as an extern function. This way, the compiler does not see the declaration from stdlib.h and thus does not display the warning. Signed-off-by: Alexandre Raymond Cc: Blue Swirl Signed-off-by: Andreas Färber --- osdep.h | 1 + oslib-posix.c | 16 ++++++++++++++++ qemu-nbd.c | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/osdep.h b/osdep.h index 970d767078..6eb9a49ec8 100644 --- a/osdep.h +++ b/osdep.h @@ -88,6 +88,7 @@ # define QEMU_GNUC_PREREQ(maj, min) 0 #endif +int qemu_daemon(int nochdir, int noclose); void *qemu_memalign(size_t alignment, size_t size); void *qemu_vmalloc(size_t size); void qemu_vfree(void *ptr); diff --git a/oslib-posix.c b/oslib-posix.c index 7bc5f7cf09..3a18e865f3 100644 --- a/oslib-posix.c +++ b/oslib-posix.c @@ -26,11 +26,27 @@ * THE SOFTWARE. */ +/* The following block of code temporarily renames the daemon() function so the + compiler does not see the warning associated with it in stdlib.h on OSX */ +#ifdef __APPLE__ +#define daemon qemu_fake_daemon_function +#include +#undef daemon +extern int daemon(int, int); +#endif + #include "config-host.h" #include "sysemu.h" #include "trace.h" #include "qemu_socket.h" + + +int qemu_daemon(int nochdir, int noclose) +{ + return daemon(nochdir, noclose); +} + void *qemu_oom_check(void *ptr) { if (ptr == NULL) { diff --git a/qemu-nbd.c b/qemu-nbd.c index 110d78e6a4..d91c02ce49 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -359,7 +359,7 @@ int main(int argc, char **argv) if (!verbose) { /* detach client and server */ - if (daemon(0, 0) == -1) { + if (qemu_daemon(0, 0) == -1) { err(EXIT_FAILURE, "Failed to daemonize"); } }