2015-04-29 18:53:47 -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 "client/crashpad_client.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.h>
|
2015-04-29 18:53:47 -07:00
|
|
|
#include <windows.h>
|
|
|
|
|
2015-08-14 15:22:09 -07:00
|
|
|
#include "base/atomicops.h"
|
2015-04-29 18:53:47 -07:00
|
|
|
#include "base/logging.h"
|
2015-08-14 15:22:09 -07:00
|
|
|
#include "base/strings/string16.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2015-09-25 13:45:32 -07:00
|
|
|
#include "base/synchronization/lock.h"
|
2015-08-14 15:22:09 -07:00
|
|
|
#include "util/file/file_io.h"
|
2015-10-16 14:55:14 -07:00
|
|
|
#include "util/win/critical_section_with_debug_info.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 "util/win/registration_protocol_win.h"
|
2015-08-14 15:22:09 -07:00
|
|
|
#include "util/win/scoped_handle.h"
|
2015-04-29 18:53:47 -07:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-09-25 13:45:32 -07:00
|
|
|
// This handle is never closed. This is used to signal to the server that a dump
|
|
|
|
// should be taken in the event of a crash.
|
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
|
|
|
HANDLE g_signal_exception = INVALID_HANDLE_VALUE;
|
2015-04-29 18:53:47 -07:00
|
|
|
|
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
|
|
|
// Where we store the exception information that the crash handler reads.
|
2015-09-25 13:45:32 -07:00
|
|
|
crashpad::ExceptionInformation g_crash_exception_information;
|
|
|
|
|
|
|
|
// These handles are never closed. g_signal_non_crash_dump is used to signal to
|
|
|
|
// the server to take a dump (not due to an exception), and the server will
|
|
|
|
// signal g_non_crash_dump_done when the dump is completed.
|
|
|
|
HANDLE g_signal_non_crash_dump = INVALID_HANDLE_VALUE;
|
|
|
|
HANDLE g_non_crash_dump_done = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
// Guards multiple simultaneous calls to DumpWithoutCrash(). This is leaked.
|
|
|
|
base::Lock* g_non_crash_dump_lock;
|
|
|
|
|
|
|
|
// Where we store a pointer to the context information when taking a non-crash
|
|
|
|
// dump.
|
|
|
|
crashpad::ExceptionInformation g_non_crash_exception_information;
|
2015-08-14 15:22:09 -07:00
|
|
|
|
2015-10-15 13:18:08 -07:00
|
|
|
// A CRITICAL_SECTION initialized with
|
|
|
|
// RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO to force it to be allocated with a
|
|
|
|
// valid .DebugInfo field. The address of this critical section is given to the
|
|
|
|
// handler. All critical sections with debug info are linked in a doubly-linked
|
|
|
|
// list, so this allows the handler to capture all of them.
|
|
|
|
CRITICAL_SECTION g_critical_section_with_debug_info;
|
|
|
|
|
2015-04-29 18:53:47 -07:00
|
|
|
LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exception_pointers) {
|
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
|
|
|
// Tracks whether a thread has already entered UnhandledExceptionHandler.
|
|
|
|
static base::subtle::AtomicWord have_crashed;
|
|
|
|
|
2015-08-14 15:22:09 -07:00
|
|
|
// This is a per-process handler. While this handler is being invoked, other
|
|
|
|
// threads are still executing as usual, so multiple threads could enter at
|
|
|
|
// the same time. Because we're in a crashing state, we shouldn't be doing
|
|
|
|
// anything that might cause allocations, call into kernel mode, etc. So, we
|
|
|
|
// don't want to take a critical section here to avoid simultaneous access to
|
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
|
|
|
// the global exception pointers in ExceptionInformation. Because the crash
|
|
|
|
// handler will record all threads, it's fine to simply have the second and
|
|
|
|
// subsequent entrants block here. They will soon be suspended by the crash
|
|
|
|
// handler, and then the entire process will be terminated below. This means
|
|
|
|
// that we won't save the exception pointers from the second and further
|
|
|
|
// crashes, but contention here is very unlikely, and we'll still have a stack
|
|
|
|
// that's blocked at this location.
|
|
|
|
if (base::subtle::Barrier_AtomicIncrement(&have_crashed, 1) > 1) {
|
2015-08-18 12:25:19 -07:00
|
|
|
SleepEx(INFINITE, false);
|
2015-08-14 15:22:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we're the first thread, so record the exception pointer and
|
|
|
|
// signal the crash handler.
|
2015-09-25 13:45:32 -07:00
|
|
|
g_crash_exception_information.thread_id = GetCurrentThreadId();
|
|
|
|
g_crash_exception_information.exception_pointers =
|
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
|
|
|
reinterpret_cast<crashpad::WinVMAddress>(exception_pointers);
|
2015-04-29 18:53:47 -07:00
|
|
|
|
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
|
|
|
// Now signal the crash server, which will take a dump and then terminate us
|
|
|
|
// when it's complete.
|
|
|
|
SetEvent(g_signal_exception);
|
2015-08-14 15:22:09 -07:00
|
|
|
|
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
|
|
|
// Time to wait for the handler to create a dump.
|
|
|
|
const DWORD kMillisecondsUntilTerminate = 60 * 1000;
|
2015-08-14 15:22:09 -07:00
|
|
|
|
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
|
|
|
// Sleep for a while to allow it to process us. Eventually, we terminate
|
|
|
|
// ourselves in case the crash server is gone, so that we don't leave zombies
|
|
|
|
// around. This would ideally never happen.
|
|
|
|
Sleep(kMillisecondsUntilTerminate);
|
|
|
|
|
|
|
|
LOG(ERROR) << "crash server did not respond, self-terminating";
|
|
|
|
|
|
|
|
const UINT kCrashExitCodeNoDump = 0xffff7001;
|
|
|
|
TerminateProcess(GetCurrentProcess(), kCrashExitCodeNoDump);
|
2015-08-14 15:22:09 -07:00
|
|
|
|
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 EXCEPTION_CONTINUE_SEARCH;
|
2015-08-14 15:22:09 -07:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:53:47 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
CrashpadClient::CrashpadClient() {
|
|
|
|
}
|
|
|
|
|
|
|
|
CrashpadClient::~CrashpadClient() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CrashpadClient::StartHandler(
|
|
|
|
const base::FilePath& handler,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments) {
|
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
|
|
|
LOG(FATAL) << "SetHandler should be used on Windows";
|
2015-04-29 18:53:47 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-10 12:23:50 -04:00
|
|
|
bool CrashpadClient::SetHandler(const std::string& ipc_port) {
|
2015-09-25 13:45:32 -07:00
|
|
|
DCHECK_EQ(g_signal_exception, INVALID_HANDLE_VALUE);
|
|
|
|
DCHECK_EQ(g_signal_non_crash_dump, INVALID_HANDLE_VALUE);
|
|
|
|
DCHECK_EQ(g_non_crash_dump_done, INVALID_HANDLE_VALUE);
|
2015-10-15 13:18:08 -07:00
|
|
|
DCHECK(!g_critical_section_with_debug_info.DebugInfo);
|
2015-09-25 13:45:32 -07:00
|
|
|
|
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
|
|
|
ClientToServerMessage message;
|
|
|
|
memset(&message, 0, sizeof(message));
|
|
|
|
message.type = ClientToServerMessage::kRegister;
|
2015-09-04 11:52:07 -07:00
|
|
|
message.registration.version = RegistrationRequest::kMessageVersion;
|
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
|
|
|
message.registration.client_process_id = GetCurrentProcessId();
|
2015-09-25 13:45:32 -07:00
|
|
|
message.registration.crash_exception_information =
|
|
|
|
reinterpret_cast<WinVMAddress>(&g_crash_exception_information);
|
|
|
|
message.registration.non_crash_exception_information =
|
|
|
|
reinterpret_cast<WinVMAddress>(&g_non_crash_exception_information);
|
2015-08-14 15:22:09 -07:00
|
|
|
|
2015-10-15 13:18:08 -07:00
|
|
|
// We create this dummy CRITICAL_SECTION with the
|
|
|
|
// RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO flag set to have an entry point
|
|
|
|
// into the doubly-linked list of RTL_CRITICAL_SECTION_DEBUG objects. This
|
|
|
|
// allows us to walk the list at crash time to gather data for !locks. A
|
|
|
|
// debugger would instead inspect ntdll!RtlCriticalSectionList to get the head
|
|
|
|
// of the list. But that is not an exported symbol, so on an arbitrary client
|
|
|
|
// machine, we don't have a way of getting that pointer.
|
2015-10-16 14:55:14 -07:00
|
|
|
if (InitializeCriticalSectionWithDebugInfoIfPossible(
|
|
|
|
&g_critical_section_with_debug_info)) {
|
2015-10-15 13:18:08 -07:00
|
|
|
message.registration.critical_section_address =
|
|
|
|
reinterpret_cast<WinVMAddress>(&g_critical_section_with_debug_info);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ServerToClientMessage response = {0};
|
2015-08-14 15:22:09 -07:00
|
|
|
|
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
|
|
|
if (!SendToCrashHandlerServer(
|
|
|
|
base::UTF8ToUTF16(ipc_port), message, &response)) {
|
2015-08-14 15:22:09 -07:00
|
|
|
return false;
|
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
|
|
|
}
|
2015-08-14 15:22:09 -07:00
|
|
|
|
|
|
|
// The server returns these already duplicated to be valid in this process.
|
2015-09-21 10:51:15 -07:00
|
|
|
g_signal_exception = reinterpret_cast<HANDLE>(
|
2015-09-25 13:45:32 -07:00
|
|
|
static_cast<uintptr_t>(response.registration.request_crash_dump_event));
|
|
|
|
g_signal_non_crash_dump = reinterpret_cast<HANDLE>(static_cast<uintptr_t>(
|
|
|
|
response.registration.request_non_crash_dump_event));
|
|
|
|
g_non_crash_dump_done = reinterpret_cast<HANDLE>(static_cast<uintptr_t>(
|
|
|
|
response.registration.non_crash_dump_completed_event));
|
|
|
|
|
|
|
|
g_non_crash_dump_lock = new base::Lock();
|
|
|
|
|
2015-08-14 15:22:09 -07:00
|
|
|
return true;
|
2015-04-29 18:53:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CrashpadClient::UseHandler() {
|
2015-09-25 13:45:32 -07:00
|
|
|
if (g_signal_exception == INVALID_HANDLE_VALUE ||
|
|
|
|
g_signal_non_crash_dump == INVALID_HANDLE_VALUE ||
|
|
|
|
g_non_crash_dump_done == INVALID_HANDLE_VALUE) {
|
2015-04-29 18:53:47 -07:00
|
|
|
return false;
|
2015-09-25 13:45:32 -07:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:53:47 -07:00
|
|
|
// In theory we could store the previous handler but it is not clear what
|
|
|
|
// use we have for it.
|
|
|
|
SetUnhandledExceptionFilter(&UnhandledExceptionHandler);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-25 13:45:32 -07:00
|
|
|
// static
|
|
|
|
void CrashpadClient::DumpWithoutCrash(const CONTEXT& context) {
|
|
|
|
if (g_signal_non_crash_dump == INVALID_HANDLE_VALUE ||
|
|
|
|
g_non_crash_dump_done == INVALID_HANDLE_VALUE) {
|
|
|
|
LOG(ERROR) << "haven't called SetHandler()";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In the non-crashing case, we aren't concerned about avoiding calls into
|
|
|
|
// Win32 APIs, so just use regular locking here in case of multiple threads
|
|
|
|
// calling this function. If a crash occurs while we're in here, the worst
|
|
|
|
// that can happen is that the server captures a partial dump for this path
|
|
|
|
// because on the other thread gathering a crash dump, it TerminateProcess()d,
|
|
|
|
// causing this one to abort.
|
|
|
|
base::AutoLock lock(*g_non_crash_dump_lock);
|
|
|
|
|
|
|
|
// Create a fake EXCEPTION_POINTERS to give the handler something to work
|
|
|
|
// with.
|
|
|
|
EXCEPTION_POINTERS exception_pointers = {0};
|
|
|
|
|
|
|
|
// This is logically const, but EXCEPTION_POINTERS does not declare it as
|
|
|
|
// const, so we have to cast that away from the argument.
|
|
|
|
exception_pointers.ContextRecord = const_cast<CONTEXT*>(&context);
|
|
|
|
|
|
|
|
// We include a fake exception and use a code of '0x517a7ed' (something like
|
|
|
|
// "simulated") so that it's relatively obvious in windbg that it's not
|
|
|
|
// actually an exception. Most values in
|
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363082.aspx have
|
|
|
|
// some of the top nibble set, so we make sure to pick a value that doesn't,
|
|
|
|
// so as to be unlikely to conflict.
|
|
|
|
const uint32_t kSimulatedExceptionCode = 0x517a7ed;
|
|
|
|
EXCEPTION_RECORD record = {0};
|
|
|
|
record.ExceptionCode = kSimulatedExceptionCode;
|
|
|
|
#if defined(ARCH_CPU_64_BITS)
|
|
|
|
record.ExceptionAddress = reinterpret_cast<void*>(context.Rip);
|
|
|
|
#else
|
|
|
|
record.ExceptionAddress = reinterpret_cast<void*>(context.Eip);
|
|
|
|
#endif // ARCH_CPU_64_BITS
|
|
|
|
|
|
|
|
exception_pointers.ExceptionRecord = &record;
|
|
|
|
|
|
|
|
g_non_crash_exception_information.thread_id = GetCurrentThreadId();
|
|
|
|
g_non_crash_exception_information.exception_pointers =
|
|
|
|
reinterpret_cast<crashpad::WinVMAddress>(&exception_pointers);
|
|
|
|
|
|
|
|
bool set_event_result = SetEvent(g_signal_non_crash_dump);
|
|
|
|
PLOG_IF(ERROR, !set_event_result) << "SetEvent";
|
|
|
|
|
|
|
|
DWORD wfso_result = WaitForSingleObject(g_non_crash_dump_done, INFINITE);
|
|
|
|
PLOG_IF(ERROR, wfso_result != WAIT_OBJECT_0) << "WaitForSingleObject";
|
|
|
|
}
|
|
|
|
|
2015-04-29 18:53:47 -07:00
|
|
|
} // namespace crashpad
|