1 // Copyright 2022 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 PARTITION_ALLOC_POINTERS_RAW_PTR_EXCLUSION_H_
6 #define PARTITION_ALLOC_POINTERS_RAW_PTR_EXCLUSION_H_
7 
8 // This header will be leakily included even when
9 // `!use_partition_alloc`, which is okay because it's a leaf header.
10 #include "build/build_config.h"
11 #include "partition_alloc/partition_alloc_base/compiler_specific.h"  // nogncheck
12 #include "partition_alloc/partition_alloc_buildflags.h"
13 
14 #if PA_HAS_ATTRIBUTE(annotate)
15 #if defined(OFFICIAL_BUILD) && !BUILDFLAG(FORCE_ENABLE_RAW_PTR_EXCLUSION)
16 // The annotation changed compiler output and increased binary size so disable
17 // for official builds.
18 // TODO(crbug.com/1320670): Remove when issue is resolved.
19 #define RAW_PTR_EXCLUSION
20 #else
21 // Marks a field as excluded from the `raw_ptr<T>` usage enforcement via
22 // Chromium Clang plugin.
23 //
24 // Example:
25 //     RAW_PTR_EXCLUSION Foo* foo_;
26 //
27 // `RAW_PTR_EXCLUSION` should be avoided, as exclusions makes it significantly
28 // easier for any bug involving the pointer to become a security vulnerability.
29 // For additional guidance please see the "When to use raw_ptr<T>" section of
30 // `//base/memory/raw_ptr.md`.
31 #define RAW_PTR_EXCLUSION __attribute__((annotate("raw_ptr_exclusion")))
32 #endif
33 #else
34 #define RAW_PTR_EXCLUSION
35 #endif
36 
37 #endif  // PARTITION_ALLOC_POINTERS_RAW_PTR_EXCLUSION_H_
38