xref: /aosp_15_r20/external/cronet/base/allocator/dispatcher/memory_tagging.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ALLOCATOR_DISPATCHER_TAGGING_H_
6 #define BASE_ALLOCATOR_DISPATCHER_TAGGING_H_
7 
8 #include "partition_alloc/tagging.h"
9 
10 namespace base::allocator::dispatcher {
11 // The various modes of Arm's MTE extension. The enum values should match their
12 // pendants in partition_alloc::TagViolationReportingMode, otherwise the below
13 // conversion function would involve a translation table or conditional jumps.
14 enum class MTEMode {
15   // Default settings
16   kUndefined,
17   // MTE explicitly disabled.
18   kDisabled,
19   // Precise tag violation reports, higher overhead. Good for unittests
20   // and security critical threads.
21   kSynchronous,
22   // Imprecise tag violation reports (async mode). Lower overhead.
23   kAsynchronous,
24 };
25 
ConvertToMTEMode(partition_alloc::TagViolationReportingMode pa_mte_reporting_mode)26 constexpr MTEMode ConvertToMTEMode(
27     partition_alloc::TagViolationReportingMode pa_mte_reporting_mode) {
28   switch (pa_mte_reporting_mode) {
29     case partition_alloc::TagViolationReportingMode::kUndefined:
30       return MTEMode::kUndefined;
31     case partition_alloc::TagViolationReportingMode::kDisabled:
32       return MTEMode::kDisabled;
33     case partition_alloc::TagViolationReportingMode::kSynchronous:
34       return MTEMode::kSynchronous;
35     case partition_alloc::TagViolationReportingMode::kAsynchronous:
36       return MTEMode::kAsynchronous;
37   }
38 }
39 
40 }  // namespace base::allocator::dispatcher
41 
42 #endif  // BASE_ALLOCATOR_DISPATCHER_TAGGING_H_
43