X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Fcommon.h;h=5e6757b4099c209bb5f135b26eea89571773e5cc;hb=7fa8c1bc673add68529fa2bda8134be5089e8745;hp=7a176a421a8c252671105f6958e81651d7621b95;hpb=43cbaab1fc66139d3dfd87a2f8b6be5d906ee317;p=apps%2Fpfixtools.git diff --git a/common/common.h b/common/common.h index 7a176a4..5e6757b 100644 --- a/common/common.h +++ b/common/common.h @@ -63,11 +63,23 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); -#define __init __attribute__((__used__,__section__("MAD_INIT,__text,regular"))) -#define __exit __attribute__((__used__,__section__("MAD_EXIT,__text,regular"))) - -#define module_init(fn) static __init initcall_t __init_##fn = fn; -#define module_exit(fn) static __exit exitcall_t __exit_##fn = fn; +void common_register_exit(exitcall_t exitcall); +void common_init(void); + +#define module_init(fn) \ + __attribute__((constructor,used)) \ + static void __init_wrapper__ ## fn (void) { \ + common_init(); \ + if (fn() != 0) { \ + exit(-1); \ + } \ + } +#define module_exit(fn) \ + __attribute__((constructor,used)) \ + static void __exit_wrapper ## fn(void) { \ + common_init(); \ + common_register_exit(fn); \ + } #define likely(expr) __builtin_expect((expr) != 0, 1) #define unlikely(expr) __builtin_expect((expr) != 0, 0)