Bug 784739 - Switch from NULL to nullptr in mozglue/linker/; r=ehsan

This commit is contained in:
Birunthan Mohanathas 2013-11-11 14:15:46 -05:00
parent e8e1ec6dec
commit 866c961b74
9 changed files with 137 additions and 131 deletions

View File

@ -28,7 +28,7 @@ extern "C" {
const Ehdr *Ehdr::validate(const void *buf)
{
if (!buf || buf == MAP_FAILED)
return NULL;
return nullptr;
const Ehdr *ehdr = reinterpret_cast<const Ehdr *>(buf);
@ -45,7 +45,7 @@ const Ehdr *Ehdr::validate(const void *buf)
ehdr->e_machine != ELFMACHINE ||
ehdr->e_version != 1 ||
ehdr->e_phentsize != sizeof(Phdr))
return NULL;
return nullptr;
return ehdr;
}
@ -74,7 +74,7 @@ class Mappable1stPagePtr: public GenericMappedPtr<Mappable1stPagePtr> {
public:
Mappable1stPagePtr(Mappable *mappable)
: GenericMappedPtr<Mappable1stPagePtr>(
mappable->mmap(NULL, PageSize(), PROT_READ, MAP_PRIVATE, 0))
mappable->mmap(nullptr, PageSize(), PROT_READ, MAP_PRIVATE, 0))
, mappable(mappable)
{
/* Ensure the content of this page */
@ -96,30 +96,30 @@ CustomElf::Load(Mappable *mappable, const char *path, int flags)
{
DEBUG_LOG("CustomElf::Load(\"%s\", 0x%x) = ...", path, flags);
if (!mappable)
return NULL;
return nullptr;
/* Keeping a RefPtr of the CustomElf is going to free the appropriate
* resources when returning NULL */
* resources when returning nullptr */
RefPtr<CustomElf> elf = new CustomElf(mappable, path);
/* Map the first page of the Elf object to access Elf and program headers */
Mappable1stPagePtr ehdr_raw(mappable);
if (ehdr_raw == MAP_FAILED)
return NULL;
return nullptr;
const Ehdr *ehdr = Ehdr::validate(ehdr_raw);
if (!ehdr)
return NULL;
return nullptr;
/* Scan Elf Program Headers and gather some information about them */
std::vector<const Phdr *> pt_loads;
Addr min_vaddr = (Addr) -1; // We want to find the lowest and biggest
Addr max_vaddr = 0; // virtual address used by this Elf.
const Phdr *dyn = NULL;
const Phdr *dyn = nullptr;
const Phdr *first_phdr = reinterpret_cast<const Phdr *>(
reinterpret_cast<const char *>(ehdr) + ehdr->e_phoff);
const Phdr *end_phdr = &first_phdr[ehdr->e_phnum];
#ifdef __ARM_EABI__
const Phdr *arm_exidx_phdr = NULL;
const Phdr *arm_exidx_phdr = nullptr;
#endif
for (const Phdr *phdr = first_phdr; phdr < end_phdr; phdr++) {
@ -138,14 +138,14 @@ CustomElf::Load(Mappable *mappable, const char *path, int flags)
dyn = phdr;
} else {
LOG("%s: Multiple PT_DYNAMIC segments detected", elf->GetPath());
return NULL;
return nullptr;
}
break;
case PT_TLS:
debug_phdr("PT_TLS", phdr);
if (phdr->p_memsz) {
LOG("%s: TLS is not supported", elf->GetPath());
return NULL;
return nullptr;
}
break;
case PT_GNU_STACK:
@ -154,7 +154,7 @@ CustomElf::Load(Mappable *mappable, const char *path, int flags)
#ifndef ANDROID
if (phdr->p_flags & PF_X) {
LOG("%s: Executable stack is not supported", elf->GetPath());
return NULL;
return nullptr;
}
#endif
break;
@ -174,11 +174,11 @@ CustomElf::Load(Mappable *mappable, const char *path, int flags)
if (min_vaddr != 0) {
LOG("%s: Unsupported minimal virtual address: 0x%08" PRIxAddr,
elf->GetPath(), min_vaddr);
return NULL;
return nullptr;
}
if (!dyn) {
LOG("%s: No PT_DYNAMIC segment found", elf->GetPath());
return NULL;
return nullptr;
}
/* Reserve enough memory to map the complete virtual address space for this
@ -191,20 +191,20 @@ CustomElf::Load(Mappable *mappable, const char *path, int flags)
* that we'll be able to use with MAP_FIXED, and then remap MAP_PRIVATE at
* the same address, because of some bad side effects of keeping it as
* MAP_SHARED. */
elf->base.Assign(MemoryRange::mmap(NULL, max_vaddr, PROT_NONE,
elf->base.Assign(MemoryRange::mmap(nullptr, max_vaddr, PROT_NONE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0));
if ((elf->base == MAP_FAILED) ||
(mmap(elf->base, max_vaddr, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) != elf->base)) {
LOG("%s: Failed to mmap", elf->GetPath());
return NULL;
return nullptr;
}
/* Load and initialize library */
for (std::vector<const Phdr *>::iterator it = pt_loads.begin();
it < pt_loads.end(); ++it)
if (!elf->LoadSegment(*it))
return NULL;
return nullptr;
/* We're not going to mmap anymore */
mappable->finalize();
@ -218,7 +218,7 @@ CustomElf::Load(Mappable *mappable, const char *path, int flags)
ElfLoader::Singleton.Register(elf);
if (!elf->InitDyn(dyn))
return NULL;
return nullptr;
#ifdef __ARM_EABI__
if (arm_exidx_phdr)
@ -275,7 +275,7 @@ void *
CustomElf::GetSymbolPtr(const char *symbol, unsigned long hash) const
{
const Sym *sym = GetSymbol(symbol, hash);
void *ptr = NULL;
void *ptr = nullptr;
if (sym && sym->st_shndx != SHN_UNDEF)
ptr = GetPtr(sym->st_value);
DEBUG_LOG("CustomElf::GetSymbolPtr(%p [\"%s\"], \"%s\") = %p",
@ -352,7 +352,7 @@ CustomElf::GetSymbolPtrInDeps(const char *symbol) const
if (sym)
return sym;
}
return NULL;
return nullptr;
}
const Sym *
@ -372,7 +372,7 @@ CustomElf::GetSymbol(const char *symbol, unsigned long hash) const
continue;
return &symtab[y];
}
return NULL;
return nullptr;
}
bool
@ -390,7 +390,7 @@ CustomElf::FindExidx(int *pcount) const
return arm_exidx;
}
*pcount = 0;
return NULL;
return nullptr;
}
#endif
@ -671,7 +671,7 @@ CustomElf::Relocate()
{
DEBUG_LOG("Relocate %s @%p", GetPath(), static_cast<void *>(base));
uint32_t symtab_index = (uint32_t) -1;
void *symptr = NULL;
void *symptr = nullptr;
for (Array<Reloc>::iterator rel = relocations.begin();
rel < relocations.end(); ++rel) {
/* Location of the relocation */
@ -690,12 +690,12 @@ CustomElf::Relocate()
if (sym.st_shndx != SHN_UNDEF) {
symptr = GetPtr(sym.st_value);
} else {
/* TODO: handle symbol resolving to NULL vs. being undefined. */
/* TODO: handle symbol resolving to nullptr vs. being undefined. */
symptr = GetSymbolPtrInDeps(strtab.GetStringAt(sym.st_name));
}
}
if (symptr == NULL)
if (symptr == nullptr)
LOG("%s: Warning: relocation to NULL @0x%08" PRIxAddr,
GetPath(), rel->r_offset);
@ -741,7 +741,7 @@ CustomElf::RelocateJumps()
else
symptr = GetSymbolPtrInDeps(strtab.GetStringAt(sym.st_name));
if (symptr == NULL) {
if (symptr == nullptr) {
LOG("%s: %s: relocation to NULL @0x%08" PRIxAddr " for symbol \"%s\"",
GetPath(),
(ELF_ST_BIND(sym.st_info) == STB_WEAK) ? "Warning" : "Error",
@ -790,7 +790,7 @@ Mappable *
CustomElf::GetMappable() const
{
if (!mappable)
return NULL;
return nullptr;
if (mappable->GetKind() == Mappable::MAPPABLE_EXTRACT_FILE)
return mappable;
return ElfLoader::GetMappableFromPath(GetPath());

View File

@ -57,7 +57,7 @@ const char *
__wrap_dlerror(void)
{
const char *error = ElfLoader::Singleton.lastError;
ElfLoader::Singleton.lastError = NULL;
ElfLoader::Singleton.lastError = nullptr;
return error;
}
@ -66,7 +66,7 @@ __wrap_dlsym(void *handle, const char *symbol)
{
if (!handle) {
ElfLoader::Singleton.lastError = "dlsym(NULL, sym) unsupported";
return NULL;
return nullptr;
}
if (handle != RTLD_DEFAULT && handle != RTLD_NEXT) {
LibHandle *h = reinterpret_cast<LibHandle *>(handle);
@ -107,7 +107,7 @@ __wrap_dl_iterate_phdr(dl_phdr_cb callback, void *data)
dl_phdr_info info;
info.dlpi_addr = reinterpret_cast<Elf::Addr>(it->l_addr);
info.dlpi_name = it->l_name;
info.dlpi_phdr = NULL;
info.dlpi_phdr = nullptr;
info.dlpi_phnum = 0;
// Assuming l_addr points to Elf headers (in most cases, this is true),
@ -140,7 +140,7 @@ __wrap___gnu_Unwind_Find_exidx(void *pc, int *pcount)
if (__gnu_Unwind_Find_exidx)
return __gnu_Unwind_Find_exidx(pc, pcount);
*pcount = 0;
return NULL;
return nullptr;
}
#endif
@ -159,7 +159,7 @@ MFBT_API void *
__dl_mmap(void *handle, void *addr, size_t length, off_t offset)
{
if (!handle)
return NULL;
return nullptr;
return reinterpret_cast<LibHandle *>(handle)->MappableMMap(addr, length,
offset);
}
@ -205,7 +205,7 @@ LibHandle::~LibHandle()
const char *
LibHandle::GetName() const
{
return path ? LeafName(path) : NULL;
return path ? LeafName(path) : nullptr;
}
size_t
@ -251,8 +251,8 @@ SystemElf::Load(const char *path, int flags)
/* The Android linker returns a handle when the file name matches an
* already loaded library, even when the full path doesn't exist */
if (path && path[0] == '/' && (access(path, F_OK) == -1)){
DEBUG_LOG("dlopen(\"%s\", 0x%x) = %p", path, flags, (void *)NULL);
return NULL;
DEBUG_LOG("dlopen(\"%s\", 0x%x) = %p", path, flags, (void *)nullptr);
return nullptr;
}
void *handle = dlopen(path, flags);
@ -263,7 +263,7 @@ SystemElf::Load(const char *path, int flags)
ElfLoader::Singleton.Register(elf);
return elf;
}
return NULL;
return nullptr;
}
SystemElf::~SystemElf()
@ -290,7 +290,7 @@ SystemElf::GetMappable() const
{
const char *path = GetPath();
if (!path)
return NULL;
return nullptr;
#ifdef ANDROID
/* On Android, if we don't have the full path, try in /system/lib */
const char *name = LeafName(path);
@ -312,7 +312,7 @@ SystemElf::FindExidx(int *pcount) const
/* TODO: properly implement when ElfLoader::GetHandleByPtr
does return SystemElf handles */
*pcount = 0;
return NULL;
return nullptr;
}
#endif
@ -331,9 +331,9 @@ ElfLoader::Load(const char *path, int flags, LibHandle *parent)
RefPtr<LibHandle> handle;
/* Handle dlopen(NULL) directly. */
/* Handle dlopen(nullptr) directly. */
if (!path) {
handle = SystemElf::Load(NULL, flags);
handle = SystemElf::Load(nullptr, flags);
return handle;
}
@ -352,7 +352,7 @@ ElfLoader::Load(const char *path, int flags, LibHandle *parent)
return *it;
}
char *abs_path = NULL;
char *abs_path = nullptr;
const char *requested_path = path;
/* When the path is not absolute and the library is being loaded for
@ -398,14 +398,14 @@ ElfLoader::GetHandleByPtr(void *addr)
if ((*it)->Contains(addr))
return *it;
}
return NULL;
return nullptr;
}
Mappable *
ElfLoader::GetMappableFromPath(const char *path)
{
const char *name = LeafName(path);
Mappable *mappable = NULL;
Mappable *mappable = nullptr;
RefPtr<Zip> zip;
const char *subpath;
if ((subpath = strchr(path, '!'))) {
@ -557,11 +557,11 @@ ElfLoader::DestructorCaller::Call()
DEBUG_LOG("ElfLoader::DestructorCaller::Call(%p, %p, %p)",
FunctionPtr(destructor), object, dso_handle);
destructor(object);
destructor = NULL;
destructor = nullptr;
}
}
ElfLoader::DebuggerHelper::DebuggerHelper(): dbg(NULL)
ElfLoader::DebuggerHelper::DebuggerHelper(): dbg(nullptr)
{
/* Find ELF auxiliary vectors.
*
@ -572,22 +572,22 @@ ElfLoader::DebuggerHelper::DebuggerHelper(): dbg(NULL)
* argv[1] (likewise)
* ...
* argv[argc - 1] (likewise)
* NULL
* nullptr
* envp[0] (pointer into environment strings defined below)
* envp[1] (likewise)
* ...
* envp[n] (likewise)
* NULL
* nullptr
* ... (more NULLs on some platforms such as Android 4.3)
* auxv[0] (first ELF auxiliary vector)
* auxv[1] (second ELF auxiliary vector)
* ...
* auxv[p] (last ELF auxiliary vector)
* (AT_NULL, NULL)
* (AT_NULL, nullptr)
* padding
* argv strings, separated with '\0'
* environment strings, separated with '\0'
* NULL
* nullptr
*
* What we are after are the auxv values defined by the following struct.
*/
@ -636,7 +636,7 @@ ElfLoader::DebuggerHelper::DebuggerHelper(): dbg(NULL)
* AT_PHNUM, which gives us the the location and size of the ELF program
* headers. */
Array<Elf::Phdr> phdrs;
char *base = NULL;
char *base = nullptr;
while (auxv->type) {
if (auxv->type == AT_PHDR) {
phdrs.Init(reinterpret_cast<Elf::Phdr*>(auxv->value));
@ -810,7 +810,7 @@ ElfLoader::DebuggerHelper::Add(ElfLoader::link_map *map)
return;
dbg->r_state = r_debug::RT_ADD;
dbg->r_brk();
map->l_prev = NULL;
map->l_prev = nullptr;
map->l_next = dbg->r_map;
if (!firstAdded) {
firstAdded = map;
@ -976,7 +976,7 @@ SEGVHandler::SEGVHandler()
return;
/* Get the current segfault signal handler. */
sys_sigaction(SIGSEGV, NULL, &this->action);
sys_sigaction(SIGSEGV, nullptr, &this->action);
/* Some devices don't provide useful information to their SIGSEGV handlers,
* making it impossible for on-demand decompression to work. To check if
@ -991,10 +991,11 @@ SEGVHandler::SEGVHandler()
action.sa_sigaction = &SEGVHandler::test_handler;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO | SA_NODEFER;
action.sa_restorer = NULL;
if (sys_sigaction(SIGSEGV, &action, NULL))
action.sa_restorer = nullptr;
if (sys_sigaction(SIGSEGV, &action, nullptr))
return;
stackPtr.Assign(MemoryRange::mmap(NULL, PageSize(), PROT_READ | PROT_WRITE,
stackPtr.Assign(MemoryRange::mmap(nullptr, PageSize(),
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
if (stackPtr.get() == MAP_FAILED)
return;
@ -1006,17 +1007,18 @@ SEGVHandler::SEGVHandler()
stackPtr.Assign(MAP_FAILED, 0);
if (signalHandlingBroken || signalHandlingSlow) {
/* Restore the original segfault signal handler. */
sys_sigaction(SIGSEGV, &this->action, NULL);
sys_sigaction(SIGSEGV, &this->action, nullptr);
return;
}
/* Setup an alternative stack if the already existing one is not big
* enough, or if there is none. */
if (sigaltstack(NULL, &oldStack) == 0) {
if (sigaltstack(nullptr, &oldStack) == 0) {
if (oldStack.ss_flags == SS_ONSTACK)
oldStack.ss_flags = 0;
if (!oldStack.ss_sp || oldStack.ss_size < stackSize) {
stackPtr.Assign(MemoryRange::mmap(NULL, stackSize, PROT_READ | PROT_WRITE,
stackPtr.Assign(MemoryRange::mmap(nullptr, stackSize,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
if (stackPtr.get() == MAP_FAILED)
return;
@ -1024,7 +1026,7 @@ SEGVHandler::SEGVHandler()
stack.ss_sp = stackPtr;
stack.ss_size = stackSize;
stack.ss_flags = 0;
if (sigaltstack(&stack, NULL) != 0)
if (sigaltstack(&stack, nullptr) != 0)
return;
}
}
@ -1032,17 +1034,17 @@ SEGVHandler::SEGVHandler()
* SEGVHandler's struct sigaction member */
action.sa_sigaction = &SEGVHandler::handler;
action.sa_flags = SA_SIGINFO | SA_NODEFER | SA_ONSTACK;
registeredHandler = !sys_sigaction(SIGSEGV, &action, NULL);
registeredHandler = !sys_sigaction(SIGSEGV, &action, nullptr);
}
SEGVHandler::~SEGVHandler()
{
/* Restore alternative stack for signals */
if (oldStack.ss_flags != SS_ONSTACK)
sigaltstack(&oldStack, NULL);
sigaltstack(&oldStack, nullptr);
/* Restore original signal handler */
if (registeredHandler)
sys_sigaction(SIGSEGV, &this->action, NULL);
sys_sigaction(SIGSEGV, &this->action, nullptr);
}
/* Test handler for a deliberately triggered SIGSEGV that determines whether
@ -1052,7 +1054,8 @@ SEGVHandler::~SEGVHandler()
void SEGVHandler::test_handler(int signum, siginfo_t *info, void *context)
{
SEGVHandler &that = ElfLoader::Singleton;
if (signum != SIGSEGV || info == NULL || info->si_addr != that.stackPtr.get())
if (signum != SIGSEGV ||
info == nullptr || info->si_addr != that.stackPtr.get())
that.signalHandlingBroken = true;
mprotect(that.stackPtr, that.stackPtr.GetLength(), PROT_READ | PROT_WRITE);
TmpData *data = reinterpret_cast<TmpData*>(that.stackPtr.get());
@ -1093,7 +1096,7 @@ void SEGVHandler::handler(int signum, siginfo_t *info, void *context)
} else if (that.action.sa_handler == SIG_DFL) {
DEBUG_LOG("Redispatching to default handler");
/* Reset the handler to the default one, and trigger it. */
sys_sigaction(signum, &that.action, NULL);
sys_sigaction(signum, &that.action, nullptr);
raise(signum);
} else if (that.action.sa_handler != SIG_IGN) {
DEBUG_LOG("Redispatching to registered handler @%p",

View File

@ -96,7 +96,7 @@ public:
* of the leaf name.
*/
LibHandle(const char *path)
: directRefCnt(0), path(path ? strdup(path) : NULL), mappable(NULL) { }
: directRefCnt(0), path(path ? strdup(path) : nullptr), mappable(nullptr) { }
/**
* Destructor.
@ -287,7 +287,7 @@ protected:
*/
void Forget()
{
dlhandle = NULL;
dlhandle = nullptr;
}
private:
@ -381,7 +381,7 @@ public:
* directory containing that parent library for the library to load.
*/
mozilla::TemporaryRef<LibHandle> Load(const char *path, int flags,
LibHandle *parent = NULL);
LibHandle *parent = nullptr);
/**
* Returns the handle of the library containing the given address in
@ -575,7 +575,7 @@ private:
bool operator<(const iterator &other) const
{
if (other.item == NULL)
if (other.item == nullptr)
return item ? true : false;
MOZ_CRASH("DebuggerHelper::iterator::operator< called with something else than DebuggerHelper::end()");
}
@ -589,12 +589,12 @@ private:
iterator begin() const
{
return iterator(dbg ? dbg->r_map : NULL);
return iterator(dbg ? dbg->r_map : nullptr);
}
iterator end() const
{
return iterator(NULL);
return iterator(nullptr);
}
private:

View File

@ -24,7 +24,7 @@ MappableFile::Create(const char *path)
int fd = open(path, O_RDONLY);
if (fd != -1)
return new MappableFile(fd);
return NULL;
return nullptr;
}
MemoryRange
@ -60,7 +60,7 @@ MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
if (!cachePath || !*cachePath) {
LOG("Warning: MOZ_LINKER_EXTRACT is set, but not MOZ_LINKER_CACHE; "
"not extracting");
return NULL;
return nullptr;
}
mozilla::ScopedDeleteArray<char> path;
path = new char[strlen(cachePath) + strlen(name) + 2];
@ -80,21 +80,21 @@ MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
S_IRUSR | S_IWUSR);
if (fd == -1) {
LOG("Couldn't open %s to decompress library", path.get());
return NULL;
return nullptr;
}
AutoUnlinkFile file;
file = path.forget();
if (stream->GetType() == Zip::Stream::DEFLATE) {
if (ftruncate(fd, stream->GetUncompressedSize()) == -1) {
LOG("Couldn't ftruncate %s to decompress library", file.get());
return NULL;
return nullptr;
}
/* Map the temporary file for use as inflate buffer */
MappedPtr buffer(MemoryRange::mmap(NULL, stream->GetUncompressedSize(),
MappedPtr buffer(MemoryRange::mmap(nullptr, stream->GetUncompressedSize(),
PROT_WRITE, MAP_SHARED, fd, 0));
if (buffer == MAP_FAILED) {
LOG("Couldn't map %s to decompress library", file.get());
return NULL;
return nullptr;
}
z_stream zStream = stream->GetZStream(buffer);
@ -102,44 +102,44 @@ MappableExtractFile::Create(const char *name, Zip *zip, Zip::Stream *stream)
/* Decompress */
if (inflateInit2(&zStream, -MAX_WBITS) != Z_OK) {
LOG("inflateInit failed: %s", zStream.msg);
return NULL;
return nullptr;
}
if (inflate(&zStream, Z_FINISH) != Z_STREAM_END) {
LOG("inflate failed: %s", zStream.msg);
return NULL;
return nullptr;
}
if (inflateEnd(&zStream) != Z_OK) {
LOG("inflateEnd failed: %s", zStream.msg);
return NULL;
return nullptr;
}
if (zStream.total_out != stream->GetUncompressedSize()) {
LOG("File not fully uncompressed! %ld / %d", zStream.total_out,
static_cast<unsigned int>(stream->GetUncompressedSize()));
return NULL;
return nullptr;
}
} else if (stream->GetType() == Zip::Stream::STORE) {
SeekableZStream zStream;
if (!zStream.Init(stream->GetBuffer(), stream->GetSize())) {
LOG("Couldn't initialize SeekableZStream for %s", name);
return NULL;
return nullptr;
}
if (ftruncate(fd, zStream.GetUncompressedSize()) == -1) {
LOG("Couldn't ftruncate %s to decompress library", file.get());
return NULL;
return nullptr;
}
MappedPtr buffer(MemoryRange::mmap(NULL, zStream.GetUncompressedSize(),
MappedPtr buffer(MemoryRange::mmap(nullptr, zStream.GetUncompressedSize(),
PROT_WRITE, MAP_SHARED, fd, 0));
if (buffer == MAP_FAILED) {
LOG("Couldn't map %s to decompress library", file.get());
return NULL;
return nullptr;
}
if (!zStream.Decompress(buffer, 0, zStream.GetUncompressedSize())) {
LOG("%s: failed to decompress", name);
return NULL;
return nullptr;
}
} else {
return NULL;
return nullptr;
}
return new MappableExtractFile(fd.forget(), file.forget());
@ -175,12 +175,12 @@ public:
/* On Android, initialize an ashmem region with the given length */
fd = open("/" ASHMEM_NAME_DEF, O_RDWR, 0600);
if (fd == -1)
return NULL;
return nullptr;
char str[ASHMEM_NAME_LEN];
strlcpy(str, name, sizeof(str));
ioctl(fd, ASHMEM_SET_NAME, str);
if (ioctl(fd, ASHMEM_SET_SIZE, length))
return NULL;
return nullptr;
/* The Gecko crash reporter is confused by adjacent memory mappings of
* the same file and chances are we're going to map from the same file
@ -189,7 +189,8 @@ public:
* depending on how mappings grow in the address space.
*/
#if defined(__arm__)
void *buf = ::mmap(NULL, length + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
void *buf = ::mmap(nullptr, length + PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (buf != MAP_FAILED) {
::mmap(AlignedEndPtr(reinterpret_cast<char *>(buf) + length, PAGE_SIZE),
PAGE_SIZE, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
@ -199,7 +200,7 @@ public:
}
#elif defined(__i386__)
size_t anon_mapping_length = length + PAGE_SIZE;
void *buf = ::mmap(NULL, anon_mapping_length, PROT_NONE,
void *buf = ::mmap(nullptr, anon_mapping_length, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf != MAP_FAILED) {
char *first_page = reinterpret_cast<char *>(buf);
@ -210,7 +211,7 @@ public:
if (actual_buf == MAP_FAILED) {
::munmap(buf, anon_mapping_length);
DEBUG_LOG("Fixed allocation of decompression buffer at %p failed", map_page);
return NULL;
return nullptr;
}
DEBUG_LOG("Decompression buffer of size 0x%x in ashmem \"%s\", mapped @%p",
@ -228,18 +229,19 @@ public:
sprintf(path, "/dev/shm/%s.XXXXXX", name);
fd = mkstemp(path);
if (fd == -1)
return NULL;
return nullptr;
unlink(path);
ftruncate(fd, length);
void *buf = ::mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
void *buf = ::mmap(nullptr, length, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (buf != MAP_FAILED) {
DEBUG_LOG("Decompression buffer of size %ld in \"%s\", mapped @%p",
length, path, buf);
return new _MappableBuffer(fd.forget(), buf, length);
}
#endif
return NULL;
return nullptr;
}
void *mmap(const void *addr, size_t length, int prot, int flags, off_t offset)
@ -285,7 +287,7 @@ MappableDeflate::Create(const char *name, Zip *zip, Zip::Stream *stream)
_MappableBuffer *buf = _MappableBuffer::Create(name, stream->GetUncompressedSize());
if (buf)
return new MappableDeflate(buf, zip, stream);
return NULL;
return nullptr;
}
MappableDeflate::MappableDeflate(_MappableBuffer *buf, Zip *zip,
@ -353,9 +355,9 @@ MappableDeflate::finalize()
/* Free zlib internal buffers */
inflateEnd(&zStream);
/* Free decompression buffer */
buffer = NULL;
buffer = nullptr;
/* Remove reference to Zip archive */
zip = NULL;
zip = nullptr;
}
size_t
@ -377,15 +379,15 @@ MappableSeekableZStream::Create(const char *name, Zip *zip,
pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
if (pthread_mutex_init(&mappable->mutex, &recursiveAttr))
return NULL;
return nullptr;
if (!mappable->zStream.Init(stream->GetBuffer(), stream->GetSize()))
return NULL;
return nullptr;
mappable->buffer = _MappableBuffer::Create(name,
mappable->zStream.GetUncompressedSize());
if (!mappable->buffer)
return NULL;
return nullptr;
mappable->chunkAvail = new unsigned char[mappable->zStream.GetChunksNum()];
memset(mappable->chunkAvail, 0, mappable->zStream.GetChunksNum());

View File

@ -256,7 +256,7 @@ SeekableZStream::GetFilter(SeekableZStream::FilterId id)
case BCJ_X86:
return BCJ_X86_filter;
default:
return NULL;
return nullptr;
}
return NULL;
return nullptr;
}

View File

@ -96,7 +96,7 @@ typedef mozilla::Scoped<AutoCloseFDTraits> AutoCloseFD;
struct AutoCloseFILETraits
{
typedef FILE *type;
static FILE *empty() { return NULL; }
static FILE *empty() { return nullptr; }
static void release(FILE *f) { if (f) fclose(f); }
};
typedef mozilla::Scoped<AutoCloseFILETraits> AutoCloseFILE;
@ -317,7 +317,7 @@ private:
*
* This is roughly equivalent to
* const S *a = reinterpret_cast<const S *>(buf);
* const S *b = NULL; b = reinterpret_cast<const S *>(buf);
* const S *b = nullptr; b = reinterpret_cast<const S *>(buf);
*
* An UnsizedArray has no known length, and it's up to the caller to make
* sure the accessed memory is mapped and makes sense.
@ -331,12 +331,12 @@ public:
/**
* Constructors and Initializers
*/
UnsizedArray(): contents(NULL) { }
UnsizedArray(): contents(nullptr) { }
UnsizedArray(const void *buf): contents(reinterpret_cast<const T *>(buf)) { }
void Init(const void *buf)
{
MOZ_ASSERT(contents == NULL);
MOZ_ASSERT(contents == nullptr);
contents = reinterpret_cast<const T *>(buf);
}
@ -358,7 +358,7 @@ public:
*/
operator bool() const
{
return contents != NULL;
return contents != nullptr;
}
private:
const T *contents;
@ -465,7 +465,7 @@ public:
class iterator
{
public:
iterator(): item(NULL) { }
iterator(): item(nullptr) { }
const T &operator *() const
{
@ -526,7 +526,7 @@ public:
class reverse_iterator
{
public:
reverse_iterator(): item(NULL) { }
reverse_iterator(): item(nullptr) { }
const T &operator *() const
{

View File

@ -19,22 +19,22 @@ Zip::Create(const char *filename)
AutoCloseFD fd(open(filename, O_RDONLY));
if (fd == -1) {
LOG("Error opening %s: %s", filename, strerror(errno));
return NULL;
return nullptr;
}
struct stat st;
if (fstat(fd, &st) == -1) {
LOG("Error stating %s: %s", filename, strerror(errno));
return NULL;
return nullptr;
}
size_t size = st.st_size;
if (size <= sizeof(CentralDirectoryEnd)) {
LOG("Error reading %s: too short", filename);
return NULL;
return nullptr;
}
void *mapped = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
void *mapped = mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0);
if (mapped == MAP_FAILED) {
LOG("Error mmapping %s: %s", filename, strerror(errno));
return NULL;
return nullptr;
}
DEBUG_LOG("Mapped %s @%p", filename, mapped);
@ -50,7 +50,7 @@ Zip::Create(const char *filename, void *mapped, size_t size)
// have been found, the zip was invalid.
if (!zip->nextFile && !zip->entries) {
LOG("%s - Invalid zip", filename);
return NULL;
return nullptr;
}
ZipCollection::Singleton.Register(zip);
@ -58,12 +58,12 @@ Zip::Create(const char *filename, void *mapped, size_t size)
}
Zip::Zip(const char *filename, void *mapped, size_t size)
: name(filename ? strdup(filename) : NULL)
: name(filename ? strdup(filename) : nullptr)
, mapped(mapped)
, size(size)
, nextFile(LocalFile::validate(mapped)) // first Local File entry
, nextDir(NULL)
, entries(NULL)
, nextDir(nullptr)
, entries(nullptr)
{
// If the first local file entry couldn't be found (which can happen
// with optimized jars), check the first central directory entry.
@ -149,7 +149,7 @@ Zip::GetStream(const char *path, Zip::Stream *out) const
/* Store the next directory entry */
nextDir = nextDir->GetNext();
nextFile = NULL;
nextFile = nullptr;
return true;
}
@ -159,7 +159,7 @@ Zip::GetFirstEntry() const
if (entries)
return entries;
const CentralDirectoryEnd *end = NULL;
const CentralDirectoryEnd *end = nullptr;
const char *_end = static_cast<const char *>(mapped) + size
- sizeof(CentralDirectoryEnd);
@ -168,7 +168,7 @@ Zip::GetFirstEntry() const
end = CentralDirectoryEnd::validate(_end);
if (!end) {
LOG("%s - Couldn't find end of central directory record", name);
return NULL;
return nullptr;
}
entries = DirectoryEntry::validate(static_cast<const char *>(mapped)

View File

@ -30,7 +30,7 @@ class Zip: public mozilla::AtomicRefCounted<Zip>
{
public:
/**
* Create a Zip instance for the given file name. Returns NULL in case
* Create a Zip instance for the given file name. Returns nullptr in case
* of failure.
*/
static mozilla::TemporaryRef<Zip> Create(const char *filename);
@ -39,7 +39,7 @@ public:
* Create a Zip instance using the given buffer.
*/
static mozilla::TemporaryRef<Zip> Create(void *buffer, size_t size) {
return Create(NULL, buffer, size);
return Create(nullptr, buffer, size);
}
private:
@ -74,7 +74,7 @@ public:
/**
* Constructor
*/
Stream(): compressedBuf(NULL), compressedSize(0), uncompressedSize(0)
Stream(): compressedBuf(nullptr), compressedSize(0), uncompressedSize(0)
, type(STORE) { }
/**
@ -178,7 +178,7 @@ public:
const T *ret = static_cast<const T *>(buf);
if (ret->signature == T::magic)
return ret;
return NULL;
return nullptr;
}
SignedEntity(uint32_t magic): signature(magic) { }

View File

@ -30,8 +30,8 @@ const char *filterName[] = {
/* Maximum supported size for chunkSize */
static const size_t maxChunkSize =
1 << (8 * std::min(sizeof(((SeekableZStreamHeader *)NULL)->chunkSize),
sizeof(((SeekableZStreamHeader *)NULL)->lastChunkSize)) - 1);
1 << (8 * std::min(sizeof(((SeekableZStreamHeader *)nullptr)->chunkSize),
sizeof(((SeekableZStreamHeader *)nullptr)->lastChunkSize)) - 1);
class Buffer: public MappedPtr
{
@ -40,7 +40,7 @@ public:
virtual bool Resize(size_t size)
{
MemoryRange buf = mmap(NULL, size, PROT_READ | PROT_WRITE,
MemoryRange buf = mmap(nullptr, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
if (buf == MAP_FAILED)
return false;
@ -78,7 +78,8 @@ public:
if (ftruncate(fd, size) == -1)
return false;
}
Assign(MemoryRange::mmap(NULL, size, PROT_READ | (writable ? PROT_WRITE : 0),
Assign(MemoryRange::mmap(nullptr, size,
PROT_READ | (writable ? PROT_WRITE : 0),
writable ? MAP_SHARED : MAP_PRIVATE, fd, 0));
return this != MAP_FAILED;
}
@ -273,7 +274,7 @@ int SzipCompress::run(const char *name, Buffer &origBuf,
mozilla::ScopedDeletePtr<Buffer> filteredBuf;
Buffer *origData;
for (SeekableZStream::FilterId f = firstFilter; f < lastFilter; ++f) {
FilteredBuffer *filteredTmp = NULL;
FilteredBuffer *filteredTmp = nullptr;
Buffer tmpBuf;
if (f != SeekableZStream::NONE) {
DEBUG_LOG("Applying filter \"%s\"", filterName[f]);
@ -288,7 +289,7 @@ int SzipCompress::run(const char *name, Buffer &origBuf,
break;
}
DEBUG_LOG("Compressing with no dictionary");
if (do_compress(*origData, tmpBuf, NULL, 0, f) == 0) {
if (do_compress(*origData, tmpBuf, nullptr, 0, f) == 0) {
if (tmpBuf.GetLength() < outBuf.GetLength()) {
outBuf.Fill(tmpBuf);
compressed = true;