feat(libSceNpCommon): implement sce::np::EventFlag and sceNpWaitEventFlag #13270
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13270"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-30T10:45:03Z.
What
Implements
sce::np::EventFlag(15 exports) and the C exportsceNpWaitEventFlagfromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console).main: 7 of them had placeholderint (void)declarations:Create,Open,Destroy,Set,Poll,D0andD2.C1,C2,D1,ctor,dtor,Wait,Clear,CancelandsceNpWaitEventFlag.EventFlag::IsInit, because open #12823 implements it.sceNpWaitEventFlag(flag, pattern, mode, result, timeout*):sceKernelWaitEventFlagwith the same arguments;0x8002003Cto0x8055800Band0x80020055(cancelled) to0x80558010;NpEventFlagObject(declared inApi.hpp, 24 bytes): vtable,KernelEventFlag flag, thenint32_t stateat +0x10. The state is 0 when uninitialized, 1 when created and 2 when opened. The vtable is{0, 0, D1, D0}.ctor: set the state to 0. C1/C2 also set the vtable.dtor: callsceKernelCloseEventFlag(opened) orsceKernelDeleteEventFlag(created). D1/D2 also reset the vtable.D0usessceNpCloseEventFlag/sceNpDeleteEventFlagand then frees throughsce::np::Object::operator delete(void*).Create(const char* name, uint32_t attr)/Open(const char* name):0x80559E03when already initialized;sceNpCreateEventFlag(&flag, name, attr, 0)/sceNpOpenEventFlag(&flag, name)and return its result as is, setting the state on success.Destroy: closes or deletes by state and always clears the state.Set(pattern)/Clear(pattern): callsceKernelSetEventFlag/sceKernelClearEventFlagdirectly.Poll(pattern, mode, result*): callssceNpPollEventFlag. Both these andSet/Clearkeep only negative results.Wait(pattern, mode, result*, uint32_t usec): callssceNpWaitEventFlag, passing a pointer to its own copy of the timeout, or null whenusecis 0, so 0 waits without a timeout.Cancel(pattern): callssceNpCancelEventFlagwith a local waiter count and returns its result.Where the module halts: before
CreateorOpen,Set,Poll,Wait,ClearandCancelassertIsInit()and panic. AnyPS5 throwsstd::invalid_argument, following the libSceJson2 exports, and the debt file records it.Tested
Linux (CachyOS, GCC 16.2, Release):
ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed.guest_np_common_runtimepassed 3 of 3 runs, in 0.03 s each.TestEventFlagObjectsinGuestNpCommonRuntime.cppuses real kernel event flags and a thread to check:Create;CreateorOpenreturning0x80559E03;Poll;Setfollowed byPoll;Waitreturning0x8055800B;Waitwith timeout 0 returning for bits already set;Clearkeeping only the bits of its pattern;Cancelending a blockedWaiton another thread with0x80558010;sceNpWaitEventFlag's timeout mapping;Openby name on a shared flag, withDestroyclosing the opened handle and leaving the creator's;D0freeing through the allocator stored byObject::operator new.Mutation check: I changed 8 single lines of the new functions, one at a time; the test fails for all 8. The changes were:
sceNpWaitEventFlagdropped;Waitalways passing a timeout;Openrecording "created";Createcheck removed;Clearignoring its pattern;Pollignoring the kernel;Destroynot clearing the state.No firmware differential: these methods wrap kernel event flags. A unicorn run would only exercise the glue against a fake kernel, and I can't swap the kernel under AnyPS5. The contract above comes from the disassembly, including the vtable relocations and the C1/C2 and D1/D2 aliases (one address each).
Windows not built. Not run on a console.
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)NP_ERROR_OBJECT_ALREADY_INITIALIZEDconstant in the same place; after #13130 lands, I mergemainhere and keep its copy. #13277 now declaresDepends on: #13130, #13270.NotImplementedstubs (the ones missing frommain), so it drops them fromInventoryExports.cppafter this lands. Agreed with its author (comment): #13120 has removed these declarations and declaresDepends on: #13130, #13270, #13277, #13281.Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T11:00:10Z.
Review: APPROVED
Reviewed — looks good
The EventFlag implementation and its focused tests are consistent with the reviewed source, and no blocking defect was found at head
5018820e73e03373871e52340aed3dce9fcc55a5.What I ran
Reviewed head
5018820e73e03373871e52340aed3dce9fcc55a5against PR based2250771ab27167fdc8e08931708f772ec39b467. A merge preview onto currentmain3948413d701b093b32a194f5fe5525ea8d5f5079was clean (tree68b54ede7df9a0f2c610b6a2409685b76d9b4232). Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5, GCC 12.2.0. I did not build or compile locally. The Linux CTest and mutation results below are reported by the author, not run by me.Results
git diff --checkguest_np_common_runtimepassed 3/3 runs.Unedited local command output
git diff --checkproduced no output.Negative control
Findings
Blocking
None found in the reviewed change.
Non-blocking
Open PR #13120 currently declares several overlapping EventFlag exports as throwing placeholders. This PR removes the corresponding placeholders from its own pending-export files, and its description already notes that whichever PR lands second must remove the duplicate inventory definitions. The overlap is a landing-order coordination item, not a defect in this PR against current
main.Sources
sceNpWaitEventFlagand object lifecycle and wait operations.sceNpWaitEventFlagplaceholder.Not verified
I did not independently run the author-reported Linux tests or mutation checks, build on Windows, or test on console hardware. Hosted Windows CI was pending at the last check.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T11:46:23Z.
Review: CHANGES_REQUESTED
Re-checked — new overlap report, changes requested
I found no new implementation defect, but the refreshed overlap report shows unresolved shared exports and source lines while the checklist still says
Depends on: none; repository rules require an agreed landing order for these overlaps.What I ran
Reviewed head
5018820e73e03373871e52340aed3dce9fcc55aagainst PR based2250771ab27167fdc8e08931708f772ec39b467. Currentmainisd823f56fbf088fcb7b1ebadfbc95acc4d3433a8b; its merge preview is clean, but it is not included in this head. Environment: Debian 12 x86_64, Python 3.11.2, GCC 12.2.0. No local build/tests were run.Results
mainis not in the PR headObserved overlap and CI output
Negative control
Not applicable to this recheck; the implementation and test assertions did not change.
Findings
Blocking
CONTRIBUTING.mdrequires agreeing with authors of overlapping open PRs on which lands first and recording that order withDepends on. #13270 documents several overlaps—including nine exports also declared as stubs by #13120 and a shared constant with #13130/#13277—but the checklist still saysDepends on: noneand the discussion does not record an agreed order. Please update the checklist after coordinating the order with the affected authors. Also refresh this branch onto currentmain; the merge preview is clean, but the rule requires an up-to-date base.Non-blocking
The earlier Linux and Windows runtime results remain useful evidence for this unchanged head; I have not repeated those builds or tests.
Sources
Not verified
No local build or tests; no PS5 console behavior. The exact merge order and resolution of the listed shared edits remain unsettled.
To get this to a good state
Coordinate and record the landing order for the overlapping PRs, update
Depends onaccordingly, rebase onto currentmain, and rerun the relevant CI/tests on the new head. I will review that exact head again.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T12:24:27Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes still needed
The updated checklist now records
#13130as a dependency, but the branch conflicts with currentmain, does not include #13130's current head, and the overlapping export order with #13120 is still unconfirmed.What I ran
Head
d5c85970c505ad7bdcd2760e7eb5ab07a312d981; PR base8e68a7d7b9f6aeedb0ca03eee115571640555988; currentmain42d009f5f37c8f388b01fbfe38d2e704c792c46f. Environment: Linux x86_64, Python 3.11.2. No local build or C++ tests were run.Results
passed_with_warnings: 322 symbols, seven lexical warnings for the same private helper definitions; no EventFlag-specific warning.mainpreview conflicts inRuntime.cpp,include/Api.hpp,GuestNpCommonRuntime.cpp, anddocs/dev/debt/libSceNpCommon.md. The current #13130 head39318d9ed35ecd533e4d2494aa7b9b5f5e556007is not included in this head.Unedited audit summary
Findings
Blocking
NotImplementedexports with #13120 still have no agreed landing order. The PR author has proposed that #13270 land first, but the latest comment says the #13120 author has not confirmed. Please get and record that confirmation; if #13120 lands first, remove the duplicates here and list #13120 as a dependency.mainis stale: its current-main preview has content conflicts in the four files listed above. The stack check also shows that the current #13130 head is absent from this branch. Once #13130's dependency state is settled, update the stack onto the appropriate current base and resolve the conflicts.Non-blocking
The EventFlag implementation is unchanged in this merge update. The author reports rerunning the focused tests on the new head; I did not reproduce them locally.
Sources
Not verified
No local build, C++ tests, Windows run, or console test. Linux and specialized hosted jobs were skipped. The ABI audit is lexical and does not prove binary ABI correctness.
To get this to a good state
Please agree on the #13120 order, ensure the current #13130 dependency head is incorporated at the appropriate time, and resolve the current-main conflicts. On the resulting head I will rerun conventions, ABI audit, diff check, and the stack/mergeability check; report the same focused test command on that head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T13:29:14Z.
Review: APPROVED
Re-checked — new head, looks good
The earlier conflict and export-order blockers are addressed by the updated merge preview and the now-confirmed landing order; I found no blocking defect in this head.
What I ran
Reviewed head
1f264fdc6480396108557b4e2e2f0731212fd65eagainst PR base42d009f5f37c8f388b01fbfe38d2e704c792c46f. The stack preview against currentmainda026c70655a132031d45e2008c24f993870d801was clean. The declared order is #13130 → #13270 → #13277; #13130 remains open and its head is not included yet. Environment: Debian GNU/Linux x86_64, Python 3.11.2. I did not configure, build, compile, or run C++ tests.Results
passed_with_warnings; seven lexical warnings for helper definitions inRuntime.cpp. I confirmed the named helpers are unchanged by this PR; none is an EventFlag-specific finding.main; the current #13130 dependency head is not included while it remains open. #13120 confirms it removed the overlapping stubs and now depends on the implementation PRs.1f264fdc6480396108557b4e2e2f0731212fd65e, the author reports 70/70 `np_common1f264fdc6480396108557b4e2e2f0731212fd65e; conventions and labels were pending at final refresh. Linux and specialized jobs were skipped.Unedited output from checks I ran
The precheck reported these unavailable helper files in its isolated checkout:
Negative control
Findings
Blocking
None found in the reviewed head.
Non-blocking
The declared #13130 dependency remains open and its head is not part of this PR head. The PR now states the intended landing order and plans to merge the dependency after it lands; the preview against current
mainis clean. The liveneeds rebaselabel is not accompanied by a conflict in the current preview, so I am not asking for a rebase solely to clear the label.Sources
Not verified
I did not independently run the Linux tests or mutation checks, or verify firmware behavior on a console. Hosted Windows passed on the exact head; hosted Linux and specialized jobs were skipped, and the latest conventions/labels runs were pending.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:59:37Z.
Review: COMMENTED
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement;
Unblocks: noneis allowed. The technical points below are unaffected.No title reaches this code. The checklist says "Unblocks: none" and the description says the behaviour was "read from disassembly, not measured on a console". Please add a title ID and a log line showing a title on main reaching
sce::np::EventFlagorsceNpWaitEventFlag(an unresolved-import or NotImplemented line for one of these 16 NIDs is enough).One code question in
Runtime.cpp:D1/D2anddtorclose or delete the kernel flag bystatebut do not resetstateafterwards, whereasDestroydoes. Is a second destructor call on the same object possible in the native module (for exampleD1after an explicitClose), and does the disassembly show the state being cleared there?