6 /** Represents one mapping in a mapping tree.
7 Instances of Mapping ("mappings") work as an iterator over a
8 mapping tree. Mapping trees are never visible on the user level.
9 Mappings are looked up directly in the mapping database (class
10 Mapdb) using Mapdb::lookup(). When carrying out such a
11 lookup, the mapping database locks the corresponding mapping tree
12 before returning the mapping. This mapping can the be used to
13 iterate over the tree and to look up other mappings in the tree.
14 The mapping tree is unlocked (and all mappings pointing into it
15 become invalid) when Mapdb::free is called with any one of its
20 friend class Jdb_mapdb;
24 Depth_root = 0, Depth_max = 252,
25 Depth_submap = 253, Depth_empty = 254, Depth_end = 255
28 enum { Alignment = Mapping_entry::Alignment };
31 Mapping(const Mapping&); // this constructor is undefined.
35 } __attribute__((packed));
61 @return the address space into which the frame is mapped.
63 PUBLIC inline NEEDS [Mapping::data]
65 Mapping::space() const
67 return data()->space();
70 /** Set address space.
71 @param space the address space into which the frame is mapped.
73 PUBLIC inline NEEDS [Mapping::data]
75 Mapping::set_space(Space *space)
77 data()->set_space(space);
81 @return the virtual address at which the frame is mapped.
83 PUBLIC inline NEEDS[Mapping::data]
87 return Page_number::create(data()->data.address);
90 /** Set virtual address.
91 @param address the virtual address at which the frame is mapped.
93 PUBLIC inline NEEDS[Mapping::data]
95 Mapping::set_page(Page_number address)
97 data()->data.address = address.value();
100 /** Depth of mapping in mapping tree. */
103 Mapping::depth() const
105 return data()->_depth;
108 /** Set depth of mapping in mapping tree. */
111 Mapping::set_depth(unsigned depth)
113 data()->_depth = depth;
117 @return true if this is unused.
119 PUBLIC inline NEEDS [Mapping::data]
121 Mapping::unused() const
123 return depth() >= Depth_empty;
128 Mapping::is_end_tag() const
130 return depth() == Depth_end;
135 Mapping::submap() const
137 return (data()->_depth == Depth_submap)
144 Mapping::set_submap(Treemap *treemap)
146 data()->_submap = treemap;
147 data()->_depth = Depth_submap;
152 Mapping::set_unused()
154 data()->_depth = Depth_empty;
158 @return parent mapping of this mapping.
163 if (depth() <= Depth_root)
164 return 0; // Sigma0 mappings don't have a parent.
166 // Iterate over mapping entries of this tree backwards until we find
167 // an entry with a depth smaller than ours. (We assume here that
168 // "special" depths (empty, end) are larger than Depth_max.)
169 Mapping *m = this - 1;
171 // NOTE: Depth_unused / Depth_submap are high, so no need to test
173 while (m->depth() >= depth())