diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2021-06-16 14:29:28 +0100 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2021-06-27 18:35:02 +0000 |
commit | cfa8e152141367edb7b53e90da4ad80e995f3607 (patch) | |
tree | b4d5e8f7a5a446436cc3ef1ada4a06fbf91a255e | |
parent | 4a1cacfb1a21b2583809451089d115fc8a23133e (diff) |
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 <Alexander.Richardson@cl.cam.ac.uk>
-rw-r--r-- | include/X11/Intrinsic.h | 16 |
1 files changed, 15 insertions, 1 deletions
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 <stdint.h> +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.) */ |