Bug 1202386: Output clear HAL IPC errors, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 10 Sep 2015 11:32:26 +0200
changeset 294241 f353659e96a7acaf3b23be1469ca90206107e60a
parent 294240 c0e2d913c6017354c2c4ef2f6a56d5aac619511e
child 294242 ac0a29169cc9fbdf077a812c95c00d002df6ceb8
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1202386
milestone43.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 1202386: Output clear HAL IPC errors, r=shuang This patch improves error logging in the IPC PDU packing and unpacking code.
ipc/hal/DaemonSocketPDUHelpers.cpp
--- a/ipc/hal/DaemonSocketPDUHelpers.cpp
+++ b/ipc/hal/DaemonSocketPDUHelpers.cpp
@@ -67,17 +67,18 @@ LogProtocolError(const char* aFmt, ...)
 
 nsresult
 Convert(bool aIn, uint8_t& aOut)
 {
   static const uint8_t sValue[] = {
     [false] = 0x00,
     [true] = 0x01
   };
-  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sValue))) {
+  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn >= MOZ_ARRAY_LENGTH(sValue), bool, uint8_t)) {
     aOut = 0;
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = sValue[aIn];
   return NS_OK;
 }
 
 nsresult
@@ -91,57 +92,64 @@ Convert(bool aIn, int32_t& aOut)
   }
   aOut = static_cast<int32_t>(out);
   return NS_OK;
 }
 
 nsresult
 Convert(int aIn, uint8_t& aOut)
 {
-  if (NS_WARN_IF(aIn < std::numeric_limits<uint8_t>::min()) ||
-      NS_WARN_IF(aIn > std::numeric_limits<uint8_t>::max())) {
+  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn < std::numeric_limits<uint8_t>::min(), int, uint8_t) ||
+      MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn > std::numeric_limits<uint8_t>::max(), int, uint8_t)) {
     aOut = 0; // silences compiler warning
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = static_cast<uint8_t>(aIn);
   return NS_OK;
 }
 
 nsresult
 Convert(int aIn, int16_t& aOut)
 {
-  if (NS_WARN_IF(aIn < std::numeric_limits<int16_t>::min()) ||
-      NS_WARN_IF(aIn > std::numeric_limits<int16_t>::max())) {
+  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn < std::numeric_limits<int16_t>::min(), int, int16_t) ||
+      MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn > std::numeric_limits<int16_t>::max(), int, int16_t)) {
     aOut = 0; // silences compiler warning
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = static_cast<int16_t>(aIn);
   return NS_OK;
 }
 
 nsresult
 Convert(int aIn, int32_t& aOut)
 {
-  if (NS_WARN_IF(aIn < std::numeric_limits<int32_t>::min()) ||
-      NS_WARN_IF(aIn > std::numeric_limits<int32_t>::max())) {
+  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn < std::numeric_limits<int32_t>::min(), int, int32_t) ||
+      MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn > std::numeric_limits<int32_t>::max(), int, int32_t)) {
     aOut = 0; // silences compiler warning
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = static_cast<int32_t>(aIn);
   return NS_OK;
 }
 
 nsresult
 Convert(uint8_t aIn, bool& aOut)
 {
   static const bool sBool[] = {
     [0x00] = false,
     [0x01] = true
   };
-  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sBool))) {
+  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn >= MOZ_ARRAY_LENGTH(sBool), uint8_t, bool)) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = sBool[aIn];
   return NS_OK;
 }
 
 nsresult
 Convert(uint8_t aIn, char& aOut)
@@ -169,29 +177,31 @@ Convert(uint32_t aIn, int& aOut)
 {
   aOut = static_cast<int>(aIn);
   return NS_OK;
 }
 
 nsresult
 Convert(uint32_t aIn, uint8_t& aOut)
 {
-  if (NS_WARN_IF(aIn < std::numeric_limits<uint8_t>::min()) ||
-      NS_WARN_IF(aIn > std::numeric_limits<uint8_t>::max())) {
+  if (MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn < std::numeric_limits<uint8_t>::min(), uint32_t, uint8_t) ||
+      MOZ_HAL_IPC_CONVERT_WARN_IF(
+        aIn > std::numeric_limits<uint8_t>::max(), uint32_t, uint8_t)) {
     aOut = 0; // silences compiler warning
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = static_cast<uint8_t>(aIn);
   return NS_OK;
 }
 
 nsresult
 Convert(size_t aIn, uint16_t& aOut)
 {
-  if (NS_WARN_IF(aIn >= (1ul << 16))) {
+  if (MOZ_HAL_IPC_CONVERT_WARN_IF(aIn >= (1ul << 16), size_t, uint16_t)) {
     aOut = 0; // silences compiler warning
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = static_cast<uint16_t>(aIn);
   return NS_OK;
 }
 
 //
@@ -241,29 +251,29 @@ UnpackPDU(DaemonSocketPDU& aPDU, char& a
 nsresult
 UnpackPDU(DaemonSocketPDU& aPDU, nsDependentCString& aOut)
 {
   // We get a pointer to the first character in the PDU, a length
   // of 1 ensures we consume the \0 byte. With 'str' pointing to
   // the string in the PDU, we can copy the actual bytes.
 
   const char* str = reinterpret_cast<const char*>(aPDU.Consume(1));
-  if (NS_WARN_IF(!str)) {
+  if (MOZ_HAL_IPC_UNPACK_WARN_IF(!str, nsDependentCString)) {
     return NS_ERROR_ILLEGAL_VALUE; // end of PDU
   }
 
   const char* end = static_cast<char*>(memchr(str, '\0', aPDU.GetSize() + 1));
-  if (NS_WARN_IF(!end)) {
+  if (MOZ_HAL_IPC_UNPACK_WARN_IF(!end, nsDependentCString)) {
     return NS_ERROR_ILLEGAL_VALUE; // no string terminator
   }
 
   ptrdiff_t len = end - str;
 
   const uint8_t* rest = aPDU.Consume(len);
-  if (NS_WARN_IF(!rest)) {
+  if (MOZ_HAL_IPC_UNPACK_WARN_IF(!rest, nsDependentCString)) {
     // We couldn't consume bytes that should have been there.
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   aOut.Rebind(str, len);
 
   return NS_OK;
 }
@@ -310,16 +320,16 @@ PDUInitOp::WarnAboutTrailingData() const
   if (MOZ_LIKELY(!size)) {
     return;
   }
 
   uint8_t service, opcode;
   uint16_t payloadSize;
   mPDU->GetHeader(service, opcode, payloadSize);
 
-  CHROMIUM_LOG(
+  detail::LogProtocolError(
     "Unpacked PDU of type (%x,%x) still contains %zu Bytes of data.",
     service, opcode, size);
 }
 
 } // namespace DaemonSocketPDUHelpers
 } // namespace ipc
 } // namespace mozilla