Skip to content

Commit

Permalink
Small fixes to the .wps loading, return nullptr instead of OSFatal, a…
Browse files Browse the repository at this point in the history
…dd asserts instead of OSFatal
  • Loading branch information
Maschell committed May 8, 2024
1 parent 6855564 commit 43a18b5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion source/PluginManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PluginManagement::loadPlugins(const std::set<std::shared_ptr<PluginData>> &plugi

if (!PluginManagement::DoFunctionPatches(plugins)) {
DEBUG_FUNCTION_LINE_ERR("Failed to patch functions");
OSFatal("Failed to patch functions");
OSFatal("WiiUPluginLoaderBackend: Failed to patch functions");
}

return plugins;
Expand Down
2 changes: 1 addition & 1 deletion source/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>
#include <wums/defines/relocation_defines.h>

#define VERSION "v0.3.1"
#define VERSION "v0.3.2"
#define VERSION_FULL VERSION VERSION_EXTRA

extern StoredBuffer gStoredTVBuffer;
Expand Down
24 changes: 18 additions & 6 deletions source/plugin/PluginInformationFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat
uint32_t sectionSize = psec->get_size();
auto address = (uint32_t) psec->get_address();
if ((address >= 0x02000000) && address < 0x10000000) {
text_size += sectionSize;
text_size += sectionSize + psec->get_addr_align();
} else if ((address >= 0x10000000) && address < 0xC0000000) {
data_size += sectionSize;
data_size += sectionSize + psec->get_addr_align();
}
if (psec->get_name().starts_with(".wups.")) {
data_size += sectionSize;
data_size += sectionSize + psec->get_addr_align();
}
}
}
Expand Down Expand Up @@ -107,16 +107,22 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat

if (destination + sectionSize > (uint32_t) text_data.data() + text_size) {
DEBUG_FUNCTION_LINE_ERR("Tried to overflow .text buffer. %08X > %08X", destination + sectionSize, (uint32_t) text_data.data() + text_data.size());
OSFatal("WUPSLoader: Tried to overflow buffer");
return std::nullopt;
} else if (destination < (uint32_t) text_data.data()) {
DEBUG_FUNCTION_LINE_ERR("Tried to underflow .text buffer. %08X < %08X", destination, (uint32_t) text_data.data());
return std::nullopt;
}
} else if ((address >= 0x10000000) && address < 0xC0000000) {
destination += (uint32_t) data_data.data();
destination -= 0x10000000;
destinations[psec->get_index()] = (uint8_t *) data_data.data();

if (destination + sectionSize > (uint32_t) data_data.data() + data_data.size()) {
DEBUG_FUNCTION_LINE_ERR("Tried to overflow .data buffer. %08X > %08X", destination + sectionSize, (uint32_t) text_data.data() + text_data.size());
OSFatal("WUPSLoader: Tried to overflow buffer");
DEBUG_FUNCTION_LINE_ERR("Tried to overflow .data buffer. %08X > %08X", destination + sectionSize, (uint32_t) data_data.data() + data_data.size());
return std::nullopt;
} else if (destination < (uint32_t) data_data.data()) {
DEBUG_FUNCTION_LINE_ERR("Tried to underflow .data buffer. %08X < %08X", destination, (uint32_t) text_data.data());
return std::nullopt;
}
} else if (address >= 0xC0000000) {
DEBUG_FUNCTION_LINE_ERR("Loading section from 0xC0000000 is NOT supported");
Expand All @@ -128,6 +134,12 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat

const char *p = psec->get_data();

uint32_t address_align = psec->get_addr_align();
if ((destination & (address_align - 1)) != 0) {
DEBUG_FUNCTION_LINE_WARN("Address not aligned: %08X %08X", destination, address_align);
return std::nullopt;
}

if (psec->get_type() == SHT_NOBITS) {
DEBUG_FUNCTION_LINE_VERBOSE("memset section %s %08X to 0 (%d bytes)", psec->get_name().c_str(), destination, sectionSize);
memset((void *) destination, 0, sectionSize);
Expand Down
13 changes: 3 additions & 10 deletions source/utils/config/CategoryRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@ CategoryRenderer::CategoryRenderer(const GeneralConfigInformation *info, const W
for (uint32_t i = 0; i < cat->getCategories().size() + cat->getItems().size(); i++) {
if (i < cat->getCategories().size()) {
auto item = make_unique_nothrow<ConfigRendererItemCategory>(cat->getCategories()[i].get());
if (!item) {
DEBUG_FUNCTION_LINE_ERR("Failed to alloc ConfigRendererItemCategory");
OSFatal("WiiUPluginBackend::CategoryRenderer::CategoryRenderer() Failed to alloc ConfigRendererItemCategory");
}
assert(item);
mItemRenderer.push_back(std::move(item));
} else {
auto itemIndex = (int32_t) (i - cat->getCategories().size());
if (itemIndex < 0 || itemIndex >= (int32_t) cat->getItems().size()) {
DEBUG_FUNCTION_LINE_ERR("unexpected index");
OSFatal("WiiUPluginBackend::CategoryRenderer::CategoryRenderer() unexpected index");
assert(false);
}
auto item = make_unique_nothrow<ConfigRendererItem>(cat->getItems()[itemIndex].get());
if (!item) {
DEBUG_FUNCTION_LINE_ERR("Failed to alloc ConfigRendererItemCategory");
OSFatal("WiiUPluginBackend::CategoryRenderer::CategoryRenderer() Failed to alloc ConfigRendererItem");
}
assert(item);
mItemRenderer.push_back(std::move(item));
}
}
Expand Down

0 comments on commit 43a18b5

Please sign in to comment.