Format the code via clang-format

This commit is contained in:
Maschell
2022-02-04 22:24:22 +01:00
parent c7b9039dae
commit fdf9993069
16 changed files with 341 additions and 147 deletions

View File

@@ -1,6 +1,6 @@
#pragma once
#include "wums/meta.h"
#include "wums/common.h"
#include "wums/exports.h"
#include "wums/hooks.h"
#include "wums/hooks.h"
#include "wums/meta.h"

View File

@@ -31,11 +31,11 @@
extern "C" {
#endif
#define WUMS_SECTION(x) __attribute__((__section__ (".wums." x)))
#define WUMS_SECTION(x) __attribute__((__section__(".wums." x)))
#define WUMS_META(id, value) \
extern const char wums_meta_ ## id [] WUMS_SECTION("meta"); \
const char wums_meta_ ## id [] = #id "=" value
#define WUMS_META(id, value) \
extern const char wums_meta_##id[] WUMS_SECTION("meta"); \
const char wums_meta_##id[] = #id "=" value
#ifdef __cplusplus
}

View File

@@ -18,20 +18,20 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define DYN_LINK_FUNCTION_NAME_LENGTH 351
#define DYN_LINK_IMPORT_NAME_LENGTH 50
#define DYN_LINK_FUNCTION_NAME_LENGTH 351
#define DYN_LINK_IMPORT_NAME_LENGTH 50
#define DYN_LINK_FUNCTION_LIST_LENGTH 500
#define DYN_LINK_IMPORT_LIST_LENGTH 50
#define DYN_LINK_FUNCTION_LIST_LENGTH 500
#define DYN_LINK_IMPORT_LIST_LENGTH 50
#define DYN_LINK_TRAMPOLINE_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
#define DYN_LINK_TRAMPOLINE_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
typedef struct _dyn_linking_function_t {
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];

View File

@@ -2,7 +2,7 @@
#include <stdint.h>
#define EXPORT_MAXIMUM_NAME_LENGTH 50
#define EXPORT_MAXIMUM_NAME_LENGTH 50
typedef struct export_data_t {
uint32_t type;
char name[EXPORT_MAXIMUM_NAME_LENGTH];

View File

@@ -17,23 +17,23 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include "dynamic_linking_defines.h"
#include "relocation_defines.h"
#include "export_defines.h"
#include "relocation_defines.h"
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAXIMUM_MODULE_PATH_NAME_LENGTH 256
#define MAXIMUM_EXPORT_MODULE_NAME_LENGTH 51
#define MAXIMUM_MODULE_PATH_NAME_LENGTH 256
#define MAXIMUM_EXPORT_MODULE_NAME_LENGTH 51
#define FUNCTION_SYMBOL_LIST_LENGTH 50000
#define DYN_LINK_RELOCATION_LIST_LENGTH 500
#define EXPORT_ENTRY_LIST_LENGTH 100
#define HOOK_ENTRY_LIST_LENGTH 20
#define FUNCTION_SYMBOL_LIST_LENGTH 50000
#define DYN_LINK_RELOCATION_LIST_LENGTH 500
#define EXPORT_ENTRY_LIST_LENGTH 100
#define HOOK_ENTRY_LIST_LENGTH 20
typedef struct hook_data_t {
uint32_t type;
@@ -41,18 +41,19 @@ typedef struct hook_data_t {
} hook_data_t;
typedef struct module_function_symbol_data_t {
char* name;
void* address;
char *name;
void *address;
uint32_t size;
} module_function_symbol_data_t;
// clang-format off
typedef struct module_information_single_t {
char path[MAXIMUM_MODULE_PATH_NAME_LENGTH]; // Path where the module is stored
char path[MAXIMUM_MODULE_PATH_NAME_LENGTH]; // Path where the module is stored
dyn_linking_relocation_entry_t linking_entries[DYN_LINK_RELOCATION_LIST_LENGTH];
char module_export_name[MAXIMUM_EXPORT_MODULE_NAME_LENGTH];
export_data_t export_entries[EXPORT_ENTRY_LIST_LENGTH];
hook_data_t hook_entries[HOOK_ENTRY_LIST_LENGTH];
int32_t priority; // Priority of this module
int32_t priority; // Priority of this module
uint32_t bssAddr;
uint32_t bssSize;
uint32_t sbssAddr;
@@ -65,19 +66,22 @@ typedef struct module_information_single_t {
module_function_symbol_data_t * function_symbol_entries;
uint32_t number_used_function_symbols;
} module_information_single_t;
// clang-format on
#define MAXIMUM_MODULES 32
#define MODULE_INFORMATION_VERSION 0x00000007
#define MAXIMUM_MODULES 32
#define MODULE_INFORMATION_VERSION 0x00000007
// clang-format off
typedef struct module_information_t {
uint32_t version;
int32_t number_used_modules; // Number of used function. Maximum is MAXIMUM_MODULES
int32_t number_used_modules; // Number of used function. Maximum is MAXIMUM_MODULES
dyn_linking_relocation_data_t linking_data;
relocation_trampoline_entry_t trampolines[DYN_LINK_TRAMPOLINE_LIST_LENGTH];
module_function_symbol_data_t function_symbols[FUNCTION_SYMBOL_LIST_LENGTH];
uint32_t number_used_function_symbols;
module_information_single_t module_data[MAXIMUM_MODULES];
} module_information_t;
// clang-format on
#ifdef __cplusplus
}

View File

@@ -2,16 +2,16 @@
#include <stdint.h>
typedef enum RelocationTrampolineStatus{
RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3,
typedef enum RelocationTrampolineStatus {
RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3,
} RelocationTrampolineStatus;
typedef enum RelocationType{
RELOC_TYPE_FIXED = 0,
RELOC_TYPE_IMPORT = 1
typedef enum RelocationType {
RELOC_TYPE_FIXED = 0,
RELOC_TYPE_IMPORT = 1
} RelocationType;
typedef struct relocation_trampoline_entry_t {

View File

@@ -38,21 +38,20 @@ typedef enum wums_entry_type_t {
typedef struct wums_entry_t {
wums_entry_type_t type;
const char *name; /* name of the export */
const void *address; /* pointer to the export */
const char *name; /* name of the export */
const void *address; /* pointer to the export */
} wums_loader_entry_t;
#define WUMS_EXPORT_FUNCTION(function) WUMS_EXPORT(WUMS_FUNCTION_EXPORT, function, function)
#define WUMS_EXPORT_DATA(pointer) WUMS_EXPORT(WUMS_DATA_EXPORT, pointer, &pointer)
#define WUMS_EXPORT_FUNCTION(function) WUMS_EXPORT(WUMS_FUNCTION_EXPORT, function, function)
#define WUMS_EXPORT_DATA(pointer) WUMS_EXPORT(WUMS_DATA_EXPORT, pointer, &pointer)
#define WUMS_EXPORT(_type, pointer, value) \
#define WUMS_EXPORT(_type, pointer, value) \
extern const wums_loader_entry_t wums_entry_##pointer \
WUMS_SECTION("exports"); \
const wums_loader_entry_t wums_entry_##pointer = { \
.type = _type, \
.name = # pointer, \
.address = (const void*) value \
}
WUMS_SECTION("exports"); \
const wums_loader_entry_t wums_entry_##pointer = { \
.type = _type, \
.name = #pointer, \
.address = (const void *) value}
#ifdef __cplusplus
}

View File

@@ -32,12 +32,11 @@
extern "C" {
#endif
#define WUMS_HOOK_EX(type_def, original_func) \
extern const wums_hook_t wums_hooks_ ## original_func WUMS_SECTION("hooks"); \
const wums_hook_t wums_hooks_ ## original_func = { \
.type = type_def, \
.target = (const void*)&(original_func) \
}
#define WUMS_HOOK_EX(type_def, original_func) \
extern const wums_hook_t wums_hooks_##original_func WUMS_SECTION("hooks"); \
const wums_hook_t wums_hooks_##original_func = { \
.type = type_def, \
.target = (const void *) &(original_func)}
typedef enum wums_hook_type_t {
WUMS_HOOK_INIT_WUT_MALLOC,
@@ -51,8 +50,8 @@ typedef enum wums_hook_type_t {
WUMS_HOOK_INIT_WUT_SOCKETS,
WUMS_HOOK_FINI_WUT_SOCKETS,
WUMS_HOOK_INIT_WRAPPER, /* Calls __init */
WUMS_HOOK_FINI_WRAPPER, /* Calls __fini */
WUMS_HOOK_INIT_WRAPPER, /* Calls __init */
WUMS_HOOK_FINI_WRAPPER, /* Calls __fini */
WUMS_HOOK_INIT,
WUMS_HOOK_APPLICATION_STARTS,
@@ -62,8 +61,8 @@ typedef enum wums_hook_type_t {
} wums_hook_type_t;
typedef struct wums_hook_t {
wums_hook_type_t type; /* Defines the type of the hook */
const void *target; /* Address of our own, new function */
wums_hook_type_t type; /* Defines the type of the hook */
const void *target; /* Address of our own, new function */
} wums_hook_t;
typedef struct wums_app_init_args_t {
@@ -74,104 +73,104 @@ typedef struct wums_relocs_done_args_t {
module_information_t *module_information;
} wums_relocs_done_args_t;
#define WUMS_INITIALIZE(myargs) \
void __wums__init(wums_app_init_args_t);\
#define WUMS_INITIALIZE(myargs) \
void __wums__init(wums_app_init_args_t); \
WUMS_HOOK_EX(WUMS_HOOK_INIT, __wums__init); \
void __wums__init(wums_app_init_args_t myargs)
#define WUMS_APPLICATION_STARTS() \
void __wums_start(void);\
#define WUMS_APPLICATION_STARTS() \
void __wums_start(void); \
WUMS_HOOK_EX(WUMS_HOOK_APPLICATION_STARTS, __wums_start); \
void __wums_start()
#define WUMS_APPLICATION_ENDS() \
void __wums_end(void);\
#define WUMS_APPLICATION_ENDS() \
void __wums_end(void); \
WUMS_HOOK_EX(WUMS_HOOK_APPLICATION_ENDS, __wums_end); \
void __wums_end()
#define WUMS_APPLICATION_REQUESTS_EXIT() \
void __wums_requests_exit(void);\
#define WUMS_APPLICATION_REQUESTS_EXIT() \
void __wums_requests_exit(void); \
WUMS_HOOK_EX(WUMS_HOOK_APPLICATION_REQUESTS_EXIT, __wums_requests_exit); \
void __wums_requests_exit()
#define WUMS_RELOCATIONS_DONE(myargs) \
void __wums_relocations_done(wums_relocs_done_args_t);\
#define WUMS_RELOCATIONS_DONE(myargs) \
void __wums_relocations_done(wums_relocs_done_args_t); \
WUMS_HOOK_EX(WUMS_HOOK_RELOCATIONS_DONE, __wums_relocations_done); \
void __wums_relocations_done(wums_relocs_done_args_t myargs)
#ifdef __cplusplus
#define __EXTERN_C_MACRO extern "C"
#define __EXTERN_C_MACRO extern "C"
#else
#define __EXTERN_C_MACRO
#endif
#define WUMS_USE_WUT_MALLOC() \
__EXTERN_C_MACRO void __init_wut_malloc(); \
void on_init_wut_malloc(){ \
__init_wut_malloc(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_MALLOC,on_init_wut_malloc); \
__EXTERN_C_MACRO void __fini_wut_malloc(); \
void on_fini_wut_malloc(){ \
__fini_wut_malloc(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_MALLOC,on_fini_wut_malloc)
#define WUMS_USE_WUT_MALLOC() \
__EXTERN_C_MACRO void __init_wut_malloc(); \
void on_init_wut_malloc() { \
__init_wut_malloc(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_MALLOC, on_init_wut_malloc); \
__EXTERN_C_MACRO void __fini_wut_malloc(); \
void on_fini_wut_malloc() { \
__fini_wut_malloc(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_MALLOC, on_fini_wut_malloc)
#define WUMS_USE_WUT_DEVOPTAB() \
__EXTERN_C_MACRO void __init_wut_devoptab(); \
void on_init_wut_devoptab(){ \
__init_wut_devoptab(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_DEVOPTAB,on_init_wut_devoptab); \
__EXTERN_C_MACRO void __fini_wut_devoptab(); \
void on_fini_wut_devoptab(){ \
__fini_wut_devoptab(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_DEVOPTAB,on_fini_wut_devoptab)
#define WUMS_USE_WUT_DEVOPTAB() \
__EXTERN_C_MACRO void __init_wut_devoptab(); \
void on_init_wut_devoptab() { \
__init_wut_devoptab(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_DEVOPTAB, on_init_wut_devoptab); \
__EXTERN_C_MACRO void __fini_wut_devoptab(); \
void on_fini_wut_devoptab() { \
__fini_wut_devoptab(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_DEVOPTAB, on_fini_wut_devoptab)
#define WUMS_USE_WUT_NEWLIB() \
__EXTERN_C_MACRO void __init_wut_newlib(); \
void on_init_wut_newlib(){ \
__init_wut_newlib(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_NEWLIB,on_init_wut_newlib); \
__EXTERN_C_MACRO void __fini_wut_newlib(); \
void on_fini_wut_newlib(){ \
__fini_wut_newlib(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_NEWLIB,on_fini_wut_newlib)
#define WUMS_USE_WUT_NEWLIB() \
__EXTERN_C_MACRO void __init_wut_newlib(); \
void on_init_wut_newlib() { \
__init_wut_newlib(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_NEWLIB, on_init_wut_newlib); \
__EXTERN_C_MACRO void __fini_wut_newlib(); \
void on_fini_wut_newlib() { \
__fini_wut_newlib(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_NEWLIB, on_fini_wut_newlib)
#define WUMS_USE_WUT_STDCPP() \
__EXTERN_C_MACRO void __init_wut_stdcpp(); \
void on_init_wut_stdcpp(){ \
__init_wut_stdcpp(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_STDCPP,on_init_wut_stdcpp); \
__EXTERN_C_MACRO void __fini_wut_stdcpp(); \
void on_fini_wut_stdcpp(){ \
__fini_wut_stdcpp(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_STDCPP,on_fini_wut_stdcpp)
#define WUMS_USE_WUT_STDCPP() \
__EXTERN_C_MACRO void __init_wut_stdcpp(); \
void on_init_wut_stdcpp() { \
__init_wut_stdcpp(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_STDCPP, on_init_wut_stdcpp); \
__EXTERN_C_MACRO void __fini_wut_stdcpp(); \
void on_fini_wut_stdcpp() { \
__fini_wut_stdcpp(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_STDCPP, on_fini_wut_stdcpp)
#define WUMS_USE_WUT_SOCKETS() \
__EXTERN_C_MACRO void __init_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_SOCKETS,__init_wut_socket); \
__EXTERN_C_MACRO void __fini_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_SOCKETS,__fini_wut_socket)
#define WUMS_USE_WUT_SOCKETS() \
__EXTERN_C_MACRO void __init_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_SOCKETS, __init_wut_socket); \
__EXTERN_C_MACRO void __fini_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_SOCKETS, __fini_wut_socket)
#define WUMS___INIT_WRAPPER() \
#define WUMS___INIT_WRAPPER() \
__EXTERN_C_MACRO void __init(); \
void __init_wrapper(){ \
__init(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WRAPPER,__init_wrapper);
void __init_wrapper() { \
__init(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WRAPPER, __init_wrapper);
#define WUMS___FINI_WRAPPER() \
#define WUMS___FINI_WRAPPER() \
__EXTERN_C_MACRO void __fini(); \
void __fini_wrapper(){ \
__fini(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_FINI_WRAPPER,__fini_wrapper);
void __fini_wrapper() { \
__fini(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WRAPPER, __fini_wrapper);
#ifdef __cplusplus
}

View File

@@ -32,22 +32,22 @@
extern "C" {
#endif
#define WUMS_MODULE_EXPORT_NAME(x) \
WUMS_META(export_name, x); \
WUMS_META(wum, "0.3.1"); \
WUMS_USE_WUT_MALLOC(); \
WUMS_USE_WUT_SOCKETS(); \
WUMS_USE_WUT_NEWLIB(); \
WUMS_USE_WUT_STDCPP(); \
WUMS___INIT_WRAPPER(); \
WUMS___FINI_WRAPPER(); \
WUMS_META(buildtimestamp, __DATE__ " " __TIME__)
#define WUMS_MODULE_EXPORT_NAME(x) \
WUMS_META(export_name, x); \
WUMS_META(wum, "0.3.1"); \
WUMS_USE_WUT_MALLOC(); \
WUMS_USE_WUT_SOCKETS(); \
WUMS_USE_WUT_NEWLIB(); \
WUMS_USE_WUT_STDCPP(); \
WUMS___INIT_WRAPPER(); \
WUMS___FINI_WRAPPER(); \
WUMS_META(buildtimestamp, __DATE__ " " __TIME__)
#define WUMS_MODULE_AUTHOR(x) WUMS_META(author, x)
#define WUMS_MODULE_VERSION(x) WUMS_META(version, x)
#define WUMS_MODULE_LICENSE(x) WUMS_META(license, x)
#define WUMS_MODULE_DESCRIPTION(x) WUMS_META(description, x)
#define WUMS_MODULE_SKIP_INIT_FINI() WUMS_META(skipInitFini, "true")
#define WUMS_MODULE_AUTHOR(x) WUMS_META(author, x)
#define WUMS_MODULE_VERSION(x) WUMS_META(version, x)
#define WUMS_MODULE_LICENSE(x) WUMS_META(license, x)
#define WUMS_MODULE_DESCRIPTION(x) WUMS_META(description, x)
#define WUMS_MODULE_SKIP_INIT_FINI() WUMS_META(skipInitFini, "true")
#define WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK() WUMS_META(initBeforeRelocationDoneHook, "true")
#ifdef __cplusplus