Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Turn off Address Sanitiser for just one function call

41 views
Skip to first unread message

Frederick Virchanza Gotham

unread,
Jun 17, 2023, 6:39:19 PM6/17/23
to

I'm currently writing a program that decrypts its own machine code at runtime.

The function that writes to the code memory is causing a crash because it's being flagged by Address Sanitizer.

I want to have a way to be able to call any function and to have the choice of disabling address sanitiser for that one invocation of the function (but not for other invocations).

Here's what I've written:

template<typename Lambda>
void NoSanitizeAddress(Lambda &f) __attribute__((__no_sanitize_address__));

template<typename Lambda>
void NoSanitizeAddress(Lambda &f)
{
f();
}

int main(void)
{
NoSanitizeAddress( [](){ SomeFunction(); } );
}

This works fine. I just wonder if there's a better way of doing this though.

Andrey Tarasevich

unread,
Jun 17, 2023, 9:50:54 PM6/17/23
to
On 06/17/23 3:39 PM, Frederick Virchanza Gotham wrote:
>
> Here's what I've written:
>
> template<typename Lambda>
> void NoSanitizeAddress(Lambda &f) __attribute__((__no_sanitize_address__));
>
> template<typename Lambda>
> void NoSanitizeAddress(Lambda &f)
> {
> f();
> }
>
> int main(void)
> {
> NoSanitizeAddress( [](){ SomeFunction(); } );
> }
>
> This works fine. I just wonder if there's a better way of doing this though.

"This works fine"? Really? Lambda expression in C++ is a prvalue. How
did you manage to pass it by an lvalue reference?

Anyhoo, what role does the lambda play here anyway? Why not just

int main(void)
{
NoSanitizeAddress(SomeFunction);
}

?

--
Best regards,
Andrey

Frederick Virchanza Gotham

unread,
Jun 18, 2023, 11:37:35 AM6/18/23
to
On Sunday, June 18, 2023 at 2:50:54 AM UTC+1, Andrey Tarasevich wrote:
>
> "This works fine"? Really? Lambda expression in C++ is a prvalue. How
> did you manage to pass it by an lvalue reference?


I had changed it to "Lambda const &f" before copy-pasting.


> Anyhoo, what role does the lambda play here anyway? Why not just
>
> int main(void)
> {
> NoSanitizeAddress(SomeFunction);
> }


Because it might be more complex:

bool retval;
NoSanitizeAddress( [&argc,argv,&retval](void) -> void { retval = SomeFunc(++argc,argv); } );


0 new messages