Null: Make Increment/DecrementMemoryUsage use uint64_t.
Otherwise on 32-bit platforms, creation of a buffer bigger than the max size_t would overflow the check and no OOM would be produced. Bug: chromium:1099621 Change-Id: I987a338b150d10c0eabc3eb5fb3b815a5c2a5ca2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23960 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
1c9e045024
commit
b231c7fb71
|
@ -209,8 +209,8 @@ namespace dawn_native { namespace null {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Device::IncrementMemoryUsage(size_t bytes) {
|
MaybeError Device::IncrementMemoryUsage(uint64_t bytes) {
|
||||||
static_assert(kMaxMemoryUsage <= std::numeric_limits<size_t>::max() / 2, "");
|
static_assert(kMaxMemoryUsage <= std::numeric_limits<size_t>::max(), "");
|
||||||
if (bytes > kMaxMemoryUsage || mMemoryUsage + bytes > kMaxMemoryUsage) {
|
if (bytes > kMaxMemoryUsage || mMemoryUsage + bytes > kMaxMemoryUsage) {
|
||||||
return DAWN_OUT_OF_MEMORY_ERROR("Out of memory.");
|
return DAWN_OUT_OF_MEMORY_ERROR("Out of memory.");
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ namespace dawn_native { namespace null {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::DecrementMemoryUsage(size_t bytes) {
|
void Device::DecrementMemoryUsage(uint64_t bytes) {
|
||||||
ASSERT(mMemoryUsage >= bytes);
|
ASSERT(mMemoryUsage >= bytes);
|
||||||
mMemoryUsage -= bytes;
|
mMemoryUsage -= bytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,8 +106,8 @@ namespace dawn_native { namespace null {
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) override;
|
uint64_t size) override;
|
||||||
|
|
||||||
MaybeError IncrementMemoryUsage(size_t bytes);
|
MaybeError IncrementMemoryUsage(uint64_t bytes);
|
||||||
void DecrementMemoryUsage(size_t bytes);
|
void DecrementMemoryUsage(uint64_t bytes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using DeviceBase::DeviceBase;
|
using DeviceBase::DeviceBase;
|
||||||
|
@ -147,7 +147,7 @@ namespace dawn_native { namespace null {
|
||||||
|
|
||||||
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
|
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
|
||||||
|
|
||||||
static constexpr size_t kMaxMemoryUsage = 256 * 1024 * 1024;
|
static constexpr uint64_t kMaxMemoryUsage = 256 * 1024 * 1024;
|
||||||
size_t mMemoryUsage = 0;
|
size_t mMemoryUsage = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue