Skip to content

Commit

Permalink
Format the code via clang-format (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell authored Feb 2, 2022
1 parent 4e29e33 commit e5ead1a
Show file tree
Hide file tree
Showing 35 changed files with 209 additions and 99 deletions.
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./src
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./src
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![CI-Release](https://github.com/wiiu-env/CustomRPXLoader/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/CustomRPXLoader/actions/workflows/ci.yml)
# CustomRPXLoader
This custom loader for `.rpx` files which can be used with any `payload.elf` loader. (For example [PayloadFromRPX](https://github.com/wiiu-env/PayloadFromRPX) or [JsTypeHax](https://github.com/wiiu-env/JsTypeHax))

Expand All @@ -23,6 +24,10 @@ docker run -it --rm -v ${PWD}:/project customrpxloader-builder make
docker run -it --rm -v ${PWD}:/project customrpxloader-builder make clean
```

## Format the code via docker

`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i`

## Credits
- Maschell
- orboditilt
Expand Down
22 changes: 11 additions & 11 deletions src/ElfUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#include <cstring>
#include "ElfUtils.h"
#include "utils/logger.h"
#include <coreinit/cache.h>
#include <cstring>
#include <whb/log.h>
#include "utils/logger.h"
#include "ElfUtils.h"

// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
Expand Down Expand Up @@ -113,19 +113,19 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
}
if (freeSlot == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) &(freeSlot->trampolin[0]));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) & (freeSlot->trampolin[0]));
return false;
}
if (target - (uint32_t) &(freeSlot->trampolin[0]) > 0x1FFFFFC) {
if (target - (uint32_t) & (freeSlot->trampolin[0]) > 0x1FFFFFC) {
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) &(freeSlot->trampolin[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) & (freeSlot->trampolin[0])));
return false;
}

freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampolin[3] = 0x4E800420; // bctr
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF);// lis r11, real_addr@h
freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampolin[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin));

Expand All @@ -135,7 +135,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
// Relocations for the imports may be overridden
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
}
auto symbolValue = (uint32_t) &(freeSlot->trampolin[0]);
auto symbolValue = (uint32_t) & (freeSlot->trampolin[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
}
Expand Down
5 changes: 4 additions & 1 deletion src/ElfUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

#pragma once

#include <cstdint>
#include "common/relocation_defines.h"
#include <cstddef>
#include <cstdint>

#ifdef __cplusplus
extern "C" {
#endif

// clang-format off
#define R_PPC_NONE 0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR16_LO 4
Expand Down Expand Up @@ -51,6 +53,7 @@ extern "C" {
#define PPC_LOW24 0x03FFFFFC
#define PPC_LOW14 0x0020FFFC
#define PPC_HALF16 0xFFFF
// clang-format on

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion src/common/dynamic_linking_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@

#pragma once

#include <cstdint>
#include <cstddef>
#include <cstdint>

#ifdef __cplusplus
extern "C" {
#endif

// clang-format off
#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_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
// clang-format on

typedef struct _dyn_linking_function_t {
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];
Expand Down
4 changes: 2 additions & 2 deletions src/common/module_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

#pragma once

#include <cstdint>
#include <cstddef>
#include "dynamic_linking_defines.h"
#include "relocation_defines.h"
#include <cstddef>
#include <cstdint>

#ifdef __cplusplus
extern "C" {
Expand Down
6 changes: 4 additions & 2 deletions src/common/relocation_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@

#include <cstdint>

typedef enum RelocationTrampolinStatus{
// clang-format off
typedef enum RelocationTrampolinStatus {
RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3,
} RelocationTrampolinStatus;

typedef enum RelocationType{
typedef enum RelocationType {
RELOC_TYPE_FIXED = 0,
RELOC_TYPE_IMPORT = 1
} RelocationType;
// clang-format on

typedef struct relocation_trampolin_entry_t {
uint32_t trampolin[4];
Expand Down
13 changes: 8 additions & 5 deletions src/dynamic.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <coreinit/dynload.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>

#define IMPORT(name) void* addr_##name
#define IMPORT(name) void *addr_##name
#define IMPORT_BEGIN(lib)
#define IMPORT_END()

Expand All @@ -11,12 +11,15 @@
#undef IMPORT_BEGIN
#undef IMPORT_END

#define IMPORT(name) do{if(OSDynLoad_FindExport(handle, 0, #name, &addr_##name) < 0)OSFatal("Function " # name " is NULL");} while(0)
#define IMPORT_BEGIN(lib) OSDynLoad_Acquire(#lib ".rpl", &handle)
#define IMPORT(name) \
do { \
if (OSDynLoad_FindExport(handle, 0, #name, &addr_##name) < 0) OSFatal("Function " #name " is NULL"); \
} while (0)
#define IMPORT_BEGIN(lib) OSDynLoad_Acquire(#lib ".rpl", &handle)
/* #define IMPORT_END() OSDynLoad_Release(handle) */
#define IMPORT_END()

#define EXPORT_VAR(type, var) type var __attribute__((section(".data")));
#define EXPORT_VAR(type, var) type var __attribute__((section(".data")));

EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeap);
EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeapEx);
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elf_types.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_dump.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_dynamic.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_header.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_note.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_relocation.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_section.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_segment.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_strings.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_symbols.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
1 change: 1 addition & 0 deletions src/elfio/elfio_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center
Expand Down
Loading

0 comments on commit e5ead1a

Please sign in to comment.