Commit 996b1f61 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Add stack frames when crashing in mojo::DataPipe::DataPipe().

Assertion failures from DataPipe construction should now:
  (1) Include DataPipe::DataPipe() in the stack trace.
  (2) Include CrashMojoResourceExhausted() in the stacktrace if the failure was due to MOJO_RESULT_RESOURCE_EXHAUSTION.

The goal is to make it easier to bucket incoming crash reports. Crashes due to resource exhaustion are often not actionable.

Bug: 921799
Change-Id: I20fcc0a04e01ce7a829d2a1e4644b26c1f8c1139
Reviewed-on: https://chromium-review.googlesource.com/c/1444832Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#627980}
parent 9d10a54d
......@@ -26,6 +26,7 @@ component("system") {
"buffer.cc",
"buffer.h",
"core.h",
"data_pipe.cc",
"data_pipe.h",
"data_pipe_drainer.cc",
"data_pipe_drainer.h",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/public/cpp/system/data_pipe.h"
namespace mojo {
namespace {
NOINLINE void CrashMojoResourceExhausted() {
LOG(FATAL)
<< "Failed to create data pipe due to MOJO_RESULT_RESOURCE_EXHAUSTED.";
}
void CrashIfResultNotOk(MojoResult result) {
if (LIKELY(result == MOJO_RESULT_OK))
return;
// Include some extra information for resource exhausted failures.
if (result == MOJO_RESULT_RESOURCE_EXHAUSTED)
CrashMojoResourceExhausted();
LOG(FATAL) << "Failed to create data pipe; result=" << result;
}
} // namespace
DataPipe::DataPipe() {
MojoResult result =
CreateDataPipe(nullptr, &producer_handle, &consumer_handle);
CrashIfResultNotOk(result);
}
DataPipe::DataPipe(uint32_t capacity_num_bytes) {
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = capacity_num_bytes;
MojoResult result =
CreateDataPipe(&options, &producer_handle, &consumer_handle);
CrashIfResultNotOk(result);
}
DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) {
MojoResult result =
CreateDataPipe(&options, &producer_handle, &consumer_handle);
CrashIfResultNotOk(result);
}
DataPipe::~DataPipe() {}
} // namespace mojo
......@@ -141,7 +141,7 @@ inline MojoResult CreateDataPipe(
// TODO(vtl): Make an even more friendly version? (Maybe templatized for a
// particular type instead of some "element"? Maybe functions that take
// vectors?)
class DataPipe {
class MOJO_CPP_SYSTEM_EXPORT DataPipe {
public:
DataPipe();
explicit DataPipe(uint32_t capacity_num_bytes);
......@@ -152,32 +152,6 @@ class DataPipe {
ScopedDataPipeConsumerHandle consumer_handle;
};
inline DataPipe::DataPipe() {
MojoResult result =
CreateDataPipe(nullptr, &producer_handle, &consumer_handle);
CHECK_EQ(MOJO_RESULT_OK, result);
}
inline DataPipe::DataPipe(uint32_t capacity_num_bytes) {
MojoCreateDataPipeOptions options;
options.struct_size = sizeof(MojoCreateDataPipeOptions);
options.flags = MOJO_CREATE_DATA_PIPE_FLAG_NONE;
options.element_num_bytes = 1;
options.capacity_num_bytes = capacity_num_bytes;
MojoResult result =
CreateDataPipe(&options, &producer_handle, &consumer_handle);
CHECK_EQ(MOJO_RESULT_OK, result);
}
inline DataPipe::DataPipe(const MojoCreateDataPipeOptions& options) {
MojoResult result =
CreateDataPipe(&options, &producer_handle, &consumer_handle);
CHECK_EQ(MOJO_RESULT_OK, result);
}
inline DataPipe::~DataPipe() {
}
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment