guminterceptor: add alt stack support#826
Conversation
|
One question I have is how best to test this in CI. Locally I changed the default value the stack size to enable the alternate stack switching and I observed the tests passing. Ideally we could run the interceptor suite twice -- once on the local stack and once on the switched stack. Any pointers on how best to do this would be great. |
| // Switch to the new stack and call the function with arguments | ||
| asm volatile ( | ||
| "movq %%rsp, %%rbx\n" // Save the current stack pointer | ||
| "movq %0, %%rsp\n" // Set the new stack pointer |
There was a problem hiding this comment.
I suppose this may be too late in some cases, as we've already used quite some stack space for saving registers?
| } | ||
|
|
||
| static InterceptorThreadContext * | ||
| get_interceptor_thread_context (void) |
There was a problem hiding this comment.
This is incorrect; in C (unlike C++), (void) means "no arguments", whereas () means "0 or more arguments".
| GumInterceptorLockedFunc func, gpointer user_data); | ||
| GUM_API gboolean gum_interceptor_is_locked (GumInterceptor * self); | ||
|
|
||
| // Configure the alternate stack for the interceptor. The alternate stack is |
There was a problem hiding this comment.
Style nitpick: Only C-style comments should be used.
| context->stack = g_array_sized_new (FALSE, TRUE, | ||
| sizeof (GumInvocationStackEntry), GUM_MAX_CALL_DEPTH); | ||
|
|
||
|
|
There was a problem hiding this comment.
Style nitpick: For consistency, two or more consecutive blank lines shouldn't be used.
| }; | ||
|
|
||
| static InterceptorThreadContext * | ||
| interceptor_thread_context_new (void) |
| # define GUM_INTERCEPTOR_CODE_SLICE_SIZE 256 | ||
| #endif | ||
|
|
||
| #if defined(__x86_64__) |
There was a problem hiding this comment.
| #if defined(__x86_64__) | |
| #if defined (HAVE_I386) && GLIB_SIZEOF_VOID_P == 8 |
(For consistency.)
Should also check that GCC or Clang is used, as MSVC doesn't support the inline assembly syntax.
This commit adds a new public API to gum to configure the size of an alternate stack to use for hooking. If the configuration is set, then when an interceptor is triggered, it will switch to this stack after the trampoline but before executing the handler. This is needed to support go or programs which do not have large and mutable thread stacks. One note is that only x86_64 support has initially been added, and that it only applies for entry invocation listeners. Exit invocation listeners are not supported because they still would not work with go out-of-the-box because go doesn't like junk being added to call stacks.
57d7b99 to
0c7bc6c
Compare
This commit adds a new public API to gum to configure the size of an alternate stack to use for hooking. If the configuration is set, then when an interceptor is triggered, it will switch to this stack after the trampoline but before executing the handler. This is needed to support go or programs which do not have large and mutable thread stacks.
One note is that only x86_64 support has initially been added, and that it only applies for entry invocation listeners. Exit invocation listeners are not supported because they still would not work with go out-of-the-box because go doesn't like junk being added to call stacks.