Talvos
0.1
SPIR-V interpreter and dynamic analysis framework
|
This class represents an address space in the virtual device. More...
#include <talvos/Memory.h>
Classes | |
struct | Buffer |
An allocation within this memory instance. More... | |
Public Member Functions | |
Memory (Device &D, MemoryScope Scope) | |
Create a new Memory instance. More... | |
~Memory () | |
uint64_t | allocate (uint64_t NumBytes) |
Allocate a new buffer of size NumBytes . More... | |
template<typename T > | |
T | atomic (uint64_t Address, uint32_t Opcode, uint32_t Scope, uint32_t Semantics, T Value=0) |
Atomically apply operation defined by Opcode to Address . More... | |
uint32_t | atomicCmpXchg (uint64_t Address, uint32_t Scope, uint32_t EqualSemantics, uint32_t UnequalSemantics, uint32_t Value, uint32_t Comparator) |
Perform an atomic compare-exchange operation at Address . More... | |
void | dump () const |
Dump the entire contents of this memory to stdout. More... | |
void | dump (uint64_t Address) const |
Dump the contents of the buffer with base address Address to stdout. More... | |
MemoryScope | getScope () const |
Get the scope of this memory instance. More... | |
void | load (uint8_t *Result, uint64_t Address, uint64_t NumBytes) const |
Load NumBytes of data from Address into Result . More... | |
uint8_t * | map (uint64_t Base, uint64_t Offset, uint64_t NumBytes) |
Map a region of memory and return a pointer to it. More... | |
void | release (uint64_t Address) |
Release the allocation with base address Address . More... | |
void | store (uint64_t Address, uint64_t NumBytes, const uint8_t *Data) |
Store NumBytes of data from Data to Address . More... | |
void | unmap (uint64_t Base) |
Unmap a previously mapped region of memory. More... | |
Memory (const Memory &)=delete | |
Memory & | operator= (const Memory &)=delete |
Static Public Member Functions | |
static void | copy (uint64_t DstAddress, Memory &DstMem, uint64_t SrcAddress, const Memory &SrcMem, uint64_t NumBytes) |
Copy data between memory instances. More... | |
static const char * | scopeToString (MemoryScope Scope) |
Returns the string representation of Scope . More... | |
Private Member Functions | |
bool | isAccessValid (uint64_t Address, uint64_t NumBytes) const |
Check whether an access resides in an allocated region of memory. More... | |
Private Attributes | |
Device & | Dev |
The device this memory instance is part of. More... | |
MemoryScope | Scope |
The scope of this memory instance. More... | |
std::mutex | Mutex |
Mutex for guarding allocate/release operations. More... | |
std::mutex | AtomicMutexes [NUM_ATOMIC_MUTEXES] |
Set of mutexes for synchronizing atomic operations. More... | |
std::vector< Buffer > | Buffers |
List of allocations. More... | |
std::vector< uint64_t > | FreeBuffers |
Base addresses available for reuse. More... | |
Static Private Attributes | |
static const uint32_t | NUM_ATOMIC_MUTEXES = 100 |
Number of mutexes to use for synchronizing atomic operations. More... | |
This class represents an address space in the virtual device.
This class provides methods to allocate and release buffers and access their data. A virtual addressing scheme is used for memory addresses. Base addresses for buffers are unique within an instance of this class, but not across separate instances. It is therefore the responsibility of the caller to route load/store calls to the correct Memory object.
talvos::Memory::Memory | ( | Device & | D, |
MemoryScope | Scope | ||
) |
Create a new Memory instance.
Definition at line 39 of file Memory.cpp.
talvos::Memory::~Memory | ( | ) |
Definition at line 45 of file Memory.cpp.
|
delete |
uint64_t talvos::Memory::allocate | ( | uint64_t | NumBytes | ) |
Allocate a new buffer of size NumBytes
.
Definition at line 52 of file Memory.cpp.
template int32_t talvos::Memory::atomic | ( | uint64_t | Address, |
uint32_t | Opcode, | ||
uint32_t | Scope, | ||
uint32_t | Semantics, | ||
T | Value = 0 |
||
) |
Atomically apply operation defined by Opcode
to Address
.
Definition at line 81 of file Memory.cpp.
uint32_t talvos::Memory::atomicCmpXchg | ( | uint64_t | Address, |
uint32_t | Scope, | ||
uint32_t | EqualSemantics, | ||
uint32_t | UnequalSemantics, | ||
uint32_t | Value, | ||
uint32_t | Comparator | ||
) |
Perform an atomic compare-exchange operation at Address
.
Definition at line 156 of file Memory.cpp.
|
static |
Copy data between memory instances.
DstMem
and SrcMem
can be the same memory instance.
Definition at line 328 of file Memory.cpp.
void talvos::Memory::dump | ( | ) | const |
Dump the entire contents of this memory to stdout.
Definition at line 202 of file Memory.cpp.
void talvos::Memory::dump | ( | uint64_t | Address | ) | const |
Dump the contents of the buffer with base address Address
to stdout.
Definition at line 211 of file Memory.cpp.
|
inline |
|
private |
Check whether an access resides in an allocated region of memory.
Definition at line 236 of file Memory.cpp.
void talvos::Memory::load | ( | uint8_t * | Result, |
uint64_t | Address, | ||
uint64_t | NumBytes | ||
) | const |
Load NumBytes
of data from Address
into Result
.
Definition at line 249 of file Memory.cpp.
uint8_t * talvos::Memory::map | ( | uint64_t | Base, |
uint64_t | Offset, | ||
uint64_t | NumBytes | ||
) |
Map a region of memory and return a pointer to it.
Definition at line 273 of file Memory.cpp.
void talvos::Memory::release | ( | uint64_t | Address | ) |
Release the allocation with base address Address
.
Definition at line 292 of file Memory.cpp.
|
inlinestatic |
void talvos::Memory::store | ( | uint64_t | Address, |
uint64_t | NumBytes, | ||
const uint8_t * | Data | ||
) |
Store NumBytes
of data from Data
to Address
.
Definition at line 306 of file Memory.cpp.
void talvos::Memory::unmap | ( | uint64_t | Base | ) |
Unmap a previously mapped region of memory.
Definition at line 326 of file Memory.cpp.
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |