From bdfc0c246ce35cde015f3e48a284052ca4caf45e Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Wed, 19 Feb 2025 19:24:22 -0600 Subject: [PATCH] Remove SetPosixErrno Ideally, we've handled all possible error conditions before calling these functions, so treat errors in platform-specific code as IO errors and return POSIX_EIO instead. --- src/core/libraries/kernel/file_system.cpp | 12 ++++++------ src/core/libraries/kernel/kernel.cpp | 12 ------------ src/core/libraries/kernel/kernel.h | 1 - 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 27e8cf092..6c2397085 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -160,9 +160,9 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) { } if (e != 0) { - // IOFile code uses platform specific errnos, they must be converted to POSIX errnos. + // IOFile code uses platform specific errnos. Use POSIX_EIO for now h->DeleteHandle(handle); - SetPosixErrno(e); + *__Error() = POSIX_EIO; return -1; } } @@ -369,8 +369,8 @@ s64 PS4_SYSV_ABI posix_lseek(s32 fd, s64 offset, s32 whence) { if (!file->f.Seek(offset, origin)) { if (errno != 0) { - // Seek failed in platform-specific code, errno needs to be converted. - SetPosixErrno(errno); + // Seek failed in platform-specific code. Use POSIX_EIO for now. + *__Error() = POSIX_EIO; } else { // Seek failed because offset is beyond the end of the file. *__Error() = POSIX_ENXIO; @@ -380,8 +380,8 @@ s64 PS4_SYSV_ABI posix_lseek(s32 fd, s64 offset, s32 whence) { s64 result = file->f.Tell(); if (result < 0) { - // Tell failed in platform-specific code, errno needs to be converted. - SetPosixErrno(errno); + // Tell failed in platform-specific code. Use POSIX_EIO for now. + *__Error() = POSIX_EIO; return -1; } return result; diff --git a/src/core/libraries/kernel/kernel.cpp b/src/core/libraries/kernel/kernel.cpp index 0ab8fac29..d42f440c7 100644 --- a/src/core/libraries/kernel/kernel.cpp +++ b/src/core/libraries/kernel/kernel.cpp @@ -84,18 +84,6 @@ int ErrnoToSceKernelError(int error) { return error + ORBIS_KERNEL_ERROR_UNKNOWN; } -void SetPosixErrno(int e) { - // Some error numbers are different between supported OSes - switch (e) { - case ENOENT: - g_posix_errno = POSIX_ENOENT; - break; - default: - UNREACHABLE_MSG("errno = {}", e); - g_posix_errno = e; - } -} - static uint64_t g_mspace_atomic_id_mask = 0; static uint64_t g_mstate_table[64] = {0}; diff --git a/src/core/libraries/kernel/kernel.h b/src/core/libraries/kernel/kernel.h index 8e7f475ad..96ad4a876 100644 --- a/src/core/libraries/kernel/kernel.h +++ b/src/core/libraries/kernel/kernel.h @@ -16,7 +16,6 @@ namespace Libraries::Kernel { void ErrSceToPosix(int result); int ErrnoToSceKernelError(int e); -void SetPosixErrno(int e); template struct StringLiteral {