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.
|
|
|
|
|
|
|
|
#ifndef CRASHPAD_UTIL_WIN_EXCEPTION_HANDLER_SERVER_H_
|
|
|
|
#define CRASHPAD_UTIL_WIN_EXCEPTION_HANDLER_SERVER_H_
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "base/synchronization/lock.h"
|
|
|
|
#include "util/win/address_types.h"
|
|
|
|
#include "util/win/scoped_handle.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
class PipeServiceContext;
|
|
|
|
class ClientData;
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
//! \brief Runs the main exception-handling server in Crashpad's handler
|
|
|
|
//! process.
|
|
|
|
class ExceptionHandlerServer {
|
|
|
|
public:
|
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
virtual ~Delegate();
|
|
|
|
|
|
|
|
//! \brief Called when the server has created the named pipe connection
|
|
|
|
//! points and is ready to service requests.
|
|
|
|
virtual void ExceptionHandlerServerStarted() = 0;
|
|
|
|
|
|
|
|
//! \brief Called when the client has signalled that it has encountered an
|
|
|
|
//! exception and so wants a crash dump to be taken.
|
|
|
|
//!
|
|
|
|
//! \param[in] process A handle to the client process. Ownership of the
|
|
|
|
//! lifetime of this handle is not passed to the delegate.
|
|
|
|
//! \param[in] exception_information_address The address in the client's
|
|
|
|
//! address space of an ExceptionInformation structure.
|
|
|
|
//! \return The exit code that should be used when terminating the client
|
|
|
|
//! process.
|
|
|
|
virtual unsigned int ExceptionHandlerServerException(
|
|
|
|
HANDLE process,
|
|
|
|
WinVMAddress exception_information_address) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! \brief Constructs the exception handling server.
|
2015-09-03 13:31:19 -07:00
|
|
|
ExceptionHandlerServer();
|
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();
|
|
|
|
|
|
|
|
//! \brief Runs the exception-handling server.
|
|
|
|
//!
|
2015-09-03 13:31:19 -07:00
|
|
|
//! \param[in] delegate The interface to which the exceptions are delegated
|
|
|
|
//! when they are caught in Run(). Ownership is not transferred.
|
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
|
|
|
//! \param[in] pipe_name The name of the pipe to listen on. Must be of the
|
|
|
|
//! form "\\.\pipe\<some_name>".
|
2015-09-03 13:31:19 -07:00
|
|
|
void Run(Delegate* delegate, const std::string& 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
|
|
|
|
|
|
|
//! \brief Stops the exception-handling server. Returns immediately. The
|
|
|
|
//! object must not be destroyed until Run() returns.
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool ServiceClientConnection(
|
|
|
|
const internal::PipeServiceContext& service_context);
|
|
|
|
static DWORD __stdcall PipeServiceProc(void* ctx);
|
|
|
|
static void __stdcall OnDumpEvent(void* ctx, BOOLEAN);
|
|
|
|
static void __stdcall OnProcessEnd(void* ctx, BOOLEAN);
|
|
|
|
|
|
|
|
ScopedKernelHANDLE port_;
|
|
|
|
|
|
|
|
base::Lock clients_lock_;
|
|
|
|
std::set<internal::ClientData*> clients_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServer);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
#endif // CRASHPAD_UTIL_WIN_EXCEPTION_HANDLER_SERVER_H_
|