gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
46 namespace gem5
47 {
48 
49 class Process;
50 struct ProcessParams;
51 class System;
52 
67 class 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; }
88  Addr getMaxStackSize() const { return _maxStackSize; }
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
214  unserialize(CheckpointIn &cp) override
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 
284 
298 };
299 
300 } // namespace gem5
301 
302 #endif
gem5::MemState::_mmapEnd
Addr _mmapEnd
Definition: mem_state.hh:278
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:269
gem5::MemState::_stackMin
Addr _stackMin
Definition: mem_state.hh:276
serialize.hh
gem5::MemState::_stackBase
Addr _stackBase
Definition: mem_state.hh:273
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::MemState::getMaxStackSize
Addr getMaxStackSize() const
Definition: mem_state.hh:88
gem5::MemState::setStackSize
void setStackSize(Addr stack_size)
Definition: mem_state.hh:94
gem5::MemState::getNextThreadStackBase
Addr getNextThreadStackBase() const
Definition: mem_state.hh:90
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:95
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
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:275
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::MemState::_pageBytes
Addr _pageBytes
Definition: mem_state.hh:271
gem5::System
Definition: system.hh:74
gem5::MemState::system
System * system() const
gem5::MemState::getStackSize
Addr getStackSize() const
Definition: mem_state.hh:87
gem5::X86ISA::count
count
Definition: misc.hh:710
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:89
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:85
name
const std::string & name()
Definition: trace.cc:48
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:297
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:91
gem5::optParamIn
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
gem5::MemState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mem_state.hh:214
gem5::MemState::_endBrkPoint
Addr _endBrkPoint
Keeps record of the furthest mapped heap location.
Definition: mem_state.hh:283
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:98
gem5::MemState::_nextThreadStackBase
Addr _nextThreadStackBase
Definition: mem_state.hh:277
gem5::MemState
This class holds the memory state for the Process class and all of its derived, architecture-specific...
Definition: mem_state.hh:67
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:97
gem5::MemState::setStackMin
void setStackMin(Addr stack_min)
Definition: mem_state.hh:96
gem5::MemState::_stackSize
Addr _stackSize
Definition: mem_state.hh:274
gem5::MemState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mem_state.hh:189
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
se_translating_port_proxy.hh
gem5::MemState::getStackBase
Addr getStackBase() const
Definition: mem_state.hh:86
gem5::MemState::_brkPoint
Addr _brkPoint
Definition: mem_state.hh:272
gem5::MemState::setStackBase
void setStackBase(Addr stack_base)
Definition: mem_state.hh:93
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:81
std::list
STL list class.
Definition: stl.hh:51
vma.hh
fatal_if
#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
page_table.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::Serializable::ScopedCheckpointSection
Definition: serialize.hh:172
gem5::MemState::setBrkPoint
void setBrkPoint(Addr brk_point)
Definition: mem_state.hh:92

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17