mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 05:51:27 +12:00
savedata: avoid passing vm memory to fs::file
This commit is contained in:
parent
03814e8d02
commit
d8ae94df5b
1 changed files with 16 additions and 7 deletions
|
@ -735,11 +735,16 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
|
|||
fs::file file(dir_path + file_path, fs::read);
|
||||
if (!file)
|
||||
{
|
||||
cellSaveData.error("savedata file not found");
|
||||
cellSaveData.error("Failed to open file %s%s", dir_path, file_path);
|
||||
return CELL_SAVEDATA_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
file.seek(fileSet->fileOffset);
|
||||
fileGet->excSize = static_cast<u32>(file.read(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize)));
|
||||
std::vector<uchar> buf;
|
||||
buf.resize(std::min<u32>(fileSet->fileSize, fileSet->fileBufSize));
|
||||
buf.resize(file.read(buf.data(), buf.size()));
|
||||
std::memcpy(fileSet->fileBuf.get_ptr(), buf.data(), buf.size());
|
||||
fileGet->excSize = ::size32(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -747,7 +752,9 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
|
|||
{
|
||||
fs::file file(dir_path + file_path, fs::write + fs::create);
|
||||
file.seek(fileSet->fileOffset);
|
||||
fileGet->excSize = static_cast<u32>(file.write(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize)));
|
||||
const auto start = static_cast<uchar*>(fileSet->fileBuf.get_ptr());
|
||||
std::vector<uchar> buf(start, start + std::min<u32>(fileSet->fileSize, fileSet->fileBufSize));
|
||||
fileGet->excSize = ::narrow<u32>(file.write(buf.data(), buf.size()));
|
||||
file.trunc(file.pos()); // truncate
|
||||
break;
|
||||
}
|
||||
|
@ -763,7 +770,9 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
|
|||
{
|
||||
fs::file file(dir_path + file_path, fs::write + fs::create);
|
||||
file.seek(fileSet->fileOffset);
|
||||
fileGet->excSize = static_cast<u32>(file.write(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize)));
|
||||
const auto start = static_cast<uchar*>(fileSet->fileBuf.get_ptr());
|
||||
std::vector<uchar> buf(start, start + std::min<u32>(fileSet->fileSize, fileSet->fileBufSize));
|
||||
fileGet->excSize = ::narrow<u32>(file.write(buf.data(), buf.size()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue