Bug 1314614 - Replace GetCurrentProcessId calls by getpid. r=h4writer
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Mon, 14 Nov 2016 11:18:14 +0000
changeset 438630 72eddba8641ac119f72b4d340591b312010e278a
parent 438629 948ab12433f4f9a1161fa0e676fedcbc799aaf05
child 438631 7cdecdce25a6ba2fa7fd1198bdd0233b057d259d
push id35794
push usersledru@mozilla.com
push dateMon, 14 Nov 2016 22:18:09 +0000
reviewersh4writer
bugs1314614
milestone52.0a1
Bug 1314614 - Replace GetCurrentProcessId calls by getpid. r=h4writer
js/src/jit/JitSpewer.cpp
js/src/vm/CodeCoverage.cpp
js/src/vm/CodeCoverage.h
--- a/js/src/jit/JitSpewer.cpp
+++ b/js/src/jit/JitSpewer.cpp
@@ -5,20 +5,21 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifdef JS_JITSPEW
 
 #include "jit/JitSpewer.h"
 
 #include "mozilla/Atomics.h"
 
-#if defined(XP_WIN)
-# include <windows.h>
+#ifdef XP_WIN
+#include <process.h>
+#define getpid _getpid
 #else
-# include <unistd.h>
+#include <unistd.h>
 #endif
 
 #include "jsprf.h"
 
 #include "jit/Ion.h"
 #include "jit/MIR.h"
 #include "jit/MIRGenerator.h"
 #include "jit/MIRGraph.h"
@@ -168,31 +169,26 @@ IonSpewer::init()
     const size_t bufferLength = 256;
     char c1Buffer[bufferLength];
     char jsonBuffer[bufferLength];
     const char *c1Filename = JIT_SPEW_DIR "/ion.cfg";
     const char *jsonFilename = JIT_SPEW_DIR "/ion.json";
 
     const char* usePid = getenv("ION_SPEW_BY_PID");
     if (usePid && *usePid != 0) {
-#if defined(XP_WIN)
-        size_t pid = GetCurrentProcessId();
-#else
-        size_t pid = getpid();
-#endif
-
+        uint32_t pid = getpid();
         size_t len;
-        len = snprintf(jsonBuffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIuSIZE ".json", pid);
+        len = snprintf(jsonBuffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIu32 ".json", pid);
         if (bufferLength <= len) {
             fprintf(stderr, "Warning: IonSpewer::init: Cannot serialize file name.");
             return false;
         }
         jsonFilename = jsonBuffer;
 
-        len = snprintf(c1Buffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIuSIZE ".cfg", pid);
+        len = snprintf(c1Buffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIu32 ".cfg", pid);
         if (bufferLength <= len) {
             fprintf(stderr, "Warning: IonSpewer::init: Cannot serialize file name.");
             return false;
         }
         c1Filename = c1Buffer;
     }
 
     if (!c1Output_.init(c1Filename) ||
--- a/js/src/vm/CodeCoverage.cpp
+++ b/js/src/vm/CodeCoverage.cpp
@@ -5,20 +5,21 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "vm/CodeCoverage.h"
 
 #include "mozilla/Atomics.h"
 #include "mozilla/IntegerPrintfMacros.h"
 
 #include <stdio.h>
-#if defined(XP_WIN)
-# include <windows.h>
+#ifdef XP_WIN
+#include <process.h>
+#define getpid _getpid
 #else
-# include <unistd.h>
+#include <unistd.h>
 #endif
 
 #include "jscompartment.h"
 #include "jsopcode.h"
 #include "jsprf.h"
 #include "jsscript.h"
 
 #include "vm/Runtime.h"
@@ -541,21 +542,17 @@ LCovCompartment::writeCompartmentName(JS
         outTN_.printf("Compartment_%p%p\n", (void*) size_t('_'), comp);
     }
 
     return !outTN_.hadOutOfMemory();
 }
 
 LCovRuntime::LCovRuntime()
   : out_(),
-#if defined(XP_WIN)
-    pid_(GetCurrentProcessId()),
-#else
     pid_(getpid()),
-#endif
     isEmpty_(false)
 {
 }
 
 LCovRuntime::~LCovRuntime()
 {
     if (out_.isInitialized())
         finishFile();
@@ -567,17 +564,17 @@ LCovRuntime::fillWithFilename(char *name
     const char* outDir = getenv("JS_CODE_COVERAGE_OUTPUT_DIR");
     if (!outDir || *outDir == 0)
         return false;
 
     int64_t timestamp = static_cast<double>(PRMJ_Now()) / PRMJ_USEC_PER_SEC;
     static mozilla::Atomic<size_t> globalRuntimeId(0);
     size_t rid = globalRuntimeId++;
 
-    int len = snprintf(name, length, "%s/%" PRId64 "-%" PRIuSIZE "-%" PRIuSIZE ".info",
+    int len = snprintf(name, length, "%s/%" PRId64 "-%" PRIu32 "-%" PRIuSIZE ".info",
                        outDir, timestamp, pid_, rid);
     if (length != size_t(len)) {
         fprintf(stderr, "Warning: LCovRuntime::init: Cannot serialize file name.");
         return false;
     }
 
     return true;
 }
@@ -610,21 +607,17 @@ LCovRuntime::finishFile()
 }
 
 void
 LCovRuntime::writeLCovResult(LCovCompartment& comp)
 {
     if (!out_.isInitialized())
         return;
 
-#if defined(XP_WIN)
-    size_t p = GetCurrentProcessId();
-#else
-    size_t p = getpid();
-#endif
+    uint32_t p = getpid();
     if (pid_ != p) {
         pid_ = p;
         finishFile();
         init();
         if (!out_.isInitialized())
             return;
     }
 
--- a/js/src/vm/CodeCoverage.h
+++ b/js/src/vm/CodeCoverage.h
@@ -157,17 +157,17 @@ class LCovRuntime
     void finishFile();
 
   private:
     // Output file which is created if code coverage is enabled.
     Fprinter out_;
 
     // The process' PID is used to watch for fork. When the process fork,
     // we want to close the current file and open a new one.
-    size_t pid_;
+    uint32_t pid_;
 
     // Flag used to report if the generated file is empty or not. If it is empty
     // when the runtime is destroyed, then the file would be removed as an empty
     // file is not a valid LCov file.
     bool isEmpty_;
 };
 
 } // namespace coverage