34 #include "debug/Vma.hh"
42 Addr max_stack_size,
Addr next_thread_stack_base,
44 : _ownerProcess(owner),
45 _pageBytes(owner->pTable->pageSize()), _brkPoint(brk_point),
46 _stackBase(stack_base), _stackSize(max_stack_size),
47 _maxStackSize(max_stack_size), _stackMin(stack_base - max_stack_size),
48 _nextThreadStackBase(next_thread_stack_base),
49 _mmapEnd(mmap_end), _endBrkPoint(brk_point)
82 Addr end_addr = start_addr + length;
83 const AddrRange range(start_addr, end_addr);
85 if (vma.intersects(range))
93 for (
auto start = start_addr; start < end_addr;
96 panic(
"Someone allocated physical memory at VA %p without "
97 "creating a VMA!\n", start);
115 if (new_brk < old_brk) {
165 const std::string& region_name,
int sim_fd,
Addr offset)
167 DPRINTF(Vma,
"memstate: creating vma (%s) [0x%x - 0x%x]\n",
168 region_name.c_str(), start_addr, start_addr + length);
186 Addr end_addr = start_addr + length;
187 const AddrRange range(start_addr, end_addr);
191 if (vma->isStrictSuperset(range)) {
192 DPRINTF(Vma,
"memstate: split vma [0x%x - 0x%x] into "
193 "[0x%x - 0x%x] and [0x%x - 0x%x]\n",
194 vma->start(), vma->end(),
195 vma->start(), start_addr,
196 end_addr, vma->end());
202 _vmaList.back().sliceRegionRight(start_addr);
207 vma->sliceRegionLeft(end_addr);
214 }
else if (vma->isSubset(range)) {
215 DPRINTF(Vma,
"memstate: destroying vma [0x%x - 0x%x]\n",
216 vma->start(), vma->end());
224 }
else if (vma->intersects(range)) {
228 if (vma->start() < start_addr) {
229 DPRINTF(Vma,
"memstate: resizing vma [0x%x - 0x%x] "
230 "into [0x%x - 0x%x]\n",
231 vma->start(), vma->end(),
232 vma->start(), start_addr);
236 vma->sliceRegionRight(start_addr);
238 DPRINTF(Vma,
"memstate: resizing vma [0x%x - 0x%x] "
239 "into [0x%x - 0x%x]\n",
240 vma->start(), vma->end(),
241 end_addr, vma->end());
245 vma->sliceRegionLeft(end_addr);
261 tc->getMMUPtr()->flushAll();
277 }
while (length > 0);
283 Addr end_addr = start_addr + length;
284 const AddrRange range(start_addr, end_addr);
288 if (vma->isStrictSuperset(range)) {
293 _vmaList.back().sliceRegionRight(start_addr);
299 _vmaList.back().sliceRegionLeft(end_addr);
305 vma->sliceRegionLeft(start_addr);
306 vma->sliceRegionRight(end_addr);
307 vma->remap(new_start_addr);
314 }
else if (vma->isSubset(range)) {
318 vma->remap(vma->start() - start_addr + new_start_addr);
319 }
else if (vma->intersects(range)) {
325 if (vma->start() < start_addr) {
329 _vmaList.back().sliceRegionRight(start_addr);
334 vma->sliceRegionLeft(start_addr);
335 vma->remap(new_start_addr);
340 _vmaList.back().sliceRegionLeft(end_addr);
345 vma->sliceRegionRight(end_addr);
346 vma->remap(new_start_addr + vma->start() - start_addr);
362 tc->getMMUPtr()->flushAll();
380 }
while (length > 0);
391 if (vma.contains(
vaddr)) {
401 if (vma.hasHostBuf()) {
410 vma.fillMemPages(vpage_start,
_pageBytes, virt_mem);
437 fatal(
"Maximum stack size exceeded\n");
440 inform(
"Increasing stack size by one page.");
460 DPRINTF(Vma,
"memstate: cannot extend vma for mmap region at %p. "
461 "Virtual address range is already reserved! Skipping a page "
462 "and trying again!\n", start);
467 DPRINTF(Vma,
"memstate: extending mmap region (old %p) (new %p)\n",
479 std::stringstream file_content;
482 std::stringstream line;
483 line << std::hex << vma.start() <<
"-";
484 line << std::hex << vma.end() <<
" ";
485 line <<
"r-xp 00000000 00:00 0 ";
486 line <<
"[" << vma.getName() <<
"]" << std::endl;
487 file_content << line.str();
490 return file_content.str();