Code cleanup

This commit is contained in:
Maschell 2021-09-18 12:10:58 +02:00
parent c225cc7f25
commit ba389535a9
9 changed files with 48 additions and 52 deletions

View File

@ -17,7 +17,7 @@
#pragma once
#include <stdint.h>
#include <cstdint>
#include "common/relocation_defines.h"
#ifdef __cplusplus

View File

@ -17,8 +17,8 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <cstdint>
#include <cstddef>
#ifdef __cplusplus
extern "C" {
@ -38,21 +38,21 @@ typedef struct _dyn_linking_function_t {
} dyn_linking_function_t;
typedef struct _dyn_linking_import_t {
char importName[DYN_LINK_IMPORT_NAME_LENGTH + 1];
char importName[DYN_LINK_IMPORT_NAME_LENGTH + 1]{};
bool isData = false;
} dyn_linking_import_t;
typedef struct _dyn_linking_relocation_entry_t {
dyn_linking_function_t *functionEntry = NULL;
dyn_linking_import_t *importEntry = NULL;
dyn_linking_function_t *functionEntry = nullptr;
dyn_linking_import_t *importEntry = nullptr;
void *destination = NULL;
char type;
size_t offset;
int32_t addend;
char type{};
size_t offset{};
int32_t addend{};
} dyn_linking_relocation_entry_t;
typedef struct _dyn_linking_relocation_data_t {
dyn_linking_function_t functions[DYN_LINK_FUNCTION_LIST_LENGTH];
dyn_linking_function_t functions[DYN_LINK_FUNCTION_LIST_LENGTH]{};
dyn_linking_import_t imports[DYN_LINK_IMPORT_LIST_LENGTH];
} dyn_linking_relocation_data_t;

View File

@ -17,8 +17,8 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <cstdint>
#include <cstddef>
#include "dynamic_linking_defines.h"
#include "relocation_defines.h"

View File

@ -15,9 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <coreinit/cache.h>
#include <coreinit/memorymap.h>

View File

@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <stdint.h>
#include <cstdint>
#include <coreinit/cache.h>
#include <coreinit/dynload.h>
#include <coreinit/title.h>
@ -111,7 +111,7 @@ int do_start(int argc, char **argv) {
// in this case we don't want to do any ProcUi stuff on error, only on success
bool doProcUI = (argc >= 1 && std::string(argv[0]) != "safe.rpx");
uint64_t *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8;
auto *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8;
*cfwLaunchedWithPtr = OSGetTitleID();
uint32_t ApplicationMemoryEnd;
@ -120,7 +120,7 @@ int do_start(int argc, char **argv) {
ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00;
module_information_t *gModuleData = (module_information_t *) ApplicationMemoryEnd;
auto *gModuleData = (module_information_t *) ApplicationMemoryEnd;
uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t));
moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000;
@ -182,7 +182,7 @@ int 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) {
RelocationData cur = curReloc;
const RelocationData& cur = curReloc;
std::string functionName = cur.getName();
std::string rplName = cur.getImportRPLInformation().getName();
int32_t isData = cur.getImportRPLInformation().isData();
@ -210,7 +210,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);
uint8_t *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));

View File

@ -24,13 +24,12 @@
class ImportRPLInformation {
public:
ImportRPLInformation(std::string name, bool isData = false) {
explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = name;
this->_isData = isData;
}
~ImportRPLInformation() {
}
~ImportRPLInformation() = default;
static std::optional<ImportRPLInformation> createImportRPLInformation(std::string rawSectionName) {
std::string fimport = ".fimport_";
@ -38,7 +37,7 @@ public:
bool data = false;
std::string rplName = "";
std::string rplName;
if (rawSectionName.size() < fimport.size()) {
return {};
@ -54,11 +53,11 @@ public:
return ImportRPLInformation(rplName, data);
}
std::string getName() const {
[[nodiscard]] std::string getName() const {
return name;
}
bool isData() const {
[[nodiscard]] bool isData() const {
return _isData;
}

View File

@ -23,11 +23,9 @@
class ModuleData {
public:
ModuleData() {
}
ModuleData() = default;
~ModuleData() {
}
~ModuleData() = default;
void setBSSLocation(uint32_t addr, uint32_t size) {
this->bssAddr = addr;
@ -47,31 +45,31 @@ public:
relocation_data_list.push_back(relocation_data);
}
const std::vector<RelocationData> &getRelocationDataList() const {
[[nodiscard]] const std::vector<RelocationData> &getRelocationDataList() const {
return relocation_data_list;
}
uint32_t getBSSAddr() const {
[[nodiscard]] uint32_t getBSSAddr() const {
return bssAddr;
}
uint32_t getBSSSize() const {
[[nodiscard]] uint32_t getBSSSize() const {
return bssSize;
}
uint32_t getSBSSAddr() const {
[[nodiscard]] uint32_t getSBSSAddr() const {
return sbssAddr;
}
uint32_t getSBSSSize() const {
[[nodiscard]] uint32_t getSBSSSize() const {
return sbssSize;
}
uint32_t getEntrypoint() const {
[[nodiscard]] uint32_t getEntrypoint() const {
return entrypoint;
}
std::string toString() const;
[[nodiscard]] std::string toString() const;
private:
std::vector<RelocationData> relocation_data_list;

View File

@ -37,7 +37,7 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string &path, uint3
uint32_t sec_num = reader.sections.size();
uint8_t **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num);
auto **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num);
uint32_t sizeOfModule = 0;
for (uint32_t i = 0; i < sec_num; ++i) {
@ -73,7 +73,7 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string &path, uint3
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
uint32_t address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
destinations[psec->get_index()] = (uint8_t *) baseOffset;
@ -106,10 +106,10 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string &path, uint3
}
//nextAddress = ROUNDUP(destination + sectionSize,0x100);
if (psec->get_name().compare(".bss") == 0) {
if (psec->get_name() == ".bss") {
moduleData.setBSSLocation(destination, sectionSize);
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
} else if (psec->get_name().compare(".sbss") == 0) {
} else if (psec->get_name() == ".sbss") {
moduleData.setSBSSLocation(destination, sectionSize);
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
}
@ -180,7 +180,7 @@ std::vector<RelocationData> ModuleDataFactory::getImportRelocationData(const elf
break;
}
uint32_t adjusted_sym_value = (uint32_t) sym_value;
auto adjusted_sym_value = (uint32_t) sym_value;
if (adjusted_sym_value < 0xC0000000) {
continue;
}
@ -223,7 +223,7 @@ bool ModuleDataFactory::linkSection(const elfio &reader, uint32_t section_index,
break;
}
uint32_t adjusted_sym_value = (uint32_t) sym_value;
auto adjusted_sym_value = (uint32_t) sym_value;
if ((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) {
adjusted_sym_value -= 0x02000000;
adjusted_sym_value += base_text;

View File

@ -31,34 +31,33 @@ public:
this->name = name;
}
~RelocationData() {
}
~RelocationData() = default;
char getType() const {
[[nodiscard]] char getType() const {
return type;
}
size_t getOffset() const {
[[nodiscard]] size_t getOffset() const {
return offset;
}
int32_t getAddend() const {
[[nodiscard]] int32_t getAddend() const {
return addend;
}
void *getDestination() const {
[[nodiscard]] void *getDestination() const {
return destination;
}
std::string getName() const {
[[nodiscard]] std::string getName() const {
return name;
}
ImportRPLInformation getImportRPLInformation() const {
[[nodiscard]] ImportRPLInformation getImportRPLInformation() const {
return rplInfo;
}
std::string toString() const;
[[nodiscard]] std::string toString() const;
private:
char type;