2010-06-10 22:11:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-04-09 20:25:05 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-06-10 22:11:11 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_Module_h
|
|
|
|
#define mozilla_Module_h
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
2018-06-26 08:39:49 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-06-10 22:11:11 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A module implements one or more XPCOM components. This structure is used
|
|
|
|
* for both binary and script modules, but the registration members
|
|
|
|
* (cids/contractids/categoryentries) are unused for modules which are loaded
|
|
|
|
* via a module loader.
|
|
|
|
*/
|
|
|
|
struct Module {
|
2018-12-10 18:58:12 +03:00
|
|
|
static const unsigned int kVersion = 66;
|
2010-06-10 22:11:11 +04:00
|
|
|
|
|
|
|
struct CIDEntry;
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
typedef already_AddRefed<nsIFactory> (*GetFactoryProcPtr)(
|
|
|
|
const Module& module, const CIDEntry& entry);
|
2010-06-10 22:11:11 +04:00
|
|
|
|
2010-06-21 20:46:26 +04:00
|
|
|
typedef nsresult (*ConstructorProcPtr)(nsISupports* aOuter, const nsIID& aIID,
|
|
|
|
void** aResult);
|
2010-06-10 22:11:11 +04:00
|
|
|
|
2010-06-21 20:46:26 +04:00
|
|
|
typedef nsresult (*LoadFuncPtr)();
|
|
|
|
typedef void (*UnloadFuncPtr)();
|
2010-06-10 22:11:11 +04:00
|
|
|
|
2014-02-10 04:11:37 +04:00
|
|
|
/**
|
|
|
|
* This selector allows CIDEntrys to be marked so that they're only loaded
|
2016-08-23 08:57:36 +03:00
|
|
|
* into certain kinds of processes. Selectors can be combined.
|
2014-02-10 04:11:37 +04:00
|
|
|
*/
|
|
|
|
enum ProcessSelector {
|
2016-08-23 08:57:36 +03:00
|
|
|
ANY_PROCESS = 0x0,
|
|
|
|
MAIN_PROCESS_ONLY = 0x1,
|
|
|
|
CONTENT_PROCESS_ONLY = 0x2,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* By default, modules are not loaded in the GPU process, even if
|
|
|
|
* ANY_PROCESS is specified. This flag enables a module in the
|
|
|
|
* GPU process.
|
|
|
|
*/
|
2018-11-06 00:28:38 +03:00
|
|
|
ALLOW_IN_GPU_PROCESS = 0x4,
|
|
|
|
ALLOW_IN_VR_PROCESS = 0x8,
|
|
|
|
ALLOW_IN_GPU_AND_VR_PROCESS = ALLOW_IN_GPU_PROCESS | ALLOW_IN_VR_PROCESS
|
2014-02-10 04:11:37 +04:00
|
|
|
};
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
/**
|
|
|
|
* The constructor callback is an implementation detail of the default binary
|
|
|
|
* loader and may be null.
|
|
|
|
*/
|
|
|
|
struct CIDEntry {
|
|
|
|
const nsCID* cid;
|
|
|
|
bool service;
|
2010-06-21 20:46:26 +04:00
|
|
|
GetFactoryProcPtr getFactoryProc;
|
|
|
|
ConstructorProcPtr constructorProc;
|
2014-02-10 04:11:37 +04:00
|
|
|
ProcessSelector processSelector;
|
2010-06-10 22:11:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ContractIDEntry {
|
|
|
|
const char* contractid;
|
2014-08-03 00:44:06 +04:00
|
|
|
nsID const* cid;
|
2014-02-10 04:11:37 +04:00
|
|
|
ProcessSelector processSelector;
|
2010-06-10 22:11:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CategoryEntry {
|
|
|
|
const char* category;
|
|
|
|
const char* entry;
|
|
|
|
const char* value;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binary compatibility check, should be kModuleVersion.
|
|
|
|
*/
|
|
|
|
unsigned int mVersion;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of CIDs (class IDs) implemented by this module. The final entry
|
2013-10-11 00:41:00 +04:00
|
|
|
* should be { nullptr }.
|
2010-06-10 22:11:11 +04:00
|
|
|
*/
|
|
|
|
const CIDEntry* mCIDs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of mappings from contractid to CID. The final entry should
|
2013-10-11 00:41:00 +04:00
|
|
|
* be { nullptr }.
|
2010-06-10 22:11:11 +04:00
|
|
|
*/
|
|
|
|
const ContractIDEntry* mContractIDs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of category manager entries. The final entry should be
|
2013-10-11 00:41:00 +04:00
|
|
|
* { nullptr }.
|
2010-06-10 22:11:11 +04:00
|
|
|
*/
|
|
|
|
const CategoryEntry* mCategoryEntries;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the component manager tries to get the factory for a CID, it first
|
|
|
|
* checks for this module-level getfactory callback. If this function is
|
|
|
|
* not implemented, it checks the CIDEntry getfactory callback. If that is
|
2013-10-11 00:41:00 +04:00
|
|
|
* also nullptr, a generic factory is generated using the CIDEntry
|
|
|
|
* constructor callback which must be non-nullptr.
|
2010-06-10 22:11:11 +04:00
|
|
|
*/
|
2010-06-21 20:46:26 +04:00
|
|
|
GetFactoryProcPtr getFactoryProc;
|
2010-06-10 22:11:11 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional Function which are called when this module is loaded and
|
|
|
|
* at shutdown. These are not C++ constructor/destructors to avoid
|
|
|
|
* calling them too early in startup or too late in shutdown.
|
|
|
|
*/
|
2010-06-21 20:46:26 +04:00
|
|
|
LoadFuncPtr loadProc;
|
|
|
|
UnloadFuncPtr unloadProc;
|
2016-08-23 08:57:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional flags which control whether the module loads on a process-type
|
|
|
|
* basis.
|
|
|
|
*/
|
|
|
|
ProcessSelector selector;
|
2010-06-10 22:11:11 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2010-06-10 22:11:11 +04:00
|
|
|
|
2013-06-15 10:33:35 +04:00
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
2010-06-10 22:11:11 +04:00
|
|
|
#define NSMODULE_NAME(_name) _name##_NSModule
|
2018-09-11 06:20:06 +03:00
|
|
|
#if defined(_MSC_VER) || (defined(__clang__) && defined(__MINGW32__))
|
2013-11-19 08:45:31 +04:00
|
|
|
#pragma section(".kPStaticModules$M", read)
|
|
|
|
#pragma comment(linker, "/merge:.kPStaticModules=.rdata")
|
|
|
|
#define NSMODULE_SECTION __declspec(allocate(".kPStaticModules$M"), dllexport)
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#if defined(__ELF__)
|
2018-06-26 08:40:51 +03:00
|
|
|
#define NSMODULE_SECTION \
|
|
|
|
__attribute__((section("kPStaticModules"), visibility("default")))
|
2013-11-19 08:45:31 +04:00
|
|
|
#elif defined(__MACH__)
|
|
|
|
#define NSMODULE_SECTION \
|
|
|
|
__attribute__((section("__DATA, .kPStaticModules"), visibility("default")))
|
2014-08-27 18:16:49 +04:00
|
|
|
#elif defined(_WIN32)
|
2018-06-26 08:40:51 +03:00
|
|
|
#define NSMODULE_SECTION __attribute__((section("kPStaticModules"), dllexport))
|
2013-11-19 08:45:31 +04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if !defined(NSMODULE_SECTION)
|
|
|
|
#error Do not know how to define sections.
|
|
|
|
#endif
|
2018-06-26 08:39:49 +03:00
|
|
|
#if defined(MOZ_HAVE_ASAN_BLACKLIST)
|
|
|
|
#define NSMODULE_ASAN_BLACKLIST __attribute__((no_sanitize_address))
|
|
|
|
#else
|
|
|
|
#define NSMODULE_ASAN_BLACKLIST
|
|
|
|
#endif
|
|
|
|
#define NSMODULE_DEFN(_name) \
|
|
|
|
extern NSMODULE_SECTION NSMODULE_ASAN_BLACKLIST \
|
|
|
|
mozilla::Module const* const NSMODULE_NAME(_name)
|
2010-06-10 22:11:11 +04:00
|
|
|
#else
|
2018-06-26 10:18:14 +03:00
|
|
|
#error Building binary XPCOM components is not supported anymore.
|
2010-06-10 22:11:11 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // mozilla_Module_h
|