Merge m-c to m-i

This commit is contained in:
Joe Drew 2011-06-28 12:21:04 -04:00
commit 075aa11a02
20 changed files with 434 additions and 72 deletions

View File

@ -88,6 +88,10 @@ endif
include $(topsrcdir)/ipc/app/defs.mk
DEFINES += -DMOZ_CHILD_PROCESS_NAME=$(MOZ_CHILD_PROCESS_NAME)
ifdef WIN32_OLD_STYLE_JEMALLOC
DEFINES += -DWIN32_OLD_STYLE_JEMALLOC=1
endif
ifdef MOZ_PKG_MANIFEST_P
MOZ_PKG_MANIFEST = package-manifest

View File

@ -63,7 +63,15 @@
@BINPATH@/@MOZ_CHILD_PROCESS_NAME@
#endif
#ifdef XP_WIN32
#ifndef MOZ_MEMORY
#ifdef MOZ_MEMORY
#ifdef WIN32_OLD_STYLE_JEMALLOC
@BINPATH@/mozcrt19.dll
@BINPATH@/mozcpp19.dll
#else
@BINPATH@/jemalloc.dll
#endif
#endif
#else
#if _MSC_VER == 1400
@BINPATH@/Microsoft.VC80.CRT.manifest
@BINPATH@/msvcm80.dll
@ -78,10 +86,7 @@
@BINPATH@/msvcp100.dll
@BINPATH@/msvcr100.dll
#endif
#else
@BINPATH@/mozcrt19.dll
@BINPATH@/mozcpp19.dll
#endif
#endif
[browser]

View File

@ -633,6 +633,8 @@ MSMANIFEST_TOOL = @MSMANIFEST_TOOL@
WIN32_REDIST_DIR = @WIN32_REDIST_DIR@
WIN32_CRT_SRC_DIR = @WIN32_CRT_SRC_DIR@
MOZ_MEMORY_LDFLAGS = @MOZ_MEMORY_LDFLAGS@
WIN32_OLD_STYLE_JEMALLOC = @WIN32_OLD_STYLE_JEMALLOC@
WIN32_CRT_LIBS = @WIN32_CRT_LIBS@
MOZ_CRT_CPU_ARCH = @MOZ_CRT_CPU_ARCH@
# This is for custom CRT building

View File

@ -195,14 +195,6 @@ OS_CXXFLAGS += -FR
endif
else # ! MOZ_DEBUG
# We don't build a static CRT when building a custom CRT,
# it appears to be broken. So don't link to jemalloc if
# the Makefile wants static CRT linking.
ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_)
# Disable default CRT libs and add the right lib path for the linker
OS_LDFLAGS += $(MOZ_MEMORY_LDFLAGS)
endif
# MOZ_DEBUG_SYMBOLS generates debug symbols in separate PDB files.
# Used for generating an optimized build with debugging symbols.
# Used in the Windows nightlies to generate symbols for crash reporting.
@ -241,6 +233,15 @@ endif
endif # NS_TRACE_MALLOC
endif # MOZ_DEBUG
# We don't build a static CRT when building a custom CRT,
# it appears to be broken. So don't link to jemalloc if
# the Makefile wants static CRT linking.
ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_)
# Disable default CRT libs and add the right lib path for the linker
OS_LDFLAGS += $(MOZ_MEMORY_LDFLAGS)
endif
endif # WINNT && !GNU_CC
#

View File

@ -838,7 +838,9 @@ ifndef NO_COMPONENTS_MANIFEST
endif
else # ! IS_COMPONENT
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
ifndef NO_INSTALL_IMPORT_LIBRARY
$(INSTALL) $(IFLAGS2) $(IMPORT_LIBRARY) $(DIST)/lib
endif
else
$(INSTALL) $(IFLAGS2) $(SHARED_LIBRARY) $(DIST)/lib
endif

View File

@ -7403,10 +7403,16 @@ else
*-mingw*)
AC_DEFINE(MOZ_MEMORY_WINDOWS)
dnl This is sort of awful. Will revisit if we add support for more versions
if test "$CC_VERSION" != "14.00.50727.762" -a "$CC_VERSION" != "15.00.30729.01"; then
AC_MSG_ERROR([Building jemalloc requires exactly Visual C++ 2005 SP1 or 2008 SP1 currently.])
if test "$CC_VERSION" == "14.00.50727.762" -o "$CC_VERSION" == "15.00.30729.01"; then
WIN32_OLD_STYLE_JEMALLOC=1
AC_DEFINE(WIN32_OLD_STYLE_JEMALLOC)
elif test "$CC_VERSION" == "16.00.30319.01" -o "$CC_VERSION" == "16.00.40219.01"; then
WIN32_NEW_STYLE_JEMALLOC=1
AC_DEFINE(WIN32_NEW_STYLE_JEMALLOC)
else
AC_MSG_ERROR([Building jemalloc requires exactly Visual C++ 2005 SP1 or 2008 SP1 or 2010 currently.])
fi
if test -z "$WIN32_CRT_SRC_DIR"; then
if test -z "$WIN32_CRT_SRC_DIR" -a -n "$WIN32_OLD_STYLE_JEMALLOC"; then
if test -z "$VCINSTALLDIR" -o ! -d "$VCINSTALLDIR"; then
AC_MSG_ERROR([When building jemalloc, set WIN32_CRT_SRC_DIR to the path to the Visual C++ CRT source (usually VCINSTALLDIR\crt\src, but VCINSTALLDIR is not set, so I can't autodetect it for you).])
else
@ -7428,13 +7434,22 @@ else
AC_SUBST(MOZ_CRT_CPU_ARCH)
if test ! -d "$WIN32_CRT_SRC_DIR"; then
AC_MSG_ERROR([Invalid Win32 CRT source directory: ${WIN32_CRT_SRC_DIR}])
if test -n "$WIN32_OLD_STYLE_JEMALLOC"; then
if test ! -d "$WIN32_CRT_SRC_DIR"; then
AC_MSG_ERROR([Invalid Win32 CRT source directory: ${WIN32_CRT_SRC_DIR}])
fi
WIN32_CRT_SRC_DIR=`cd "$WIN32_CRT_SRC_DIR" && pwd -W`
_objdir_win=`pwd -W`
WIN32_CUSTOM_CRT_DIR="$_objdir_win/memory/jemalloc/crtsrc/build/$MOZ_CRT_CPU_ARCH"
MOZ_MEMORY_LDFLAGS="-MANIFEST:NO -LIBPATH:\"$WIN32_CUSTOM_CRT_DIR\" -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt19 -DEFAULTLIB:mozcpp19"
else
MOZ_MEMORY_LDFLAGS='-MANIFEST:NO -LIBPATH:$(DIST)/lib -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt'
if test -z "$MOZ_DEBUG"; then
WIN32_CRT_LIBS="msvcrt.lib msvcprt.lib"
else
WIN32_CRT_LIBS="msvcrtd.lib msvcprtd.lib"
fi
fi
WIN32_CRT_SRC_DIR=`cd "$WIN32_CRT_SRC_DIR" && pwd -W`
_objdir_win=`pwd -W`
WIN32_CUSTOM_CRT_DIR="$_objdir_win/memory/jemalloc/crtsrc/build/$MOZ_CRT_CPU_ARCH"
MOZ_MEMORY_LDFLAGS="-MANIFEST:NO -LIBPATH:\"$WIN32_CUSTOM_CRT_DIR\" -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt19 -DEFAULTLIB:mozcpp19"
dnl Also pass this to NSPR/NSS
DLLFLAGS="$DLLFLAGS $MOZ_MEMORY_LDFLAGS"
export DLLFLAGS
@ -7453,6 +7468,8 @@ else
fi # MOZ_MEMORY
AC_SUBST(MOZ_MEMORY)
AC_SUBST(MOZ_MEMORY_LDFLAGS)
AC_SUBST(WIN32_OLD_STYLE_JEMALLOC)
AC_SUBST(WIN32_CRT_LIBS)
AC_SUBST(WIN32_CRT_SRC_DIR)
dnl Need to set this for make because NSS doesn't have configure
AC_SUBST(DLLFLAGS)

View File

@ -183,14 +183,7 @@ NS_IMETHODIMP
nsHTMLOptionElement::GetSelected(PRBool* aValue)
{
NS_ENSURE_ARG_POINTER(aValue);
*aValue = PR_FALSE;
// If we haven't been explictly selected or deselected, use our default value
if (!mSelectedChanged) {
return GetDefaultSelected(aValue);
}
*aValue = mIsSelected;
*aValue = Selected();
return NS_OK;
}
@ -257,6 +250,23 @@ nsHTMLOptionElement::GetIndex(PRInt32* aIndex)
return NS_OK;
}
bool
nsHTMLOptionElement::Selected() const
{
// If we haven't been explictly selected or deselected, use our default value
if (!mSelectedChanged) {
return DefaultSelected();
}
return mIsSelected;
}
bool
nsHTMLOptionElement::DefaultSelected() const
{
return HasAttr(kNameSpaceID_None, nsGkAtoms::selected);
}
nsChangeHint
nsHTMLOptionElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
PRInt32 aModType) const
@ -341,18 +351,10 @@ nsEventStates
nsHTMLOptionElement::IntrinsicState() const
{
nsEventStates state = nsGenericHTMLElement::IntrinsicState();
// Nasty hack because we need to call an interface method, and one that
// toggles some of our hidden internal state at that! Would that we could
// use |mutable|.
PRBool selected;
const_cast<nsHTMLOptionElement*>(this)->GetSelected(&selected);
if (selected) {
if (Selected()) {
state |= NS_EVENT_STATE_CHECKED;
}
// Also calling a non-const interface method (for :default)
const_cast<nsHTMLOptionElement*>(this)->GetDefaultSelected(&selected);
if (selected) {
if (DefaultSelected()) {
state |= NS_EVENT_STATE_DEFAULT;
}
@ -475,9 +477,7 @@ nsHTMLOptionElement::CopyInnerTo(nsGenericElement* aDest) const
NS_ENSURE_SUCCESS(rv, rv);
if (aDest->GetOwnerDoc()->IsStaticDocument()) {
PRBool selected = PR_FALSE;
const_cast<nsHTMLOptionElement*>(this)->GetSelected(&selected);
static_cast<nsHTMLOptionElement*>(aDest)->SetSelected(selected);
static_cast<nsHTMLOptionElement*>(aDest)->SetSelected(Selected());
}
return NS_OK;
}

View File

@ -80,6 +80,9 @@ public:
using nsGenericElement::GetText;
NS_DECL_NSIDOMHTMLOPTIONELEMENT
bool Selected() const;
bool DefaultSelected() const;
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
JSObject *aObj, PRUint32 argc, jsval *argv);

View File

@ -494,7 +494,9 @@ NS_IMETHODIMP nsWebBrowser::SetItemType(PRInt32 aItemType)
NS_ENSURE_TRUE((aItemType == typeContentWrapper || aItemType == typeChromeWrapper), NS_ERROR_FAILURE);
mContentType = aItemType;
if (mDocShellAsItem)
mDocShellAsItem->SetItemType(mContentType == typeChromeWrapper ? typeChrome : typeContent);
mDocShellAsItem->SetItemType(mContentType == typeChromeWrapper
? static_cast<PRInt32>(typeChrome)
: static_cast<PRInt32>(typeContent));
return NS_OK;
}
@ -804,7 +806,8 @@ NS_IMETHODIMP nsWebBrowser::SetProperty(PRUint32 aId, PRUint32 aValue)
case nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER:
{
NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG);
SetItemType(aValue ? typeChromeWrapper : typeContentWrapper);
SetItemType(aValue ? static_cast<PRInt32>(typeChromeWrapper)
: static_cast<PRInt32>(typeContentWrapper));
}
break;
default:

View File

@ -944,9 +944,12 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent,
}
}
newDocShell->LoadURI(uriToLoad, loadInfo,
windowIsNew ? nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD :
nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
newDocShell->LoadURI(uriToLoad,
loadInfo,
windowIsNew
? static_cast<PRUint32>(nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD)
: static_cast<PRUint32>(nsIWebNavigation::LOAD_FLAGS_NONE),
PR_TRUE);
}
// Copy the current session storage for the current domain.

View File

@ -195,14 +195,6 @@ OS_CXXFLAGS += -FR
endif
else # ! MOZ_DEBUG
# We don't build a static CRT when building a custom CRT,
# it appears to be broken. So don't link to jemalloc if
# the Makefile wants static CRT linking.
ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_)
# Disable default CRT libs and add the right lib path for the linker
OS_LDFLAGS += $(MOZ_MEMORY_LDFLAGS)
endif
# MOZ_DEBUG_SYMBOLS generates debug symbols in separate PDB files.
# Used for generating an optimized build with debugging symbols.
# Used in the Windows nightlies to generate symbols for crash reporting.
@ -241,6 +233,15 @@ endif
endif # NS_TRACE_MALLOC
endif # MOZ_DEBUG
# We don't build a static CRT when building a custom CRT,
# it appears to be broken. So don't link to jemalloc if
# the Makefile wants static CRT linking.
ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_)
# Disable default CRT libs and add the right lib path for the linker
OS_LDFLAGS += $(MOZ_MEMORY_LDFLAGS)
endif
endif # WINNT && !GNU_CC
#

View File

@ -838,7 +838,9 @@ ifndef NO_COMPONENTS_MANIFEST
endif
else # ! IS_COMPONENT
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
ifndef NO_INSTALL_IMPORT_LIBRARY
$(INSTALL) $(IFLAGS2) $(IMPORT_LIBRARY) $(DIST)/lib
endif
else
$(INSTALL) $(IFLAGS2) $(SHARED_LIBRARY) $(DIST)/lib
endif

View File

@ -50,6 +50,7 @@ MODULE = jemalloc
VISIBILITY_FLAGS=
ifeq (WINNT,$(OS_TARGET))
ifdef WIN32_OLD_STYLE_JEMALLOC
# Building the CRT from source
CRT_OBJ_DIR = $(CURDIR)/crtsrc
MOZ_CRT_DLL_NAME = mozcrt19
@ -107,6 +108,22 @@ $(MOZ_CRT_DLL): \
# but still export jemalloc.h
EXPORTS = jemalloc.h jemalloc_types.h
else
CSRCS = jemalloc.c
EXPORTS = jemalloc.h jemalloc_types.h
LIBRARY_NAME = jemalloc
FORCE_SHARED_LIB = 1
MOZ_MEMORY_LDFLAGS = # Don't link against ourselves
DEFFILE = $(srcdir)/jemalloc.def
LDFLAGS += -ENTRY:DllMain
NO_INSTALL_IMPORT_LIBRARY = 1
endif
else # Not Windows
MODULE_OPTIMIZE_FLAGS = -O2
@ -144,3 +161,88 @@ include $(topsrcdir)/config/rules.mk
ifeq (Darwin,$(OS_TARGET))
LDFLAGS += -init _jemalloc_darwin_init
endif
ifeq (WINNT,$(OS_TARGET))
ifndef WIN32_OLD_STYLE_JEMALLOC
# Roll our own custom logic here for the import library
###############################################################################
#
# Linking Mozilla itself to jemalloc is not particularly difficult. To do this
# we avoid linking directly to the Microsoft-provided CRT import libraries.
# Instead, we link to our own import library which we generate here. To
# replace the CRT's malloc/free/other memory management symbols we export
# our own versions out of jemalloc.dll. We then take the import library that
# the compiler generates for jemalloc.dll and combine it with the MS CRT import
# libraries. We put our library on the command line first, and the CRT symbols
# are discarded in favor of our versions!
#
# Unfortunately that was too easy. The CRT import library is not a standard
# import library that contains a list of symbols and whatnot. It also includes
# object files that are linked into generated programs. One of these,
# crtdll.obj is (as one might expect) linked into all DLLs that link against
# the CRT. This file does things like run static C++ constructors when the
# DLL is attached, call DllMain, etc.
#
# In the CRT source all malloc/free calls are made to malloc_crt and free_crt.
# In debug builds these are both defined to malloc_dbg and free_dbg. In opt
# builds malloc_crt is an actual function, implemented and exposed from the
# CRT. free_crt is, however, defined to be just plain old free. This works
# fine inside the CRT where malloc_crt and free operate on the same heap.
# Outside the CRT malloc_crt is in the CRT's heap, but free is in jemalloc's
# heap. This causes much pain at shutdown :-(
#
# The obvious solution here is to override malloc_crt too. Unfortunately,
# that doesn't work because the CRT expects to be able to call msize on this
# piece of memory deep inside the CRT, which will fail because it'll call the
# CRT's msize on a pointer in jemalloc's heap.
#
# Our solution to this is quite devious. We take apart the CRT's import lib
# and remove the problematic object file. We then poke at the object file's
# symbol table and replace '__imp__free' (which means grab free from some
# other DLL) with '__imp__frex'. Then we define our own dummy no-op function
# in jemalloc.dll and export it as frex. Then we put the CRT import lib
# back together with the patched crtdll.obj, glue it to the end of jemalloc's
# import library and link the rest of Mozilla to that.
#
# The result? A binary that uses jemalloc, doesn't crash, and leaks a tiny
# amount of memory (32 words per DLL in the 2010 CRT) at shutdown.
#
###############################################################################
libs:: $(DIST)/lib/mozcrt.lib
$(DIST)/lib/mozcrt.lib:: mozcrt.lib
$(INSTALL) $(IFLAGS2) mozcrt.lib $(DIST)/lib
# And finally combine that with the jemalloc import library to get an import
# library that has our malloc/free/etc and the CRT's everything else
mozcrt.lib:: $(IMPORT_LIBRARY) msvc_modified.lib
lib -OUT:$@ $^
# Put the fixed object file back in
msvc_modified.lib:: msvc_removed.lib crtdll_fixed.obj
lib -OUT:$@ $^
# Fix the object file
crtdll_fixed.obj:: crtdll.obj
$(PYTHON) $(srcdir)/fixcrt.py
# Find the path of crtdll.obj
CRTDLL_FULLPATH=$(subst \,\\,$(shell lib -list msvc_combined.lib | grep crtdll\\.obj))
# Remove the broken object file, only after we have extracted it
msvc_removed.lib:: msvc_combined.lib crtdll.obj
lib -OUT:$@ msvc_combined.lib -REMOVE:$(CRTDLL_FULLPATH)
# Extract the broken object file out of the combined library
crtdll.obj:: msvc_combined.lib
lib -OUT:$@ $^ -EXTRACT:$(CRTDLL_FULLPATH)
# Grab both CRT libraries and combine them into one library to simplify things
msvc_combined.lib::
lib -OUT:$@ $(WIN32_CRT_LIBS)
endif
endif

44
memory/jemalloc/fixcrt.py Normal file
View File

@ -0,0 +1,44 @@
# ***** 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 build system.
#
# 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):
# Kyle Huey <me@kylehuey.com>
#
# 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 *****
from __future__ import with_statement
with open('crtdll.obj', 'rb') as infile:
data = infile.read()
with open('crtdll_fixed.obj', 'wb') as outfile:
data = data.replace('__imp__free', '__imp__frex')
outfile.write(data)

View File

@ -206,8 +206,17 @@
#ifdef MOZ_MEMORY_WINDOWS
/* XXXkhuey switch to not patching the CRT for jemalloc all the time */
/* We use ifndef NEW_STYLE here because when we're build as part of the CRT
we don't have access to AC_DEFINEs */
#ifndef WIN32_NEW_STYLE_JEMALLOC
#include <cruntime.h>
#include <internal.h>
#else
/* Some defines from the CRT internal headers that we need here. */
#define _CRT_SPINCOUNT 5000
#define __crtInitCritSecAndSpinCount InitializeCriticalSectionAndSpinCount
#endif
#include <io.h>
#include <windows.h>
@ -5717,14 +5726,18 @@ malloc_shutdown()
#define free(a) moz_free(a)
#endif
#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC)
#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC) || defined(WIN32_NEW_STYLE_JEMALLOC)
inline void sys_free(void* ptr) {return free(ptr);}
#define malloc(a) je_malloc(a)
#define valloc(a) je_valloc(a)
#define calloc(a, b) je_calloc(a, b)
#define realloc(a, b) je_realloc(a, b)
#define free(a) je_free(a)
#if defined(WIN32_NEW_STYLE_JEMALLOC)
#define memalign(a, b) je_memalign(a, b)
#endif
#define posix_memalign(a, b, c) je_posix_memalign(a, b, c)
#define malloc_usable_size(a) je_malloc_usable_size(a)
char *je_strndup(const char *src, size_t len) {
char* dst = (char*)je_malloc(len + 1);
@ -6459,3 +6472,59 @@ void *(*__memalign_hook)(size_t alignment, size_t size) = MEMALIGN;
*/
# error "Interposing malloc is unsafe on this system without libc malloc hooks."
#endif
#ifdef WIN32_NEW_STYLE_JEMALLOC
/*
* In the new style jemalloc integration jemalloc is built as a separate
* shared library. Since we're no longer hooking into the CRT binary,
* we need to initialize the heap at the first opportunity we get.
* DLL_PROCESS_ATTACH in DllMain is that opportunity.
*/
BOOL APIENTRY DllMain(HINSTANCE hModule,
DWORD reason,
LPVOID lpReserved)
{
switch (reason) {
case DLL_PROCESS_ATTACH:
/* Don't force the system to page DllMain back in every time
* we create/destroy a thread */
DisableThreadLibraryCalls(hModule);
/* Initialize the heap */
malloc_init_hard();
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
/*
* There's a fun allocator mismatch in (at least) the VS 2010 CRT
* (see the giant comment in this directory's Makefile.in
* that gets redirected here to avoid a crash on shutdown.
*/
void
je_dumb_free_thunk(void *ptr)
{
return; /* shutdown leaks that we don't care about */
}
#include <wchar.h>
/*
* We also need to provide our own impl of wcsdup so that we don't ask
* the CRT for memory from its heap (which will then be unfreeable).
*/
wchar_t *je_wcsdup(const wchar_t *src)
{
size_t len = wcslen(src);
wchar_t* dst = (wchar_t*)je_malloc((len + 1) * sizeof(wchar_t));
if(dst)
wcsncpy(dst, src, len + 1);
return dst;
}
#endif

View File

@ -0,0 +1,53 @@
; ***** 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 Initial Developer of this code is the Mozilla Foundation
;
; Portions created by the Initial Developer are Copyright (C) 2011
; the Initial Developer. All Rights Reserved.
;
; Contributor(s):
; Kyle Huey <me@kylehuey.com>
;
; Alternatively, the contents of this file may be used under the terms of
; either of 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 *****
LIBRARY jemalloc.dll
EXPORTS
; symbols that are actually useful
malloc=je_malloc
valloc=je_valloc
calloc=je_calloc
realloc=je_realloc
free=je_free
memalign=je_memalign
posix_memalign=je_posix_memalign
strndup=je_strndup
strdup=je_strdup
wcsdup=je_wcsdup
malloc_usable_size=je_malloc_usable_size
jemalloc_stats
; A hack to work around the CRT (see giant comment in Makefile.in)
frex=je_dumb_free_thunk

View File

@ -50,15 +50,21 @@ void free(void *ptr);
int posix_memalign(void **memptr, size_t alignment, size_t size);
#endif /* MOZ_MEMORY_DARWIN, MOZ_MEMORY_LINUX */
#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC)
#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC) || defined(WIN32_NEW_STYLE_JEMALLOC)
void *je_malloc(size_t size);
void *je_valloc(size_t size);
void *je_calloc(size_t num, size_t size);
void *je_realloc(void *ptr, size_t size);
void je_free(void *ptr);
void *je_memalign(size_t alignment, size_t size);
int je_posix_memalign(void **memptr, size_t alignment, size_t size);
char *je_strndup(const char *src, size_t len);
char *je_strdup(const char *src);
#if defined(MOZ_MEMORY_ANDROID)
size_t je_malloc_usable_size(void *ptr);
#else
size_t je_malloc_usable_size(const void *ptr);
#endif
#endif
/* Linux has memalign and malloc_usable_size */

View File

@ -86,6 +86,7 @@
#define strdup(a) je_strdup(a)
#define strndup(a, b) je_strndup(a, b)
#define posix_memalign(a, b, c) je_posix_memalign(a, b, c)
#define malloc_usable_size(a) je_malloc_usable_size(a)
#endif
void

View File

@ -1497,27 +1497,65 @@ NS_IMETHODIMP
nsNSSCertificateDB::FindCertByEmailAddress(nsISupports *aToken, const char *aEmailAddress, nsIX509Cert **_retval)
{
nsNSSShutDownPreventionLock locker;
CERTCertificate *any_cert = CERT_FindCertByNicknameOrEmailAddr(CERT_GetDefaultCertDB(), (char*)aEmailAddress);
if (!any_cert)
return NS_ERROR_FAILURE;
nsCOMPtr<nsINSSComponent> inss;
nsRefPtr<nsCERTValInParamWrapper> survivingParams;
nsresult nsrv;
if (nsNSSComponent::globalConstFlagUsePKIXVerification) {
inss = do_GetService(kNSSComponentCID, &nsrv);
if (!inss)
return nsrv;
nsrv = inss->GetDefaultCERTValInParam(survivingParams);
if (NS_FAILED(nsrv))
return nsrv;
}
CERTCertificateCleaner certCleaner(any_cert);
// any_cert now contains a cert with the right subject, but it might not have the correct usage
CERTCertList *certlist = CERT_CreateSubjectCertList(
nsnull, CERT_GetDefaultCertDB(), &any_cert->derSubject, PR_Now(), PR_TRUE);
CERTCertList *certlist = PK11_FindCertsFromEmailAddress(aEmailAddress, nsnull);
if (!certlist)
return NS_ERROR_FAILURE;
// certlist now contains certificates with the right email address,
// but they might not have the correct usage or might even be invalid
CERTCertListCleaner listCleaner(certlist);
if (SECSuccess != CERT_FilterCertListByUsage(certlist, certUsageEmailRecipient, PR_FALSE))
return NS_ERROR_FAILURE;
if (CERT_LIST_END(CERT_LIST_HEAD(certlist), certlist))
return NS_ERROR_FAILURE; // no certs found
CERTCertListNode *node;
// search for a valid certificate
for (node = CERT_LIST_HEAD(certlist);
!CERT_LIST_END(node, certlist);
node = CERT_LIST_NEXT(node)) {
if (!nsNSSComponent::globalConstFlagUsePKIXVerification) {
if (CERT_VerifyCert(CERT_GetDefaultCertDB(), node->cert,
PR_TRUE, certUsageEmailRecipient, PR_Now(), nsnull, nsnull) == SECSuccess) {
// found a valid certificate
break;
}
}
else {
CERTValOutParam cvout[1];
cvout[0].type = cert_po_end;
if (CERT_PKIXVerifyCert(node->cert, certificateUsageEmailRecipient,
survivingParams->GetRawPointerForNSS(),
cvout, nsnull)
== SECSuccess) {
// found a valid certificate
break;
}
}
}
if (CERT_LIST_END(node, certlist)) {
// no valid cert found
return NS_ERROR_FAILURE;
nsNSSCertificate *nssCert = nsNSSCertificate::Create(CERT_LIST_HEAD(certlist)->cert);
}
// node now contains the first valid certificate with correct usage
nsNSSCertificate *nssCert = nsNSSCertificate::Create(node->cert);
if (!nssCert)
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -83,10 +83,12 @@ SDK_SUFFIX = $(PKG_SUFFIX)
SDK = $(SDK_PATH)$(PKG_BASENAME).sdk$(SDK_SUFFIX)
# JavaScript Shell packaging
ifndef LIBXUL_SDK
JSSHELL_BINS = \
$(DIST)/bin/js$(BIN_SUFFIX) \
$(DIST)/bin/$(LIB_PREFIX)nspr4$(DLL_SUFFIX) \
$(NULL)
ifndef MOZ_NATIVE_NSPR
JSSHELL_BINS += $(DIST)/bin/$(LIB_PREFIX)nspr4$(DLL_SUFFIX)
ifeq ($(OS_ARCH),WINNT)
JSSHELL_BINS += $(DIST)/bin/mozcrt19$(DLL_SUFFIX)
else
@ -95,7 +97,9 @@ JSSHELL_BINS += \
$(DIST)/bin/$(LIB_PREFIX)plc4$(DLL_SUFFIX) \
$(NULL)
endif
endif # MOZ_NATIVE_NSPR
MAKE_JSSHELL = $(ZIP) -9j $(PKG_JSSHELL) $(JSSHELL_BINS)
endif # LIBXUL_SDK
MAKE_PACKAGE = $(error What is a $(MOZ_PKG_FORMAT) package format?);
_ABS_DIST = $(call core_abspath,$(DIST))
@ -683,10 +687,12 @@ endif
ifdef MOZ_PKG_REMOVALS
$(SYSINSTALL) $(IFLAGS1) $(MOZ_PKG_REMOVALS_GEN) $(DIST)/$(STAGEPATH)$(MOZ_PKG_DIR)$(_BINPATH)
endif # MOZ_PKG_REMOVALS
ifndef LIBXUL_SDK
# Package JavaScript Shell
@echo "Packaging JavaScript Shell..."
$(RM) $(PKG_JSSHELL)
$(MAKE_JSSHELL)
endif # LIBXUL_SDK
make-package: stage-package $(PACKAGE_XULRUNNER) make-sourcestamp-file
@echo "Compressing..."