mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
01583602a9
The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
160 lines
4.0 KiB
C++
160 lines
4.0 KiB
C++
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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 CustomElf_h
|
|
#define CustomElf_h
|
|
|
|
#include "ElfLoader.h"
|
|
#include "BaseElf.h"
|
|
#include "Logging.h"
|
|
#include "Elfxx.h"
|
|
|
|
/**
|
|
* Library Handle class for ELF libraries we don't let the system linker
|
|
* handle.
|
|
*/
|
|
class CustomElf: public BaseElf, private ElfLoader::link_map
|
|
{
|
|
friend class ElfLoader;
|
|
friend class SEGVHandler;
|
|
public:
|
|
/**
|
|
* Returns a new CustomElf using the given file descriptor to map ELF
|
|
* content. The file descriptor ownership is stolen, and it will be closed
|
|
* in CustomElf's destructor if an instance is created, or by the Load
|
|
* method otherwise. The path corresponds to the file descriptor, and flags
|
|
* are the same kind of flags that would be given to dlopen(), though
|
|
* currently, none are supported and the behaviour is more or less that of
|
|
* RTLD_GLOBAL | RTLD_BIND_NOW.
|
|
*/
|
|
static already_AddRefed<LibHandle> Load(Mappable *mappable,
|
|
const char *path, int flags);
|
|
|
|
/**
|
|
* Inherited from LibHandle/BaseElf
|
|
*/
|
|
virtual ~CustomElf();
|
|
|
|
protected:
|
|
virtual Mappable *GetMappable() const;
|
|
|
|
public:
|
|
/**
|
|
* Shows some stats about the Mappable instance. The when argument is to be
|
|
* used by the caller to give an identifier of the when the stats call is
|
|
* made.
|
|
*/
|
|
virtual void stats(const char *when) const;
|
|
|
|
/**
|
|
* Returns the instance, casted as BaseElf. (short of a better way to do
|
|
* this without RTTI)
|
|
*/
|
|
virtual BaseElf *AsBaseElf() { return this; }
|
|
|
|
private:
|
|
/**
|
|
* Scan dependent libraries to find the address corresponding to the
|
|
* given symbol name. This is used to find symbols that are undefined
|
|
* in the Elf object.
|
|
*/
|
|
void *GetSymbolPtrInDeps(const char *symbol) const;
|
|
|
|
/**
|
|
* Private constructor
|
|
*/
|
|
CustomElf(Mappable *mappable, const char *path)
|
|
: BaseElf(path, mappable)
|
|
, link_map()
|
|
, init(0)
|
|
, fini(0)
|
|
, initialized(false)
|
|
, has_text_relocs(false)
|
|
{ }
|
|
|
|
/**
|
|
* Loads an Elf segment defined by the given PT_LOAD header.
|
|
* Returns whether this succeeded or failed.
|
|
*/
|
|
bool LoadSegment(const Elf::Phdr *pt_load) const;
|
|
|
|
/**
|
|
* Initializes the library according to information found in the given
|
|
* PT_DYNAMIC header.
|
|
* Returns whether this succeeded or failed.
|
|
*/
|
|
bool InitDyn(const Elf::Phdr *pt_dyn);
|
|
|
|
/**
|
|
* Apply .rel.dyn/.rela.dyn relocations.
|
|
* Returns whether this succeeded or failed.
|
|
*/
|
|
bool Relocate();
|
|
|
|
/**
|
|
* Apply .rel.plt/.rela.plt relocations.
|
|
* Returns whether this succeeded or failed.
|
|
*/
|
|
bool RelocateJumps();
|
|
|
|
/**
|
|
* Call initialization functions (.init/.init_array)
|
|
* Returns true;
|
|
*/
|
|
bool CallInit();
|
|
|
|
/**
|
|
* Call destructor functions (.fini_array/.fini)
|
|
* Returns whether this succeeded or failed.
|
|
*/
|
|
void CallFini();
|
|
|
|
/**
|
|
* Call a function given a pointer to its location.
|
|
*/
|
|
void CallFunction(void *ptr) const
|
|
{
|
|
/* C++ doesn't allow direct conversion between pointer-to-object
|
|
* and pointer-to-function. */
|
|
union {
|
|
void *ptr;
|
|
void (*func)(void);
|
|
} f;
|
|
f.ptr = ptr;
|
|
DEBUG_LOG("%s: Calling function @%p", GetPath(), ptr);
|
|
f.func();
|
|
}
|
|
|
|
/**
|
|
* Call a function given a an address relative to the library base
|
|
*/
|
|
void CallFunction(Elf::Addr addr) const
|
|
{
|
|
return CallFunction(GetPtr(addr));
|
|
}
|
|
|
|
/* List of dependent libraries */
|
|
std::vector<RefPtr<LibHandle> > dependencies;
|
|
|
|
/* List of .rel.dyn/.rela.dyn relocations */
|
|
Array<Elf::Reloc> relocations;
|
|
|
|
/* List of .rel.plt/.rela.plt relocation */
|
|
Array<Elf::Reloc> jumprels;
|
|
|
|
/* Relative address of the initialization and destruction functions
|
|
* (.init/.fini) */
|
|
Elf::Addr init, fini;
|
|
|
|
/* List of initialization and destruction functions
|
|
* (.init_array/.fini_array) */
|
|
Array<void *> init_array, fini_array;
|
|
|
|
bool initialized;
|
|
|
|
bool has_text_relocs;
|
|
};
|
|
|
|
#endif /* CustomElf_h */
|