Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work-around an issue in Arm64 regarding the isolated use of CONTEXT_CONTROL. #313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,35 +1837,40 @@ LONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer)
}
}

// Update any suspended threads.
for (t = s_pPendingThreads; t != NULL; t = t->pNext) {
CONTEXT cxt;
cxt.ContextFlags = CONTEXT_CONTROL;

#undef DETOURS_EIP
#undef DETOURS_CONTEXT_FLAGS

#ifdef DETOURS_X86
#define DETOURS_EIP Eip
#define DETOURS_CONTEXT_FLAGS CONTEXT_CONTROL
#endif // DETOURS_X86

#ifdef DETOURS_X64
#define DETOURS_EIP Rip
#define DETOURS_CONTEXT_FLAGS (CONTEXT_CONTROL | CONTEXT_INTEGER)
Copy link
Member

@jaykrell jaykrell Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we "just" use this consistently for all architectures?
i.e. also x86?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment explaining it? I realize there is git blame and PRs. Some orgs are super comment heavy these days and want everything explained on every line. I realize Detours is not that org.

#endif // DETOURS_X64

#ifdef DETOURS_IA64
#define DETOURS_EIP StIIP
#define DETOURS_CONTEXT_FLAGS CONTEXT_CONTROL
#endif // DETOURS_IA64

#ifdef DETOURS_ARM
#define DETOURS_EIP Pc
#define DETOURS_CONTEXT_FLAGS CONTEXT_CONTROL
#endif // DETOURS_ARM

#ifdef DETOURS_ARM64
#define DETOURS_EIP Pc
#define DETOURS_CONTEXT_FLAGS (CONTEXT_CONTROL | CONTEXT_INTEGER)
#endif // DETOURS_ARM64

typedef ULONG_PTR DETOURS_EIP_TYPE;

// Update any suspended threads.
for (t = s_pPendingThreads; t != NULL; t = t->pNext) {
CONTEXT cxt;
cxt.ContextFlags = DETOURS_CONTEXT_FLAGS;
if (GetThreadContext(t->hThread, &cxt)) {
for (o = s_pPendingOperations; o != NULL; o = o->pNext) {
if (o->fIsRemove) {
Expand Down