mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-27 04:25:12 +00:00
alloc save memory instead return error
This commit is contained in:
parent
d5a4413d60
commit
289e9fb5ab
@ -10,6 +10,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include "boost/icl/concept/interval.hpp"
|
||||||
#include "common/elf_info.h"
|
#include "common/elf_info.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/path_util.h"
|
#include "common/path_util.h"
|
||||||
@ -43,6 +44,7 @@ struct SlotData {
|
|||||||
|
|
||||||
static std::mutex g_slot_mtx;
|
static std::mutex g_slot_mtx;
|
||||||
static std::unordered_map<u32, SlotData> g_attached_slots;
|
static std::unordered_map<u32, SlotData> g_attached_slots;
|
||||||
|
static size_t g_memory_size = 0;
|
||||||
|
|
||||||
void PersistMemory(u32 slot_id, bool lock) {
|
void PersistMemory(u32 slot_id, bool lock) {
|
||||||
std::unique_lock lck{g_slot_mtx, std::defer_lock};
|
std::unique_lock lck{g_slot_mtx, std::defer_lock};
|
||||||
@ -190,25 +192,24 @@ void SaveSFO(u32 slot_id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Error ReadMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset) {
|
void ReadMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset) {
|
||||||
std::lock_guard lk{g_slot_mtx};
|
std::lock_guard lk{g_slot_mtx};
|
||||||
auto& data = g_attached_slots[slot_id];
|
auto& data = g_attached_slots[slot_id];
|
||||||
auto& memory = data.memory_cache;
|
auto& memory = data.memory_cache;
|
||||||
if (memory.empty()) { // Load file
|
if (memory.empty()) { // Load file
|
||||||
|
memory.resize(g_memory_size);
|
||||||
|
memset(memory.data(), 0, g_memory_size);
|
||||||
IOFile f{data.folder_path / FilenameSaveDataMemory, Common::FS::FileAccessMode::Read};
|
IOFile f{data.folder_path / FilenameSaveDataMemory, Common::FS::FileAccessMode::Read};
|
||||||
if (!f.IsOpen()) {
|
if (f.IsOpen()) {
|
||||||
return Error::NOT_FOUND;
|
|
||||||
}
|
|
||||||
memory.resize(f.GetSize());
|
|
||||||
f.Seek(0);
|
f.Seek(0);
|
||||||
f.ReadSpan(std::span{memory});
|
f.ReadSpan(std::span{memory});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
s64 read_size = buf_size;
|
s64 read_size = buf_size;
|
||||||
if (read_size + offset > memory.size()) {
|
if (read_size + offset > memory.size()) {
|
||||||
read_size = memory.size() - offset;
|
read_size = memory.size() - offset;
|
||||||
}
|
}
|
||||||
std::memcpy(buf, memory.data() + offset, read_size);
|
std::memcpy(buf, memory.data() + offset, read_size);
|
||||||
return Error::OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset) {
|
void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset) {
|
||||||
@ -224,4 +225,8 @@ void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset) {
|
|||||||
Backup::OrbisSaveDataEventType::__DO_NOT_SAVE);
|
Backup::OrbisSaveDataEventType::__DO_NOT_SAVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetMemorySize(size_t memory_size) {
|
||||||
|
g_memory_size = memory_size;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Libraries::SaveData::SaveMemory
|
} // namespace Libraries::SaveData::SaveMemory
|
@ -37,8 +37,10 @@ void SetIcon(u32 slot_id, void* buf = nullptr, size_t buf_size = 0);
|
|||||||
// Save now or wait for the background thread to save
|
// Save now or wait for the background thread to save
|
||||||
void SaveSFO(u32 slot_id);
|
void SaveSFO(u32 slot_id);
|
||||||
|
|
||||||
Error ReadMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset);
|
void ReadMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset);
|
||||||
|
|
||||||
void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset);
|
void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset);
|
||||||
|
|
||||||
|
void SetMemorySize(size_t memory_size);
|
||||||
|
|
||||||
} // namespace Libraries::SaveData::SaveMemory
|
} // namespace Libraries::SaveData::SaveMemory
|
@ -1139,10 +1139,7 @@ Error PS4_SYSV_ABI sceSaveDataGetSaveDataMemory2(OrbisSaveDataMemoryGet2* getPar
|
|||||||
LOG_DEBUG(Lib_SaveData, "called");
|
LOG_DEBUG(Lib_SaveData, "called");
|
||||||
auto data = getParam->data;
|
auto data = getParam->data;
|
||||||
if (data != nullptr) {
|
if (data != nullptr) {
|
||||||
auto result = SaveMemory::ReadMemory(slot_id, data->buf, data->bufSize, data->offset);
|
SaveMemory::ReadMemory(slot_id, data->buf, data->bufSize, data->offset);
|
||||||
if (Error::OK != result) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
auto param = getParam->param;
|
auto param = getParam->param;
|
||||||
if (param != nullptr) {
|
if (param != nullptr) {
|
||||||
@ -1568,6 +1565,8 @@ Error PS4_SYSV_ABI sceSaveDataSetupSaveDataMemory2(const OrbisSaveDataMemorySetu
|
|||||||
slot_id = setupParam->slotId;
|
slot_id = setupParam->slotId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SaveMemory::SetMemorySize(setupParam->memorySize);
|
||||||
|
|
||||||
const auto& save_path = SaveMemory::GetSavePath(setupParam->userId, slot_id, g_game_serial);
|
const auto& save_path = SaveMemory::GetSavePath(setupParam->userId, slot_id, g_game_serial);
|
||||||
for (const auto& instance : g_mount_slots) {
|
for (const auto& instance : g_mount_slots) {
|
||||||
if (instance.has_value() && instance->GetSavePath() == save_path) {
|
if (instance.has_value() && instance->GetSavePath() == save_path) {
|
||||||
|
Loading…
Reference in New Issue
Block a user