blob: dd4ade67059aea1711b3e36cf5e15ec322181808 [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
#include <ktl/array.h>
#include <ktl/string_view.h>
#include <vm/pinned_vm_object.h>
#include <vm/vm_address_region.h>
class Handle;
// This maintains a kernel mapping from a VMO; mapped pages must stay pinned to
// prevent kernel-mode page faults. Destroying this object unmaps and unpins.
class KernelMappedVmo {
// Initialize with a kernel mapping from the VMO.
zx_status_t Init(fbl::RefPtr<VmObject> vmo, size_t offset, size_t size, const char* name);
// Publish this VMO to userland as a read-only handle using the given name
// and content size.
Handle* Publish(ktl::string_view vmo_name, size_t content_size);
template <size_t N>
Handle* Publish(const ktl::array<char, N>& name, size_t content_size) {
return Publish(ktl::string_view(, name.size()), content_size);
// Return the bounds of the mapping in the kernel address space.
vaddr_t base_locking() const { return mapping_->base_locking(); }
size_t size_locking() const { return mapping_->size_locking(); }
PinnedVmObject pinned_vmo_;
fbl::RefPtr<VmMapping> mapping_;