diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..56cc685 --- /dev/null +++ b/.clang-format @@ -0,0 +1,67 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..c57cc35 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,25 @@ +name: CI-PR + +on: [pull_request] + +jobs: + clang-format-lib: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./include ./libraries + build-lib: + runs-on: ubuntu-18.04 + needs: clang-format-lib + steps: + - uses: actions/checkout@v2 + - name: build binary + run: | + docker build . -f Dockerfile.buildlocal -t builder + docker run --rm -v ${PWD}:/project builder make + - uses: actions/upload-artifact@master + with: + name: binary + path: "/lib/*.a" \ No newline at end of file diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index 9cd7bbd..ab5253e 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -4,8 +4,25 @@ on: branches: - master jobs: - build: + clang-format-lib: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./include ./libraries + build-lib: + runs-on: ubuntu-18.04 + needs: clang-format-lib + steps: + - uses: actions/checkout@v2 + - name: build binary + run: | + docker build . -f Dockerfile.buildlocal -t builder + docker run --rm -v ${PWD}:/project builder make + push_image: runs-on: ubuntu-latest + needs: build-lib steps: - uses: actions/checkout@master - name: Get release version diff --git a/Dockerfile b/Dockerfile index cf127e6..25db3d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM wiiuenv/devkitppc:20210920 +FROM wiiuenv/devkitppc:20211229 WORKDIR build COPY . . diff --git a/Dockerfile.buildlocal b/Dockerfile.buildlocal new file mode 100644 index 0000000..080eec7 --- /dev/null +++ b/Dockerfile.buildlocal @@ -0,0 +1,3 @@ +FROM wiiuenv/devkitppc:20211229 + +WORKDIR project \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..77d0912 --- /dev/null +++ b/README.MD @@ -0,0 +1,80 @@ +[![Publish Docker Image](https://github.com/wiiu-env/WiiUModuleSystem/actions/workflows/push_image.yml/badge.svg)](https://github.com/wiiu-env/WiiUModuleSystem/actions/workflows/push_image.yml) + +# Wii U Module System + +This lib is required to build Modules to be loaded with the [Wii U Module System Loader](https://github.com/wiiu-env/WUMSLoader). + +## Usage + +A module needs to implements at least the following macros. +```C++ +#include + +WUMS_MODULE_EXPORT_NAME("homebrew_modulename"); + +WUMS_INITIALIZE() { + /** THIS CODE WILL BE RUN ONCE **/ +} +``` + +The `WUMS_MODULE_EXPORT_NAME` needs to be a globally unique name across all loaded modules. `WUMS_INITIALIZE` defines the code that will be run after the module was loaded. +The module will have full permission to the sd card via `fs:/vol/external01`. + +### Optional macros/hooks +Other optional macros/hooks are support, here some examples: + +```C++ +WUMS_APPLICATION_STARTS() { + /** Is called when a new application was started. **/ +} + +WUMS_APPLICATION_REQUESTS_EXIT() { + /** Is called when a new application is going to be closed. **/ +} +``` + +This list is incomplete, see `hooks.h` for all hooks and `meta.h` for all macros. + +### Export functions + +Modules can be used to export functions for other modules or "normal" applications. + +```C++ +#include + +void MyCustomFunction() { + /** Some special code that should be useable for everyone */ +} + +WUMS_EXPORT_FUNCTION(MyCustomFunction); +``` + +This function can then be used like they would be inside a .rpl, where the name of the "rpl" is the one defined in `WUMS_MODULE_EXPORT_NAME`. + +Example using the Cafe OS OSDynLoad API: +```C++ +if (OSDynLoad_Acquire("homebrew_modulename", &sModuleHandle) != OS_DYNLOAD_OK) { + OSFatal("OSDynLoad_Acquire failed."); +} + +void (*sMyCustomFunction)() = NULL; + +if (OSDynLoad_FindExport(sModuleHandle, FALSE, "MyCustomFunction", (void**) &sMyCustomFunction) != OS_DYNLOAD_OK) { + OSFatal("OSDynLoad_FindExport failed."); +} +``` + +## Use this lib in Dockerfiles. +A prebuilt version of this lib can found on dockerhub. To use it for your projects, add this to your Dockerfile. +```Dockerfile +[...] +COPY --from=wiiuenv/wiiumodulesystem:[tag] /artifacts $DEVKITPRO +[...] +``` +Replace [tag] with a tag you want to use, a list of tags can be found [here](https://hub.docker.com/r/wiiuenv/wiiumodulesystem/tags). +It's highly recommended to pin the version to the **latest date** instead of using `latest`. + +## Format the code via docker +```bash +docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./include ./libraries -i +``` diff --git a/include/wums.h b/include/wums.h index a66b630..8c2f126 100644 --- a/include/wums.h +++ b/include/wums.h @@ -1,6 +1,6 @@ #pragma once -#include "wums/meta.h" #include "wums/common.h" #include "wums/exports.h" -#include "wums/hooks.h" \ No newline at end of file +#include "wums/hooks.h" +#include "wums/meta.h" \ No newline at end of file diff --git a/include/wums/common.h b/include/wums/common.h index 8c400ea..817807b 100644 --- a/include/wums/common.h +++ b/include/wums/common.h @@ -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 } diff --git a/include/wums/defines/dynamic_linking_defines.h b/include/wums/defines/dynamic_linking_defines.h index 406b4dc..39e4cf6 100644 --- a/include/wums/defines/dynamic_linking_defines.h +++ b/include/wums/defines/dynamic_linking_defines.h @@ -18,20 +18,20 @@ #pragma once #include -#include #include +#include #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]; diff --git a/include/wums/defines/export_defines.h b/include/wums/defines/export_defines.h index d061412..ac01c8e 100644 --- a/include/wums/defines/export_defines.h +++ b/include/wums/defines/export_defines.h @@ -2,7 +2,7 @@ #include -#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]; diff --git a/include/wums/defines/module_defines.h b/include/wums/defines/module_defines.h index 0b0c5e9..30bcc7a 100644 --- a/include/wums/defines/module_defines.h +++ b/include/wums/defines/module_defines.h @@ -17,23 +17,23 @@ #pragma once -#include -#include #include "dynamic_linking_defines.h" -#include "relocation_defines.h" #include "export_defines.h" +#include "relocation_defines.h" +#include +#include #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 } diff --git a/include/wums/defines/relocation_defines.h b/include/wums/defines/relocation_defines.h index e2719b8..5ca5881 100644 --- a/include/wums/defines/relocation_defines.h +++ b/include/wums/defines/relocation_defines.h @@ -2,16 +2,16 @@ #include -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 { diff --git a/include/wums/exports.h b/include/wums/exports.h index 3b4a726..fc802c0 100644 --- a/include/wums/exports.h +++ b/include/wums/exports.h @@ -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 } diff --git a/include/wums/hooks.h b/include/wums/hooks.h index 92d780c..0179b0e 100644 --- a/include/wums/hooks.h +++ b/include/wums/hooks.h @@ -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 } diff --git a/include/wums/meta.h b/include/wums/meta.h index 6982c5c..041a64f 100644 --- a/include/wums/meta.h +++ b/include/wums/meta.h @@ -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 diff --git a/libraries/libwums/crt.c b/libraries/libwums/crt.c index 19d4f1e..93dbf77 100644 --- a/libraries/libwums/crt.c +++ b/libraries/libwums/crt.c @@ -10,7 +10,7 @@ static int __wut_socket_devoptab_added = 0; extern void socket_lib_init(); void __attribute__((weak)) __init_wut_socket() { - if(!&__wut_socket_init_devoptab) return; + if (!&__wut_socket_init_devoptab) return; if (!__wut_socket_devoptab_added) { socket_lib_init(); __wut_socket_init_devoptab(); @@ -19,7 +19,7 @@ void __attribute__((weak)) __init_wut_socket() { } void __attribute__((weak)) __fini_wut_socket() { - if(!&__wut_socket_init_devoptab || !&__wut_socket_fini_devoptab) return; + if (!&__wut_socket_init_devoptab || !&__wut_socket_fini_devoptab) return; if (__wut_socket_devoptab_added) { __wut_socket_fini_devoptab(); __wut_socket_devoptab_added = 0;