eapol/eapol_framework/eapol_common/am/include/eap_am_memory.h
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 
       
    20 
       
    21 #if !defined(_EAP_MEMORY_H_)
       
    22 #define _EAP_MEMORY_H_
       
    23 
       
    24 
       
    25 #if !defined(USE_EAP_MEMORY_FUNCTIONS_FAILURES)
       
    26 
       
    27 	#define g_eap_set_memory_parameters( \
       
    28 		alloc_failures_probability, \
       
    29 		alloc_failures_skip_count)
       
    30 
       
    31 	#define g_eap_alloc_failures_enabled()
       
    32 
       
    33 	#define g_eap_alloc_failures_disabled()
       
    34 
       
    35 #endif // #if defined(USE_EAP_MEMORY_FUNCTIONS_FAILURES)
       
    36 
       
    37 
       
    38 #if defined(DMALLOC) || defined(USE_EAP_MEMORY_FUNCTIONS)
       
    39 
       
    40 	#include "eap_tools.h"
       
    41 	#include "eap_variable_data.h"
       
    42 	#include "eap_am_export.h"
       
    43 
       
    44 
       
    45 	#if defined(USE_EAP_MEMORY_FUNCTIONS_FAILURES)
       
    46 
       
    47 		void g_eap_set_memory_parameters(
       
    48 			const u32_t alloc_failures_probability,
       
    49 			const u32_t alloc_failures_skip_count);
       
    50 
       
    51 		void g_eap_alloc_failures_enabled();
       
    52 
       
    53 		void g_eap_alloc_failures_disabled();
       
    54 
       
    55 		bool g_eap_alloc_failures_active();
       
    56 
       
    57 	#endif // #if defined(USE_EAP_MEMORY_FUNCTIONS_FAILURES)
       
    58 
       
    59 
       
    60 	#define USE_JPH_REALLOC
       
    61 
       
    62 	#if defined(__GNUC__)
       
    63 		#include <unistd.h>
       
    64 	#elif defined(__SYMBIAN32__)
       
    65 		#include <e32std.h>
       
    66 	#endif
       
    67 
       
    68 	#if defined(_WIN32) && !defined(__GNUC__) && defined(USE_MEMORY_LEAK_DETECTION)
       
    69 		#pragma message("Uses memory leak detection of WIN32.") 
       
    70 		#define _CRTDBG_MAP_ALLOC
       
    71 		#include <crtdbg.h>
       
    72 	#endif
       
    73 
       
    74 	#if defined(_WIN32) || defined(__GNUC__)
       
    75 		#include <stdlib.h>
       
    76 	#endif
       
    77 
       
    78 	#if defined(__cplusplus) || defined(__cc)
       
    79 	extern "C" {
       
    80 	#endif
       
    81 
       
    82 	#if defined(_WIN32)	|| defined(__GNUC__)
       
    83 		/*
       
    84 		 * An overload function the malloc.
       
    85 		 */
       
    86 		EAP_C_FUNC_IMPORT void *jph_malloc(size_t n);
       
    87 
       
    88 		/*
       
    89 		 * An overload function the malloc.
       
    90 		 */
       
    91 		EAP_C_FUNC_IMPORT void *jph_malloc_ex(size_t n, const char *file, int line);
       
    92 
       
    93 		#if defined(USE_JPH_REALLOC)
       
    94 			/*
       
    95 			 * An overload function the realloc.
       
    96 			 */
       
    97 			EAP_C_FUNC_IMPORT void *jph_realloc(void *oldbuf, size_t n);
       
    98 
       
    99 			/*
       
   100 			 * An overload function the realloc.
       
   101 			 */
       
   102 			EAP_C_FUNC_IMPORT void *jph_realloc_ex(void *oldbuf, size_t n, const char *file, int line);
       
   103 		#endif //#if defined(USE_JPH_REALLOC)
       
   104 
       
   105 		#if defined(USE_JPH_CALLOC)
       
   106 			/*
       
   107 			 * An overload function the calloc.
       
   108 			 */
       
   109 			EAP_C_FUNC_IMPORT void *jph_calloc(size_t count, size_t size);
       
   110 		#endif //#if defined(USE_JPH_CALLOC)
       
   111 
       
   112 		/*
       
   113 		 * An overload function for the free.
       
   114 		 */
       
   115 		EAP_C_FUNC_IMPORT void jph_free(void *cp);
       
   116 
       
   117 
       
   118 		EAP_C_FUNC_IMPORT void *jph_new(size_t n);
       
   119 
       
   120 		EAP_C_FUNC_IMPORT void jph_delete(void *cp);
       
   121 
       
   122 	#endif /* #if defined(_WIN32) */
       
   123 
       
   124 	#if defined(__cplusplus) || defined(__cc)
       
   125 	}
       
   126 	#endif
       
   127 
       
   128 
       
   129 	#if defined(__cplusplus) || defined(__cc)
       
   130 
       
   131 		// NOTE, gcc does not need these prototypes. These are defined internally.
       
   132 
       
   133 		#if defined(_WIN32) && !defined(__GNUC__) && !defined(__SYMBIAN32__) && !defined(USE_MEMORY_LEAK_DETECTION)
       
   134 
       
   135 			inline void *operator new(size_t n)
       
   136 			{
       
   137 				return jph_new(n);
       
   138 			}
       
   139 
       
   140 			inline void *operator new[](size_t n)
       
   141 			{
       
   142 				return jph_new(n);
       
   143 			}
       
   144 
       
   145 			inline void operator delete(void *cp)
       
   146 			{
       
   147 				if (cp)
       
   148 				{
       
   149 					jph_delete(cp);
       
   150 				}
       
   151 			}
       
   152 
       
   153 			inline void operator delete[](void *cp)
       
   154 			{
       
   155 				if (cp)
       
   156 				{
       
   157 					jph_delete(cp);
       
   158 				}
       
   159 			}
       
   160 
       
   161 		#elif defined(__GNUC__)
       
   162 
       
   163 			#include <new>
       
   164 
       
   165 			void *operator new(std::size_t n) throw (std::bad_alloc);
       
   166 
       
   167 			void *operator new[](std::size_t n) throw (std::bad_alloc);
       
   168 
       
   169 			void operator delete(void *cp) throw();
       
   170 
       
   171 			void operator delete[](void *cp) throw();
       
   172 
       
   173 		#endif //#if defined(WIN32)
       
   174 
       
   175 
       
   176 		#if defined(unix)
       
   177 			typedef int (*jph_new_handler) (size_t);
       
   178 			EAP_C_FUNC_IMPORT jph_new_handler jph_set_new_handler(jph_new_handler);
       
   179 		#elif defined(_WIN32) && !defined(__GNUC__)
       
   180 			typedef int (__cdecl * jph_new_handler) (size_t);
       
   181 			EAP_C_FUNC_IMPORT jph_new_handler __cdecl jph_set_new_handler(jph_new_handler);
       
   182 		#else
       
   183 			// Not supported in Symbian.
       
   184 		#endif
       
   185 
       
   186 
       
   187 	#endif // #if defined(__cplusplus) || defined(__cc)
       
   188 
       
   189 #elif defined(USE_EAP_GLOBAL_NEW_AND_DELETE_H)
       
   190 
       
   191 	#include "GlobalNewAndDelete.h"
       
   192 
       
   193 #endif //#if defined(DMALLOC) || defined(USE_EAP_MEMORY_FUNCTIONS)
       
   194 
       
   195 #endif //#if !defined(_EAP_MEMORY_H_)
       
   196 
       
   197 //--------------------------------------------------
       
   198 
       
   199 
       
   200 
       
   201 // End.