Date: Thu, 28 Nov 2024 09:38:48 -0800
On Thursday 28 November 2024 05:30:56 Pacific Standard Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> Another useful function:
>
> auto get_return_address(void) -> void (*&)(void);
>
> It returns a reference to where the return address is stored on the
> stack.
And if it isn't on the stack? All architectures except for x86 store it in a
register upon function calling and they don't need to store on the stack if
they are leaf functions. Even then, the compiler has the option of storing it
in a callee-save register instead and spill that one to the stack.
See https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html though
> I think it makes more sense for it to be a reference to a
> pointer, than a pointer to a pointer, because it might be a register
> instead of on the stack (e.g. the Link Register on 64-Bit ARM).
That makes even less sense. How can you have a reference to a register? Why do
you need it to be a reference or a pointer in any case? Are you going to
modify it? That is return-oriented programming and you can't do that, not with
Control Flow Enforcement protections active.
Gotham via Std-Proposals wrote:
> Another useful function:
>
> auto get_return_address(void) -> void (*&)(void);
>
> It returns a reference to where the return address is stored on the
> stack.
And if it isn't on the stack? All architectures except for x86 store it in a
register upon function calling and they don't need to store on the stack if
they are leaf functions. Even then, the compiler has the option of storing it
in a callee-save register instead and spill that one to the stack.
See https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html though
> I think it makes more sense for it to be a reference to a
> pointer, than a pointer to a pointer, because it might be a register
> instead of on the stack (e.g. the Link Register on 64-Bit ARM).
That makes even less sense. How can you have a reference to a register? Why do
you need it to be a reference or a pointer in any case? Are you going to
modify it? That is return-oriented programming and you can't do that, not with
Control Flow Enforcement protections active.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel DCAI Platform & System Engineering
Received on 2024-11-28 17:38:54