예제 #1
0
        internal static T LookupInternalFunction <T> (string name) where T : class
        {
            IntPtr rv;

            if (runtime_library == IntPtr.Zero)
            {
                runtime_library = new IntPtr(-2 /* RTLD_DEFAULT */);
                rv = Dlfcn.dlsym(runtime_library, name);
                if (rv == IntPtr.Zero)
                {
                    runtime_library = Dlfcn.dlopen("libxammac.dylib", 0);
                    if (runtime_library == IntPtr.Zero)
                    {
                        runtime_library = Dlfcn.dlopen(Path.Combine(Path.GetDirectoryName(typeof(NSApplication).Assembly.Location), "libxammac.dylib"), 0);
                    }
                    if (runtime_library == IntPtr.Zero)
                    {
                        throw new DllNotFoundException("Could not find the runtime library libxammac.dylib");
                    }
                    rv = Dlfcn.dlsym(runtime_library, name);
                }
            }
            else
            {
                rv = Dlfcn.dlsym(runtime_library, name);
            }
            if (rv == IntPtr.Zero)
            {
                throw new EntryPointNotFoundException(string.Format("Could not find the runtime method '{0}'", name));
            }
            return((T)(object)Marshal.GetDelegateForFunctionPointer(rv, typeof(T)));
        }
예제 #2
0
        internal static T LookupInternalFunction <T> (string name) where T : class
        {
            IntPtr rv;

            if (runtime_library == IntPtr.Zero)
            {
                runtime_library = new IntPtr(-5 /* RTLD_MAIN_ONLY */);
                rv = Dlfcn.dlsym(runtime_library, name);
                if (rv == IntPtr.Zero)
                {
                    runtime_library = Dlfcn.dlopen("libxammac.dylib", 0);
                    if (runtime_library == IntPtr.Zero)
                    {
                        throw new DllNotFoundException("Could not find the runtime library libxammac.dylib");
                    }
                    rv = Dlfcn.dlsym(runtime_library, name);
                }
            }
            else
            {
                rv = Dlfcn.dlsym(runtime_library, name);
            }
            if (rv == IntPtr.Zero)
            {
                throw new EntryPointNotFoundException(string.Format("Could not find the runtime method '{0}'", name));
            }
            return((T)(object)Marshal.GetDelegateForFunctionPointer(rv, typeof(T)));
        }
예제 #3
0
 public static unsafe IntPtr CachePointer(IntPtr handle, string constant, IntPtr *storage)
 {
     if (*storage == IntPtr.Zero)
     {
         *storage = Dlfcn.GetIntPtr(handle, constant);
     }
     return(*storage);
 }