34 #include "debug/Vma.hh"
42 Addr max_stack_size,
Addr next_thread_stack_base,
44 : _ownerProcess(owner),
45 _pageBytes(owner->
system->getPageBytes()), _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)
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);
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->getDTBPtr()->flushAll();
262 tc->getITBPtr()->flushAll();
285 const AddrRange range(start_addr, end_addr);
289 if (vma->isStrictSuperset(range)) {
294 _vmaList.back().sliceRegionRight(start_addr);
300 _vmaList.back().sliceRegionLeft(end_addr);
306 vma->sliceRegionLeft(start_addr);
307 vma->sliceRegionRight(end_addr);
308 vma->remap(new_start_addr);
315 }
else if (vma->isSubset(range)) {
319 vma->remap(vma->start() - start_addr + new_start_addr);
320 }
else if (vma->intersects(range)) {
326 if (vma->start() < start_addr) {
330 _vmaList.back().sliceRegionRight(start_addr);
335 vma->sliceRegionLeft(start_addr);
336 vma->remap(new_start_addr);
341 _vmaList.back().sliceRegionLeft(end_addr);
346 vma->sliceRegionRight(end_addr);
347 vma->remap(new_start_addr + vma->start() - start_addr);
363 tc->getDTBPtr()->flushAll();
364 tc->getITBPtr()->flushAll();
393 if (vma.contains(
vaddr)) {
403 if (vma.hasHostBuf()) {
412 vma.fillMemPages(vpage_start,
_pageBytes, virt_mem);
439 fatal(
"Maximum stack size exceeded\n");
442 inform(
"Increasing stack size by one page.");
462 DPRINTF(Vma,
"memstate: cannot extend vma for mmap region at %p. "
463 "Virtual address range is already reserved! Skipping a page "
464 "and trying again!\n", start);
469 DPRINTF(Vma,
"memstate: extending mmap region (old %p) (new %p)\n",
481 std::stringstream file_content;
484 std::stringstream line;
485 line << std::hex << vma.start() <<
"-";
486 line << std::hex << vma.end() <<
" ";
487 line <<
"r-xp 00000000 00:00 0 ";
488 line <<
"[" << vma.getName() <<
"]" << std::endl;
489 file_content << line.str();
492 return file_content.str();