|
ReXGlue SDK
|
Classes | |
| class | BitStream |
| class | ByteStream |
| class | ChunkedMappedMemoryWriter |
| class | GuestMembase |
| struct | HostStats |
| struct | IsMappedPtr |
| struct | IsMappedPtr< MappedPtr< T > > |
| class | MappedMemory |
| class | MappedPtr |
| class | MappedPtr< char > |
| class | MappedPtr< char16_t > |
| class | MappedPtr< void > |
| struct | MappedPtrInnerType |
| struct | MappedPtrInnerType< MappedPtr< T > > |
| class | RingBuffer |
| class | TagScope |
| struct | TagStats |
Typedefs | |
| using | FourCCT = u32 |
| using | RingSizeT = u32 |
| using | FileMappingHandle = int |
Enumerations | |
| enum class | Tag : u8 { kCore = 0 , kThirdParty = 1 } |
| enum class | PageAccess : u8 { kNoAccess = 0 , kReadOnly = 1 << 0 , kReadWrite = kReadOnly | 1 << 1 , kExecuteReadOnly = kReadOnly | 1 << 2 , kExecuteReadWrite = kReadWrite | 1 << 2 } |
| enum class | AllocationType : u8 { kReserve = 1 << 0 , kCommit = 1 << 1 , kReserveCommit = kReserve | kCommit } |
| enum class | DeallocationType : u8 { kRelease = 1 << 0 , kDecommit = 1 << 1 } |
Functions | |
| void | Copy128Aligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_16_aligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_16_unaligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_32_aligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_32_unaligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_64_aligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_64_unaligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_16_in_32_aligned (void *dest, const void *src, size_t count) |
| void | copy_and_swap_16_in_32_unaligned (void *dest, const void *src, size_t count) |
| template<typename T> | |
| void | copy_and_swap (T *dest, const T *src, size_t count) |
| template<typename T> | |
| T | load (const void *mem) |
| template<typename T> | |
| T | load_and_swap (const void *mem) |
| template<> | |
| std::string | load_and_swap< std::string > (const void *mem) |
| template<> | |
| std::u16string | load_and_swap< std::u16string > (const void *mem) |
| template<typename T> | |
| void | store (void *mem, const T &value) |
| template<typename T> | |
| void | store_and_swap (void *mem, const T &value) |
| template<> | |
| void | store_and_swap< std::string_view > (void *mem, const std::string_view &value) |
| template<> | |
| void | store_and_swap< std::string > (void *mem, const std::string &value) |
| template<> | |
| void | store_and_swap< std::u16string_view > (void *mem, const std::u16string_view &value) |
| template<> | |
| void | store_and_swap< std::u16string > (void *mem, const std::u16string &value) |
| constexpr u32 | LoadUint24BE (const u8 *p) |
| constexpr u32 | LoadUint24LE (const u8 *p) |
| constexpr void | StoreUint24LE (u8 *p, u32 value) |
| constexpr FourCCT | make_fourcc (char a, char b, char c, char d) |
| constexpr FourCCT | make_fourcc (const std::string_view fourcc) |
| void * | HostAlloc (size_t size, size_t align=0) noexcept |
| void | HostFree (void *ptr, size_t size=0, size_t align=0) noexcept |
| size_t | HostSize (const void *ptr) noexcept |
| HostStats | GetHostStats () noexcept |
| void | SetAllocStackDepth (i32 depth) noexcept |
| i32 | GetAllocStackDepth () noexcept |
| Tag | GetThreadTag () noexcept |
| const char * | GetTagName (Tag tag) noexcept |
| void | SetTagName (Tag tag, const char *name) noexcept |
| template<typename T = u8*> | |
| T | GuestPtr (u8 *base, u32 guest_address) noexcept |
| u32 | HostPtrToGuest (const u8 *base, const void *host_address) noexcept |
| size_t | GetPageSize () |
| size_t | GetAllocationGranularity () |
| bool | IsWritableExecutableMemorySupported () |
| void * | AllocFixed (void *base_address, size_t length, AllocationType allocation_type, PageAccess access) |
| bool | DeallocFixed (void *base_address, size_t length, DeallocationType deallocation_type) |
| bool | Protect (void *base_address, size_t length, PageAccess access, PageAccess *out_old_access=nullptr) |
| bool | QueryProtect (void *base_address, size_t &length, PageAccess &out_access) |
| template<typename T> | |
| T * | AlignedAlloc (size_t alignment) |
| template<typename T> | |
| void | AlignedFree (T *ptr) |
| FileMappingHandle | CreateFileMappingHandle (const std::filesystem::path &path, size_t length, PageAccess access, bool commit) |
| std::filesystem::path | CreateFileMappingName (std::string_view prefix) |
| void | RemoveStaleFileMappings (std::string_view prefix) |
| void | CloseFileMappingHandle (FileMappingHandle handle, const std::filesystem::path &path) |
| void * | MapFileView (FileMappingHandle handle, void *base_address, size_t length, PageAccess access, size_t file_offset) |
| bool | UnmapFileView (FileMappingHandle handle, void *base_address, size_t length) |
| void * | LowAddress (void *address) |
Variables | |
| constexpr size_t | kMaxTags = 16 |
| template<typename T> | |
| constexpr bool | is_mapped_ptr_v = IsMappedPtr<T>::value |
| constexpr FileMappingHandle | kFileMappingHandleInvalid = -1 |
Guest memory types and helpers.
| using rex::memory::FileMappingHandle = int |
File mapping handle, a file descriptor.
| using rex::memory::FourCCT = u32 |
4 character code packed into 32 bits.
|
strong |
|
strong |
|
strong |
|
inline |
Allocates aligned host memory for one object.
| alignment | Alignment in bytes, a power of 2. |
| void rex::memory::AlignedFree | ( | T * | ptr | ) |
Frees memory AlignedAlloc returned.
| ptr | Pointer AlignedAlloc returned. |
| void * rex::memory::AllocFixed | ( | void * | base_address, |
| size_t | length, | ||
| AllocationType | allocation_type, | ||
| PageAccess | access ) |
Allocates host pages at a page aligned address.
| base_address | Requested address, or null to let the system choose. |
| allocation_type | Reserve, commit or both. |
| access | Access rights of the new pages. |
| void rex::memory::CloseFileMappingHandle | ( | FileMappingHandle | handle, |
| const std::filesystem::path & | path ) |
Closes a handle CreateFileMappingHandle returned. POSIX unlinks the object.
| path | Name the object was created with. |
| void rex::memory::Copy128Aligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 16 byte blocks between 16 byte aligned buffers.
| count | Number of 16 byte blocks. |
| void rex::memory::copy_and_swap | ( | T * | dest, |
| const T * | src, | ||
| size_t | count ) |
Copies values and swaps the byte order of each.
| T | Element type, 1, 2, 4 or 8 bytes. |
| void rex::memory::copy_and_swap_16_aligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 16 bit values and swaps the byte order of each. Both buffers are 16 byte aligned.
| count | Number of 16 bit values. |
| void rex::memory::copy_and_swap_16_in_32_aligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 32 bit values and swaps the two 16 bit halves of each. Both buffers are 16 byte aligned.
| count | Number of 32 bit values. |
| void rex::memory::copy_and_swap_16_in_32_unaligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 32 bit values and swaps the two 16 bit halves of each.
| count | Number of 32 bit values. |
| void rex::memory::copy_and_swap_16_unaligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 16 bit values and swaps the byte order of each.
| count | Number of 16 bit values. |
| void rex::memory::copy_and_swap_32_aligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 32 bit values and swaps the byte order of each. Both buffers are 16 byte aligned.
| count | Number of 32 bit values. |
| void rex::memory::copy_and_swap_32_unaligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 32 bit values and swaps the byte order of each.
| count | Number of 32 bit values. |
| void rex::memory::copy_and_swap_64_aligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 64 bit values and swaps the byte order of each. Both buffers are 16 byte aligned.
| count | Number of 64 bit values. |
| void rex::memory::copy_and_swap_64_unaligned | ( | void * | dest, |
| const void * | src, | ||
| size_t | count ) |
Copies 64 bit values and swaps the byte order of each.
| count | Number of 64 bit values. |
| FileMappingHandle rex::memory::CreateFileMappingHandle | ( | const std::filesystem::path & | path, |
| size_t | length, | ||
| PageAccess | access, | ||
| bool | commit ) |
Creates a named shared memory object.
| access | Access rights of views of the object. |
| commit | True to commit the whole object up front. Only Windows reads it. |
| std::filesystem::path rex::memory::CreateFileMappingName | ( | std::string_view | prefix | ) |
Builds a unique name from the prefix, process ID, underscore and random hex.
| bool rex::memory::DeallocFixed | ( | void * | base_address, |
| size_t | length, | ||
| DeallocationType | deallocation_type ) |
Decommits or releases host pages.
| length | Byte count. Windows ignores it for kRelease and releases the whole region. |
| deallocation_type | Decommit or release. |
| size_t rex::memory::GetAllocationGranularity | ( | ) |
|
nodiscardnoexcept |
Returns how many call stack frames the profiler keeps per allocation, 0 for none.
|
noexcept |
Returns a snapshot of the counters, not atomic across tags.
| size_t rex::memory::GetPageSize | ( | ) |
|
noexcept |
|
noexcept |
Returns the tag of the calling thread. New allocations on this thread receive it.
|
inlinenoexcept |
Translates a guest address to a host pointer with the arithmetic recompiled code uses.
|
noexcept |
Allocates host memory under the tag of the calling thread. Works before main and after Shutdown.
| size | The size in bytes, 0 returns a unique block. |
| align | The alignment in bytes, a power of 2, 0 for the default alignment of 16. |
|
noexcept |
Frees a block made by HostAlloc.
| ptr | The block, null does nothing. |
| size | The size passed to HostAlloc, 0 when unknown. |
| align | The alignment passed to HostAlloc, 0 when unknown. |
|
inlinenoexcept |
Translates a host pointer into guest memory back to its guest address. Inverts GuestPtr.
| host_address | The host pointer, null for no address. |
|
noexcept |
Returns the requested size of a block made by HostAlloc.
| ptr | The block, not null. |
| bool rex::memory::IsWritableExecutableMemorySupported | ( | ) |
Reports whether host pages can use PageAccess::kExecuteReadWrite.
|
inline |
Loads a value from memory of any alignment.
|
inline |
Loads a value from memory and swaps its byte order.
| T | Value type, 1, 2, 4 or 8 bytes. |
|
inline |
Loads a NUL terminated 8 bit string.
|
inline |
Loads a NUL terminated big endian UTF-16 string.
|
constexpr |
Reads a 24 bit big endian value.
| p | The 3 source bytes. |
|
constexpr |
Reads a 24 bit little endian value.
| p | The 3 source bytes. |
|
inline |
Truncates a host pointer to its low 32 bits.
|
constexpr |
Packs 4 characters into a FourCC in host byte order.
| a | First character, the most significant byte. |
| d | Fourth character, the least significant byte. |
|
constexpr |
Packs a 4 character string into a FourCC in host byte order.
| fourcc | String of exactly 4 characters. Any other length throws std::runtime_error. |
| void * rex::memory::MapFileView | ( | FileMappingHandle | handle, |
| void * | base_address, | ||
| size_t | length, | ||
| PageAccess | access, | ||
| size_t | file_offset ) |
Maps a view of a shared memory object.
| handle | Handle CreateFileMappingHandle returned. |
| base_address | Requested address, or null to let the system choose. |
| file_offset | Offset of the view in the object, page aligned. |
| bool rex::memory::Protect | ( | void * | base_address, |
| size_t | length, | ||
| PageAccess | access, | ||
| PageAccess * | out_old_access = nullptr ) |
Changes the access rights of host pages.
| out_old_access | Receives the previous access rights of the first page, or null. |
| bool rex::memory::QueryProtect | ( | void * | base_address, |
| size_t & | length, | ||
| PageAccess & | out_access ) |
Returns the access rights of the region that holds an address.
| base_address | Address inside the region. |
| length | Receives the byte count of consecutive pages with the same access rights. |
| out_access | Receives the access rights. |
| void rex::memory::RemoveStaleFileMappings | ( | std::string_view | prefix | ) |
Removes shared memory objects whose name starts with the prefix, a dead process ID and an underscore. Only Linux removes any.
| prefix | Leading part of the names to inspect. |
|
noexcept |
Sets how many call stack frames the profiler keeps per allocation. No effect without profiling.
| depth | The frame count, clamped to 0 through 32, 0 for none. |
|
noexcept |
Names a tag for the profiler and diagnostics. Works before main.
| tag | The tag, below kMaxTags. A larger value does nothing. |
| name | The name, shorter than 32 characters. The allocator copies it. |
|
inline |
Stores a value to memory of any alignment.
|
inline |
Swaps the byte order of a value and stores it to memory.
| T | Value type, 1, 2, 4 or 8 bytes. |
|
inline |
Stores the characters of an 8 bit string without a terminator.
|
inline |
Stores the characters of an 8 bit string without a terminator.
|
inline |
Stores a UTF-16 string as big endian code units without a terminator.
|
inline |
Stores a UTF-16 string as big endian code units without a terminator.
|
constexpr |
Writes a 24 bit little endian value.
| p | The 3 destination bytes. |
| value | Value whose top 8 bits are discarded. |
| bool rex::memory::UnmapFileView | ( | FileMappingHandle | handle, |
| void * | base_address, | ||
| size_t | length ) |
Unmaps a view MapFileView returned.
|
constexpr |
Value CreateFileMappingHandle returns on failure.
|
inlineconstexpr |
The number of tag slots. A tag value at or above it is not valid.