Example #1
0
 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));
     }
 }
Example #2
0
            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);
            }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #5
0
        /// <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));