Skip to content

ntdll: Make syscall dispatcher properly restore X16 and X17 in ARM64.

Jinoh Kang requested to merge fix/ntdll/arm64-NtContinue-x16-x17-clobbered into master

Today, NtContinue() on ARM64 does not restore X16 and X17 from the context.

This is because they are used as scratch registers for restoring SP and PC in __wine_syscall_dispatcher. Scratch registers are required because they cannot be loaded directly from memory or other architectural state.

Fix this by changing ARM64 __wine_syscall_dispatcher to perform a full context restore when NtContinue() is used. This is achieved by splitting the ARM64 syscall dispatcher's returning behaviour into a fast path and a slow path.

  • If CONTEXT_INTEGER is not set, the dispatcher takes the fast path: the X16 and X17 registers are clobbered as usual.

  • If X16 == PC and X17 == SP, the dispatcher also takes the fast path: it can safely use X16 and X17 without corrupting the register values, since those two registers already have the desired values.

    This fast path is used in call_user_apc_dispatcher(), call_user_exception_dispatcher(), and call_init_thunk().

  • Otherwise, the dispatcher takes the slow path: it raises SIGUSR2 and does full context restore in the signal handler.

Fixes: 88e33621

Merge request reports

Loading