vrtd::BarFile
-
class BarFile
Owning RAII handle for a mapped BAR region.
Encapsulates a
slash_bar_filecontaining the BAR mapping (map) and length (len). Provides typed access viagetPtr<T>()which brackets memory access with the appropriateslash_bar_file_start_*/slash_bar_file_end_*calls. Direct raw access is available viagetRawPtr(), but requires manual bracketing.Note
Move-only; copying is disabled. The moved-from object is closed.
Warning
Not thread-safe. At most one memory operation (read or write) may be active at a time per
BarFileinstance. Concurrent calls togetPtr()/getRawPtr()on the same object are not allowed.Public Types
Public Functions
-
~BarFile()
Destructor.
Releases the mapping and FD if still open.
-
size_t getLen() const noexcept
Size of the mapped BAR in bytes.
-
volatile void *getRawPtr(size_t address = 0) const noexcept
Get a raw volatile pointer into the mapping.
Warning
Using the raw pointer requires the caller to manually bracket accesses with
slash_bar_file_start_read()/_end_read()orslash_bar_file_start_write()/_end_write()as appropriate. PrefergetPtr<T>()for RAII-safe access.- Parameters:
address – Byte offset from the start of the mapping (default 0).
- Throws:
std::runtime_error – if the file is closed or
addressis out of range.- Returns:
volatilevoid* pointing ataddressinside the mapping.
-
void close()
Close the mapping and underlying FD.
After a successful close,
isClosed()returns true and further operations will throw.Warning
Not idempotent/noexcept by design: if a memory operation is still in progress (i.e., a
BarFilePtris alive), this function may throw to signal misuse.
-
bool isClosed() const noexcept
Whether the BAR has been closed.
-
template<class T>
inline BarFilePtr<T> getPtr(Direction direction, size_t address = 0) Acquire a typed RAII pointer into the BAR mapping.
Starts a read or write session (depending on
direction) and returns a move-onlyBarFilePtr<T>that will automatically end the session on destruction. Only one operation (read or write) may be active at a time.Warning
The caller is responsible for alignment correctness.
- Template Parameters:
T – Element type. Must be an object type; recommended to be trivially copyable/standard-layout. Accesses are through
volatilepointers to model device memory semantics.- Parameters:
direction – Whether this is a read or write operation.
address – Byte offset into the mapping where
Tis addressed.
- Throws:
std::runtime_error – if:
the file is closed,
addressis out of range,another read/write operation is already in progress,
directionis invalid.
- Returns:
BarFilePtr<T>owning the access session.
-
~BarFile()