summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2016-02-27 19:37:50 +0000
committerFrediano Ziglio <fziglio@redhat.com>2016-03-17 17:16:30 +0000
commit2505f9ac964fc28b7ad97f3cd2d7cb3475dcaee5 (patch)
treea88cb9bcb3e8e1c80e1ec54da58d0e45f90d66c2
parent0f45924f4c5bfca7cfa98553c6e9f85499023c5f (diff)
define SPICE_CONSTRUCTOR_FUNC and SPICE_DESTRUCTOR_FUNC macros
Allow to define functions executed at program/shared object initialization or close. Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Victor Toso <victortoso@redhat.com>
-rw-r--r--common/macros.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/common/macros.h b/common/macros.h
index 47289be..fe36929 100644
--- a/common/macros.h
+++ b/common/macros.h
@@ -29,5 +29,27 @@
#define SPICE_ATTR_PRINTF
#endif /* __GNUC__ */
+#ifdef __GNUC__
+#define SPICE_CONSTRUCTOR_FUNC(func_name) \
+ static void __attribute__((constructor)) func_name(void)
+#define SPICE_DESTRUCTOR_FUNC(func_name) \
+ static void __attribute__((destructor)) func_name(void)
+#elif defined(_MSC_VER)
+#define SPICE_CONSTRUCTOR_FUNC(func_name) \
+ static void func_name(void); \
+ static int func_name ## _wrapper(void) { func_name(); return 0; } \
+ __pragma(section(".CRT$XCU",read)) \
+ __declspec(allocate(".CRT$XCU")) static int (* _array ## func_name)(void) = func_name ## _wrapper; \
+ static void func_name(void)
+#define SPICE_DESTRUCTOR_FUNC(func_name) \
+ static void func_name(void); \
+ static int func_name ## _wrapper(void) { func_name(); return 0; } \
+ __pragma(section(".CRT$XPU",read)) \
+ __declspec(allocate(".CRT$XPU")) static int (* _array ## func_name)(void) = func_name ## _wrapper; \
+ static void func_name(void)
+#else
+#error Please implement SPICE_CONSTRUCTOR_FUNC and SPICE_DESTRUCTOR_FUNC for this compiler
+#endif
+
#endif /* __MACROS_H */