Commit b232fbf8 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

refactor: use C-style commenting everywhere

parent ff302030
...@@ -36,7 +36,7 @@ size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags) ...@@ -36,7 +36,7 @@ size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
if (!str) if (!str)
return 0; return 0;
len = strlen(str); // not \0 terminated len = strlen(str); /* not \0 terminated */
if (buffer && len <= size) if (buffer && len <= size)
memcpy(buffer, str, len); memcpy(buffer, str, len);
......
...@@ -99,7 +99,7 @@ void hist_put(struct hist *h, double value) ...@@ -99,7 +99,7 @@ void hist_put(struct hist *h, double value)
h->_m[0] = h->_m[1] + (value - h->_m[1]) / h->total; h->_m[0] = h->_m[1] + (value - h->_m[1]) / h->total;
h->_s[0] = h->_s[1] + (value - h->_m[1]) * (value - h->_m[0]); h->_s[0] = h->_s[1] + (value - h->_m[1]) * (value - h->_m[0]);
// set up for next iteration /* Set up for next iteration */
h->_m[1] = h->_m[0]; h->_m[1] = h->_m[0];
h->_s[1] = h->_s[0]; h->_s[1] = h->_s[0];
} }
......
...@@ -134,12 +134,12 @@ int kernel_module_load(const char *module) ...@@ -134,12 +134,12 @@ int kernel_module_load(const char *module)
pid_t pid = fork(); pid_t pid = fork();
switch (pid) { switch (pid) {
case -1: // error case -1: /* error */
return -1; return -1;
case 0: // child case 0: /* child */
execlp("modprobe", "modprobe", module, (char *) 0); execlp("modprobe", "modprobe", module, (char *) 0);
exit(EXIT_FAILURE); // exec never returns exit(EXIT_FAILURE); /* exec never returns */
default: default:
wait(&ret); wait(&ret);
......
...@@ -50,8 +50,7 @@ int pci_init(struct pci *p) ...@@ -50,8 +50,7 @@ int pci_init(struct pci *p)
} }
while ((e = readdir(dp))) { while ((e = readdir(dp))) {
/* Ignore special entries */
// ignore special entries
if ((strcmp(e->d_name, ".") == 0) || if ((strcmp(e->d_name, ".") == 0) ||
(strcmp(e->d_name, "..") == 0) ) (strcmp(e->d_name, "..") == 0) )
continue; continue;
...@@ -244,8 +243,7 @@ int pci_device_compare(const struct pci_device *d, const struct pci_device *f) ...@@ -244,8 +243,7 @@ int pci_device_compare(const struct pci_device *d, const struct pci_device *f)
if ((f->id.class_code != 0) || (f->id.class_code != d->id.class_code)) if ((f->id.class_code != 0) || (f->id.class_code != d->id.class_code))
return 1; return 1;
// found return 0; /* found */
return 0;
} }
struct pci_device * pci_lookup_device(struct pci *p, struct pci_device *f) struct pci_device * pci_lookup_device(struct pci *p, struct pci_device *f)
...@@ -276,7 +274,8 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions) ...@@ -276,7 +274,8 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions)
size_t len = 0; size_t len = 0;
int region = 0; int region = 0;
// cap to 8 regions, just because we don't know how many may exist
/* Cap to 8 regions, just because we don't know how many may exist. */
while(region < 8 && (bytesRead = getline(&line, &len, f)) != -1) { while(region < 8 && (bytesRead = getline(&line, &len, f)) != -1) {
unsigned long long tokens[3]; unsigned long long tokens[3];
char* s = line; char* s = line;
...@@ -285,7 +284,7 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions) ...@@ -285,7 +284,7 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions)
tokens[i] = strtoull(s, &end, 16); tokens[i] = strtoull(s, &end, 16);
if(s == end) { if(s == end) {
printf("Error parsing line %d of %s\n", region + 1, sysfs); printf("Error parsing line %d of %s\n", region + 1, sysfs);
tokens[0] = tokens[1] = 0; // mark invalid tokens[0] = tokens[1] = 0; /* Mark invalid */
break; break;
} }
s = end; s = end;
...@@ -293,12 +292,12 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions) ...@@ -293,12 +292,12 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions)
free(line); free(line);
// required for getline() to allocate a new buffer on the next iteration /* Required for getline() to allocate a new buffer on the next iteration. */
line = NULL; line = NULL;
len = 0; len = 0;
if(tokens[0] != tokens[1]) { if(tokens[0] != tokens[1]) {
// this is a valid region /* This is a valid region */
cur_region->num = region; cur_region->num = region;
cur_region->start = tokens[0]; cur_region->start = tokens[0];
cur_region->end = tokens[1]; cur_region->end = tokens[1];
......
...@@ -129,6 +129,6 @@ bool isPreemptible() ...@@ -129,6 +129,6 @@ bool isPreemptible()
#endif /* __linux__ */ #endif /* __linux__ */
} // namespace villas } /* namespace villas */
} // namespace kernel } /* namespace kernel */
} // namespace rt } /* namespace rt */
...@@ -22,23 +22,23 @@ ...@@ -22,23 +22,23 @@
#include <villas/kernel/pci.h> #include <villas/kernel/pci.h>
static const char *vfio_pci_region_names[] = { static const char *vfio_pci_region_names[] = {
"PCI_BAR0", // VFIO_PCI_BAR0_REGION_INDEX, "PCI_BAR0", /* VFIO_PCI_BAR0_REGION_INDEX */
"PCI_BAR1", // VFIO_PCI_BAR1_REGION_INDEX, "PCI_BAR1", /* VFIO_PCI_BAR1_REGION_INDEX */
"PCI_BAR2", // VFIO_PCI_BAR2_REGION_INDEX, "PCI_BAR2", /* VFIO_PCI_BAR2_REGION_INDEX */
"PCI_BAR3", // VFIO_PCI_BAR3_REGION_INDEX, "PCI_BAR3", /* VFIO_PCI_BAR3_REGION_INDEX */
"PCI_BAR4", // VFIO_PCI_BAR4_REGION_INDEX, "PCI_BAR4", /* VFIO_PCI_BAR4_REGION_INDEX */
"PCI_BAR5", // VFIO_PCI_BAR5_REGION_INDEX, "PCI_BAR5", /* VFIO_PCI_BAR5_REGION_INDEX */
"PCI_ROM", // VFIO_PCI_ROM_REGION_INDEX, "PCI_ROM", /* VFIO_PCI_ROM_REGION_INDEX */
"PCI_CONFIG", // VFIO_PCI_CONFIG_REGION_INDEX, "PCI_CONFIG", /* VFIO_PCI_CONFIG_REGION_INDEX */
"PCI_VGA" // VFIO_PCI_INTX_IRQ_INDEX, "PCI_VGA" /* VFIO_PCI_INTX_IRQ_INDEX */
}; };
static const char *vfio_pci_irq_names[] = { static const char *vfio_pci_irq_names[] = {
"PCI_INTX", // VFIO_PCI_INTX_IRQ_INDEX, "PCI_INTX", /* VFIO_PCI_INTX_IRQ_INDEX */
"PCI_MSI", // VFIO_PCI_MSI_IRQ_INDEX, "PCI_MSI", /* VFIO_PCI_MSI_IRQ_INDEX */
"PCI_MSIX", // VFIO_PCI_MSIX_IRQ_INDEX, "PCI_MSIX", /* VFIO_PCI_MSIX_IRQ_INDEX */
"PCI_ERR", // VFIO_PCI_ERR_IRQ_INDEX, "PCI_ERR", /* VFIO_PCI_ERR_IRQ_INDEX */
"PCI_REQ" // VFIO_PCI_REQ_IRQ_INDEX, "PCI_REQ" /* VFIO_PCI_REQ_IRQ_INDEX */
}; };
/* Helpers */ /* Helpers */
......
...@@ -52,23 +52,23 @@ ...@@ -52,23 +52,23 @@
using namespace villas; using namespace villas;
static const char *vfio_pci_region_names[] = { static const char *vfio_pci_region_names[] = {
"PCI_BAR0", // VFIO_PCI_BAR0_REGION_INDEX, "PCI_BAR0", /* VFIO_PCI_BAR0_REGION_INDEX */
"PCI_BAR1", // VFIO_PCI_BAR1_REGION_INDEX, "PCI_BAR1", /* VFIO_PCI_BAR1_REGION_INDEX */
"PCI_BAR2", // VFIO_PCI_BAR2_REGION_INDEX, "PCI_BAR2", /* VFIO_PCI_BAR2_REGION_INDEX */
"PCI_BAR3", // VFIO_PCI_BAR3_REGION_INDEX, "PCI_BAR3", /* VFIO_PCI_BAR3_REGION_INDEX */
"PCI_BAR4", // VFIO_PCI_BAR4_REGION_INDEX, "PCI_BAR4", /* VFIO_PCI_BAR4_REGION_INDEX */
"PCI_BAR5", // VFIO_PCI_BAR5_REGION_INDEX, "PCI_BAR5", /* VFIO_PCI_BAR5_REGION_INDEX */
"PCI_ROM", // VFIO_PCI_ROM_REGION_INDEX, "PCI_ROM", /* VFIO_PCI_ROM_REGION_INDEX */
"PCI_CONFIG", // VFIO_PCI_CONFIG_REGION_INDEX, "PCI_CONFIG", /* VFIO_PCI_CONFIG_REGION_INDEX */
"PCI_VGA" // VFIO_PCI_INTX_IRQ_INDEX, "PCI_VGA" /* VFIO_PCI_INTX_IRQ_INDEX */
}; };
static const char *vfio_pci_irq_names[] = { static const char *vfio_pci_irq_names[] = {
"PCI_INTX", // VFIO_PCI_INTX_IRQ_INDEX, "PCI_INTX", /* VFIO_PCI_INTX_IRQ_INDEX */
"PCI_MSI", // VFIO_PCI_MSI_IRQ_INDEX, "PCI_MSI", /* VFIO_PCI_MSI_IRQ_INDEX */
"PCI_MSIX", // VFIO_PCI_MSIX_IRQ_INDEX, "PCI_MSIX", /* VFIO_PCI_MSIX_IRQ_INDEX */
"PCI_ERR", // VFIO_PCI_ERR_IRQ_INDEX, "PCI_ERR", /* VFIO_PCI_ERR_IRQ_INDEX */
"PCI_REQ" // VFIO_PCI_REQ_IRQ_INDEX, "PCI_REQ" /* VFIO_PCI_REQ_IRQ_INDEX */
}; };
namespace villas { namespace villas {
...@@ -243,7 +243,7 @@ VfioContainer::attachDevice(const char* name, int index) ...@@ -243,7 +243,7 @@ VfioContainer::attachDevice(const char* name, int index)
logger->debug("Device has {} regions", device->info.num_regions); logger->debug("Device has {} regions", device->info.num_regions);
logger->debug("Device has {} IRQs", device->info.num_irqs); logger->debug("Device has {} IRQs", device->info.num_irqs);
// reserve slots already so that we can use the []-operator for access /* Reserve slots already so that we can use the []-operator for access */
device->irqs.resize(device->info.num_irqs); device->irqs.resize(device->info.num_irqs);
device->regions.resize(device->info.num_regions); device->regions.resize(device->info.num_regions);
device->mappings.resize(device->info.num_regions); device->mappings.resize(device->info.num_regions);
...@@ -383,11 +383,12 @@ VfioContainer::memoryMap(uintptr_t virt, uintptr_t phys, size_t length) ...@@ -383,11 +383,12 @@ VfioContainer::memoryMap(uintptr_t virt, uintptr_t phys, size_t length)
logger->debug("DMA map size={:#x}, iova={:#x}, vaddr={:#x}", logger->debug("DMA map size={:#x}, iova={:#x}, vaddr={:#x}",
dmaMap.size, dmaMap.iova, dmaMap.vaddr); dmaMap.size, dmaMap.iova, dmaMap.vaddr);
// mapping successful, advance IOVA allocator /* Mapping successful, advance IOVA allocator */
this->iova_next += iovaIncrement; this->iova_next += iovaIncrement;
// we intentionally don't return the actual mapped length, the users are /* We intentionally don't return the actual mapped length, the users are
// only guaranteed to have their demanded memory mapped correctly * only guaranteed to have their demanded memory mapped correctly
*/
return dmaMap.iova; return dmaMap.iova;
} }
...@@ -423,14 +424,14 @@ VfioContainer::getOrAttachGroup(int index) ...@@ -423,14 +424,14 @@ VfioContainer::getOrAttachGroup(int index)
{ {
Logger logger = logging.get("kernel:vfio"); Logger logger = logging.get("kernel:vfio");
// search if group with index already exists /* Search if group with index already exists */
for (auto& group : groups) { for (auto& group : groups) {
if(group->index == index) { if(group->index == index) {
return *group; return *group;
} }
} }
// group not yet part of this container, so acquire ownership /* Group not yet part of this container, so acquire ownership */
auto group = VfioGroup::attach(*this, index); auto group = VfioGroup::attach(*this, index);
if (not group) { if (not group) {
logger->error("Failed to attach to IOMMU group: {}", index); logger->error("Failed to attach to IOMMU group: {}", index);
...@@ -439,7 +440,7 @@ VfioContainer::getOrAttachGroup(int index) ...@@ -439,7 +440,7 @@ VfioContainer::getOrAttachGroup(int index)
logger->debug("Attached new group {} to VFIO container", index); logger->debug("Attached new group {} to VFIO container", index);
} }
// push to our list /* Push to our list */
groups.push_back(std::move(group)); groups.push_back(std::move(group));
return *groups.back(); return *groups.back();
...@@ -837,5 +838,5 @@ VfioGroup::attach(VfioContainer& container, int groupIndex) ...@@ -837,5 +838,5 @@ VfioGroup::attach(VfioContainer& container, int groupIndex)
return group; return group;
} }
} // namespace villas } /* namespace villas */
...@@ -47,7 +47,7 @@ Log::Log(Level lvl) : ...@@ -47,7 +47,7 @@ Log::Log(Level lvl) :
setLevel(level); setLevel(level);
setPattern(pattern); setPattern(pattern);
// Default sink /* Default sink */
sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>(); sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
sinks->add_sink(sink); sinks->add_sink(sink);
......
...@@ -53,7 +53,7 @@ HostRam::HostRamAllocator::allocateBlock(size_t size) ...@@ -53,7 +53,7 @@ HostRam::HostRamAllocator::allocateBlock(size_t size)
auto& mm = MemoryManager::get(); auto& mm = MemoryManager::get();
// assemble name for this block /* Assemble name for this block */
std::stringstream name; std::stringstream name;
name << std::showbase << std::hex << reinterpret_cast<uintptr_t>(addr); name << std::showbase << std::hex << reinterpret_cast<uintptr_t>(addr);
...@@ -78,7 +78,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId ...@@ -78,7 +78,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId
internalOffset(internalOffset), internalOffset(internalOffset),
allocationCount(0) allocationCount(0)
{ {
// make sure to start at aligned offset, reduce size in case we need padding /* Make sure to start at aligned offset, reduce size in case we need padding */
if(const size_t paddingBytes = getAlignmentPadding(internalOffset)) { if(const size_t paddingBytes = getAlignmentPadding(internalOffset)) {
assert(paddingBytes < memorySize); assert(paddingBytes < memorySize);
...@@ -86,7 +86,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId ...@@ -86,7 +86,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId
memorySize -= paddingBytes; memorySize -= paddingBytes;
} }
// deallocation callback /* Deallocation callback */
free = [&](MemoryBlock* mem) { free = [&](MemoryBlock* mem) {
logger->debug("Deallocating memory block at local addr {:#x} (addr space {})", logger->debug("Deallocating memory block at local addr {:#x} (addr space {})",
mem->getOffset(), mem->getAddrSpaceId()); mem->getOffset(), mem->getAddrSpaceId());
...@@ -97,7 +97,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId ...@@ -97,7 +97,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId
if(allocationCount == 0) { if(allocationCount == 0) {
logger->debug("All allocations are deallocated now, freeing memory"); logger->debug("All allocations are deallocated now, freeing memory");
// all allocations have been deallocated, free all memory /* All allocations have been deallocated, free all memory */
nextFreeAddress = 0; nextFreeAddress = 0;
} }
...@@ -126,28 +126,28 @@ LinearAllocator::allocateBlock(size_t size) ...@@ -126,28 +126,28 @@ LinearAllocator::allocateBlock(size_t size)
throw std::bad_alloc(); throw std::bad_alloc();
} }
// assign address /* Assign address */
const uintptr_t localAddr = nextFreeAddress + internalOffset; const uintptr_t localAddr = nextFreeAddress + internalOffset;
// reserve memory /* Reserve memory */
nextFreeAddress += size; nextFreeAddress += size;
// make sure it is aligned /* Make sure it is aligned */
if(const size_t paddingBytes = getAlignmentPadding(nextFreeAddress)) { if(const size_t paddingBytes = getAlignmentPadding(nextFreeAddress)) {
nextFreeAddress += paddingBytes; nextFreeAddress += paddingBytes;
// if next free address is outside this block due to padding, cap it /* If next free address is outside this block due to padding, cap it */
nextFreeAddress = std::min(nextFreeAddress, memorySize); nextFreeAddress = std::min(nextFreeAddress, memorySize);
} }
auto& mm = MemoryManager::get(); auto& mm = MemoryManager::get();
// assemble name for this block /* Assemble name for this block */
std::stringstream blockName; std::stringstream blockName;
blockName << std::showbase << std::hex << localAddr; blockName << std::showbase << std::hex << localAddr;
// create address space /* Create address space */
auto addrSpaceName = mm.getSlaveAddrSpaceName(getName(), blockName.str()); auto addrSpaceName = mm.getSlaveAddrSpaceName(getName(), blockName.str());
auto addrSpaceId = mm.getOrCreateAddressSpace(addrSpaceName); auto addrSpaceId = mm.getOrCreateAddressSpace(addrSpaceName);
...@@ -157,10 +157,10 @@ LinearAllocator::allocateBlock(size_t size) ...@@ -157,10 +157,10 @@ LinearAllocator::allocateBlock(size_t size)
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn> std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
mem(new MemoryBlock(localAddr, size, addrSpaceId), this->free); mem(new MemoryBlock(localAddr, size, addrSpaceId), this->free);
// mount block into the memory graph /* Mount block into the memory graph */
insertMemoryBlock(*mem); insertMemoryBlock(*mem);
// increase the allocation count /* Increase the allocation count */
allocationCount++; allocationCount++;
return mem; return mem;
...@@ -233,13 +233,13 @@ HostDmaRam::HostDmaRamAllocator::~HostDmaRamAllocator() ...@@ -233,13 +233,13 @@ HostDmaRam::HostDmaRamAllocator::~HostDmaRamAllocator()
auto translation = mm.getTranslationFromProcess(getAddrSpaceId()); auto translation = mm.getTranslationFromProcess(getAddrSpaceId());
baseVirt = reinterpret_cast<void*>(translation.getLocalAddr(0)); baseVirt = reinterpret_cast<void*>(translation.getLocalAddr(0));
} catch(const std::out_of_range&) { } catch(const std::out_of_range&) {
// not mapped, nothing to do /* Not mapped, nothing to do */
return; return;
} }
logger->debug("Unmapping {}", getName()); logger->debug("Unmapping {}", getName());
// try to unmap it /* Try to unmap it */
if(::munmap(baseVirt, getSize()) != 0) { if(::munmap(baseVirt, getSize()) != 0) {
logger->warn("munmap() failed for {:p} of size {:#x}", logger->warn("munmap() failed for {:p} of size {:#x}",
baseVirt, getSize()); baseVirt, getSize());
...@@ -301,4 +301,4 @@ HostDmaRam::HostDmaRamAllocator&HostDmaRam::getAllocator(int num) ...@@ -301,4 +301,4 @@ HostDmaRam::HostDmaRamAllocator&HostDmaRam::getAllocator(int num)
return *allocator; return *allocator;
} }
} // namespace villas } /* namespace villas */
...@@ -48,14 +48,14 @@ MemoryManager::AddressSpaceId ...@@ -48,14 +48,14 @@ MemoryManager::AddressSpaceId
MemoryManager::getOrCreateAddressSpace(std::string name) MemoryManager::getOrCreateAddressSpace(std::string name)
{ {
try { try {
// try fast lookup /* Try fast lookup */
return addrSpaceLookup.at(name); return addrSpaceLookup.at(name);
} catch (const std::out_of_range&) { } catch (const std::out_of_range&) {
// does not yet exist, create /* Does not yet exist, create */
std::shared_ptr<AddressSpace> addrSpace(new AddressSpace); std::shared_ptr<AddressSpace> addrSpace(new AddressSpace);
addrSpace->name = name; addrSpace->name = name;
// cache it for the next access /* Cache it for the next access */
addrSpaceLookup[name] = memoryGraph.addVertex(addrSpace); addrSpaceLookup[name] = memoryGraph.addVertex(addrSpace);
return addrSpaceLookup[name]; return addrSpaceLookup[name];
...@@ -104,7 +104,7 @@ MemoryManager::findPath(MemoryManager::AddressSpaceId fromAddrSpaceId, ...@@ -104,7 +104,7 @@ MemoryManager::findPath(MemoryManager::AddressSpaceId fromAddrSpaceId,
auto fromAddrSpace = memoryGraph.getVertex(fromAddrSpaceId); auto fromAddrSpace = memoryGraph.getVertex(fromAddrSpaceId);
auto toAddrSpace = memoryGraph.getVertex(toAddrSpaceId); auto toAddrSpace = memoryGraph.getVertex(toAddrSpaceId);
// find a path through the memory graph /* Find a path through the memory graph */
MemoryGraph::Path pathGraph; MemoryGraph::Path pathGraph;
if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, pathGraph, pathCheckFunc)) { if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, pathGraph, pathCheckFunc)) {
...@@ -126,7 +126,7 @@ MemoryTranslation ...@@ -126,7 +126,7 @@ MemoryTranslation
MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId,
MemoryManager::AddressSpaceId toAddrSpaceId) MemoryManager::AddressSpaceId toAddrSpaceId)
{ {
// find a path through the memory graph /* Find a path through the memory graph */
MemoryGraph::Path path; MemoryGraph::Path path;
if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, path, pathCheckFunc)) { if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, path, pathCheckFunc)) {
...@@ -138,10 +138,10 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, ...@@ -138,10 +138,10 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId,
throw std::out_of_range("no translation found"); throw std::out_of_range("no translation found");
} }
// start with an identity mapping /* Start with an identity mapping */
MemoryTranslation translation(0, 0, SIZE_MAX); MemoryTranslation translation(0, 0, SIZE_MAX);
// iterate through path and merge all mappings into a single translation /* Iterate through path and merge all mappings into a single translation */
for(auto& mappingId : path) { for(auto& mappingId : path) {
auto mapping = memoryGraph.getEdge(mappingId); auto mapping = memoryGraph.getEdge(mappingId);
translation += getTranslationFromMapping(*mapping); translation += getTranslationFromMapping(*mapping);
...@@ -153,11 +153,12 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, ...@@ -153,11 +153,12 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId,
bool bool
MemoryManager::pathCheck(const MemoryGraph::Path& path) MemoryManager::pathCheck(const MemoryGraph::Path& path)
{ {
// start with an identity mapping /* Start with an identity mapping */
MemoryTranslation translation(0, 0, SIZE_MAX); MemoryTranslation translation(0, 0, SIZE_MAX);
// Try to add all mappings together to a common translation. If this fails /* Try to add all mappings together to a common translation. If this fails
// there is a non-overlapping window * there is a non-overlapping window.
*/
for(auto& mappingId : path) { for(auto& mappingId : path) {
auto mapping = memoryGraph.getEdge(mappingId); auto mapping = memoryGraph.getEdge(mappingId);
try { try {
...@@ -191,7 +192,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other) ...@@ -191,7 +192,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other)
{ {
Logger logger = logging.get("MemoryTranslation"); Logger logger = logging.get("MemoryTranslation");
// set level to debug to enable debug output /* Set level to debug to enable debug output */
logger->set_level(spdlog::level::info); logger->set_level(spdlog::level::info);
const uintptr_t this_dst_high = this->dst + this->size; const uintptr_t this_dst_high = this->dst + this->size;
...@@ -206,7 +207,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other) ...@@ -206,7 +207,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other)
logger->debug("this_dst_high: {:#x}", this_dst_high); logger->debug("this_dst_high: {:#x}", this_dst_high);
logger->debug("other_src_high: {:#x}", other_src_high); logger->debug("other_src_high: {:#x}", other_src_high);
// make sure there is a common memory area /* Make sure there is a common memory area */
assertExcept(other.src < this_dst_high, MemoryManager::InvalidTranslation()); assertExcept(other.src < this_dst_high, MemoryManager::InvalidTranslation());
assertExcept(this->dst < other_src_high, MemoryManager::InvalidTranslation()); assertExcept(this->dst < other_src_high, MemoryManager::InvalidTranslation());
...@@ -227,23 +228,25 @@ MemoryTranslation::operator+=(const MemoryTranslation& other) ...@@ -227,23 +228,25 @@ MemoryTranslation::operator+=(const MemoryTranslation& other)
logger->debug("diff_hi: {:#x}", diff_hi); logger->debug("diff_hi: {:#x}", diff_hi);
logger->debug("diff_lo: {:#x}", diff_lo); logger->debug("diff_lo: {:#x}", diff_lo);
// new size of aperture, can only stay or shrink /* New size of aperture, can only stay or shrink */
this->size = (hi - lo) - diff_hi - diff_lo; this->size = (hi - lo) - diff_hi - diff_lo;
// new translation will come out other's destination (by default)