Skip to content

Reject NULL / uninitialised mutex handles with EINVAL - #3

Merged
sharkwouter merged 1 commit into
pspdev:platform_agnosticfrom
fjtrujy:fix/mutex-null-handle-rejection
May 12, 2026
Merged

sharkwouter merged 1 commit into
pspdev:platform_agnosticfrom
fjtrujy:fix/mutex-null-handle-rejection

Conversation

@fjtrujy

@fjtrujy fjtrujy commented May 11, 2026

Copy link
Copy Markdown
Member

Summary

  • Make pthread_mutex_{lock,trylock,timedlock,unlock,destroy} reject mutex == NULL and *mutex == NULL with EINVAL instead of dereferencing.
  • The previous code relied on the OS to convert a bad load into an error. On the embedded targets this library runs on (PS2 EE, PSP, Vita) there is no signal handling for bad loads — the kernel traps and the process dies, so the API itself has to validate the pointer.
  • Add tests/mutex9.c exercising both NULL handles and the post-failed-init NULL-value case across all five mutex APIs.

Test plan

  • Build the test suite for PSP and confirm pthread_test_mutex9() passes.
  • Build the test suite for PS2 and confirm pthread_test_mutex9() passes.
  • Confirm existing mutex tests (1..8r) still pass on both targets.

The mutex API previously dereferenced *mutex unconditionally, relying
on the OS to convert a bad load into an error. On the embedded targets
this library runs on (PS2 EE, PSP, Vita) there is no signal handling
for bad loads — the kernel traps and the process dies, so the API
itself has to validate the pointer.

Make pthread_mutex_{lock,trylock,timedlock,unlock,destroy} reject both
mutex == NULL and *mutex == NULL with EINVAL. Add tests/mutex9.c to
cover both NULL handles and the post-failed-init NULL value case.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@sharkwouter
sharkwouter merged commit 97fe4ce into pspdev:platform_agnostic May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants