Introducing reflection levels concept into core components (#91)

The idea is to allow as much internal information into inner components.
to not burden all builds, the reflection level can be controlled via the
MOMO_REFLECTION_LEVEL (where 0 means no reflection code is included).

more reflection variables will be introduced as needed.

For now, the memory manager's layout state version is used to track
whether the memory layout is changed or not (at the lowest level). the
win_emu API consumer can use this reflection to decide to whether to
refresh or not expensive computations
This commit is contained in:
Elias Bachaalany
2025-01-20 11:19:33 -08:00
committed by GitHub
3 changed files with 33 additions and 0 deletions

View File

@@ -5,6 +5,10 @@ cmake_minimum_required(VERSION 3.26.4)
option(MOMO_ENABLE_SANITIZER "Enable sanitizer" OFF)
option(MOMO_BUILD_AS_LIBRARY "Configure and Build the emulator as a shared library (without the samples and tests)" OFF)
set(MOMO_REFLECTION_LEVEL "0" CACHE STRING "Reflection level for the build")
message(STATUS "Reflection level is set to: ${MOMO_REFLECTION_LEVEL}")
add_compile_definitions(MOMO_REFLECTION_LEVEL=${MOMO_REFLECTION_LEVEL})
if(MOMO_BUILD_AS_LIBRARY)
add_compile_definitions(MOMO_BUILD_AS_LIBRARY=1)
else()

View File

@@ -214,6 +214,9 @@ bool memory_manager::protect_memory(const uint64_t address, const size_t size, c
}
merge_regions(committed_regions);
invalidate_memory_layout_state_version();
return true;
}
@@ -237,6 +240,8 @@ bool memory_manager::allocate_mmio(const uint64_t address, const size_t size, mm
entry->second.committed_regions[address] = committed_region{size, memory_permission::read_write};
invalidate_memory_layout_state_version();
return true;
}
@@ -261,6 +266,8 @@ bool memory_manager::allocate_memory(const uint64_t address, const size_t size,
entry->second.committed_regions[address] = committed_region{size, memory_permission::read_write};
}
invalidate_memory_layout_state_version();
return true;
}
@@ -320,6 +327,9 @@ bool memory_manager::commit_memory(const uint64_t address, const size_t size, co
}
merge_regions(committed_regions);
invalidate_memory_layout_state_version();
return true;
}
@@ -366,6 +376,8 @@ bool memory_manager::decommit_memory(const uint64_t address, const size_t size)
++i;
}
invalidate_memory_layout_state_version();
return true;
}
@@ -418,6 +430,7 @@ bool memory_manager::release_memory(const uint64_t address, size_t size)
}
this->reserved_regions_.erase(entry);
invalidate_memory_layout_state_version();
return true;
}

View File

@@ -1,5 +1,7 @@
#pragma once
#include <map>
#include <atomic>
#include <cstdint>
#include "memory_region.hpp"
#include "address_utils.hpp"
@@ -123,6 +125,11 @@ class memory_manager
return reserved_regions_;
}
std::uint64_t get_memory_layout_state_ver() const
{
return memory_layout_state_version_.load(std::memory_order_relaxed);
}
private:
reserved_region_map reserved_regions_{};
@@ -133,6 +140,15 @@ class memory_manager
virtual void apply_memory_protection(uint64_t address, size_t size, memory_permission permissions) = 0;
protected:
std::atomic<std::uint64_t> memory_layout_state_version_{0};
void invalidate_memory_layout_state_version()
{
#if MOMO_REFLECTION_LEVEL > 0
memory_layout_state_version_.fetch_add(1, std::memory_order_relaxed);
#endif
}
void serialize_memory_state(utils::buffer_serializer& buffer, bool is_snapshot) const;
void deserialize_memory_state(utils::buffer_deserializer& buffer, bool is_snapshot);
};