|
| RMonoVariant () |
|
| RMonoVariant (const Self &other) |
|
template<typename T , typename Enable = std::enable_if_t<!std::is_base_of_v<MonoObjectPtrWrapper, T>>> |
| RMonoVariant (T val) |
|
template<typename T > |
| RMonoVariant (T *val) |
|
| RMonoVariant (void *data, size_t size, bool copy=false) |
|
| RMonoVariant (const RMonoObjectPtr &v, bool autoUnbox=true) |
|
| RMonoVariant (RMonoObjectPtr &&v, bool autoUnbox=true) |
|
| RMonoVariant (RMonoObjectPtr *v, bool autoUnbox=true) |
|
| RMonoVariant (const MonoObjectPtrWrapper &v, bool autoUnbox=true) |
|
| RMonoVariant (std::nullptr_t) |
|
| RMonoVariant (rmono_voidp v, RawPtr) |
|
| RMonoVariant (rmono_voidp *v, RawPtr) |
|
Self & | operator= (const Self &other) |
|
Self | forDirection (Direction dir) const |
|
Self | in () const |
|
Self | out () const |
|
Self | inout () const |
|
bool | isValid () const |
|
Type | getType () const |
|
Direction | getDirection () const |
|
void | setDirection (Direction dir) |
|
void | setAutoUnboxEnabled (bool autoUnbox) |
|
bool | isAutoUnboxEnabled () const |
|
bool | isNullPointer () const |
|
size_t | getValueSize () const |
|
void * | getValueData () |
|
const void * | getValueData () const |
|
template<typename T > |
T | getValue () const |
|
RMonoObjectPtr | getMonoObjectPtr () const |
|
rmono_voidp | getRawPtr () const |
|
template<typename ABI > |
size_t | getRemoteMemorySize (ABI &abi, size_t &alignment) const |
|
template<typename ABI > |
void | copyForRemoteMemory (ABI &abi, void *buf) const |
|
template<typename ABI > |
void | updateFromRemoteMemory (ABI &abi, RMonoAPIBase &mono, void *buf) |
|
A special class that can encapsulate any instance of a Mono/.NET reference or value type. This means it can hold any of the following:
- A value of a built-in type like
int
, short
, float
, char
, bool
etc.
- An instance of a custom value type (in C# terms: an instance of a struct derived from System.ValueType).
- An instance of a reference type, i.e. a MonoObject* (in C# terms: an object of a class derived from System.Object).
This type is mostly used in certain places where the raw Mono API has a void*
parameter or return value referring to a managed value, e.g. the value in mono_field_set_value()
or mono_object_unbox()
. It is also used in functions like mono_runtime_invoke()
for the method parameters (as an element of a RMonoVariantArray).
We use object of this class instead of simple void*
values for multiple reasons:
- It contains info about what kind of type is stored in it (value type, reference type or raw pointer). This is useful e.g. for reference types (i.e. MonoObject*): Here we keep
rmono_gchandle
s instead of the raw pointers to be on the safe side of the Mono GC. Because we don't want to pin the GC handles, we must actually pass the GC handle itself to the remote process and convert back to the raw pointer just-in-time. To do this, RemoteMono's generated wrapper functions need to know if the value it receives is such a GC handle or not.
- For value types, it stores them together with info about their size. We need that when copying the values to and from remote memory.
- It contains additional metadata necessary for calling certain Mono API functions. E.g. for mono_runtime_invoke(), we need to know if each parameter is an input, output, or both. That's because mono_runtime_invoke() needs parameters (specifically reference types) to be passed differently depending on this directionality. This class can provide this information (see forDirection()).
This documentation may reference C# types, but it is not actually specific to C# remotes.
Direction of the value contained in the variant.
This is only useful when calling Mono API functions whose parameters are not always of a fixed directionality. One such example is mono_runtime_invoke(), where the directionality of each parameter depends on how the method was defined (e.g. in C# whether the out
or ref
modifiers were used for a parameter). In this case, you must specify the direction if it differs from the default (see the parameter tags in the function definition in RMonoAPIBackend).
For example: For mono_runtime_invoke(), you must pass out-params (C# out
) and inout-params (C# ref
) using DirectionOut and DirectionInOut, respectively. Not doing so (even if you don't care about the result of an out-param) will lead to crashes.
- See also
- forDirection()
-
in()
-
out()
-
inout()
Enumerator |
---|
DirectionDefault | Direction not specified.
This is the default for all variants and means that the variant uses the direction that is the default for whatever Mono API function it's used in.
|
DirectionIn | Input direction (local value is passed to remote Mono API function, but is not read back).
|
DirectionOut | Output direction (undefined value is passed to remote Mono API function, but the new value after the call is read back).
|
DirectionInOut | Both directions.
|
template<typename T , typename Enable = std::enable_if_t<!std::is_base_of_v<MonoObjectPtrWrapper, T>>>
remotemono::RMonoVariant::RMonoVariant |
( |
T |
val | ) |
|
|
inline |
Creates an object of a value type.
This is equivalent to calling RMonoVariant(&val, sizeof(T), true)
, i.e. it copies the data.
- Parameters
-
- See also
- RMonoVariant(void*, size_t, bool)
remotemono::RMonoVariant::RMonoVariant |
( |
void * |
data, |
|
|
size_t |
size, |
|
|
bool |
copy = false |
|
) |
| |
|
inline |
Creates an object of a value type from a buffer.
Can be used for two purposes:
- For C# built-in value types (e.g. int, float, byte), in which case you can just pass a pointer to a variable of the corresponding C++ type (e.g. int32_t, float, uint8_t).
- For any custom value types, in which case you can pass a pointer to the equivalent C++ struct (be aware of alignment and other details), or to a raw buffer that you received from another Mono API call.
The data can either be copied into the variant object itself, or the object can simply store a pointer to the user-supplied memory. In the latter case, the user has to ensure that the data remains valid for as long as the RMonoVariant object is used. Storing a direct pointer can be useful for getting output values into user-supplied variables without unnecessary copying.
If the variant is used for an output-only value, you can also pass a pointer to uninitialized memory, as long as the memory is large enough to hold the expected value type.
- Parameters
-
data | Pointer to the value type object's data. May be NULL, in which case a raw NULL pointer will be passed to the Mono API. |
size | Size of the value type object's data in bytes. |
copy | true if the object should make a copy of the data, false if it should store the pointer directly. |
remotemono::RMonoVariant::RMonoVariant |
( |
rmono_voidp * |
v, |
|
|
RawPtr |
|
|
) |
| |
|
inlineexplicit |
Creates a variant that represents a raw pointer in remote memory. The pointer is passed directly to any Mono API functions. The caller must ensure that it is valid in the context of the remote process.
This version of the constructor takes a pointer to the raw remote pointer, and can be used to receive raw pointers returned from a Mono API function.
Use RMonoVariant::rawPtr for the second parameter. It is just a constructor overload disambiguation tag.
- Parameters
-
v | Pointer to the raw pointer in remote memory. |