C-style cast cleanup V

This commit is contained in:
Nekotekina 2019-12-03 00:31:34 +03:00
parent 46ca39ec4d
commit 185c067d5b
44 changed files with 439 additions and 435 deletions

View file

@ -19,34 +19,34 @@
namespace vm
{
static u8* memory_reserve_4GiB(std::uintptr_t _addr = 0)
static u8* memory_reserve_4GiB(void* _addr, u64 size = 0x100000000)
{
for (u64 addr = _addr + 0x100000000;; addr += 0x100000000)
for (u64 addr = reinterpret_cast<u64>(_addr) + 0x100000000;; addr += 0x100000000)
{
if (auto ptr = utils::memory_reserve(0x100000000, (void*)addr))
if (auto ptr = utils::memory_reserve(size, reinterpret_cast<void*>(addr)))
{
return static_cast<u8*>(ptr);
}
}
// TODO: a condition to break loop
return static_cast<u8*>(utils::memory_reserve(0x100000000));
return static_cast<u8*>(utils::memory_reserve(size));
}
// Emulated virtual memory
u8* const g_base_addr = memory_reserve_4GiB(0x2'0000'0000);
u8* const g_base_addr = memory_reserve_4GiB(reinterpret_cast<void*>(0x2'0000'0000));
// Unprotected virtual memory mirror
u8* const g_sudo_addr = memory_reserve_4GiB((std::uintptr_t)g_base_addr);
u8* const g_sudo_addr = memory_reserve_4GiB(g_base_addr);
// Auxiliary virtual memory for executable areas
u8* const g_exec_addr = memory_reserve_4GiB((std::uintptr_t)g_sudo_addr);
u8* const g_exec_addr = memory_reserve_4GiB(g_sudo_addr, 0x200000000);
// Stats for debugging
u8* const g_stat_addr = memory_reserve_4GiB((std::uintptr_t)g_exec_addr);
u8* const g_stat_addr = memory_reserve_4GiB(g_exec_addr);
// Reservation stats (compressed x16)
u8* const g_reservations = memory_reserve_4GiB((std::uintptr_t)g_stat_addr);
u8* const g_reservations = memory_reserve_4GiB(g_stat_addr);
// Memory locations
std::vector<std::shared_ptr<block_t>> g_locations;
@ -128,7 +128,7 @@ namespace vm
if (LIKELY(test_addr(g_addr_lock.load(), addr, end)))
{
// Optimistic path (hope that address range is not locked)
_ret = _register_range_lock((u64)end << 32 | addr);
_ret = _register_range_lock(u64{end} << 32 | addr);
if (LIKELY(test_addr(g_addr_lock.load(), addr, end)))
{
@ -140,7 +140,7 @@ namespace vm
{
::reader_lock lock(g_mutex);
_ret = _register_range_lock((u64)end << 32 | addr);
_ret = _register_range_lock(u64{end} << 32 | addr);
}
return _ret;
@ -540,7 +540,7 @@ namespace vm
if (!block)
{
fmt::throw_exception("Invalid memory location (%u)" HERE, (uint)location);
fmt::throw_exception("Invalid memory location (%u)" HERE, +location);
}
return block->alloc(size, align);
@ -552,7 +552,7 @@ namespace vm
if (!block)
{
fmt::throw_exception("Invalid memory location (%u, addr=0x%x)" HERE, (uint)location, addr);
fmt::throw_exception("Invalid memory location (%u, addr=0x%x)" HERE, +location, addr);
}
return block->falloc(addr, size);
@ -564,7 +564,7 @@ namespace vm
if (!block)
{
fmt::throw_exception("Invalid memory location (%u, addr=0x%x)" HERE, (uint)location, addr);
fmt::throw_exception("Invalid memory location (%u, addr=0x%x)" HERE, +location, addr);
}
return block->dealloc(addr);
@ -576,7 +576,7 @@ namespace vm
if (!block)
{
LOG_ERROR(MEMORY, "vm::dealloc(): invalid memory location (%u, addr=0x%x)\n", (uint)location, addr);
LOG_ERROR(MEMORY, "vm::dealloc(): invalid memory location (%u, addr=0x%x)\n", +location, addr);
return;
}