2017-12-06 10:08:11 -08:00
|
|
|
// Copyright 2017 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 "handler/fuchsia/exception_handler_server.h"
|
|
|
|
|
2018-07-30 15:50:17 -07:00
|
|
|
#include <lib/zx/time.h>
|
2018-05-04 12:20:52 -07:00
|
|
|
#include <zircon/syscalls/port.h>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "base/fuchsia/fuchsia_logging.h"
|
2017-12-06 10:08:11 -08:00
|
|
|
#include "base/logging.h"
|
2018-05-04 12:20:52 -07:00
|
|
|
#include "handler/fuchsia/crash_report_exception_handler.h"
|
|
|
|
#include "util/fuchsia/system_exception_port_key.h"
|
2017-12-06 10:08:11 -08:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
2018-07-30 15:50:17 -07:00
|
|
|
ExceptionHandlerServer::ExceptionHandlerServer(zx::job root_job,
|
|
|
|
zx::port exception_port)
|
2018-05-04 12:20:52 -07:00
|
|
|
: root_job_(std::move(root_job)),
|
|
|
|
exception_port_(std::move(exception_port)) {}
|
2017-12-06 10:08:11 -08:00
|
|
|
|
2018-05-04 12:20:52 -07:00
|
|
|
ExceptionHandlerServer::~ExceptionHandlerServer() = default;
|
2017-12-06 10:08:11 -08:00
|
|
|
|
|
|
|
void ExceptionHandlerServer::Run(CrashReportExceptionHandler* handler) {
|
2018-05-04 12:20:52 -07:00
|
|
|
while (true) {
|
|
|
|
zx_port_packet_t packet;
|
2018-07-30 15:50:17 -07:00
|
|
|
zx_status_t status = exception_port_.wait(zx::time::infinite(), &packet);
|
2018-05-04 12:20:52 -07:00
|
|
|
if (status != ZX_OK) {
|
|
|
|
ZX_LOG(ERROR, status) << "zx_port_wait, aborting";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet.key != kSystemExceptionPortKey) {
|
|
|
|
LOG(ERROR) << "unexpected packet key, ignoring";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:45:51 -07:00
|
|
|
bool result =
|
|
|
|
handler->HandleException(packet.exception.pid, packet.exception.tid);
|
2018-05-04 12:20:52 -07:00
|
|
|
if (!result) {
|
|
|
|
LOG(ERROR) << "HandleException failed";
|
|
|
|
}
|
|
|
|
}
|
2017-12-06 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace crashpad
|