diff options
author | Frediano Ziglio <fziglio@redhat.com> | 2018-03-06 17:22:52 +0000 |
---|---|---|
committer | Frediano Ziglio <freddy77@gmail.com> | 2021-01-19 13:24:55 +0000 |
commit | 13b90a74a6a8f0f7ceade8656e3bc736a0319dcc (patch) | |
tree | 6d5644545250c9b6c22752e01f36e1dc9f5fc337 | |
parent | 06aa9375ad17ffa690a8b572aff6ee1168ffcf7a (diff) |
stream-device: Force proper packing of protocol structures
Assuming the packing of structure can be a portability issue.
Currently there are no real-world ABI that would break these structure
however to be safe force a 4 byte packing.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r-- | spice/end-packed4.h | 34 | ||||
-rw-r--r-- | spice/meson.build | 2 | ||||
-rw-r--r-- | spice/start-packed4.h | 59 | ||||
-rw-r--r-- | spice/stream-device.h | 4 |
4 files changed, 99 insertions, 0 deletions
diff --git a/spice/end-packed4.h b/spice/end-packed4.h new file mode 100644 index 0000000..79fd74c --- /dev/null +++ b/spice/end-packed4.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + Copyright (C) 2009-2018 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* See start-packed4.h for details */ + +#pragma pack(pop) diff --git a/spice/meson.build b/spice/meson.build index 37268df..c871b86 100644 --- a/spice/meson.build +++ b/spice/meson.build @@ -1,6 +1,7 @@ spice_protocol_headers = [ 'barrier.h', 'end-packed.h', + 'end-packed4.h', 'enums.h', 'ipc_ring.h', 'macros.h', @@ -8,6 +9,7 @@ spice_protocol_headers = [ 'qxl_dev.h', 'qxl_windows.h', 'start-packed.h', + 'start-packed4.h', 'stats.h', 'types.h', 'vd_agent.h', diff --git a/spice/start-packed4.h b/spice/start-packed4.h new file mode 100644 index 0000000..996f640 --- /dev/null +++ b/spice/start-packed4.h @@ -0,0 +1,59 @@ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + Copyright (C) 2009-2018 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Ideally this should all have been macros in a common headers, but + * its not possible to put pragmas into header files, so we have + * to use include magic. + * + * Use it like this: + * + * #include <spice/start-packed4.h> + * + * typedef struct { + * ... + * } Type; + * + * #include <spice/end-packed4.h> + * + */ + +#ifdef __GNUC__ + +#pragma pack(push,4) + +#else + +#pragma pack(push) +#pragma pack(4) +#pragma warning(disable:4200) +#pragma warning(disable:4103) + +#endif diff --git a/spice/stream-device.h b/spice/stream-device.h index 15d839b..e559f16 100644 --- a/spice/stream-device.h +++ b/spice/stream-device.h @@ -42,6 +42,8 @@ #include <spice/types.h> +#include <spice/start-packed4.h> + /* * Structures are all "naturally aligned" * containing integers up to 64 bit. @@ -267,4 +269,6 @@ typedef struct StreamMsgCursorMove { int32_t y; } StreamMsgCursorMove; +#include <spice/end-packed4.h> + #endif /* SPICE_STREAM_DEVICE_H_ */ |