fix(libkernel): look up the descriptor of lseek before the whence value

lseek on a descriptor that is not open with an invalid whence answered EINVAL.
FreeBSD 11.4 kern_lseek looks the descriptor up first and only then lets the
file's seek operation judge the whence, so the answer is EBADF.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
xXPBSXxandClaude Sonnet 5.5 committed 2026-10-20 13:39:50 +02:00
1 parent d50ec76da0
commit 06ee881eba
2 files changed
+4

No files matched your search

@@ -887,6 +887,7 @@ int APS5_VABI sceKernelFtruncate(int d, int64_t length) {
}
int64_t APS5_VABI lseek_nid_postfix(int d, int64_t offset, int whence) {
if (!GuestSockets::IsOpen(d) && !DescriptorIsOpen_nid_no_patch(d)) return PosixFailure(GUEST_EBADF);
if (whence < 0 || whence > 2) return PosixFailure(GUEST_EINVAL);
return PosixResult(sceKernelLseek(d, offset, whence));
}
+3
View File
@@ -1026,6 +1026,9 @@ int main() {
Require(flock_nid_postfix(other, 2 | 4) == 0);
Require(flock_nid_postfix(other, 8) == 0);
Require(flock_nid_postfix(locked, 2 | 4) == 0);
Require(lseek_nid_postfix(-1, 0, 7) == -1 && *__error_nid_postfix() == 9);
Require(lseek_nid_postfix(0x7fffffff, 0, -1) == -1 && *__error_nid_postfix() == 9);
Require(lseek_nid_postfix(locked, 0, 7) == -1 && *__error_nid_postfix() == 22);
Require(flock_nid_postfix(-1, 2 | 4) == -1 && *__error_nid_postfix() == 9);
Require(flock_nid_postfix(0x7fffffff, 1) == -1 && *__error_nid_postfix() == 9);
int flockPipe[2] = {-1, -1};