On 11/01/05 Shankari wrote:
> I am trying to get the base of unmanaged stack, the reason I want this is 
> because i am sandboxing my C code so that it doesnt write to managed heap and 
> stack.

The managed and unmanaged stack are intermingled: they use the same
thread stack and at the managed <-> unmanaged transitions it's really
difficult to say that a bit of stack belongs to one or the other: it
could belong to both.
You could use the stack walking functions to have an approximate view of
things, but this requires arch-dependent code corrently.
In the future we'll keep track of this info more precisely, because we
need it to optimize the new GC, but right now it's not easy to get it.
Have a look at the exception handling code: you need to walk the stack
the same way and keep track of the base/stack pointer in the MonoContext
struct (checking for transitions by looking at the flags of methods invoked).

The summary, though, is that you won't get two nice boundary values,
but a list of pairs that delimit managed and unmanaged areas (with the
added complexity that some areas belong to both), so sandboxing code by
checking memory boundaries would be really complex and slow.

> I got the value of the esp at the beginning of the C program (via assembly 
> instructions) but (as jonp said) at this point the  local variables are 
> already on the unmanaged stack.
>  
> Is there any way to get to the beginning of the unmanaged stack?

The GC has code to handle this (for example, grep for LINUX_STACKBOTTOM
in mono/libgc).

> ( I tried inserting extra marker arguments in (emit_wrapper) so that I can 
> get to it in C code, but I totally broke mono compilation !!  )

If you add extra arguments to functions that don't take them, you're
asking for trouble, yes;-)

> Also, to insert an ARGUMENT of type  say at runtime,   valuetype 
> PlatformInvokeTest/DataObj*   V_4. (Need to generate Il code to declare a 
> pointer to the user defined structure)
> should i use:    
>  um_ptr = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
> or      um_ptr = mono_mb_add_local (mb, &(pclass->byval_arg));

If you just need a pointer, the first is fine (when we'll enforce strict
type checking we'll add an option to turn it off for runtime generated
code such as this).
Also note that this is a local variable, not an argument.

lupus

-- 
-----------------------------------------------------------------
[EMAIL PROTECTED]                                     debian/rules
[EMAIL PROTECTED]                             Monkeys do it better
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to