fix(libkernel): route equeue socket checks by membership

This commit is contained in:
MarcZX100 2026-10-13 03:28:27 +00:00
parent eb2b360f0b
commit e0ec0c8094
2 changed files with 6 additions and 10 deletions

View File

@ -559,8 +559,8 @@ int VnodeDescriptorError(int descriptor) {
if (descriptor < 0) {
return GUEST_EBADF;
}
if (descriptor >= GuestSockets::FirstDescriptor) {
return GuestSockets::IsOpen(descriptor) ? GUEST_EINVAL : GUEST_EBADF;
if (GuestSockets::IsOpen(descriptor)) {
return GUEST_EINVAL;
}
if (!DescriptorIsOpen_nid_no_patch(descriptor)) {
return GUEST_EBADF;
@ -647,7 +647,7 @@ int APS5_VABI sceKernelDeleteFileEvent(KernelEqueue eq, int fd) {
if (!EqueuePin_nid_postfix(eq)) {
return SCE_KERNEL_ERROR_EBADF;
}
if (fd < 0 || (fd >= GuestSockets::FirstDescriptor ? !GuestSockets::IsOpen(fd) : !DescriptorIsOpen_nid_no_patch(fd))) {
if (fd < 0 || (!GuestSockets::IsOpen(fd) && !DescriptorIsOpen_nid_no_patch(fd))) {
return SCE_KERNEL_ERROR_EBADF;
}
return EqueueDeleteEvent_nid_postfix(eq, static_cast<std::uintptr_t>(fd), EVFILT_VNODE);

View File

@ -118,8 +118,8 @@ int DescriptorFilterError(int kqueueDescriptor, std::uintptr_t ident) {
return GUEST_EBADF;
}
const int descriptor = static_cast<int>(ident);
if (descriptor >= GuestSockets::FirstDescriptor) {
return GuestSockets::IsOpen(descriptor) ? 0 : GUEST_EBADF;
if (GuestSockets::IsOpen(descriptor)) {
return 0;
}
if (!DescriptorIsOpen_nid_no_patch(descriptor)) {
return GUEST_EBADF;
@ -135,7 +135,7 @@ int AddDescriptorKnote(const KernelEqueueRef& queue, KernelEvent& change, std::u
}
NotImplemented_nid_no_patch("kevent: EVFILT_READ on a kqueue descriptor");
}
if (descriptor < GuestSockets::FirstDescriptor) {
if (!GuestSockets::IsOpen(descriptor)) {
NotImplemented_nid_no_patch(change.filter == EVFILT_READ ? "kevent: EVFILT_READ on a non-socket descriptor" : "kevent: EVFILT_WRITE on a non-socket descriptor");
}
if ((change.fflags & NOTE_LOWAT) != 0) {
@ -325,10 +325,6 @@ int APS5_VABI kqueue_nid_postfix() {
if (errno == ENFILE) return PosixFailure(GUEST_ENFILE);
throw std::runtime_error(std::string(__func__) + ": reserving a descriptor failed, errno=" + std::to_string(errno));
}
if (descriptor >= GuestSockets::FirstDescriptor) {
ReleaseDescriptor(descriptor);
throw std::runtime_error(std::string(__func__) + ": host descriptor reached the guest socket range");
}
auto queue = std::make_shared<KernelEqueuePrivate>(static_cast<KernelEqueue>(descriptor), true);
queue->SetName("kqueue");
std::lock_guard lock(g_kqueueMutex);