public ExvokerImpl(object o, DelegateStorage d, ICallingConventionAdapter a) { foreach (var sdt in d.DelegateTypes) { var del = Delegate.CreateDelegate(sdt.DelegateType, o, sdt.Method); Delegates.Add(del); // prevent garbage collection of the delegate, which would invalidate the pointer EntryPoints.Add(sdt.EntryPointName, a.GetFunctionPointerForDelegate(del)); } }
public object Create(IImportResolver dll, IMonitor monitor, ICallingConventionAdapter adapter) { var ret = Activator.CreateInstance(ImplType); ConnectCallingConventionAdapter(ret, adapter); foreach (var f in Hooks) { f(ret, dll, adapter); } ConnectMonitor?.Invoke(ret, monitor); return(ret); }
public static IImportResolver GetExvoker(object o, ICallingConventionAdapter a) { DelegateStorage ds; lock (Impls) { var type = o.GetType(); if (!Impls.TryGetValue(type, out ds)) { ds = new DelegateStorage(type); Impls.Add(type, ds); } } return(new ExvokerImpl(o, ds, a)); }
public static T GetInvoker <T>(IImportResolver dll, IMonitor monitor, ICallingConventionAdapter adapter) where T : class { InvokerImpl impl; lock (Impls) { var baseType = typeof(T); if (!Impls.TryGetValue(baseType, out impl)) { impl = CreateProxy(baseType, true); Impls.Add(baseType, impl); } } if (impl.ConnectMonitor == null) { throw new InvalidOperationException("Class was previously proxied without a monitor!"); } return((T)impl.Create(dll, monitor, adapter)); }
/// <exception cref="InvalidOperationException">this method was previously called with <paramref name="dll"/></exception> public static T GetInvoker <T>(IImportResolver dll, IMonitor monitor, ICallingConventionAdapter adapter) where T : class { var nonTrivialAdapter = adapter.GetType() != CallingConventionAdapters.Native.GetType(); InvokerImpl?impl; lock (Impls) { var baseType = typeof(T); if (!Impls.TryGetValue(baseType, out impl)) { impl = CreateProxy(baseType, true, nonTrivialAdapter); Impls.Add(baseType, impl !); } } if (!(impl !.IsMonitored)) { throw new InvalidOperationException("Class was previously proxied without a monitor!"); } return((T)impl.Create(dll, monitor, adapter)); }
public static T GetDelegateForFunctionPointer <T>(this ICallingConventionAdapter a, IntPtr p) where T : class { return((T)(object)a.GetDelegateForFunctionPointer(p, typeof(T))); }
static WaterboxAdapter() { WaterboxWrapper = OSTailoredCode.IsUnixHost ? new NativeConvention() : (ICallingConventionAdapter) new MsHostSysVGuest(); }
public static T GetDelegateForFunctionPointer <T>(this ICallingConventionAdapter a, IntPtr p) where T : Delegate => (T)a.GetDelegateForFunctionPointer(p, typeof(T));