mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 10:25:28 +00:00
Use a common helper for std::nothrow
It's come up multiple times that ASAN doesn't support std::nothrow which leads to OOM bugs filed by the fuzzers. Use a common helper to avoid this and return nullptr for large allocations when ASAN is enabled. Bug: none Change-Id: I492b4ff4e498cf82d4ca08ba849671d3d16b9cfb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/36280 Reviewed-by: Jiawei Shao <jiawei.shao@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
c120b02dbe
commit
e3fd026108
32
src/common/Alloc.h
Normal file
32
src/common/Alloc.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2020 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef COMMON_ALLOC_H_
|
||||
#define COMMON_ALLOC_H_
|
||||
|
||||
#include <new>
|
||||
|
||||
template <typename T>
|
||||
T* AllocNoThrow(size_t count) {
|
||||
#if defined(ADDRESS_SANITIZER)
|
||||
if (count * sizeof(T) >= 0x70000000) {
|
||||
// std::nothrow isn't implemented on ASAN and it has a 2GB allocation limit.
|
||||
// Catch large allocations and error out so fuzzers make progress.
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
return new (std::nothrow) T[count];
|
||||
}
|
||||
|
||||
#endif // COMMON_ALLOC_H_
|
||||
@@ -152,6 +152,7 @@ config("dawn_internal") {
|
||||
if (is_win || is_linux || is_chromeos || is_mac || is_fuchsia || is_android) {
|
||||
static_library("common") {
|
||||
sources = [
|
||||
"Alloc.h",
|
||||
"Assert.cpp",
|
||||
"Assert.h",
|
||||
"BitSetIterator.h",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
add_library(dawn_common STATIC ${DAWN_DUMMY_FILE})
|
||||
target_sources(dawn_common PRIVATE
|
||||
"Alloc.h"
|
||||
"Assert.cpp"
|
||||
"Assert.h"
|
||||
"BitSetIterator.h"
|
||||
|
||||
Reference in New Issue
Block a user