eapol/eapol_framework/eapol_common/am/common/stack/eap_am_stack_trace.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 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 the License "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:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 17 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 
       
    29 #if defined(unix)
       
    30 	#include <unistd.h>
       
    31 #endif
       
    32 #if defined(WIN32)
       
    33 	#include <windows.h>
       
    34 #endif
       
    35 
       
    36 #if !defined(__SYMBIAN32__)
       
    37 	#include <stdlib.h>
       
    38 	#include <stdio.h>
       
    39 	#include <setjmp.h>
       
    40 	#include <assert.h>
       
    41 #endif //#if !defined(__SYMBIAN32__)
       
    42 
       
    43 #include "eap_am_stack_trace.h"
       
    44 
       
    45 #include "abs_eap_am_tools.h"
       
    46 #include "eap_am_tools.h"
       
    47 
       
    48 /********************************************************************/
       
    49 
       
    50 EAP_FUNC_EXPORT stack_trace::~stack_trace()
       
    51 {
       
    52 }
       
    53 
       
    54 /********************************************************************/
       
    55 
       
    56 EAP_FUNC_EXPORT stack_trace::stack_trace(abs_eap_am_tools_c * const tools)
       
    57 : m_am_tools(tools)
       
    58 {
       
    59 }
       
    60 
       
    61 /********************************************************************/
       
    62 
       
    63 EAP_FUNC_EXPORT void stack_trace::trace_frames(
       
    64 	unsigned long *bp
       
    65 )
       
    66 {
       
    67 
       
    68 #if !defined(__SYMBIAN32__)
       
    69 
       
    70 	unsigned long *tmp_bp = bp;
       
    71 
       
    72 	if (bp == 0)
       
    73 	{
       
    74 		return;
       
    75 	}
       
    76 
       
    77 	while ( tmp_bp != 0x0 && tmp_bp < reinterpret_cast<unsigned long *>(0xbffff8ec)
       
    78 #if defined(linux)
       
    79 			&& tmp_bp > reinterpret_cast<unsigned long *>(0xbf800000)
       
    80 #else
       
    81 			&& tmp_bp < reinterpret_cast<unsigned long *>(0x77000000)
       
    82 #endif
       
    83 			   )
       
    84 	{
       
    85 
       
    86 		EAP_TRACE_ALWAYS(m_am_tools, TRACE_FLAGS_DEFAULT,
       
    87 						(EAPL("function: 0x%08x\n"),
       
    88 						 reinterpret_cast<void *>(*(tmp_bp+1))));
       
    89 
       
    90 		tmp_bp = reinterpret_cast<unsigned long *>(*tmp_bp);
       
    91 	}
       
    92 
       
    93 #else
       
    94 
       
    95 	EAP_UNREFERENCED_PARAMETER(bp);
       
    96 
       
    97 #endif //#if !defined(__SYMBIAN32__)
       
    98 
       
    99 }
       
   100 
       
   101 /********************************************************************/
       
   102 
       
   103 
       
   104 EAP_FUNC_EXPORT void stack_trace::trace(const void * const memory_address)
       
   105 {
       
   106 
       
   107 #if defined(__SYMBIAN32__) && (defined(USE_EAP_STACK_TRACE) || defined(USE_EAP_ASSERT_STACK_TRACE))
       
   108 
       
   109 	u32_t current_sp = 0;
       
   110 
       
   111 #if 0
       
   112 	// Thumb does not support inline assembler.
       
   113 	__asm
       
   114 	{
       
   115 		MOV current_sp, __current_sp()
       
   116 	}
       
   117 #else
       
   118 	current_sp = reinterpret_cast<u32_t>(&current_sp);
       
   119 #endif
       
   120 
       
   121 	if (current_sp == 0)
       
   122 	{
       
   123 		EAP_TRACE_ERROR(
       
   124 			m_am_tools,
       
   125 			TRACE_FLAGS_DEFAULT,
       
   126 			(EAPL("Cannot obtain current stack pointer.\n")));
       
   127 	}
       
   128 
       
   129 	TThreadStackInfo aInfo;
       
   130 
       
   131 	RThread current_thread;
       
   132 	
       
   133 	if (current_thread.StackInfo(aInfo) != KErrNone)
       
   134 	{
       
   135 		EAP_TRACE_ERROR(
       
   136 			m_am_tools,
       
   137 			TRACE_FLAGS_DEFAULT,
       
   138 			(EAPL("Cannot obtain stack information.\n")));
       
   139 	}
       
   140 
       
   141 	if (aInfo.iBase < current_sp)
       
   142 	{
       
   143 		EAP_TRACE_ERROR(
       
   144 			m_am_tools,
       
   145 			TRACE_FLAGS_DEFAULT,
       
   146 			(EAPL("Stack start %d < current stack pointer %d.\n"),
       
   147 			 aInfo.iBase,
       
   148 			 current_sp));
       
   149 	}
       
   150 
       
   151 	u32_t *start_address = reinterpret_cast<u32_t *>(current_sp);
       
   152 	u32_t *address = start_address;
       
   153 
       
   154 	EAP_TRACE_ALWAYS(m_am_tools, TRACE_FLAGS_DEFAULT,
       
   155 					(EAPL("address 0x%08x, accessed from:.\n"),
       
   156 					 memory_address));
       
   157 
       
   158 	while (reinterpret_cast<TLinAddr>(address) >= aInfo.iLimit)
       
   159 	{
       
   160 		EAP_TRACE_ALWAYS(
       
   161 			m_am_tools,
       
   162 			TRACE_FLAGS_DEFAULT,
       
   163 			(EAPL("stack address 0x%08x: 0x%08x\n"),
       
   164 			 address,
       
   165 			 *address));
       
   166 
       
   167 		--address;
       
   168 	}
       
   169 
       
   170 	EAP_TRACE_ALWAYS(m_am_tools, TRACE_FLAGS_DEFAULT,
       
   171 					(EAPL("\n")));
       
   172 	EAP_TRACE_ALWAYS(m_am_tools, TRACE_FLAGS_DEFAULT,
       
   173 					(EAPL("address 0x%08x, accessed from:.\n"),
       
   174 					 memory_address));
       
   175 
       
   176 	address = start_address;
       
   177 
       
   178 	while (reinterpret_cast<TLinAddr>(address) < aInfo.iBase)
       
   179 	{
       
   180 		EAP_TRACE_ALWAYS(
       
   181 			m_am_tools,
       
   182 			TRACE_FLAGS_DEFAULT,
       
   183 			(EAPL("stack address 0x%08x: 0x%08x\n"),
       
   184 			 address,
       
   185 			 *address));
       
   186 
       
   187 		++address;
       
   188 	}
       
   189 
       
   190 #elif (defined(unix) || defined(WIN32)) && (defined(USE_EAP_STACK_TRACE) || defined(USE_EAP_ASSERT_STACK_TRACE))
       
   191 
       
   192 	jmp_buf tmp_buf;
       
   193 
       
   194 
       
   195 #if defined(linux)
       
   196 	_setjmp( tmp_buf );
       
   197 #else
       
   198 	setjmp( tmp_buf );
       
   199 #endif
       
   200 
       
   201 
       
   202 	EAP_TRACE_ALWAYS(m_am_tools, TRACE_FLAGS_DEFAULT,
       
   203 					(EAPL("address 0x%08x, accessed from:.\n"),
       
   204 					 memory_address));
       
   205 
       
   206 
       
   207 	trace_frames(
       
   208 		#if defined(linux)
       
   209 			reinterpret_cast<unsigned long *>(tmp_buf->__jmpbuf[JB_BP])
       
   210 		#elif defined(WIN32)
       
   211 			reinterpret_cast<unsigned long *>(((_JUMP_BUFFER *)tmp_buf)->Ebp)
       
   212 		#elif defined(cygwin)
       
   213 			reinterpret_cast<unsigned long *>(tmp_buf[0].ebp)
       
   214 		#else
       
   215 			reinterpret_cast<unsigned long *>(tmp_buf->__ebp)
       
   216 		#endif
       
   217 			);
       
   218 
       
   219 #else
       
   220 
       
   221 	EAP_UNREFERENCED_PARAMETER(memory_address);
       
   222 
       
   223 #endif //#if defined(unix) || defined(WIN32)
       
   224 
       
   225 }
       
   226 
       
   227 
       
   228 /********************************************************************/
       
   229 /* End. */