зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1536697
- Fix error handling in base::SharedMemory::Map. r=froydnj
If mmap failed, we'd leave the memory_ member variable set to MAP_FAILED, but everything else in this file checks for nullptr (and only nullptr) to test if the pointer is valid. Also, this removes the debug assertion that the mmap succeeded, to allow writing unit tests where we expect it to fail (e.g., for insufficient permissions). Depends on D26747 Differential Revision: https://phabricator.services.mozilla.com/D26748 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
1ad12afe4e
Коммит
87ae2d99b5
|
@ -290,29 +290,28 @@ bool SharedMemory::Freeze() {
|
|||
|
||||
bool SharedMemory::Map(size_t bytes, void* fixed_address) {
|
||||
if (mapped_file_ == -1) return false;
|
||||
DCHECK(!memory_);
|
||||
|
||||
// Don't use MAP_FIXED when a fixed_address was specified, since that can
|
||||
// replace pages that are alread mapped at that address.
|
||||
memory_ =
|
||||
void* mem =
|
||||
mmap(fixed_address, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
|
||||
MAP_SHARED, mapped_file_, 0);
|
||||
|
||||
bool mmap_succeeded = memory_ != MAP_FAILED;
|
||||
|
||||
DCHECK(mmap_succeeded) << "Call to mmap failed, errno=" << errno;
|
||||
|
||||
if (mmap_succeeded) {
|
||||
if (fixed_address && memory_ != fixed_address) {
|
||||
bool munmap_succeeded = munmap(memory_, bytes) == 0;
|
||||
DCHECK(munmap_succeeded) << "Call to munmap failed, errno=" << errno;
|
||||
memory_ = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
mapped_size_ = bytes;
|
||||
if (mem == MAP_FAILED) {
|
||||
CHROMIUM_LOG(WARNING) << "Call to mmap failed: " << strerror(errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
return mmap_succeeded;
|
||||
if (fixed_address && mem != fixed_address) {
|
||||
bool munmap_succeeded = munmap(mem, bytes) == 0;
|
||||
DCHECK(munmap_succeeded) << "Call to munmap failed, errno=" << errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
memory_ = mem;
|
||||
mapped_size_ = bytes;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedMemory::Unmap() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче