Files
AC6_recomp/thirdparty/rexglue-sdk/include/rex/system/kernel_module.h
T

63 lines
2.0 KiB
C++

#pragma once
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*
* @modified Tom Clay, 2026 - Adapted for ReXGlue runtime
*/
#include <unordered_map>
#include <rex/system/export_resolver.h>
#include <rex/system/xmodule.h>
namespace rex::system {
class KernelState;
class KernelModule : public XModule {
public:
KernelModule(KernelState* kernel_state, const std::string_view path);
~KernelModule() override;
const std::string& path() const override { return path_; }
const std::string& name() const override { return name_; }
uint32_t GetProcAddressByOrdinal(uint16_t ordinal, uint32_t caller_address = 0) override;
uint32_t GetProcAddressByName(const std::string_view name) override;
/**
* Erase any cached thunks whose guest address falls in [lo, hi).
*/
void InvalidateThunkCacheInRange(uint32_t lo, uint32_t hi);
protected:
rex::runtime::ExportResolver* export_resolver_;
std::string name_;
std::string path_;
rex::thread::global_critical_region global_critical_region_;
// Cache of (caller_module_base, ordinal) -> thunk guest address.
struct ThunkKey {
uint32_t caller_module_base;
uint16_t ordinal;
bool operator==(const ThunkKey& other) const {
return caller_module_base == other.caller_module_base && ordinal == other.ordinal;
}
};
struct ThunkKeyHash {
std::size_t operator()(const ThunkKey& k) const noexcept {
return std::hash<uint64_t>{}((uint64_t(k.caller_module_base) << 16) | k.ordinal);
}
};
std::unordered_map<ThunkKey, uint32_t, ThunkKeyHash> thunk_cache_;
};
} // namespace rex::system