Bug 1231224 part 11 - Add missing OOM checks in Module::setProfilingEnabled. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 06 Jan 2016 21:07:05 +0100
changeset 278861 a1c2db363fa9f8b0c2c36c7d21b5483f52b08d7a
parent 278860 80a318392bb0b16cf7b0f5cccfd94839bcfbe133
child 278862 6d6334c0964fa13a07070c7eec22d95d09c99756
push id29860
push usercbook@mozilla.com
push dateThu, 07 Jan 2016 10:51:20 +0000
treeherdermozilla-central@e0bcd16e1d4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1231224
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1231224 part 11 - Add missing OOM checks in Module::setProfilingEnabled. r=luke
js/src/asmjs/WasmModule.cpp
js/src/asmjs/WasmModule.h
--- a/js/src/asmjs/WasmModule.cpp
+++ b/js/src/asmjs/WasmModule.cpp
@@ -635,38 +635,45 @@ Module::sendCodeRangesToProfiler(JSConte
             method.class_file_name = nullptr;
             method.source_file_name = nullptr;
             iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&method);
         }
     }
 #endif
 }
 
-void
-Module::setProfilingEnabled(bool enabled, JSContext* cx)
+bool
+Module::setProfilingEnabled(JSContext* cx, bool enabled)
 {
     MOZ_ASSERT(dynamicallyLinked_);
     MOZ_ASSERT(!activation());
 
     if (profilingEnabled_ == enabled)
-        return;
+        return true;
 
     // When enabled, generate profiling labels for every name in funcNames_
     // that is the name of some Function CodeRange. This involves malloc() so
     // do it now since, once we start sampling, we'll be in a signal-handing
     // context where we cannot malloc.
     if (enabled) {
-        funcLabels_.resize(funcNames_.length());
+        if (!funcLabels_.resize(funcNames_.length())) {
+            ReportOutOfMemory(cx);
+            return false;
+        }
         for (const CodeRange& codeRange : codeRanges_) {
             if (!codeRange.isFunction())
                 continue;
             unsigned lineno = codeRange.funcLineNumber();
             const char* name = funcNames_[codeRange.funcNameIndex()].get();
-            funcLabels_[codeRange.funcNameIndex()] =
-                UniqueChars(JS_smprintf("%s (%s:%u)", name, filename_.get(), lineno));
+            UniqueChars label(JS_smprintf("%s (%s:%u)", name, filename_.get(), lineno));
+            if (!label) {
+                ReportOutOfMemory(cx);
+                return false;
+            }
+            funcLabels_[codeRange.funcNameIndex()] = Move(label);
         }
     } else {
         funcLabels_.clear();
     }
 
     // Patch callsites and returns to execute profiling prologues/epililogues.
     {
         AutoMutateCode amc(cx, *this, "Module::setProfilingEnabled");
@@ -688,16 +695,17 @@ Module::setProfilingEnabled(bool enabled
             if (!enabled)
                 Swap(from, to);
             MOZ_ASSERT(array[i] == from);
             array[i] = to;
         }
     }
 
     profilingEnabled_ = enabled;
+    return true;
 }
 
 Module::ImportExit&
 Module::importToExit(const Import& import)
 {
     return *reinterpret_cast<ImportExit*>(globalData() + import.exitGlobalDataOffset());
 }
 
@@ -1047,18 +1055,20 @@ Module::callExport(JSContext* cx, uint32
     MOZ_ASSERT(dynamicallyLinked_);
 
     const Export& exp = exports_[exportIndex];
 
     // Enable/disable profiling in the Module to match the current global
     // profiling state. Don't do this if the Module is already active on the
     // stack since this would leave the Module in a state where profiling is
     // enabled but the stack isn't unwindable.
-    if (profilingEnabled() != cx->runtime()->spsProfiler.enabled() && !activation())
-        setProfilingEnabled(cx->runtime()->spsProfiler.enabled(), cx);
+    if (profilingEnabled() != cx->runtime()->spsProfiler.enabled() && !activation()) {
+        if (!setProfilingEnabled(cx, cx->runtime()->spsProfiler.enabled()))
+            return false;
+    }
 
     // The calling convention for an external call into wasm is to pass an
     // array of 16-byte values where each value contains either a coerced int32
     // (in the low word), a double value (in the low dword) or a SIMD vector
     // value, with the coercions specified by the wasm signature. The external
     // entry point unpacks this array into the system-ABI-specified registers
     // and stack memory and then calls into the internal entry point. The return
     // value is stored in the first element of the array (which, therefore, must
--- a/js/src/asmjs/WasmModule.h
+++ b/js/src/asmjs/WasmModule.h
@@ -425,17 +425,17 @@ class Module
 
     uint32_t totalBytes() const;
     uint8_t* rawHeapPtr() const;
     uint8_t*& rawHeapPtr();
     WasmActivation*& activation();
     void specializeToHeap(ArrayBufferObjectMaybeShared* heap);
     void despecializeFromHeap(ArrayBufferObjectMaybeShared* heap);
     void sendCodeRangesToProfiler(JSContext* cx);
-    void setProfilingEnabled(bool enabled, JSContext* cx);
+    MOZ_WARN_UNUSED_RESULT bool setProfilingEnabled(JSContext* cx, bool enabled);
     ImportExit& importToExit(const Import& import);
 
     enum CacheBool { NotLoadedFromCache = false, LoadedFromCache = true };
     enum ProfilingBool { ProfilingDisabled = false, ProfilingEnabled = true };
 
     static CacheablePod zeroPod();
     void init();
     Module(const CacheablePod& pod,