Skip to content

Commit f5d9c0b

Browse files
tsepezcopybara-github
authored andcommitted
Add PA_UNSAFE_BUFFER_USAGE macro to partition alloc.
Mirror what chromium does in the standalone partition alloc file. First step towards removing PA from unsafe_buffers_paths.txt suppression file, and a precursor to catching some unsafe raw ptr indexing as allowed. -- Also add PA_UNSAFE_BUFFERS() and PA_UNSAFE_TODO(). Bug: 435068772 Change-Id: If606654f5ed61b6fae439b2071dea55feecc3943 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6803082 Reviewed-by: Arthur Sonzogni <[email protected]> Reviewed-by: Daniel Cheng <[email protected]> Commit-Queue: Tom Sepez <[email protected]> Cr-Commit-Position: refs/heads/main@{#1495591} NOKEYCHECK=True GitOrigin-RevId: a0517a2258135a1dd2c43073d893001a3d6c992e
1 parent ec5fa71 commit f5d9c0b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/partition_alloc/partition_alloc_base/compiler_specific.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,32 @@ inline constexpr bool AnalyzerAssumeTrue(bool arg) {
480480
#define PA_NOPROFILE
481481
#endif
482482

483+
// Annotates a function or class data member indicating it can lead to
484+
// out-of-bounds accesses (OOB) if given incorrect inputs.
485+
#if PA_HAS_CPP_ATTRIBUTE(clang::unsafe_buffer_usage)
486+
#define PA_UNSAFE_BUFFER_USAGE [[clang::unsafe_buffer_usage]]
487+
#else
488+
#define PA_UNSAFE_BUFFER_USAGE
489+
#endif
490+
491+
// Annotates code indicating that it should be permanently exempted from
492+
// `-Wunsafe-buffer-usage`. For temporary cases such as migrating callers to
493+
// safer patterns, use `UNSAFE_TODO()` instead;
494+
#if defined(__clang__)
495+
// Disabling `clang-format` allows each `_Pragma` to be on its own line, as
496+
// recommended by https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html.
497+
// clang-format off
498+
#define PA_UNSAFE_BUFFERS(...) \
499+
_Pragma("clang unsafe_buffer_usage begin") \
500+
__VA_ARGS__ \
501+
_Pragma("clang unsafe_buffer_usage end")
502+
// clang-format on
503+
#else
504+
#define PA_UNSAFE_BUFFERS(...) __VA_ARGS__
505+
#endif
506+
507+
// Annotates code indicating that it should be temporarily exempted from
508+
// `-Wunsafe-buffer-usage`.
509+
#define PA_UNSAFE_TODO(...) PA_UNSAFE_BUFFERS(__VA_ARGS__)
510+
483511
#endif // PARTITION_ALLOC_PARTITION_ALLOC_BASE_COMPILER_SPECIFIC_H_

0 commit comments

Comments
 (0)