diff -r 0b04a48f65cc tools/ioemu/aes.c --- a/tools/ioemu/aes.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/aes.c Thu Sep 27 11:50:43 2007 +0000 @@ -30,7 +30,9 @@ #include "vl.h" #include "aes.h" +#ifndef NDEBUG #define NDEBUG +#endif #include typedef uint32_t u32; diff -r 0b04a48f65cc tools/ioemu/audio/audio.c --- a/tools/ioemu/audio/audio.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/audio/audio.c Thu Sep 27 11:50:43 2007 +0000 @@ -207,7 +207,7 @@ static char *audio_alloc_prefix (const c strcat (r, s); for (i = 0; i < len; ++i) { - u[i] = toupper (u[i]); + u[i] = toupper ((uint8_t)u[i]); } } return r; @@ -446,7 +446,7 @@ static void audio_process_options (const /* copy while upper-casing, including trailing zero */ for (i = 0; i <= preflen; ++i) { - optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]); + optname[i + sizeof (qemu_prefix) - 1] = toupper ((uint8_t)prefix[i]); } strcat (optname, "_"); strcat (optname, opt->name); diff -r 0b04a48f65cc tools/ioemu/audio/mixeng.c --- a/tools/ioemu/audio/mixeng.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/audio/mixeng.c Thu Sep 27 11:50:43 2007 +0000 @@ -102,6 +102,7 @@ #undef SHIFT t_sample *mixeng_conv[2][2][2][2] = { +#ifndef _BSD { { { @@ -146,9 +147,11 @@ t_sample *mixeng_conv[2][2][2][2] = { } } } +#endif /* !_BSD */ }; f_sample *mixeng_clip[2][2][2][2] = { +#ifndef _BSD { { { @@ -193,6 +196,7 @@ f_sample *mixeng_clip[2][2][2][2] = { } } } +#endif /* !_BSD */ }; /* diff -r 0b04a48f65cc tools/ioemu/audio/ossaudio.c --- a/tools/ioemu/audio/ossaudio.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/audio/ossaudio.c Thu Sep 27 11:50:43 2007 +0000 @@ -21,10 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include #include #include #include +#if defined(__OpenBSD__) +#include +#else #include +#endif #include "vl.h" #define AUDIO_CAP "oss" @@ -231,7 +236,7 @@ static int oss_open (int in, struct oss_ goto err; } - if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) { + if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) { oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n"); goto err; } diff -r 0b04a48f65cc tools/ioemu/block-qcow2.c --- a/tools/ioemu/block-qcow2.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/block-qcow2.c Thu Sep 27 11:50:43 2007 +0000 @@ -1884,6 +1884,8 @@ static int grow_refcount_table(BlockDriv int new_table_size, new_table_size2, refcount_table_clusters, i, ret; uint64_t *new_table; int64_t table_offset; + int old_table_size; + int64_t old_table_offset; uint64_t data64; uint32_t data32; @@ -1931,10 +1933,14 @@ static int grow_refcount_table(BlockDriv &data32, sizeof(data32)) != sizeof(data32)) goto fail; qemu_free(s->refcount_table); + old_table_offset = s->refcount_table_offset; + old_table_size = s->refcount_table_size; s->refcount_table = new_table; s->refcount_table_size = new_table_size; + s->refcount_table_offset = table_offset; update_refcount(bs, table_offset, new_table_size2, 1); + free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t)); return 0; fail: free_clusters(bs, table_offset, new_table_size2); diff -r 0b04a48f65cc tools/ioemu/block-raw.c --- a/tools/ioemu/block-raw.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/block-raw.c Thu Sep 27 11:50:43 2007 +0000 @@ -53,8 +53,13 @@ #include #include #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) #include +#endif +#if defined(__OpenBSD__) +#include +#include +#include #endif //#define DEBUG_FLOPPY @@ -496,6 +501,23 @@ static int raw_truncate(BlockDriverState return 0; } +#ifdef __OpenBSD__ +static int64_t raw_getlength(BlockDriverState *bs) +{ + int fd = ((BDRVRawState*)bs->opaque)->fd; + struct stat st; + if(fstat(fd, &st)) + return -1; + if(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)){ + struct disklabel dl; + if(ioctl(fd, DIOCGDINFO, &dl)) + return -1; + return (uint64_t)dl.d_secsize * + dl.d_partitions[DISKPART(st.st_rdev)].p_size; + }else + return st.st_size; +} +#else /* !__OpenBSD__ */ static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -542,6 +564,7 @@ static int64_t raw_getlength(BlockDrive } return size; } +#endif static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) diff -r 0b04a48f65cc tools/ioemu/block-vvfat.c --- a/tools/ioemu/block-vvfat.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/block-vvfat.c Thu Sep 27 11:50:43 2007 +0000 @@ -1017,7 +1017,7 @@ DLOG(if (stderr == NULL) { i = strrchr(dirname, ':') - dirname; assert(i >= 3); - if (dirname[i-2] == ':' && isalpha(dirname[i-1])) + if (dirname[i-2] == ':' && isalpha((uint8_t)dirname[i-1])) /* workaround for DOS drive names */ dirname += i-1; else diff -r 0b04a48f65cc tools/ioemu/bswap.h --- a/tools/ioemu/bswap.h Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/bswap.h Thu Sep 27 11:50:43 2007 +0000 @@ -4,6 +4,11 @@ #include "config-host.h" #include + +#ifdef _BSD +#include +#include +#else #ifdef HAVE_BYTESWAP_H #include @@ -73,6 +78,8 @@ static inline void bswap64s(uint64_t *s) *s = bswap64(*s); } +#endif /* _BSD */ + #if defined(WORDS_BIGENDIAN) #define be_bswap(v, size) (v) #define le_bswap(v, size) bswap ## size(v) diff -r 0b04a48f65cc tools/ioemu/cpu-all.h --- a/tools/ioemu/cpu-all.h Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/cpu-all.h Thu Sep 27 11:50:43 2007 +0000 @@ -1010,13 +1010,22 @@ static inline int64_t cpu_get_real_ticks #endif } #else -/* The host CPU doesn't have an easily accessible cycle counter. - Just return a monotonically increasing vlue. This will be totally wrong, - but hopefully better than nothing. */ + +#include +#include + static inline int64_t cpu_get_real_ticks (void) { - static int64_t ticks = 0; - return ticks++; + struct timeval tv; + static int64_t i = 0; + int64_t j; + + gettimeofday(&tv, NULL); + do { + j = (tv.tv_sec * (uint64_t) 1000000) + tv.tv_usec; + } while (i == j); + i = j; + return j; } #endif diff -r 0b04a48f65cc tools/ioemu/cutils.c --- a/tools/ioemu/cutils.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/cutils.c Thu Sep 27 11:50:43 2007 +0000 @@ -23,7 +23,7 @@ */ #include "vl.h" -void pstrcpy(char *buf, int buf_size, const char *str) +void pstrcpy(char *buf, size_t buf_size, const char *str) { int c; char *q = buf; @@ -41,7 +41,7 @@ void pstrcpy(char *buf, int buf_size, co } /* strcat and truncate. */ -char *pstrcat(char *buf, int buf_size, const char *s) +char *pstrcat(char *buf, size_t buf_size, const char *s) { int len; len = strlen(buf); @@ -72,7 +72,7 @@ int stristart(const char *str, const cha p = str; q = val; while (*q != '\0') { - if (toupper(*p) != toupper(*q)) + if (toupper((uint8_t)*p) != toupper((uint8_t)*q)) return 0; p++; q++; diff -r 0b04a48f65cc tools/ioemu/dis-asm.h --- a/tools/ioemu/dis-asm.h Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/dis-asm.h Thu Sep 27 11:50:43 2007 +0000 @@ -13,6 +13,7 @@ #include #include #include +#include "config.h" #define PARAMS(x) x typedef void *PTR; diff -r 0b04a48f65cc tools/ioemu/hw/acpi.c --- a/tools/ioemu/hw/acpi.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/hw/acpi.c Thu Sep 27 11:50:43 2007 +0000 @@ -473,7 +473,7 @@ void piix4_pm_init(PCIBus *bus, int devf { PIIX4PMState *s; uint8_t *pci_conf; - uint32_t pm_io_base, smb_io_base; + uint32_t smb_io_base; s = (PIIX4PMState *)pci_register_device(bus, "PM", sizeof(PIIX4PMState), diff -r 0b04a48f65cc tools/ioemu/hw/fdc.c --- a/tools/ioemu/hw/fdc.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/hw/fdc.c Thu Sep 27 11:50:43 2007 +0000 @@ -176,7 +176,7 @@ typedef struct fd_format_t { uint8_t last_sect; uint8_t max_track; uint8_t max_head; - const unsigned char *str; + const char *str; } fd_format_t; static fd_format_t fd_formats[] = { diff -r 0b04a48f65cc tools/ioemu/hw/ne2000.c --- a/tools/ioemu/hw/ne2000.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/hw/ne2000.c Thu Sep 27 11:50:43 2007 +0000 @@ -207,7 +207,7 @@ static int ne2000_buffer_full(NE2000Stat index = s->curpag << 8; boundary = s->boundary << 8; - if (index <= boundary) + if (index < boundary) avail = boundary - index; else avail = (s->stop - s->start) - (index - boundary); diff -r 0b04a48f65cc tools/ioemu/hw/pc.c --- a/tools/ioemu/hw/pc.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/hw/pc.c Thu Sep 27 11:50:43 2007 +0000 @@ -480,7 +480,9 @@ static void pc_init1(uint64_t ram_size, int piix3_devfn = -1; CPUState *env; NICInfo *nd; +#ifdef CONFIG_PASSTHROUGH int rc; +#endif linux_boot = (kernel_filename != NULL); @@ -782,7 +784,7 @@ static void pc_init1(uint64_t ram_size, #if 0 /* ??? Need to figure out some way for the user to specify SCSI devices. */ - if (pci_enabled) { + if (pci_enabled && scsi_enabled) { void *scsi; BlockDriverState *bdrv; diff -r 0b04a48f65cc tools/ioemu/monitor.c --- a/tools/ioemu/monitor.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/monitor.c Thu Sep 27 11:50:43 2007 +0000 @@ -1890,7 +1890,7 @@ static int get_str(char *buf, int buf_si q = buf; p = *pp; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p == '\0') { fail: @@ -1935,7 +1935,7 @@ static int get_str(char *buf, int buf_si } p++; } else { - while (*p != '\0' && !isspace(*p)) { + while (*p != '\0' && !isspace((uint8_t)*p)) { if ((q - buf) < buf_size - 1) { *q++ = *p; } @@ -1975,12 +1975,12 @@ static void monitor_handle_command(const /* extract the command name */ p = cmdline; q = cmdname; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p == '\0') return; pstart = p; - while (*p != '\0' && *p != '/' && !isspace(*p)) + while (*p != '\0' && *p != '/' && !isspace((uint8_t)*p)) p++; len = p - pstart; if (len > sizeof(cmdname) - 1) @@ -2016,7 +2016,7 @@ static void monitor_handle_command(const int ret; char *str; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*typestr == '?') { typestr++; @@ -2195,7 +2195,7 @@ static void monitor_handle_command(const c = *typestr++; if (c == '\0') goto bad_type; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; has_option = 0; if (*p == '-') { @@ -2225,7 +2225,7 @@ static void monitor_handle_command(const } } /* check that all arguments were parsed */ - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p != '\0') { term_printf("%s: extraneous characters at the end of line\n", diff -r 0b04a48f65cc tools/ioemu/osdep.h --- a/tools/ioemu/osdep.h Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/osdep.h Thu Sep 27 11:50:43 2007 +0000 @@ -2,6 +2,10 @@ #define QEMU_OSDEP_H #include +#ifdef __OpenBSD__ +#include +#include +#endif #define qemu_printf printf diff -r 0b04a48f65cc tools/ioemu/target-i386-dm/exec-dm.c --- a/tools/ioemu/target-i386-dm/exec-dm.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/target-i386-dm/exec-dm.c Thu Sep 27 11:50:43 2007 +0000 @@ -168,8 +168,8 @@ void cpu_set_log_filename(const char *fi #else setvbuf(logfile, NULL, _IOLBF, 0); #endif - stdout = logfile; - stderr = logfile; + dup2(fileno(logfile), 1); + dup2(fileno(logfile), 2); } /* mask must never be zero, except for A20 change call */ diff -r 0b04a48f65cc tools/ioemu/vl.c --- a/tools/ioemu/vl.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/vl.c Thu Sep 27 11:50:43 2007 +0000 @@ -24,6 +24,7 @@ #include "vl.h" #include +#include #include #include #include @@ -38,22 +39,29 @@ #include #include #include +#include #include #include +#include +#if defined(__NetBSD__) +#include +#endif +#if defined(__linux__) || defined(__Linux__) +#include +#endif #include #include #include #ifdef _BSD #include -#ifndef __APPLE__ +#ifndef _BSD #include +#else +#include #endif #else #ifndef __sun__ -#include -#include #include -#include #include #include #endif @@ -65,7 +73,6 @@ #endif #ifdef _WIN32 -#include #include #include #define getopt_long_only getopt_long @@ -91,7 +98,11 @@ #include #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup" +#ifdef _BSD +#define DEFAULT_BRIDGE "bridge0" +#else #define DEFAULT_BRIDGE "xenbr0" +#endif #ifdef __sun__ #define SMBD_COMMAND "/usr/sfw/sbin/smbd" #else @@ -1794,7 +1805,7 @@ static int store_dev_info(char *devName, return 0; } -#if defined(__linux__) +#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) static CharDriverState *qemu_chr_open_pty(void) { struct termios tty; @@ -1949,6 +1960,7 @@ static CharDriverState *qemu_chr_open_tt return chr; } +#if defined(__linux__) static int pp_ioctl(CharDriverState *chr, int cmd, void *arg) { int fd = (int)chr->opaque; @@ -2013,13 +2025,14 @@ static CharDriverState *qemu_chr_open_pp return chr; } +#endif /* __linux__ */ #else static CharDriverState *qemu_chr_open_pty(void) { return NULL; } -#endif +#endif /* __linux__ || __NetBSD__ || __OpenBSD__ */ #endif /* !defined(_WIN32) */ @@ -2958,7 +2971,7 @@ static int parse_macaddr(uint8_t *macadd return 0; } -static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) +static int get_str_sep(char *buf, size_t buf_size, const char **pp, int sep) { const char *p, *p1; int len; @@ -3031,7 +3044,7 @@ int parse_host_port(struct sockaddr_in * if (buf[0] == '\0') { saddr->sin_addr.s_addr = 0; } else { - if (isdigit(buf[0])) { + if (isdigit((uint8_t)buf[0])) { if (!inet_aton(buf, &saddr->sin_addr)) return -1; } else { @@ -3373,18 +3386,30 @@ static int tap_open(char *ifname, int if static int tap_open(char *ifname, int ifname_size) { int fd; +#ifndef TAPGIFNAME char *dev; struct stat s; +#endif + struct ifreq ifr; fd = open("/dev/tap", O_RDWR); if (fd < 0) { - fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n"); + fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation %s\n", strerror(errno)); return -1; } +#ifdef TAPGIFNAME + if (ioctl (fd, TAPGIFNAME, (void*)&ifr) < 0) { + fprintf(stderr, "warning: could not open get tap name: %s\n", + strerror(errno)); + return -1; + } + pstrcpy(ifname, ifname_size, ifr.ifr_name); +#else fstat(fd, &s); dev = devname(s.st_rdev, S_IFCHR); pstrcpy(ifname, ifname_size, dev); +#endif fcntl(fd, F_SETFL, O_NONBLOCK); return fd; @@ -3434,6 +3459,8 @@ static int net_tap_init(VLANState *vlan, char *args[4]; char **parg; char ifname[128]; + + memset(ifname, 0, sizeof(ifname)); if (ifname1 != NULL) pstrcpy(ifname, sizeof(ifname), ifname1); @@ -3611,7 +3638,7 @@ static int net_socket_mcast_create(struc val = 1; ret=setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - (const char *)&val, sizeof(val)); + (const char *)&val, sizeof(char)); if (ret < 0) { perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); goto fail; @@ -3893,7 +3920,7 @@ static int net_socket_mcast_init(VLANSta } -static int get_param_value(char *buf, int buf_size, +static int get_param_value(char *buf, size_t buf_size, const char *tag, const char *str) { const char *p; @@ -4019,6 +4046,10 @@ static int net_client_init(const char *s char setup_script[1024]; char bridge[16]; int fd; + + memset(ifname, 0, sizeof(ifname)); + memset(setup_script, 0, sizeof(setup_script)); + if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { fd = strtol(buf, NULL, 0); ret = -1; @@ -6914,7 +6945,6 @@ static int qemu_map_cache_init(void) nr_buckets = (((MAX_MCACHE_SIZE >> PAGE_SHIFT) + (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1) >> (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)); - fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets); /* * Use mmap() directly: lets us allocate a big hash table with no up-front @@ -6923,8 +6953,9 @@ static int qemu_map_cache_init(void) */ size = nr_buckets * sizeof(struct map_cache); size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx size %lu\n", nr_buckets, size); mapcache_entry = mmap(NULL, size, PROT_READ|PROT_WRITE, - MAP_SHARED|MAP_ANONYMOUS, 0, 0); + MAP_SHARED|MAP_ANON, -1, 0); if (mapcache_entry == MAP_FAILED) { errno = ENOMEM; return -1; @@ -7061,6 +7092,7 @@ int main(int argc, char **argv) unsigned long ioreq_pfn; extern void *shared_page; extern void *buffered_io_page; + struct rlimit rl; #ifdef __ia64__ unsigned long nr_pages; xen_pfn_t *page_array; @@ -7069,6 +7101,32 @@ int main(int argc, char **argv) sigset_t set; char qemu_dm_logfilename[128]; const char *direct_pci = NULL; + + /* XXX required for now */ + if (setenv("PTHREAD_DIAGASSERT", "A", 1) != 0) + perror("setenv"); + if (getrlimit(RLIMIT_STACK, &rl) != 0) { + perror("getrlimit(RLIMIT_STACK)"); + exit(1); + } + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_STACK, &rl) != 0) + perror("setrlimit(RLIMIT_STACK)"); + if (getrlimit(RLIMIT_DATA, &rl) != 0) { + perror("getrlimit(RLIMIT_DATA)"); + exit(1); + } + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_DATA, &rl) != 0) + perror("setrlimit(RLIMIT_DATA)"); + rl.rlim_cur = RLIM_INFINITY; + rl.rlim_max = RLIM_INFINITY; + if (setrlimit(RLIMIT_RSS, &rl) != 0) + perror("setrlimit(RLIMIT_RSS)"); + rl.rlim_cur = RLIM_INFINITY; + rl.rlim_max = RLIM_INFINITY; + if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0) + perror("setrlimit(RLIMIT_MEMLOCK)"); /* Ensure that SIGUSR2 is blocked by default when a new thread is created, then only the threads that use the signal unblock it -- this fixes a diff -r 0b04a48f65cc tools/ioemu/vl.h --- a/tools/ioemu/vl.h Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/vl.h Thu Sep 27 11:50:43 2007 +0000 @@ -103,8 +103,8 @@ static inline char *realpath(const char #endif /* cutils.c */ -void pstrcpy(char *buf, int buf_size, const char *str); -char *pstrcat(char *buf, int buf_size, const char *s); +void pstrcpy(char *buf, size_t buf_size, const char *str); +char *pstrcat(char *buf, size_t buf_size, const char *s); int strstart(const char *str, const char *val, const char **ptr); int stristart(const char *str, const char *val, const char **ptr); diff -r 0b04a48f65cc tools/ioemu/vnc.c --- a/tools/ioemu/vnc.c Wed Sep 26 17:11:07 2007 +0100 +++ b/tools/ioemu/vnc.c Thu Sep 27 11:50:43 2007 +0000 @@ -24,6 +24,9 @@ * THE SOFTWARE. */ +#include +#include +#include #include "vl.h" #include "qemu_socket.h" #include