Skip to content

gamesir-labs/rosettax87_jit

 
 

Repository files navigation

RosettaHack x87 + JIT

Overview

An experimental project that hooks into Apple's Rosetta to replace x87 instruction handlers with faster implementations, and patches the translation pipeline to emit AArch64 instructions directly for improved performance.

Prerequisites

  • macOS 15 or later
  • C compiler (clang)
  • CMake

Building

Main Project

cmake -B build
cmake --build build

Testing & Benchmarks

Tests and benchmarks are built automatically as part of the CMake build.

Run the test suite:

bash scripts/run_tests.sh              # build + test (native Rosetta & runtime_loader)
bash scripts/run_tests.sh --no-build   # skip build
bash scripts/run_tests.sh --native-only # native Rosetta only
bash scripts/run_tests.sh test_arith   # run a specific test

Run benchmarks (compares native Rosetta, loader with optimizations disabled, and loader with full optimizations):

bash scripts/run_benchmarks.sh            # build + benchmark
bash scripts/run_benchmarks.sh --no-build # skip build

You will see a popup asking you to authorize debugging. Once approved, the process is granted a debug session. Reference: Debugging tool entitlement

Alternatively (Not Recommended), you can disable Debugging Restrictions part of System Integrity Protection (SIP) by running csrutil enable --without debug in macOS Recovery.

Warning: This reduces system security. NOT recommended.

Configuration

All flags are set via environment variables and read at runtime.

Optimization & Performance

Variable Description
ROSETTA_X87_FAST_ROUND=1 Skip rounding mode dispatch (faster but unsafe for FLDCW-heavy code)
ROSETTA_X87_EXTENDED_FPR_SCRATCH=1 Expand FPR scratch register pool

Debugging & Troubleshooting

These flags are primarily useful for narrowing down bugs by selectively disabling features.

Variable Description
ROSETTA_X87_DISABLE_CACHE=1 Disable x87 translation cache
ROSETTA_X87_DISABLE_DEFERRED_FXCH=1 Disable deferred FXCH optimization
ROSETTA_X87_DISABLE_IR=1 Disable IR optimization pipeline
ROSETTA_X87_DISABLE_ALL_OPS=1 Disable all translated opcodes (fall back to Rosetta default)
ROSETTA_X87_DISABLE_ALL_FUSIONS=1 Disable all instruction fusions
ROSETTA_X87_DISABLE_OPS=op1,op2,... Disable specific opcodes (comma-separated)
ROSETTA_X87_DISABLE_FUSIONS=f1,f2,... Disable specific fusions (comma-separated)
ROSETTA_X87_LOGS=1 Enable verbose logging output from the loader
ROSETTA_X87_FORCE_ATTACH=1 Always attach the debugger, bypassing the automatic x64 detection

Automatic x64 Bypass

When used with Wine, runtime_loader automatically detects whether the Windows executable is 32-bit (x86) or 64-bit (x64) by reading its PE headers. 64-bit programs do not use x87 instructions, so the loader passes them through directly without attaching the debugger.

Usage with Wine

Windows Applications

You can use the brew wine@devel cask with RosettaHack x87+JIT. It supports launching Windows applications through Wine with an environment variable ROSETTA_X87_PATH.

  1. Install wine@devel using Homebrew
brew install --cask wine@devel
  1. To permanently set the environment variable, add the following to your ~/.bashrc or ~/.zshrc file:
export ROSETTA_X87_PATH=/Path/To/runtime_loader
  1. Run the Windows application
wine PATH_TO_BINARY.exe

License

This project is licensed under MIT.

About

rosettax87 but with jit

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages

  • C++ 50.1%
  • C 46.2%
  • Shell 3.1%
  • CMake 0.6%