fix(libkernel): close guest sockets in sceKernelClose

sceKernelClose passed every descriptor to the host close. Guest socket
descriptors start at 0x10000000 and are not host descriptors, so closing
an open socket returned SCE_KERNEL_ERROR_EBADF and left it in the guest
socket table with its host socket open. Route them to GuestSockets::Close
as close, sceKernelRead and sceKernelWrite already do; a closed socket
still returns SCE_KERNEL_ERROR_EBADF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Niko 2026-10-12 00:02:17 +02:00
parent af0b52ebb4
commit 5731e02841
2 changed files with 5 additions and 1 deletions

View File

@ -224,6 +224,7 @@ int APS5_VABI sceKernelOpen(const char* path, int flags, std::uint16_t mode) {
}
int APS5_VABI sceKernelClose(int d) {
if (d >= GuestSockets::FirstDescriptor) return GuestSockets::Close(d) == 0 ? 0 : SceKernelError(*__error_nid_postfix());
File::ForgetRandomDevice(d);
#ifdef _WIN32
File::ForgetDirectoryDescriptor(d);

View File

@ -30,6 +30,7 @@ int APS5_VABI accept_nid_postfix(int, void*, std::uint32_t*);
int APS5_VABI fcntl_nid_postfix(int, int, ...);
int APS5_VABI poll_nid_postfix(PollDescriptor*, std::uint32_t, int);
int APS5_VABI close_nid_postfix(int);
int APS5_VABI sceKernelClose(int);
std::int64_t APS5_VABI read_nid_postfix(int, void*, std::uint64_t);
std::int64_t APS5_VABI write_nid_postfix(int, const char*, std::int64_t);
std::int64_t APS5_VABI _read_nid_postfix(int, void*, std::size_t);
@ -167,6 +168,8 @@ int main() {
Require(pwrite_nid_disambig1_nid_postfix(server, request, 1, 0) == -1 && *__error_nid_postfix() == 9);
Require(preadv_nid_postfix(server, positionedIov, 1, 0) == -1 && *__error_nid_postfix() == 9);
Require(pwritev_nid_postfix(server, positionedIov, 1, 0) == -1 && *__error_nid_postfix() == 9);
Require(close_nid_postfix(listener) == 0);
Require(sceKernelClose(listener) == 0);
Require(sceKernelClose(listener) == KernelBadDescriptor);
Require(close_nid_postfix(listener) == -1 && *__error_nid_postfix() == 9);
return 0;
}