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" |
|
27 #include "atdriveinfo.h" |
26 #include "atdriveinfo.h" |
28 #include <analyzetool/analyzetooltraceconstants.h> |
27 #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.5" ); |
124 _LIT( KAtoolApiVersion, "1.7.6" ); |
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, "ERROR_OCCURED INCORRECT_ATOOL_VERSION [API v.%S][ATOOL v.%S]" ); |
136 _LIT( KIncorrectText, "ERR INCORRECT_ATOOL_VERSION [API v.%S][ATOOL v.%S]" ); |
137 _LIT( KIncorrectTextTrace, "PCSS " ); |
137 _LIT( KIncorrectTextTrace, "<AT> " ); |
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, |
243 SStdEpocThreadCreateInfo& aInfo, const TFileName& aFileName, const TPath& aFilePath, |
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 |
254 // Check version number |
255 // Check version number |
255 TBuf<KAtoolVersionNumberLength> atoolVer; |
256 TBuf<KAtoolVersionNumberLength> atoolVer; |
256 if ( CheckVersion( aVersion, atoolVer ) != KErrNone ) |
257 TBuf<KApiVersionLength> apiVer; |
|
258 TInt err( KErrNone ); |
|
259 err = CheckVersion( aVersion, atoolVer, apiVer ); |
|
260 |
|
261 if ( err ) |
257 { |
262 { |
258 LOGSTR1( "ATMH > Wrong API version > Inform user and Exit." ); |
263 LOGSTR1( "ATMH > Wrong API version > Inform user and Exit." ); |
259 ReportIncorrectVersion( aLogOption, aFileName, atoolVer ); |
264 ReportIncorrectVersion( aLogOption, aFileName, aFilePath, atoolVer ); |
260 return KAtoolVersionError; |
265 return KAtoolVersionError; |
261 } |
266 } |
262 |
267 |
263 // Check is this shared heap |
268 // Check is this shared heap |
264 if ( aInfo.iAllocator == NULL ) |
269 if ( aInfo.iAllocator == NULL ) |
275 TInt setErr( UserSvr::DllSetTls( KDummyHandle, dummyPtr ) ); |
280 TInt setErr( UserSvr::DllSetTls( KDummyHandle, dummyPtr ) ); |
276 LOGSTR2( "ATMH > Set Tls err(%i)", setErr ); |
281 LOGSTR2( "ATMH > Set Tls err(%i)", setErr ); |
277 #endif |
282 #endif |
278 #endif |
283 #endif |
279 // Install the RAllocator |
284 // Install the RAllocator |
280 aInfo.iAllocator = &InstallAllocator( aNotFirst, aFileName, aLogOption, aIsDebug, |
285 TBuf8<KAtoolVersionLength> atoolVer8; |
281 aAllocCallStackSize, aFreeCallStackSize ); |
286 atoolVer8.Copy(atoolVer); |
|
287 TBuf8<KApiVersionLength> apiVer8; |
|
288 apiVer8.Copy(apiVer); |
|
289 aInfo.iAllocator = &InstallAllocator( aNotFirst, aFileName, aFilePath, aLogOption, aIsDebug, |
|
290 aAllocCallStackSize, aFreeCallStackSize, atoolVer8, apiVer8 ); |
282 } |
291 } |
283 else |
292 else |
284 { |
293 { |
285 LOGSTR1( "ATMH sharing the heap" ); |
294 LOGSTR1( "ATMH sharing the heap" ); |
286 // The heap is shared. Acquire pointer to the original heap |
295 // The heap is shared. Acquire pointer to the original heap |
289 // Share the heap |
298 // Share the heap |
290 allocator->ShareHeap(); |
299 allocator->ShareHeap(); |
291 // Switch thread heap |
300 // Switch thread heap |
292 User::SwitchAllocator( allocator ); |
301 User::SwitchAllocator( allocator ); |
293 } |
302 } |
|
303 |
|
304 |
294 return ret; |
305 return ret; |
295 } |
306 } |
296 |
307 |
297 // ----------------------------------------------------------------------------- |
308 // ----------------------------------------------------------------------------- |
298 // CustomUser::InstallAllocator |
309 // CustomUser::InstallAllocator |
299 // Installs the RAllocator |
310 // Installs the RAllocator |
300 // ----------------------------------------------------------------------------- |
311 // ----------------------------------------------------------------------------- |
301 // |
312 // |
302 //lint -e{429} suppress "Custodial pointer 'allocator' has not been freed or returned" |
313 //lint -e{429} suppress "Custodial pointer 'allocator' has not been freed or returned" |
303 EXPORT_C RAllocator& CustomUser::InstallAllocator( TBool aNotFirst, |
314 EXPORT_C RAllocator& CustomUser::InstallAllocator( TBool aNotFirst, |
304 const TFileName& aFileName, TUint32 aLogOption, TUint32 aIsDebug, |
315 const TFileName& aFileName, const TPath& aFilePath, TUint32 aLogOption, TUint32 aIsDebug, |
305 TUint32 aAllocCallStackSize, TUint32 aFreeCallStackSize ) |
316 TUint32 aAllocCallStackSize, TUint32 aFreeCallStackSize, const TDesC8& aAtoolVersion, const TDesC8& aApiVersion ) |
306 { |
317 { |
307 LOGSTR1( "ATMH CustomUser::InstallAllocator()" ); |
318 LOGSTR1( "ATMH CustomUser::InstallAllocator()" ); |
308 |
319 |
309 // Open handle to the device driver |
320 // Open handle to the device driver |
310 RAnalyzeTool analyzetool; |
321 RAnalyzeTool analyzetool; |
329 if ( params().iAlone ) |
340 if ( params().iAlone ) |
330 { |
341 { |
331 LOGSTR1( "ATMH CustomUser::InstallAllocator() - first thread of the program" ); |
342 LOGSTR1( "ATMH CustomUser::InstallAllocator() - first thread of the program" ); |
332 // Only one thread in the program. Must be main thread |
343 // Only one thread in the program. Must be main thread |
333 RAnalyzeToolMainAllocator* allocator = |
344 RAnalyzeToolMainAllocator* allocator = |
334 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aLogOption, |
345 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aFilePath, aLogOption, |
335 aIsDebug, aAllocCallStackSize, aFreeCallStackSize ); |
346 aIsDebug, aAllocCallStackSize, aFreeCallStackSize, |
|
347 aAtoolVersion, aApiVersion ); |
336 |
348 |
337 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
349 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
338 |
350 |
339 // Change threads allocator |
351 // Change threads allocator |
340 User::SwitchAllocator( allocator ); |
352 User::SwitchAllocator( allocator ); |
347 { |
359 { |
348 LOGSTR1( "ATMH CustomUser::InstallAllocator() - create a new allocator for the new thread" ); |
360 LOGSTR1( "ATMH CustomUser::InstallAllocator() - create a new allocator for the new thread" ); |
349 // Create new RAllocator with handles from the main thread |
361 // Create new RAllocator with handles from the main thread |
350 RAnalyzeToolAllocator* allocator = new RAnalyzeToolAllocator( |
362 RAnalyzeToolAllocator* allocator = new RAnalyzeToolAllocator( |
351 aNotFirst, |
363 aNotFirst, |
352 ((RAnalyzeToolMainAllocator*)params().iAllocator)->StorageServer(), |
|
353 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Codeblocks(), |
364 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Codeblocks(), |
354 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Mutex(), |
365 ((RAnalyzeToolMainAllocator*)params().iAllocator)->Mutex(), |
355 ((RAnalyzeToolMainAllocator*)params().iAllocator)->ProcessId(), |
366 ((RAnalyzeToolMainAllocator*)params().iAllocator)->ProcessId(), |
356 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AnalyzeTool(), |
367 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AnalyzeTool(), |
357 ((RAnalyzeToolMainAllocator*)params().iAllocator)->StorageServerOpen(), |
|
358 ((RAnalyzeToolMainAllocator*)params().iAllocator)->LogOption(), |
368 ((RAnalyzeToolMainAllocator*)params().iAllocator)->LogOption(), |
359 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AllocMaxCallStack(), |
369 ((RAnalyzeToolMainAllocator*)params().iAllocator)->AllocMaxCallStack(), |
360 ((RAnalyzeToolMainAllocator*)params().iAllocator)->FreeMaxCallStack() ); |
370 ((RAnalyzeToolMainAllocator*)params().iAllocator)->FreeMaxCallStack(), |
|
371 ((RAnalyzeToolMainAllocator*)params().iAllocator)->LogFile() ); |
361 |
372 |
362 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
373 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
363 |
374 |
364 // Change threads allocator |
375 // Change threads allocator |
365 User::SwitchAllocator( allocator ); |
376 User::SwitchAllocator( allocator ); |
371 // The device driver does not exists so this must be the first thread |
382 // The device driver does not exists so this must be the first thread |
372 else |
383 else |
373 { |
384 { |
374 LOGSTR1( "ATMH CustomUser::InstallAllocator() - analyzetool.Open() returned error, creating DD" ); |
385 LOGSTR1( "ATMH CustomUser::InstallAllocator() - analyzetool.Open() returned error, creating DD" ); |
375 RAnalyzeToolMainAllocator* allocator = |
386 RAnalyzeToolMainAllocator* allocator = |
376 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aLogOption, aIsDebug, |
387 new RAnalyzeToolMainAllocator( aNotFirst, aFileName, aFilePath, aLogOption, aIsDebug, |
377 aAllocCallStackSize, aFreeCallStackSize ); |
388 aAllocCallStackSize, aFreeCallStackSize, aAtoolVersion, aApiVersion ); |
378 |
389 |
379 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
390 __ASSERT_ALWAYS( allocator != NULL, AssertPanic( ENoMemory ) ); |
380 |
391 |
381 // Change threads allocator |
392 // Change threads allocator |
382 User::SwitchAllocator( allocator ); |
393 User::SwitchAllocator( allocator ); |
389 // ----------------------------------------------------------------------------- |
400 // ----------------------------------------------------------------------------- |
390 // CustomUser::CheckVersion |
401 // CustomUser::CheckVersion |
391 // Check atool version |
402 // Check atool version |
392 // ----------------------------------------------------------------------------- |
403 // ----------------------------------------------------------------------------- |
393 // |
404 // |
394 TInt CustomUser::CheckVersion( const TATVersion& aVersion, TDes& aToolVersion ) |
405 TInt CustomUser::CheckVersion( const TATVersion& aVersion, TDes& aToolVersion, TDes& aApiVersion ) |
395 { |
406 { |
396 LOGSTR2( "ATMH CustomUser::CheckVersion(), aVersion( %S )", &aVersion ); |
407 LOGSTR2( "ATMH CustomUser::CheckVersion(), aVersion( %S )", &aVersion ); |
397 |
408 |
398 TFileName version; |
409 TFileName version; |
399 version.Copy( aVersion ); |
410 version.Copy( aVersion ); |
400 TBuf<KAtoolVersionNumberLength> apiVer; |
411 TBuf<KAtoolVersionNumberLength> apiVer; |
401 |
412 |
402 // Find separator place |
413 // Find separator place |
403 TInt findplace( version.Find( KVersionSeparator() ) ); |
414 TInt findplace( version.Find( KVersionSeparator() ) ); |
404 // Parse API version first [x.x.x;x.x.x] |
415 // Parse API version first [x.x.x;x.x.x] |
405 if ( findplace >= 0 && findplace <= apiVer.MaxLength() ) |
416 if ( findplace >= 0 && findplace <= aApiVersion.MaxLength() ) |
406 { |
417 { |
407 apiVer.Copy( version.Mid( 0, findplace ) ); |
418 aApiVersion.Copy( version.Mid( 0, findplace ) ); |
408 version.Delete( 0, findplace + KVersionSeparator().Length() ); |
419 version.Delete( 0, findplace + KVersionSeparator().Length() ); |
409 } |
420 } |
410 |
421 |
411 if ( version.Length() <= aToolVersion.MaxLength() ) |
422 if ( version.Length() <= aToolVersion.MaxLength() ) |
412 { |
423 { |
413 aToolVersion.Copy( version ); |
424 aToolVersion.Copy( version ); |
414 if ( aToolVersion.Compare( KAtoolApiVersion ) == KErrNone && |
425 if ( aToolVersion.Compare( KAtoolApiVersion ) == KErrNone && |
415 apiVer.Length() == 0 ) |
426 aApiVersion.Length() == 0 ) |
416 { |
427 { |
417 // Support 1.5.0 version (Version info: [1.5.0]) |
428 // Support 1.5.0 version (Version info: [1.5.0]) |
418 apiVer.Copy( version ); |
429 aApiVersion.Copy( version ); |
419 } |
430 } |
420 } |
431 } |
421 |
432 |
422 LOGSTR3( "ATMH > API version( %S ), ATOOL version( %S )", |
433 LOGSTR3( "ATMH > API version( %S ), ATOOL version( %S )", |
423 &apiVer, &aToolVersion ); |
434 &aApiVersion, &aToolVersion ); |
424 |
435 |
425 // Check version numbers |
436 // Check version numbers |
426 if ( apiVer.Compare( KAtoolApiVersion ) == KErrNone ) |
437 if ( aApiVersion.Compare( KAtoolApiVersion ) == KErrNone ) |
427 { |
438 { |
428 return KErrNone; |
439 return KErrNone; |
429 } |
440 } |
430 return KErrCancel; |
441 return KErrCancel; |
431 } |
442 } |
434 // CustomUser::ReportIncorrectVersion |
445 // CustomUser::ReportIncorrectVersion |
435 // Function for showing incorrect version information |
446 // Function for showing incorrect version information |
436 // ----------------------------------------------------------------------------- |
447 // ----------------------------------------------------------------------------- |
437 // |
448 // |
438 void CustomUser::ReportIncorrectVersion( const TUint32 aLogOption, |
449 void CustomUser::ReportIncorrectVersion( const TUint32 aLogOption, |
439 const TFileName& aFileName, const TDes& aToolVersion ) |
450 const TFileName& aFileName, const TPath& aFilePath, const TDes& aToolVersion ) |
440 { |
451 { |
441 LOGSTR2( "ATMH CustomUser::ReportIncorrectVersion(), aFileName( %S )", |
452 LOGSTR2( "ATMH CustomUser::ReportIncorrectVersion(), aFileName( %S )", |
442 &aFileName ); |
453 &aFileName ); |
443 |
454 |
444 switch ( aLogOption ) |
455 switch ( aLogOption ) |
445 { |
456 { |
446 case EATLogToFile: |
457 case EATLogToFile: |
447 { |
458 { |
448 LOGSTR1( "ATMH ReportIncorrectVersion > EATLogToFile" ); |
459 LOGSTR1( "ATMH ReportIncorrectVersion > EATLogToFile" ); |
457 // Connects a client to the file server. |
468 // Connects a client to the file server. |
458 TInt err( fs.Connect() ); |
469 TInt err( fs.Connect() ); |
459 |
470 |
460 if ( !err ) |
471 if ( !err ) |
461 { |
472 { |
462 err = TATDriveInfo::CreatePath( logFileBuf, aFileName, fs ); |
473 err = TATDriveInfo::CreatePath( logFileBuf, aFileName, aFilePath, fs ); |
463 |
474 |
464 // Replace file if exists |
475 // Replace file if exists |
465 if ( err && err != KErrAlreadyExists ) |
476 if ( err && err != KErrAlreadyExists ) |
466 { |
477 { |
467 LOGSTR2( "ATMH > TATDriveInfo::CreatePath() err( %i )", err ); |
478 LOGSTR2( "ATMH > TATDriveInfo::CreatePath() err( %i )", err ); |