C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Interceptor Function (preserve stack and all registers)

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Wed, 15 Apr 2026 09:12:37 +0200
Why not use a header file? (=declaration) If you create a feature out of it, the compiler could directly use the named arguments. Depending on whether the feature is a language or library feature. But how would the implementation navigate the ABI, if it does not have the function signature? In the best case it is ugly to use, in the worst case, it won't work correctly for some function calls. In any way, it would be error prone, as the use might specify parameter types at the wrong position.   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mi 15.04.2026 00:00 Betreff:Re: [std-proposals] Interceptor Function (preserve stack and all registers) An:std-proposals_at_[hidden]; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; On Tue, Apr 14, 2026 at 6:36 PM Thiago Macieira wrote: > > The first thing anyone is going to ask is to get access to the arguments of the > call, so they can be logged. > > The second is going to be to change the arguments. The main idea of an 'interceptor' is that it's agnostic to the target function's parameters and return type. So if you're asking what the arguments are, well they can be provided if you specify the type, for example:    std::get_arg<double>( 1 ); The above will get the value of xmm2 on x86_64. Of course it won't be perfect if the stack is involved, because if you have many arguments pushed onto the stack, and if you don't know how big the previous stack argument was (e.g. 8 bytes Vs 16 bytes), then you won't know where the Nth argument is on the stack. But yeah you could log it something like:    cout << get_arg<uintptr_t>( 0 ) << get_arg<uintptr_t>( 1 ); << get_arg<uintptr_t>( 2 ); << endl; > > Some x86_64 processors only have SSE, some have AVX-256, and some have > > AVX-512, so at runtime I need to execute the CPUID instruction to find out. > > Or you can use IFUNC and make a call instead. Push the target address onto the > stack and JMP to the saver-redirector-restorer. Not familiar with this . . . let me chat to ChatGPT about it for a while and I'll get back to you. > >         kmovq %k0, 520(%rsp) > >         kmovq %k1, 528(%rsp) > >         kmovq %k2, 536(%rsp) > >         kmovq %k3, 544(%rsp) > >         kmovq %k4, 552(%rsp) > >         kmovq %k5, 560(%rsp) > >         kmovq %k6, 568(%rsp) > >         kmovq %k7, 576(%rsp) > >         jmp .Lpush_done\@ > > Why are you saving the k regs? They are all scratch registers, aren't they? ChatGPT told me they need to be preserved but I'll look into it to confirm. -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-04-15 07:14:05