Use clang-format to format the code

This commit is contained in:
Maschell 2022-02-02 18:34:27 +01:00
parent 07259a4f01
commit 6db316c682
12 changed files with 148 additions and 44 deletions

66
.clang-format Normal file
View File

@ -0,0 +1,66 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
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: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -6,8 +6,16 @@ on:
- master
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:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary

View File

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

View File

@ -18,3 +18,6 @@ docker run -it --rm -v ${PWD}:/project memorymappingmodule-builder make
# make clean
docker run -it --rm -v ${PWD}:/project memorymappingmodule-builder make clean
```
## Format the code via docker
`docker run --rm -it -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`

View File

@ -16,10 +16,10 @@
****************************************************************************/
#pragma once
#include <coreinit/thread.h>
#include <cstdint>
#include <malloc.h>
#include <unistd.h>
#include <cstdint>
#include <coreinit/thread.h>
class CThread {
public:
@ -36,7 +36,9 @@ public:
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
//! create the thread
if (pThread && pThreadStack) {
// clang-format off
OSCreateThread(pThread, (int(*)(int, const char **)) & CThread::threadCallback, 1, (char *) this, (void *) (pThreadStack + iStackSize), iStackSize, iPriority, iAttributes);
// clang-format on
}
}
@ -129,6 +131,7 @@ public:
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
};
private:
static int32_t threadCallback(int32_t argc, void *arg) {
//! After call to start() continue with the internal function

View File

@ -31,7 +31,6 @@ DECL_FUNCTION(uint32_t, KiPhysicalToEffectiveUncached, uint32_t addressSpace, ui
uint32_t result = real_KiPhysicalToEffectiveUncached(addressSpace, virtualAddress);
if (result == 0) {
return MemoryMapping_PhysicalToEffective(virtualAddress);
}
return result;
}
@ -54,7 +53,9 @@ DECL_FUNCTION(uint32_t, KiIsEffectiveRangeValid, uint32_t addressSpace, uint32_t
}
// clang-format off
#define k_memcpy ((void(*)(void *, void *, uint32_t))(0xfff09e44))
// clang-format on
DECL_FUNCTION(uint32_t, KiGetOrPutUserData, void *src, uint32_t size, void *dst, bool isRead) {
//
@ -70,6 +71,7 @@ DECL_FUNCTION(uint32_t, KiGetOrPutUserData, void *src, uint32_t size, void *dst,
return real_KiGetOrPutUserData(src, size, dst, isRead);
}
// clang-format off
function_replacement_data_t function_replacements[] __attribute__((section(".data"))) = {
REPLACE_FUNCTION_VIA_ADDRESS(sCheckDataRange, 0x3200cf60, 0x0100cf60),
REPLACE_FUNCTION_VIA_ADDRESS(KiEffectiveToPhysical, 0xffee0aac, 0xffee0aac),
@ -79,5 +81,6 @@ function_replacement_data_t function_replacements[] __attribute__((section(".dat
REPLACE_FUNCTION_VIA_ADDRESS(IPCKDriver_ValidatePhysicalAddress, 0xfff0cb5c, 0xfff0cb5c),
REPLACE_FUNCTION_VIA_ADDRESS(KiGetOrPutUserData, 0xffee0794, 0xffee0794),
};
// clang-format on
uint32_t function_replacements_size __attribute__((section(".data"))) = sizeof(function_replacements) / sizeof(function_replacement_data_t);

View File

@ -1,7 +1,7 @@
#pragma once
#include <function_patcher/function_patching.h>
#include <cstdint>
#include <function_patcher/function_patching.h>
extern function_replacement_data_t function_replacements[] __attribute__((section(".data")));

View File

@ -1,8 +1,8 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;

View File

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

View File

@ -1,8 +1,8 @@
#include <wums.h>
#include "memory_mapping.h"
#include <function_patcher/function_patching.h>
#include "function_replacements.h"
#include "logger.h"
#include "memory_mapping.h"
#include <function_patcher/function_patching.h>
#include <wums.h>
WUMS_MODULE_EXPORT_NAME("homebrew_memorymapping");
WUMS_MODULE_SKIP_INIT_FINI();

View File

@ -1,15 +1,15 @@
#include "memory_mapping.h"
#include <coreinit/memorymap.h>
#include <coreinit/memdefaultheap.h>
#include <coreinit/cache.h>
#include <coreinit/memdefaultheap.h>
#include <coreinit/memexpheap.h>
#include <coreinit/memorymap.h>
#include <coreinit/thread.h>
#include <vector>
#include "memory.h"
#include "logger.h"
#include "CThread.h"
#include "logger.h"
#include "memory.h"
#include <cstring>
#include <vector>
// #define DEBUG_FUNCTION_LINE(x,...)
@ -159,7 +159,6 @@ void MemoryMapping_searchEmptyMemoryRegions() {
if (success) {
DEBUG_FUNCTION_LINE("Test %d was successful!", i + 1);
}
}
DEBUG_FUNCTION_LINE("All tests done.");
}
@ -274,7 +273,6 @@ void MemoryMapping_readTestValuesFromMemory() {
if (success) {
DEBUG_FUNCTION_LINE("Test %d was successful!", i + 1);
}
}
DEBUG_FUNCTION_LINE("All tests done.");
}
@ -645,8 +643,7 @@ void MemoryMapping_printPageTableTranslation(sr_table_t srTable, uint32_t *trans
current.kp == kp &&
current.nx == nx &&
current.pp == pp &&
current.phys == phys - current.size
) {
current.phys == phys - current.size) {
current.size += pageSize;
//DEBUG_FUNCTION_LINE("New size of %08X is %08X",current.addr,current.size);
} else {
@ -879,5 +876,3 @@ uint32_t MemoryMapping_EffectiveToPhysical(uint32_t effectiveAddress) {
}
return result;
}

View File

@ -6,9 +6,9 @@
extern "C" {
#endif
#include <stdint.h>
#include <kernel/kernel.h>
#include <kernel/kernel_defs.h>
#include <stdint.h>
typedef struct pageInformation_ {
uint32_t addr;
@ -31,47 +31,58 @@ typedef struct _memory_mapping_t {
const memory_values_t *physical_addresses;
} memory_mapping_t;
// clang-format off
#define SEGMENT_UNIQUE_ID 0x00AABBCC // Unique ID. Chosen arbitrary.
#define PAGE_INDEX_SHIFT (32-15)
#define PAGE_INDEX_MASK ((1 << (28 - PAGE_INDEX_SHIFT)) - 1)
#define MEMORY_START_BASE 0x80000000
#define MEMORY_START_VIDEO_BASE (MEMORY_START_BASE + 0x08000000)
// clang-format on
// clang-format off
const memory_values_t mem_vals_heap_1[] = {
{0x28000000 + 0x06620000, 0x28000000 + 0x07F80000}, // size: 25984 kB
{0, 0}
};
// clang-format on
#define MEMORY_HEAP0_SIZE 0x1960000
#define MEMORY_HEAP0 MEMORY_START_BASE
// clang-format off
const memory_values_t mem_vals_heap_2[] = {
{0x28000000 + 0x09000000, 0x28000000 + 0x09E20000}, // size: 14464 kB
{0, 0}
};
// clang-format on
#define MEMORY_HEAP1_SIZE 0xE20000
#define MEMORY_HEAP1 (MEMORY_HEAP0 + MEMORY_HEAP0_SIZE)
// clang-format off
const memory_values_t mem_vals_heap_3[] = {
{0x28000000 + 0x058E0000, 0x28000000 + 0x06000000}, // size: 7296 kB
{0, 0}
};
// clang-format on
#define MEMORY_HEAP2_SIZE 0x720000
#define MEMORY_HEAP2 (MEMORY_HEAP1 + MEMORY_HEAP1_SIZE)
// clang-format off
const memory_values_t mem_vals_heap_4[] = {
{0x28000000 + 0x053C0000, 0x28000000 + 0x05880000}, // size: 4864 kB
{0, 0}
};
// clang-format on
#define MEMORY_HEAP3_SIZE 0x4C0000
#define MEMORY_HEAP3 (MEMORY_HEAP2 + MEMORY_HEAP2_SIZE)
#define MEMORY_HEAP4 (MEMORY_HEAP3 + MEMORY_HEAP3_SIZE)
// clang-format off
const memory_values_t mem_vals_video[] = {
// The GPU doesn't have access to the 0x28000000 - 0x32000000 area, so we need memory from somewhere else.
// From the SharedReadHeap of the loader.
@ -105,10 +116,14 @@ const memory_values_t mem_vals_video[] = {
//{0x18000000 , 0x18000000 +0x3000000}, // size: 3840 kB
{0, 0}
};
// clang-format on
// clang-format off
#define MEMORY_START_VIDEO MEMORY_START_VIDEO_BASE
#define MEMORY_END_VIDEO (MEMORY_START_VIDEO + 0xE60000)
// clang-format on
// clang-format off
const memory_mapping_t mem_mapping[] = {
{MEMORY_HEAP0, MEMORY_HEAP1, mem_vals_heap_1},
{MEMORY_HEAP1, MEMORY_HEAP2, mem_vals_heap_2},
@ -117,8 +132,9 @@ const memory_mapping_t mem_mapping[] = {
{MEMORY_START_VIDEO, MEMORY_END_VIDEO, mem_vals_video},
{0, 0, nullptr}
};
// clang-format on
// clang-format off
// Values needs to be aligned to 0x20000 and size needs to be a multiple of 0x20000
const memory_values_t mem_vals_heap[] = {
// 5.5.2 EUR
@ -162,6 +178,7 @@ const memory_values_t mem_vals_heap[] = {
{0, 0}
};
// clang-format on
uint32_t MemoryMapping_MEMGetAllocatableSize();