template <typename Object>

class Accessor

Defined at line 44 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

Provides access to a single object of type |Object|.

Use |PageMap::MakeAccessor| to create an Accessor.

Accessors can be used in two ways Read/Write and raw.

The Read() and Write() methods provide TOCTOU-safe access to an object or its fields by copying

to/from the object (or fields) fields and then issuing a compiler barrier to prevent copy

elision.

The raw() method provides direct access to the object or its fields. Because raw() provides no

compiler barrier, its use can be susceptible to TOCTOU. Use with caution. Prefer to use

Read()/Write() whenever possible. See also |BarrierAfterCopyTo|.

Instances of Accessor are not safe for concurrent use (i.e. not thread-safe).

Public Methods

void Accessor<Object> ()

Construct a invalid Accessor. See |PageMap::MakeAccessor|

Defined at line 49 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

bool IsValid ()

Returns true if this instance is valid.

Invalid instances are akin to null pointers. Only valid instances may be read/written.

Defined at line 58 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

void Accessor<Object> (const Accessor<Object> & )

Defined at line 65 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

Accessor<Object> & operator= (const Accessor<Object> & )

Defined at line 66 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

template <typename T>
void BarrierAfterCopyTo (T * dst)

A compiler barrier used to prevent copy elision induced TOCTOU.

This is intended for use *after* copying to |*dst|, but *before* validating the copy. It is

designed to prevent TOCTOU in the case where the compiler might otherwise elide the copy.

By telling the compiler that this volatile assembly statement uses the object-in-memory pointed

to by dst as both output and input, we ensure the compiler:

- cannot optimize-away a preceding copy to |*dst|

- cannot reorder a validation of |*dst| occurring after the barrier with a use of |*dst|

preceding the barrier.

Defined at line 115 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

Object & raw ()

Provides direct access to the underlying object when Read()/Write() won't cut it.

Prefer to use Read()/Write() instead.

It is a programming error to call this on an instance that isn't |IsValid()|.

WARNING: This provides no TOCTOU protection. You must issue an appropriate compiler barrier

yourself. See |BarrierAfterCopyTo|. Do not use this if you are not familiar with TOCTOU and

copy elision.

Defined at line 128 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

void ~Accessor<Object> ()

Because a mapping may be destroyed upon the destruction of the last Accessor that references

it, this may only be called from thread context, where it's safe to acquire VM locks.

Defined at line 174 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

void Accessor<Object> (Accessor<Object> && other)

Accessor is a move-only type.

The source of a move operation will be invalidated.

Defined at line 179 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

Accessor<Object> & operator= (Accessor<Object> && other)

Defined at line 184 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

void Read (Object & dst)

Read (copy) the object from the VMO into |dst|.

It is an error to call this on an invalid instance.

Defined at line 194 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

void Write (const Object & src)

Write (copy) |src| to the object.

It is an error to call this on an invalid instance.

Defined at line 208 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

template <auto Field, typename FieldType = decltype(Field)>
void Read (FieldType & dst_field)

Like Read, but for reading only one field of an object.

FieldType is a pointer-to-member. E.g.

struct Aggregate { int field1; int field2; };

Accessor a = ...;

int f1;

a.Read

<

&Aggregate

::field1>(f1);

Defined at line 200 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

template <auto Field, typename FieldType = decltype(Field)>
void Write (const FieldType & src_field)

Like Write, but for writing only one field of an object.

FieldType is a pointer-to-member. E.g.

struct Aggregate { int field1; int field2; };

Accessor a = ...;

int f1 = 42;

a.Write

<

&Aggregate

::field1>(f1);

Defined at line 214 of file ../../zircon/kernel/lib/page-map/include/lib/page-map/accessor.h

Records

Friends

template <typename Object>
class PageMap