forked from xinyu391/zircon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fzl] Add a VMO-owning variant of VmoMapper
This allows clients to create mappings alongside a vmo, without necessarily enabling resize semantics. Test: owned-vmo-mapper-tests in /boot/test/sys/libfzl-test Change-Id: I8be9e4b40b97dfc0129bfad26d81810afbf63631
- Loading branch information
1 parent
aecb14b
commit 12768d7
Showing
9 changed files
with
540 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2018 The Fuchsia Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#pragma once | ||
|
||
#include <fbl/macros.h> | ||
#include <fbl/ref_ptr.h> | ||
#include <fbl/ref_counted.h> | ||
#include <lib/fzl/vmar-manager.h> | ||
#include <lib/fzl/vmo-mapper.h> | ||
#include <lib/zx/vmo.h> | ||
|
||
namespace fzl { | ||
|
||
// OwnedVmoWrapper is a convenience wrapper around the underlying VmoMapper | ||
// which also takes ownership of the underlying VMO. | ||
class OwnedVmoMapper : protected VmoMapper { | ||
public: | ||
OwnedVmoMapper() = default; | ||
~OwnedVmoMapper() { Reset(); } | ||
DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(OwnedVmoMapper); | ||
|
||
// Move support | ||
OwnedVmoMapper(OwnedVmoMapper&& other) { | ||
MoveFromOther(&other); | ||
} | ||
|
||
OwnedVmoMapper& operator=(OwnedVmoMapper&& other) { | ||
Reset(); | ||
MoveFromOther(&other); | ||
return *this; | ||
} | ||
|
||
// See |VmoMapper::CreateAndMap|. | ||
zx_status_t CreateAndMap(uint64_t size, | ||
const char* name, | ||
zx_vm_option_t map_options = ZX_VM_PERM_READ | ZX_VM_PERM_WRITE, | ||
fbl::RefPtr<VmarManager> vmar_manager = nullptr, | ||
uint32_t cache_policy = 0); | ||
|
||
// See |VmoMapper::Map|. | ||
zx_status_t Map(zx::vmo vmo, | ||
uint64_t size = 0, | ||
zx_vm_option_t map_options = ZX_VM_PERM_READ | ZX_VM_PERM_WRITE, | ||
fbl::RefPtr<VmarManager> vmar_manager = nullptr); | ||
|
||
// Reset the VMO from whichever VMAR it was mapped into, then release. | ||
void Reset() { | ||
vmo_.reset(); | ||
VmoMapper::Unmap(); | ||
} | ||
|
||
const zx::vmo& vmo() const { return vmo_; } | ||
|
||
using VmoMapper::start; | ||
using VmoMapper::size; | ||
using VmoMapper::manager; | ||
|
||
protected: | ||
void MoveFromOther(OwnedVmoMapper* other) { | ||
vmo_ = fbl::move(other->vmo_); | ||
VmoMapper::MoveFromOther(other); | ||
} | ||
|
||
private: | ||
zx::vmo vmo_; | ||
}; | ||
|
||
} // namespace fzl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2018 The Fuchsia Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <fbl/algorithm.h> | ||
#include <fbl/alloc_checker.h> | ||
#include <lib/fzl/owned-vmo-mapper.h> | ||
#include <string.h> | ||
|
||
namespace fzl { | ||
|
||
zx_status_t OwnedVmoMapper::CreateAndMap(uint64_t size, | ||
const char* name, | ||
zx_vm_option_t map_options, | ||
fbl::RefPtr<VmarManager> vmar_manager, | ||
uint32_t cache_policy) { | ||
zx::vmo temp; | ||
zx_status_t res = VmoMapper::CreateAndMap(size, | ||
map_options, | ||
fbl::move(vmar_manager), | ||
&temp, | ||
ZX_RIGHT_SAME_RIGHTS, | ||
cache_policy); | ||
|
||
if (res == ZX_OK) { | ||
temp.set_property(ZX_PROP_NAME, name, name ? strlen(name) : 0); | ||
vmo_ = fbl::move(temp); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
zx_status_t OwnedVmoMapper::Map(zx::vmo vmo, | ||
uint64_t size, | ||
zx_vm_option_t map_options, | ||
fbl::RefPtr<VmarManager> vmar_manager) { | ||
zx_status_t res = VmoMapper::Map(vmo, 0, size, map_options, vmar_manager); | ||
|
||
if (res == ZX_OK) { | ||
vmo_ = fbl::move(vmo); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
} // namespace fzl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.