1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <fbl/algorithm.h>
6 #include <fbl/alloc_checker.h>
7 #include <lib/fzl/owned-vmo-mapper.h>
8 #include <string.h>
9
10 #include <utility>
11
12 namespace fzl {
13
CreateAndMap(uint64_t size,const char * name,zx_vm_option_t map_options,fbl::RefPtr<VmarManager> vmar_manager,uint32_t cache_policy)14 zx_status_t OwnedVmoMapper::CreateAndMap(uint64_t size,
15 const char* name,
16 zx_vm_option_t map_options,
17 fbl::RefPtr<VmarManager> vmar_manager,
18 uint32_t cache_policy) {
19 zx::vmo temp;
20 zx_status_t res = VmoMapper::CreateAndMap(size,
21 map_options,
22 std::move(vmar_manager),
23 &temp,
24 ZX_RIGHT_SAME_RIGHTS,
25 cache_policy);
26
27 if (res == ZX_OK) {
28 temp.set_property(ZX_PROP_NAME, name, name ? strlen(name) : 0);
29 vmo_ = std::move(temp);
30 }
31
32 return res;
33 }
34
Map(zx::vmo vmo,uint64_t size,zx_vm_option_t map_options,fbl::RefPtr<VmarManager> vmar_manager)35 zx_status_t OwnedVmoMapper::Map(zx::vmo vmo,
36 uint64_t size,
37 zx_vm_option_t map_options,
38 fbl::RefPtr<VmarManager> vmar_manager) {
39 zx_status_t res = VmoMapper::Map(vmo, 0, size, map_options, vmar_manager);
40
41 if (res == ZX_OK) {
42 vmo_ = std::move(vmo);
43 }
44
45 return res;
46 }
47
48 } // namespace fzl
49