Skip to content

fix(libc): keep the app0.zar state through exit handlers - #7558

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
mugurc:fix/libc-app-archive-exit
Oct 18, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
mugurc:fix/libc-app-archive-exit

Conversation

@mugurc

@mugurc mugurc commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

What

guest_path_lifetime fails on macOS on main since #5835: path services during exit: mutex lock failed: Invalid argument. Every path resolution reaches the app0.zar state in AppArchive.cpp, which was a function-local static. The test registers an exit handler before its first path resolution, so the static is constructed after the handler is registered and destroyed before it runs: the handler resolves a path and locks the destroyed mutex. glibc does not check that; macOS fails the lock with EINVAL.

The state is now allocated once and never destroyed, as the working directory state in General.cpp (Directories()) already is.

#7332, which brings the open macOS pull requests together, makes the same change to State() among its other fixes; this pull request is that change on its own.

Tested

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Every path resolution reaches the app0.zar state, which was a
function-local static: it is destroyed during exit before the handlers
registered ahead of its first use run, so a path resolved in such a
handler locked a destroyed mutex. glibc lets that pass; macOS fails it
with EINVAL, and guest_path_lifetime failed there. The state is now
allocated once and never destroyed, as the working directory state
beside it already is.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the change against the exit-ordering failure and current call sites. Keeping Archive alive for the process lifetime prevents its mutex and reader from being destroyed before registered exit handlers finish resolving app0 paths; this matches the lifetime used for the shared directory state.

The PR reports a focused macOS guest_path_lifetime fail/pass reproduction, and its hosted checks are green. I did not run the macOS reproduction locally. I found no correctness issue in this diff.

@oneandonlydean oneandonlydean self-assigned this Oct 18, 2026
@github-actions github-actions Bot added the libc label Oct 18, 2026
@oneandonlydean
oneandonlydean merged commit e5f18ea into boykopovar:main Oct 18, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants