C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 26 Jul 2024 07:24:00 -0700
On Friday 26 July 2024 07:15:53 GMT-7 Thiago Macieira via Std-Proposals wrote:
> So you have a problem in the C language. Maybe you should be directing your
> suggestions to WG14.

A more helpful suggestion: write to your compiler. This looks like a valid
use-case using __attribute__ as there are several ones that are very similar,
like __attribute__((interrupt)).

https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-interrupt-function-attribute_002c-x86

This one is nearly everything you need, except that it will likely not do the
tail-call jump and will return with IRET.

Though most likely you don't need to decorate functions like this at all. All
you need is the assembly thunk, which you write only once and change what your
redirector is called. Your redirector does any logging or modification you
need, then returns the tail-call jump pointer. The thunk then restores the ABI
and jumps there.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2024-07-26 14:24:04