1 //===-- options.h -----------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef SCUDO_OPTIONS_H_
10 #define SCUDO_OPTIONS_H_
12 #include "atomic_helpers.h"
18 enum class OptionBit
{
24 TrackAllocationStacks
,
27 AddLargeAllocationSlack
,
33 bool get(OptionBit Opt
) const { return Val
& (1U << static_cast<u32
>(Opt
)); }
35 FillContentsMode
getFillContentsMode() const {
36 return static_cast<FillContentsMode
>(
37 (Val
>> static_cast<u32
>(OptionBit::FillContents0of2
)) & 3);
41 template <typename Config
> bool useMemoryTagging(const Options
&Options
) {
42 return allocatorSupportsMemoryTagging
<Config
>() &&
43 Options
.get(OptionBit::UseMemoryTagging
);
46 struct AtomicOptions
{
49 Options
load() const { return Options
{atomic_load_relaxed(&Val
)}; }
51 void clear(OptionBit Opt
) {
52 atomic_fetch_and(&Val
, ~(1U << static_cast<u32
>(Opt
)),
53 memory_order_relaxed
);
56 void set(OptionBit Opt
) {
57 atomic_fetch_or(&Val
, 1U << static_cast<u32
>(Opt
), memory_order_relaxed
);
60 void setFillContentsMode(FillContentsMode FillContents
) {
61 u32 Opts
= atomic_load_relaxed(&Val
), NewOpts
;
64 NewOpts
&= ~(3U << static_cast<u32
>(OptionBit::FillContents0of2
));
65 NewOpts
|= static_cast<u32
>(FillContents
)
66 << static_cast<u32
>(OptionBit::FillContents0of2
);
67 } while (!atomic_compare_exchange_strong(&Val
, &Opts
, NewOpts
,
68 memory_order_relaxed
));
74 #endif // SCUDO_OPTIONS_H_