mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-05 18:23:16 +00:00
Swap around sceKernelLseek and posix_lseek
This ensures that these have the correct error behavior, and makes their behavior align with the updated implementations for earlier functions.
This commit is contained in:
parent
ba75bc2274
commit
555dea92f4
1 changed files with 33 additions and 12 deletions
|
@ -331,16 +331,22 @@ size_t PS4_SYSV_ABI sceKernelWritev(s32 fd, const SceKernelIovec* iov, s32 iovcn
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
s64 PS4_SYSV_ABI sceKernelLseek(int d, s64 offset, int whence) {
|
s64 PS4_SYSV_ABI posix_lseek(s32 fd, s64 offset, s32 whence) {
|
||||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||||
auto* file = h->GetFile(d);
|
auto* file = h->GetFile(fd);
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
return ORBIS_KERNEL_ERROR_EBADF;
|
*__Error() = POSIX_EBADF;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::scoped_lock lk{file->m_mutex};
|
std::scoped_lock lk{file->m_mutex};
|
||||||
if (file->type == Core::FileSys::FileType::Device) {
|
if (file->type == Core::FileSys::FileType::Device) {
|
||||||
return file->device->lseek(offset, whence);
|
s64 result = file->device->lseek(offset, whence);
|
||||||
|
if (result < 0) {
|
||||||
|
ErrSceToPosix(result);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::FS::SeekOrigin origin{};
|
Common::FS::SeekOrigin origin{};
|
||||||
|
@ -350,25 +356,40 @@ s64 PS4_SYSV_ABI sceKernelLseek(int d, s64 offset, int whence) {
|
||||||
origin = Common::FS::SeekOrigin::CurrentPosition;
|
origin = Common::FS::SeekOrigin::CurrentPosition;
|
||||||
} else if (whence == 2) {
|
} else if (whence == 2) {
|
||||||
origin = Common::FS::SeekOrigin::End;
|
origin = Common::FS::SeekOrigin::End;
|
||||||
|
} else {
|
||||||
|
*__Error() = POSIX_EINVAL;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file->f.Seek(offset, origin)) {
|
if (!file->f.Seek(offset, origin)) {
|
||||||
LOG_CRITICAL(Kernel_Fs, "sceKernelLseek: failed to seek");
|
if (errno != 0) {
|
||||||
return ORBIS_KERNEL_ERROR_EINVAL;
|
// Seek failed in platform-specific code, errno needs to be converted.
|
||||||
|
SetPosixErrno(errno);
|
||||||
|
} else {
|
||||||
|
// Seek failed because offset is beyond the end of the file.
|
||||||
|
*__Error() = POSIX_ENXIO;
|
||||||
}
|
}
|
||||||
return file->f.Tell();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s64 PS4_SYSV_ABI posix_lseek(int d, s64 offset, int whence) {
|
s64 result = file->f.Tell();
|
||||||
s64 result = sceKernelLseek(d, offset, whence);
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
LOG_ERROR(Kernel_Pthread, "posix_lseek: error = {}", result);
|
// Tell failed in platform-specific code, errno needs to be converted.
|
||||||
ErrSceToPosix(result);
|
SetPosixErrno(errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s64 PS4_SYSV_ABI sceKernelLseek(s32 fd, s64 offset, s32 whence) {
|
||||||
|
s64 result = posix_lseek(fd, offset, whence);
|
||||||
|
if (result < 0) {
|
||||||
|
LOG_ERROR(Kernel_Fs, "lseek: error = {}", *__Error());
|
||||||
|
return ErrnoToSceKernelError(*__Error());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
s64 PS4_SYSV_ABI sceKernelRead(int d, void* buf, size_t nbytes) {
|
s64 PS4_SYSV_ABI sceKernelRead(int d, void* buf, size_t nbytes) {
|
||||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||||
auto* file = h->GetFile(d);
|
auto* file = h->GetFile(d);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue