From cfa8e152141367edb7b53e90da4ad80e995f3607 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Wed, 16 Jun 2021 14:29:28 +0100 Subject: XtArgVal: Support architectures where pointers are bigger than long On CHERI-enabled architectures (e.g. Arm's Morello), pointers are twice the size of addresses (i.e. 128 bits for Morello, 64 bits for 32-bit RISC-V). However, XtArgVal is currently defined as long, so it cannot be used to store pointers on these architectures. This commit changes XtArgVal to use intptr_t instead, which should be long on most architectures but is larger for CHERI. It also introduces XtIntPtr/XtUIntPtr which will be used in follow-up changes. This commit should also help on LLP64 ABIs where long is 32 bits but pointers are 64 bits. I am not sure what the compiler and C standard requirements are, so I've guarded the use of stdint.h with `#if __STDC_VERSION__ >= 199901L`. I've also added a _Static_assert() when compiling in C11 mode to statically verify that the XtArgVal type requirements are met. Signed-off-by: Alex Richardson --- include/X11/Intrinsic.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/X11/Intrinsic.h b/include/X11/Intrinsic.h index cf8d3fe..9bcc8dc 100644 --- a/include/X11/Intrinsic.h +++ b/include/X11/Intrinsic.h @@ -111,6 +111,15 @@ typedef char *String; #define TRUE 1 #endif +#if __STDC_VERSION__ >= 199901L +#include +typedef intptr_t XtIntPtr; +typedef uintptr_t XtUIntPtr; +#else +typedef long XtIntPtr; +typedef unsigned long XtUIntPtr; +#endif + #define XtNumber(arr) ((Cardinal) (sizeof(arr) / sizeof(arr[0]))) typedef struct _WidgetRec *Widget; @@ -157,7 +166,7 @@ typedef int XtCacheType; * ****************************************************************/ typedef char Boolean; -typedef long XtArgVal; +typedef XtIntPtr XtArgVal; typedef unsigned char XtEnum; typedef unsigned int Cardinal; @@ -165,6 +174,11 @@ typedef unsigned short Dimension; /* Size in pixels */ typedef short Position; /* Offset from 0 coordinate */ typedef void* XtPointer; +#if __STDC_VERSION__ >= 201112L +_Static_assert(sizeof(XtArgVal) >= sizeof(XtPointer), "XtArgVal too small"); +_Static_assert(sizeof(XtArgVal) >= sizeof(long), "XtArgVal too small"); +#endif + /* The type Opaque is NOT part of the Xt standard, do NOT use it. */ /* (It remains here only for backward compatibility.) */ -- cgit v1.2.1