34 #include "debug/Vma.hh"
45 Addr max_stack_size,
Addr next_thread_stack_base,
47 : _ownerProcess(owner),
48 _pageBytes(owner->pTable->pageSize()), _brkPoint(brk_point),
49 _stackBase(stack_base), _stackSize(max_stack_size),
50 _maxStackSize(max_stack_size), _stackMin(stack_base - max_stack_size),
51 _nextThreadStackBase(next_thread_stack_base),
52 _mmapEnd(mmap_end), _endBrkPoint(brk_point)
85 Addr end_addr = start_addr + length;
86 const AddrRange range(start_addr, end_addr);
88 if (vma.intersects(range))
96 for (
auto start = start_addr; start < end_addr;
99 panic(
"Someone allocated physical memory at VA %p without "
100 "creating a VMA!\n", start);
118 if (new_brk < old_brk) {
168 const std::string& region_name,
int sim_fd,
Addr offset)
170 DPRINTF(Vma,
"memstate: creating vma (%s) [0x%x - 0x%x]\n",
171 region_name.c_str(), start_addr, start_addr + length);
189 Addr end_addr = start_addr + length;
190 const AddrRange range(start_addr, end_addr);
194 if (vma->isStrictSuperset(range)) {
195 DPRINTF(Vma,
"memstate: split vma [0x%x - 0x%x] into "
196 "[0x%x - 0x%x] and [0x%x - 0x%x]\n",
197 vma->start(), vma->end(),
198 vma->start(), start_addr,
199 end_addr, vma->end());
205 _vmaList.back().sliceRegionRight(start_addr);
210 vma->sliceRegionLeft(end_addr);
217 }
else if (vma->isSubset(range)) {
218 DPRINTF(Vma,
"memstate: destroying vma [0x%x - 0x%x]\n",
219 vma->start(), vma->end());
227 }
else if (vma->intersects(range)) {
231 if (vma->start() < start_addr) {
232 DPRINTF(Vma,
"memstate: resizing vma [0x%x - 0x%x] "
233 "into [0x%x - 0x%x]\n",
234 vma->start(), vma->end(),
235 vma->start(), start_addr);
239 vma->sliceRegionRight(start_addr);
241 DPRINTF(Vma,
"memstate: resizing vma [0x%x - 0x%x] "
242 "into [0x%x - 0x%x]\n",
243 vma->start(), vma->end(),
244 end_addr, vma->end());
248 vma->sliceRegionLeft(end_addr);
264 tc->getMMUPtr()->flushAll();
280 }
while (length > 0);
286 Addr end_addr = start_addr + length;
287 const AddrRange range(start_addr, end_addr);
291 if (vma->isStrictSuperset(range)) {
296 _vmaList.back().sliceRegionRight(start_addr);
302 _vmaList.back().sliceRegionLeft(end_addr);
308 vma->sliceRegionLeft(start_addr);
309 vma->sliceRegionRight(end_addr);
310 vma->remap(new_start_addr);
317 }
else if (vma->isSubset(range)) {
321 vma->remap(vma->start() - start_addr + new_start_addr);
322 }
else if (vma->intersects(range)) {
328 if (vma->start() < start_addr) {
332 _vmaList.back().sliceRegionRight(start_addr);
337 vma->sliceRegionLeft(start_addr);
338 vma->remap(new_start_addr);
343 _vmaList.back().sliceRegionLeft(end_addr);
348 vma->sliceRegionRight(end_addr);
349 vma->remap(new_start_addr + vma->start() - start_addr);
365 tc->getMMUPtr()->flushAll();
383 }
while (length > 0);
394 if (vma.contains(
vaddr)) {
404 if (vma.hasHostBuf()) {
413 vma.fillMemPages(vpage_start,
_pageBytes, virt_mem);
440 fatal(
"Maximum stack size exceeded\n");
443 inform(
"Increasing stack size by one page.");
463 DPRINTF(Vma,
"memstate: cannot extend vma for mmap region at %p. "
464 "Virtual address range is already reserved! Skipping a page "
465 "and trying again!\n", start);
470 DPRINTF(Vma,
"memstate: extending mmap region (old %p) (new %p)\n",
482 std::stringstream file_content;
485 std::stringstream line;
486 line << std::hex << vma.start() <<
"-";
487 line << std::hex << vma.end() <<
" ";
488 line <<
"r-xp 00000000 00:00 0 ";
489 line <<
"[" << vma.getName() <<
"]" << std::endl;
490 file_content << line.str();
493 return file_content.str();