remotemono
Public Types | Public Member Functions | Protected Attributes | List of all members
remotemono::RMonoAPIFunctionWrapBase< CommonT, ABI, RetT, ArgsT > Class Template Reference

#include <RMonoAPIFunctionWrap_Def.h>

Inheritance diagram for remotemono::RMonoAPIFunctionWrapBase< CommonT, ABI, RetT, ArgsT >:
Inheritance graph
[legend]
Collaboration diagram for remotemono::RMonoAPIFunctionWrapBase< CommonT, ABI, RetT, ArgsT >:
Collaboration graph
[legend]

Public Types

typedef RetT WrapRetType
 
typedef std::tuple< ArgsT... > WrapArgsTuple
 
typedef RMonoAPIFunctionSimple< RetT, ArgsT... > WrapFunc
 

Public Member Functions

void linkWrap (blackbone::ptr_t wrapFuncAddr)
 
RetT invokeWrap (ArgsT... args)
 
blackbone::ptr_t getWrapFuncAddress () const
 

Protected Attributes

WrapFunc wrapFunc
 

Additional Inherited Members

- Protected Types inherited from remotemono::RMonoAPIFunctionCommon< ABI >
enum  ParamFlags {
  ParamFlagMonoObjectPtr = 0x0001, ParamFlagOut = 0x0002, ParamFlagDirectPtr = 0x0004, ParamFlagDisableAutoUnbox = 0x0008,
  ParamFlagLastArrayElement = 0x8000
}
 
typedef uint16_t variantflags_t
 

Detailed Description

template<class CommonT, typename ABI, typename RetT, typename... ArgsT>
class remotemono::RMonoAPIFunctionWrapBase< CommonT, ABI, RetT, ArgsT >

A component of RMonoAPIFunction, this class provides the wrapper functions around a raw Mono API function. Wrapper functions are generated at runtime using AsmJit and then injected into the remote process (just copied over into executable memory).

Wrapper functions are necessary for many Mono API functions for the following reasons:

  1. For MonoObject* parameters, we pass GC handles instead of raw pointers. To be GC-safe, we only convert the GC handles back to raw pointers in the remote process, and this conversion (and the one in the opposite direction) is what these wrapper functions do. We must do it in the remote process because the Mono GC is only guaranteed not to move the memory around randomly as long as a raw pointer to that memory is either in a CPU register or on the stack of a Mono-attached thread in the remote process.
  2. Some other parameter types can be more easily and/or efficiently handled if we can do a few more things before or after the actual API call, like calculating the length of a returned string.

This class contains code to generate general wrapper functions depending on the signature of the Mono API function. To do this, it makes heavy use of template metaprogramming and it requires certain additional information about parameter types to be encoded into the function signature (this is what the tag classes like ParamOut<> or ReturnOwn<> are for). This class is also heavily tied to the implementation of RMonoAPIFunctionAPI, which is responsible for building the specific parameters and the data block required by the generated wrappers.

Note that not every Mono API function will need (or have) a wrapper function. For example, functions that only handle fundamental data types and/or pointers to non-managed resources will often not have a wrapper. For those functions, RemoteMono will just call the raw function.

See also
RMonoAPIFunctionAPIBase

The documentation for this class was generated from the following file: