Skip to content

feat: move syscalls off UI thread; refactor mach write protection - #54

Merged
JeanExtreme002 merged 1 commit into
mainfrom
jeanextreme002/offload-syscalls-off-ui-thread
Jun 6, 2026
Merged

JeanExtreme002 merged 1 commit into
mainfrom
jeanextreme002/offload-syscalls-off-ui-thread

Conversation

@JeanExtreme002

Copy link
Copy Markdown
Owner

Summary

Moves two expensive/potentially-blocking syscalls off the Qt UI thread and
refactors the macOS Mach write path.

Changes

UI-thread write offloading (cheat_poll_worker.py, cheat_table.py)Inline value edits in the cheat table previously called write_process_memory
directly on the UI thread. A slow target or a page fault would stall the
interface for the full duration of the syscall. Writes are now queued via
_CheatPollWorker.request_write() and drained at the start of each poll tick.
Failures are surfaced through the new write_failed signal so the cheat table
can show an error dialog without the syscall touching the UI thread.

Region snapshot built on scan worker (scan_worker.py, main_window.py)The first-scan snapshot of memory regions was previously enumerated on the UI
thread before the scan worker started. On a large target this could visibly
stall the interface. When ScanRequest.build_snapshot=True and no cached
snapshot is supplied, FirstScanWorker now enumerates regions itself and
emits the result via the new snapshot_ready signal so the main window can
cache it for subsequent refine/update scans.

macOS Mach write path (macos/functions.py)Extracted the protect-flip logic from _mach_write into a standalone
_elevated_write_protection context manager. _mach_write is now a thin
wrapper that calls mach_vm_write directly on the fast path and defers to the
context manager only on a retry-eligible failure code. The error messages now
consistently report the original kern return, not the one from the retry.

mach_port_deallocate error handling (macos/functions.py)The return value was previously ignored. Failures are now logged as warnings so
send-right leaks are visible instead of silent.

pyproject.toml

  • Added maintainers field.
  • Added Funding URL to [project.urls].
  • Pinned hatchling>=1.27 (required for the PEP 639 SPDX license = "MIT"
    expression and license-files glob already present in the file).

**.github/FUNDING.yml**Added GitHub Sponsors configuration.

Tests

Two new tests in tests/test_cheat_poll_worker.py cover:

  • request_write is queued and the syscall is deferred until _drain_pending_writes runs.
  • A write failure comes back as a structured failure tuple (not an exception on the caller's thread).

- CheatTable inline edits are now queued via _CheatPollWorker.request_write()
  and drained at the top of each tick, keeping write_process_memory off the
  UI thread. Failures come back through the new write_failed signal.
- FirstScanWorker builds the MemoryRegion snapshot off the UI thread when
  request.build_snapshot=True, emitting it via snapshot_ready for reuse by
  subsequent refine/update scans.
- Extracted _elevated_write_protection context manager from _mach_write so
  the protect-flip logic can be tested in isolation; _mach_write now defers
  to it for the retry path.
- mach_port_deallocate return value is now checked; failures are logged as
  warnings instead of being silently swallowed.
- Add .github/FUNDING.yml for GitHub Sponsors.
- Add maintainers field and Funding URL to pyproject.toml.
- Pin hatchling>=1.27 (required for PEP 639 SPDX licence expression).
- Add tests for request_write queuing and failure reporting.
@github-actions github-actions Bot added app GUI application changes (PyMemoryEditor/app/) win32 Windows backend changes (PyMemoryEditor/win32/) macOS macOS backend changes (PyMemoryEditor/macos/) lib Library changes (PyMemoryEditor/) tests Test changes (tests/) labels Jun 6, 2026
@JeanExtreme002 JeanExtreme002 changed the title Move syscalls off UI thread; refactor mach write protection feat: move syscalls off UI thread; refactor mach write protection Jun 6, 2026
@JeanExtreme002
JeanExtreme002 merged commit be7e822 into main Jun 6, 2026
17 of 18 checks passed
@github-actions
github-actions Bot deleted the jeanextreme002/offload-syscalls-off-ui-thread branch June 6, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app GUI application changes (PyMemoryEditor/app/) lib Library changes (PyMemoryEditor/) macOS macOS backend changes (PyMemoryEditor/macos/) tests Test changes (tests/) win32 Windows backend changes (PyMemoryEditor/win32/)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant