Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mods getting duplicated when scanning multiple times, fix incorrect mmap for rdram #71

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions librecomp/include/librecomp/addresses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace recomp {
// 512GB (kseg0 size)
constexpr size_t mem_size = 512U * 1024U * 1024U;
// 2GB (Addressable upper half of the address space)
constexpr size_t allocation_size = 2048U * 1024U * 1024U;
constexpr size_t mem_size = 512ULL * 1024ULL * 1024ULL;
// 4GB (the full address space)
constexpr size_t allocation_size = 4096ULL * 1024ULL * 1024ULL;
// We need a place in rdram to hold the PI handles, so pick an address in extended rdram
constexpr int32_t cart_handle = 0x80800000;
constexpr int32_t drive_handle = (int32_t)(cart_handle + sizeof(OSPiHandle));
Expand Down
1 change: 1 addition & 0 deletions librecomp/include/librecomp/mods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ namespace recomp {
CodeModLoadError load_mod_code(uint8_t* rdram, const std::unordered_map<uint32_t, uint16_t>& section_vrom_map, recomp::mods::ModHandle& mod, int32_t load_address, uint32_t& ram_used, std::string& error_param);
CodeModLoadError resolve_code_dependencies(recomp::mods::ModHandle& mod, std::string& error_param);
void add_opened_mod(ModManifest&& manifest, std::vector<size_t>&& game_indices, std::vector<ModContentTypeId>&& detected_content_types);
void close_mods();

static void on_code_mod_enabled(ModContext& context, const ModHandle& mod);

Expand Down
9 changes: 9 additions & 0 deletions librecomp/src/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,18 @@ void recomp::mods::ModContext::register_game(const std::string& mod_game_id) {
mod_game_ids.emplace(mod_game_id, mod_game_ids.size());
}

void recomp::mods::ModContext::close_mods() {
opened_mods_by_id.clear();
opened_mods.clear();
mod_ids.clear();
enabled_mods.clear();
}

std::vector<recomp::mods::ModOpenErrorDetails> recomp::mods::ModContext::scan_mod_folder(const std::filesystem::path& mod_folder) {
std::vector<recomp::mods::ModOpenErrorDetails> ret{};
std::error_code ec;
close_mods();

for (const auto& mod_path : std::filesystem::directory_iterator{mod_folder, std::filesystem::directory_options::skip_permission_denied, ec}) {
bool is_mod = false;
bool requires_manifest = true;
Expand Down
2 changes: 1 addition & 1 deletion librecomp/src/recomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void recomp::start(
}
}
#else
rdram = (uint8_t*)mmap(NULL, allocation_size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
rdram = (uint8_t*)mmap(NULL, allocation_size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
alloc_failed = rdram == reinterpret_cast<uint8_t*>(MAP_FAILED);
if (!alloc_failed) {
// mprotect returns -1 on failure.
Expand Down