From 53ff16348973deef1295e123b20a218eb6b7e339 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 3 Feb 2020 12:55:07 -0800 Subject: libs/sig: consideration for sig_t.ctxt alignment The flexible array of void *'s would just align to a pointer, which may not be safe for all members of whatever gets shoved in here. In an effort to make it more robust, make it an array of a junk drawer union of types. --- src/libs/sig/sig.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/libs') diff --git a/src/libs/sig/sig.c b/src/libs/sig/sig.c index fea83b6..865c6b4 100644 --- a/src/libs/sig/sig.c +++ b/src/libs/sig/sig.c @@ -4,10 +4,28 @@ #include "sig.h" +/* This is to try ensure ctxt's alignment accomodates all the base type sizes, + * it may waste some space in sig_t but since the caller supplies just a size + * via the supplied sig_ops_t.size(), we know nothing of the alignment reqs. + * + * XXX: If callers start using other types like xmmintrinsics __m128, this + * struct will have to get those added. + */ +typedef union sig_context_t { + float f; + double d; + long double ld; + char c; + short s; + int i; + long l; + long long ll; + void *p; +} sig_context_t; typedef struct sig_t { const sig_ops_t *ops; - void *ctxt[]; + sig_context_t ctxt[]; } sig_t; -- cgit v1.2.3