[Mono-bugs] [Bug 660868] New: mono_jit_exec causes a crash if argv[0] is not the name of the managed executable

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Dec 21 14:37:41 EST 2010



           Summary: mono_jit_exec causes a crash if argv[0] is not the
                    name of the managed executable
    Classification: Mono
           Product: Mono: Runtime
           Version: 2.8.x
          Platform: x86-64
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: JIT
        AssignedTo: lupus at novell.com
        ReportedBy: salamat at qualcomm.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us)
AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4

I spent almost a whole day trying to debug a few lines of code that I had
written to run a managed executable through mono embedding. The code is pretty
much the same as what is given in the mono documentations (see it below), but
the program was crashing with a seg fault and gdb was telling me that it
happens at mono_jit_exec. After spending a lot of time, I figured out that
argv[0] passed to the mono_jit_exec must be the managed executable name. This
should be mentioned in the mono embedding documents. Moreover, the runtime
should give a better error message and shutdown gracefully.

The code:

int main (int argc, char *argv[])
    MonoDomain *domain;
    domain = mono_jit_init("HelloWorld.exe");
    if (!domain)
        cout << "cannot init hello world" << endl;
        return 1;

    string filename("../bin/Debug/HelloWorld.exe");
    MonoAssembly *assembly;
    assembly = mono_domain_assembly_open (domain, filename.c_str());
    if (!assembly)
        cout << "cannot open assembly " << filename << endl;
        return 1;

    int retval = mono_jit_exec (domain, assembly, argc - 1, argv + 1);
    mono_jit_cleanup (domain);
    return retval;

Reproducible: Always

Steps to Reproduce:
1. Use the code give in the "Details" to run a managed executable through mono
2. Do not set argv[0] to the name of the managed executable
3. Compile and run
Actual Results:  

Native stacktrace:

    /home/salamat/Programs/mono/lib/libmono-2.0.so.1(+0xa9c8a) [0x7f7acbd77c8a]
    /home/salamat/Programs/mono/lib/libmono-2.0.so.1(+0xfed7f) [0x7f7acbdccd7f]
    /lib/libpthread.so.0(+0xfb40) [0x7f7acb6b4b40]
    MCJSInvoker/bin/Release/MCJSInvoker() [0x400def]
    /lib/libc.so.6(__libc_start_main+0xfe) [0x7f7acaba1d8e]
    MCJSInvoker/bin/Release/MCJSInvoker() [0x400c99]

Debug info from gdb:

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.

Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.

Aborted (core dumped)

Expected Results:  
Run the managed executable

I have not tried the code on other HW platforms or other operating systems, but
you will probably get the same result on other platforms and OSes too.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list