gem5  v22.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 "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
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:65
System * system() const
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
Addr getBrkPoint() const
Get/set base addresses and sizes for the stack and data segments of the process' memory.
Definition: mem_state.hh:82
Process * _ownerProcess
Owner process of MemState.
Definition: mem_state.hh:253
void setMmapEnd(Addr mmap_end)
Definition: mem_state.hh:95
Addr extendMmap(Addr length)
Definition: mem_state.cc:452
Addr getMaxStackSize() const
Definition: mem_state.hh:85
void setStackSize(Addr stack_size)
Definition: mem_state.hh:91
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page.
Definition: mem_state.cc:387
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mem_state.hh:186
Addr _maxStackSize
Definition: mem_state.hh:259
void setNextThreadStackBase(Addr ntsb)
Definition: mem_state.hh:94
Addr _endBrkPoint
Keeps record of the furthest mapped heap location.
Definition: mem_state.hh:267
void replicatePage(const MemState &in, Addr vaddr, Addr new_paddr, bool alloc_page)
Addr _nextThreadStackBase
Definition: mem_state.hh:261
void setStackBase(Addr stack_base)
Definition: mem_state.hh:90
void updateBrkRegion(Addr old_brk, Addr new_brk)
Change the end of a process' program break.
Definition: mem_state.cc:108
Addr getStackSize() const
Definition: mem_state.hh:84
void setBrkPoint(Addr brk_point)
Definition: mem_state.hh:89
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: mem_state.hh:208
std::string printVmaList()
Print the list of VMAs in a format similar to /proc/self/maps.
Definition: mem_state.cc:480
Addr getStackMin() const
Definition: mem_state.hh:86
void setMaxStackSize(Addr max_stack)
Definition: mem_state.hh:92
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
void resetOwner(Process *owner)
Change the Process owner in case this MemState is copied.
Definition: mem_state.cc:77
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:83
MemState & operator=(const MemState &in)
Definition: mem_state.cc:57
Addr getNextThreadStackBase() const
Definition: mem_state.hh:87
Addr getMmapEnd() const
Definition: mem_state.hh:88
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:187
void remapRegion(Addr start_addr, Addr new_start_addr, Addr length)
Remap a pre-existing region.
Definition: mem_state.cc:284
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
void setStackMin(Addr stack_min)
Definition: mem_state.hh:93
Basic support for object serialization.
Definition: serialize.hh:170
STL list class.
Definition: stl.hh:51
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 23, 0 > offset
Definition: types.hh:144
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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:49

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1