Bug 321594 (MONO78877) - [PATCH] Can't assign to WeakReference.Target
Summary: [PATCH] Can't assign to WeakReference.Target
Status: RESOLVED FIXED
Alias: MONO78877
Product: Mono: Runtime
Classification: Mono
Component: GC (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Paolo Molaro
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-17 14:27 UTC by Antonio Cuni
Modified: 2007-09-15 21:24 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
GCHandle.patch (1.07 KB, patch)
2006-07-28 14:31 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:03:53 UTC


---- Reported by anto.cuni@gmail.com 2006-07-17 07:27:49 MST ----

Description of Problem:

The runtime crashes when trying to assign the Target field of a WeakReference.

Steps to reproduce the problem:

Compile & execute the following code:

using System;
class MyClass{ }
class Test
{
    static void Main(string[] argv)
    {
        WeakReference refe = new WeakReference(null);
        refe.Target = new MyClass();
        MyClass obj = (MyClass)refe.Target;
    }
}

Actual Results:

=================================================================
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.
=================================================================

Stacktrace:

in (wrapper managed-to-native)
System.Runtime.InteropServices.GCHandle:GetTargetHandle
(object,int,System.Runtime.InteropServices.GCHandleType) <0x4>
in (wrapper managed-to-native)
System.Runtime.InteropServices.GCHandle:GetTargetHandle
(object,int,System.Runtime.InteropServices.GCHandleType) <0xa3>
in System.Runtime.InteropServices.GCHandle:set_Target (object) <0x1b>
in System.WeakReference:set_Target (object) <0x13>
in Test:Main (string[]) <0x46>
in (wrapper runtime-invoke) System.Object:runtime_invoke_void_string[]
(object,intptr,intptr,intptr) <0x50a03027>

Native stacktrace:

        mono(mono_handle_native_sigsegv+0xc3) [0x81487c3]
        mono [0x8134c16]
        /lib/libpthread.so.0 [0x4c54f81b]
        [0xffffe440]
        mono [0x814aa09]
        mono [0x814a3bc]
        [0xb7731e6a]
        [0xb7731ee4]
        [0xb7731eac]
        [0xb7731c67]
        [0xb7731ac3]
        mono [0x8134ac0]
        mono(mono_runtime_invoke+0x27) [0x80cf647]
        mono(mono_runtime_exec_main+0x5a) [0x80d05da]
        mono(mono_runtime_run_main+0x19f) [0x80d026f]
        mono [0x805d0a1]
        mono(mono_main+0x812) [0x805da72]
        mono [0x805c42b]
        /lib/libc.so.6(__libc_start_main+0xb7) [0x4bc628a7]
        mono [0x805c361]

Expected Results:

Nothing.

How often does this happen? 

Always.

Additional Information:

Tested on linux with Mono 1.1.13.4 and 1.1.15, and on Windows with
1.1.13.8. It always crashes.

With Microsoft CLR it works fine.



---- Additional Comments From robertj@gmx.net 2006-07-28 07:29:38 MST ----

Actually it's GChandle, respectively its indirect internal call
to mono_gchandle_set_target, that doesn't support the remapping
of null handles.

It's probably easier to solve this in the managed world
instead of modifying the GC.

Is this ok?




---- Additional Comments From robertj@gmx.net 2006-07-28 07:31:08 MST ----

Created an attachment (id=170123)
GCHandle.patch




---- Additional Comments From lupus@ximian.com 2006-08-22 10:47:54 MST ----

Fixed in svn (directly in the runtime GC handle code).
Thanks Robert for the detective work and the patch.

Imported an attachment (id=170123)

Unknown bug field "cf_op_sys_details" encountered while moving bug
   <cf_op_sys_details>Linux anto 2.6.14.3 #2 PREEMPT Mon Dec 19 16:18:17 CET 2005 i686 Mobile AMD Athlon(tm) XP 3000+ AuthenticAMD GNU/Linux</cf_op_sys_details>
Unknown operating system unknown. Setting to default OS "Other".