xserver: Branch 'master'
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Dec 17 19:36:19 UTC 2023
record/set.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
New commits:
commit cb8938e3d37f28b75a18974a8825cac554a48718
Author: Alex Richardson <Alexander.Richardson at cl.cam.ac.uk>
Date: Sun May 22 14:57:52 2022 +0000
record: Support architectures with sizeof(void*) > sizeof(long)
I was seeing SIGBUS errors when running TigerVNC inside the record code
because the offsets into the memory buffer were not sufficiently aligned
to use the RecordSetRec (alignof(void*)). The current code ensures that
all offsets are aligned to sizeof(unsigned long), but that may not be
sufficient to load/store a pointer. Architectures where this is not true
include Arm Morello which has 16-byte pointers and 8-byte longs.
diff --git a/record/set.c b/record/set.c
index e0db385b9..74e40d93e 100644
--- a/record/set.c
+++ b/record/set.c
@@ -54,6 +54,17 @@ from The Open Group.
#include "misc.h"
#include "set.h"
+/*
+ * Ideally we would always use _Alignof(type) here, but that requires C11, so
+ * we approximate this using sizeof(void*) for older C standards as that
+ * should be a valid assumption on all supported architectures.
+ */
+#if defined(__STDC__) && (__STDC_VERSION__ - 0 >= 201112L)
+#define MinSetAlignment(type) max(_Alignof(type), _Alignof(unsigned long))
+#else
+#define MinSetAlignment(type) max(sizeof(void*), sizeof(unsigned long))
+#endif
+
static int
maxMemberInInterval(RecordSetInterval * pIntervals, int nIntervals)
{
@@ -179,7 +190,7 @@ BitVectorSetMemoryRequirements(RecordSetInterval * pIntervals, int nIntervals,
{
int nlongs;
- *alignment = sizeof(unsigned long);
+ *alignment = MinSetAlignment(BitVectorSet);
nlongs = (maxMember + BITS_PER_LONG) / BITS_PER_LONG;
return (sizeof(BitVectorSet) + nlongs * sizeof(unsigned long));
}
@@ -289,7 +300,7 @@ static int
IntervalListMemoryRequirements(RecordSetInterval * pIntervals, int nIntervals,
int maxMember, int *alignment)
{
- *alignment = sizeof(unsigned long);
+ *alignment = MinSetAlignment(IntervalListSet);
return sizeof(IntervalListSet) + nIntervals * sizeof(RecordSetInterval);
}
More information about the xorg-commit
mailing list