crashpad/util/win/exception_handler_server_test.cc

214 lines
6.3 KiB
C++
Raw Normal View History

win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "util/win/exception_handler_server.h"
#include <windows.h>
#include <sys/types.h>
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
#include "client/crashpad_client.h"
#include "gtest/gtest.h"
#include "test/win/win_child_process.h"
#include "util/thread/thread.h"
#include "util/win/address_types.h"
#include "util/win/registration_protocol_win.h"
#include "util/win/scoped_handle.h"
namespace crashpad {
namespace test {
namespace {
// Runs the ExceptionHandlerServer on a background thread.
class RunServerThread : public Thread {
public:
// Instantiates a thread which will invoke server->Run(delegate).
RunServerThread(ExceptionHandlerServer* server,
ExceptionHandlerServer::Delegate* delegate)
: server_(server), delegate_(delegate) {}
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
~RunServerThread() override {}
private:
// Thread:
void ThreadMain() override { server_->Run(delegate_); }
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
ExceptionHandlerServer* server_;
ExceptionHandlerServer::Delegate* delegate_;
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
DISALLOW_COPY_AND_ASSIGN(RunServerThread);
};
class TestDelegate : public ExceptionHandlerServer::Delegate {
public:
explicit TestDelegate(HANDLE server_ready) : server_ready_(server_ready) {}
~TestDelegate() override {}
void ExceptionHandlerServerStarted() override {
SetEvent(server_ready_);
}
unsigned int ExceptionHandlerServerException(
HANDLE process,
WinVMAddress exception_information_address,
WinVMAddress debug_critical_section_address) override {
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
return 0;
}
void WaitForStart() { WaitForSingleObject(server_ready_, INFINITE); }
private:
HANDLE server_ready_; // weak
DISALLOW_COPY_AND_ASSIGN(TestDelegate);
};
class ExceptionHandlerServerTest : public testing::Test {
public:
ExceptionHandlerServerTest()
: server_(true),
pipe_name_(L"\\\\.\\pipe\\test_name"),
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
server_ready_(CreateEvent(nullptr, false, false, nullptr)),
delegate_(server_ready_.get()),
server_thread_(&server_, &delegate_) {
server_.SetPipeName(pipe_name_);
}
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
TestDelegate& delegate() { return delegate_; }
ExceptionHandlerServer& server() { return server_; }
Thread& server_thread() { return server_thread_; }
const std::wstring& pipe_name() const { return pipe_name_; }
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
private:
ExceptionHandlerServer server_;
std::wstring pipe_name_;
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
ScopedKernelHANDLE server_ready_;
TestDelegate delegate_;
RunServerThread server_thread_;
DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServerTest);
};
// During destruction, ensures that the server is stopped and the background
// thread joined.
class ScopedStopServerAndJoinThread {
public:
ScopedStopServerAndJoinThread(ExceptionHandlerServer* server, Thread* thread)
: server_(server), thread_(thread) {}
~ScopedStopServerAndJoinThread() {
server_->Stop();
thread_->Join();
}
private:
ExceptionHandlerServer* server_;
Thread* thread_;
DISALLOW_COPY_AND_ASSIGN(ScopedStopServerAndJoinThread);
};
TEST_F(ExceptionHandlerServerTest, Instantiate) {
}
TEST_F(ExceptionHandlerServerTest, StartAndStop) {
server_thread().Start();
ScopedStopServerAndJoinThread scoped_stop_server_and_join_thread(
&server(), &server_thread());
ASSERT_NO_FATAL_FAILURE(delegate().WaitForStart());
}
TEST_F(ExceptionHandlerServerTest, StopWhileConnected) {
server_thread().Start();
ScopedStopServerAndJoinThread scoped_stop_server_and_join_thread(
&server(), &server_thread());
ASSERT_NO_FATAL_FAILURE(delegate().WaitForStart());
CrashpadClient client;
client.SetHandlerIPCPipe(pipe_name());
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
// Leaving this scope causes the server to be stopped, while the connection
// is still open.
}
std::wstring ReadWString(FileHandle handle) {
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
size_t length = 0;
Make file_io reads more rational and predictable ReadFile() attempted to continue reading after a short read. In most cases, this is fine. However, ReadFile() would keep trying to fill a partially-filled buffer until experiencing a 0-length read(), signaling end-of-file. For certain weird file descriptors like terminal input, EOF is an ephemeral condition, and attempting to read beyond EOF doesn’t actually return 0 (EOF) provided that they remain open, it will block waiting for more input. Consequently, ReadFile() and anything based on ReadFile() had an undocumented and quirky interface, which was that any short read that it returned (not an underlying short read) actually indicated EOF. This facet of ReadFile() was unexpected, so it’s being removed. The new behavior is that ReadFile() will return an underlying short read. The behavior of FileReaderInterface::Read() is updated in accordance with this change. Upon experiencing a short read, the caller can determine the best action. Most callers were already prepared for this behavior. Outside of util/file, only crashpad_database_util properly implemented EOF detection according to previous semantics, and adapting it to new semantics is trivial. Callers who require an exact-length read can use the new ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or CheckedReadFileExactly(). These functions will retry following a short read. The renamed functions were previously called LoggingReadFile() and CheckedReadFile(), but those names implied that they were simply wrapping ReadFile(), which is not the case. They wrapped ReadFile() and further, insisted on a full read. Since ReadFile()’s semantics are now changing but these functions’ are not, they’re now even more distinct from ReadFile(), and must be renamed to avoid confusion. Test: * Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908 Reviewed-on: https://chromium-review.googlesource.com/456676 Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
EXPECT_TRUE(LoggingReadFileExactly(handle, &length, sizeof(length)));
std::wstring str(length, L'\0');
if (length > 0) {
Make file_io reads more rational and predictable ReadFile() attempted to continue reading after a short read. In most cases, this is fine. However, ReadFile() would keep trying to fill a partially-filled buffer until experiencing a 0-length read(), signaling end-of-file. For certain weird file descriptors like terminal input, EOF is an ephemeral condition, and attempting to read beyond EOF doesn’t actually return 0 (EOF) provided that they remain open, it will block waiting for more input. Consequently, ReadFile() and anything based on ReadFile() had an undocumented and quirky interface, which was that any short read that it returned (not an underlying short read) actually indicated EOF. This facet of ReadFile() was unexpected, so it’s being removed. The new behavior is that ReadFile() will return an underlying short read. The behavior of FileReaderInterface::Read() is updated in accordance with this change. Upon experiencing a short read, the caller can determine the best action. Most callers were already prepared for this behavior. Outside of util/file, only crashpad_database_util properly implemented EOF detection according to previous semantics, and adapting it to new semantics is trivial. Callers who require an exact-length read can use the new ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or CheckedReadFileExactly(). These functions will retry following a short read. The renamed functions were previously called LoggingReadFile() and CheckedReadFile(), but those names implied that they were simply wrapping ReadFile(), which is not the case. They wrapped ReadFile() and further, insisted on a full read. Since ReadFile()’s semantics are now changing but these functions’ are not, they’re now even more distinct from ReadFile(), and must be renamed to avoid confusion. Test: * Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908 Reviewed-on: https://chromium-review.googlesource.com/456676 Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
EXPECT_TRUE(
LoggingReadFileExactly(handle, &str[0], length * sizeof(str[0])));
}
return str;
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
}
void WriteWString(FileHandle handle, const std::wstring& str) {
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
size_t length = str.size();
EXPECT_TRUE(LoggingWriteFile(handle, &length, sizeof(length)));
if (length > 0) {
EXPECT_TRUE(LoggingWriteFile(handle, &str[0], length * sizeof(str[0])));
}
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
}
class TestClient final : public WinChildProcess {
public:
TestClient() : WinChildProcess() {}
~TestClient() {}
private:
int Run() override {
std::wstring pipe_name = ReadWString(ReadPipeHandle());
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
CrashpadClient client;
if (!client.SetHandlerIPCPipe(pipe_name)) {
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
ADD_FAILURE();
return EXIT_FAILURE;
}
WriteWString(WritePipeHandle(), L"OK");
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
return EXIT_SUCCESS;
}
DISALLOW_COPY_AND_ASSIGN(TestClient);
};
TEST_F(ExceptionHandlerServerTest, MultipleConnections) {
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
WinChildProcess::EntryPoint<TestClient>();
std::unique_ptr<WinChildProcess::Handles> handles_1 =
WinChildProcess::Launch();
std::unique_ptr<WinChildProcess::Handles> handles_2 =
WinChildProcess::Launch();
std::unique_ptr<WinChildProcess::Handles> handles_3 =
WinChildProcess::Launch();
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
// Must ensure the delegate outlasts the server.
{
server_thread().Start();
ScopedStopServerAndJoinThread scoped_stop_server_and_join_thread(
&server(), &server_thread());
ASSERT_NO_FATAL_FAILURE(delegate().WaitForStart());
// Tell all the children where to connect.
WriteWString(handles_1->write.get(), pipe_name());
WriteWString(handles_2->write.get(), pipe_name());
WriteWString(handles_3->write.get(), pipe_name());
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE} gtest used to require (expected, actual) ordering for arguments to EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify each side as “expected” or “actual.” Tests in Crashpad adhered to this traditional ordering. After a gtest change in February 2016, it is now agnostic with respect to the order of these arguments. This change mechanically updates all uses of these macros to (actual, expected) by reversing them. This provides consistency with our use of the logging CHECK_EQ and DCHECK_EQ macros, and makes for better readability by ordinary native speakers. The rough (but working!) conversion tool is https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py, and “git cl format” cleaned up its output. EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made a judgment that one side or the other needed to provide an “unexpected” value. Consequently, some code used (unexpected, actual) while other code used (actual, unexpected). For consistency with the new EXPECT_EQ and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE, this change also updates these use sites to (actual, unexpected) where one side can be called “unexpected” as, for example, std::string::npos can be. Unfortunately, this portion was a manual conversion. References: https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65 https://github.com/google/googletest/pull/713 Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3 Reviewed-on: https://chromium-review.googlesource.com/466727 Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
ASSERT_EQ(ReadWString(handles_3->read.get()), L"OK");
ASSERT_EQ(ReadWString(handles_2->read.get()), L"OK");
ASSERT_EQ(ReadWString(handles_1->read.get()), L"OK");
win: Crash handler server This replaces the registration server, and adds dispatch to a delegate on crash requests. (As you are already aware) we went around in circles on trying to come up with a slightly-too-fancy threading design. All of them seemed to have problems when it comes to out of order events, and orderly shutdown, so I've gone back to something not-too-fancy. Two named pipe instances (that clients connect to) are created. These are used only for registration (which should take <1ms), so 2 should be sufficient to avoid any waits. When a client registers, we duplicate an event to it, which is used to signal when it wants a dump taken. The server registers threadpool waits on that event, and also on the process handle (which will be signalled when the client process exits). These requests (in particular the taking of the dump) are serviced on the threadpool, which avoids us needing to manage those threads, but still allows parallelism in taking dumps. On process termination, we use an IO Completion Port to post a message back to the main thread to request cleanup. This complexity is necessary so that we can unregister the threadpool waits without being on the threadpool, which we need to do synchronously so that we can be sure that no further callbacks will execute (and expect to have the client data around still). In a followup, I will readd support for DumpWithoutCrashing -- I don't think it will be too difficult now that we have an orderly way to clean up client records in the server. R=cpu@chromium.org, mark@chromium.org, jschuh@chromium.org BUG=crashpad:1,crashpad:45 Review URL: https://codereview.chromium.org/1301853002 .
2015-09-03 11:06:17 -07:00
}
}
} // namespace
} // namespace test
} // namespace crashpad