Module: xenomai-forge
Branch: master
Commit: 4b4fe59d9eefee241ec4e85c5d94e22d11d9575f
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=4b4fe59d9eefee241ec4e85c5d94e22d11d9575f

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Jul 15 12:35:19 2013 +0200

cobalt/signal: add generic accessors to extra siginfo/sigevent data

---

 include/cobalt/uapi/signal.h |   65 ++++++++++++++++++++++++++++++++++++++++++
 kernel/cobalt/posix/thread.c |    1 +
 2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/include/cobalt/uapi/signal.h b/include/cobalt/uapi/signal.h
index b6a3cf3..1cb06b4 100644
--- a/include/cobalt/uapi/signal.h
+++ b/include/cobalt/uapi/signal.h
@@ -59,4 +59,69 @@
 
 #define COBALT_DELAYMAX                        2147483647U
 
+/*
+ * Internal accessors to extra siginfo/sigevent fields, extending some
+ * existing base field. The extra data should be grouped in a
+ * dedicated struct type. The extra space is taken from the padding
+ * area available from the original structure definitions.
+ *
+ * e.g. getting the address of the following extension to
+ * _sifields._rt from siginfo_t,
+ *
+ * struct bar {
+ *    int foo;
+ * };
+ *
+ * would be noted as:
+ *
+ * siginfo_t si;
+ * struct bar *p = __cobalt_si_extra(&si, _rt, struct bar);
+ *
+ * This code is shared between kernel and user space. Proper
+ * definitions of siginfo_t and sigevent_t should have been read prior
+ * to including this file.
+ *
+ * CAUTION: this macro does not handle alignment issues for the extra
+ * data. The extra type definition should take care of this.
+ */
+#ifdef __OPTIMIZE__
+extern void *__siginfo_overflow(void);
+static inline void *__check_si_overflow(size_t fldsz, size_t extrasz, void *p)
+{
+       siginfo_t *si __attribute__((unused));
+
+       if (fldsz + extrasz <= sizeof(si->_sifields))
+               return p;
+
+       return __siginfo_overflow();
+}
+#define __cobalt_si_extra(__si, __basefield, __type)                           
\
+       ((__type *)__check_si_overflow(sizeof(__si->_sifields.__basefield),     
\
+              sizeof(__type), &(__si->_sifields.__basefield) + 1))
+#else
+#define __cobalt_si_extra(__si, __basefield, __type)                           
\
+       ((__type *)((&__si->_sifields.__basefield) + 1))
+#endif
+
+/* Same approach, this time for extending sigevent_t. */
+
+#ifdef __OPTIMIZE__
+extern void *__sigevent_overflow(void);
+static inline void *__check_sev_overflow(size_t fldsz, size_t extrasz, void *p)
+{
+       sigevent_t *sev __attribute__((unused));
+
+       if (fldsz + extrasz <= sizeof(sev->_sigev_un))
+               return p;
+
+       return __sigevent_overflow();
+}
+#define __cobalt_sev_extra(__sev, __basefield, __type)                         
\
+       ((__type *)__check_sev_overflow(sizeof(__sev->_sigev_un.__basefield),   
\
+              sizeof(__type), &(__sev->_sigev_un.__basefield) + 1))
+#else
+#define __cobalt_sev_extra(__sev, __basefield, __type)                         
\
+       ((__type *)((&__sev->_sigev_un.__basefield) + 1))
+#endif
+
 #endif /* !_COBALT_UAPI_SIGNAL_H */
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 2986bc4..c3ddfd4 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -31,6 +31,7 @@
 #include <linux/types.h>
 #include <linux/cred.h>
 #include <linux/jhash.h>
+#include <linux/signal.h>
 #include <cobalt/uapi/signal.h>
 #include "thread.h"
 #include "timer.h"


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to