gem5 v24.0.0.0
Loading...
Searching...
No Matches
mem_state.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017-2020 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef SRC_SIM_MEM_STATE_HH
30#define SRC_SIM_MEM_STATE_HH
31
32#include <fcntl.h>
33#include <unistd.h>
34
35#include <list>
36#include <memory>
37#include <string>
38#include <vector>
39
40#include "debug/Vma.hh"
41#include "mem/page_table.hh"
43#include "sim/serialize.hh"
44#include "sim/vma.hh"
45
46namespace gem5
47{
48
49class Process;
50struct ProcessParams;
51class System;
52
67class MemState : public Serializable
68{
69 public:
70 MemState(Process *owner, Addr brk_point, Addr stack_base,
71 Addr max_stack_size, Addr next_thread_stack_base,
72 Addr mmap_end);
73
74 MemState& operator=(const MemState &in);
75
79 void resetOwner(Process *owner);
80
85 Addr getBrkPoint() const { return _brkPoint; }
86 Addr getStackBase() const { return _stackBase; }
87 Addr getStackSize() const { return _stackSize; }
89 Addr getStackMin() const { return _stackMin; }
91 Addr getMmapEnd() const { return _mmapEnd; }
92 void setBrkPoint(Addr brk_point) { _brkPoint = brk_point; }
93 void setStackBase(Addr stack_base) { _stackBase = stack_base; }
94 void setStackSize(Addr stack_size) { _stackSize = stack_size; }
95 void setMaxStackSize(Addr max_stack) { _maxStackSize = max_stack; }
96 void setStackMin(Addr stack_min) { _stackMin = stack_min; }
98 void setMmapEnd(Addr mmap_end) { _mmapEnd = mmap_end; }
99
100 /*
101 * Extend the end of the mmap region by length bytes. Once a contiguous
102 * region of free virtual memory is found the start of that region is
103 * returned.
104 */
105 Addr extendMmap(Addr length);
106
116 bool isUnmapped(Addr start_addr, Addr length);
117
130 void mapRegion(Addr start_addr, Addr length,
131 const std::string& name="anon", int sim_fd=-1,
132 Addr offset=0);
133
142 void unmapRegion(Addr start_addr, Addr length);
143
154 void remapRegion(Addr start_addr, Addr new_start_addr, Addr length);
155
163 void updateBrkRegion(Addr old_brk, Addr new_brk);
164
173 bool fixupFault(Addr vaddr);
174
186 void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
187
188 void
189 serialize(CheckpointOut &cp) const override
190 {
191 paramOut(cp, "brkPoint", _brkPoint);
192 paramOut(cp, "stackBase", _stackBase);
193 paramOut(cp, "stackSize", _stackSize);
194 paramOut(cp, "maxStackSize", _maxStackSize);
195 paramOut(cp, "stackMin", _stackMin);
196 paramOut(cp, "nextThreadStackBase", _nextThreadStackBase);
197 paramOut(cp, "mmapEnd", _mmapEnd);
198
199 ScopedCheckpointSection sec(cp, "vmalist");
200 paramOut(cp, "size", _vmaList.size());
201 int count = 0;
202 for (auto vma : _vmaList) {
203 ScopedCheckpointSection sec(cp, csprintf("Vma%d", count++));
204 paramOut(cp, "name", vma.getName());
205 if (vma.hasHostBuf()) {
206 paramOut(cp, "fileOffset", vma.getFileMappingOffset());
207 }
208 paramOut(cp, "addrRangeStart", vma.start());
209 paramOut(cp, "addrRangeEnd", vma.end());
210 }
211 }
212
213 void
215 {
216 paramIn(cp, "brkPoint", _brkPoint);
217 paramIn(cp, "stackBase", _stackBase);
218 paramIn(cp, "stackSize", _stackSize);
219 paramIn(cp, "maxStackSize", _maxStackSize);
220 paramIn(cp, "stackMin", _stackMin);
221 paramIn(cp, "nextThreadStackBase", _nextThreadStackBase);
222 paramIn(cp, "mmapEnd", _mmapEnd);
223
224 int count;
225 ScopedCheckpointSection sec(cp, "vmalist");
226 paramIn(cp, "size", count);
227 for (int i = 0; i < count; ++i) {
228 ScopedCheckpointSection sec(cp, csprintf("Vma%d", i));
229 std::string name;
230 Addr start;
231 Addr end;
232 off_t offset = 0;
233 int host_fd = -1;
234 paramIn(cp, "name", name);
235 if (optParamIn(cp, "fileOffset", offset, false)) {
236 host_fd = open(name.c_str(), O_RDONLY);
237 fatal_if(host_fd < 0,
238 "Failed to open %s file "
239 "while unserializing file-backed VMA\n", name);
240 }
241 paramIn(cp, "addrRangeStart", start);
242 paramIn(cp, "addrRangeEnd", end);
243 _vmaList.emplace_back(AddrRange(start, end), _pageBytes, name,
244 host_fd, offset);
245 close(host_fd);
246 }
247 }
248
252 std::string printVmaList();
253
254 private:
258 void replicatePage(const MemState &in, Addr vaddr, Addr new_paddr,
259 bool alloc_page);
260
264 System * system() const;
265
270
279
293};
294
295} // namespace gem5
296
297#endif
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition addr_range.hh:82
This class holds the memory state for the Process class and all of its derived, architecture-specific...
Definition mem_state.hh:68
std::list< VMA > _vmaList
The _vmaList member is a list of virtual memory areas in the target application space that have been ...
Definition mem_state.hh:292
Addr getBrkPoint() const
Get/set base addresses and sizes for the stack and data segments of the process' memory.
Definition mem_state.hh:85
Process * _ownerProcess
Owner process of MemState.
Definition mem_state.hh:269
void setMmapEnd(Addr mmap_end)
Definition mem_state.hh:98
Addr extendMmap(Addr length)
Definition mem_state.cc:457
Addr getMaxStackSize() const
Definition mem_state.hh:88
void setStackSize(Addr stack_size)
Definition mem_state.hh:94
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page.
Definition mem_state.cc:392
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition mem_state.hh:189
void setNextThreadStackBase(Addr ntsb)
Definition mem_state.hh:97
void replicatePage(const MemState &in, Addr vaddr, Addr new_paddr, bool alloc_page)
Addr _nextThreadStackBase
Definition mem_state.hh:277
void setStackBase(Addr stack_base)
Definition mem_state.hh:93
void updateBrkRegion(Addr old_brk, Addr new_brk)
Change the end of a process' program break.
Definition mem_state.cc:107
Addr getStackSize() const
Definition mem_state.hh:87
void setBrkPoint(Addr brk_point)
Definition mem_state.hh:92
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition mem_state.hh:214
std::string printVmaList()
Print the list of VMAs in a format similar to /proc/self/maps.
Definition mem_state.cc:485
Addr getStackMin() const
Definition mem_state.hh:89
void setMaxStackSize(Addr max_stack)
Definition mem_state.hh:95
bool isUnmapped(Addr start_addr, Addr length)
Check if any page in the virtual address range from start_addr to start_addr + length is already mapp...
Definition mem_state.cc:82
void resetOwner(Process *owner)
Change the Process owner in case this MemState is copied.
Definition mem_state.cc:76
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
Given the vaddr and size, this method will chunk the allocation into page granularity and then reques...
Addr getStackBase() const
Definition mem_state.hh:86
MemState & operator=(const MemState &in)
Definition mem_state.cc:57
Addr getNextThreadStackBase() const
Definition mem_state.hh:90
Addr getMmapEnd() const
Definition mem_state.hh:91
MemState(Process *owner, Addr brk_point, Addr stack_base, Addr max_stack_size, Addr next_thread_stack_base, Addr mmap_end)
Definition mem_state.cc:44
void unmapRegion(Addr start_addr, Addr length)
Unmap a pre-existing region.
Definition mem_state.cc:192
void remapRegion(Addr start_addr, Addr new_start_addr, Addr length)
Remap a pre-existing region.
Definition mem_state.cc:289
void mapRegion(Addr start_addr, Addr length, const std::string &name="anon", int sim_fd=-1, Addr offset=0)
Add a new memory region.
Definition mem_state.cc:172
void setStackMin(Addr stack_min)
Definition mem_state.hh:96
System * system() const
Basic support for object serialization.
Definition serialize.hh:170
STL list class.
Definition stl.hh:51
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
bool optParamIn(CheckpointIn &cp, const std::string &name, T &param, bool do_warn=true)
This function is used for restoring optional parameters from the checkpoint.
Definition serialize.hh:357
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 7 > vma
Definition vector.hh:79
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition types.cc:40
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition types.cc:72
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
Declarations of a non-full system Page Table.
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0