|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Collections.Generic; |
|
19 using System.Text; |
|
20 using System.Text.RegularExpressions; |
|
21 using System.IO; |
|
22 using SymbianUtils.DataBuffer.Entry; |
|
23 using SymbianUtils.Range; |
|
24 using SymbianStackLib.Exceptions; |
|
25 |
|
26 namespace SymbianStackLib.AddressInfo |
|
27 { |
|
28 /// <summary> |
|
29 /// Stack flows from the base upwards: |
|
30 /// |
|
31 /// -------------- TOP ---------------- 0x402000 |
|
32 /// | |
|
33 /// | Unused Stack |
|
34 /// | |
|
35 /// |----------- CURRENT SP ----------- 0x4033b8 |
|
36 /// | |
|
37 /// | ^ |
|
38 /// | | |
|
39 /// | |
|
40 /// | Used Stack [Stack |
|
41 /// | Pointer |
|
42 /// | | Range] |
|
43 /// | | |
|
44 /// | | |
|
45 /// | |
|
46 /// -------------- BASE --------------- 0x407000 |
|
47 /// </summary> |
|
48 public sealed class StackAddressInfo |
|
49 { |
|
50 #region Constructors |
|
51 internal StackAddressInfo() |
|
52 { |
|
53 } |
|
54 #endregion |
|
55 |
|
56 #region API |
|
57 public void Set( uint aSP, uint aTop, uint aBase ) |
|
58 { |
|
59 Pointer = aSP; |
|
60 Top = aTop; |
|
61 Base = aBase; |
|
62 } |
|
63 |
|
64 internal void Validate() |
|
65 { |
|
66 if ( Top != 0 && Base < Top ) |
|
67 { |
|
68 throw new StackAddressException( StackAddressException.TType.ETypeBaseAddressBeforeTopAddress ); |
|
69 } |
|
70 else if ( Base != 0 && Top > Base ) |
|
71 { |
|
72 throw new StackAddressException( StackAddressException.TType.ETypeTopAddressAfterBaseAddress ); |
|
73 } |
|
74 else if ( Pointer == 0 ) |
|
75 { |
|
76 throw new StackAddressException( StackAddressException.TType.ETypePointerIsNull ); |
|
77 } |
|
78 else if ( Pointer > Base ) |
|
79 { |
|
80 throw new StackAddressException( StackAddressException.TType.ETypePointerOutOfBounds ); |
|
81 } |
|
82 else if ( Pointer < Top ) |
|
83 { |
|
84 // Not an error as possibly a stack overflow... |
|
85 } |
|
86 } |
|
87 |
|
88 internal bool IsWithinStackDomain( DataBufferByte aEntry ) |
|
89 { |
|
90 bool ret = Range.Contains( aEntry.Address ); |
|
91 return ret; |
|
92 } |
|
93 |
|
94 internal bool IsWithinCurrentStackDomain( DataBufferByte aEntry ) |
|
95 { |
|
96 bool ret = StackPointerRange.Contains( aEntry.Address ); |
|
97 return ret; |
|
98 } |
|
99 #endregion |
|
100 |
|
101 #region Properties |
|
102 public uint Base |
|
103 { |
|
104 get { return iBase; } |
|
105 set |
|
106 { |
|
107 iBase = value; |
|
108 } |
|
109 } |
|
110 |
|
111 public uint Top |
|
112 { |
|
113 get { return iTop; } |
|
114 set |
|
115 { |
|
116 iTop = value; |
|
117 } |
|
118 } |
|
119 |
|
120 public uint Pointer |
|
121 { |
|
122 get { return iPointer; } |
|
123 set |
|
124 { |
|
125 iPointer = value; |
|
126 |
|
127 // Don't record that we've set the stack pointer if somebody is just |
|
128 // zeroing it out. |
|
129 if ( value != 0 ) |
|
130 { |
|
131 HaveSetStackPointer = true; |
|
132 } |
|
133 } |
|
134 } |
|
135 |
|
136 public AddressRange Range |
|
137 { |
|
138 get { return new AddressRange( Top, Base ); } |
|
139 set |
|
140 { |
|
141 Top = value.Min; |
|
142 Base = value.Max; |
|
143 } |
|
144 } |
|
145 |
|
146 public AddressRange StackPointerRange |
|
147 { |
|
148 get |
|
149 { |
|
150 AddressRange ret = new AddressRange( Pointer, Base ); |
|
151 |
|
152 // If we don't have a valid SP value, then use the entire stack |
|
153 if ( Pointer == 0 ) |
|
154 { |
|
155 ret = Range; |
|
156 } |
|
157 // |
|
158 return ret; |
|
159 } |
|
160 } |
|
161 |
|
162 public AddressRange StackPointerRangeWithExtensionArea |
|
163 { |
|
164 get |
|
165 { |
|
166 AddressRange ret; |
|
167 // |
|
168 uint pointer = Pointer; |
|
169 uint pointerMinusExtension = pointer - KStackRangeExtension; |
|
170 if ( pointer == 0 || pointerMinusExtension < 0 || pointerMinusExtension < Top ) |
|
171 { |
|
172 ret = Range; |
|
173 } |
|
174 else |
|
175 { |
|
176 ret = StackPointerRange; |
|
177 ret.Min = pointerMinusExtension; |
|
178 } |
|
179 // |
|
180 return ret; |
|
181 } |
|
182 } |
|
183 #endregion |
|
184 |
|
185 #region Internal methods |
|
186 internal bool HaveSetStackPointer |
|
187 { |
|
188 get { return iHaveSetSP; } |
|
189 set { iHaveSetSP = value; } |
|
190 } |
|
191 #endregion |
|
192 |
|
193 #region Internal constants |
|
194 private const int KStackRangeExtension = 12 * 4; |
|
195 #endregion |
|
196 |
|
197 #region Data members |
|
198 private uint iBase = 0; |
|
199 private uint iTop = 0; |
|
200 private uint iPointer = 0; |
|
201 private bool iHaveSetSP = false; |
|
202 #endregion |
|
203 } |
|
204 } |