21 #include "analyzetoolmainallocator.h" |
21 #include "analyzetoolmainallocator.h" |
22 #include "analyzetoolallocator.h" |
22 #include "analyzetoolallocator.h" |
23 #include "atlog.h" |
23 #include "atlog.h" |
24 #include "analyzetoolmemoryallocator.h" |
24 #include "analyzetoolmemoryallocator.h" |
25 #include "analyzetoolpanics.pan" |
25 #include "analyzetoolpanics.pan" |
|
26 #include "atstorageservercommon.h" |
26 #include "atdriveinfo.h" |
27 #include "atdriveinfo.h" |
27 #include <analyzetool/analyzetooltraceconstants.h> |
28 #include <analyzetool/analyzetooltraceconstants.h> |
28 #include "analyzetoolfastlog.h" |
|
29 |
29 |
30 #ifdef USE_CLEANER_DLL |
30 #ifdef USE_CLEANER_DLL |
31 // Global variable to detect dll attach & detach in process. |
31 // Global variable to detect dll attach & detach in process. |
32 // Note! This is initialized after SetupThreadHeap so its not usable there. |
32 // Note! This is initialized after SetupThreadHeap so its not usable there. |
33 // This is used to store the main thread id and track when the process ends |
33 // This is used to store the main thread id and track when the process ends |
119 #endif |
119 #endif |
120 |
120 |
121 // CONSTANTS |
121 // CONSTANTS |
122 // When needed, update the version number directly inside _LIT macro. |
122 // When needed, update the version number directly inside _LIT macro. |
123 // Constant for the atool API(staticlib) version. |
123 // Constant for the atool API(staticlib) version. |
124 _LIT( KAtoolApiVersion, "1.7.6" ); |
124 _LIT( KAtoolApiVersion, "1.7.5" ); |
125 |
125 |
126 // Version number buffer length |
126 // Version number buffer length |
127 const TInt KAtoolVersionNumberLength = 10; |
127 const TInt KAtoolVersionNumberLength = 10; |
128 |
128 |
129 // Wrong version error code |
129 // Wrong version error code |
131 |
131 |
132 // Version number separator |
132 // Version number separator |
133 _LIT( KVersionSeparator, ";" ); |
133 _LIT( KVersionSeparator, ";" ); |
134 |
134 |
135 // Incorrect version error strings |
135 // Incorrect version error strings |
136 _LIT( KIncorrectText, "ERR INCORRECT_ATOOL_VERSION [API v.%S][ATOOL v.%S]" ); |
136 _LIT( KIncorrectText, "ERROR_OCCURED INCORRECT_ATOOL_VERSION [API v.%S][ATOOL v.%S]" ); |
137 _LIT( KIncorrectTextTrace, "<AT> " ); |
137 _LIT( KIncorrectTextTrace, "PCSS " ); |
138 |
138 |
139 // ----------------------------------------------------------------------------- |
139 // ----------------------------------------------------------------------------- |
140 // CustomUser::Panic() |
140 // CustomUser::Panic() |
141 // Overloaded User::Panic() function |
141 // Overloaded User::Panic() function |
142 // ----------------------------------------------------------------------------- |
142 // ----------------------------------------------------------------------------- |
238 // CustomUser::SetupThreadHeap() |
238 // CustomUser::SetupThreadHeap() |
239 // Overloaded UserHeap::SetupThreadHeap function |
239 // Overloaded UserHeap::SetupThreadHeap function |
240 // ----------------------------------------------------------------------------- |
240 // ----------------------------------------------------------------------------- |
241 // |
241 // |
242 EXPORT_C TInt CustomUser::SetupThreadHeap( TBool aNotFirst, |
242 EXPORT_C TInt CustomUser::SetupThreadHeap( TBool aNotFirst, |
243 SStdEpocThreadCreateInfo& aInfo, const TFileName& aFileName, const TPath& aFilePath, |
243 SStdEpocThreadCreateInfo& aInfo, const TFileName& aFileName, |
244 TUint32 aLogOption, TUint32 aIsDebug, const TATVersion& aVersion, |
244 TUint32 aLogOption, TUint32 aIsDebug, const TATVersion& aVersion, |
245 TUint32 aAllocCallStackSize, TUint32 aFreeCallStackSize, |
245 TUint32 aAllocCallStackSize, TUint32 aFreeCallStackSize, |
246 TRefByValue<const TDesC> aFmt, ... ) |
246 TRefByValue<const TDesC> aFmt, ... ) |
247 { |
247 { |
248 LOGSTR1( "ATMH CustomUser::SetupThreadHeap()" ); |
248 LOGSTR1( "ATMH CustomUser::SetupThreadHeap()" ); |
249 LOGSTR2( "ATMH > Thread id(%d)", RThread().Id().operator TUint() ); |
249 LOGSTR2( "ATMH > Thread id(%d)", RThread().Id().operator TUint() ); |
250 |
250 |
251 // Add handling of the argument list here. |
251 // Add handling of the argument list here. |
252 |
252 |
253 TInt ret( KErrNone ); |
253 TInt ret( KErrNone ); |
254 |
|
255 // Check version number |
254 // Check version number |
256 TBuf<KAtoolVersionNumberLength> atoolVer; |
255 TBuf<KAtoolVersionNumberLength> atoolVer; |
257 TBuf<KApiVersionLength> apiVer; |
256 if ( CheckVersion( aVersion, atoolVer ) != KErrNone ) |
258 TInt err( KErrNone ); |
|
259 err = CheckVersion( aVersion, atoolVer, apiVer ); |
|
260 |
|
261 if ( err ) |
|
262 { |
257 { |
263 LOGSTR1( "ATMH > Wrong API version > Inform user and Exit." ); |
258 LOGSTR1( "ATMH > Wrong API version > Inform user and Exit." ); |
264 ReportIncorrectVersion( aLogOption, aFileName, aFilePath, atoolVer ); |
259 ReportIncorrectVersion( aLogOption, aFileName, atoolVer ); |
265 return KAtoolVersionError; |
260 return KAtoolVersionError; |
266 } |
261 } |
267 |
262 |
268 // Check is this shared heap |
263 // Check is this shared heap |
269 if ( aInfo.iAllocator == NULL ) |
264 if ( aInfo.iAllocator == NULL ) |
280 TInt setErr( UserSvr::DllSetTls( KDummyHandle, dummyPtr ) ); |
275 TInt setErr( UserSvr::DllSetTls( KDummyHandle, dummyPtr ) ); |
281 LOGSTR2( "ATMH > Set Tls err(%i)", setErr ); |
276 LOGSTR2( "ATMH > Set Tls err(%i)", setErr ); |
282 #endif |
277 #endif |
283 #endif |
278 #endif |
284 // Install the RAllocator |
279 // Install the RAllocator |
285 TBuf8<KAtoolVersionLength> atoolVer8; |
280 aInfo.iAllocator = &InstallAllocator( aNotFirst, aFileName, aLogOption, aIsDebug, |
286 atoolVer8.Copy(atoolVer); |
281 aAllocCallStackSize, aFreeCallStackSize ); |
287 TBuf8<KApiVersionLength> apiVer8; |
|
288 apiVer8.Copy(apiVer); |
|
289 aInfo.iAllocator = &InstallAllocator( aNotFirst, aFileName, aFilePath, aLogOption, aIsDebug, |
|
290 aAllocCallStackSize, aFreeCallStackSize, atoolVer8, apiVer8 ); |
|
291 } |
282 } |
292 else |
283 else |
293 { |
284 { |
294 LOGSTR1( "ATMH sharing the heap" ); |
285 LOGSTR1( "ATMH sharing the heap" ); |
295 // The heap is shared. Acquire pointer to the original heap |
286 // The heap is shared. Acquire pointer to the original heap |
298 // Share the heap |
289 // Share the heap |
299 allocator->ShareHeap(); |
290 allocator->ShareHeap(); |
300 // Switch thread heap |
291 // Switch thread heap |
301 User::SwitchAllocator( allocator ); |
292 User::SwitchAllocator( allocator ); |
302 } |
293 } |
303 |
|
304 |
|
305 return ret; |
294 return ret; |
306 } |
295 } |
307 |
296 |
308 // ----------------------------------------------------------------------------- |
297 // ----------------------------------------------------------------------------- |
309 // CustomUser::InstallAllocator |
298 // CustomUser::InstallAllocator |
310 // Installs the RAllocator |
299 // Installs the RAllocator |
311 // ----------------------------------------------------------------------------- |
300 // ----------------------------------------------------------------------------- |
312 // |
301 // |
313 //lint -e{429} suppress "Custodial pointer 'allocator' has not been freed or returned" |
302 //lint -e{429} suppress "Custodial pointer 'allocator' has not been freed or returned" |
314 EXPORT_C RAllocator& CustomUser::InstallAllocator( TBool aNotFirst, |
303 EXPORT_C RAllocator& CustomUser::InstallAllocator( TBool aNotFirst, |
315 const TFileName& aFileName, const TPath& aFilePath, TUint32 aLogOption, TUint32 aIsDebug, |
304 const TFileName& aFileName, TUint32 aLogOption, TUint32 aIsDebug, |
316 TUint32 aAllocCallStackSize, TUint32 aFreeCallStackSize, const TDesC8& aAtoolVersion, const TDesC8& aApiVersion ) |
305 TUint32 aAllocCallStackSize, TUint32 aFreeCallStackSize ) |
317 { |
306 { |
318 LOGSTR1( "ATMH CustomUser::InstallAllocator()" ); |
307 LOGSTR1( "ATMH CustomUser::InstallAllocator()" ); |
319 |
308 |
320 // Open handle to the device driver |
309 // Open handle to the device driver |
321 RAnalyzeTool analyzetool; |
310 RAnalyzeTool analyzetool; |
340 if ( params().iAlone ) |
329 if ( params().iAlone ) |
341 { |
330 { |
342 LOGSTR1( "ATMH CustomUser::InstallAllocator() - first thread of the program" ); |
331 LOGSTR1( "ATMH CustomUser::InstallAllocator() - first thread of the program" ); |
343 // Only one thread in the program. Must be main thread |
332 // Only one thread in the program. Must be main thread |
344 RAnalyzeToolMainAllocator* allocator = |
333 RAnalyzeToolMainAllocator* allocator = |
345 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aFilePath, aLogOption, |
334 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aLogOption, |
346 aIsDebug, aAllocCallStackSize, aFreeCallStackSize, |
335 aIsDebug, aAllocCallStackSize, aFreeCallStackSize ); |
347 aAtoolVersion, aApiVersion ); |
|
348 |
336 |
349 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
337 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
350 |
338 |
351 // Change threads allocator |
339 // Change threads allocator |
352 User::SwitchAllocator( allocator ); |
340 User::SwitchAllocator( allocator ); |
359 { |
347 { |
360 LOGSTR1( "ATMH CustomUser::InstallAllocator() - create a new allocator for the new thread" ); |
348 LOGSTR1( "ATMH CustomUser::InstallAllocator() - create a new allocator for the new thread" ); |
361 // Create new RAllocator with handles from the main thread |
349 // Create new RAllocator with handles from the main thread |
362 RAnalyzeToolAllocator* allocator = new RAnalyzeToolAllocator( |
350 RAnalyzeToolAllocator* allocator = new RAnalyzeToolAllocator( |
363 aNotFirst, |
351 aNotFirst, |
|
352 ((RAnalyzeToolMainAllocator*)params().iAllocator)->StorageServer(), |
364 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Codeblocks(), |
353 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Codeblocks(), |
365 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Mutex(), |
354 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Mutex(), |
366 ((RAnalyzeToolMainAllocator*)params().iAllocator)->ProcessId(), |
355 ((RAnalyzeToolMainAllocator*)params().iAllocator)->ProcessId(), |
367 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AnalyzeTool(), |
356 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AnalyzeTool(), |
|
357 ((RAnalyzeToolMainAllocator*)params().iAllocator)->StorageServerOpen(), |
368 ((RAnalyzeToolMainAllocator*)params().iAllocator)->LogOption(), |
358 ((RAnalyzeToolMainAllocator*)params().iAllocator)->LogOption(), |
369 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AllocMaxCallStack(), |
359 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AllocMaxCallStack(), |
370 ((RAnalyzeToolMainAllocator*)params().iAllocator)->FreeMaxCallStack(), |
360 ((RAnalyzeToolMainAllocator*)params().iAllocator)->FreeMaxCallStack() ); |
371 ((RAnalyzeToolMainAllocator*)params().iAllocator)->LogFile() ); |
|
372 |
361 |
373 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
362 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
374 |
363 |
375 // Change threads allocator |
364 // Change threads allocator |
376 User::SwitchAllocator( allocator ); |
365 User::SwitchAllocator( allocator ); |
382 // The device driver does not exists so this must be the first thread |
371 // The device driver does not exists so this must be the first thread |
383 else |
372 else |
384 { |
373 { |
385 LOGSTR1( "ATMH CustomUser::InstallAllocator() - analyzetool.Open() returned error, creating DD" ); |
374 LOGSTR1( "ATMH CustomUser::InstallAllocator() - analyzetool.Open() returned error, creating DD" ); |
386 RAnalyzeToolMainAllocator* allocator = |
375 RAnalyzeToolMainAllocator* allocator = |
387 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aFilePath, aLogOption, aIsDebug, |
376 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aLogOption, aIsDebug, |
388 aAllocCallStackSize, aFreeCallStackSize, aAtoolVersion, aApiVersion ); |
377 aAllocCallStackSize, aFreeCallStackSize ); |
389 |
378 |
390 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
379 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
391 |
380 |
392 // Change threads allocator |
381 // Change threads allocator |
393 User::SwitchAllocator( allocator ); |
382 User::SwitchAllocator( allocator ); |
400 // ----------------------------------------------------------------------------- |
389 // ----------------------------------------------------------------------------- |
401 // CustomUser::CheckVersion |
390 // CustomUser::CheckVersion |
402 // Check atool version |
391 // Check atool version |
403 // ----------------------------------------------------------------------------- |
392 // ----------------------------------------------------------------------------- |
404 // |
393 // |
405 TInt CustomUser::CheckVersion( const TATVersion& aVersion, TDes& aToolVersion, TDes& aApiVersion ) |
394 TInt CustomUser::CheckVersion( const TATVersion& aVersion, TDes& aToolVersion ) |
406 { |
395 { |
407 LOGSTR2( "ATMH CustomUser::CheckVersion(), aVersion( %S )", &aVersion ); |
396 LOGSTR2( "ATMH CustomUser::CheckVersion(), aVersion( %S )", &aVersion ); |
408 |
397 |
409 TFileName version; |
398 TFileName version; |
410 version.Copy( aVersion ); |
399 version.Copy( aVersion ); |
411 TBuf<KAtoolVersionNumberLength> apiVer; |
400 TBuf<KAtoolVersionNumberLength> apiVer; |
412 |
401 |
413 // Find separator place |
402 // Find separator place |
414 TInt findplace( version.Find( KVersionSeparator() ) ); |
403 TInt findplace( version.Find( KVersionSeparator() ) ); |
415 // Parse API version first [x.x.x;x.x.x] |
404 // Parse API version first [x.x.x;x.x.x] |
416 if ( findplace >= 0 && findplace <= aApiVersion.MaxLength() ) |
405 if ( findplace >= 0 && findplace <= apiVer.MaxLength() ) |
417 { |
406 { |
418 aApiVersion.Copy( version.Mid( 0, findplace ) ); |
407 apiVer.Copy( version.Mid( 0, findplace ) ); |
419 version.Delete( 0, findplace + KVersionSeparator().Length() ); |
408 version.Delete( 0, findplace + KVersionSeparator().Length() ); |
420 } |
409 } |
421 |
410 |
422 if ( version.Length() <= aToolVersion.MaxLength() ) |
411 if ( version.Length() <= aToolVersion.MaxLength() ) |
423 { |
412 { |
424 aToolVersion.Copy( version ); |
413 aToolVersion.Copy( version ); |
425 if ( aToolVersion.Compare( KAtoolApiVersion ) == KErrNone && |
414 if ( aToolVersion.Compare( KAtoolApiVersion ) == KErrNone && |
426 aApiVersion.Length() == 0 ) |
415 apiVer.Length() == 0 ) |
427 { |
416 { |
428 // Support 1.5.0 version (Version info: [1.5.0]) |
417 // Support 1.5.0 version (Version info: [1.5.0]) |
429 aApiVersion.Copy( version ); |
418 apiVer.Copy( version ); |
430 } |
419 } |
431 } |
420 } |
432 |
421 |
433 LOGSTR3( "ATMH > API version( %S ), ATOOL version( %S )", |
422 LOGSTR3( "ATMH > API version( %S ), ATOOL version( %S )", |
434 &aApiVersion, &aToolVersion ); |
423 &apiVer, &aToolVersion ); |
435 |
424 |
436 // Check version numbers |
425 // Check version numbers |
437 if ( aApiVersion.Compare( KAtoolApiVersion ) == KErrNone ) |
426 if ( apiVer.Compare( KAtoolApiVersion ) == KErrNone ) |
438 { |
427 { |
439 return KErrNone; |
428 return KErrNone; |
440 } |
429 } |
441 return KErrCancel; |
430 return KErrCancel; |
442 } |
431 } |
445 // CustomUser::ReportIncorrectVersion |
434 // CustomUser::ReportIncorrectVersion |
446 // Function for showing incorrect version information |
435 // Function for showing incorrect version information |
447 // ----------------------------------------------------------------------------- |
436 // ----------------------------------------------------------------------------- |
448 // |
437 // |
449 void CustomUser::ReportIncorrectVersion( const TUint32 aLogOption, |
438 void CustomUser::ReportIncorrectVersion( const TUint32 aLogOption, |
450 const TFileName& aFileName, const TPath& aFilePath, const TDes& aToolVersion ) |
439 const TFileName& aFileName, const TDes& aToolVersion ) |
451 { |
440 { |
452 LOGSTR2( "ATMH CustomUser::ReportIncorrectVersion(), aFileName( %S )", |
441 LOGSTR2( "ATMH CustomUser::ReportIncorrectVersion(), aFileName( %S )", |
453 &aFileName ); |
442 &aFileName ); |
454 |
443 |
455 switch ( aLogOption ) |
444 switch ( aLogOption ) |
456 { |
445 { |
457 case EATLogToFile: |
446 case EATLogToFile: |
458 { |
447 { |
459 LOGSTR1( "ATMH ReportIncorrectVersion > EATLogToFile" ); |
448 LOGSTR1( "ATMH ReportIncorrectVersion > EATLogToFile" ); |
468 // Connects a client to the file server. |
457 // Connects a client to the file server. |
469 TInt err( fs.Connect() ); |
458 TInt err( fs.Connect() ); |
470 |
459 |
471 if ( !err ) |
460 if ( !err ) |
472 { |
461 { |
473 err = TATDriveInfo::CreatePath( logFileBuf, aFileName, aFilePath, fs ); |
462 err = TATDriveInfo::CreatePath( logFileBuf, aFileName, fs ); |
474 |
463 |
475 // Replace file if exists |
464 // Replace file if exists |
476 if ( err && err != KErrAlreadyExists ) |
465 if ( err && err != KErrAlreadyExists ) |
477 { |
466 { |
478 LOGSTR2( "ATMH > TATDriveInfo::CreatePath() err( %i )", err ); |
467 LOGSTR2( "ATMH > TATDriveInfo::CreatePath() err( %i )", err ); |