template <typename Backing>
class VmoStore
Defined at line 120 of file ../../src/lib/vmo_store/vmo_store.h
A data structure that keeps track of registered VMOs using a `Backing` storage type.
`VmoStore` keeps track of registered VMOs and performs common mapping and pinning operations,
providing common operations used in VMO pre-registration on Banjo and FIDL APIs.
This structure is not thread-safe. Users must provide their own thread-safety accounting for the
chosen `Backing` format.
`Backing` is the data structure used to store the registered VMOs. It must implement
`AbstractStorage`.
Example usage:
```
using namespace vmo_store;
// Declaring our types first.
// `MyKey` is the key type that is used to register and retrieve VMOs from a VmoStore.
using MyKey = size_t;
// `MyMeta` is extra user metadata associated with every stored VMO (can be `void`).
using MyMeta = std::string;
// Declare our store alias, we're using `HashTableStorage` in this example.
// See `storage_types.h` for other Backing storage types.
using MyVmoStore = VmoStore
<HashTableStorage
<MyKey
, MyMeta>>;
MyVmoStore store(Options{...});
// Now let's register, retrieve, and unregister a `zx::vmo` obtained through `GetVmo()`.
// The second argument to `Register` is our user metadata.
zx::result
<size
_t> result = store.Register(GetVmo(), "my first VMO");
size_t key = result.take_value();
auto * my_registered_vmo = store.GetVmo(key);
// Print metadata associated with VMO.
std::cout
<
<
"Got Vmo called "
<
<
my_registered_vmo->meta()
<
<
std::endl;
// see `stored_vmo.h` for other `StoredVmo` methods, like retrieving mapped or pinned memory.
// Finally, unregister the VMO, which will discard the VMO handle along with any mapping or
// pinning.
store.Unregister(key);
```
See `OwnedVmoStore` for an alternative API where registration happens through an ownership agent.
Public Methods
template <typename... StoreArgs>
void VmoStore<Backing> (Options options, StoreArgs... store_args)
Defined at line 131 of file ../../src/lib/vmo_store/vmo_store.h
template <typename... MetaArgs>
zx::result<Key> Register (zx::vmo vmo, MetaArgs... vmo_args)
Registers a VMO with this store, returning the key used to access that VMO on success.
Defined at line 137 of file ../../src/lib/vmo_store/vmo_store.h
zx::result<Key> Register (StoredVmo vmo)
Defined at line 141 of file ../../src/lib/vmo_store/vmo_store.h
template <typename... MetaArgs>
zx_status_t RegisterWithKey (Key key, zx::vmo vmo, MetaArgs... vmo_args)
Registers a VMO with this store using the provided `key`.
Defined at line 155 of file ../../src/lib/vmo_store/vmo_store.h
zx_status_t RegisterWithKey (Key key, StoredVmo vmo)
Defined at line 160 of file ../../src/lib/vmo_store/vmo_store.h
zx::result<zx::vmo> Unregister (Key key)
Unregisters the VMO at `key`.
All the mapping and pinning handles will be dropped, and the VMO will be
returned to the caller.
Returns `ZX_ERR_NOT_FOUND` if `key` does not point to a registered VMO.
Defined at line 172 of file ../../src/lib/vmo_store/vmo_store.h
StoredVmo * GetVmo (const Key & key)
Gets an _unowned_ pointer to the `StoredVmo` referenced by `key`.
Returns `nullptr` if `key` does not point to a register VMO.
Defined at line 182 of file ../../src/lib/vmo_store/vmo_store.h
void VmoStore<Backing> (const VmoStore<Backing> & )
Defined at line 184 of file ../../src/lib/vmo_store/vmo_store.h
VmoStore<Backing> & operator= (const VmoStore<Backing> & )
Defined at line 184 of file ../../src/lib/vmo_store/vmo_store.h