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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright (c) 2011-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* Virtual memory map management.
*/
#ifndef _VM_VM_MAP_H
#define _VM_VM_MAP_H
#include <kern/list.h>
#include <kern/mutex.h>
#include <kern/rbtree.h>
#include <kern/stdint.h>
#include <machine/pmap.h>
#include <vm/vm_adv.h>
#include <vm/vm_inherit.h>
#include <vm/vm_prot.h>
/*
* Mapping flags.
*
* Unless otherwise mentioned, these can also be used as map entry flags.
*/
#define VM_MAP_NOMERGE 0x10000
#define VM_MAP_FIXED 0x20000 /* Not an entry flag */
/*
* Macro used to forge "packed" flags.
*/
#define VM_MAP_FLAGS(prot, maxprot, inherit, advice, mapflags) \
((prot) | ((maxprot) << 4) | ((inherit) << 8) | ((advice) << 12) \
| (mapflags))
/*
* Flags usable as map entry flags.
*
* Map entry flags also use the packed format.
*/
#define VM_MAP_ENTRY_MASK (VM_MAP_NOMERGE | 0xffff)
/*
* Macros used to extract specific properties out of packed flags.
*/
#define VM_MAP_PROT(flags) ((flags) & 0xf)
#define VM_MAP_MAXPROT(flags) (((flags) & 0xf0) >> 4)
#define VM_MAP_INHERIT(flags) (((flags) & 0xf00) >> 8)
#define VM_MAP_ADVICE(flags) (((flags) & 0xf000) >> 12)
/*
* Memory range descriptor.
*/
struct vm_map_entry {
struct list list_node;
struct rbtree_node tree_node;
uintptr_t start;
uintptr_t end;
struct vm_object *object;
uint64_t offset;
int flags;
};
/*
* Memory map.
*/
struct vm_map {
struct mutex lock;
struct list entry_list;
struct rbtree entry_tree;
unsigned int nr_entries;
uintptr_t start;
uintptr_t end;
size_t size;
struct vm_map_entry *lookup_cache;
uintptr_t find_cache;
size_t find_cache_threshold;
struct pmap *pmap;
};
/*
* Create a virtual mapping.
*/
int vm_map_enter(struct vm_map *map, uintptr_t *startp,
size_t size, size_t align, int flags,
struct vm_object *object, uint64_t offset);
/*
* Remove mappings from start to end.
*/
void vm_map_remove(struct vm_map *map, uintptr_t start, uintptr_t end);
/*
* Set up the vm_map module.
*/
void vm_map_setup(void);
/*
* Create a VM map.
*/
int vm_map_create(struct vm_map **mapp);
/*
* Display information about a memory map.
*/
void vm_map_info(struct vm_map *map);
#endif /* _VM_VM_MAP_H */
|