Fix SDL_Event definition to support systems with pointers larger than 8 bytes

This is needed to support CHERI, and thus Arm's experimental Morello
prototype, where pointers are implemented using unforgeable capabilities
that include bounds and permissions metadata to provide fine-grained
spatial and referential memory safety, as well as revocation by sweeping
memory to provide heap temporal memory safety.
This commit is contained in:
Jessica Clarke 2021-07-29 17:53:10 +01:00 committed by Sam Lantinga
parent 9d457aa446
commit c8b4edf3d0

View File

@ -620,18 +620,24 @@ typedef union SDL_Event
SDL_DollarGestureEvent dgesture; /**< Gesture event data */ SDL_DollarGestureEvent dgesture; /**< Gesture event data */
SDL_DropEvent drop; /**< Drag and drop event data */ SDL_DropEvent drop; /**< Drag and drop event data */
/* This is necessary for ABI compatibility between Visual C++ and GCC /* This is necessary for ABI compatibility between Visual C++ and GCC.
Visual C++ will respect the push pack pragma and use 52 bytes for Visual C++ will respect the push pack pragma and use 52 bytes (size of
this structure, and GCC will use the alignment of the largest datatype SDL_TextEditingEvent, the largest structure for 32-bit and 64-bit
within the union, which is 8 bytes. architectures) for this union, and GCC will use the alignment of the
largest datatype within the union, which is 8 bytes on 64-bit
architectures.
So... we'll add padding to force the size to be 56 bytes for both. So... we'll add padding to force the size to be 56 bytes for both.
On architectures where pointers are 16 bytes, this needs rounding up to
the next multiple of 16, 64, and on architectures where pointers are
even larger the size of SDL_UserEvent will dominate as being 3 pointers.
*/ */
Uint8 padding[56]; Uint8 padding[sizeof(void *) <= 8 ? 56 : sizeof(void *) == 16 ? 64 : 3 * sizeof(void *)];
} SDL_Event; } SDL_Event;
/* Make sure we haven't broken binary compatibility */ /* Make sure we haven't broken binary compatibility */
SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == 56); SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == sizeof(((SDL_Event *)NULL)->padding));
/* Function prototypes */ /* Function prototypes */