From 7682e8580722f951559f372ba3d2b6170fdbe734 Mon Sep 17 00:00:00 2001 From: Nickolai Zeldovich Date: Mon, 7 Jan 2013 15:38:39 -0500 Subject: [PATCH 1/6] readline: avoid memcpy() of overlapping regions memcpy() for overlapping regions is undefined behavior; use memmove() instead in readline_hist_add(). [Keep tab characters since surrounding code still uses them -- Stefan] Signed-off-by: Nickolai Zeldovich Reviewed-by: Richard Henderson Signed-off-by: Stefan Hajnoczi --- readline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readline.c b/readline.c index 5fc9643c2b..a0c9638e4d 100644 --- a/readline.c +++ b/readline.c @@ -248,8 +248,8 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline) if (idx == READLINE_MAX_CMDS) { /* Need to get one free slot */ free(rs->history[0]); - memcpy(rs->history, &rs->history[1], - (READLINE_MAX_CMDS - 1) * sizeof(char *)); + memmove(rs->history, &rs->history[1], + (READLINE_MAX_CMDS - 1) * sizeof(char *)); rs->history[READLINE_MAX_CMDS - 1] = NULL; idx = READLINE_MAX_CMDS - 1; } From 75f13596452692fb7375ee558e9fb37cd649e603 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 5 Jan 2013 12:17:38 +0100 Subject: [PATCH 2/6] configure: Fix comment (copy+paste bug) Signed-off-by: Stefan Weil Signed-off-by: Stefan Hajnoczi --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index fe18ed2b25..148d5aa052 100755 --- a/configure +++ b/configure @@ -2705,7 +2705,7 @@ if compile_prog "" "" ; then byteswap_h=yes fi -# Search for bswap_32 function +# Search for bswap32 function bswap_h=no cat > $TMPC << EOF #include From 1d57db193f2eb619ccc9a60e76120379b757d9f2 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Mon, 7 Jan 2013 17:29:55 +0000 Subject: [PATCH 3/6] qga/channel-posix.c: Explicitly include string.h Explicitly include string.h to avoid warnings under MacOS X/clang about implicit declarations of strerror() and strlen(). Signed-off-by: Peter Maydell Reviewed-by: Stefan Weil Signed-off-by: Stefan Hajnoczi --- qga/channel-posix.c | 1 + 1 file changed, 1 insertion(+) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index d4fd628907..ca9e4aaaf9 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "qemu/osdep.h" #include "qemu/sockets.h" #include "qga/channel.h" From 68b891ec3937aa2e18eed5a403b1d9fd9b875084 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 7 Jan 2013 22:20:27 +0100 Subject: [PATCH 4/6] savevm: Remove MinGW specific code which is no longer needed QEMU provides a portable function qemu_gettimeofday instead of gettimeofday and also an implementation of localtime_r for MinGW. Signed-off-by: Stefan Weil Signed-off-by: Stefan Hajnoczi --- savevm.c | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/savevm.c b/savevm.c index 529d60ec1f..4e970ca0db 100644 --- a/savevm.c +++ b/savevm.c @@ -23,15 +23,6 @@ */ #include "config-host.h" - -#ifndef _WIN32 -#include -#endif - -#ifdef _WIN32 -#include -#endif - #include "qemu-common.h" #include "hw/hw.h" #include "hw/qdev.h" @@ -2093,13 +2084,8 @@ void do_savevm(Monitor *mon, const QDict *qdict) QEMUFile *f; int saved_vm_running; uint64_t vm_state_size; -#ifdef _WIN32 - struct _timeb tb; - struct tm *ptm; -#else - struct timeval tv; + qemu_timeval tv; struct tm tm; -#endif const char *name = qdict_get_try_str(qdict, "name"); /* Verify if there is a device that doesn't support snapshots and is writable */ @@ -2129,15 +2115,9 @@ void do_savevm(Monitor *mon, const QDict *qdict) memset(sn, 0, sizeof(*sn)); /* fill auxiliary fields */ -#ifdef _WIN32 - _ftime(&tb); - sn->date_sec = tb.time; - sn->date_nsec = tb.millitm * 1000000; -#else - gettimeofday(&tv, NULL); + qemu_gettimeofday(&tv); sn->date_sec = tv.tv_sec; sn->date_nsec = tv.tv_usec * 1000; -#endif sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock); if (name) { @@ -2149,15 +2129,9 @@ void do_savevm(Monitor *mon, const QDict *qdict) pstrcpy(sn->name, sizeof(sn->name), name); } } else { -#ifdef _WIN32 - time_t t = tb.time; - ptm = localtime(&t); - strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", ptm); -#else /* cast below needed for OpenBSD where tv_sec is still 'long' */ localtime_r((const time_t *)&tv.tv_sec, &tm); strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm); -#endif } /* Delete old snapshots of the same name */ From eb7ff6fb0bddb33991fa44586ac8e2e02019dc97 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 7 Jan 2013 23:08:13 +0100 Subject: [PATCH 5/6] Replace remaining gmtime, localtime by gmtime_r, localtime_r MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows removing of MinGW specific code and improves reentrancy for POSIX hosts. [Removed unused ret variable in qemu_get_timedate() to fix warning: vl.c: In function ‘qemu_get_timedate’: vl.c:451:16: error: variable ‘ret’ set but not used [-Werror=unused-but-set-variable] -- Stefan Hajnoczi] Signed-off-by: Stefan Weil Signed-off-by: Stefan Hajnoczi --- block.c | 10 ---------- block/vvfat.c | 4 ---- hw/omap1.c | 2 +- vl.c | 9 +++------ 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index 4e28c55bc7..60873eafea 100644 --- a/block.c +++ b/block.c @@ -3338,11 +3338,7 @@ char *get_human_readable_size(char *buf, int buf_size, int64_t size) char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn) { char buf1[128], date_buf[128], clock_buf[128]; -#ifdef _WIN32 - struct tm *ptm; -#else struct tm tm; -#endif time_t ti; int64_t secs; @@ -3352,15 +3348,9 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn) "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK"); } else { ti = sn->date_sec; -#ifdef _WIN32 - ptm = localtime(&ti); - strftime(date_buf, sizeof(date_buf), - "%Y-%m-%d %H:%M:%S", ptm); -#else localtime_r(&ti, &tm); strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm); -#endif secs = sn->vm_clock_nsec / 1000000000; snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d:%02d.%03d", diff --git a/block/vvfat.c b/block/vvfat.c index 83706ce556..06e6654824 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -529,13 +529,9 @@ static inline uint8_t fat_chksum(const direntry_t* entry) /* if return_time==0, this returns the fat_date, else the fat_time */ static uint16_t fat_datetime(time_t time,int return_time) { struct tm* t; -#ifdef _WIN32 - t=localtime(&time); /* this is not thread safe */ -#else struct tm t1; t = &t1; localtime_r(&time,t); -#endif if(return_time) return cpu_to_le16((t->tm_sec/2)|(t->tm_min<<5)|(t->tm_hour<<11)); return cpu_to_le16((t->tm_mday)|((t->tm_mon+1)<<5)|((t->tm_year-80)<<9)); diff --git a/hw/omap1.c b/hw/omap1.c index 8536e96687..e85f2e2423 100644 --- a/hw/omap1.c +++ b/hw/omap1.c @@ -2830,7 +2830,7 @@ static void omap_rtc_tick(void *opaque) s->round = 0; } - memcpy(&s->current_tm, localtime(&s->ti), sizeof(s->current_tm)); + localtime_r(&s->ti, &s->current_tm); if ((s->interrupts & 0x08) && s->ti == s->alarm_ti) { s->status |= 0x40; diff --git a/vl.c b/vl.c index f056c95807..aed4182ae8 100644 --- a/vl.c +++ b/vl.c @@ -448,21 +448,18 @@ StatusInfo *qmp_query_status(Error **errp) void qemu_get_timedate(struct tm *tm, int offset) { time_t ti; - struct tm *ret; time(&ti); ti += offset; if (rtc_date_offset == -1) { if (rtc_utc) - ret = gmtime(&ti); + gmtime_r(&ti, tm); else - ret = localtime(&ti); + localtime_r(&ti, tm); } else { ti -= rtc_date_offset; - ret = gmtime(&ti); + gmtime_r(&ti, tm); } - - memcpy(tm, ret, sizeof(struct tm)); } int qemu_timedate_diff(struct tm *tm) From c02e1eac887b1b0aee7361b1fcf889e7d47fed9d Mon Sep 17 00:00:00 2001 From: Julien Grall Date: Wed, 9 Jan 2013 18:10:22 +0000 Subject: [PATCH 6/6] hw/pc.c: Fix converting of ioport_register* to MemoryRegion The commit 258711 introduced MemoryRegion to replace ioport_region* for ioport 80h and F0h. A MemoryRegion needs to have both read and write callback otherwise a segfault will occur when an access is made. The previous behaviour of this both ioport is to return 0xffffffffffffffff. So keep this behaviour. Reported-by: Adam Lackorzynski Signed-off-by: Julien Grall Tested-by: Adam Lackorzynski Signed-off-by: Stefan Hajnoczi --- hw/pc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/pc.c b/hw/pc.c index df0c48e41b..90b1bf76d6 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -103,6 +103,11 @@ static void ioport80_write(void *opaque, hwaddr addr, uint64_t data, { } +static uint64_t ioport80_read(void *opaque, hwaddr addr, unsigned size) +{ + return 0xffffffffffffffff; +} + /* MSDOS compatibility mode FPU exception support */ static qemu_irq ferr_irq; @@ -123,6 +128,11 @@ static void ioportF0_write(void *opaque, hwaddr addr, uint64_t data, qemu_irq_lower(ferr_irq); } +static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size) +{ + return 0xffffffffffffffff; +} + /* TSC handling */ uint64_t cpu_get_tsc(CPUX86State *env) { @@ -960,6 +970,7 @@ static void cpu_request_exit(void *opaque, int irq, int level) static const MemoryRegionOps ioport80_io_ops = { .write = ioport80_write, + .read = ioport80_read, .endianness = DEVICE_NATIVE_ENDIAN, .impl = { .min_access_size = 1, @@ -969,6 +980,7 @@ static const MemoryRegionOps ioport80_io_ops = { static const MemoryRegionOps ioportF0_io_ops = { .write = ioportF0_write, + .read = ioportF0_read, .endianness = DEVICE_NATIVE_ENDIAN, .impl = { .min_access_size = 1,