Skip to content

Commit

Permalink
Update .clang-format to update the comment, macro and assignment form…
Browse files Browse the repository at this point in the history
…atting
  • Loading branch information
Maschell committed Feb 3, 2022
1 parent e5ead1a commit 9e96647
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 81 deletions.
5 changes: 3 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
Expand Down Expand Up @@ -56,7 +57,7 @@ SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
Expand Down
14 changes: 7 additions & 7 deletions src/ElfUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
return true;
}
auto target = destination + offset;
auto value = symbol_addr + addend;
auto value = symbol_addr + addend;


auto relValue = value - static_cast<uint32_t>(target);
Expand Down Expand Up @@ -122,10 +122,10 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
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 @@ -136,8 +136,8 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
}
auto symbolValue = (uint32_t) & (freeSlot->trampolin[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/common/dynamic_linking_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
extern "C" {
#endif

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

typedef struct _dyn_linking_function_t {
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];
Expand All @@ -46,8 +44,8 @@ typedef struct _dyn_linking_import_t {

typedef struct _dyn_linking_relocation_entry_t {
dyn_linking_function_t *functionEntry = nullptr;
dyn_linking_import_t *importEntry = nullptr;
void *destination = NULL;
dyn_linking_import_t *importEntry = nullptr;
void *destination = nullptr;
char type{};
size_t offset{};
int32_t addend{};
Expand Down
14 changes: 6 additions & 8 deletions src/common/relocation_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@

#include <cstdint>

// 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,
RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3,
} RelocationTrampolinStatus;

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

typedef struct relocation_trampolin_entry_t {
uint32_t trampolin[4];
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ EXPORT_VAR(uint32_t *, MEMFreeToDefaultHeap);

void InitFunctionPointers(void) {
OSDynLoad_Module handle;
addr_OSDynLoad_Acquire = (void *) 0x0102A3B4;
addr_OSDynLoad_Acquire = (void *) 0x0102A3B4;
addr_OSDynLoad_FindExport = (void *) 0x0102B828;

OSDynLoad_Acquire("coreinit.rpl", &handle);
Expand Down
10 changes: 5 additions & 5 deletions src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

#pragma once

#define KERN_SYSCALL_TBL_1 0xFFE84C70// unknown
#define KERN_SYSCALL_TBL_2 0xFFE85070// works with games
#define KERN_SYSCALL_TBL_3 0xFFE85470// works with loader
#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_1 0xFFE84C70 // unknown
#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu
#define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL)

#ifdef __cplusplus
extern "C" {
Expand Down
22 changes: 11 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ extern "C" int _start(int argc, char **argv) {

// Save last entry on mem2 heap to detect leaked memory
MEMHeapHandle mem2_heap_handle = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
auto heap = (MEMExpHeap *) mem2_heap_handle;
MEMExpHeapBlock *memory_start = heap->usedList.tail;
auto heap = (MEMExpHeap *) mem2_heap_handle;
MEMExpHeapBlock *memory_start = heap->usedList.tail;

initLogging();
DEBUG_FUNCTION_LINE("Hello from CustomRPXloader");
Expand All @@ -95,7 +95,7 @@ extern "C" int _start(int argc, char **argv) {
if (memory_end == memory_start) {
break;
}
auto mem_ptr = &memory_end[1];// &memory_end + sizeof(MEMExpHeapBlock);
auto mem_ptr = &memory_end[1]; // &memory_end + sizeof(MEMExpHeapBlock);
free(mem_ptr);
leak_count++;
}
Expand All @@ -119,7 +119,7 @@ uint32_t do_start(int argc, char **argv) {
bool doProcUI = (argc >= 1 && std::string(argv[0]) != "safe.rpx");

auto *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8;
*cfwLaunchedWithPtr = OSGetTitleID();
*cfwLaunchedWithPtr = OSGetTitleID();

uint32_t ApplicationMemoryEnd;

Expand All @@ -131,7 +131,7 @@ uint32_t do_start(int argc, char **argv) {
auto *gModuleData = (module_information_t *) ApplicationMemoryEnd;

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");
int result = 0;
Expand Down Expand Up @@ -164,7 +164,7 @@ uint32_t do_start(int argc, char **argv) {

if (doProcUI) {
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::Finalize();

Expand All @@ -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) {
for (auto const &curReloc : relocData) {
const RelocationData &cur = curReloc;
std::string functionName = cur.getName();
std::string rplName = cur.getImportRPLInformation().getName();
int32_t isData = cur.getImportRPLInformation().isData();
const RelocationData &cur = curReloc;
std::string functionName = cur.getName();
std::string rplName = cur.getImportRPLInformation().getName();
int32_t isData = cur.getImportRPLInformation().isData();
OSDynLoad_Module rplHandle = nullptr;
OSDynLoad_Acquire(rplName.c_str(), &rplHandle);

Expand All @@ -217,7 +217,7 @@ void SplashScreen(const char *message, int32_t durationInMs) {
OSScreenInit();
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
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_DRC, (void *) (screenBuffer + screen_buf0_size));

Expand Down
4 changes: 2 additions & 2 deletions src/module/ImportRPLInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ImportRPLInformation {

public:
explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = name;
this->name = name;
this->_isData = isData;
}

Expand All @@ -45,7 +45,7 @@ class ImportRPLInformation {
rplName = rawSectionName.substr(fimport.size());
} else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) {
rplName = rawSectionName.substr(dimport.size());
data = true;
data = true;
} else {
DEBUG_FUNCTION_LINE("invalid section name\n");
return {};
Expand Down
8 changes: 4 additions & 4 deletions src/module/ModuleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class ModuleData {
private:
std::vector<RelocationData> relocation_data_list;

uint32_t bssAddr = 0;
uint32_t bssSize = 0;
uint32_t sbssAddr = 0;
uint32_t sbssSize = 0;
uint32_t bssAddr = 0;
uint32_t bssSize = 0;
uint32_t sbssAddr = 0;
uint32_t sbssSize = 0;
uint32_t entrypoint = 0;
};
2 changes: 1 addition & 1 deletion src/module/ModuleDataFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
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;

Expand Down
8 changes: 4 additions & 4 deletions src/module/RelocationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class RelocationData {

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

~RelocationData() = default;
Expand Down
34 changes: 17 additions & 17 deletions src/utils/StringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
static char tmp[512];
static wchar_t strWChar[512];
strWChar[0] = 0;
tmp[0] = 0;
tmp[0] = 0;

if (!format) {
return (const wchar_t *) strWChar;
Expand All @@ -101,7 +101,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
if ((vsprintf(tmp, format, va) >= 0)) {
int bt;
int32_t strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);

if (bt > 0) {
strWChar[bt] = 0;
Expand All @@ -115,13 +115,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {

int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
static char tmp[512];
tmp[0] = 0;
tmp[0] = 0;
int32_t result = 0;

va_list va;
va_start(va, format);
if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp;
str = tmp;
result = str.size();
}
va_end(va);
Expand Down Expand Up @@ -223,7 +223,7 @@ const char *StringTools::FullpathToFilename(const char *path) {
return path;
}

const char *ptr = path;
const char *ptr = path;
const char *Filename = ptr;

while (*ptr != '\0') {
Expand Down Expand Up @@ -253,13 +253,13 @@ void StringTools::RemoveDoubleSlashs(std::string &str) {

// You must free the result if result is non-NULL.
char *StringTools::str_replace(char *orig, char *rep, char *with) {
char *result; // the return string
char *ins; // the next insert point
char *tmp; // varies
int len_rep; // length of rep (the string to remove)
int len_with; // length of with (the string to replace rep with)
int len_front;// distance between rep and end of last rep
int count; // number of replacements
char *result; // the return string
char *ins; // the next insert point
char *tmp; // varies
int len_rep; // length of rep (the string to remove)
int len_with; // length of with (the string to replace rep with)
int len_front; // distance between rep and end of last rep
int count; // number of replacements

// sanity checks and initialization
if (!orig || !rep) {
Expand All @@ -268,7 +268,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
len_rep = strlen(rep);
if (len_rep == 0) {
return NULL;
}// empty rep causes infinite loop during count
} // empty rep causes infinite loop during count
if (!with) {
with = (char *) "";
}
Expand All @@ -292,11 +292,11 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
// ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep"
while (count--) {
ins = strstr(orig, rep);
ins = strstr(orig, rep);
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep;// move to next "end of rep"
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep"
}
strcpy(tmp, orig);
return result;
Expand Down
12 changes: 6 additions & 6 deletions src/utils/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#include <whb/log_udp.h>

uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif// DEBUG
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif // DEBUG

void initLogging() {
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
udpLogInit = WHBLogUdpInit();
}
#endif// DEBUG
#endif // DEBUG
}

void deinitLogging() {
Expand All @@ -32,5 +32,5 @@ void deinitLogging() {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif// DEBUG
#endif // DEBUG
}
Loading

0 comments on commit 9e96647

Please sign in to comment.