Skip to content

Conversation

@bpowers
Copy link
Member

@bpowers bpowers commented Jan 20, 2026

Summary

  • Interpose posix_spawn and posix_spawnp to acquire allocator locks before spawning, preventing races between spawn and fork operations
  • Remove unnecessary mprotect calls around fork that were causing issues
  • Remove leftover debugging line in meshable_arena

Fixes #123
Closes #124

Test plan

  • Existing fork tests pass
  • Manual testing with applications that use posix_spawn

These functions can create child processes similar to fork(), so they
need to acquire the same locks as prepareForFork to prevent concurrent
allocation operations from corrupting heap state.

The SpawnLockGuard RAII class acquires locks in the same order as
prepareForFork (heap lock, runtime lock, internal heap lock) and
releases them in reverse order on destruction.
Port tests from rustforkexploration/mesh_tests to gtest:
- ForkRaceWithWriters: tests mprotect race with threads actively writing
  during fork (verifies segfault handler correctly waits for fork)
- PosixSpawn: tests posix_spawn behavior (no atfork handlers)
- MixedSpawns: tests alternating posix_spawn and fork+exec
- PosixSpawnWithConcurrentAllocations: stress test with concurrent allocs
@bpowers bpowers merged commit b9ca5ca into plasma-umass:master Jan 21, 2026
1 check was pending
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.

Mesh crashes when used as allocator for cargo build

1 participant