Update .clang-format to update the comment, macro and assignment formatting

This commit is contained in:
Maschell 2022-02-03 13:49:11 +01:00
parent e5ead1af44
commit 9e96647469
14 changed files with 78 additions and 81 deletions

View File

@ -2,7 +2,8 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
AccessModifierOffset: -4 AccessModifierOffset: -4
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align AlignOperands: Align
AllowAllArgumentsOnNextLine: false AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false AllowAllConstructorInitializersOnNextLine: false
@ -56,7 +57,7 @@ SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0 SpacesBeforeTrailingComments: 1
SpacesInAngles: false SpacesInAngles: false
SpacesInCStyleCastParentheses: false SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false SpacesInContainerLiterals: false

View File

@ -28,7 +28,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
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);
@ -122,10 +122,10 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
return false; return false;
} }
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF);// lis r11, real_addr@h 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[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11 freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampolin[3] = 0x4E800420; // bctr freeSlot->trampolin[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin)); DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin)); ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
@ -136,8 +136,8 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
freeSlot->status = RELOC_TRAMP_IMPORT_DONE; freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
} }
auto symbolValue = (uint32_t) & (freeSlot->trampolin[0]); auto symbolValue = (uint32_t) & (freeSlot->trampolin[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);
} }
} }

View File

@ -24,15 +24,13 @@
extern "C" { extern "C" {
#endif #endif
// clang-format off #define DYN_LINK_FUNCTION_NAME_LENGTH 351
#define DYN_LINK_FUNCTION_NAME_LENGTH 351 #define DYN_LINK_IMPORT_NAME_LENGTH 50
#define DYN_LINK_IMPORT_NAME_LENGTH 50
#define DYN_LINK_FUNCTION_LIST_LENGTH 500 #define DYN_LINK_FUNCTION_LIST_LENGTH 500
#define DYN_LINK_IMPORT_LIST_LENGTH 50 #define DYN_LINK_IMPORT_LIST_LENGTH 50
#define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH #define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
// clang-format on
typedef struct _dyn_linking_function_t { typedef struct _dyn_linking_function_t {
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1]; char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];
@ -46,8 +44,8 @@ typedef struct _dyn_linking_import_t {
typedef struct _dyn_linking_relocation_entry_t { typedef struct _dyn_linking_relocation_entry_t {
dyn_linking_function_t *functionEntry = nullptr; dyn_linking_function_t *functionEntry = nullptr;
dyn_linking_import_t *importEntry = nullptr; dyn_linking_import_t *importEntry = nullptr;
void *destination = NULL; void *destination = nullptr;
char type{}; char type{};
size_t offset{}; size_t offset{};
int32_t addend{}; int32_t addend{};

View File

@ -19,19 +19,17 @@
#include <cstdint> #include <cstdint>
// clang-format off
typedef enum RelocationTrampolinStatus { typedef enum RelocationTrampolinStatus {
RELOC_TRAMP_FREE = 0, RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1, RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2, RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3, RELOC_TRAMP_IMPORT_DONE = 3,
} RelocationTrampolinStatus; } RelocationTrampolinStatus;
typedef enum RelocationType { typedef enum RelocationType {
RELOC_TYPE_FIXED = 0, RELOC_TYPE_FIXED = 0,
RELOC_TYPE_IMPORT = 1 RELOC_TYPE_IMPORT = 1
} RelocationType; } RelocationType;
// clang-format on
typedef struct relocation_trampolin_entry_t { typedef struct relocation_trampolin_entry_t {
uint32_t trampolin[4]; uint32_t trampolin[4];

View File

@ -27,7 +27,7 @@ EXPORT_VAR(uint32_t *, MEMFreeToDefaultHeap);
void InitFunctionPointers(void) { void InitFunctionPointers(void) {
OSDynLoad_Module handle; OSDynLoad_Module handle;
addr_OSDynLoad_Acquire = (void *) 0x0102A3B4; addr_OSDynLoad_Acquire = (void *) 0x0102A3B4;
addr_OSDynLoad_FindExport = (void *) 0x0102B828; addr_OSDynLoad_FindExport = (void *) 0x0102B828;
OSDynLoad_Acquire("coreinit.rpl", &handle); OSDynLoad_Acquire("coreinit.rpl", &handle);

View File

@ -17,11 +17,11 @@
#pragma once #pragma once
#define KERN_SYSCALL_TBL_1 0xFFE84C70// unknown #define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
#define KERN_SYSCALL_TBL_2 0xFFE85070// works with games #define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games
#define KERN_SYSCALL_TBL_3 0xFFE85470// works with loader #define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
#define KERN_SYSCALL_TBL_4 0xFFEAAA60// works with home menu #define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu
#define KERN_SYSCALL_TBL_5 0xFFEAAE60// works with browser (previously KERN_SYSCALL_TBL) #define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -77,8 +77,8 @@ extern "C" int _start(int argc, char **argv) {
// Save last entry on mem2 heap to detect leaked memory // Save last entry on mem2 heap to detect leaked memory
MEMHeapHandle mem2_heap_handle = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2); MEMHeapHandle mem2_heap_handle = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
auto heap = (MEMExpHeap *) mem2_heap_handle; auto heap = (MEMExpHeap *) mem2_heap_handle;
MEMExpHeapBlock *memory_start = heap->usedList.tail; MEMExpHeapBlock *memory_start = heap->usedList.tail;
initLogging(); initLogging();
DEBUG_FUNCTION_LINE("Hello from CustomRPXloader"); DEBUG_FUNCTION_LINE("Hello from CustomRPXloader");
@ -95,7 +95,7 @@ extern "C" int _start(int argc, char **argv) {
if (memory_end == memory_start) { if (memory_end == memory_start) {
break; break;
} }
auto mem_ptr = &memory_end[1];// &memory_end + sizeof(MEMExpHeapBlock); auto mem_ptr = &memory_end[1]; // &memory_end + sizeof(MEMExpHeapBlock);
free(mem_ptr); free(mem_ptr);
leak_count++; leak_count++;
} }
@ -119,7 +119,7 @@ uint32_t do_start(int argc, char **argv) {
bool doProcUI = (argc >= 1 && std::string(argv[0]) != "safe.rpx"); bool doProcUI = (argc >= 1 && std::string(argv[0]) != "safe.rpx");
auto *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8; auto *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8;
*cfwLaunchedWithPtr = OSGetTitleID(); *cfwLaunchedWithPtr = OSGetTitleID();
uint32_t ApplicationMemoryEnd; uint32_t ApplicationMemoryEnd;
@ -131,7 +131,7 @@ uint32_t do_start(int argc, char **argv) {
auto *gModuleData = (module_information_t *) ApplicationMemoryEnd; auto *gModuleData = (module_information_t *) ApplicationMemoryEnd;
uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t)); uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t));
moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000; moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000;
std::string filepath("fs:/vol/external01/wiiu/payload.rpx"); std::string filepath("fs:/vol/external01/wiiu/payload.rpx");
int result = 0; int result = 0;
@ -164,7 +164,7 @@ uint32_t do_start(int argc, char **argv) {
if (doProcUI) { if (doProcUI) {
nn::act::Initialize(); nn::act::Initialize();
nn::act::SlotNo slot = nn::act::GetSlotNo(); nn::act::SlotNo slot = nn::act::GetSlotNo();
nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount(); nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount();
nn::act::Finalize(); nn::act::Finalize();
@ -189,10 +189,10 @@ uint32_t do_start(int argc, char **argv) {
bool doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) { bool doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) {
for (auto const &curReloc : relocData) { for (auto const &curReloc : relocData) {
const RelocationData &cur = curReloc; const RelocationData &cur = curReloc;
std::string functionName = cur.getName(); std::string functionName = cur.getName();
std::string rplName = cur.getImportRPLInformation().getName(); std::string rplName = cur.getImportRPLInformation().getName();
int32_t isData = cur.getImportRPLInformation().isData(); int32_t isData = cur.getImportRPLInformation().isData();
OSDynLoad_Module rplHandle = nullptr; OSDynLoad_Module rplHandle = nullptr;
OSDynLoad_Acquire(rplName.c_str(), &rplHandle); OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
@ -217,7 +217,7 @@ void SplashScreen(const char *message, int32_t durationInMs) {
OSScreenInit(); OSScreenInit();
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV); uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC); uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
auto *screenBuffer = (uint8_t *) memalign(0x100, screen_buf0_size + screen_buf1_size); auto *screenBuffer = (uint8_t *) memalign(0x100, screen_buf0_size + screen_buf1_size);
OSScreenSetBufferEx(SCREEN_TV, (void *) screenBuffer); OSScreenSetBufferEx(SCREEN_TV, (void *) screenBuffer);
OSScreenSetBufferEx(SCREEN_DRC, (void *) (screenBuffer + screen_buf0_size)); OSScreenSetBufferEx(SCREEN_DRC, (void *) (screenBuffer + screen_buf0_size));

View File

@ -25,7 +25,7 @@ class ImportRPLInformation {
public: public:
explicit ImportRPLInformation(std::string name, bool isData = false) { explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = name; this->name = name;
this->_isData = isData; this->_isData = isData;
} }
@ -45,7 +45,7 @@ public:
rplName = rawSectionName.substr(fimport.size()); rplName = rawSectionName.substr(fimport.size());
} else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) { } else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) {
rplName = rawSectionName.substr(dimport.size()); rplName = rawSectionName.substr(dimport.size());
data = true; data = true;
} else { } else {
DEBUG_FUNCTION_LINE("invalid section name\n"); DEBUG_FUNCTION_LINE("invalid section name\n");
return {}; return {};

View File

@ -74,9 +74,9 @@ public:
private: private:
std::vector<RelocationData> relocation_data_list; std::vector<RelocationData> relocation_data_list;
uint32_t bssAddr = 0; uint32_t bssAddr = 0;
uint32_t bssSize = 0; uint32_t bssSize = 0;
uint32_t sbssAddr = 0; uint32_t sbssAddr = 0;
uint32_t sbssSize = 0; uint32_t sbssSize = 0;
uint32_t entrypoint = 0; uint32_t entrypoint = 0;
}; };

View File

@ -74,7 +74,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t destination_address, u
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) { if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size(); uint32_t sectionSize = psec->get_size();
auto address = (uint32_t) psec->get_address(); auto address = (uint32_t) psec->get_address();
destinations[psec->get_index()] = (uint8_t *) baseOffset; destinations[psec->get_index()] = (uint8_t *) baseOffset;

View File

@ -24,11 +24,11 @@ class RelocationData {
public: public:
RelocationData(char type, size_t offset, int32_t addend, void *destination, const std::string &name, const ImportRPLInformation &rplInfo) : rplInfo(rplInfo) { RelocationData(char type, size_t offset, int32_t addend, void *destination, const std::string &name, const ImportRPLInformation &rplInfo) : rplInfo(rplInfo) {
this->type = type; this->type = type;
this->offset = offset; this->offset = offset;
this->addend = addend; this->addend = addend;
this->destination = destination; this->destination = destination;
this->name = name; this->name = name;
} }
~RelocationData() = default; ~RelocationData() = default;

View File

@ -86,7 +86,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
static char tmp[512]; static char tmp[512];
static wchar_t strWChar[512]; static wchar_t strWChar[512];
strWChar[0] = 0; strWChar[0] = 0;
tmp[0] = 0; tmp[0] = 0;
if (!format) { if (!format) {
return (const wchar_t *) strWChar; return (const wchar_t *) strWChar;
@ -101,7 +101,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
if ((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
int bt; int bt;
int32_t strlength = strlen(tmp); int32_t strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
if (bt > 0) { if (bt > 0) {
strWChar[bt] = 0; strWChar[bt] = 0;
@ -115,13 +115,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
int32_t StringTools::strprintf(std::string &str, const char *format, ...) { int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
static char tmp[512]; static char tmp[512];
tmp[0] = 0; tmp[0] = 0;
int32_t result = 0; int32_t result = 0;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if ((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp; str = tmp;
result = str.size(); result = str.size();
} }
va_end(va); va_end(va);
@ -223,7 +223,7 @@ const char *StringTools::FullpathToFilename(const char *path) {
return path; return path;
} }
const char *ptr = path; const char *ptr = path;
const char *Filename = ptr; const char *Filename = ptr;
while (*ptr != '\0') { while (*ptr != '\0') {
@ -253,13 +253,13 @@ void StringTools::RemoveDoubleSlashs(std::string &str) {
// You must free the result if result is non-NULL. // You must free the result if result is non-NULL.
char *StringTools::str_replace(char *orig, char *rep, char *with) { char *StringTools::str_replace(char *orig, char *rep, char *with) {
char *result; // the return string char *result; // the return string
char *ins; // the next insert point char *ins; // the next insert point
char *tmp; // varies char *tmp; // varies
int len_rep; // length of rep (the string to remove) int len_rep; // length of rep (the string to remove)
int len_with; // length of with (the string to replace rep with) int len_with; // length of with (the string to replace rep with)
int len_front;// distance between rep and end of last rep int len_front; // distance between rep and end of last rep
int count; // number of replacements int count; // number of replacements
// sanity checks and initialization // sanity checks and initialization
if (!orig || !rep) { if (!orig || !rep) {
@ -268,7 +268,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
len_rep = strlen(rep); len_rep = strlen(rep);
if (len_rep == 0) { if (len_rep == 0) {
return NULL; return NULL;
}// empty rep causes infinite loop during count } // empty rep causes infinite loop during count
if (!with) { if (!with) {
with = (char *) ""; with = (char *) "";
} }
@ -292,11 +292,11 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
// ins points to the next occurrence of rep in orig // ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep" // orig points to the remainder of orig after "end of rep"
while (count--) { while (count--) {
ins = strstr(orig, rep); ins = strstr(orig, rep);
len_front = ins - orig; len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front; tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with; tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep;// move to next "end of rep" orig += len_front + len_rep; // move to next "end of rep"
} }
strcpy(tmp, orig); strcpy(tmp, orig);
return result; return result;

View File

@ -5,17 +5,17 @@
#include <whb/log_udp.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
} }
void deinitLogging() { void deinitLogging() {
@ -32,5 +32,5 @@ void deinitLogging() {
WHBLogUdpDeinit(); WHBLogUdpDeinit();
udpLogInit = false; udpLogInit = false;
} }
#endif// DEBUG #endif // DEBUG
} }

View File

@ -9,8 +9,8 @@ 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)
@ -28,9 +28,9 @@ extern "C" {
#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