zeromq / clrzmq4

ZeroMQ C# namespace (.NET and mono, Windows, Linux and MacOSX, x86 and amd64)
GNU Lesser General Public License v3.0
241 stars 112 forks source link

Segmentation fault when running in MonoDevelop #38

Closed ingarpedersen closed 8 years ago

ingarpedersen commented 9 years ago

When running this code in MonoDevelop (4.0.12), using Mono/.net 4.0 as target:

private void buttonStart_Click(object sender, EventArgs e)
        {
            if (!bRunning)
            {
                ZContext context = ZContext.Create();
                using (var worker = new ZSocket(context, ZSocketType.DEALER)) 
                                {
                                }
            }
        }

I get a segmentation fault at the ZContext.Create(): at <0xffffffff> at (wrapper managed-to-native) ZeroMQ.lib.Platform/Posix.dlopen (intptr,int) IL 0x00036, 0xffffffff at ZeroMQ.lib.Platform/Posix.OpenHandle (string) IL 0x0000d, 0x0004f at ZeroMQ.lib.Platform/Posix.LoadUnmanagedLibrary (string) IL 0x00113, 0x0049b

This happens with precompiled binaries and the same thing happens if I compile the source myself. When singlestepping it seems to happens when it tries to load the sodium library (which is installed correctly) I'm running on a 32-bit Debian installation.
metadings commented 9 years ago

AHA... that sounds interesting... I am running an ubuntu GNU/Linux machine on a x64_86 processor... CLRZMQ4 is actually implemented using GNU/C libdl.so.

CLRZMQ4 is currently looking ... into libdl.so (Platform will use Platform.Posix, because there is PlatformName.Posix)... for function pointers to dlopen, dlclose, dlerror and the like...

So you basically need to implement, for example a PlatformName.Example and a class Platform.Example, looking like

public static partial class Platform {

    public static class Example {

        public const string LibraryFileExtension = ".so";
        private const string KernelLib = "libdl";

        public static UnmanagedLibrary LoadUnmanagedLibrary(string libraryName) // ...
        public static SafeLibraryHandle OpenHandle(string filename) // ...
        public static IntPtr LoadProcedure(SafeLibraryHandle handle, string functionName) // ...
        public static bool ReleaseHandle(IntPtr handle) // ...
        public static Exception GetLastLibraryError() // ...

Finally you need to add a detection in Platform, to enable your PlatformName.Example, class Platform.Example:

static Platform() {
    // ...
    Version osVersion;
    switch (Environment.OSVersion.Platform) {
        case PlatformID.Win32Windows: // ...
            Kind = PlatformKind.Win32;
            Name = PlatformName.Windows;
            break;
        case PlatformID.Unix:
            Kind = PlatformKind.Posix;
            Name = PlatformName.Posix;
            break;
        default: // ...
    }
    // do some detection of your Platform and set the Name:
    //  Kind = PlatformKind.Posix;
    //  Name = PlatformName.Example;
    // ...

    SetupPlatformImplementation(typeof(Platform));
}

So you have a real Debian GNU/Linux... You need to look further :)

metadings commented 8 years ago

I had the same problem... I installed Linux Mint instead of ubuntu. Now looking for a libld.so or libdl.so doesn't work... because there is a /lib/x86_64-linux-gnu/libdl.so.2 or the like....

I was used to have a workaround, simply by hardlinking ln libdl.so libdl.so.2.

Now I've made an update for the Platform and Platform.Posix class, to read the ld.so.conf and to read include /etc/ld.so.conf.d/*.conf. In Platform.Posix.EnumerateLibLdConf.

Please, do a git pull zeromq master to try the changes.

metadings commented 8 years ago

I'm going to close the issue. Package is live on nuget.org.