Skip to content

Commit 867f2d9

Browse files
committed
[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
1 parent ae2ebc2 commit 867f2d9

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

compiler-rt/lib/scudo/standalone/combined.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class Allocator {
299299
#endif
300300
}
301301

302-
uptr computeOddEvenMaskForPointerMaybe(Options Options, uptr Ptr,
302+
uptr computeOddEvenMaskForPointerMaybe(const Options &Options, uptr Ptr,
303303
uptr ClassId) {
304304
if (!Options.get(OptionBit::UseOddEvenTags))
305305
return 0;
@@ -1134,7 +1134,7 @@ class Allocator {
11341134
reinterpret_cast<uptr>(Ptr) - SizeOrUnusedBytes;
11351135
}
11361136

1137-
void quarantineOrDeallocateChunk(Options Options, void *TaggedPtr,
1137+
void quarantineOrDeallocateChunk(const Options &Options, void *TaggedPtr,
11381138
Chunk::UnpackedHeader *Header,
11391139
uptr Size) NO_THREAD_SAFETY_ANALYSIS {
11401140
void *Ptr = getHeaderTaggedPointer(TaggedPtr);
@@ -1273,7 +1273,7 @@ class Allocator {
12731273
storeEndMarker(RoundNewPtr, NewSize, BlockEnd);
12741274
}
12751275

1276-
void storePrimaryAllocationStackMaybe(Options Options, void *Ptr) {
1276+
void storePrimaryAllocationStackMaybe(const Options &Options, void *Ptr) {
12771277
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
12781278
return;
12791279
auto *Ptr32 = reinterpret_cast<u32 *>(Ptr);
@@ -1305,7 +1305,7 @@ class Allocator {
13051305
atomic_store_relaxed(&Entry->Ptr, reinterpret_cast<uptr>(Ptr));
13061306
}
13071307

1308-
void storeSecondaryAllocationStackMaybe(Options Options, void *Ptr,
1308+
void storeSecondaryAllocationStackMaybe(const Options &Options, void *Ptr,
13091309
uptr Size) {
13101310
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
13111311
return;
@@ -1320,8 +1320,8 @@ class Allocator {
13201320
storeRingBufferEntry(untagPointer(Ptr), Trace, Tid, Size, 0, 0);
13211321
}
13221322

1323-
void storeDeallocationStackMaybe(Options Options, void *Ptr, u8 PrevTag,
1324-
uptr Size) {
1323+
void storeDeallocationStackMaybe(const Options &Options, void *Ptr,
1324+
u8 PrevTag, uptr Size) {
13251325
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
13261326
return;
13271327

compiler-rt/lib/scudo/standalone/options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Options {
3838
}
3939
};
4040

41-
template <typename Config> bool useMemoryTagging(Options Options) {
41+
template <typename Config> bool useMemoryTagging(const Options &Options) {
4242
return allocatorSupportsMemoryTagging<Config>() &&
4343
Options.get(OptionBit::UseMemoryTagging);
4444
}

compiler-rt/lib/scudo/standalone/secondary.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ template <typename Config> class MapAllocatorNoCache {
9090
public:
9191
void init(UNUSED s32 ReleaseToOsInterval) {}
9292
bool retrieve(UNUSED uptr Size, UNUSED CachedBlock &Entry) { return false; }
93-
void store(UNUSED Options Options, LargeBlock::Header *H) { unmap(H); }
93+
void store(UNUSED const Options &Options, LargeBlock::Header *H) { unmap(H); }
9494
bool canCache(UNUSED uptr Size) { return false; }
9595
void disable() {}
9696
void enable() {}
@@ -113,7 +113,7 @@ template <typename Config> class MapAllocatorNoCache {
113113
static const uptr MaxUnusedCachePages = 4U;
114114

115115
template <typename Config>
116-
bool mapSecondary(Options Options, uptr CommitBase, uptr CommitSize,
116+
bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
117117
uptr AllocPos, uptr Flags, MemMapT &MemMap) {
118118
Flags |= MAP_RESIZABLE;
119119
Flags |= MAP_ALLOWNOMEM;
@@ -179,7 +179,7 @@ template <typename Config> class MapAllocatorCache {
179179
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
180180
}
181181

182-
void store(Options Options, LargeBlock::Header *H) EXCLUDES(Mutex) {
182+
void store(const Options &Options, LargeBlock::Header *H) EXCLUDES(Mutex) {
183183
if (!canCache(H->CommitSize))
184184
return unmap(H);
185185

@@ -407,11 +407,11 @@ template <typename Config> class MapAllocator {
407407
S->link(&Stats);
408408
}
409409

410-
void *allocate(Options Options, uptr Size, uptr AlignmentHint = 0,
410+
void *allocate(const Options &Options, uptr Size, uptr AlignmentHint = 0,
411411
uptr *BlockEnd = nullptr,
412412
FillContentsMode FillContents = NoFill);
413413

414-
void deallocate(Options Options, void *Ptr);
414+
void deallocate(const Options &Options, void *Ptr);
415415

416416
static uptr getBlockEnd(void *Ptr) {
417417
auto *B = LargeBlock::getHeader<Config>(Ptr);
@@ -443,7 +443,7 @@ template <typename Config> class MapAllocator {
443443
}
444444
}
445445

446-
inline void setHeader(Options Options, CachedBlock &Entry,
446+
inline void setHeader(const Options &Options, CachedBlock &Entry,
447447
LargeBlock::Header *H, bool &Zeroed) {
448448
Zeroed = Entry.Time == 0;
449449
if (useMemoryTagging<Config>(Options)) {
@@ -501,8 +501,8 @@ template <typename Config> class MapAllocator {
501501
// the committed memory will amount to something close to Size - AlignmentHint
502502
// (pending rounding and headers).
503503
template <typename Config>
504-
void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
505-
uptr *BlockEndPtr,
504+
void *MapAllocator<Config>::allocate(const Options &Options, uptr Size,
505+
uptr Alignment, uptr *BlockEndPtr,
506506
FillContentsMode FillContents) {
507507
if (Options.get(OptionBit::AddLargeAllocationSlack))
508508
Size += 1UL << SCUDO_MIN_ALIGNMENT_LOG;
@@ -620,7 +620,7 @@ void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
620620
}
621621

622622
template <typename Config>
623-
void MapAllocator<Config>::deallocate(Options Options, void *Ptr)
623+
void MapAllocator<Config>::deallocate(const Options &Options, void *Ptr)
624624
EXCLUDES(Mutex) {
625625
LargeBlock::Header *H = LargeBlock::getHeader<Config>(Ptr);
626626
const uptr CommitSize = H->CommitSize;

0 commit comments

Comments
 (0)