Repository navigation
feat(libkernel): implement the unnamed ksem semaphores - #9284
DavidSamir wants to merge 7 commits into
Conversation
…sed and replaced ids
Progress report (0c6a5bd → b0d85e3)📈 System libraries: 42.17% (+0.07%, +7 implemented, -7 removed functions) ✅ 7 implemented
🗑️ 7 removed
|
|
I had
Everything else I checked matches: the I also have |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
@pipe1os thank you, all four points check out against the source, and point 1 matters most.
On the named part: #9293 already has |
…elative name An absolute host temp path is not mapped by the Linux guest resolver. Found by xXPBSXx on boykopovar#9097.
The PS5 3.20 export lists have ksem_* in libkernel as well as libkernel_sys, and on Windows a libkernel import never reaches libkernel_sys, so titles importing them from libkernel did not find them. Following pipe1os's review on boykopovar#9284, also: ENOSPC from ksem_init when no descriptor is left, the SEM_MAX limit of 30 with ENOSPC, and dup/dup2 from a ksem id throwing as for a kqueue.
Here it is: https://github.com/pipe1os/AnyPS5/tree/feat/libkernel-ksem. One commit, all ten in libkernel; the tests are in Comparing #9293's
And you're right about |
|
@pipe1os all four points are in 8db8924:
Negative controls for 3 and 4 are in Tested. I've retitled the PR AI-assisted: yes |
It's here: https://github.com/pipe1os/AnyPS5/tree/feat/libkernel-ksem (I linked it in my last comment too, easy to miss). The named cases are I also ran 8db8924 on Windows: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 (ucrt-posix-seh r7), Ninja, Release,
One thing for #9293: the limit here checks |
jotitadev
left a comment
There was a problem hiding this comment.
Linux run of b0d85e3c2, since the description only lists Windows.
Machine: Linux x86_64, i7-8700 (6 cores / 12 threads), Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build. Head b0d85e3c2 on its own base (main 4ec064d29).
- Build ok.
guest_kernel_sys_ksempasses. - Restoring
libkernel_sys/Export.Discovery.cppto that base and keeping the test aborts it withksem_init_nid_postfix not implemented, so the test covers the change.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
|
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine. |
What
Implements the unnamed
ksem_*exports in libkernel, in a newlibkernel/Semaphore/src/Ksem.cpp, following FreeBSD 11sys/kern/uipc_sem.c. They were discovery stubs inlibkernel_systhat threwNotImplemented.Moved to libkernel so libkernel imports reach it on Windows. The PS5 3.20 export lists have
ksem_*in libkernel as well as in libkernel_sys and libkernel_web. On Windows a libkernel import never searches libkernel_sys:WindowsEntryStubBuilder.cpp:175only falls back the other way, from libkernel_sys and libkernel_web to libkernel. With the implementation in libkernel and the libkernel_sys stubs removed, both imports reach it, and the duplicate-export rule holds. On Linux and macOS, ELF lookup is global, so either import already worked. (Review by @pipe1os.)ksem_init(semid_t* idp, u_int value)EINVALforvalue > SEM_VALUE_MAX(0x7fffffff).ENOSPCwhen no descriptor is left, whatever the cause (uipc_sem.c:475-479).EFAULTfor a NULLidp.ENOSPConce 30 semaphores (SEM_MAX,p1003_1b.sem_nsems_max) exist (:300-304,:496-498); that check comes after the id is written, as in FreeBSD.ksem_post(semid_t)EOVERFLOWatSEM_VALUE_MAXksem_wait(semid_t)ksem_trywait(semid_t)EAGAINat 0ksem_timedwait(semid_t, const timespec*)CLOCK_REALTIMEdeadline, givingETIMEDOUT. Atv_nsecoutside 0..999999999 givesEINVALbefore any wait, assys_ksem_timedwaitdoes.ksem_getvalue(semid_t, int*)EFAULTfor a NULL out pointerksem_destroy(semid_t)EBUSYwhile a thread waitsAn id that isn't a live ksem gives
EINVAL, asksem_getmapsfget's failure.semid_tisintptr_t(sys/_semaphore.h).The id is a descriptor, as in FreeBSD:
kqueuereserves one, and the semaphore lives in a table keyed by that descriptor.EqueueDescriptorClosed) gains a small observer list. It is already called fromclose, fromdup2replacing a descriptor, and from sockets.Ksem.cppregisters throughRegisterDescriptorCloseObserver_nid_no_patchto drop the entry when its descriptor is closed or replaced.ksem_destroyreleases the id through the guestclose.Duplicating an id throws:
dupof a ksem id, ordup2from one, throws, as the same spot does for a kqueue (Stdio.cpp). This avoids handing back a descriptor that isn't a semaphore, where FreeBSD would share it.dup2onto an id is exact: it closes the semaphore.The named forms (
ksem_open,ksem_close,ksem_unlink) follow in #9293, which depends on this one. A debt line inlibkernel.mdrecords thedupthrow and that a guest signal doesn't interrupt a wait withEINTR.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. These are CPU-side exports, so no GPU is involved.
guest_kernel_sys_ksem(core/libs/tests/GuestKernelSysKsem.cpp) covers:EAGAIN,EOVERFLOWat the maximum, andEFAULTfor NULL pointers;timedwaitwith a badtv_nsec(EINVAL), a 150 ms real-time deadline (ETIMEDOUT), and a later post that satisfies a wait;ksem_post, withksem_destroygivingEBUSYwhile it waits;EINVAL;closeof an id, a regular file that reuses the same number getsEINVALfromksem_postandksem_getvalue; afterdup2of a file over an id,ksem_postandksem_trywaitgiveEINVAL;dupof an id anddup2from an id both throw, whiledup2(id, id)keeps the semaphore;ksem_initgivesENOSPCwith the id written but dead; destroying one makes room again.The stale-descriptor file is opened by a guest-relative name, not a host temp path, so the test also runs on Linux (found by @xXPBSXx on #9097).
Results:
NotifyDescriptorCloseObserverscall removed fromEqueueDescriptorClosed, the test fails, because a destroyed id still answers;SEM_MAXcheck removed, it fails at line 166;dupcheck removed, it fails at line 153.guest_kernel_sys, semaphore, kqueue, equeue, dup, descriptor, stdio andguest_filepass, 4 runs out of 5. The other run had one failure that didn't repeat in three more runs of the set or ten runs of the ksem test.tools/check_conventions.pypasses, including the duplicate-export rule.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)