crashpad/util/mach/composite_mach_message_server.cc
Mark Mentovai 6278690abe Update copyright boilerplate, 2022 edition (Crashpad)
sed -i '' -E -e 's/Copyright (.+) The Crashpad Authors\. All rights reserved\.$/Copyright \1 The Crashpad Authors/' $(git grep -El 'Copyright (.+) The Crashpad Authors\. All rights reserved\.$')

Bug: chromium:1098010
Change-Id: I8d6138469ddbe3d281a5d83f64cf918ec2491611
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3878262
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-09-06 23:54:07 +00:00

88 lines
2.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2014 The Crashpad Authors
//
// 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/mach/composite_mach_message_server.h"
#include <algorithm>
#include <ostream>
#include <utility>
#include "base/check_op.h"
#include "util/mach/mach_message.h"
namespace crashpad {
CompositeMachMessageServer::CompositeMachMessageServer()
: MachMessageServer::Interface(),
handler_map_(),
request_size_(sizeof(mach_msg_header_t)),
reply_size_(sizeof(mig_reply_error_t)) {
}
CompositeMachMessageServer::~CompositeMachMessageServer() {
}
void CompositeMachMessageServer::AddHandler(
MachMessageServer::Interface* handler) {
// Other cycles would be invalid as well, but they arent currently checked.
DCHECK_NE(handler, this);
std::set<mach_msg_id_t> request_ids = handler->MachMessageServerRequestIDs();
for (mach_msg_id_t request_id : request_ids) {
std::pair<HandlerMap::const_iterator, bool> result =
handler_map_.insert(std::make_pair(request_id, handler));
CHECK(result.second) << "duplicate request ID " << request_id;
}
request_size_ =
std::max(request_size_, handler->MachMessageServerRequestSize());
reply_size_ = std::max(reply_size_, handler->MachMessageServerReplySize());
}
bool CompositeMachMessageServer::MachMessageServerFunction(
const mach_msg_header_t* in,
mach_msg_header_t* out,
bool* destroy_complex_request) {
HandlerMap::const_iterator iterator = handler_map_.find(in->msgh_id);
if (iterator == handler_map_.end()) {
// Do what MIG-generated server routines do when they cant dispatch a
// message.
PrepareMIGReplyFromRequest(in, out);
SetMIGReplyError(out, MIG_BAD_ID);
return false;
}
MachMessageServer::Interface* handler = iterator->second;
return handler->MachMessageServerFunction(in, out, destroy_complex_request);
}
std::set<mach_msg_id_t>
CompositeMachMessageServer::MachMessageServerRequestIDs() {
std::set<mach_msg_id_t> request_ids;
for (const auto& entry : handler_map_) {
request_ids.insert(entry.first);
}
return request_ids;
}
mach_msg_size_t CompositeMachMessageServer::MachMessageServerRequestSize() {
return request_size_;
}
mach_msg_size_t CompositeMachMessageServer::MachMessageServerReplySize() {
return reply_size_;
}
} // namespace crashpad