Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #91061
| Newsgroups | comp.lang.c++ |
|---|---|
| Date | 2023-07-13 09:42 -0700 |
| References | <05d2fc9e-088e-41a6-9039-2de1717ba952n@googlegroups.com> <4b5f0bd6-0816-4800-b8bd-adfae203932cn@googlegroups.com> |
| Message-ID | <990646ef-4d2c-411b-8c19-e90cd3eacbfcn@googlegroups.com> (permalink) |
| Subject | Re: Custom stack for function invocation (any signature) |
| From | Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> |
About an hour ago, I wrote:
> Half an hour ago, I posted:
> >
> >
> > // Step 4: Invoke the function
> > " call rax \n" // --- Invoke the function!
> Ah crap, I realised just now that I'm editing the stack here. The return address is pushed onto the stack when I invoke the 'call' instruction. This hasn't caused a malfunction because none of the function arguments are on the stack. The code would malfunction if the target function were to have more than 6 parameters, as the 7th would be pushed onto the stack.
>
> Somehow I need to have a 'jmp' instruction instead of a 'call' instruction here. . .
> and yet somehow have control over where it jumps back to. I need to make a
> change to the caller of the caller.
I have an idea. When the assembler function is entered, the return address is at the top of the stack. So the first thing I will do is copy the return address to a global thread_local variable. Next I will edit the return address at the top of the stack. Then I will change the 'call' to a 'jmp', and then later when it 'ret' back to my own location, I will then jump back to the address that I stored in the thread_local variable.
Furthermore, if the target function returns a very very big struct by value, and therefore pushes a portion of the return value onto the stack, then I can compare the stack pointer before and after the call, something like:
old = get_stack_ptr();
InvokeTargetFunction();
new = get_stack_ptr();
if ( new < old )
{
bytes_to_copy = old - new;
memcpy( original_stack -= bytes_to_copy, custom_stack, bytes_to_copy );
}
I'll try code this when I'm home later.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-13 07:38 -0700
Re: Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-13 08:09 -0700
Re: Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-13 09:42 -0700
Re: Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-13 14:50 -0700
Re: Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-14 02:19 -0700
Re: Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-14 05:01 -0700
Re: Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-14 18:55 -0700
Re: Custom stack for function invocation (any signature) Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-07-15 06:42 -0700
csiph-web