This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Detach the hooks from Scudo's internal implementation
ClosedPublic

Authored by Chia-hungDuan on Jun 5 2023, 12:21 PM.

Details

Summary

Move the invocation of hooks from Scudo internal to wrapper_c.cpp and
wrapper_c_bionic.cpp respectively. Therefore, Scudo's core algorithm
doesnt need to worry about the reentrant of hooks and leave the caring
of reentrant to the hook users.

Diff Detail

Event Timeline

Chia-hungDuan created this revision.Jun 5 2023, 12:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2023, 12:21 PM
Chia-hungDuan requested review of this revision.Jun 5 2023, 12:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2023, 12:21 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Note, I'll update scudo_hooks_test.cpp later. Now this is more like a RFC for hook users

Chia-hungDuan planned changes to this revision.Jun 5 2023, 12:32 PM
fabio-d added a subscriber: fabio-d.Jun 5 2023, 3:06 PM

Adding some preliminary (minor) notes, as I haven't tested this CL on Fuchsia yet.

compiler-rt/lib/scudo/standalone/wrappers_c.inc
34

Should this pass Product as the second argument?

134

nit: This can be moved after the if below

156

Should the hook report the rounded-up size to avoid changing the current behavior? (on the other hand I'd be surprised if any existing user depends on it)

177

Similarly to above, the current behavior is to call the allocate hook first, then then deallocate hook.

nit: the two NewPtr != ptr checks can be grouped under only one if

Chia-hungDuan marked 4 inline comments as done.

Address review comment.

Still haven't changed the test cases. Will wait the opinion of @chelfi who is
using the hooks and wrote the tests

compiler-rt/lib/scudo/standalone/wrappers_c.inc
156

thanks, the bug from copypasta!

177

Order swapped.

I may prefer single if statement which has less indent.

Chia-hungDuan planned changes to this revision.Jun 5 2023, 3:41 PM
chelfi added a comment.Jun 6 2023, 7:34 AM

Thanks @Chia-hungDuan for looking into this!

Those changes look good to me. Do you also need to change wrappers_cpp.cpp similarly?

Remove scudo_hook_test.cpp and move the hook tests to wrappers_c_test.cpp and wrappers_cpp_test.cpp

Thanks @Chia-hungDuan for looking into this!

Those changes look good to me. Do you also need to change wrappers_cpp.cpp similarly?

Done.

hctim accepted this revision.Jun 12 2023, 10:15 AM

LGTM

This revision is now accepted and ready to land.Jun 12 2023, 10:15 AM
chelfi accepted this revision.Jun 13 2023, 1:28 AM

LGTM, thanks for working on that, @Chia-hungDuan .

I have not tested this patch yet on Fuchsia, but I intend to do so shortly this week.

FYI, @chelfi @fabio-d, I'm planning to submit this change by the end of this week.

cferris accepted this revision.Aug 23 2023, 7:40 PM

That sounds like a good plan.