Пример #1
0
        public void Fields()
        {
            // fields are not available in iOS (at least up to 5.1.1)
            // this test will fail if this ever change in the future
            IntPtr lib = Dlfcn.dlopen(Constants.FoundationLibrary, 0);

            try {
                Assert.That(Dlfcn.dlsym(lib, "NSFontAttributeName"), Is.EqualTo(IntPtr.Zero), "NSFontAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSLinkAttributeName"), Is.EqualTo(IntPtr.Zero), "NSLinkAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSUnderlineStyleAttributeName"), Is.EqualTo(IntPtr.Zero), "NSUnderlineStyleAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSStrikethroughStyleAttributeName"), Is.EqualTo(IntPtr.Zero), "NSStrikethroughStyleAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSStrokeWidthAttributeName"), Is.EqualTo(IntPtr.Zero), "NSStrokeWidthAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSParagraphStyleAttributeName"), Is.EqualTo(IntPtr.Zero), "NSParagraphStyleAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSForegroundColorAttributeName"), Is.EqualTo(IntPtr.Zero), "NSForegroundColorAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSBackgroundColorAttributeName"), Is.EqualTo(IntPtr.Zero), "NSBackgroundColorAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSLigatureAttributeName"), Is.EqualTo(IntPtr.Zero), "NSLigatureAttributeName");
                Assert.That(Dlfcn.dlsym(lib, "NSObliquenessAttributeName"), Is.EqualTo(IntPtr.Zero), "NSObliquenessAttributeName");
            }
            finally {
                Dlfcn.dlclose(lib);
            }
        }
Пример #2
0
        static CMTimeRange()
        {
            var lib     = Libraries.CoreMedia.Handle;
            var retZero = Dlfcn.dlsym(lib, "kCMTimeRangeZero");

            Zero = (CMTimeRange)Marshal.PtrToStructure(retZero, typeof(CMTimeRange));

            var retInvalid = Dlfcn.dlsym(lib, "kCMTimeRangeInvalid");

#if !XAMCORE_3_0
            Invalid = (CMTimeRange)Marshal.PtrToStructure(retInvalid, typeof(CMTimeRange));
#endif
            InvalidRange = (CMTimeRange)Marshal.PtrToStructure(retInvalid, typeof(CMTimeRange));

            var retMappingInvalid = Dlfcn.dlsym(lib, "kCMTimeMappingInvalid");
            if (retMappingInvalid != IntPtr.Zero)
            {
                InvalidMapping = (CMTimeRange)Marshal.PtrToStructure(retMappingInvalid, typeof(CMTimeRange));
            }

            TimeMappingSourceKey = Dlfcn.GetStringConstant(lib, "kCMTimeMappingSourceKey");
            TimeMappingTargetKey = Dlfcn.GetStringConstant(lib, "kCMTimeMappingTargetKey");
        }
Пример #3
0
        public void Fields()
        {
            // documented as new in iOS 5.0 - https://developer.apple.com/library/ios/DOCUMENTATION/CoreLocation/Reference/CoreLocationConstantsRef/CoreLocationConstantsRef.pdf
            // in PDF only, not in the HTML documentation - but it's also inside CLError.h
            // this test will fail if Apple decide to include them in the future
            IntPtr lib = Dlfcn.dlopen(Constants.CoreLocationLibrary, 0);

            try {
                string field = "kCLErrorUserInfoAlternateRegionKey";
                var    p     = Dlfcn.dlsym(lib, field);
                if (TestRuntime.CheckiOSSystemVersion(7, 1))
                {
                    Assert.That(p, Is.Not.EqualTo(IntPtr.Zero), field);
                }
                else
                {
                    Assert.That(p, Is.EqualTo(IntPtr.Zero), field);
                }
            }
            finally {
                Dlfcn.dlclose(lib);
            }
        }
Пример #4
0
            public VnodeMonitor(string path, VnodeMonitorKind vnodeKind, DispatchQueue queue = null)
            {
                if (path == null)
                {
                    throw new ArgumentNullException("path");
                }

                fd = open(path, O_EVTONLY);
                if (fd == -1)
                {
                    throw new IOException("Failure to open the file", Marshal.GetLastWin32Error());
                }
                if (type_vnode == IntPtr.Zero)
                {
                    type_vnode = Dlfcn.dlsym(Libraries.System.Handle, "_dispatch_source_type_vnode");
                }
                this.queue = queue;

                handle = dispatch_source_create(type_vnode,
                                                handle: (IntPtr)fd,
                                                mask:   (IntPtr)vnodeKind,
                                                queue:  queue == null ? IntPtr.Zero : queue.Handle);
            }
Пример #5
0
        // we just want to confirm the symbol exists so `dlsym` can be disabled
        protected void Check(Assembly a)
        {
            Errors = 0;
            ErrorData.Clear();
            int n = 0;

            foreach (var t in a.GetTypes())
            {
                foreach (var m in t.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
                {
                    if ((m.Attributes & MethodAttributes.PinvokeImpl) == 0)
                    {
                        continue;
                    }

                    var dllimport = m.GetCustomAttribute <DllImportAttribute> ();

                    string name = dllimport.EntryPoint ?? m.Name;
                    switch (name)
                    {
                    // known not to be present in ARM64
                    case "objc_msgSend_stret":
                    case "objc_msgSendSuper_stret":
                        // the linker normally removes them (IntPtr.Size optimization)
                        continue;
                    }

                    string path = dllimport.Value;
                    switch (path)
                    {
                    case "__Internal":
                        // load from executable
                        path = null;
                        break;

#if NET
                    case "QCall":
                        // Globalization hasn't been implemented yet: https://github.com/xamarin/xamarin-macios/issues/8906
                        if (name.StartsWith("GlobalizationNative_", StringComparison.Ordinal))
                        {
                            continue;
                        }
                        break;

                    case "libhostpolicy":
                        // There's no libhostpolicy library.
                        // https://github.com/dotnet/runtime/issues/38543
                        continue;

                    case "libSystem.Native":
                        path += ".dylib";
                        break;
#endif
                    case "libc":
                        // we still have some rogue/not-fully-qualified DllImport
                        path = "/usr/lib/libSystem.dylib";
                        break;

                    case "System.Native":
                    case "System.Security.Cryptography.Native.Apple":
                    case "System.Net.Security.Native":
                        if (MonoNativeConfig.LinkMode == MonoNativeLinkMode.None)
                        {
                            continue;
                        }
#if __IOS__
                        path = MonoNativeConfig.GetPInvokeLibraryName(MonoNativeFlavor.Compat, MonoNativeConfig.LinkMode);
#else
                        path = null;
#endif
                        break;
                    }

                    var lib = Dlfcn.dlopen(path, 0);
                    var h   = Dlfcn.dlsym(lib, name);
                    if (h == IntPtr.Zero)
                    {
                        ReportError("Could not find the symbol '{0}' in {1}", name, path);
                    }
                    Dlfcn.dlclose(lib);
                    n++;
                }
            }
            Assert.AreEqual(0, Errors, "{0} errors found in {1} symbol lookups{2}", Errors, n, Errors == 0 ? string.Empty : ":\n" + ErrorData.ToString() + "\n");
        }
Пример #6
0
 static DispatchData()
 {
     free = Marshal.ReadIntPtr(Dlfcn.dlsym(Libraries.LibC.Handle, "_dispatch_data_destructor_free"));
 }
Пример #7
0
 static DispatchData()
 {
     lib  = Dlfcn.dlopen(Constants.libcLibrary, 0);
     free = Marshal.ReadIntPtr(Dlfcn.dlsym(lib, "_dispatch_data_destructor_free"));
 }
Пример #8
0
        // we just want to confirm the symbol exists so `dlsym` can be disabled
        protected void Check(Assembly a)
        {
            Errors = 0;
            ErrorData.Clear();
            int n = 0;

            foreach (var t in a.GetTypes())
            {
                foreach (var m in t.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
                {
                    if ((m.Attributes & MethodAttributes.PinvokeImpl) == 0)
                    {
                        continue;
                    }

                    var dllimport = m.GetCustomAttribute <DllImportAttribute> ();

                    string name = dllimport.EntryPoint ?? m.Name;
                    switch (name)
                    {
                    // known not to be present in ARM64
                    case "objc_msgSend_stret":
                    case "objc_msgSendSuper_stret":
                        // the linker normally removes them (IntPtr.Size optimization)
                        continue;
                    }

                    string path = dllimport.Value;
                    switch (path)
                    {
                    case "__Internal":
                        // load from executable
                        path = null;
                        break;

#if NET
                    case "libSystem.Globalization.Native":
                        // load from executable (like __Internal above since it's part of the static library)
                        path = null;
                        break;

                    case "libSystem.Native":
                        path += ".dylib";
                        break;
#endif
                    case "libc":
                        // we still have some rogue/not-fully-qualified DllImport
                        path = "/usr/lib/libSystem.dylib";
                        break;

                    case "System.Native":
                    case "System.Security.Cryptography.Native.Apple":
                    case "System.Net.Security.Native":
                        if (MonoNativeConfig.LinkMode == MonoNativeLinkMode.None)
                        {
                            continue;
                        }
#if __IOS__
                        path = MonoNativeConfig.GetPInvokeLibraryName(MonoNativeFlavor.Compat, MonoNativeConfig.LinkMode);
#else
                        path = null;
#endif
                        break;
                    }

                    var lib = Dlfcn.dlopen(path, 0);
                    var h   = Dlfcn.dlsym(lib, name);
                    if (h == IntPtr.Zero)
                    {
                        ReportError("Could not find the symbol '{0}' in {1} for the P/Invoke {2}.{3} in {4}", name, path, t.FullName, m.Name, a.GetName().Name);
                    }
                    else if (path != null)
                    {
                        // Verify that the P/Invoke points to the right library.
                        Dl_info info  = default(Dl_info);
                        var     found = dladdr(h, out info);
                        if (found != 0)
                        {
                            // Resolve symlinks in both cases
                            var dllImportPath = ResolveLibrarySymlinks(path);
                            var foundLibrary  = ResolveLibrarySymlinks(Marshal.PtrToStringAuto(info.dli_fname));
                            if (Skip(name, ref dllImportPath, ref foundLibrary))
                            {
                                // Skipped
                            }
                            else if (foundLibrary != dllImportPath)
                            {
                                ReportError($"Found the symbol '{name}' in the library '{foundLibrary}', but the P/Invoke {t.FullName}.{m.Name} in {a.GetName ().Name} claims it's in '{dllimport.Value}'.");
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Unable to find the library for the symbol '{name}' claimed to be in {path} for the P/Invoke {t.FullName}.{m.Name} in {a.GetName ().Name} (rv: {found})");
                        }
                    }

                    Dlfcn.dlclose(lib);
                    n++;
                }
            }
            Assert.AreEqual(0, Errors, "{0} errors found in {1} symbol lookups{2}", Errors, n, Errors == 0 ? string.Empty : ":\n" + ErrorData.ToString() + "\n");
        }