[runtime] Switch getenv to use heap memory
[mono.git] / mono / utils / mono-stack-unwinding.h
1 /*
2  * Copyright 2008-2010 Novell, Inc.
3  * Copyright 2011 Xamarin Inc.
4  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
5  */
6 #ifndef __MONO_MONO_STACK_UNWINDING_H__
7 #define __MONO_MONO_STACK_UNWINDING_H__
8
9 #include <mono/metadata/appdomain.h>
10 #include <mono/metadata/metadata.h>
11 #include <mono/utils/mono-context.h>
12
13 /*
14  * Possible frame types returned by the stack walker.
15  */
16 typedef enum {
17         /* Normal managed frames */
18         FRAME_TYPE_MANAGED = 0,
19         /* Pseudo frame marking the start of a method invocation done by the soft debugger */
20         FRAME_TYPE_DEBUGGER_INVOKE = 1,
21         /* Frame for transitioning to native code */
22         FRAME_TYPE_MANAGED_TO_NATIVE = 2,
23         FRAME_TYPE_TRAMPOLINE = 3,
24         FRAME_TYPE_NUM = 4
25 } MonoStackFrameType;
26
27 typedef enum {
28         MONO_UNWIND_NONE = 0x0,
29         MONO_UNWIND_LOOKUP_IL_OFFSET = 0x1,
30         /* NOT signal safe */
31         MONO_UNWIND_LOOKUP_ACTUAL_METHOD = 0x2,
32         /*
33          * Store the locations where caller-saved registers are saved on the stack in
34          * frame->reg_locations. The pointer is only valid during the call to the unwind
35          * callback.
36          */
37         MONO_UNWIND_REG_LOCATIONS = 0x4,
38         MONO_UNWIND_DEFAULT = MONO_UNWIND_LOOKUP_ACTUAL_METHOD,
39         MONO_UNWIND_SIGNAL_SAFE = MONO_UNWIND_NONE,
40         MONO_UNWIND_LOOKUP_ALL = MONO_UNWIND_LOOKUP_IL_OFFSET | MONO_UNWIND_LOOKUP_ACTUAL_METHOD,
41 } MonoUnwindOptions;
42
43 typedef struct {
44         MonoStackFrameType type;
45         /* 
46          * For FRAME_TYPE_MANAGED, otherwise NULL.
47          */
48         MonoJitInfo *ji;
49         /*
50          * Same as ji->method.
51          * Not valid if ASYNC_CONTEXT is true.
52          */
53         MonoMethod *method;
54         /*
55          * If ji->method is a gshared method, this is the actual method instance.
56          * This is only filled if lookup for actual method was requested (MONO_UNWIND_LOOKUP_ACTUAL_METHOD)
57          * Not valid if ASYNC_CONTEXT is true.
58          */
59         MonoMethod *actual_method;
60         /* The domain containing the code executed by this frame */
61         MonoDomain *domain;
62         /* Whenever method is a user level method */
63         gboolean managed;
64         /*
65          * Whenever this frame was loaded in async context.
66          */
67         gboolean async_context;
68         int native_offset;
69         /*
70          * IL offset of this frame.
71          * Only available if the runtime have debugging enabled (--debug switch) and 
72          *  il offset resultion was requested (MONO_UNWIND_LOOKUP_IL_OFFSET)
73          */
74         int il_offset;
75
76         /* The next fields are only useful for the jit */
77         gpointer lmf;
78         guint32 unwind_info_len;
79         guint8 *unwind_info;
80
81         mgreg_t **reg_locations;
82 } MonoStackFrameInfo;
83
84 /*Index into MonoThreadState::unwind_data. */
85 enum {
86         MONO_UNWIND_DATA_DOMAIN,
87         MONO_UNWIND_DATA_LMF,
88         MONO_UNWIND_DATA_JIT_TLS,       
89 };
90
91 /*
92  * This structs holds all information needed to unwind the stack
93  * of a thread.
94  */
95 typedef struct {
96         MonoContext ctx;
97         gpointer unwind_data [3]; /*right now: domain, lmf and jit_tls*/
98         gboolean valid;
99         void *gc_stackdata;
100         int gc_stackdata_size;
101 } MonoThreadUnwindState;
102
103
104 #endif