From 6d77b155bcd4725e09837604e6ea86f5f124ba9c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 5 Dec 2023 20:10:48 +0100 Subject: Third commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libsyscalls.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'libsyscalls.h') diff --git a/libsyscalls.h b/libsyscalls.h index 4c904b7..066de20 100644 --- a/libsyscalls.h +++ b/libsyscalls.h @@ -1129,8 +1129,9 @@ struct libsyscalls_datatype_description { enum libsyscalls_datatype_section section; /** - * This is a ~0 terminated array describing the order - * of the bytes the the data type + * This is a ~0 terminated array — but, it can also + * be terminated by the end of the array — describing + * the order of the bytes the the data type * * The lowest non-zero values contains the width of * a byte (in bytes), however no such value exists @@ -1146,8 +1147,17 @@ struct libsyscalls_datatype_description { * there is always a value in .byteorder that is 0, * unless .byteorder[0] is ~0 * - * To avoid problems checking for ~0, use - * the LIBSYSCALLS_IS_BYTEORDER_END macro + * To avoid problems checking for ~0, use the + * LIBSYSCALLS_IS_BYTEORDER_END macro; please also be + * aware that both the type and length can change in + * the future: do not assume it's `unsigned char`, + * and do not assume it has 32 elements, do not only + * `LIBSYSCALLS_IS_BYTEORDER_END` to detect ~0, but + * also check that no more than + * `sizeof(x.byteorder) / sizeof(*x.byteorder)` + * elements are read (where x is the instance of the + * structure) (you should definitely have your own + * macro for that one) */ unsigned char byteorder[32]; @@ -1160,8 +1170,13 @@ struct libsyscalls_datatype_description { * @param SHIFT The value to test `struct libsyscalls_datatype_description.byteorder` * @return :int Whether the value is ~0 */ -#define LIBSYSCALLS_IS_BYTEORDER_END(SHIFT)\ +#ifdef UINTMAX_C +# define LIBSYSCALLS_IS_BYTEORDER_END(SHIFT)\ + (!~((SHIFT) | ~LIBSYSCALLS_FIELD_MASK_(UINTMAX_C(1), struct libsyscalls_datatype_description, byteorder[0]))) +#else +# define LIBSYSCALLS_IS_BYTEORDER_END(SHIFT)\ (!~((SHIFT) | ~LIBSYSCALLS_FIELD_MASK_(1ULL, struct libsyscalls_datatype_description, byteorder[0]))) +#endif }; -- cgit v1.2.3-70-g09d2