diff --git a/config/config.mk b/config/config.mk index 3e354b92dad..953a182a024 100644 --- a/config/config.mk +++ b/config/config.mk @@ -526,7 +526,7 @@ OS_COMPILE_CMMFLAGS += -fobjc-exceptions endif COMPILE_CFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS) -COMPILE_CXXFLAGS = $(VISIBILITY_FLAGS) $(STL_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS) +COMPILE_CXXFLAGS = $(STL_FLAGS) $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS) COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS) COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS) diff --git a/config/gcc-stl-wrapper.template.h b/config/gcc-stl-wrapper.template.h index 739f6651821..6b1a7184873 100644 --- a/config/gcc-stl-wrapper.template.h +++ b/config/gcc-stl-wrapper.template.h @@ -45,13 +45,23 @@ # error "STL code can only be used with -fno-exceptions" #endif +// Silence "warning: #include_next is a GCC extension" +#pragma GCC system_header + +// mozalloc.h wants ; break the cycle by always explicitly +// including here. NB: this is a tad sneaky. Sez the gcc docs: +// +// `#include_next' does not distinguish between and "file" +// inclusion, nor does it check that the file you specify has the +// same name as the current file. It simply looks for the file +// named, starting with the directory in the search path after the +// one where the current file was found. +#include_next + // See if we're in code that can use mozalloc. NB: this duplicates // code in nscore.h because nscore.h pulls in prtypes.h, and chromium // can't build with that being included before base/basictypes.h. #if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC) -# include // to give mozalloc std::bad_alloc -# include // to give mozalloc malloc/free decls -# include # include "mozilla/mozalloc.h" #else # error "STL code can only be used with infallible ::operator new()" @@ -78,8 +88,8 @@ // these __throw_*() functions will always throw exceptions (shades of // -fshort-wchar). We don't want that and so define our own inlined // __throw_*(). -#ifndef mozilla_functexcept_h -# include "mozilla/functexcept.h" +#ifndef mozilla_throw_gcc_h +# include "mozilla/throw_gcc.h" #endif #endif // if mozilla_${HEADER}_h diff --git a/config/make-stl-wrappers.py b/config/make-stl-wrappers.py index 106dbd6547b..700cd864165 100644 --- a/config/make-stl-wrappers.py +++ b/config/make-stl-wrappers.py @@ -62,7 +62,8 @@ def main(outdir, compiler, template_file, header_list_file): os.mkdir(outdir) template = open(template_file, 'r').read() - + path_to_new = header_path('new', compiler) + for header in open(header_list_file, 'r'): header = header.rstrip() if 0 == len(header) or is_comment(header): @@ -72,7 +73,8 @@ def main(outdir, compiler, template_file, header_list_file): try: f = open(os.path.join(outdir, header), 'w') f.write(string.Template(template).substitute(HEADER=header, - HEADER_PATH=path)) + HEADER_PATH=path, + NEW_HEADER_PATH=path_to_new)) finally: f.close() diff --git a/config/msvc-stl-wrapper.template.h b/config/msvc-stl-wrapper.template.h index 97d45c617c8..764e29f4b05 100644 --- a/config/msvc-stl-wrapper.template.h +++ b/config/msvc-stl-wrapper.template.h @@ -45,13 +45,22 @@ # error "STL code can only be used with -fno-exceptions" #endif +// Code built with !_HAS_EXCEPTIONS calls std::_Throw(), but the win2k +// CRT doesn't export std::_Throw(). So we define it. +#ifndef mozilla_Throw_h +# include "mozilla/throw_msvc.h" +#endif + +// Code might include before other wrapped headers, but +// includes and so we want to wrap it. But mozalloc.h +// wants also, so we break the cycle by always explicitly +// including here. +#include <${NEW_HEADER_PATH}> + // See if we're in code that can use mozalloc. NB: this duplicates // code in nscore.h because nscore.h pulls in prtypes.h, and chromium // can't build with that being included before base/basictypes.h. #if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC) -# include // to give mozalloc std::bad_alloc -# include // to give mozalloc malloc/free decls -# include # include "mozilla/mozalloc.h" #else # error "STL code can only be used with infallible ::operator new()" diff --git a/config/stl-headers b/config/stl-headers index 69790c9a1eb..5c4493a228b 100644 --- a/config/stl-headers +++ b/config/stl-headers @@ -12,8 +12,17 @@ # safety of for gcc and MSVC". # +new + # FIXME: these headers haven't been reviewed yet, but we use them -# unsafely in modules/libpr0n, so we might as well prevent it from +# unsafely in Gecko, so we might as well prevent them from # throwing exceptions algorithm +deque +iostream +list +map +memory +stack +string vector diff --git a/embedding/browser/gtk/tests/Makefile.in b/embedding/browser/gtk/tests/Makefile.in index 9aec4673576..292d12a5b28 100644 --- a/embedding/browser/gtk/tests/Makefile.in +++ b/embedding/browser/gtk/tests/Makefile.in @@ -76,6 +76,7 @@ include $(topsrcdir)/config/rules.mk LIBS += $(XPCOM_STANDALONE_GLUE_LDOPTS) DEFINES += -DXPCOM_GLUE +STL_FLAGS = CXXFLAGS += $(MOZ_GTK2_CFLAGS) diff --git a/js/src/config/config.mk b/js/src/config/config.mk index 3e354b92dad..953a182a024 100644 --- a/js/src/config/config.mk +++ b/js/src/config/config.mk @@ -526,7 +526,7 @@ OS_COMPILE_CMMFLAGS += -fobjc-exceptions endif COMPILE_CFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS) -COMPILE_CXXFLAGS = $(VISIBILITY_FLAGS) $(STL_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS) +COMPILE_CXXFLAGS = $(STL_FLAGS) $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS) COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS) COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS) diff --git a/memory/mozalloc/Makefile.in b/memory/mozalloc/Makefile.in index 32fdbae984c..23151f766c4 100644 --- a/memory/mozalloc/Makefile.in +++ b/memory/mozalloc/Makefile.in @@ -44,6 +44,10 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk VISIBILITY_FLAGS= +STL_FLAGS = +ifdef _MSC_VER +STL_FLAGS = -D_HAS_EXCEPTIONS=0 +endif MODULE = mozalloc LIBRARY_NAME = mozalloc @@ -62,11 +66,27 @@ DEFINES += -D_GNU_SOURCE endif EXPORTS_NAMESPACES = mozilla -EXPORTS_mozilla = mozalloc.h mozalloc_macro_wrappers.h mozalloc_oom.h +EXPORTS_mozilla = \ + mozalloc.h \ + mozalloc_abort.h \ + mozalloc_macro_wrappers.h \ + mozalloc_oom.h \ + $(NULL) -CPPSRCS = \ +CPPSRCS = \ mozalloc.cpp \ + mozalloc_abort.cpp \ mozalloc_oom.cpp \ $(NULL) +ifdef WRAP_STL_INCLUDES +ifdef GCC_VERSION +EXPORTS_mozilla += throw_gcc.h +endif +ifdef _MSC_VER +EXPORTS_mozilla += throw_msvc.h +CPPSRCS += throw_msvc.cpp +endif +endif # WRAP_STL_INCLUDES + include $(topsrcdir)/config/rules.mk diff --git a/memory/mozalloc/mozalloc.h b/memory/mozalloc/mozalloc.h index cd42eb89cd7..ed793c22260 100644 --- a/memory/mozalloc/mozalloc.h +++ b/memory/mozalloc/mozalloc.h @@ -41,18 +41,16 @@ #ifndef mozilla_mozalloc_h #define mozilla_mozalloc_h - /* * https://bugzilla.mozilla.org/show_bug.cgi?id=427099 */ -/* - * NB: this header depends on the symbols malloc(), free(), and - * std::bad_alloc. But because this header is used in situations - * where malloc/free have different visibility, we rely on code - * including this header to provide the declarations of malloc/free. - * I.e., we don't #include or on purpose. - */ +#include +#include +#if defined(__cplusplus) +# include +#endif + #if defined(MOZALLOC_EXPORT) // do nothing: it's been defined to __declspec(dllexport) by diff --git a/memory/mozalloc/mozalloc_abort.cpp b/memory/mozalloc/mozalloc_abort.cpp new file mode 100644 index 00000000000..66c082eb0a8 --- /dev/null +++ b/memory/mozalloc/mozalloc_abort.cpp @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: sw=4 ts=4 et : + */ +/* ***** 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 Code + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Jones + * + * 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 ***** */ + +#include +#include // for abort() + +#if defined(_WIN32) +# include // for raise +#elif defined(XP_UNIX) +# include // for _exit +#endif + +#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec)) +# define MOZALLOC_EXPORT __declspec(dllexport) +#endif + +#include "mozilla/mozalloc_abort.h" + +static int gDummyCounter; + +void +mozalloc_abort(const char* const msg) +{ + fputs(msg, stderr); + fputs("\n", stderr); + + // XXX/cjones: most of this function was copied from + // xpcom/base/nsDebugImpl.cpp:Abort(), except that we assume on + // UNIX-like platforms can directly abort() rather than need to go + // through PR_Abort(). we don't want this code to rely on NSPR. + + // FIXME/bug 558928: improve implementation for windows/wince + +#if defined(_WIN32) +# if !defined(WINCE) + //This should exit us + raise(SIGABRT); +# endif + //If we are ignored exit this way.. + _exit(3); +#elif defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS) + abort(); +#else +# warning not attempting to abort() on this platform +#endif + + // Still haven't aborted? Try dereferencing null. + // (Written this way to lessen the likelihood of it being optimized away.) + gDummyCounter += *((int*) 0); // TODO annotation saying we know + // this is crazy + + // Still haven't aborted? Try _exit(). + _exit(127); +} diff --git a/memory/mozalloc/mozalloc_abort.h b/memory/mozalloc/mozalloc_abort.h new file mode 100644 index 00000000000..8ee8f012566 --- /dev/null +++ b/memory/mozalloc/mozalloc_abort.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: sw=4 ts=4 et : + */ +/* ***** 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 Code + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Jones + * + * 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_mozalloc_abort_h +#define mozilla_mozalloc_abort_h + +#if defined(MOZALLOC_EXPORT) +// do nothing: it's been defined to __declspec(dllexport) by +// mozalloc*.cpp on platforms where that's required +#elif defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec)) +# define MOZALLOC_EXPORT __declspec(dllimport) +#elif defined(HAVE_VISIBILITY_ATTRIBUTE) +/* Make sure symbols are still exported even if we're wrapped in a + * |visibility push(hidden)| blanket. */ +# define MOZALLOC_EXPORT __attribute__ ((visibility ("default"))) +#else +# define MOZALLOC_EXPORT +#endif + +/** + * Terminate this process in such a way that breakpad is triggered, if + * at all possible. + */ +MOZALLOC_EXPORT void mozalloc_abort(const char* const msg) NS_NORETURN; + + +#endif /* ifndef mozilla_mozalloc_abort_h */ diff --git a/memory/mozalloc/mozalloc_oom.cpp b/memory/mozalloc/mozalloc_oom.cpp index 8d4878abb20..10b0b7ade54 100644 --- a/memory/mozalloc/mozalloc_oom.cpp +++ b/memory/mozalloc/mozalloc_oom.cpp @@ -38,52 +38,18 @@ * * ***** END LICENSE BLOCK ***** */ -#include // for abort() - -#if defined(_WIN32) -# include // for raise -#elif defined(XP_UNIX) -# include // for _exit -#endif - #if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec)) # define MOZALLOC_EXPORT __declspec(dllexport) #endif +#include "mozilla/mozalloc_abort.h" #include "mozilla/mozalloc_oom.h" -static int gDummyCounter; - void mozalloc_handle_oom() { // NB: this is handle_oom() stage 1, which simply aborts on OOM. // we might proceed to a stage 2 in which an attempt is made to // reclaim memory - - // XXX/cjones: most of this function was copied from - // xpcom/base/nsDebugImpl.cpp:Abort(), except that we assume on - // UNIX-like platforms can directly abort() rather than need to go - // through PR_Abort(). we don't want this code to rely on NSPR. - -#if defined(_WIN32) -# if !defined(WINCE) - //This should exit us - raise(SIGABRT); -# endif - //If we are ignored exit this way.. - _exit(3); -#elif defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS) - abort(); -#else -# warning not attempting to abort() on this platform -#endif - - // Still haven't aborted? Try dereferencing null. - // (Written this way to lessen the likelihood of it being optimized away.) - gDummyCounter += *((int*) 0); // TODO annotation saying we know - // this is crazy - - // Still haven't aborted? Try _exit(). - _exit(127); + mozalloc_abort("out of memory"); } diff --git a/xpcom/glue/functexcept.h b/memory/mozalloc/throw_gcc.h similarity index 66% rename from xpcom/glue/functexcept.h rename to memory/mozalloc/throw_gcc.h index 5492f8dd737..bab83787678 100644 --- a/xpcom/glue/functexcept.h +++ b/memory/mozalloc/throw_gcc.h @@ -1,5 +1,5 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 et : +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: sw=4 ts=4 et : */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -38,127 +38,116 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef mozilla_functexcept_h -#define mozilla_functexcept_h +#ifndef mozilla_throw_gcc_h +#define mozilla_throw_gcc_h -#include -#include -#include +#include // snprintf // For gcc, we define these inline to abort so that we're absolutely // certain that (i) no exceptions are thrown from Gecko; (ii) these // errors are always terminal and caught by breakpad. -// NB: It would be nice to #include "nsDebug.h" and use -// NS_RUNTIMEABORT(), but because this file is used within chromium, -// and nsDebug pulls in nscore, and nscore pulls in prtypes, and -// chromium can't build with prtypes being included before -// base/basictypes, then we have to roll our own aborting impl. - -// Assume that if we're building with gcc, we're on a platform where -// abort() is fatal and triggers breakpad. -#define MOZ_FE_ABORT(_msg) \ - do { \ - fputs(_msg, stderr); \ - fputs("\n", stderr); \ - abort(); \ - } while (0) +#include "mozilla/mozalloc_abort.h" namespace std { +// NB: user code is not supposed to touch the std:: namespace. We're +// doing this after careful review because we want to define our own +// exception throwing semantics. Don't try this at home! + inline void NS_NORETURN __throw_bad_exception(void) { - MOZ_FE_ABORT("fatal: STL threw bad_exception"); + mozalloc_abort("fatal: STL threw bad_exception"); } inline void NS_NORETURN __throw_bad_alloc(void) { - MOZ_FE_ABORT("fatal: STL threw bad_alloc"); + mozalloc_abort("fatal: STL threw bad_alloc"); } inline void NS_NORETURN __throw_bad_cast(void) { - MOZ_FE_ABORT("fatal: STL threw bad_cast"); + mozalloc_abort("fatal: STL threw bad_cast"); } inline void NS_NORETURN __throw_bad_typeid(void) { - MOZ_FE_ABORT("fatal: STL threw bad_typeid"); + mozalloc_abort("fatal: STL threw bad_typeid"); } inline void NS_NORETURN __throw_logic_error(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_domain_error(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_invalid_argument(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_length_error(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_out_of_range(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_runtime_error(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_range_error(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_overflow_error(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_underflow_error(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_ios_failure(const char* msg) { - MOZ_FE_ABORT(msg); + mozalloc_abort(msg); } inline void NS_NORETURN __throw_system_error(int err) { - char error[128]; - snprintf(error, sizeof(error)-1, - "fatal: STL threw system_error: %s (%d)", strerror(err), err); - MOZ_FE_ABORT(error); + char error[128]; + snprintf(error, sizeof(error)-1, + "fatal: STL threw system_error: %s (%d)", strerror(err), err); + mozalloc_abort(error); } } // namespace std -#endif // mozilla_functexcept_h +#endif // mozilla_throw_gcc_h diff --git a/memory/mozalloc/throw_msvc.cpp b/memory/mozalloc/throw_msvc.cpp new file mode 100644 index 00000000000..7d3fa5ecd03 --- /dev/null +++ b/memory/mozalloc/throw_msvc.cpp @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: sw=4 ts=4 et : + */ +/* ***** 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 Code + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Jones + * + * 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 ***** */ + +#include + +#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec)) +# define MOZALLOC_EXPORT __declspec(dllexport) +#endif + +#include "mozilla/mozalloc_abort.h" + +namespace std { + +// NB: user code is not supposed to touch the std:: namespace. We're +// doing this after careful review because we want to define our own +// exception throwing semantics. Don't try this at home! + +__declspec(dllexport) void mozilla_Throw(const exception& e); + +void +mozilla_Throw(const exception& e) +{ + mozalloc_abort(e.what()); +} + +} // namespace std diff --git a/memory/mozalloc/throw_msvc.h b/memory/mozalloc/throw_msvc.h new file mode 100644 index 00000000000..bdea4d12cbf --- /dev/null +++ b/memory/mozalloc/throw_msvc.h @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: sw=4 ts=4 et : + */ +/* ***** 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 Code + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Jones + * + * 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_throw_msvc_h +#define mozilla_throw_msvc_h + +// For MSVC, we define our own _Throw because the Win2k CRT doesn't +// export it. + +#ifdef _EXCEPTION_ +# error "Unable to wrap _Throw(); CRT _Throw() already declared" +#endif + +#define _Throw mozilla_Throw +#include + +#endif // mozilla_throw_msvc_h diff --git a/profile/dirserviceprovider/standalone/Makefile.in b/profile/dirserviceprovider/standalone/Makefile.in index b682bc5b2c1..25649985aad 100644 --- a/profile/dirserviceprovider/standalone/Makefile.in +++ b/profile/dirserviceprovider/standalone/Makefile.in @@ -55,6 +55,7 @@ include $(topsrcdir)/config/rules.mk LOCAL_INCLUDES = -I$(srcdir)/../src DEFINES += -DXPCOM_GLUE +STL_FLAGS = export:: $(MODULES_PROFILEDIRSERVICE_SRC_CSRCS) $(INSTALL) $^ . diff --git a/xpcom/base/nscore.h b/xpcom/base/nscore.h index af02324a422..a9f1ad239b1 100644 --- a/xpcom/base/nscore.h +++ b/xpcom/base/nscore.h @@ -47,13 +47,6 @@ /* Definitions of functions and operators that allocate memory. */ #if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC) -# if defined(__cplusplus) -# include NEW_H /* to give mozalloc std::bad_alloc */ -# endif -/* include these to avoid the macro wrappers causing these headers to - * declare system functions with moz_ prefixes */ -# include -# include # include "mozilla/mozalloc.h" # include "mozilla/mozalloc_macro_wrappers.h" #endif diff --git a/xpcom/glue/Makefile.in b/xpcom/glue/Makefile.in index 5b64237f6be..5db33876c0e 100644 --- a/xpcom/glue/Makefile.in +++ b/xpcom/glue/Makefile.in @@ -134,12 +134,6 @@ EXPORTS_mozilla = \ SSE.h \ $(NULL) -ifdef WRAP_STL_INCLUDES -ifdef GCC_VERSION -EXPORTS_mozilla += functexcept.h -endif -endif - SDK_LIBRARY = \ $(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \ $(NULL) diff --git a/xpcom/glue/standalone/Makefile.in b/xpcom/glue/standalone/Makefile.in index 37a8cc9e689..2c867a977fa 100644 --- a/xpcom/glue/standalone/Makefile.in +++ b/xpcom/glue/standalone/Makefile.in @@ -105,6 +105,9 @@ FORCE_USE_PIC = 1 # for this library on Windows. USE_STATIC_LIBS = 1 +# Don't use STL wrappers here (i.e. wrapped ); they require mozalloc +STL_FLAGS = + GARBAGE += $(XPCOM_GLUE_SRC_LCSRCS) $(XPCOM_GLUE_SRC_LCPPSRCS) $(wildcard *.$(OBJ_SUFFIX)) SRCS_IN_OBJDIR = 1 diff --git a/xpcom/tools/registry/Makefile.in b/xpcom/tools/registry/Makefile.in index b2b53a9ef2e..6f27f133c4f 100644 --- a/xpcom/tools/registry/Makefile.in +++ b/xpcom/tools/registry/Makefile.in @@ -46,6 +46,7 @@ MODULE = xpcom CPPSRCS = regxpcom.cpp DEFINES += -DXPCOM_GLUE +STL_FLAGS = LOCAL_INCLUDES = \ -I$(srcdir)/../../build \