|
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: Declaration of the class RAnalyzeToolMainAllocator. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef ANALYZETOOLMAINALLOCATOR_H |
|
20 #define ANALYZETOOLMAINALLOCATOR_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <u32std.h> |
|
24 #include "codeblock.h" |
|
25 #include <analyzetool/analyzetool.h> |
|
26 #include <analyzetool/atcommon.h> |
|
27 #include "analyzetoolmemoryallocator.h" |
|
28 #include "analyzetooleventhandlernotifier.h" |
|
29 #include "analyzetoolfilelog.h" |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class CLibraryEventHandler; |
|
33 |
|
34 // CLASS DECLARATION |
|
35 |
|
36 /** |
|
37 * Class which overloads the RAlloctor functions and provides access to |
|
38 * the overloaded functions |
|
39 */ |
|
40 class RAnalyzeToolMainAllocator : public RAnalyzeToolMemoryAllocator, |
|
41 public MAnalyzeToolEventhandlerNotifier |
|
42 { |
|
43 |
|
44 public: |
|
45 |
|
46 /** |
|
47 * C++ default constructor. |
|
48 * @param aNotFirst Is this first thread using this heap |
|
49 * @param aFileName The name of the log file |
|
50 * @param aLogOption The logging option |
|
51 * @param aIsDebug Determines whether a binary is UDEB or UREL |
|
52 * @param aAllocCallStackSize Max number of stored callstack items when memory allocated |
|
53 * @param aFreeCallStackSize Max number of stored callstack items when memory freed |
|
54 * @param aAtoolVersion Version of atool |
|
55 * @param aApiVersion Version of api |
|
56 */ |
|
57 RAnalyzeToolMainAllocator( TBool aNotFirst, |
|
58 const TFileName& aFileName, |
|
59 const TPath& aFilePath, |
|
60 TUint32 aLogOption, TUint32 aIsDebug, |
|
61 TUint32 aAllocCallStackSize, |
|
62 TUint32 aFreeCallStackSize, |
|
63 const TDesC8& aAtoolVersion, |
|
64 const TDesC8& aApiVersion ); |
|
65 |
|
66 /** |
|
67 * Destructor. |
|
68 */ |
|
69 ~RAnalyzeToolMainAllocator(); |
|
70 |
|
71 /** |
|
72 * Allocates a cell of specified size from the heap. |
|
73 * @param aSize The size of the cell to be allocated from the heap. |
|
74 * @return TAny* A pointer to the allocated cell. |
|
75 */ |
|
76 TAny* Alloc( TInt aSize ); |
|
77 |
|
78 /** |
|
79 * Frees the specified cell and returns it to the heap. |
|
80 * @param aPtr A pointer to a cell to be freed. |
|
81 */ |
|
82 void Free( TAny* aPtr ); |
|
83 |
|
84 /** |
|
85 * Increases or decreases the size of an existing cell. |
|
86 * @param aPtr A pointer to the cell to be reallocated. |
|
87 * @param aSize The new size of the cell. This may be bigger |
|
88 * or smaller than the size of the original cell. |
|
89 * @param aMode Flags controlling the reallocation. |
|
90 * @return TAny* A pointer to the reallocated cell. This may be the |
|
91 * same as the original pointer supplied through aCell. |
|
92 */ |
|
93 TAny* ReAlloc( TAny* aPtr, TInt aSize, TInt aMode = 0 ); |
|
94 |
|
95 /** |
|
96 * Gets the length of the available space in the specified |
|
97 * allocated cell. |
|
98 * @param aCell A pointer to the allocated cell. |
|
99 * @return TInt The length of the available space in the allocated cell. |
|
100 */ |
|
101 TInt AllocLen(const TAny* aCell) const; |
|
102 |
|
103 #ifndef __KERNEL_MODE__ |
|
104 |
|
105 /** |
|
106 * Opens this heap for shared access. Opening the heap increases |
|
107 * the heap's access count by one. |
|
108 */ |
|
109 TInt Open(); |
|
110 |
|
111 /** |
|
112 * Closes this shared heap. Closing the heap decreases the heap's |
|
113 * access count by one. |
|
114 */ |
|
115 void Close(); |
|
116 |
|
117 /** |
|
118 * The function frees excess committed space from the top of the heap. |
|
119 * The size of the heap is never reduced below the minimum size |
|
120 * specified during creation of the heap. |
|
121 * @return TInt The space reclaimed. If no space can be reclaimed, |
|
122 then this value is zero. |
|
123 */ |
|
124 TInt Compress(); |
|
125 |
|
126 /** |
|
127 * Frees all allocated cells on this heap. |
|
128 */ |
|
129 void Reset(); |
|
130 |
|
131 /** |
|
132 * Gets the number of cells allocated on this heap, and |
|
133 * the total space allocated to them. |
|
134 * @param aTotalAllocSize On return, contains the total |
|
135 * space allocated to the cells. |
|
136 * @return TInt The number of cells allocated on this heap. |
|
137 */ |
|
138 TInt AllocSize( TInt& aTotalAllocSize ) const; |
|
139 |
|
140 /** |
|
141 * Gets the total free space currently available on the heap and the |
|
142 * space available in the largest free block. The space available |
|
143 * represents the total space which can be allocated. Note that |
|
144 * compressing the heap may reduce the total free space available |
|
145 * and the space available in the largest free block. |
|
146 * @param aBiggestBlock On return, contains the space available |
|
147 * in the largest free block on the heap. |
|
148 |
|
149 * @return TInt The total free space currently available on the heap. |
|
150 |
|
151 */ |
|
152 TInt Available( TInt& aBiggestBlock ) const; |
|
153 |
|
154 #endif |
|
155 |
|
156 /** |
|
157 * Invocates specified debug funtionality. |
|
158 * @param aFunc The debug function |
|
159 * @param a1 Debug function specific paramenter. |
|
160 * @param a2 Debug function specific paramenter. |
|
161 * @return TInt Returns KErrNone, if successful otherwise one |
|
162 * of the other system-wide error codes. |
|
163 */ |
|
164 TInt DebugFunction( TInt aFunc, TAny* a1 = NULL, TAny* a2 = NULL ); |
|
165 |
|
166 // From MAnalyzeToolEventhandlerNotifier |
|
167 |
|
168 /** |
|
169 * Remove killed thread from threads array. |
|
170 * @param aThreadId - Thread Id |
|
171 */ |
|
172 void RemoveKilledThread( const TUint aThreadId ); |
|
173 |
|
174 protected: |
|
175 |
|
176 /** |
|
177 * Extension function |
|
178 * @param aExtensionId The extension id |
|
179 * @param a0 Extension specific paramenter. |
|
180 * @param a1 Extension specific paramenter. |
|
181 * @return TInt Returns KErrNone, if successful otherwise one |
|
182 * of the other system-wide error codes. |
|
183 */ |
|
184 TInt Extension_( TUint aExtensionId, TAny*& a0, TAny* a1 ); |
|
185 |
|
186 public: // from RAnalyzeToolMemoryAllocator |
|
187 |
|
188 /** |
|
189 * Installs the RTraceAllocator allocator |
|
190 */ |
|
191 void Uninstall(); |
|
192 |
|
193 /** |
|
194 * Shares the heap |
|
195 */ |
|
196 void ShareHeap(); |
|
197 |
|
198 public: // inlines |
|
199 |
|
200 /** |
|
201 * Acquires the codeblocks of the process |
|
202 * @return RArray<TCodeblock>& The process codeblocks |
|
203 */ |
|
204 inline RArray<TCodeblock>& Codeblocks(); |
|
205 |
|
206 /** |
|
207 * Acquires the mutex used to access shared objects |
|
208 * @return RMutex& A reference to open mutex |
|
209 */ |
|
210 inline RMutex& Mutex(); |
|
211 |
|
212 /** |
|
213 * Acquires the current process id |
|
214 * @return TInt The process id |
|
215 */ |
|
216 inline TInt ProcessId(); |
|
217 |
|
218 /** |
|
219 * Acquires the logical channel handle |
|
220 * @return RAnalyzeTool A reference to logical channel |
|
221 */ |
|
222 inline RAnalyzeTool& AnalyzeTool(); |
|
223 |
|
224 /** |
|
225 * Acquires the log option type |
|
226 * @return TUint32 iLogOption |
|
227 */ |
|
228 inline TUint32 LogOption(); |
|
229 |
|
230 /** |
|
231 * Acquires the max size of call stack when memory allocated |
|
232 * @return TUint32 iAllocMaxCallStack |
|
233 */ |
|
234 inline TUint32 AllocMaxCallStack(); |
|
235 |
|
236 /** |
|
237 * Acquires the max size of call stack when memory freed |
|
238 * @return TUint32 iFreeMaxCallStack |
|
239 */ |
|
240 inline TUint32 FreeMaxCallStack(); |
|
241 |
|
242 /** |
|
243 * Acquires handle to lig file |
|
244 * @return RATFileLog iLogFile |
|
245 */ |
|
246 inline RATFileLog& LogFile(); |
|
247 |
|
248 private: // private functions |
|
249 |
|
250 /** |
|
251 * Log the process initial information |
|
252 * @param aFileName The name of the log file |
|
253 * @param aLogOption The logging option |
|
254 * @param aIsDebug Determines whether a binary is UDEB or UREL |
|
255 */ |
|
256 void LogProcessInformation( const TFileName& aFileName, const TPath& aFilePath, TUint32 aLogOption, |
|
257 TUint32 aIsDebug, const TDesC8& aAtoolVersion, const TDesC8& aApiVersion ); |
|
258 |
|
259 /** |
|
260 * Find the current thread which is using the heap |
|
261 * @param aStackStart A reference where the stack start is stored |
|
262 * @return TBool ETrue if a thread can be found, EFalse otherwise |
|
263 */ |
|
264 TBool FindCurrentThreadStack( TUint32& aStackStart ); |
|
265 |
|
266 /** |
|
267 * Installs the eventhandler, if possible |
|
268 */ |
|
269 void InstallEventHandler(); |
|
270 |
|
271 /** |
|
272 * Logs version of ATApp, ATApi, S60 version and ROM checksum |
|
273 * at the startup of hooked application |
|
274 */ |
|
275 void LogDeviceInfo(); |
|
276 |
|
277 private: // member variables |
|
278 |
|
279 /* Handle to the RAnalyzeTool */ |
|
280 RAnalyzeTool iAnalyzeTool; |
|
281 |
|
282 /* A flag for indicating that the RAnalyzeTool is open */ |
|
283 TBool iAnalyzeToolOpen; |
|
284 |
|
285 /* A flag for indicating that the device driver is loaded */ |
|
286 TBool iDeviceDriverLoaded; |
|
287 |
|
288 /* The codeblocks of the process */ |
|
289 RArray<TCodeblock> iCodeblocks; |
|
290 |
|
291 /* The handler for kerner events */ |
|
292 CLibraryEventHandler* iEventHandler; |
|
293 |
|
294 /* The mutex for serializing access to the shared resources */ |
|
295 mutable RMutex iMutex; |
|
296 |
|
297 /* Array for storing the callstack */ |
|
298 TFixedArray <TUint32, KATMaxCallstackLength> iCallStack; |
|
299 |
|
300 /* Array for storing the reallocation callstack */ |
|
301 TFixedArray <TUint32, KATMaxCallstackLength> iReCallStack; |
|
302 |
|
303 /* Array for storing the reallocation callstack */ |
|
304 TFixedArray<TUint32, KATMaxFreeCallstackLength> iFreeCallStack; |
|
305 |
|
306 /* Array of threads using this heap */ |
|
307 RArray<TThreadStack> iThreadArray; |
|
308 |
|
309 /* Log option */ |
|
310 TUint32 iLogOption; |
|
311 |
|
312 /* The process id */ |
|
313 TUint iProcessId; |
|
314 |
|
315 /* Max items on stored call stack when memory allocated */ |
|
316 TUint32 iAllocMaxCallStack; |
|
317 |
|
318 /* Max items on stored call stack when memory freed */ |
|
319 TUint32 iFreeMaxCallStack; |
|
320 |
|
321 /* Binary log file */ |
|
322 RATFileLog iLogFile; |
|
323 |
|
324 |
|
325 }; |
|
326 |
|
327 // INLINES |
|
328 #include "analyzetoolmainallocator.inl" |
|
329 |
|
330 #endif // ANALYZETOOLMAINALLOCATOR_H |
|
331 |
|
332 // End of File |