Skip to content

Apple Silicon: pthread_jit_write_protect_np crash with hardened runtime and pty4j-unix-spawn-helper #175

@kshivang

Description

@kshivang

Issue Description

PTY4J 0.13.10-1 causes crashes on Apple Silicon (ARM64) macOS when used with hardened runtime code signing. The crash occurs during JVM initialization with pthread_jit_write_protect_np and EXC_BREAKPOINT (SIGTRAP).

Environment

  • macOS Version: 15.5 (24F74)
  • Hardware: Apple Silicon (ARM64)
  • PTY4J Version: 0.13.10-1
  • Java Version: Amazon Corretto 22 ARM64
  • Code Signing: Developer ID with hardened runtime

Crash Details

Error Type: EXC_BREAKPOINT (SIGTRAP) - Apple Mobile File Integrity (AMFI) fatal report type 309
Stack Trace: Crash occurs in pthread_jit_write_protect_np during Threads::create_vm() JVM initialization
Root Cause: The pty4j-unix-spawn-helper binary is incompatible with Apple Silicon W^X (Write XOR Execute) memory protection under hardened runtime

Steps to Reproduce

  1. Create a macOS app bundle using PTY4J 0.13.10-1
  2. Sign the app with Developer ID and hardened runtime entitlements
  3. Include these entitlements (standard for Compose Desktop apps):
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
  4. Launch the app on Apple Silicon macOS
  5. App crashes immediately with pthread_jit_write_protect_np error

Expected Behavior

App should launch without crashing, as it does in development mode (without hardened runtime).

Actual Behavior

Immediate crash with SIGTRAP during JVM initialization.

Workaround Found

The issue can be resolved by:

  1. Removing pty4j-unix-spawn-helper binaries from the PTY4J jar
  2. Using only libpty.dylib (similar to IntelliJ IDEA's approach)

This suggests the spawn helper binary is the specific component incompatible with Apple Silicon hardened runtime.

Additional Context

  • Development Mode: Works perfectly with ./gradlew run (no hardened runtime)
  • IntelliJ IDEA: Works on Apple Silicon because it uses only libpty.dylib, not spawn helper
  • PTY4J 0.12.13: Did not have this issue (no spawn helper binary)
  • PTY4J 0.13.10-1: Introduced pty4j-unix-spawn-helper which causes the crashes

Question

Is there a way to make pty4j-unix-spawn-helper compatible with Apple Silicon hardened runtime, or should apps exclude it and use only libpty.dylib on Apple Silicon?

This affects any Compose Desktop or JavaFX application using PTY4J that needs to be distributed through the Mac App Store or signed with Developer ID.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions