vrtd::BarFile

class BarFile

Owning RAII handle for a mapped BAR region.

Encapsulates a slash_bar_file containing the BAR mapping (map) and length (len). Provides typed access via getPtr<T>() which brackets memory access with the appropriate slash_bar_file_start_* / slash_bar_file_end_* calls. Direct raw access is available via getRawPtr(), 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 BarFile instance. Concurrent calls to getPtr() / getRawPtr() on the same object are not allowed.

Public Types

enum class Direction

Direction of an access session.

Values:

enumerator Read
enumerator Write

Public Functions

~BarFile()

Destructor.

Releases the mapping and FD if still open.

Warning

If a memory operation is still in progress (i.e., a live BarFilePtr returned by getPtr() has not been destroyed), the destructor may throw (e.g., to signal improper usage). Users must ensure all BarFilePtr instances are destroyed before destroying or closing the BarFile.

BarFile(BarFile&&) noexcept

Move constructor; transfers ownership and closes the source.

BarFile &operator=(BarFile&&) noexcept

Move assignment; closes current, then takes ownership.

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() or slash_bar_file_start_write() / _end_write() as appropriate. Prefer getPtr<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 address is out of range.

Returns:

volatile void* pointing at address inside 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 BarFilePtr is 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-only BarFilePtr<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 volatile pointers to model device memory semantics.

Parameters:
  • direction – Whether this is a read or write operation.

  • address – Byte offset into the mapping where T is addressed.

Throws:

std::runtime_error – if:

  • the file is closed,

  • address is out of range,

  • another read/write operation is already in progress,

  • direction is invalid.

Returns:

BarFilePtr<T> owning the access session.