Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Sep 18, 2021
1 parent c225cc7 commit ba38953
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/ElfUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

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

#ifdef __cplusplus
Expand Down
18 changes: 9 additions & 9 deletions src/common/dynamic_linking_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#pragma once

#include <stdint.h>
#include <stddef.h>
#include <cstdint>
#include <cstddef>

#ifdef __cplusplus
extern "C" {
Expand All @@ -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;

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,8 +17,8 @@

#pragma once

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

Expand Down
6 changes: 3 additions & 3 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));

Expand Down
11 changes: 5 additions & 6 deletions src/module/ImportRPLInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@
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_";
std::string dimport = ".dimport_";

bool data = false;

std::string rplName = "";
std::string rplName;

if (rawSectionName.size() < fimport.size()) {
return {};
Expand All @@ -54,11 +53,11 @@ class ImportRPLInformation {
return ImportRPLInformation(rplName, data);
}

std::string getName() const {
[[nodiscard]] std::string getName() const {
return name;
}

bool isData() const {
[[nodiscard]] bool isData() const {
return _isData;
}

Expand Down
20 changes: 9 additions & 11 deletions src/module/ModuleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@

class ModuleData {
public:
ModuleData() {
}
ModuleData() = default;

~ModuleData() {
}
~ModuleData() = default;

void setBSSLocation(uint32_t addr, uint32_t size) {
this->bssAddr = addr;
Expand All @@ -47,31 +45,31 @@ class ModuleData {
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;
Expand Down
12 changes: 6 additions & 6 deletions src/module/ModuleDataFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 8 additions & 9 deletions src/module/RelocationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,33 @@ class RelocationData {
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;
Expand Down

0 comments on commit ba38953

Please sign in to comment.