#101
Add virtual-memory and thread-control primitives
Summary
Adds the low-level virtual-memory and thread-control primitives needed for cross-platform inline hooking, plus a few correctness fixes surfaced along the way. Targets Linux, macOS, and Windows on x86-64.
Intention
The Zyrex hook engine needs to allocate executable trampolines near a target (within +/-2 GiB), query existing page protections, and suspend and redirect threads while a patch is applied. Those capabilities previously existed only implicitly on Windows. This adds portable APIs so the hook engine can run on POSIX.
Changes
ZyanMemoryVirtualAllocandZyanMemoryVirtualQuery, including an address hint for near allocation within +/-2 GiB of a target.- Thread control:
ZyanThreadEnumerate,ZyanThreadSuspend/ZyanThreadResume, and get/set instruction pointer, using a realtime-signal park mechanism on Linux. - Fix
ZyanProcessFlushInstructionCacheon POSIX to use__builtin___clear_cacheinstead ofmsync, which only accepts page-aligned ranges. - Fix
ZYAN_ALIGN_DOWNso it no longer misaligns values that are already aligned. - Bound the
ZyanThreadSuspendpark-wait so it cannot deadlock on a thread that is exiting.
Notes
These primitives are consumed by the zyan-hook-engine multi-platform inline hooking PR.