xref: /aosp_15_r20/external/cronet/base/memory/nonscannable_memory.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 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_MEMORY_NONSCANNABLE_MEMORY_H_
6 #define BASE_MEMORY_NONSCANNABLE_MEMORY_H_
7 
8 #include <cstddef>
9 
10 #include "base/base_export.h"
11 
12 // This file contains allocation/deallocation functions for memory that doesn't
13 // need to be scanned by PCScan. Such memory should only contain "data" objects,
14 // i.e. objects that don't have pointers/references to other objects. An example
15 // would be strings or socket/IPC/file buffers. Use with caution.
16 namespace base {
17 
18 // Allocate/free non-scannable, but still quarantinable memory.
19 BASE_EXPORT void* AllocNonScannable(size_t size);
20 BASE_EXPORT void FreeNonScannable(void* ptr);
21 
22 // Allocate/free non-scannable and non-quarantinable memory. These functions
23 // behave as normal, *Scan-unaware allocation functions. This can be useful for
24 // allocations that are guaranteed to be safe by the user, i.e. allocations that
25 // cannot be referenced from outside and cannot contain dangling references
26 // themselves.
27 BASE_EXPORT void* AllocNonQuarantinable(size_t size);
28 BASE_EXPORT void FreeNonQuarantinable(void* ptr);
29 
30 // Deleters to be used with std::unique_ptr.
31 struct NonScannableDeleter {
operatorNonScannableDeleter32   void operator()(void* ptr) const { FreeNonScannable(ptr); }
33 };
34 struct NonQuarantinableDeleter {
operatorNonQuarantinableDeleter35   void operator()(void* ptr) const { FreeNonQuarantinable(ptr); }
36 };
37 
38 }  // namespace base
39 
40 #endif  // BASE_MEMORY_NONSCANNABLE_MEMORY_H_
41