class SharedMemory

Defined at line 43 of file ../../src/sys/fuzzing/common/shared-memory.h

This class can be used to share VMOs mapped into multiple processes.

For example, to share a fixed length data, one process may create an object using:

SharedMemory sender;

sender.Mirror(data, size);

To share variable-length data, |Mirror| can be replaced with |Reserve|, e.g.:

SharedMemory sender;

sender.Reserve(capacity);

In either case, the process can created a shared VMO from the object:

zx::vmo vmo;

sender.Share(

&vmo

);

It can then send it to another process via FIDL, which can link it:

SharedMemory receiver;

receiver.Link(std::move(vmo));

At this point, the sender can |Update| the fixed length data, or |Write| to the variable length

data. In the latter case, the receiver needs to |Read| before accessing the data with |data| and

|size|. Reading and writing this size is not guaranteed to be atomic, so callers should use some

other method to coordinate when the size changes, e.g. with an |AsyncEventPair|.

Public Methods

SharedMemory & operator= (SharedMemory && other)

Defined at line 26 of file ../../src/sys/fuzzing/common/shared-memory.cc

void ~SharedMemory ()

Public methods

Defined at line 24 of file ../../src/sys/fuzzing/common/shared-memory.cc

zx_status_t Reserve (size_t capacity)

Resets this object, then creates a VMO of at least |capacity| bytes, maps it. The size of the

shared memory is recorded in the buffer itself, making it compatible with |Resize| and |Write|.

Defined at line 37 of file ../../src/sys/fuzzing/common/shared-memory.cc

zx_status_t Mirror (void * data, size_t size)

Resets and configures the object so subsequent calls to |Update| copy the region of memory

described by |data| and |size|. This region of memory MUST remain valid until this object is

destroyed or reset. The primary use of this method is to share compiler-provided

instrumentation across processes.

Defined at line 44 of file ../../src/sys/fuzzing/common/shared-memory.cc

void SharedMemory ()

Defined at line 45 of file ../../src/sys/fuzzing/common/shared-memory.h

void SharedMemory (SharedMemory && other)

Defined at line 46 of file ../../src/sys/fuzzing/common/shared-memory.h

uint8_t * data ()

Defined at line 50 of file ../../src/sys/fuzzing/common/shared-memory.h

size_t size ()

Defined at line 51 of file ../../src/sys/fuzzing/common/shared-memory.h

size_t capacity ()

Defined at line 52 of file ../../src/sys/fuzzing/common/shared-memory.h

zx_status_t Share (zx::vmo * out)

Returns a buffer containing a duplicate of the VMO backing this memory region via |out|,

suitable for sending to another process. The size is written to the ZX_PROP_VMO_CONTENT_SIZE

property of the VMO, as in |fuchsia.debugdata.Publisher|.

Defined at line 60 of file ../../src/sys/fuzzing/common/shared-memory.cc

zx_status_t Link (zx::vmo vmo)

Resets this object, then takes ownership of the |vmo| and maps it. The VMO must have been

|Share|d from an object that was |Reserve|d or |Mirror|ed.

Defined at line 68 of file ../../src/sys/fuzzing/common/shared-memory.cc

zx_status_t Read ()

Refreshes the valid region of the mapped memory. Callers should use this method before calling

|size()|.

Defined at line 80 of file ../../src/sys/fuzzing/common/shared-memory.cc

zx_status_t Write (const void * data, size_t size)

Replaces the contents of the VMO with the given |data|.

Defined at line 92 of file ../../src/sys/fuzzing/common/shared-memory.cc

void Update ()

Copies data from the mirrored memory region into this object. Must only be called on an object

that was |Mirror|ed.

Defined at line 108 of file ../../src/sys/fuzzing/common/shared-memory.cc

void Clear ()

Zeros the |Mirror|ed memory, if any.

Defined at line 113 of file ../../src/sys/fuzzing/common/shared-memory.cc