[WUPS] Added Macro for the Initialization hook

This commit is contained in:
Maschell 2018-02-10 17:00:17 +01:00
parent 17e34ad60b
commit 81b5bed341
3 changed files with 40 additions and 10 deletions

View File

@ -5,12 +5,16 @@ SECTIONS {
.wups.load : {
*(.wups.load*)
}
.wups.hooks : {
*(.wups.hooks*)
}
.text : {
*(.text*)
}
.sdata : {
*(.sdata*)
}.data : {
}
.data : {
*(.data*)
}
.rodata : {

View File

@ -7,4 +7,8 @@ SECTIONS {
wups_load = .;
*(.wups.load*)
}
.wups.hooks : {
wups_hooks = .;
*(.wups.hooks*)
}
}

View File

@ -34,17 +34,11 @@ extern "C" {
#endif
#define WUPS_SECTION(x) __attribute__((__section__ (".wups." x)))
#define DECL_FUNCTION(res, name, ...) \
res (* real_ ## name)(__VA_ARGS__) __attribute__((section(".data"))); \
res my_ ## name(__VA_ARGS__)
typedef enum wups_loader_entry_type_t {
WUPS_LOADER_ENTRY_FUNCTION,
WUPS_LOADER_ENTRY_FUNCTION_MANDATORY,
WUPS_LOADER_ENTRY_EXPORT
} wups_loader_entry_type_t;
typedef enum wups_loader_library_type_t {
WUPS_LOADER_LIBRARY_AVM,
WUPS_LOADER_LIBRARY_CAMERA,
@ -114,6 +108,36 @@ typedef enum wups_loader_library_type_t {
WUPS_LOADER_LIBRARY_ZLIB125,
} wups_loader_library_type_t;
typedef enum wups_loader_hook_type_t {
WUPS_LOADER_HOOK_INIT_FUNCTION
} wups_loader_hook_type_t;
typedef struct wups_loader_hook_t {
wups_loader_hook_type_t type;
const void *target; /*Address of our own, new function (my_XXX)*/
} wups_loader_hook_t;
#define WUPS_HOOK_INIT(original_func) \
extern const wups_loader_hook_t wups_hooks_init_ ## original_func \
WUPS_SECTION("hooks"); \
const wups_loader_hook_t wups_hooks_init_ ## original_func = { \
.type = WUPS_LOADER_HOOK_INIT_FUNCTION, \
.target = (const void*)&(original_func) \
}
#define INITIALIZE() \
void init();\
WUPS_HOOK_INIT(init); \
void init()
typedef enum wups_loader_entry_type_t {
WUPS_LOADER_ENTRY_FUNCTION,
WUPS_LOADER_ENTRY_FUNCTION_MANDATORY,
WUPS_LOADER_ENTRY_EXPORT
} wups_loader_entry_type_t;
typedef struct wups_loader_entry_t {
wups_loader_entry_type_t type;
union {
@ -127,8 +151,6 @@ typedef struct wups_loader_entry_t {
} data;
} wups_loader_entry_t;
#define WUPS_MUST_REPLACE(x, lib, function_name) WUPS_MUST_REPLACE_EX(real_ ## x, lib, my_ ## x, function_name);
#define WUPS_MUST_REPLACE_EX(original_func, rpl_type, replace_func, replace_function_name) \