summaryrefslogtreecommitdiff
path: root/libddekit/include/ddekit/initcall.h
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2011-05-08 22:45:06 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2011-05-08 22:45:06 +0200
commit878c5456c5a2f9bff741a7b7bcdccd5c1694db22 (patch)
treebcf3d101215fa70b953aa7e9d0de805c5f8865b4 /libddekit/include/ddekit/initcall.h
parent9062642230b7bfb48e7b30f98cba8528172b2d36 (diff)
parentc8f311a7a32d4b0cb0c21672f63bca8efdf5d83a (diff)
Merge branch 'dde' into HEAD
Diffstat (limited to 'libddekit/include/ddekit/initcall.h')
-rw-r--r--libddekit/include/ddekit/initcall.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/libddekit/include/ddekit/initcall.h b/libddekit/include/ddekit/initcall.h
new file mode 100644
index 00000000..6befa31c
--- /dev/null
+++ b/libddekit/include/ddekit/initcall.h
@@ -0,0 +1,42 @@
+#ifndef _ddekit_initcall_h
+#define _ddekit_initcall_h
+
+// from l4/sys/compiler.h
+#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4
+#define L4_STICKY(x) __attribute__((used)) x
+#else
+#define L4_STICKY(x) __attribute__((unused)) x
+#endif
+
+#define l4str(s) #s
+
+// from dde_linux/ARCH-x86/ctor.h
+typedef void (*l4ddekit_initcall_t)(void);
+
+#define __l4ddekit_initcall(p) \
+ __attribute__ ((__section__ (".l4dde_ctors." #p)))
+
+/** Define a function to be a DDEKit initcall.
+ *
+ * Define a function to be a DDEKit initcall. This function will then be placed
+ * in a separate linker section of the binary (called .l4dde_ctors). The L4Env
+ * construction mechanism will execute all constructors in this section during
+ * application startup.
+ *
+ * This is the right place to place Linux' module_init functions & Co.
+ *
+ * \param fn function
+ */
+#define DDEKIT_INITCALL(fn) DDEKIT_CTOR(fn, 1)
+
+#define DDEKIT_CTOR(fn, prio) \
+ l4ddekit_initcall_t \
+ L4_STICKY(__l4ddekit_initcall_##fn) \
+ __l4ddekit_initcall(prio) = (void *)fn
+
+/**
+ * Runs all registered initcalls.
+ */
+void ddekit_do_initcalls(void);
+
+#endif