forked from includeos/IncludeOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.cpp
More file actions
71 lines (59 loc) · 2.12 KB
/
service.cpp
File metadata and controls
71 lines (59 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// 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 <os>
#include <kernel/memory.hpp>
#include <util/bitops.hpp>
using namespace util;
void Service::start(const std::string&)
{
INFO("Memmap", "Testing the kernel memory map");
auto& map = os::mem::vmmap();
Expects(map.size());
// Verify that you can't create any overlapping ranges
const auto s = map.size();
size_t failed = 0;
auto i = 0;
for (auto it : map) {
try {
auto m = it.second;
Expects(m.size());
int offs = rand() % m.size() + 1;
uintptr_t begin = i++ % 2 ? m.addr_start() + offs : m.addr_start() - offs;
uintptr_t end = begin + offs * 2;
os::mem::Fixed_memory_range rng {begin, end, "Can't work"};
map.assign_range(std::move(rng));
} catch (const std::exception& e) {
failed++;
}
}
Expects(failed == s);
Expects(map.size() == s);
// mem::map is using memory_map to keep track of virutal memory
// TODO: we might consider consolidating ranges with mappings.
auto m = os::mem::map({42_GiB, 42_GiB, os::mem::Access::read, 1_GiB},
"Test range");
Expects(m);
Expects(map.size() == s + 1);
auto key = map.in_range(42_GiB);
Expects(key == 42_GiB);
auto rng = map.at(key);
Expects(rng.size() == 1_GiB);
// TODO: There's an unimplemented map.assign_range(size) to integrate.
// auto& given = map.assign_range(5_GiB);
// Expects(given.size() == 5_GiB);
INFO("Memmap", "SUCCESS");
}