vta_phy_addr_t VirtualMemoryManager::GetPhyAddr()

in src/vmem/virtual_memory.cc [66:82]


vta_phy_addr_t VirtualMemoryManager::GetPhyAddr(void* buf) {
  std::lock_guard<std::mutex> lock(mutex_);
  auto it = pmap_.find(buf);
  uint64_t offset = 0;
  if (it == pmap_.end()) {
    for (it = pmap_.begin(); it != pmap_.end(); it++) {
      uint64_t bytes = it->second->num_pages << kPageBits;
      if ((buf >= it->first) && (buf < static_cast<char*>(it->first) + bytes)) {
        offset = static_cast<char*>(buf) - static_cast<char*>(it->first);
        break;
      }
    }
    CHECK(it != pmap_.end());
  }
  Page* p = it->second.get();
  return ((p->ptable_begin + 1) << kPageBits) + offset;
}