Commit a0345a44 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[Memory] Warn on unused result for base/platform memory functions.

- Warn on unused result for OS Allocate, Free, SetPermissions,
  CommitRegion, UncommitRegion functions.
- Adds CHECKS or DCHECK/USE around call sites.

Bug: chromium:756050

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ic00b0a42a1e09bdba013b7fa2b1b4e2b7591bac6
Reviewed-on: https://chromium-review.googlesource.com/769792Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49449}
parent 1438986d
......@@ -185,9 +185,7 @@ void VirtualMemory::Release() {
size_t size = size_;
CHECK(InVM(address, size));
Reset();
bool result = base::OS::Free(address, size);
USE(result);
DCHECK(result);
CHECK(base::OS::Free(address, size));
}
void VirtualMemory::TakeControl(VirtualMemory* from) {
......
......@@ -509,9 +509,7 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
return Free(data, length);
}
case v8::ArrayBuffer::Allocator::AllocationMode::kReservation: {
bool result = base::OS::Free(data, length);
DCHECK(result);
USE(result);
CHECK(base::OS::Free(data, length));
return;
}
}
......@@ -526,7 +524,7 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
(protection == v8::ArrayBuffer::Allocator::Protection::kReadWrite)
? base::OS::MemoryPermission::kReadWrite
: base::OS::MemoryPermission::kNoAccess;
base::OS::SetPermissions(data, length, permission);
CHECK(base::OS::SetPermissions(data, length, permission));
}
};
......
......@@ -170,8 +170,8 @@ MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate,
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<MemCopyUint8Function>(buffer);
#endif
}
......@@ -261,8 +261,8 @@ MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function(
masm.GetCode(isolate, &desc);
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<MemCopyUint16Uint8Function>(buffer);
#endif
}
......@@ -290,8 +290,8 @@ UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#endif
}
......
......@@ -176,7 +176,7 @@ void OS::SignalCodeMovingGC() {
void* addr = mmap(OS::GetRandomMmapAddr(), size, PROT_READ | PROT_EXEC,
MAP_PRIVATE, fileno(f), 0);
DCHECK_NE(MAP_FAILED, addr);
OS::Free(addr, size);
CHECK(Free(addr, size));
fclose(f);
}
......
......@@ -253,14 +253,14 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
if (aligned_base != base) {
DCHECK_LT(base, aligned_base);
size_t prefix_size = static_cast<size_t>(aligned_base - base);
OS::Free(base, prefix_size);
CHECK(Free(base, prefix_size));
request_size -= prefix_size;
}
// Unmap memory allocated after the potentially unaligned end.
if (size != request_size) {
DCHECK_LT(size, request_size);
size_t suffix_size = request_size - size;
OS::Free(aligned_base + size, suffix_size);
CHECK(Free(aligned_base + size, suffix_size));
request_size -= suffix_size;
}
......@@ -427,7 +427,7 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) OS::Free(memory_, size_);
if (memory_) CHECK(OS::Free(memory_, size_));
fclose(file_);
}
......
......@@ -179,24 +179,26 @@ class V8_BASE_EXPORT OS {
// The address parameter is a hint. The size and alignment parameters must be
// multiples of AllocatePageSize(). Returns the address of the allocated
// memory, with the specified size and alignment, or nullptr on failure.
static void* Allocate(void* address, size_t size, size_t alignment,
MemoryPermission access);
V8_WARN_UNUSED_RESULT static void* Allocate(void* address, size_t size,
size_t alignment,
MemoryPermission access);
// Frees memory allocated by a call to Allocate. address and size must be
// multiples of AllocatePageSize(). Returns true on success, otherwise false.
static bool Free(void* address, const size_t size);
V8_WARN_UNUSED_RESULT static bool Free(void* address, const size_t size);
// Sets permissions according to the access argument. address and size must be
// multiples of CommitPageSize(). Returns true on success, otherwise false.
static bool SetPermissions(void* address, size_t size,
MemoryPermission access);
V8_WARN_UNUSED_RESULT static bool SetPermissions(void* address, size_t size,
MemoryPermission access);
static bool CommitRegion(void* address, size_t size);
V8_WARN_UNUSED_RESULT static bool CommitRegion(void* address, size_t size);
static bool UncommitRegion(void* address, size_t size);
V8_WARN_UNUSED_RESULT static bool UncommitRegion(void* address, size_t size);
// Release part of a reserved address range.
static bool ReleasePartialRegion(void* address, size_t size);
V8_WARN_UNUSED_RESULT static bool ReleasePartialRegion(void* address,
size_t size);
static bool HasLazyCommits();
......
......@@ -142,9 +142,7 @@ class ShellArrayBufferAllocator : public ArrayBufferAllocatorBase {
void Free(void* data, size_t length) override {
#if USE_VM
if (RoundToPageSize(&length)) {
bool result = base::OS::Free(data, length);
DCHECK(result);
USE(result);
CHECK(base::OS::Free(data, length));
return;
}
#endif
......
......@@ -443,9 +443,7 @@ void MemoryAllocator::FreeMemory(Address base, size_t size,
code_range()->FreeRawMemory(base, size);
} else {
DCHECK(executable == NOT_EXECUTABLE || !code_range()->valid());
bool result = base::OS::Free(base, size);
USE(result);
DCHECK(result);
CHECK(base::OS::Free(base, size));
}
}
......@@ -541,8 +539,8 @@ void MemoryChunk::SetReadAndExecutable() {
size_t page_size = MemoryAllocator::GetCommitPageSize();
DCHECK(IsAddressAligned(protect_start, page_size));
size_t protect_size = RoundUp(area_size(), page_size);
base::OS::SetPermissions(protect_start, protect_size,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(protect_start, protect_size,
base::OS::MemoryPermission::kReadExecute));
}
}
......@@ -560,8 +558,8 @@ void MemoryChunk::SetReadAndWritable() {
size_t page_size = MemoryAllocator::GetCommitPageSize();
DCHECK(IsAddressAligned(unprotect_start, page_size));
size_t unprotect_size = RoundUp(area_size(), page_size);
base::OS::SetPermissions(unprotect_start, unprotect_size,
base::OS::MemoryPermission::kReadWrite);
CHECK(base::OS::SetPermissions(unprotect_start, unprotect_size,
base::OS::MemoryPermission::kReadWrite));
}
}
......@@ -578,8 +576,9 @@ void MemoryChunk::SetReadWriteAndExecutable() {
size_t page_size = MemoryAllocator::GetCommitPageSize();
DCHECK(IsAddressAligned(unprotect_start, page_size));
size_t unprotect_size = RoundUp(area_size(), page_size);
base::OS::SetPermissions(unprotect_start, unprotect_size,
base::OS::MemoryPermission::kReadWriteExecute);
CHECK(
base::OS::SetPermissions(unprotect_start, unprotect_size,
base::OS::MemoryPermission::kReadWriteExecute));
}
MemoryChunk* MemoryChunk::Initialize(Heap* heap, Address base, size_t size,
......@@ -630,8 +629,9 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap, Address base, size_t size,
size_t page_size = MemoryAllocator::GetCommitPageSize();
DCHECK(IsAddressAligned(area_start, page_size));
size_t area_size = RoundUp(area_end - area_start, page_size);
base::OS::SetPermissions(area_start, area_size,
base::OS::MemoryPermission::kReadWriteExecute);
CHECK(base::OS::SetPermissions(
area_start, area_size,
base::OS::MemoryPermission::kReadWriteExecute));
}
}
......
......@@ -39,8 +39,8 @@ UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
}
......@@ -452,8 +452,8 @@ MemMoveFunction CreateMemMoveFunction(Isolate* isolate) {
masm.GetCode(isolate, &desc);
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
// TODO(jkummerow): It would be nice to register this code creation event
// with the PROFILE / GDBJIT system.
return FUNCTION_CAST<MemMoveFunction>(buffer);
......
......@@ -545,8 +545,8 @@ MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate,
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<MemCopyUint8Function>(buffer);
#endif
}
......@@ -574,8 +574,8 @@ UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#endif
}
......
......@@ -546,8 +546,8 @@ MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate,
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<MemCopyUint8Function>(buffer);
#endif
}
......@@ -575,8 +575,8 @@ UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#endif
}
......
......@@ -41,8 +41,8 @@ UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#endif
}
......
......@@ -38,8 +38,8 @@ UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#endif
}
......
......@@ -32,8 +32,8 @@ UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
Assembler::FlushICache(isolate, buffer, allocated);
base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute);
CHECK(base::OS::SetPermissions(buffer, allocated,
base::OS::MemoryPermission::kReadExecute));
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment