This is an archive of the discontinued LLVM Phabricator instance.

[GWP-ASan] Move random-related code in the allocator
ClosedPublic

Authored by cryptoad on Oct 21 2020, 1:04 PM.

Details

Summary

We need to have all thread specific data packed into a single uint64_t
for the upcoming Fuchsia support. We can move the RandomState into the
ThreadLocalPackedVariables, reducing the size of NextSampleCounter
to 31 bits (or we could reduce RandomState to 31 bits).

We move getRandomUnsigned32 into the platform agnostic part of the
class, and initPRNG in the platform specific part.

ScopedBoolean is replaced by actual assignments since non-const
references to bitfields are prohibited.

random.{h,cpp} are removed.

Diff Detail

Event Timeline

cryptoad created this revision.Oct 21 2020, 1:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2020, 1:04 PM
Herald added subscribers: Restricted Project, mgorny. · View Herald Transcript
cryptoad requested review of this revision.Oct 21 2020, 1:04 PM
cryptoad updated this revision to Diff 299806.Oct 21 2020, 2:31 PM
  • Update options check to account for 31 bits.
  • Use an initializer for RandomState that yield 0xffffffff on first XorShift iteration.
cryptoad edited the summary of this revision. (Show Details)Oct 21 2020, 2:31 PM
cryptoad added reviewers: hctim, eugenis, mcgrathr.
cryptoad added a subscriber: llvm-commits.
cryptoad updated this revision to Diff 299817.Oct 21 2020, 3:27 PM
  • Restoring the old constants because some test failed with mine.
hctim added inline comments.Oct 22 2020, 9:34 AM
compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
150–151

While we're here, can you also add ThreadLocals.NextSampleCounter = AdjustedSampleRatePlusOne - 1; to keep on the slow path for 2^31 more allocations after 2^31 have been done?

160

I'd prefer if this could be a private class like ScopedRecursiveGuard inside GPA where the c'tor sets ThreadLocals.RecursiveGuard = true; and the d'tor sets ThreadLocals.RecursiveGuard = false;.

281

Originally the goal was to keep this PRNG as platform-specific implementation and just provide xorshift as a default (so if someone wanted their own proper PRNG they could provide it). After thinking, this is fine anyway, as if we want to provide platform-specific sampling then we want to allow other methods like 1-in-N-bytes and so will need a refactor anyway.

compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
222

nit: Seeded using platform-specific mechanisms by initPRNG().

cryptoad updated this revision to Diff 300025.Oct 22 2020, 10:01 AM
cryptoad marked 3 inline comments as done.

Addressing review comments.

hctim accepted this revision.Oct 22 2020, 10:08 AM

LGTM!

This revision is now accepted and ready to land.Oct 22 2020, 10:08 AM
This revision was landed with ongoing or failed builds.Oct 22 2020, 11:52 AM
This revision was automatically updated to reflect the committed changes.
nikic added a subscriber: nikic.Oct 22 2020, 1:01 PM

I've reverted this in https://github.com/llvm/llvm-project/commit/04e42f62548d4c0367664188a938b609435718e2 due to a build failure with GCC. The code seems a bit sensitive, so I didn't want to introduce random casts.

I've reverted this in https://github.com/llvm/llvm-project/commit/04e42f62548d4c0367664188a938b609435718e2 due to a build failure with GCC. The code seems a bit sensitive, so I didn't want to introduce random casts.

Thank you, will fix it and reland.

compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp