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

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: ...@@ -30,8 +30,14 @@ public:
MemoryTranslation(uintptr_t src, uintptr_t dst, size_t size) : MemoryTranslation(uintptr_t src, uintptr_t dst, size_t size) :
src(src), dst(dst), size(size) {} src(src), dst(dst), size(size) {}
uintptr_t template<typename ReturnType = uintptr_t>
getLocalAddr(uintptr_t addrInForeignAddrSpace) const; ReturnType
getLocalAddr(uintptr_t addrInForeignAddrSpace) const
{
assert(addrInForeignAddrSpace >= dst);
assert(addrInForeignAddrSpace < (dst + size));
return reinterpret_cast<ReturnType>(src + addrInForeignAddrSpace - dst);
}
uintptr_t uintptr_t
getForeignAddr(uintptr_t addrInLocalAddrSpace) const; getForeignAddr(uintptr_t addrInLocalAddrSpace) const;
......
...@@ -148,13 +148,6 @@ MemoryManager::pathCheck(const MemoryGraph::Path& path) ...@@ -148,13 +148,6 @@ MemoryManager::pathCheck(const MemoryGraph::Path& path)
return true; return true;
} }
uintptr_t
MemoryTranslation::getLocalAddr(uintptr_t addrInForeignAddrSpace) const
{
assert(addrInForeignAddrSpace >= dst);
assert(addrInForeignAddrSpace < (dst + size));
return src + addrInForeignAddrSpace - dst;
}
uintptr_t uintptr_t
MemoryTranslation::getForeignAddr(uintptr_t addrInLocalAddrSpace) const MemoryTranslation::getForeignAddr(uintptr_t addrInLocalAddrSpace) const
......
Supports Markdown
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