Format the code via clang-format

This commit is contained in:
Maschell 2022-02-04 16:42:24 +01:00
parent f49c84ac5f
commit 4690dfcb39
7 changed files with 128 additions and 38 deletions

67
.clang-format Normal file
View File

@ -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

View File

@ -6,8 +6,16 @@ on:
- master - master
jobs: jobs:
clang-format:
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 ./source
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary
@ -26,7 +34,7 @@ jobs:
id: get_repository_name id: get_repository_name
run: | run: |
echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV
echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV
- uses: actions/download-artifact@master - uses: actions/download-artifact@master
with: with:
name: binary name: binary

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request] on: [pull_request]
jobs: jobs:
clang-format:
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 ./source
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary

View File

@ -1,3 +1,5 @@
[![CI-Release](https://github.com/wiiu-env/PatchMemoryRelocationsModule/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/PatchMemoryRelocationsModule/actions/workflows/ci.yml)
# PatchMemoryRelocationsModule # PatchMemoryRelocationsModule
Replaces the usage of `MEMAllocFromDefaultHeap`, `MEMAllocFromDefaultHeapEx` and `MEMFreeToDefaultHeap` with similar function from the MemoryMappingModule in the currently running modules. Replaces the usage of `MEMAllocFromDefaultHeap`, `MEMAllocFromDefaultHeapEx` and `MEMFreeToDefaultHeap` with similar function from the MemoryMappingModule in the currently running modules.
@ -22,6 +24,10 @@ docker run -it --rm -v ${PWD}:/project patchmemoryrelocationsmodule-builder make
docker run -it --rm -v ${PWD}:/project patchmemoryrelocationsmodule-builder make clean docker run -it --rm -v ${PWD}:/project patchmemoryrelocationsmodule-builder make clean
``` ```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`
# Dependencies: # Dependencies:
- [wut](https://github.com/decaf-emu/wut) - [wut](https://github.com/decaf-emu/wut)
- [WUMS](https://github.com/wiiu-env/WiiUModuleSystem) - [WUMS](https://github.com/wiiu-env/WiiUModuleSystem)

View File

@ -1,19 +1,19 @@
#ifdef DEBUG #ifdef DEBUG
#include <stdint.h> #include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h> #include <whb/log_cafe.h>
#include <whb/log_module.h> #include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false; uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false; uint32_t cafeLogInit = false;
uint32_t udpLogInit = false; uint32_t udpLogInit = false;
#endif // DEBUG #endif // DEBUG
void initLogging() { void initLogging() {
#ifdef DEBUG #ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) { if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit(); cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit(); udpLogInit = WHBLogUdpInit();
} }
#endif // DEBUG #endif // DEBUG
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <whb/log.h>
#include <string.h> #include <string.h>
#include <whb/log.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -9,26 +9,28 @@ extern "C" {
#ifdef DEBUG #ifdef DEBUG
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
#else #else
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
#endif #endif
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,10 +1,10 @@
#include <wums.h> #include <wums.h>
#include "logger.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <cstring> #include <cstring>
#include <coreinit/cache.h>
#include <memory/mappedmemory.h> #include <memory/mappedmemory.h>
#include "logger.h"
WUMS_MODULE_EXPORT_NAME("homebrew_patchmemoryrelocations"); WUMS_MODULE_EXPORT_NAME("homebrew_patchmemoryrelocations");
WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK(); WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
@ -31,7 +31,7 @@ WUMS_RELOCATIONS_DONE(args) {
continue; continue;
} }
DEBUG_FUNCTION_LINE_VERBOSE("Patch relocations of %s", gModuleData->module_data[i].module_export_name); DEBUG_FUNCTION_LINE_VERBOSE("Patch relocations of %s", gModuleData->module_data[i].module_export_name);
for (auto &curEntry: gModuleData->module_data[i].linking_entries) { for (auto &curEntry : gModuleData->module_data[i].linking_entries) {
if (curEntry.functionEntry == nullptr) { if (curEntry.functionEntry == nullptr) {
continue; continue;
} }
@ -57,18 +57,18 @@ WUMS_RELOCATIONS_DONE(args) {
deinitLogging(); deinitLogging();
} }
#define R_PPC_NONE 0 #define R_PPC_NONE 0
#define R_PPC_ADDR32 1 #define R_PPC_ADDR32 1
#define R_PPC_ADDR16_LO 4 #define R_PPC_ADDR16_LO 4
#define R_PPC_ADDR16_HI 5 #define R_PPC_ADDR16_HI 5
#define R_PPC_ADDR16_HA 6 #define R_PPC_ADDR16_HA 6
#define R_PPC_REL24 10 #define R_PPC_REL24 10
#define R_PPC_REL14 11 #define R_PPC_REL14 11
#define R_PPC_DTPMOD32 68 #define R_PPC_DTPMOD32 68
#define R_PPC_DTPREL32 78 #define R_PPC_DTPREL32 78
#define R_PPC_GHS_REL16_HA 251 #define R_PPC_GHS_REL16_HA 251
#define R_PPC_GHS_REL16_HI 252 #define R_PPC_GHS_REL16_HI 252
#define R_PPC_GHS_REL16_LO 253 #define R_PPC_GHS_REL16_LO 253
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144 // See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length, bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
@ -77,7 +77,7 @@ bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination,
return true; return true;
} }
auto target = destination + offset; auto target = destination + offset;
auto value = symbol_addr + addend; auto value = symbol_addr + addend;
auto relValue = value - static_cast<uint32_t>(target); auto relValue = value - static_cast<uint32_t>(target);
@ -164,16 +164,16 @@ bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination,
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance); DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
return false; return false;
} }
if (target - (uint32_t) &(freeSlot->trampoline[0]) > 0x1FFFFFC) { if (target - (uint32_t) & (freeSlot->trampoline[0]) > 0x1FFFFFC) {
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer)."); DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance); DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
return false; return false;
} }
freeSlot->trampoline[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h freeSlot->trampoline[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11 freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampoline[3] = 0x4E800420; // bctr freeSlot->trampoline[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampoline, sizeof(freeSlot->trampoline)); DCFlushRange((void *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
ICInvalidateRange((unsigned char *) freeSlot->trampoline, sizeof(freeSlot->trampoline)); ICInvalidateRange((unsigned char *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
@ -183,9 +183,9 @@ bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination,
// Relocations for the imports may be overridden // Relocations for the imports may be overridden
freeSlot->status = RELOC_TRAMP_IMPORT_IN_PROGRESS; freeSlot->status = RELOC_TRAMP_IMPORT_IN_PROGRESS;
} }
uint32_t symbolValue = (uint32_t) &(freeSlot->trampoline[0]); uint32_t symbolValue = (uint32_t) & (freeSlot->trampoline[0]);
value = symbolValue + addend; value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target); distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
DEBUG_FUNCTION_LINE("Created tramp\n"); DEBUG_FUNCTION_LINE("Created tramp\n");
} }
} }