mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-29 22:20:48 +00:00
savedata: avoid passing vm memory to fs::file
This commit is contained in:
parent
03814e8d02
commit
d8ae94df5b
@ -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);
|
fs::file file(dir_path + file_path, fs::read);
|
||||||
if (!file)
|
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;
|
return CELL_SAVEDATA_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.seek(fileSet->fileOffset);
|
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;
|
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);
|
fs::file file(dir_path + file_path, fs::write + fs::create);
|
||||||
file.seek(fileSet->fileOffset);
|
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
|
file.trunc(file.pos()); // truncate
|
||||||
break;
|
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);
|
fs::file file(dir_path + file_path, fs::write + fs::create);
|
||||||
file.seek(fileSet->fileOffset);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user