Backout bug 552864, bug 632404 and bug 657297 because of leak test bustage

This commit is contained in:
Mike Hommey 2011-05-22 17:52:16 +02:00
Родитель c0827dae86
Коммит a47726df7f
24 изменённых файлов: 265 добавлений и 670 удалений

Просмотреть файл

@ -91,22 +91,62 @@ include $(topsrcdir)/config/rules.mk
else
# Build a binary bootstrapping with XRE_main
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
PROGRAM = $(MOZ_APP_NAME)$(BIN_SUFFIX)
else
PROGRAM = $(MOZ_APP_NAME)-bin$(BIN_SUFFIX)
endif
CPPSRCS = nsBrowserApp.cpp
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
DEFINES += -DXPCOM_GLUE
STL_FLAGS=
ifdef BUILD_STATIC_LIBS
ifdef _MSC_VER
STATIC_COMPONENTS_LINKER_PATH = -LIBPATH:$(DEPTH)/staticlib
else
STATIC_COMPONENTS_LINKER_PATH = -L$(DEPTH)/staticlib
endif
LIBS += $(DEPTH)/toolkit/xre/$(LIB_PREFIX)xulapp_s.$(LIB_SUFFIX)
else
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
LIBS += $(DIST)/bin/XUL
else
EXTRA_DSO_LIBS += xul
endif
endif
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
TK_LIBS := $(TK_LIBS)
endif
ifdef MOZ_ENABLE_LIBXUL
APP_XPCOM_LIBS = $(XPCOM_GLUE_LDOPTS)
else
MOZILLA_INTERNAL_API = 1
APP_XPCOM_LIBS = $(XPCOM_LIBS)
endif
LIBS += \
$(STATIC_COMPONENTS_LINKER_PATH) \
$(EXTRA_DSO_LIBS) \
$(XPCOM_STANDALONE_GLUE_LDOPTS) \
$(APP_XPCOM_LIBS) \
$(NSPR_LIBS) \
$(NULL)
ifdef BUILD_STATIC_LIBS
LIBS += \
$(MOZ_JS_LIBS) \
$(TK_LIBS) \
$(NULL)
# Add explicit X11 dependency when building against X11 toolkits
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
LIBS += $(XLDFLAGS) $(XLIBS) $(ZLIB_LIBS)
endif
endif
ifdef MOZ_JPROF
LIBS += -ljprof
endif
@ -131,6 +171,18 @@ ifdef _MSC_VER
WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
endif
ifdef BUILD_STATIC_LIBS
include $(topsrcdir)/config/static-config.mk
EXTRA_DEPS += \
$(STATIC_EXTRA_DEPS) \
$(NULL)
DEFINES += $(STATIC_DEFINES)
CPPSRCS += $(STATIC_CPPSRCS)
EXTRA_DSO_LIBS += $(STATIC_EXTRA_DSO_LIBS)
EXTRA_LIBS += $(STATIC_EXTRA_LIBS)
endif
ifeq ($(OS_ARCH),WINNT)
OS_LIBS += $(call EXPAND_LIBNAME,comctl32 comdlg32 uuid shell32 ole32 oleaut32 version winspool)
OS_LIBS += $(call EXPAND_LIBNAME,usp10 msimg32)
@ -143,6 +195,9 @@ RCFLAGS += -DMOZ_PHOENIX -I$(srcdir)
else
RCFLAGS += -DMOZ_PHOENIX --include-dir $(srcdir)
endif
ifdef BUILD_STATIC_LIBS
RCFLAGS += -DMOZ_STATIC_BUILD
endif
ifdef DEBUG
RCFLAGS += -DDEBUG
endif
@ -151,6 +206,9 @@ endif
ifeq ($(OS_ARCH),OS2)
RESFILE=splashos2.res
RCFLAGS += -DMOZ_PHOENIX
ifdef BUILD_STATIC_LIBS
RCFLAGS += -DMOZ_STATIC_BUILD -i $(DIST)/include
endif
ifdef DEBUG
RCFLAGS += -DDEBUG
endif
@ -159,6 +217,12 @@ endif
include $(topsrcdir)/config/rules.mk
ifdef BUILD_STATIC_LIBS
include $(topsrcdir)/config/static-rules.mk
DEFINES += -DIMPL_XREAPI
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),photon)
LIBS += -lphexlib
endif
@ -185,9 +249,18 @@ endif
ifneq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
libs::
cp -p $(MOZ_APP_NAME)$(BIN_SUFFIX) $(DIST)/bin/$(MOZ_APP_NAME)-bin$(BIN_SUFFIX)
$(MOZ_APP_NAME):: $(topsrcdir)/build/unix/mozilla.in $(GLOBAL_DEPS)
cat $< | sed -e "s|%MOZAPPDIR%|$(installdir)|" \
-e "s|%MOZ_APP_DISPLAYNAME%|$(MOZ_APP_DISPLAYNAME)|" > $@
chmod +x $@
libs:: $(MOZ_APP_NAME)
$(INSTALL) $< $(DIST)/bin
install:: $(MOZ_APP_NAME)
$(SYSINSTALL) $< $(DESTDIR)$(bindir)
GARBAGE += $(MOZ_APP_NAME)
GARBAGE += $(addprefix $(DIST)/bin/defaults/pref/, firefox.js)
endif
@ -255,7 +328,7 @@ libs repackage:: $(PROGRAM) application.ini
rsync -a $(DIST)/bin/ $(DIST)/$(APP_NAME).app/Contents/$(APPFILES)
$(RM) $(DIST)/$(APP_NAME).app/Contents/$(APPFILES)/mangle $(DIST)/$(APP_NAME).app/Contents/$(APPFILES)/shlibsign
ifdef LIBXUL_SDK
cp $(LIBXUL_DIST)/bin/$(XR_STUB_NAME) $(DIST)/$(APP_NAME).app/Contents/MacOS/firefox
cp $(LIBXUL_DIST)/bin/$(XR_STUB_NAME) $(DIST)/$(APP_NAME).app/Contents/MacOS/firefox-bin
else
$(RM) $(DIST)/$(APP_NAME).app/Contents/MacOS/$(PROGRAM)
rsync -aL $(PROGRAM) $(DIST)/$(APP_NAME).app/Contents/MacOS

Просмотреть файл

@ -94,7 +94,7 @@
</dict>
</array>
<key>CFBundleExecutable</key>
<string>firefox</string>
<string>firefox-bin</string>
<key>CFBundleGetInfoString</key>
<string>%APP_NAME% %APP_VERSION%</string>
<key>CFBundleIconFile</key>

Просмотреть файл

@ -36,19 +36,14 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPCOMGlue.h"
#include "nsXULAppAPI.h"
#if defined(XP_WIN)
#ifdef XP_WIN
#include <windows.h>
#include <stdlib.h>
#elif defined(XP_UNIX)
#include <sys/time.h>
#include <sys/resource.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "plstr.h"
#include "prprf.h"
@ -59,14 +54,11 @@
#include "nsStringGlue.h"
#ifdef XP_WIN
// we want to use the DLL blocklist if possible
#define XRE_WANT_DLL_BLOCKLIST
// we want a wmain entry point
#include "nsWindowsWMain.cpp"
#define snprintf _snprintf
#define strcasecmp _stricmp
#endif
#include "BinaryPath.h"
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
static void Output(const char *fmt, ... )
{
@ -93,12 +85,12 @@ static PRBool IsArg(const char* arg, const char* s)
{
if (*++arg == '-')
++arg;
return !strcasecmp(arg, s);
return !PL_strcasecmp(arg, s);
}
#if defined(XP_WIN) || defined(XP_OS2)
if (*arg == '/')
return !strcasecmp(++arg, s);
return !PL_strcasecmp(++arg, s);
#endif
return PR_FALSE;
@ -114,48 +106,22 @@ public:
~ScopedLogging() { NS_LogTerm(); }
};
XRE_GetFileFromPathType XRE_GetFileFromPath;
XRE_CreateAppDataType XRE_CreateAppData;
XRE_FreeAppDataType XRE_FreeAppData;
#ifdef XRE_HAS_DLL_BLOCKLIST
XRE_SetupDllBlocklistType XRE_SetupDllBlocklist;
#endif
XRE_TelemetryAddType XRE_TelemetryAdd;
XRE_mainType XRE_main;
static const nsDynamicFunctionLoad kXULFuncs[] = {
{ "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
{ "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
{ "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
#ifdef XRE_HAS_DLL_BLOCKLIST
{ "XRE_SetupDllBlocklist", (NSFuncPtr*) &XRE_SetupDllBlocklist },
#endif
{ "XRE_TelemetryAdd", (NSFuncPtr*) &XRE_TelemetryAdd },
{ "XRE_main", (NSFuncPtr*) &XRE_main },
{ nsnull, nsnull }
};
static int do_main(const char *exePath, int argc, char* argv[])
int main(int argc, char* argv[])
{
ScopedLogging log;
nsCOMPtr<nsILocalFile> appini;
#ifdef XP_WIN
// exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8
// encoded path, so it is safe to convert it
nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), PR_FALSE,
getter_AddRefs(appini));
#else
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_FALSE,
getter_AddRefs(appini));
#endif
nsresult rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appini));
if (NS_FAILED(rv)) {
Output("Couldn't calculate the application directory.");
return 255;
}
appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini"));
// Allow firefox.exe to launch XULRunner apps via -app <application.ini>
// Note that -app must be the *first* argument.
const char *appDataFile = getenv("XUL_APP_FILE");
char *appEnv = nsnull;
const char *appDataFile = PR_GetEnv("XUL_APP_FILE");
if (appDataFile && *appDataFile) {
rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini));
if (NS_FAILED(rv)) {
@ -175,12 +141,8 @@ static int do_main(const char *exePath, int argc, char* argv[])
return 255;
}
char appEnv[MAXPATHLEN];
snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
if (putenv(appEnv)) {
Output("Couldn't set %s.\n", appEnv);
return 255;
}
appEnv = PR_smprintf("XUL_APP_FILE=%s", argv[2]);
PR_SetEnv(appEnv);
argv[2] = argv[0];
argv += 2;
argc -= 2;
@ -195,90 +157,7 @@ static int do_main(const char *exePath, int argc, char* argv[])
int result = XRE_main(argc, argv, appData);
XRE_FreeAppData(appData);
return result;
}
int main(int argc, char* argv[])
{
char exePath[MAXPATHLEN];
nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath);
if (NS_FAILED(rv)) {
Output("Couldn't calculate the application directory.\n");
return 255;
}
char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
if (!lastSlash || (lastSlash - exePath > MAXPATHLEN - sizeof(XPCOM_DLL) - 1))
return 255;
strcpy(++lastSlash, XPCOM_DLL);
int gotCounters;
#if defined(XP_UNIX)
struct rusage initialRUsage;
gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage);
#elif defined(XP_WIN)
// GetProcessIoCounters().ReadOperationCount seems to have little to
// do with actual read operations. It reports 0 or 1 at this stage
// in the program. Luckily 1 coincides with when prefetch is
// enabled. If Windows prefetch didn't happen we can do our own
// faster dll preloading.
IO_COUNTERS ioCounters;
gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters);
if (gotCounters && !ioCounters.ReadOperationCount)
#endif
{
XPCOMGlueEnablePreload();
}
rv = XPCOMGlueStartup(exePath);
if (NS_FAILED(rv)) {
Output("Couldn't load XPCOM.\n");
return 255;
}
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
if (NS_FAILED(rv)) {
Output("Couldn't load XRE functions.\n");
return 255;
}
#ifdef XRE_HAS_DLL_BLOCKLIST
XRE_SetupDllBlocklist();
#endif
if (gotCounters) {
#if defined(XP_WIN)
XRE_TelemetryAdd("Early.GlueStartup::ProcessIoCounters.ReadOperationCount",
int(ioCounters.ReadOperationCount), 1, 100, 12, HISTOGRAM_LINEAR);
XRE_TelemetryAdd("Early.GlueStartup::ProcessIoCounters.ReadTransferCount (KB)",
int(ioCounters.ReadTransferCount / 1024), 1, 50 * 1024, 12, HISTOGRAM_LINEAR);
IO_COUNTERS newIoCounters;
if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) {
XRE_TelemetryAdd("GlueStartup::ProcessIoCounters.ReadOperationCount",
int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount), 1, 100, 12, HISTOGRAM_LINEAR);
XRE_TelemetryAdd("GlueStartup::ProcessIoCounters.ReadTransferCount (KB)",
int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024), 1, 50 * 1024, 12, HISTOGRAM_LINEAR);
}
#elif defined(XP_UNIX)
XRE_TelemetryAdd("Early.GlueStartup::HardFaults",
int(initialRUsage.ru_majflt), 1, 100, 12, HISTOGRAM_LINEAR);
struct rusage newRUsage;
if (!getrusage(RUSAGE_SELF, &newRUsage)) {
XRE_TelemetryAdd("GlueStartup::HardFaults",
int(newRUsage.ru_majflt - initialRUsage.ru_majflt), 1, 500, 12, HISTOGRAM_LINEAR);
}
#endif
}
int result;
{
ScopedLogging log;
result = do_main(exePath, argc, argv);
}
XPCOMGlueShutdown();
if (appEnv)
PR_smprintf_free(appEnv);
return result;
}

Просмотреть файл

@ -110,7 +110,6 @@ PluginProcessChild::Init()
protectCurrentDirectory = false;
}
if (protectCurrentDirectory) {
SanitizeEnvironmentVariables();
NS_SetDllDirectory(L"");
}

Просмотреть файл

@ -73,7 +73,6 @@ main(int argc, char* argv[])
// avoid it for unsupported plugins. See PluginProcessChild::Init for
// the details.
if (proctype != GeckoProcessType_Plugin) {
mozilla::SanitizeEnvironmentVariables();
mozilla::NS_SetDllDirectory(L"");
}
#endif

Просмотреть файл

@ -95,7 +95,6 @@ endif
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
CPPSRCS += nsNativeAppSupportWin.cpp
CPPSRCS += nsWindowsDllBlocklist.cpp
DEFINES += -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE
EXPORTS = nsWindowsDllInterceptor.h
else
@ -195,7 +194,6 @@ LOCAL_INCLUDES += \
-I$(topsrcdir)/dom/ipc \
-I$(topsrcdir)/toolkit/crashreporter \
-I$(topsrcdir)/dom/base \
-I$(topsrcdir)/xpcom/build \
$(NULL)
ifdef BUILD_STATIC_LIBS

Просмотреть файл

@ -251,7 +251,6 @@ static char **gQtOnlyArgv;
#endif /* MOZ_X11 */
#include "nsGTKToolkit.h"
#endif
#include "BinaryPath.h"
// Save literal putenv string to environment variable.
static void
@ -1446,10 +1445,141 @@ RemoteCommandLine(const char* aDesktopStartupID)
}
#endif // MOZ_ENABLE_XREMOTE
#ifdef XP_MACOSX
static char const *gBinaryPath;
#endif
nsresult
XRE_GetBinaryPath(const char* argv0, nsILocalFile* *aResult)
{
return mozilla::BinaryPath::GetFile(argv0, aResult);
nsresult rv;
nsCOMPtr<nsILocalFile> lf;
// We need to use platform-specific hackery to find the
// path of this executable. This is copied, with some modifications, from
// nsGREDirServiceProvider.cpp
#ifdef XP_WIN
PRUnichar exePath[MAXPATHLEN];
if (!::GetModuleFileNameW(0, exePath, MAXPATHLEN))
return NS_ERROR_FAILURE;
rv = NS_NewLocalFile(nsDependentString(exePath), PR_TRUE,
getter_AddRefs(lf));
if (NS_FAILED(rv))
return rv;
#elif defined(XP_MACOSX)
if (gBinaryPath)
return NS_NewNativeLocalFile(nsDependentCString(gBinaryPath), PR_FALSE,
aResult);
NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(lf));
nsCOMPtr<nsILocalFileMac> lfm (do_QueryInterface(lf));
if (!lfm)
return NS_ERROR_FAILURE;
// Works even if we're not bundled.
CFBundleRef appBundle = CFBundleGetMainBundle();
if (!appBundle)
return NS_ERROR_FAILURE;
CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
if (!executableURL)
return NS_ERROR_FAILURE;
rv = lfm->InitWithCFURL(executableURL);
CFRelease(executableURL);
if (NS_FAILED(rv))
return rv;
// Callers expect a normalized path.
lfm->Normalize();
#elif defined(XP_UNIX)
struct stat fileStat;
char exePath[MAXPATHLEN];
char tmpPath[MAXPATHLEN];
rv = NS_ERROR_FAILURE;
// on unix, there is no official way to get the path of the current binary.
// instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to
// multiple applications, we will try a series of techniques:
//
// 1) look for /proc/<pid>/exe which is a symlink to the executable on newer
// Linux kernels
// 2) use realpath() on argv[0], which works unless we're loaded from the
// PATH
// 3) manually walk through the PATH and look for ourself
// 4) give up
// #ifdef __linux__
// Commented out because it used to not work because it used to not deal
// with readlink not null-terminating the buffer.
#if 0
int r = readlink("/proc/self/exe", exePath, MAXPATHLEN);
if (r > 0 && r < MAXPATHLEN) {
exePath[r] = '\0';
if (stat(exePath, &fileStat) == 0) {
rv = NS_OK;
}
}
#endif
if (NS_FAILED(rv) &&
realpath(argv0, exePath) && stat(exePath, &fileStat) == 0) {
rv = NS_OK;
}
if (NS_FAILED(rv)) {
const char *path = getenv("PATH");
if (!path)
return NS_ERROR_FAILURE;
char *pathdup = strdup(path);
if (!pathdup)
return NS_ERROR_OUT_OF_MEMORY;
PRBool found = PR_FALSE;
char *newStr = pathdup;
char *token;
while ( (token = nsCRT::strtok(newStr, ":", &newStr)) ) {
sprintf(tmpPath, "%s/%s", token, argv0);
if (realpath(tmpPath, exePath) && stat(exePath, &fileStat) == 0) {
found = PR_TRUE;
break;
}
}
free(pathdup);
if (!found)
return NS_ERROR_FAILURE;
}
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,
getter_AddRefs(lf));
if (NS_FAILED(rv))
return rv;
#elif defined(XP_OS2)
PPIB ppib;
PTIB ptib;
char exePath[MAXPATHLEN];
DosGetInfoBlocks( &ptib, &ppib);
DosQueryModuleName( ppib->pib_hmte, MAXPATHLEN, exePath);
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,
getter_AddRefs(lf));
if (NS_FAILED(rv))
return rv;
#else
#error Oops, you need platform-specific code here
#endif
NS_ADDREF(*aResult = lf);
return NS_OK;
}
#define NS_ERROR_LAUNCHED_CHILD_PROCESS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_PROFILE, 200)
@ -2689,6 +2819,16 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
NS_ENSURE_TRUE(aAppData, 2);
#ifdef XP_MACOSX
// The xulrunner stub executable tricks CFBundleGetMainBundle on
// purpose into lying about the main bundle path. It will set
// XRE_BINARY_PATH to inform us of our real location.
gBinaryPath = getenv("XRE_BINARY_PATH");
if (gBinaryPath && !*gBinaryPath)
gBinaryPath = nsnull;
#endif
// Check for application.ini overrides
const char* override = nsnull;
ar = CheckArg("override", PR_TRUE, &override);
@ -3608,6 +3748,14 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
SaveFileToEnvIfUnset("XRE_PROFILE_LOCAL_PATH", profLD);
SaveWordToEnvIfUnset("XRE_PROFILE_NAME", profileName);
#ifdef XP_MACOSX
if (gBinaryPath) {
static char kEnvVar[MAXPATHLEN];
sprintf(kEnvVar, "XRE_BINARY_PATH=%s", gBinaryPath);
PR_SetEnv(kEnvVar);
}
#endif
#ifdef MOZ_WIDGET_GTK2
MOZ_gdk_display_close(display);
#endif

Просмотреть файл

@ -40,12 +40,6 @@
#include <stdio.h>
#ifdef XRE_WANT_DLL_BLOCKLIST
#define XRE_SetupDllBlocklist SetupDllBlocklist
#else
#include "nsXULAppAPI.h"
#endif
#include "nsAutoPtr.h"
#include "prlog.h"
@ -214,7 +208,7 @@ continue_loading:
WindowsDllInterceptor NtDllIntercept;
void
XRE_SetupDllBlocklist()
SetupDllBlocklist()
{
NtDllIntercept.Init("ntdll.dll");

Просмотреть файл

@ -76,7 +76,6 @@ FreeAllocStrings(int argc, char **argv)
int wmain(int argc, WCHAR **argv)
{
#ifndef XRE_DONT_PROTECT_DLL_LOAD
mozilla::SanitizeEnvironmentVariables();
mozilla::NS_SetDllDirectory(L"");
#endif

Просмотреть файл

@ -98,6 +98,7 @@ EXPORTS_mozilla = \
$(NULL)
ifeq (windows,$(MOZ_WIDGET_TOOLKIT))
CPPSRCS += nsSetDllDirectory.cpp
CPPSRCS += nsCrashOnException.cpp
endif

Просмотреть файл

@ -47,7 +47,6 @@
#include "jsapi.h"
#include "nsStringGlue.h"
#include "nsITelemetry.h"
#include "nsXULAppAPI.h"
namespace {
@ -150,10 +149,10 @@ WrapAndReturnHistogram(Histogram *h, JSContext *cx, jsval *ret)
&& JS_DefineFunction (cx, obj, "snapshot", JSHistogram_Snapshot, 1, 0)) ? NS_OK : NS_ERROR_FAILURE;
}
static nsresult
HistogramGet(const char *name, PRUint32 min, PRUint32 max, PRUint32 bucket_count,
PRUint32 histogram_type, Histogram **aResult)
NS_IMETHODIMP
Telemetry::NewHistogram(const nsACString &name, PRUint32 min, PRUint32 max, PRUint32 bucket_count, PRUint32 histogram_type, JSContext *cx, jsval *ret)
{
// Sanity checks on histogram parameters.
if (min < 1)
return NS_ERROR_ILLEGAL_VALUE;
@ -163,22 +162,12 @@ HistogramGet(const char *name, PRUint32 min, PRUint32 max, PRUint32 bucket_count
if (bucket_count <= 2)
return NS_ERROR_ILLEGAL_VALUE;
if (histogram_type == nsITelemetry::HISTOGRAM_EXPONENTIAL) {
*aResult = Histogram::FactoryGet(name, min, max, bucket_count, Histogram::kNoFlags);
} else {
*aResult = LinearHistogram::FactoryGet(name, min, max, bucket_count, Histogram::kNoFlags);
}
return NS_OK;
}
NS_IMETHODIMP
Telemetry::NewHistogram(const nsACString &name, PRUint32 min, PRUint32 max, PRUint32 bucket_count, PRUint32 histogram_type, JSContext *cx, jsval *ret)
{
Histogram *h;
nsresult rv = HistogramGet(name.BeginReading(), min, max, bucket_count, histogram_type, &h);
if (NS_FAILED(rv))
return rv;
// Sanity checks on histogram parameters.
if (histogram_type == nsITelemetry::HISTOGRAM_EXPONENTIAL) {
h = Histogram::FactoryGet(name.BeginReading(), min, max, bucket_count, Histogram::kNoFlags);
} else {
h = LinearHistogram::FactoryGet(name.BeginReading(), min, max, bucket_count, Histogram::kNoFlags);
}
return WrapAndReturnHistogram(h, cx, ret);
}
@ -253,19 +242,3 @@ const mozilla::Module kTelemetryModule = {
} // anonymous namespace
NSMODULE_DEFN(nsTelemetryModule) = &kTelemetryModule;
/**
* The XRE_TelemetryAdd function is to be used by embedding applications
* that can't use histogram.h directly.
*/
nsresult
XRE_TelemetryAdd(const char *name, int sample, PRUint32 min, PRUint32 max,
PRUint32 bucket_count, HistogramTypes histogram_type)
{
base::Histogram *h;
nsresult rv = HistogramGet(name, min, max, bucket_count, histogram_type, &h);
if (NS_FAILED(rv))
return rv;
h->Add(sample);
return NS_OK;
}

Просмотреть файл

@ -45,9 +45,6 @@ interface nsITelemetry : nsISupports
* Histogram types:
* HISTOGRAM_EXPONENTIAL - buckets increase exponentially
* HISTOGRAM_LINEAR - buckets increase linearly
*
* Please update the HistogramTypes enum in xpcom/build/nsXULAppAPI.h when
* adding/changing values.
*/
const unsigned long HISTOGRAM_EXPONENTIAL = 0;
const unsigned long HISTOGRAM_LINEAR = 1;

Просмотреть файл

@ -43,48 +43,13 @@
#error This file only makes sense on Windows.
#endif
#include <windows.h>
#include <nscore.h>
#include <stdlib.h>
namespace mozilla {
static void SanitizeEnvironmentVariables()
{
DWORD bufferSize = GetEnvironmentVariableW(L"PATH", NULL, 0);
if (bufferSize) {
wchar_t* originalPath = new wchar_t[bufferSize];
if (bufferSize - 1 == GetEnvironmentVariableW(L"PATH", originalPath, bufferSize)) {
bufferSize = ExpandEnvironmentStringsW(originalPath, NULL, 0);
if (bufferSize) {
wchar_t* newPath = new wchar_t[bufferSize];
if (ExpandEnvironmentStringsW(originalPath,
newPath,
bufferSize)) {
SetEnvironmentVariableW(L"PATH", newPath);
}
delete[] newPath;
}
}
delete[] originalPath;
}
}
// Sets the directory from which DLLs can be loaded if the SetDllDirectory OS
// API is available.
// You must call SanitizeEnvironmentVariables before this function when calling
// it the first time.
static inline void NS_SetDllDirectory(const WCHAR *aDllDirectory)
{
typedef BOOL
(WINAPI *pfnSetDllDirectory) (LPCWSTR);
pfnSetDllDirectory setDllDirectory = nsnull;
setDllDirectory = reinterpret_cast<pfnSetDllDirectory>
(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDllDirectoryW"));
if (setDllDirectory) {
setDllDirectory(aDllDirectory);
}
}
XPCOM_API(void) NS_SetDllDirectory(const WCHAR *aDllDirectory);
}

Просмотреть файл

@ -1,178 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Hommey <mh@glandium.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_BinaryPath_h
#define mozilla_BinaryPath_h
#include "nsXPCOMPrivate.h" // for MAXPATHLEN
#include "prtypes.h"
#ifdef XP_WIN
#include <windows.h>
#elif defined(XP_MACOSX)
#include <CoreFoundation/CoreFoundation.h>
#elif defined(XP_UNIX)
#include <sys/stat.h>
#endif
namespace mozilla {
class BinaryPath {
public:
#ifdef XP_WIN
static nsresult Get(const char *argv0, char aResult[MAXPATHLEN])
{
PRUnichar wide_path[MAXPATHLEN];
nsresult rv = GetW(argv0, wide_path);
if (NS_FAILED(rv))
return rv;
WideCharToMultiByte(CP_UTF8, 0, wide_path, -1,
aResult, MAXPATHLEN, NULL, NULL);
return NS_OK;
}
private:
static nsresult GetW(const char *argv0, PRUnichar aResult[MAXPATHLEN])
{
if (::GetModuleFileNameW(0, aResult, MAXPATHLEN))
return NS_OK;
return NS_ERROR_FAILURE;
}
#elif defined(XP_MACOSX)
static nsresult Get(const char *argv0, char aResult[MAXPATHLEN])
{
// Works even if we're not bundled.
CFBundleRef appBundle = CFBundleGetMainBundle();
if (!appBundle)
return NS_ERROR_FAILURE;
CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
if (!executableURL)
return NS_ERROR_FAILURE;
nsresult rv;
if (CFURLGetFileSystemRepresentation(executableURL, false, (UInt8 *)aResult, MAXPATHLEN))
rv = NS_OK;
else
rv = NS_ERROR_FAILURE;
CFRelease(executableURL);
return rv;
}
#elif defined(XP_UNIX)
static nsresult Get(const char *argv0, char aResult[MAXPATHLEN])
{
struct stat fileStat;
// on unix, there is no official way to get the path of the current binary.
// instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to
// multiple applications, we will try a series of techniques:
//
// 1) use realpath() on argv[0], which works unless we're loaded from the
// PATH
// 2) manually walk through the PATH and look for ourself
// 3) give up
if (realpath(argv0, aResult) && stat(aResult, &fileStat) == 0)
return NS_OK;
const char *path = getenv("PATH");
if (!path)
return NS_ERROR_FAILURE;
char *pathdup = strdup(path);
if (!pathdup)
return NS_ERROR_OUT_OF_MEMORY;
PRBool found = PR_FALSE;
char *token = strtok(pathdup, ":");
while (token) {
char tmpPath[MAXPATHLEN];
sprintf(tmpPath, "%s/%s", token, argv0);
if (realpath(tmpPath, aResult) && stat(aResult, &fileStat) == 0) {
found = PR_TRUE;
break;
}
token = strtok(NULL, ":");
}
free(pathdup);
if (found)
return NS_OK;
return NS_ERROR_FAILURE;
}
#elif defined(XP_OS2)
static nsresult Get(const char *argv0, char aResult[MAXPATHLEN])
{
PPIB ppib;
PTIB ptib;
DosGetInfoBlocks( &ptib, &ppib);
DosQueryModuleName(ppib->pib_hmte, MAXPATHLEN, aResult);
}
#else
#error Oops, you need platform-specific code here
#endif
public:
static nsresult GetFile(const char *argv0, nsILocalFile* *aResult)
{
nsCOMPtr<nsILocalFile> lf;
#ifdef XP_WIN
PRUnichar exePath[MAXPATHLEN];
nsresult rv = GetW(argv0, exePath);
#else
char exePath[MAXPATHLEN];
nsresult rv = Get(argv0, exePath);
#endif
if (NS_FAILED(rv))
return rv;
#ifdef XP_WIN
rv = NS_NewLocalFile(nsDependentString(exePath), PR_TRUE,
getter_AddRefs(lf));
#else
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_TRUE,
getter_AddRefs(lf));
#endif
if (NS_FAILED(rv))
return rv;
NS_ADDREF(*aResult = lf);
return NS_OK;
}
};
}
#endif /* mozilla_BinaryPath_h */

Просмотреть файл

@ -281,6 +281,7 @@ void XXXNeverCalled()
sXPCOMHasLoadedNewDLLs = !sXPCOMHasLoadedNewDLLs;
NS_SetHasLoadedNewDLLs();
NS_NewWindowsRegKey(nsnull);
NS_SetDllDirectory(nsnull);
#if defined (DEBUG)
PurePrintf(0);
#endif

Просмотреть файл

@ -562,24 +562,4 @@ XRE_API(bool,
XRE_API(void,
XRE_InstallX11ErrorHandler, ())
#if defined(_MSC_VER) && defined(_M_IX86)
#define XRE_HAS_DLL_BLOCKLIST
XRE_API(void,
XRE_SetupDllBlocklist, ())
#endif
enum HistogramTypes {
HISTOGRAM_EXPONENTIAL = 0,
HISTOGRAM_LINEAR = 1
};
XRE_API(nsresult,
XRE_TelemetryAdd, (const char *name,
int sample,
PRUint32 min,
PRUint32 max,
PRUint32 bucket_count,
HistogramTypes histogram_type))
#endif // _nsXULAppAPI_h__

Просмотреть файл

@ -48,7 +48,7 @@ XPCOMGlueLoad(const char *xpcomFile, GetFrozenFunctionsFunc *func NS_OUTPARAM);
NS_HIDDEN_(void)
XPCOMGlueUnload();
typedef void (*DependentLibsCallback)(const char *aDependentLib, PRBool do_preload);
typedef void (*DependentLibsCallback)(const char *aDependentLib);
NS_HIDDEN_(void)
XPCOMGlueLoadDependentLibs(const char *xpcomDir, DependentLibsCallback cb);

Просмотреть файл

@ -21,7 +21,6 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Hommey <mh@glandium.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -40,14 +39,6 @@
#include "nsGlueLinking.h"
#include "nsXPCOMGlue.h"
#ifdef LINUX
#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
#include <elf.h>
#include <limits.h>
#endif
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
@ -82,69 +73,9 @@ AppendDependentLib(void *libHandle)
sTop = d;
}
#ifdef LINUX
static const unsigned int bufsize = 4096;
#ifdef HAVE_64BIT_OS
typedef Elf64_Ehdr Elf_Ehdr;
typedef Elf64_Phdr Elf_Phdr;
static const unsigned char ELFCLASS = ELFCLASS64;
typedef Elf64_Off Elf_Off;
#else
typedef Elf32_Ehdr Elf_Ehdr;
typedef Elf32_Phdr Elf_Phdr;
static const unsigned char ELFCLASS = ELFCLASS32;
typedef Elf32_Off Elf_Off;
#endif
static void
preload(const char *file)
ReadDependentCB(const char *aDependentLib)
{
union {
char buf[bufsize];
Elf_Ehdr ehdr;
} elf;
int fd = open(file, O_RDONLY);
if (fd < 0)
return;
// Read ELF header (ehdr) and program header table (phdr).
// We check that the ELF magic is found, that the ELF class matches
// our own, and that the program header table as defined in the ELF
// headers fits in the buffer we read.
if ((read(fd, elf.buf, bufsize) <= 0) ||
(memcmp(elf.buf, ELFMAG, 4)) ||
(elf.ehdr.e_ident[EI_CLASS] != ELFCLASS) ||
(elf.ehdr.e_phoff + elf.ehdr.e_phentsize * elf.ehdr.e_phnum >= bufsize)) {
close(fd);
return;
}
// The program header table contains segment definitions. One such
// segment type is PT_LOAD, which describes how the dynamic loader
// is going to map the file in memory. We use that information to
// find the biggest offset from the library that will be mapped in
// memory.
Elf_Phdr *phdr = (Elf_Phdr *)&elf.buf[elf.ehdr.e_phoff];
Elf_Off end = 0;
for (int phnum = elf.ehdr.e_phnum; phnum; phdr++, phnum--)
if ((phdr->p_type == PT_LOAD) &&
(end < phdr->p_offset + phdr->p_filesz))
end = phdr->p_offset + phdr->p_filesz;
// Let the kernel read ahead what the dynamic loader is going to
// map in memory soon after.
if (end > 0) {
readahead(fd, 0, end);
}
close(fd);
}
#endif
static void
ReadDependentCB(const char *aDependentLib, PRBool do_preload)
{
#ifdef LINUX
if (do_preload)
preload(aDependentLib);
#endif
void *libHandle = dlopen(aDependentLib, RTLD_GLOBAL | RTLD_LAZY);
if (!libHandle)
return;

Просмотреть файл

@ -68,7 +68,7 @@ AppendDependentLib(HMODULE libHandle)
}
static void
ReadDependentCB(const char *aDependentLib, PRBool do_preload)
ReadDependentCB(const char *aDependentLib)
{
CHAR pszError[_MAX_PATH];
ULONG ulrc = NO_ERROR;

Просмотреть файл

@ -21,7 +21,6 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Hommey <mh@glandium.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -46,131 +45,11 @@
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <mach/machine.h>
#include <mach-o/fat.h>
#include <mach-o/loader.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <limits.h>
#if defined(__i386__)
static const uint32_t CPU_TYPE = CPU_TYPE_X86;
#elif defined(__x86_64__)
static const uint32_t CPU_TYPE = CPU_TYPE_X86_64;
#elif defined(__ppc__)
static const uint32_t CPU_TYPE = CPU_TYPE_POWERPC;
#elif defined(__ppc64__)
static const uint32_t CPU_TYPE = CPU_TYPE_POWERPC64;
#else
#error Unsupported CPU type
#endif
#ifdef HAVE_64BIT_OS
#undef LC_SEGMENT
#define LC_SEGMENT LC_SEGMENT_64
#undef MH_MAGIC
#define MH_MAGIC MH_MAGIC_64
#define cpu_mach_header mach_header_64
#define segment_command segment_command_64
#else
#define cpu_mach_header mach_header
#endif
class ScopedMMap
{
public:
ScopedMMap(const char *file): buf(NULL) {
fd = open(file, O_RDONLY);
if (fd < 0)
return;
struct stat st;
if (fstat(fd, &st) < 0)
return;
size = st.st_size;
buf = (char *)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
}
~ScopedMMap() {
if (buf)
munmap(buf, size);
if (fd >= 0)
close(fd);
}
operator char *() { return buf; }
int getFd() { return fd; }
private:
int fd;
char *buf;
size_t size;
};
static void
preload(const char *file)
{
ScopedMMap buf(file);
char *base = buf;
if (!base)
return;
// An OSX binary might either be a fat (universal) binary or a
// Mach-O binary. A fat binary actually embeds several Mach-O
// binaries. If we have a fat binary, find the offset where the
// Mach-O binary for our CPU type can be found.
struct fat_header *fh = (struct fat_header *)base;
if (OSSwapBigToHostInt32(fh->magic) == FAT_MAGIC) {
uint32_t nfat_arch = OSSwapBigToHostInt32(fh->nfat_arch);
struct fat_arch *arch = (struct fat_arch *)&buf[sizeof(struct fat_header)];
for (; nfat_arch; arch++, nfat_arch--) {
if (OSSwapBigToHostInt32(arch->cputype) == CPU_TYPE) {
base += OSSwapBigToHostInt32(arch->offset);
break;
}
}
if (base == buf)
return;
}
// Check Mach-O magic in the Mach header
struct cpu_mach_header *mh = (struct cpu_mach_header *)base;
if (mh->magic != MH_MAGIC)
return;
// The Mach header is followed by a sequence of load commands.
// Each command has a header containing the command type and the
// command size. LD_SEGMENT commands describes how the dynamic
// loader is going to map the file in memory. We use that
// information to find the biggest offset from the library that
// will be mapped in memory.
char *cmd = &base[sizeof(struct cpu_mach_header)];
off_t end = 0;
for (uint32_t ncmds = mh->ncmds; ncmds; ncmds--) {
struct segment_command *sh = (struct segment_command *)cmd;
if (sh->cmd != LC_SEGMENT)
continue;
if (end < sh->fileoff + sh->filesize)
end = sh->fileoff + sh->filesize;
cmd += sh->cmdsize;
}
// Let the kernel read ahead what the dynamic loader is going to
// map in memory soon after. The F_RDADVISE fcntl is equivalent
// to Linux' readahead() system call.
if (end > 0) {
struct radvisory ra;
ra.ra_offset = (base - buf);
ra.ra_count = end;
fcntl(buf.getFd(), F_RDADVISE, &ra);
}
}
static const mach_header* sXULLibImage;
static void
ReadDependentCB(const char *aDependentLib, PRBool do_preload)
ReadDependentCB(const char *aDependentLib)
{
if (do_preload)
preload(aDependentLib);
(void) NSAddImage(aDependentLib,
NSADDIMAGE_OPTION_RETURN_ON_ERROR |
NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME);

Просмотреть файл

@ -70,34 +70,11 @@ AppendDependentLib(HINSTANCE libHandle)
}
static void
preload(LPCWSTR dll)
{
HANDLE fd = CreateFileW(dll, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
char buf[64 * 1024];
if (fd == INVALID_HANDLE_VALUE)
return;
DWORD dwBytesRead;
// Do dummy reads to trigger kernel-side readhead via FILE_FLAG_SEQUENTIAL_SCAN.
// Abort when underfilling because during testing the buffers are read fully
// A buffer that's not keeping up would imply that readahead isn't working right
while (ReadFile(fd, buf, sizeof(buf), &dwBytesRead, NULL) && dwBytesRead == sizeof(buf))
/* Nothing */;
CloseHandle(fd);
}
static void
ReadDependentCB(const char *aDependentLib, PRBool do_preload)
ReadDependentCB(const char *aDependentLib)
{
wchar_t wideDependentLib[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, aDependentLib, -1, wideDependentLib, MAX_PATH);
if (do_preload)
preload(wideDependentLib);
HINSTANCE h =
LoadLibraryExW(wideDependentLib, NULL, MOZ_LOADLIBRARY_FLAGS);

Просмотреть файл

@ -55,13 +55,6 @@
#endif
static XPCOMFunctions xpcomFunctions;
static PRBool do_preload = PR_FALSE;
extern "C"
void XPCOMGlueEnablePreload()
{
do_preload = PR_TRUE;
}
extern "C"
nsresult XPCOMGlueStartup(const char* xpcomFile)
@ -135,7 +128,7 @@ XPCOMGlueLoadDependentLibs(const char *xpcomDir, DependentLibsCallback cb)
snprintf(buffer2, sizeof(buffer2),
"%s" XPCOM_FILE_PATH_SEPARATOR "%s",
xpcomDir, buffer);
cb(buffer2, do_preload);
cb(buffer2);
}
fclose(flist);

Просмотреть файл

@ -47,12 +47,6 @@
* The following functions are only available in the standalone glue.
*/
/**
* Enabled preloading of dynamically loaded libraries
*/
extern "C" NS_HIDDEN_(void)
XPCOMGlueEnablePreload();
/**
* Initialize the XPCOM glue by dynamically linking against the XPCOM
* shared library indicated by xpcomFile.

Просмотреть файл

@ -317,13 +317,6 @@ sub do_copyfile
}
}
unlink("$destpath$destname$destsuffix") if ( -e "$destpath$destname$destsuffix");
# If source is a symbolic link pointing in the same directory, create a
# symbolic link
if ((-l "$srcpath$srcname$srcsuffix") && (readlink("$srcpath$srcname$srcsuffix") !~ /\//)) {
symlink(readlink("$srcpath$srcname$srcsuffix"), "$destpath$destname$destsuffix") ||
die "Error: copy of symbolic link $srcpath$srcname$srcsuffix failed ($package, $component, $lineno): $!. Exiting...\n";
return;
}
copy ("$srcpath$srcname$srcsuffix", "$destpath$destname$destsuffix") ||
die "Error: copy of file $srcpath$srcname$srcsuffix failed ($package, $component, $lineno): $!. Exiting...\n";