Skip to content

Commit f74982b

Browse files
pmsjtPedro Justo (TEIXEIRA)
and
Pedro Justo (TEIXEIRA)
authored
Work-around an issue in Arm64 (and Arm64EC) in which LR and FP registers may become zeroed when CONTEXT_CONTROL is used without CONTEXT_INTEGER. (#313)
Co-authored-by: Pedro Justo (TEIXEIRA) <[email protected]>
1 parent b2bf32a commit f74982b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/detours.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -1911,35 +1911,40 @@ LONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer)
19111911
}
19121912
}
19131913

1914-
// Update any suspended threads.
1915-
for (t = s_pPendingThreads; t != NULL; t = t->pNext) {
1916-
CONTEXT cxt;
1917-
cxt.ContextFlags = CONTEXT_CONTROL;
1918-
19191914
#undef DETOURS_EIP
1915+
#undef DETOURS_CONTEXT_FLAGS
19201916

19211917
#ifdef DETOURS_X86
19221918
#define DETOURS_EIP Eip
1919+
#define DETOURS_CONTEXT_FLAGS CONTEXT_CONTROL
19231920
#endif // DETOURS_X86
19241921

19251922
#ifdef DETOURS_X64
19261923
#define DETOURS_EIP Rip
1924+
#define DETOURS_CONTEXT_FLAGS (CONTEXT_CONTROL | CONTEXT_INTEGER)
19271925
#endif // DETOURS_X64
19281926

19291927
#ifdef DETOURS_IA64
19301928
#define DETOURS_EIP StIIP
1929+
#define DETOURS_CONTEXT_FLAGS CONTEXT_CONTROL
19311930
#endif // DETOURS_IA64
19321931

19331932
#ifdef DETOURS_ARM
19341933
#define DETOURS_EIP Pc
1934+
#define DETOURS_CONTEXT_FLAGS CONTEXT_CONTROL
19351935
#endif // DETOURS_ARM
19361936

19371937
#ifdef DETOURS_ARM64
19381938
#define DETOURS_EIP Pc
1939+
#define DETOURS_CONTEXT_FLAGS (CONTEXT_CONTROL | CONTEXT_INTEGER)
19391940
#endif // DETOURS_ARM64
19401941

19411942
typedef ULONG_PTR DETOURS_EIP_TYPE;
19421943

1944+
// Update any suspended threads.
1945+
for (t = s_pPendingThreads; t != NULL; t = t->pNext) {
1946+
CONTEXT cxt;
1947+
cxt.ContextFlags = DETOURS_CONTEXT_FLAGS;
19431948
if (GetThreadContext(t->hThread, &cxt)) {
19441949
for (o = s_pPendingOperations; o != NULL; o = o->pNext) {
19451950
if (o->fIsRemove) {

0 commit comments

Comments
 (0)