ioemu: Build fixes for BSD and bug fixes from BSD
PATCH 1/1 ioemu: Build fixes for BSD and bug fixes from BSD
Hi!
Attached patch makes ioemu build on *BSD.
It also applies bug fixes from *BSD for Linux and *BSD :-)
P.S.: Could someone with contact to qemu people make this patch go upstream to qemu, please?
Signature · 12 lines
AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Geschäftsführer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
tools/ioemu/aes.c +2 -0
@@ -30,7 +30,9 @@#include "vl.h" #include "aes.h" +#ifndef NDEBUG #define NDEBUG +#endif #include <assert.h> typedef uint32_t u32 ;
tools/ioemu/audio/audio.c +2 -2
@@ -207,7 +207,7 @@ static char *audio_alloc_prefix (const cstrcat (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);
tools/ioemu/audio/mixeng.c +4 -0
@@ -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 */ };/*
tools/ioemu/audio/ossaudio.c +6 -1
@@ -21,10 +21,15 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include <stdlib.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/ioctl.h> +#if defined(__OpenBSD__) +#include <soundcard.h> +#else #include <sys/soundcard.h> +#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; }
tools/ioemu/block-qcow2.c +6 -0
@@ -1884,6 +1884,8 @@ static int grow_refcount_table(BlockDrivint 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);
tools/ioemu/block-raw.c +24 -1
@@ -53,8 +53,13 @@#include <linux/cdrom.h> #include <linux/fd.h> #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__)#include <sys/disk.h> +#endif +#if defined(__OpenBSD__) +#include <sys/ioctl.h> +#include <sys/disklabel.h> +#include <sys/dkio.h> #endif //#define DEBUG_FLOPPY
@@ -496,6 +501,23 @@ static int raw_truncate(BlockDriverStatereturn 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)
tools/ioemu/block-vvfat.c +1 -1
@@ -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
tools/ioemu/bswap.h +7 -0
@@ -4,6 +4,11 @@#include "config-host.h" #include <inttypes.h> + +#ifdef _BSD +#include <sys/endian.h> +#include <sys/types.h> +#else #ifdef HAVE_BYTESWAP_H #include <byteswap.h>
@@ -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)
tools/ioemu/cpu-all.h +14 -5
@@ -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 <sys/time.h> +#include <time.h> +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
tools/ioemu/cutils.c +3 -3
@@ -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++;
tools/ioemu/dis-asm.h +1 -0
@@ -13,6 +13,7 @@#include <stdio.h> #include <string.h> #include <inttypes.h> +#include "config.h" #define PARAMS (x) xtypedef void *PTR ;
tools/ioemu/hw/acpi.c +1 -1
@@ -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),
tools/ioemu/hw/fdc.c +1 -1
@@ -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[] = {
tools/ioemu/hw/ne2000.c +1 -1
@@ -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);
tools/ioemu/hw/pc.c +3 -1
@@ -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;
tools/ioemu/monitor.c +7 -7
@@ -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(constint 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",
tools/ioemu/osdep.h +4 -0
@@ -2,6 +2,10 @@#define QEMU_OSDEP_H #include <stdarg.h> +#ifdef __OpenBSD__ +#include <sys/types.h> +#include <sys/signal.h> +#endif #define qemu_printf printf
tools/ioemu/target-i386-dm/exec-dm.c +2 -2
@@ -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 */
tools/ioemu/vl.c +72 -14
225 lines not on this page · raw message
tools/ioemu/vl.h +2 -2
@@ -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);
tools/ioemu/vnc.c +3 -0
@@ -24,6 +24,9 @@* THE SOFTWARE. */ +#include <sys/stat.h> +#include <sys/socket.h> +#include <netinet/in.h> #include "vl.h" #include "qemu_socket.h" #include <assert.h>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 7 lines · Christoph Egger
Attached patch makes ioemu build on *BSD.
It also applies bug fixes from *BSD for Linux and *BSD :-)Signed-off-by Christoph Egger <[email protected]>
P.S.: Could someone with contact to qemu people make this patch go upstream to qemu, please?
Why the setenv PTHREAD_DIAGASSERT? There is very little pthread usage at all in ioemu. In fact basically none.
And why do you need to fiddle with {get,set}rlimit()? Is ioemu stack usage excessive?
-- Keir
Quoted 11 lines · On Thursday 27 September 2007 16:19:42 Keir Fraser wrote:
Quoted 7 lines · Christoph Egger
Attached patch makes ioemu build on *BSD.
It also applies bug fixes from *BSD for Linux and *BSD :-)Signed-off-by Christoph Egger <[email protected]>
P.S.: Could someone with contact to qemu people make this patch go upstream to qemu, please?Why the setenv
PTHREAD_DIAGASSERT? There is very little pthread usage at all in ioemu. In fact basically none.
Oh, a debugging leftover. You may kill that.
Quoted 2 lines
And why do you need to fiddle with {get,set}rlimit()? Is ioemu stack usage excessive?
The resource limits on BSD are more limited than on Linux. Look:
NetBSD: ulimit -a
-----------------
time(cpu-seconds) unlimited file(blocks) unlimited coredump(blocks) unlimited data(kbytes) 262144 stack(kbytes) 2048 lockedmem(kbytes) 1111329 memory(kbytes) 3333988
nofiles(descriptors) 64
processes 160
sbsize(bytes) unlimited
-----------------
OpenBSD: ulimit -a
--------------------
time(cpu-seconds) unlimited file(blocks) unlimited coredump(blocks) unlimited data(kbytes) 524288 stack(kbytes) 4096 lockedmem(kbytes) 335258 memory(kbytes) 1004356
nofiles(descriptors) 128
processes 128
----------------------
Linux: ulimit -a
-----------------------
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 20
file size (blocks, -f) unlimited
pending signals (-i) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) unlimited
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
-----------------------
Signature · 12 lines
AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Geschäftsführer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
Quoted 6 lines · Christoph Egger
Hi!
Attached patch makes ioemu build on *BSD.
It also applies bug fixes from *BSD for Linux and *BSD :-)Signed-off-by Christoph Egger <[email protected]>
I checked in all the bits that look like they are there just to make ioemu build and run on *BSD (that's about 90-95% of the patch). The remainder I rejected -- that's generic bug fixes to ioemu (belongs upstream and/or as separate patches to xen-devel) and anything that looked like it merely fixes a build warning (we don't build ioemu with -Werror, and we tolerate build warnings because they should really be fixed upstream first). You may want to check that I didn't cut too hard, and resubmit a few bits.
-- Keir
Quoted 6 lines · On Thursday 27 September 2007 17:39:18 Keir Fraser wrote:
Quoted 5 lines · Christoph Egger
Hi!
Attached patch makes ioemu build on *BSD.
It also applies bug fixes from *BSD for Linux and *BSD :-)
Quoted 8 lines
Quoted 1 line
Signed-off-by Christoph Egger <[email protected]>I checked in all the bits that look like they are there just to make ioemu build and run on *BSD (that's about 90-95% of the patch). The remainder I rejected -- that's generic bug fixes to ioemu (belongs upstream and/or as separate patches to xen-devel) and anything that looked like it merely fixes a build warning (we don't build ioemu with -Werror, and we tolerate build warnings because they should really be fixed upstream first).
I agree with you, this also should go into qemu. But I don't have contact to the qemu people. That's why I asked in the first signed-off mail, if there is someone with contact to qemu.
Maybe someone from qemu is subscribed on xen-devel, so I resubmit the remainder as separate patch.
Quoted 3 lines
You may want to check that I didn't cut too hard, and resubmit a few bits.
-- Keir
I just checked. I can live with that what you committed. But I resubmit the remainder for the case someone from qemu is on xen-devel or someone with contact to qemu people is on xen-devel, in hope the *full* patch goes into qemu the one or the other way.
Christoph
Signature · 12 lines
AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Geschäftsführer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
tools/ioemu/aes.c +2 -0
@@ -30,7 +30,9 @@#include "vl.h" #include "aes.h" +#ifndef NDEBUG #define NDEBUG +#endif #include <assert.h> typedef uint32_t u32 ;
tools/ioemu/block-qcow2.c +6 -0
@@ -1884,6 +1884,8 @@ static int grow_refcount_table(BlockDrivint 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);
tools/ioemu/cpu-all.h +14 -5
@@ -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 <sys/time.h> +#include <time.h> +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
tools/ioemu/dis-asm.h +1 -0
@@ -13,6 +13,7 @@#include <stdio.h> #include <string.h> #include <inttypes.h> +#include "config.h" #define PARAMS (x) xtypedef void *PTR ;
tools/ioemu/hw/acpi.c +1 -1
@@ -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),
tools/ioemu/hw/fdc.c +1 -1
@@ -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[] = {
tools/ioemu/hw/ne2000.c +1 -1
@@ -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);
tools/ioemu/hw/pc.c +2 -0
@@ -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 );
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 2 lines · Christoph Egger
I agree with you, this also should go into qemu. But I don't have contact to the qemu people.
You could post to qemu-devel.
http://lists.nongnu.org/mailman/listinfo/qemu-devel
Ian.