Implement and test asn1 ber visitors
v2 cover Implement and test asn1 ber visitors
These patches implement asn1 ber visitors for encoding and decoding data.
changed since v1:
Moved .c files into qapi directory
Moved .h files into include/qapi
Added sized buffer code
cleaned up Makefile changes to play nicer
Broke out patches for output/input visitors
New tests in tests/test-visitor-serialization.c
Fixed width integer encoding now marked with application specific bit Removed qapi array code
Added Mike Roth's previously sent carray qapi patch
misc small cleanups
forward ported to keep up with git HEAD
added real number support
PATCH v2 1/9 qemu-file
This patch reorganizes qemu file operations to be in their own source file instead of being lumped in savevm.c. Besides being more logical for maintenance it also makes it easier for future users of the file functions to add tests.
--- Makefile.objs | 2 +- include/migration/qemu-file.h | 6 + qemu-file.c | 715 +++++++++++++++++++++++++++++++++++++++++ savevm.c | 690 --------------------------------------- 4 files changed, 722 insertions(+), 691 deletions(-) create mode 100644 qemu-file.c
Makefile.objs +1 -1
@@ -1,7 +1,7 @@ ####################################################################### # Common libraries for tools and emulators stub-obj-y = stubs/ -util-obj-y = util/ qobject/ qapi/ trace/ +util-obj-y = util/ qobject/ qapi/ trace/ qemu-file.o ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img
include/migration/qemu-file.h +6 -0
@@ -98,6 +98,12 @@ void qemu_file_reset_rate_limit(QEMUFile *f);void qemu_file_set_rate_limit (QEMUFile *f,int64_t new_rate);int64_t qemu_file_get_rate_limit (QEMUFile *f);int qemu_file_get_error (QEMUFile *f); +void qemu_file_set_error (QEMUFile *f,int ret); +QEMUFile *qemu_fopen_bdrv (BlockDriverState *bs,int is_writable); +int qemu_peek_buffer (QEMUFile *f,uint8_t *buf,int size,size_t offset); +int qemu_peek_byte (QEMUFile *f,int offset); +void qemu_file_skip (QEMUFile *f,int size); +void qemu_fflush (QEMUFile *f);static inline void qemu_put_be64s (QEMUFile *f,const uint64_t *pv) {
qemu-file.c new file +715 -0
715 lines not on this page · raw message
savevm.c +0 -690
696 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v2 2/9 qapi_c_arrays.diff
In reply to Joel SchoppForward ported Mike's previously sent patch
(see http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg05782.html ) in my series since it impelments a qapi array interface the ASN.1 BER visitor needs.
Generally these will be serialized into lists, but the representation can be of any form so long as it can be deserialized into a single-dimension C array.
--- include/qapi/visitor-impl.h | 4 ++++ include/qapi/visitor.h | 4 ++++ qapi/qapi-visit-core.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+)
include/qapi/visitor-impl.h +4 -0
@@ -34,6 +34,10 @@ struct Visitorvoid (*type_str)(Visitor *v,char **obj,const char *name,Error **errp);void (*type_number)(Visitor *v,double *obj,const char *name,Error **errp); +void (*start_carray)(Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void (*next_carray)(Visitor *v,Error **errp); +void (*end_carray)(Visitor *v,Error **errp);/* May be NULL */ void (*start_optional)(Visitor *v, bool *present, const char *name,
include/qapi/visitor.h +4 -0
@@ -51,5 +51,9 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void visit_next_carray (Visitor *v,Error **errp); +void visit_end_carray (Visitor *v,Error **errp);#endif
qapi/qapi-visit-core.c +25 -0
@@ -313,3 +313,28 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp) +{ +g_assert (v->start_carray); +if (!error_is_set (errp)) { + v->start_carray (v, obj, name, elem_count, elem_size, errp); + } +} + +void visit_next_carray (Visitor *v,Error **errp) +{ +g_assert (v->next_carray); +if (!error_is_set (errp)) { + v->next_carray (v, errp); + } +} + +void visit_end_carray (Visitor *v,Error **errp) +{ +g_assert (v->end_carray); +if (!error_is_set (errp)) { + v->end_carray (v, errp); + } +}
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 2/9] qapi_c_arrays.diff
Quoted 3 lines · Joel Schopp
Forward ported Mike's previously sent patch
(see http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg05782.html ) in my series since it impelments a qapi array interface the ASN.1 BER visitor needs.
s/impelments/implements/
include/qapi/visitor-impl.h struct Visitor · line 38
Quoted 13 lines
Generally these will be serialized into lists, but the representation can be of any form so long as it can be deserialized into a single-dimension C array.
+++
b/include/qapi/visitor-impl.hinclude/qapi/visitor-impl.h +2
-0@@ -34,6 +34,10 @@ struct Visitorvoid (*type_str)(Visitor *v,char **obj,const char *name,Error **errp);void (*type_number)(Visitor *v,double *obj,const char *name,Error **errp); +void (*start_carray)(Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp);
Indentation looks off.
include/qapi/visitor.h void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp); · line 55
Quoted 7 lines
include/qapi/visitor.h +3
-0+++ b/include/qapi/visitor.h@@ -51,5 +51,9 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_start_carray (Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp);
Indentation.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 3/9 two new file wrappers
In reply to Joel SchoppAdd a 3 very short file wrapper functions to make code that follows more readable. Also export an existing function that is currently static.
--- include/migration/qemu-file.h | 3 +++ qemu-file.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/migration/qemu-file.h +3 -0
@@ -68,6 +68,9 @@ int qemu_fclose(QEMUFile *f);int64_t qemu_ftell (QEMUFile *f);void qemu_put_buffer (QEMUFile *f,const uint8_t *buf,int size);void qemu_put_byte (QEMUFile *f,int v); +int qemu_read_bytes (QEMUFile *f,uint8_t *buf,int size); +int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset); +int qemu_write_bytes (QEMUFile *f,const uint8_t *buf,int size);static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {
qemu-file.c +30 -0
@@ -713,3 +713,33 @@ uint64_t qemu_get_be64(QEMUFile *f)return v; } +int qemu_read_bytes (QEMUFile *f,uint8_t *buf,int size) +{ +if (qemu_file_get_error (f)) { +return -1 ; + } +return qemu_get_buffer (f, buf, size); +} + +int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset) +{ +if (qemu_file_get_error (f)) { +return -1 ; + } +return qemu_peek_buffer (f, buf, size, offset); +} + +int qemu_write_bytes (QEMUFile *f,const uint8_t *buf,int size) +{ +if (qemu_file_get_error (f)) { +return -1 ; + } + +qemu_put_buffer (f, buf, size); + +if (qemu_file_get_error (f)) { +return -1 ; + } + +return size; +}
Signature · 1 line
1.7.10.4
PATCH v2 4/9 qemu_qsb.diff
In reply to Joel SchoppThis patch adds support functions for operating on in memory sized file buffers.
--- include/migration/qemu-file.h | 12 +++ include/qemu-common.h | 15 ++++ qemu-file.c | 184 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+)
include/migration/qemu-file.h +12 -0
@@ -24,6 +24,8 @@#ifndef QEMU_FILE_H #define QEMU_FILE_H 1 +#include <stdint.h> +/* This function writes a chunk of data to a file at the given position. * The pos argument can be ignored if the file is only being used for * streaming. The handler should try to write all of the data it can.
@@ -58,6 +60,14 @@ typedef struct QEMUFileOps {QEMUFileGetFD *get_fd; } QEMUFileOps; +struct QEMUSizedBuffer { +unsigned char *buffer; +uint64_t size; +uint64_t used; +}; + +typedef struct QEMUSizedBuffer QEMUSizedBuffer ; +QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops);QEMUFile *qemu_fopen (const char *filename,const char *mode);QEMUFile *qemu_fdopen (int fd,const char *mode);
@@ -71,6 +81,8 @@ void qemu_put_byte(QEMUFile *f, int v);int qemu_read_bytes (QEMUFile *f,uint8_t *buf,int size);int qemu_peek_bytes (QEMUFile *f,uint8_t *buf,int size,size_t offset);int qemu_write_bytes (QEMUFile *f,const uint8_t *buf,int size); +QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input); +const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f);static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {
include/qemu-common.h +15 -0
@@ -442,4 +442,19 @@ int64_t pow2floor(int64_t value);int uleb128_encode_small (uint8_t *out,uint32_t n);int uleb128_decode_small (const uint8_t *in,uint32_t *n); +/* QEMU Sized Buffer */ +#include "include/migration/qemu-file.h" +QEMUSizedBuffer *qsb_create (const uint8_t *buffer,uint64_t len); +QEMUSizedBuffer *qsb_clone (const QEMUSizedBuffer *); +void qsb_free (QEMUSizedBuffer *); +uint64_t qsb_set_length (QEMUSizedBuffer *qsb,uint64_t length); +uint64_t qsb_get_length (const QEMUSizedBuffer *qsb); +const unsigned char *qsb_get_buffer (const QEMUSizedBuffer *,int64_t pos); +int qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, +int64_t pos,int size); +int qsb_append_qsb (QEMUSizedBuffer *dest,const QEMUSizedBuffer *src); +int qsb_append (QEMUSizedBuffer *dest,const uint8_t *buffer,uint64_t len); + + +#endif
qemu-file.c +184 -0
187 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v2 5/9 qapi_sized_buffer
In reply to Joel SchoppAdd a sized buffer interface to qapi.
--- include/qapi/visitor-impl.h | 2 ++ include/qapi/visitor.h | 2 ++ qapi/qapi-visit-core.c | 8 ++++++++ 3 files changed, 12 insertions(+)
include/qapi/visitor-impl.h +2 -0
@@ -38,6 +38,8 @@ struct Visitor size_t elem_count, size_t elem_size, Error **errp);void (*next_carray)(Visitor *v,Error **errp);void (*end_carray)(Visitor *v,Error **errp); +void (*type_sized_buffer)(Visitor *v,uint8_t **obj,size_t size, +const char *name,Error **errp);/* May be NULL */ void (*start_optional)(Visitor *v, bool *present, const char *name,
include/qapi/visitor.h +2 -0
@@ -55,5 +55,7 @@ void visit_start_carray(Visitor *v, void **obj, const char *name, size_t elem_count, size_t elem_size, Error **errp);void visit_next_carray (Visitor *v,Error **errp);void visit_end_carray (Visitor *v,Error **errp); +void visit_type_sized_buffer (Visitor *v,uint8_t **obj,size_t len, +const char *name,Error **errp);#endif
qapi/qapi-visit-core.c +8 -0
@@ -338,3 +338,11 @@ void visit_end_carray(Visitor *v, Error **errp) v->end_carray (v, errp); } } + +void visit_type_sized_buffer (Visitor *v,uint8_t **obj,size_t len, +const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_sized_buffer (v, obj, len, name, errp); + } +}
Signature · 1 line
1.7.10.4
PATCH v2 6/9 asn1_output-visitor.diff
In reply to Joel SchoppImplement an output visitor for ASN.1 BER encoding.
--- configure | 2 +- include/qapi/ber-output-visitor.h | 28 ++ include/qapi/ber.h | 107 +++++++ qapi/Makefile.objs | 1 + qapi/ber-common.c | 86 ++++++ qapi/ber-common.h | 29 ++ qapi/ber-output-visitor.c | 617 +++++++++++++++++++++++++++++++++++++ 7 files changed, 869 insertions(+), 1 deletion(-) create mode 100644 include/qapi/ber-output-visitor.h create mode 100644 include/qapi/ber.h create mode 100644 qapi/ber-common.c create mode 100644 qapi/ber-common.h create mode 100644 qapi/ber-output-visitor.c
configure +1 -1
@@ -2826,7 +2826,7 @@ fi # Do we need libm cat > $TMPC << EOF #include <math.h> -int main(void) { return isnan(sin(0.0)); } +int main(void) { return isnan(nan("NAN")); } EOF if compile_prog "" "" ; then :
include/qapi/ber-output-visitor.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* BER Output Visitor header +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef BER_OUTPUT_VISITOR_H +#define BER_OUTPUT_VISITOR_H + +#include "qapi/visitor.h" +#include "qapi/ber.h" + +typedef struct BEROutputVisitor BEROutputVisitor ; + +BEROutputVisitor *ber_output_visitor_new (QEMUFile *,BERTypePC mode); +void ber_output_visitor_cleanup (BEROutputVisitor *v); + +Visitor *ber_output_get_visitor (BEROutputVisitor *v); + +#endif
include/qapi/ber.h new file +107 -0
107 lines not on this page · raw message
qapi/Makefile.objs +1 -0
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o util-obj-y += opts-visitor.o +util-obj-y += ber-common.o ber-output-visitor.o
qapi/ber-common.c new file +86 -0
86 lines not on this page · raw message
qapi/ber-common.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* BER Visitor -- common code +* +* Copyright IBM, Corp. 2013 +* +* Authors: +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ +#ifndef __QAPI_BER_COMMON_H__ +#define __QAPI_BER_COMMON_H__ + +#include <stdint.h> + +#include "qemu/compiler.h" + +struct ieee754_buffer { +uint8_t type; +uint8_t length; +uint8_t first; +uint16_t exponent; +uint32_t mant_hi; +uint32_t mant_lo; +}QEMU_PACKED ; + +#endif /* __QAPI_BER_COMMON_H__ */
qapi/ber-output-visitor.c new file +617 -0
617 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 6/9] asn1_output-visitor.diff
include/qapi/ber-output-visitor.h line 4
Quoted 13 lines · Joel Schopp
Implement an output visitor for ASN.1 BER encoding.
Cc Michael Tsirkin <[email protected]>Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>---
+++
b/include/qapi/ber-output-visitor.hinclude/qapi/ber-output-visitor.h new file +4
-0@@ -0,0 +1,28 @@ +/* +* BER Output Visitor header +* +* Copyright IBM, Corp. 2011
It's 2013.
Quoted 13 lines
qapi/ber-output-visitor.c new file +13
-0+static unsigned int ber_encode_len (uint8_t *buffer,uint32_t buflen, +uint64_t len,Error **errp) +{ +uint64_t mask =0xFF00000000000000ULL ; +int shift =64 -8 ; +int c =0 ; + +if (len <=0x7f && buflen >=1 ) { + buffer[0 ] = len; +return 1 ; + } + +while (mask && (mask & len) ==0 ) {
qapi/ber-output-visitor.c line 145
Quoted 10 lines
qapi/ber-output-visitor.c new file +10
-0+ mask >>=8 ; + shift -=8 ; + } + +while (shift >=0 ) { +if (1 + c +1 > buflen) { +error_set (errp,QERR_BUFFER_OVERRUN ); +return 0 ; + } + buffer[1 +c] = (len >> shift);
Space around binary operators.
qapi/ber-output-visitor.c line 398
Quoted 3 lines
qapi/ber-output-visitor.c new file +3
-0+ +if (maxnumbytes >1 ) { + exp_zeros = ((mask & val) ==0 ) ? true : false;
I'm not a fan of 'bool expr ? true : false', when just 'bool expr' will do.
Quoted 7 lines
qapi/ber-output-visitor.c new file +7
-0+while (mask !=0xFF ) { +if (exp_zeros) { +if ((mask & val) !=0 ) { +break ; + } + }else { +if ((mask & val) != mask) {
qapi/ber-output-visitor.c line 415
Quoted 10 lines
qapi/ber-output-visitor.c new file +10
-0+break ; + } + } + shift -=8 ; + mask >>=8 ; + } + } + +while (shift >=0 ) { + buf[2 +c] = (val >> shift);
Another case of spaces around binary operator (I didn't look closely, so you may want to scrub the entire patch for more instances than what I saw on a casual quick read)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 7/9 asn1_input-visitor.diff
In reply to Joel SchoppImplement an input visitor for ASN.1 BER encoding.
--- include/qapi/ber-input-visitor.h | 30 ++ qapi/Makefile.objs | 2 +- qapi/ber-input-visitor.c | 1073 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1104 insertions(+), 1 deletion(-) create mode 100644 include/qapi/ber-input-visitor.h create mode 100644 qapi/ber-input-visitor.c
include/qapi/ber-input-visitor.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* BER Input Visitor header +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef BER_INPUT_VISITOR_H +#define BER_INPUT_VISITOR_H + +#include "qapi/visitor.h" + +typedef struct BERInputVisitor BERInputVisitor ; + +BERInputVisitor *ber_input_visitor_new (QEMUFile *, +uint64_t max_allowd_buffer_size); +void ber_input_visitor_cleanup (BERInputVisitor *v); +uint64_t ber_input_get_parser_position (BERInputVisitor *v); +uint64_t ber_input_get_largest_needed_buffer (BERInputVisitor *v); + +Visitor *ber_input_get_visitor (BERInputVisitor *v); + +#endif
qapi/Makefile.objs +1 -1
@@ -3,4 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o util-obj-y += opts-visitor.o -util-obj-y += ber-common.o ber-output-visitor.o +util-obj-y += ber-common.o ber-output-visitor.o ber-input-visitor.o
qapi/ber-input-visitor.c new file +1073 -0
1,073 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 7/9] asn1_input-visitor.diff
Quoted 19 lines · Joel Schopp
Implement an input visitor for ASN.1 BER encoding.
Cc Michael Tsirkin <[email protected]>Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/qapi/ber-input-visitor.h | 30 ++ qapi/Makefile.objs | 2 +- qapi/ber-input-visitor.c | 1073 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1104 insertions(+), 1 deletion(-) create mode 100644 include/qapi/ber-input-visitor.h create mode 100644 qapi/ber-input-visitor.cinclude/qapi/ber-input-visitor.h new file +0
-0
include/qapi/ber-input-visitor.h line 4
Quoted 4 lines
include/qapi/ber-input-visitor.h new file +4
-0@@ -0,0 +1,30 @@ +/* +* BER Input Visitor header +* +* Copyright IBM, Corp. 2011
It's 2013
Quoted 15 lines
include/qapi/ber-input-visitor.h new file +14
-0+static void ber_input_type_number (Visitor *v,double *obj,const char *name, +Error **errp) +{ +BERInputVisitor *aiv =to_biv (v); +uint32_t ber_type_tag; +uint8_t ber_type_flags; +uint32_t len; +bool is_indefinite; +char buf[128 ], buf2[128 ]; +GDoubleIEEE754 num; +struct ieee754_buffer number; +size_t to_read; + +switch (number.first) {
include/qapi/ber-input-visitor.h
Quoted 10 lines
include/qapi/ber-input-visitor.h new file +10
-0+case 0x42 : + *obj =nan ("NAN" ); +break ; +case 0x41 : +case 0x40 : + num.mpn.sign = ((number.first &0x1 ) !=0 ); + num.mpn.biased_exponent = ~0 ; + num.mpn.mantissa_low =0 ; + num.mpn.mantissa_high =0 ; + *obj = num.v_double;
Is this really portable enough? In other words, do we really require that qemu only compiles on platforms where double is in IEEE format?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 7/9] asn1_input-visitor.diff
Quoted 45 lines · Eric Blake
Quoted 19 lines · Joel Schopp
Implement an input visitor for ASN.1 BER encoding.
Cc Michael Tsirkin <[email protected]>Signed-off-by Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>--- include/qapi/ber-input-visitor.h | 30 ++ qapi/Makefile.objs | 2 +- qapi/ber-input-visitor.c | 1073 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1104 insertions(+), 1 deletion(-)create mode 100644
include/qapi/ber-input-visitor.hcreate mode 100644qapi/ber-input-visitor.cinclude/qapi/ber-input-visitor.h new file +0
-0include/qapi/ber-input-visitor.h line 4
Quoted 4 lines
include/qapi/ber-input-visitor.h new file +4
-0@@ -0,0 +1,30 @@ +/* +* BER Input Visitor header +* +* Copyright IBM, Corp. 2011 It's 2013
Quoted 18 lines
include/qapi/ber-input-visitor.h new file +18
-0+static void ber_input_type_number (Visitor *v,double *obj,const char *name, +Error **errp) +{ +BERInputVisitor *aiv =to_biv (v); +uint32_t ber_type_tag; +uint8_t ber_type_flags; +uint32_t len; +bool is_indefinite; +char buf[128 ], buf2[128 ]; +GDoubleIEEE754 num; +struct ieee754_buffer number; +size_t to_read; + +switch (number.first) { +case 0x42 : + *obj =nan ("NAN" ); +break ; +case 0x41 :
Quoted 9 lines
include/qapi/ber-input-visitor.h line 28
Quoted 6 lines
include/qapi/ber-input-visitor.h new file +6
-0+case 0x40 : + num.mpn.sign = ((number.first &0x1 ) !=0 ); + num.mpn.biased_exponent = ~0 ; + num.mpn.mantissa_low =0 ; + num.mpn.mantissa_high =0 ; + *obj = num.v_double;Is this really portable enough? In other words, do we really require that qemu only compiles on platforms where double is in IEEE format?
Good question. I don't know in what format the other platforms are, though. I know it's used on i386, x86_64, ppc, ppc64. My guess is that it would have to be a really exotic CPU to not use this standard.
I hope this applies to ARM in general...
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0067d/Cihgejjg.html
Regards,
Stefan
Stefan
Re: [Qemu-devel] [PATCH 7/9] asn1_input-visitor.diff
Quoted 11 lines
Quoted 11 lines
qapi/ber-input-visitor.c line 1007
Quoted 8 lines
qapi/ber-input-visitor.c new file +7
-0+case 0x41 : +case 0x40 : + num.mpn.sign = ((number.first &0x1 ) !=0 ); + num.mpn.biased_exponent = ~0 ; + num.mpn.mantissa_low =0 ; + num.mpn.mantissa_high =0 ; + *obj = num.v_double;Is this really portable enough? In other words, do we really require that qemu only compiles on platforms where double is in IEEE format?
Quoted 7 lines
Good question. I don't know in what format the other platforms are, though. I know it's used on i386,
x86_64, ppc, ppc64. My guess is that it would have to be a really exotic CPU to not use this standard.I hope this applies to ARM in general...
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0067d/Cihgejjg.html
There are chips without hardware floating point, for example the ppc 404. However, these use software emulation of IEE floating point when doing floating point math. What we are looking for is a platform that has floating point that isn't IEEE.
Cell SPE comes to mind, though I don't think qemu emulates it and it is a dead architecture (RIP). It also has an IEEE mode that makes its non-standard floating point compliant. Even in non-compliant mode the code above would work, it's more rounding that might be off.
In summary I can't think of a platform we run on or emulate that has a floating point mode the above would not work on. If somebody can think of one please let me know so we can #ifdef a special case for it. Otherwise let's assume the above works for all the platforms we care about.
-Joel
Re: [Qemu-devel] [PATCH 7/9] asn1_input-visitor.diff
Quoted 20 lines · Joel Schopp
Quoted 11 lines
Quoted 11 lines
qapi/ber-input-visitor.c line 1007
Quoted 8 lines
qapi/ber-input-visitor.c new file +7
-0+case 0x41 : +case 0x40 : + num.mpn.sign = ((number.first &0x1 ) !=0 ); + num.mpn.biased_exponent = ~0 ; + num.mpn.mantissa_low =0 ; + num.mpn.mantissa_high =0 ; + *obj = num.v_double;Is this really portable enough? In other words, do we really require that qemu only compiles on platforms where double is in IEEE format?
Quoted 8 lines
Good question. I don't know in what format the other platforms are, though. I know it's used on i386,
x86_64, ppc, ppc64. My guess is that it would have to be a really exotic CPU to not use this standard.I hope this applies to ARM in general...
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0067d/Cihgejjg.html
Quoted 5 lines
There are chips without hardware floating point, for example the ppc 404. However, these use software emulation of IEE floating point when doing floating point math. What we are looking for is a platform that has floating point that isn't IEEE.
Cell SPE comes to mind, though I don't think qemu emulates it and it is a dead architecture (RIP). It also has an IEEE mode that makes its non-standard floating point compliant. Even in non-compliant mode the code above would work, it's more rounding that might be off.
In summary I can't think of a platform we run on or emulate that has a floating point mode the above would not work on. If somebody can think of one please let me know so we can #ifdef a special case for it. Otherwise let's assume the above works for all the platforms we care about.
One other choice could be string-encoding as also suggested by the standard with possible loss of precision. Though I think that any exotic processor could be dealt with a #ifdef around the code pressing its format into 2 bytes of exponent and 8 bytes of mantissa.
Stefan
PATCH v2 8/9 asn1_test_visitor_serialization.diff
In reply to Joel SchoppAdd BER Visitor hooks to test-visitor-serialization
--- tests/Makefile | 2 +- tests/test-visitor-serialization.c | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-)
tests/Makefile +1 -1
@@ -124,7 +124,7 @@ tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-q tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) qapi-types.o qapi-visit.o libqemuutil.a libqemustub.a -tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a +tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) $(block-obj-y) libqemuutil.a libqemustub.a tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
tests/test-visitor-serialization.c +72 -0
96 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v2 9/9 update_maintainers.diff
In reply to Joel SchoppSince I'm throwing all this code out there I'm also signing up to maintain it. Send me your bug reports.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -790,3 +790,11 @@ Stable 0.10 L: [email protected] T: git git://git.qemu.org/qemu-stable-0.10.git S: Orphan + +Visitors +--------------- +ASN.1 BER +M: Joel Schopp <[email protected]> +S: Maintained +F: /qapi/ber* +F: include/qapi/ber*
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 9/9] update_maintainers.diff
Quoted 6 lines · Joel Schopp
Since I'm throwing all this code out there I'm also signing up to maintain it. Send me your bug reports.
Cc Michael Tsirkin <[email protected]>Cc Stefan Berger <[email protected]>Signed-off-by Joel Schopp <[email protected]>
Quoted 8 lines
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)+++ b/MAINTAINERS
+F:
include/qapi/ber*
\ No newline at end of file
Fix that.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org