Context
PR #1578 adds a no-surrogate mode (HYPERLIGHT_MAX_SURROGATES=0) that uses WHvMapGpaRange instead of WHvMapGpaRange2. Currently whp.rs branches on Option<SurrogateProcess> to choose the mapping path.
Proposal
Unify the surrogate and no-surrogate paths so whp.rs doesn't need to know or care which mode is active. Two possible approaches:
-
Enum / trait abstraction: Make SurrogateProcess an enum (or dyn Trait) with two variants — one backed by a real surrogate process (WHvMapGpaRange2) and one that maps from the host process directly (WHvMapGpaRange). The NoSurrogateGuard could be folded into the no-surrogate variant.
-
Always use WHvMapGpaRange2: Use the current process handle as the source when surrogates are disabled, eliminating the branch entirely. This needs validation — it's unclear whether WHvMapGpaRange2 with GetCurrentProcess() is a supported pattern.
Either way, the mapping call would move into the surrogate module so whp.rs just calls a single map(...) method.
Origin
Suggestion from @syntactically in PR #1578 review.
Context
PR #1578 adds a no-surrogate mode (
HYPERLIGHT_MAX_SURROGATES=0) that usesWHvMapGpaRangeinstead ofWHvMapGpaRange2. Currentlywhp.rsbranches onOption<SurrogateProcess>to choose the mapping path.Proposal
Unify the surrogate and no-surrogate paths so
whp.rsdoesn't need to know or care which mode is active. Two possible approaches:Enum / trait abstraction: Make
SurrogateProcessan enum (ordyn Trait) with two variants — one backed by a real surrogate process (WHvMapGpaRange2) and one that maps from the host process directly (WHvMapGpaRange). TheNoSurrogateGuardcould be folded into the no-surrogate variant.Always use
WHvMapGpaRange2: Use the current process handle as the source when surrogates are disabled, eliminating the branch entirely. This needs validation — it's unclear whetherWHvMapGpaRange2withGetCurrentProcess()is a supported pattern.Either way, the mapping call would move into the surrogate module so
whp.rsjust calls a singlemap(...)method.Origin
Suggestion from @syntactically in PR #1578 review.