The bytemap classes will be used by the primary32 allocator to associate
classes with memory regions. It's similar to the sanitizer_common one
except for the fact that the base (level1) maps are mapped instead of
being static to reduce the memory footprint of an uninitialized allocator.
Details
Diff Detail
- Repository
- rCRT Compiler Runtime
Event Timeline
lib/scudo/standalone/bytemap.h | ||
---|---|---|
23 | With this I followed the way it was done in sanitizer_common with an init function that would skip the zero initialization if not needed (most our structures are either mapped or static). Would you have an example of what you are suggesting, I am not sure I fully understand how to organize it? |
lib/scudo/standalone/bytemap.h | ||
---|---|---|
23 | Essentially, make the zero-initialization explicit in the constexpr constructor, and then do all dynamic initialization in init. class FlatByteMap { constexpr FlatByteMap() : Map(nullptr) {} void init() { Map = reinterpret_cast<u8 *>(map(nullptr, Size, "scudo:bytemap")); } }; class TwoLevelByteMap { constexpr TwoLevelByteMap() : Level1Map(nullptr), Mutex{} {} void init() { Level1Map = reinterpret_cast<atomic_uptr *>( map(nullptr, sizeof(atomic_uptr) * Level1Size, "scudo:bytemap")); } }; The constexpr constructor will initialize any statics / globals at compile time while still working at runtime for non-static instantiations. Then the call to init completes any dynamic initialization required. |
lib/scudo/standalone/bytemap.h | ||
---|---|---|
23 | The linker-init function will work fine, but since we're reimplementing much of sanitizer_common for Scudo now, maybe it's a good opportunity to modernize a bit. |
lib/scudo/standalone/bytemap.h | ||
---|---|---|
23 | You'll probably also need to refactor StaticSpinMutex to use a constexpr constructor for initialization. In fact, we could probably completely remove StaticSpinMutex and just give SpinMutex a constexpr constructor. class SpinMutex { constexpr SpinMutex() : State{} {} }; Then SpinMutex can be used as either global or local. |
lib/scudo/standalone/bytemap.h | ||
---|---|---|
23 | I went into the rabbit hole of changing those and started hitting issues along the way (with __thread). |
lib/scudo/standalone/bytemap.h | ||
---|---|---|
23 | SGTM |
Having two init functions is a little confusing. Would it make more sense to have a constexpr constructor and a single init() function?