gem5  v20.1.0.0
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 <list>
33 #include <memory>
34 #include <string>
35 #include <vector>
36 
37 #include "config/the_isa.hh"
38 #include "debug/Vma.hh"
39 #include "mem/page_table.hh"
41 #include "sim/serialize.hh"
42 #include "sim/vma.hh"
43 
44 class Process;
45 class ProcessParams;
46 class System;
47 
62 class MemState : public Serializable
63 {
64  public:
65  MemState(Process *owner, Addr brk_point, Addr stack_base,
66  Addr max_stack_size, Addr next_thread_stack_base,
67  Addr mmap_end);
68 
69  MemState& operator=(const MemState &in);
70 
74  void resetOwner(Process *owner);
75 
80  Addr getBrkPoint() const { return _brkPoint; }
81  Addr getStackBase() const { return _stackBase; }
82  Addr getStackSize() const { return _stackSize; }
83  Addr getMaxStackSize() const { return _maxStackSize; }
84  Addr getStackMin() const { return _stackMin; }
86  Addr getMmapEnd() const { return _mmapEnd; }
87  void setBrkPoint(Addr brk_point) { _brkPoint = brk_point; }
88  void setStackBase(Addr stack_base) { _stackBase = stack_base; }
89  void setStackSize(Addr stack_size) { _stackSize = stack_size; }
90  void setMaxStackSize(Addr max_stack) { _maxStackSize = max_stack; }
91  void setStackMin(Addr stack_min) { _stackMin = stack_min; }
93  void setMmapEnd(Addr mmap_end) { _mmapEnd = mmap_end; }
94 
95  /*
96  * Extend the end of the mmap region by length bytes. Once a contiguous
97  * region of free virtual memory is found the start of that region is
98  * returned.
99  */
101 
111  bool isUnmapped(Addr start_addr, Addr length);
112 
125  void mapRegion(Addr start_addr, Addr length,
126  const std::string& name="anon", int sim_fd=-1,
127  Addr offset=0);
128 
137  void unmapRegion(Addr start_addr, Addr length);
138 
149  void remapRegion(Addr start_addr, Addr new_start_addr, Addr length);
150 
158  void updateBrkRegion(Addr old_brk, Addr new_brk);
159 
168  bool fixupFault(Addr vaddr);
169 
181  void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
182 
183  void
184  serialize(CheckpointOut &cp) const override
185  {
186  paramOut(cp, "brkPoint", _brkPoint);
187  paramOut(cp, "stackBase", _stackBase);
188  paramOut(cp, "stackSize", _stackSize);
189  paramOut(cp, "maxStackSize", _maxStackSize);
190  paramOut(cp, "stackMin", _stackMin);
191  paramOut(cp, "nextThreadStackBase", _nextThreadStackBase);
192  paramOut(cp, "mmapEnd", _mmapEnd);
193 
194  ScopedCheckpointSection sec(cp, "vmalist");
195  paramOut(cp, "size", _vmaList.size());
196  int count = 0;
197  for (auto vma : _vmaList) {
198  ScopedCheckpointSection sec(cp, csprintf("Vma%d", count++));
199  paramOut(cp, "name", vma.getName());
200  paramOut(cp, "addrRangeStart", vma.start());
201  paramOut(cp, "addrRangeEnd", vma.end());
202  }
203  }
204 
205  void
207  {
208  paramIn(cp, "brkPoint", _brkPoint);
209  paramIn(cp, "stackBase", _stackBase);
210  paramIn(cp, "stackSize", _stackSize);
211  paramIn(cp, "maxStackSize", _maxStackSize);
212  paramIn(cp, "stackMin", _stackMin);
213  paramIn(cp, "nextThreadStackBase", _nextThreadStackBase);
214  paramIn(cp, "mmapEnd", _mmapEnd);
215 
216  int count;
217  ScopedCheckpointSection sec(cp, "vmalist");
218  paramIn(cp, "size", count);
219  for (int i = 0; i < count; ++i) {
220  ScopedCheckpointSection sec(cp, csprintf("Vma%d", i));
221  std::string name;
222  Addr start;
223  Addr end;
224  paramIn(cp, "name", name);
225  paramIn(cp, "addrRangeStart", start);
226  paramIn(cp, "addrRangeEnd", end);
227  _vmaList.emplace_back(AddrRange(start, end), _pageBytes, name);
228  }
229  }
230 
234  std::string printVmaList();
235 
236  private:
241 
250 
255 
269 };
270 
271 #endif
MemState::_ownerProcess
Process * _ownerProcess
Owner process of MemState.
Definition: mem_state.hh:240
MemState::printVmaList
std::string printVmaList()
Print the list of VMAs in a format similar to /proc/self/maps.
Definition: mem_state.cc:479
MemState::setMmapEnd
void setMmapEnd(Addr mmap_end)
Definition: mem_state.hh:93
MemState::MemState
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:41
length
uint8_t length
Definition: inet.hh:422
MemState
This class holds the memory state for the Process class and all of its derived, architecture-specific...
Definition: mem_state.hh:62
MemState::isUnmapped
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:80
serialize.hh
MemState::resetOwner
void resetOwner(Process *owner)
Change the Process owner in case this MemState is copied.
Definition: mem_state.cc:74
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
MemState::remapRegion
void remapRegion(Addr start_addr, Addr new_start_addr, Addr length)
Remap a pre-existing region.
Definition: mem_state.cc:282
Process
Definition: process.hh:65
MemState::operator=
MemState & operator=(const MemState &in)
Definition: mem_state.cc:54
Serializable
Basic support for object serialization.
Definition: serialize.hh:172
X86ISA::count
count
Definition: misc.hh:703
MemState::_pageBytes
Addr _pageBytes
Definition: mem_state.hh:242
paramOut
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
Definition: types.cc:38
MemState::getStackBase
Addr getStackBase() const
Definition: mem_state.hh:81
cp
Definition: cprintf.cc:40
AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:68
MemState::setStackMin
void setStackMin(Addr stack_min)
Definition: mem_state.hh:91
System
Definition: system.hh:73
MemState::extendMmap
Addr extendMmap(Addr length)
Definition: mem_state.cc:451
MemState::setNextThreadStackBase
void setNextThreadStackBase(Addr ntsb)
Definition: mem_state.hh:92
MipsISA::vaddr
vaddr
Definition: pra_constants.hh:275
MemState::_stackSize
Addr _stackSize
Definition: mem_state.hh:245
MemState::getStackSize
Addr getStackSize() const
Definition: mem_state.hh:82
MemState::_vmaList
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:268
MemState::mapRegion
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:164
MemState::getBrkPoint
Addr getBrkPoint() const
Get/set base addresses and sizes for the stack and data segments of the process' memory.
Definition: mem_state.hh:80
MemState::_endBrkPoint
Addr _endBrkPoint
Keeps record of the furthest mapped heap location.
Definition: mem_state.hh:254
MemState::fixupFault
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page.
Definition: mem_state.cc:386
MemState::_mmapEnd
Addr _mmapEnd
Definition: mem_state.hh:249
MemState::setStackBase
void setStackBase(Addr stack_base)
Definition: mem_state.hh:88
MemState::setBrkPoint
void setBrkPoint(Addr brk_point)
Definition: mem_state.hh:87
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Serializable::ScopedCheckpointSection
Definition: serialize.hh:175
name
const std::string & name()
Definition: trace.cc:50
MemState::getNextThreadStackBase
Addr getNextThreadStackBase() const
Definition: mem_state.hh:85
MemState::getMmapEnd
Addr getMmapEnd() const
Definition: mem_state.hh:86
MemState::_stackBase
Addr _stackBase
Definition: mem_state.hh:244
MemState::_brkPoint
Addr _brkPoint
Definition: mem_state.hh:243
MemState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mem_state.hh:184
MemState::setMaxStackSize
void setMaxStackSize(Addr max_stack)
Definition: mem_state.hh:90
MemState::_nextThreadStackBase
Addr _nextThreadStackBase
Definition: mem_state.hh:248
MemState::allocateMem
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...
MemState::_maxStackSize
Addr _maxStackSize
Definition: mem_state.hh:246
paramIn
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
Definition: types.cc:69
MemState::getMaxStackSize
Addr getMaxStackSize() const
Definition: mem_state.hh:83
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
se_translating_port_proxy.hh
std::list< VMA >
MemState::unmapRegion
void unmapRegion(Addr start_addr, Addr length)
Unmap a pre-existing region.
Definition: mem_state.cc:184
MemState::getStackMin
Addr getStackMin() const
Definition: mem_state.hh:84
vma.hh
page_table.hh
MemState::_stackMin
Addr _stackMin
Definition: mem_state.hh:247
CheckpointIn
Definition: serialize.hh:67
MemState::setStackSize
void setStackSize(Addr stack_size)
Definition: mem_state.hh:89
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
MemState::updateBrkRegion
void updateBrkRegion(Addr old_brk, Addr new_brk)
Change the end of a process' program break.
Definition: mem_state.cc:105
MemState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mem_state.hh:206
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17