[Mono-list] Fault isolation : IL code

Shankari shankari82 at yahoo.com
Tue Nov 8 20:55:54 EST 2005


Hello all,
I am restating my problem.
My problem : isolating faults caused by unmanaged code. To achieve this I am not allowing the unmanaged code to "modify managed memory".
I am doing this in two stages.
1) ensuring that the unmanaged C code does not modify any managegd memory. This I am doing by modifying the ASSEMBLY code of the unmanaged program and sandboxing it so that all the "write " instructions dont write to managed memory.
2) If an argument is passed by reference, I have make a copy of the object in unmanaged memory and pass this reference to the unmanaged code. So the program will get a reference to the unmanaged memory and not managed memory.
By these two stages,  I am ensuring that the managed memory is not at any time being corrupted by unmanaged code. (the results, the final updated unmanaged meory object will be passed back by another mechanism, have to yet work on this )

I am tryingto do the second part described above as follows:
1) I figured that marshal.c is the place where IL code is being emitted to push the arguments before the call.
2) so, if an argument is passed by reference, am emitting IL code to make a copy of the object in unmanaged memory and pass this.
I wrote code to emit IL code to achieve this and it errors out 
** (pinvref.exe:15147): WARNING **: implement me 0x77
** ERROR **: file class.c: line 2812 (mono_class_from_mono_type): should not be reached
aborting...
Aborted

I am sending the code that I wrote. Can anyone tell me what I am doing wrong??
Here is the C code to emit IL code :  ( for testing purposes, I directly did a g_malloc,to allocate unmanaged memory, instead of emitting a call to "AllocCoTaskMem", which I have commented out . The emit_managed_call does work when I inspected the trace of execution )

 MonoType *t = sig->params[argnum];
 MonoClass *pclasee = mono_class_from_mono_type(t);
 inst_size = pclass->instance_size;   / * not sure if i should use this or mono_class_value_size (klass, NULL) , have tried both!!  */
 
        um_mem = (MonoType *)g_malloc(inst_size);

        /* EMITTING MEMORY ALLOC CALL :    */
        /* pushing the alloc_size on stack for use by AllocCoTaskMem */
        /* mono_mb_emit_byte (mb, CEE_LDC_I4_S);
        mono_mb_emit_byte (mb, inst_size);
        klassAllocCoTaskMem= mono_class_from_name(mono_defaults.corlib,"System.Runtime.InteropServices", "Marshal");
        methodAllocCoTaskMem = mono_class_get_method_from_name(klassAllocCoTaskMem,"AllocCoTaskMem", -1);
        mono_mb_emit_managed_call(mb,methodAllocCoTaskMem,NULL);  */
        /* dest */
        mono_mb_emit_icon(mb,um_mem);
        /* src*/
        mono_mb_emit_ldarg(mb, argnum);
     
        mono_mb_emit_byte(mb, CEE_LDIND_REF);
       
 mono_mb_emit_byte(mb, CEE_STIND_REF);
 /* emit the call to push the NEW REFERENCE */
       emit_marshal (m, argnum, um_mem, spec, conv_arg, NULL, MARSHAL_ACTION_PUSH);
 
ALSO tried the followng way
 /* destination addr on stack */
       mono_mb_emit_icon(mb,um_mem);
 
 /* source address */
       mono_mb_emit_ldarg(mb, argnum); 
       mono_mb_emit_icon (mb, inst_size);
       mono_mb_emit_byte (mb, CEE_PREFIX1);
       mono_mb_emit_byte (mb, CEE_CPBLK);
 
 
 
Thanks a lot for your time,
S


		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20051108/d3e51ec7/attachment.html


More information about the Mono-list mailing list