[scudo] Make Options a reference for functions.

Modify all places that use the Options structure to be a const
reference. The underlying structure is a u32 so making it a
reference doesn't really do anything. However, if the structure
changes in the future it already works and avoids future coders
wondering why a structure is being passed by value. This also
makes it clear that the Options should not be modified in those functions.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D156372
This commit is contained in:
Christopher Ferris 2023-07-26 14:29:00 -07:00
parent ae2ebc24e1
commit 867f2d9e5c
3 changed files with 16 additions and 16 deletions

View File

@ -299,7 +299,7 @@ public:
#endif
}
uptr computeOddEvenMaskForPointerMaybe(Options Options, uptr Ptr,
uptr computeOddEvenMaskForPointerMaybe(const Options &Options, uptr Ptr,
uptr ClassId) {
if (!Options.get(OptionBit::UseOddEvenTags))
return 0;
@ -1134,7 +1134,7 @@ private:
reinterpret_cast<uptr>(Ptr) - SizeOrUnusedBytes;
}
void quarantineOrDeallocateChunk(Options Options, void *TaggedPtr,
void quarantineOrDeallocateChunk(const Options &Options, void *TaggedPtr,
Chunk::UnpackedHeader *Header,
uptr Size) NO_THREAD_SAFETY_ANALYSIS {
void *Ptr = getHeaderTaggedPointer(TaggedPtr);
@ -1273,7 +1273,7 @@ private:
storeEndMarker(RoundNewPtr, NewSize, BlockEnd);
}
void storePrimaryAllocationStackMaybe(Options Options, void *Ptr) {
void storePrimaryAllocationStackMaybe(const Options &Options, void *Ptr) {
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
return;
auto *Ptr32 = reinterpret_cast<u32 *>(Ptr);
@ -1305,7 +1305,7 @@ private:
atomic_store_relaxed(&Entry->Ptr, reinterpret_cast<uptr>(Ptr));
}
void storeSecondaryAllocationStackMaybe(Options Options, void *Ptr,
void storeSecondaryAllocationStackMaybe(const Options &Options, void *Ptr,
uptr Size) {
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
return;
@ -1320,8 +1320,8 @@ private:
storeRingBufferEntry(untagPointer(Ptr), Trace, Tid, Size, 0, 0);
}
void storeDeallocationStackMaybe(Options Options, void *Ptr, u8 PrevTag,
uptr Size) {
void storeDeallocationStackMaybe(const Options &Options, void *Ptr,
u8 PrevTag, uptr Size) {
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
return;

View File

@ -38,7 +38,7 @@ struct Options {
}
};
template <typename Config> bool useMemoryTagging(Options Options) {
template <typename Config> bool useMemoryTagging(const Options &Options) {
return allocatorSupportsMemoryTagging<Config>() &&
Options.get(OptionBit::UseMemoryTagging);
}

View File

@ -90,7 +90,7 @@ template <typename Config> class MapAllocatorNoCache {
public:
void init(UNUSED s32 ReleaseToOsInterval) {}
bool retrieve(UNUSED uptr Size, UNUSED CachedBlock &Entry) { return false; }
void store(UNUSED Options Options, LargeBlock::Header *H) { unmap(H); }
void store(UNUSED const Options &Options, LargeBlock::Header *H) { unmap(H); }
bool canCache(UNUSED uptr Size) { return false; }
void disable() {}
void enable() {}
@ -113,7 +113,7 @@ public:
static const uptr MaxUnusedCachePages = 4U;
template <typename Config>
bool mapSecondary(Options Options, uptr CommitBase, uptr CommitSize,
bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
uptr AllocPos, uptr Flags, MemMapT &MemMap) {
Flags |= MAP_RESIZABLE;
Flags |= MAP_ALLOWNOMEM;
@ -179,7 +179,7 @@ public:
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
}
void store(Options Options, LargeBlock::Header *H) EXCLUDES(Mutex) {
void store(const Options &Options, LargeBlock::Header *H) EXCLUDES(Mutex) {
if (!canCache(H->CommitSize))
return unmap(H);
@ -407,11 +407,11 @@ public:
S->link(&Stats);
}
void *allocate(Options Options, uptr Size, uptr AlignmentHint = 0,
void *allocate(const Options &Options, uptr Size, uptr AlignmentHint = 0,
uptr *BlockEnd = nullptr,
FillContentsMode FillContents = NoFill);
void deallocate(Options Options, void *Ptr);
void deallocate(const Options &Options, void *Ptr);
static uptr getBlockEnd(void *Ptr) {
auto *B = LargeBlock::getHeader<Config>(Ptr);
@ -443,7 +443,7 @@ public:
}
}
inline void setHeader(Options Options, CachedBlock &Entry,
inline void setHeader(const Options &Options, CachedBlock &Entry,
LargeBlock::Header *H, bool &Zeroed) {
Zeroed = Entry.Time == 0;
if (useMemoryTagging<Config>(Options)) {
@ -501,8 +501,8 @@ private:
// the committed memory will amount to something close to Size - AlignmentHint
// (pending rounding and headers).
template <typename Config>
void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
uptr *BlockEndPtr,
void *MapAllocator<Config>::allocate(const Options &Options, uptr Size,
uptr Alignment, uptr *BlockEndPtr,
FillContentsMode FillContents) {
if (Options.get(OptionBit::AddLargeAllocationSlack))
Size += 1UL << SCUDO_MIN_ALIGNMENT_LOG;
@ -620,7 +620,7 @@ void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
}
template <typename Config>
void MapAllocator<Config>::deallocate(Options Options, void *Ptr)
void MapAllocator<Config>::deallocate(const Options &Options, void *Ptr)
EXCLUDES(Mutex) {
LargeBlock::Header *H = LargeBlock::getHeader<Config>(Ptr);
const uptr CommitSize = H->CommitSize;