Commit 4471d735 authored by Daniel Krebs's avatar Daniel Krebs

mm/translation: let user choose the return type as template parameter

this can avoid sooo many reinterpret_cast<> in application code
parent d10917d3
......@@ -30,8 +30,14 @@ public:
MemoryTranslation(uintptr_t src, uintptr_t dst, size_t size) :
src(src), dst(dst), size(size) {}
uintptr_t
getLocalAddr(uintptr_t addrInForeignAddrSpace) const;
template<typename ReturnType = uintptr_t>
ReturnType
getLocalAddr(uintptr_t addrInForeignAddrSpace) const
{
assert(addrInForeignAddrSpace >= dst);
assert(addrInForeignAddrSpace < (dst + size));
return reinterpret_cast<ReturnType>(src + addrInForeignAddrSpace - dst);
}
uintptr_t
getForeignAddr(uintptr_t addrInLocalAddrSpace) const;
......
......@@ -148,13 +148,6 @@ MemoryManager::pathCheck(const MemoryGraph::Path& path)
return true;
}
uintptr_t
MemoryTranslation::getLocalAddr(uintptr_t addrInForeignAddrSpace) const
{
assert(addrInForeignAddrSpace >= dst);
assert(addrInForeignAddrSpace < (dst + size));
return src + addrInForeignAddrSpace - dst;
}
uintptr_t
MemoryTranslation::getForeignAddr(uintptr_t addrInLocalAddrSpace) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment