Bug 725230 - Enable and fix assertions in linker code. r=tglek
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -76,16 +76,18 @@
#endif
enum StartupEvent {
#define mozilla_StartupTimeline_Event(ev, z) ev,
#include "StartupTimeline.h"
#undef mozilla_StartupTimeline_Event
};
+using namespace mozilla;
+
static uint64_t *sStartupTimeline;
void StartupTimeline_Record(StartupEvent ev, struct timeval *tm)
{
sStartupTimeline[ev] = (((uint64_t)tm->tv_sec * 1000000LL) + (uint64_t)tm->tv_usec);
}
static struct mapping_info * lib_mapping = NULL;
@@ -646,17 +648,17 @@ loadGeckoLibs(const char *apkName)
apk_mtime = status.st_mtime;
#endif
struct timeval t0, t1;
gettimeofday(&t0, 0);
struct rusage usage1;
getrusage(RUSAGE_THREAD, &usage1);
- Zip *zip = new Zip(apkName);
+ RefPtr<Zip> zip = new Zip(apkName);
#ifdef MOZ_CRASHREPORTER
file_ids = (char *)extractBuf("lib.id", zip);
#endif
#ifndef MOZ_OLD_LINKER
char *file = new char[strlen(apkName) + sizeof("!/libxpcom.so")];
sprintf(file, "%s!/libxpcom.so", apkName);
@@ -677,18 +679,16 @@ loadGeckoLibs(const char *apkName)
xul_handle = MOZLOAD("xul");
MOZLOAD("xpcom");
MOZLOAD("nssckbi");
MOZLOAD("freebl3");
MOZLOAD("softokn3");
#undef MOZLOAD
#endif
- delete zip;
-
#ifdef MOZ_CRASHREPORTER
free(file_ids);
file_ids = NULL;
#endif
if (!xul_handle)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libxul!");
@@ -744,17 +744,17 @@ static void loadSQLiteLibs(const char *a
#ifdef MOZ_OLD_LINKER
simple_linker_init();
struct stat status;
if (!stat(apkName, &status))
apk_mtime = status.st_mtime;
#endif
- Zip *zip = new Zip(apkName);
+ RefPtr<Zip> zip = new Zip(apkName);
lib_mapping = (struct mapping_info *)calloc(MAX_MAPPING_INFO, sizeof(*lib_mapping));
#ifdef MOZ_CRASHREPORTER
file_ids = (char *)extractBuf("lib.id", zip);
#endif
#ifndef MOZ_OLD_LINKER
char *file = new char[strlen(apkName) + sizeof("!/libmozsqlite3.so")];
@@ -762,18 +762,16 @@ static void loadSQLiteLibs(const char *a
sqlite_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
delete [] file;
#else
#define MOZLOAD(name) mozload("lib" name ".so", zip)
sqlite_handle = MOZLOAD("mozsqlite3");
#undef MOZLOAD
#endif
- delete zip;
-
#ifdef MOZ_CRASHREPORTER
free(file_ids);
file_ids = NULL;
#endif
if (!sqlite_handle)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libmozsqlite3!");
--- a/mozglue/linker/ElfLoader.cpp
+++ b/mozglue/linker/ElfLoader.cpp
@@ -313,17 +313,16 @@ ElfLoader::~ElfLoader()
if (handles.size()) {
list = handles;
for (LibHandleList::reverse_iterator it = list.rbegin();
it < list.rend(); ++it) {
if ((*it)->IsSystemElf()) {
debug("ElfLoader::~ElfLoader(): Remaining handle for \"%s\" "
"[%d direct refs, %d refs total]", (*it)->GetPath(),
(*it)->DirectRefCount(), (*it)->refCount());
- delete (*it);
} else {
debug("ElfLoader::~ElfLoader(): Unexpected remaining handle for \"%s\" "
"[%d direct refs, %d refs total]", (*it)->GetPath(),
(*it)->DirectRefCount(), (*it)->refCount());
/* Not removing, since it could have references to other libraries,
* destroying them as a side effect, and possibly leaving dangling
* pointers in the handle list we're scanning */
}
--- a/mozglue/linker/ElfLoader.h
+++ b/mozglue/linker/ElfLoader.h
@@ -2,18 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ElfLoader_h
#define ElfLoader_h
#include <vector>
#include <dlfcn.h>
-/* Until RefPtr.h stops using JS_Assert */
-#undef DEBUG
#include "mozilla/RefPtr.h"
#include "Zip.h"
/**
* dlfcn.h replacement functions
*/
extern "C" {
void *__wrap_dlopen(const char *path, int flags);
@@ -93,17 +91,17 @@ public:
/**
* Releases a direct reference, and returns whether there are any direct
* references left.
*/
bool ReleaseDirectRef()
{
bool ret = false;
if (directRefCnt) {
- // ASSERT(directRefCnt >= mozilla::RefCounted<LibHandle>::refCount())
+ MOZ_ASSERT(directRefCnt <= mozilla::RefCounted<LibHandle>::refCount());
if (--directRefCnt)
ret = true;
mozilla::RefCounted<LibHandle>::Release();
}
return ret;
}
/**
--- a/mozglue/linker/Mappable.cpp
+++ b/mozglue/linker/Mappable.cpp
@@ -30,18 +30,18 @@ MappableFile *MappableFile::Create(const
return new MappableFile(fd);
return NULL;
}
void *
MappableFile::mmap(const void *addr, size_t length, int prot, int flags,
off_t offset)
{
- // ASSERT(fd != -1)
- // ASSERT(! flags & MAP_SHARED)
+ MOZ_ASSERT(fd != -1);
+ MOZ_ASSERT(!(flags & MAP_SHARED));
flags |= MAP_PRIVATE;
void *mapped = ::mmap(const_cast<void *>(addr), length, prot, flags,
fd, offset);
if (mapped == MAP_FAILED)
return mapped;
/* Fill the remainder of the last page with zeroes when the requested
@@ -186,17 +186,17 @@ public:
return new _MappableBuffer(fd.forget(), buf, length);
}
#endif
return NULL;
}
void *mmap(const void *addr, size_t length, int prot, int flags, off_t offset)
{
- // ASSERT(fd != -1)
+ MOZ_ASSERT(fd != -1);
#ifdef ANDROID
/* Mapping ashmem MAP_PRIVATE is like mapping anonymous memory, even when
* there is content in the ashmem */
if (flags & MAP_PRIVATE) {
flags &= ~MAP_PRIVATE;
flags |= MAP_SHARED;
}
#endif
@@ -217,34 +217,34 @@ private:
/* File descriptor for the temporary file or ashmem */
AutoCloseFD fd;
};
MappableDeflate *
MappableDeflate::Create(const char *name, Zip *zip, Zip::Stream *stream)
{
- // ASSERT(stream->GetType() == Zip::Stream::DEFLATE)
+ MOZ_ASSERT(stream->GetType() == Zip::Stream::DEFLATE);
_MappableBuffer *buf = _MappableBuffer::Create(name, stream->GetUncompressedSize());
if (buf)
return new MappableDeflate(buf, zip, stream);
return NULL;
}
MappableDeflate::MappableDeflate(_MappableBuffer *buf, Zip *zip,
Zip::Stream *stream)
: zip(zip), buffer(buf), zStream(stream->GetZStream(*buf)) { }
MappableDeflate::~MappableDeflate() { }
void *
MappableDeflate::mmap(const void *addr, size_t length, int prot, int flags, off_t offset)
{
- // ASSERT(buffer)
- // ASSERT(! flags & MAP_SHARED)
+ MOZ_ASSERT(buffer);
+ MOZ_ASSERT(!(flags & MAP_SHARED));
flags |= MAP_PRIVATE;
/* The deflate stream is uncompressed up to the required offset + length, if
* it hasn't previously been uncompressed */
ssize_t missing = offset + length + zStream.avail_out - buffer->GetLength();
if (missing > 0) {
uInt avail_out = zStream.avail_out;
zStream.avail_out = missing;
--- a/mozglue/linker/Utils.h
+++ b/mozglue/linker/Utils.h
@@ -4,16 +4,17 @@
#ifndef Utils_h
#define Utils_h
#include <stdint.h>
#include <stddef.h>
#include <sys/mman.h>
#include <unistd.h>
+#include "mozilla/Assertions.h"
/**
* On architectures that are little endian and that support unaligned reads,
* we can use direct type, but on others, we want to have a special class
* to handle conversion and alignment issues.
*/
#if defined(__i386__) || defined(__x86_64__)
typedef uint16_t le_uint16;
@@ -275,26 +276,26 @@ public:
/**
* Constructors and Initializers
*/
UnsizedArray(): contents(NULL) { }
UnsizedArray(const void *buf): contents(reinterpret_cast<const T *>(buf)) { }
void Init(const void *buf)
{
- // ASSERT(operator bool())
+ MOZ_ASSERT(contents == NULL);
contents = reinterpret_cast<const T *>(buf);
}
/**
* Returns the nth element of the array
*/
const T &operator[](const idx_t index) const
{
- // ASSERT(operator bool())
+ MOZ_ASSERT(contents);
return contents[index];
}
/**
* Returns whether the array points somewhere
*/
operator bool() const
{
@@ -341,17 +342,17 @@ public:
void Init(const void *buf)
{
UnsizedArray<T>::Init(buf);
}
void Init(const idx_t len)
{
- // ASSERT(length != 0)
+ MOZ_ASSERT(length == 0);
length = len;
}
void InitSize(const idx_t size)
{
Init(size / sizeof(T));
}
@@ -367,18 +368,18 @@ public:
InitSize(size);
}
/**
* Returns the nth element of the array
*/
const T &operator[](const idx_t index) const
{
- // ASSERT(index < length)
- // ASSERT(operator bool())
+ MOZ_ASSERT(index < length);
+ MOZ_ASSERT(operator bool());
return UnsizedArray<T>::operator[](index);
}
/**
* Returns the number of elements in the array
*/
idx_t numElements() const
{
--- a/mozglue/linker/Zip.h
+++ b/mozglue/linker/Zip.h
@@ -5,18 +5,16 @@
#ifndef Zip_h
#define Zip_h
#include <cstring>
#include <stdint.h>
#include <vector>
#include <zlib.h>
#include "Utils.h"
-/* Until RefPtr.h stops using JS_Assert */
-#undef DEBUG
#include "mozilla/RefPtr.h"
/**
* Forward declaration
*/
class ZipCollection;
/**