gem5  v21.1.0.2
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 "debug/Vma.hh"
38 #include "mem/page_table.hh"
40 #include "sim/serialize.hh"
41 #include "sim/vma.hh"
42 
43 namespace gem5
44 {
45 
46 class Process;
47 struct ProcessParams;
48 class System;
49 
64 class MemState : public Serializable
65 {
66  public:
67  MemState(Process *owner, Addr brk_point, Addr stack_base,
68  Addr max_stack_size, Addr next_thread_stack_base,
69  Addr mmap_end);
70 
71  MemState& operator=(const MemState &in);
72 
76  void resetOwner(Process *owner);
77 
82  Addr getBrkPoint() const { return _brkPoint; }
83  Addr getStackBase() const { return _stackBase; }
84  Addr getStackSize() const { return _stackSize; }
85  Addr getMaxStackSize() const { return _maxStackSize; }
86  Addr getStackMin() const { return _stackMin; }
88  Addr getMmapEnd() const { return _mmapEnd; }
89  void setBrkPoint(Addr brk_point) { _brkPoint = brk_point; }
90  void setStackBase(Addr stack_base) { _stackBase = stack_base; }
91  void setStackSize(Addr stack_size) { _stackSize = stack_size; }
92  void setMaxStackSize(Addr max_stack) { _maxStackSize = max_stack; }
93  void setStackMin(Addr stack_min) { _stackMin = stack_min; }
95  void setMmapEnd(Addr mmap_end) { _mmapEnd = mmap_end; }
96 
97  /*
98  * Extend the end of the mmap region by length bytes. Once a contiguous
99  * region of free virtual memory is found the start of that region is
100  * returned.
101  */
102  Addr extendMmap(Addr length);
103 
113  bool isUnmapped(Addr start_addr, Addr length);
114 
127  void mapRegion(Addr start_addr, Addr length,
128  const std::string& name="anon", int sim_fd=-1,
129  Addr offset=0);
130 
139  void unmapRegion(Addr start_addr, Addr length);
140 
151  void remapRegion(Addr start_addr, Addr new_start_addr, Addr length);
152 
160  void updateBrkRegion(Addr old_brk, Addr new_brk);
161 
170  bool fixupFault(Addr vaddr);
171 
183  void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
184 
185  void
186  serialize(CheckpointOut &cp) const override
187  {
188  paramOut(cp, "brkPoint", _brkPoint);
189  paramOut(cp, "stackBase", _stackBase);
190  paramOut(cp, "stackSize", _stackSize);
191  paramOut(cp, "maxStackSize", _maxStackSize);
192  paramOut(cp, "stackMin", _stackMin);
193  paramOut(cp, "nextThreadStackBase", _nextThreadStackBase);
194  paramOut(cp, "mmapEnd", _mmapEnd);
195 
196  ScopedCheckpointSection sec(cp, "vmalist");
197  paramOut(cp, "size", _vmaList.size());
198  int count = 0;
199  for (auto vma : _vmaList) {
200  ScopedCheckpointSection sec(cp, csprintf("Vma%d", count++));
201  paramOut(cp, "name", vma.getName());
202  paramOut(cp, "addrRangeStart", vma.start());
203  paramOut(cp, "addrRangeEnd", vma.end());
204  }
205  }
206 
207  void
208  unserialize(CheckpointIn &cp) override
209  {
210  paramIn(cp, "brkPoint", _brkPoint);
211  paramIn(cp, "stackBase", _stackBase);
212  paramIn(cp, "stackSize", _stackSize);
213  paramIn(cp, "maxStackSize", _maxStackSize);
214  paramIn(cp, "stackMin", _stackMin);
215  paramIn(cp, "nextThreadStackBase", _nextThreadStackBase);
216  paramIn(cp, "mmapEnd", _mmapEnd);
217 
218  int count;
219  ScopedCheckpointSection sec(cp, "vmalist");
220  paramIn(cp, "size", count);
221  for (int i = 0; i < count; ++i) {
222  ScopedCheckpointSection sec(cp, csprintf("Vma%d", i));
223  std::string name;
224  Addr start;
225  Addr end;
226  paramIn(cp, "name", name);
227  paramIn(cp, "addrRangeStart", start);
228  paramIn(cp, "addrRangeEnd", end);
229  _vmaList.emplace_back(AddrRange(start, end), _pageBytes, name);
230  }
231  }
232 
236  std::string printVmaList();
237 
238  private:
242  void replicatePage(const MemState &in, Addr vaddr, Addr new_paddr,
243  bool alloc_page);
244 
248  System * system() const;
249 
254 
263 
268 
282 };
283 
284 } // namespace gem5
285 
286 #endif
gem5::MemState::_mmapEnd
Addr _mmapEnd
Definition: mem_state.hh:262
gem5::MemState::extendMmap
Addr extendMmap(Addr length)
Definition: mem_state.cc:452
gem5::MemState::_ownerProcess
Process * _ownerProcess
Owner process of MemState.
Definition: mem_state.hh:253
gem5::MemState::_stackMin
Addr _stackMin
Definition: mem_state.hh:260
serialize.hh
gem5::MemState::_stackBase
Addr _stackBase
Definition: mem_state.hh:257
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::MemState::getMaxStackSize
Addr getMaxStackSize() const
Definition: mem_state.hh:85
gem5::MemState::setStackSize
void setStackSize(Addr stack_size)
Definition: mem_state.hh:91
gem5::MemState::getNextThreadStackBase
Addr getNextThreadStackBase() const
Definition: mem_state.hh:87
gem5::MemState::remapRegion
void remapRegion(Addr start_addr, Addr new_start_addr, Addr length)
Remap a pre-existing region.
Definition: mem_state.cc:284
gem5::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:83
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::MemState::setMaxStackSize
void setMaxStackSize(Addr max_stack)
Definition: mem_state.hh:92
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::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:44
gem5::MemState::_maxStackSize
Addr _maxStackSize
Definition: mem_state.hh:259
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::MemState::_pageBytes
Addr _pageBytes
Definition: mem_state.hh:255
gem5::System
Definition: system.hh:77
gem5::MemState::system
System * system() const
gem5::MemState::getStackSize
Addr getStackSize() const
Definition: mem_state.hh:84
gem5::X86ISA::count
count
Definition: misc.hh:709
gem5::MemState::printVmaList
std::string printVmaList()
Print the list of VMAs in a format similar to /proc/self/maps.
Definition: mem_state.cc:480
gem5::MemState::unmapRegion
void unmapRegion(Addr start_addr, Addr length)
Unmap a pre-existing region.
Definition: mem_state.cc:187
gem5::MemState::getStackMin
Addr getStackMin() const
Definition: mem_state.hh:86
gem5::MemState::operator=
MemState & operator=(const MemState &in)
Definition: mem_state.cc:57
gem5::MemState::fixupFault
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page.
Definition: mem_state.cc:387
gem5::MemState::updateBrkRegion
void updateBrkRegion(Addr old_brk, Addr new_brk)
Change the end of a process' program break.
Definition: mem_state.cc:108
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::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...
gem5::MemState::replicatePage
void replicatePage(const MemState &in, Addr vaddr, Addr new_paddr, bool alloc_page)
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::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:82
name
const std::string & name()
Definition: trace.cc:49
gem5::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:281
gem5::MemState::resetOwner
void resetOwner(Process *owner)
Change the Process owner in case this MemState is copied.
Definition: mem_state.cc:77
gem5::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:167
gem5::Process
Definition: process.hh:67
gem5::MemState::getMmapEnd
Addr getMmapEnd() const
Definition: mem_state.hh:88
gem5::MemState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mem_state.hh:208
gem5::MemState::_endBrkPoint
Addr _endBrkPoint
Keeps record of the furthest mapped heap location.
Definition: mem_state.hh:267
gem5::paramOut
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition: types.cc:40
gem5::MemState::setMmapEnd
void setMmapEnd(Addr mmap_end)
Definition: mem_state.hh:95
gem5::MemState::_nextThreadStackBase
Addr _nextThreadStackBase
Definition: mem_state.hh:261
gem5::MemState
This class holds the memory state for the Process class and all of its derived, architecture-specific...
Definition: mem_state.hh:64
gem5::paramIn
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition: types.cc:72
gem5::MemState::setNextThreadStackBase
void setNextThreadStackBase(Addr ntsb)
Definition: mem_state.hh:94
gem5::MemState::setStackMin
void setStackMin(Addr stack_min)
Definition: mem_state.hh:93
gem5::MemState::_stackSize
Addr _stackSize
Definition: mem_state.hh:258
gem5::MemState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mem_state.hh:186
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
se_translating_port_proxy.hh
gem5::MemState::getStackBase
Addr getStackBase() const
Definition: mem_state.hh:83
gem5::MemState::_brkPoint
Addr _brkPoint
Definition: mem_state.hh:256
gem5::MemState::setStackBase
void setStackBase(Addr stack_base)
Definition: mem_state.hh:90
gem5::MipsISA::vaddr
vaddr
Definition: pra_constants.hh:278
gem5::AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:71
std::list
STL list class.
Definition: stl.hh:51
vma.hh
page_table.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::Serializable::ScopedCheckpointSection
Definition: serialize.hh:172
gem5::MemState::setBrkPoint
void setBrkPoint(Addr brk_point)
Definition: mem_state.hh:89

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17