2018-01-16 14:46:29 -08:00
|
|
|
// Copyright 2018 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/process/process_memory_fuchsia.h"
|
|
|
|
|
2018-01-18 11:47:55 -08:00
|
|
|
#include <limits>
|
|
|
|
|
2018-01-16 14:46:29 -08:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/fuchsia/fuchsia_logging.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
ProcessMemoryFuchsia::ProcessMemoryFuchsia()
|
|
|
|
: ProcessMemory(), process_(), initialized_() {}
|
|
|
|
|
|
|
|
ProcessMemoryFuchsia::~ProcessMemoryFuchsia() {}
|
|
|
|
|
2018-07-30 15:50:17 -07:00
|
|
|
bool ProcessMemoryFuchsia::Initialize(const zx::unowned_process& process) {
|
|
|
|
return Initialize(*process);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessMemoryFuchsia::Initialize(const zx::process& process) {
|
2018-01-16 14:46:29 -08:00
|
|
|
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
2018-07-30 15:50:17 -07:00
|
|
|
process_ = zx::unowned_process(process);
|
2018-01-16 14:46:29 -08:00
|
|
|
INITIALIZATION_STATE_SET_VALID(initialized_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-18 11:47:55 -08:00
|
|
|
ssize_t ProcessMemoryFuchsia::ReadUpTo(VMAddress address,
|
|
|
|
size_t size,
|
|
|
|
void* buffer) const {
|
2018-01-16 14:46:29 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
2018-01-18 11:47:55 -08:00
|
|
|
DCHECK_LE(size, size_t{std::numeric_limits<ssize_t>::max()});
|
|
|
|
|
2018-01-16 14:46:29 -08:00
|
|
|
size_t actual;
|
2018-07-30 15:50:17 -07:00
|
|
|
zx_status_t status = process_->read_memory(address, buffer, size, &actual);
|
2018-01-16 14:46:29 -08:00
|
|
|
|
|
|
|
if (status != ZX_OK) {
|
|
|
|
ZX_LOG(ERROR, status) << "zx_process_read_memory";
|
2018-01-18 11:47:55 -08:00
|
|
|
return -1;
|
2018-01-16 14:46:29 -08:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:47:55 -08:00
|
|
|
return actual;
|
2018-01-16 14:46:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace crashpad
|