28 static
int getDynData(
OUT DYNBUF *dynBuf,
31 IN_INT const int messageParam )
50 dynBuf->data = dynBuf->dataBuffer;
55 status =
krnlSendMessage( cryptHandle, message, &msgData, messageParam );
64 msgData.data = dataPtr;
69 clFree(
"dynCreate", dataPtr );
72 dynBuf->data = dataPtr;
78 msgData.data = dynBuf->data;
84 dynBuf->length = msgData.
length;
123 assert(
isWritePtr( dynBuf->data, dynBuf->length ) );
128 zeroise( dynBuf->data, dynBuf->length );
129 if( dynBuf->data != dynBuf->dataBuffer )
130 clFree(
"dynDestroy", dynBuf->data );
149 BUFFER( storageSize, storagePos )
151 int storageSize, storagePos;
158 if( state->storageSize < 64 || \
163 if( state->storagePos < 0 || \
165 state->storagePos > state->storageSize )
172 int initMemPool(
OUT void *statePtr,
181 #if defined( __WIN32__ ) && defined( _MSC_VER )
182 #pragma warning( disable: 4127 )
186 #if defined( __WIN32__ ) && defined( _MSC_VER )
187 #pragma warning( 4: 4127 )
202 const int allocSize =
roundUp( size,
sizeof(
int ) );
247 if( memblock >= state->
storage && \
248 memblock < (
void * ) ( (
BYTE * ) state->
storage + \
253 clFree(
"freeMemPool", memblock );
269 #ifdef CONFIG_DEBUG_MALLOC
280 wchar_t wcBuffer[ 1024 + 8 ];
285 va_start( argPtr, format );
286 length =
vsprintf_s( buffer, 1024, format, argPtr );
290 mbstowcs( wcBuffer, buffer, length + 1 );
291 NKDbgPrintfW( wcBuffer );
296 #define printf wcPrintf
300 static int clAllocIndex = 0;
302 void *clAllocFn(
const char *
fileName,
const char *fnName,
303 const int lineNo,
size_t size )
305 #ifdef CONFIG_MALLOCTEST
306 static int mallocCount = 0, mallocFailCount = 0;
308 char buffer[ 512 + 8 ];
312 assert( fileName != NULL );
313 assert( fnName != NULL );
314 assert( lineNo > 0 );
319 #if defined( __WIN32__ ) || defined( __UNIX__ )
320 if( getcwd( buffer, 512 ) != NULL )
322 const int pathLen = strlen( buffer ) + 1;
324 assert( pathLen < strlen( fileName ) );
329 length =
DEBUG_PRINT(
"ALLOC: %s:%s:%d", fileName, fnName, lineNo );
335 DEBUG_PRINT(
" %4d - %d bytes.\n", clAllocIndex, size );
336 #ifdef CONFIG_MALLOCTEST
339 if( mallocCount >= mallocFailCount )
348 if( ( memPtr = malloc( size +
sizeof( LONG ) ) ) == NULL )
355 void clFreeFn(
const char *fileName,
const char *fnName,
356 const int lineNo,
void *memblock )
358 char buffer[ 512 + 8 ];
359 BYTE *memPtr = (
BYTE * ) memblock -
sizeof( LONG );
362 assert( fileName != NULL );
363 assert( fnName != NULL );
364 assert( lineNo > 0 );
368 #if defined( __WIN32__ ) || defined( __UNIX__ )
369 if( getcwd( buffer, 512 ) != NULL )
371 const int pathLen = strlen( buffer ) + 1;
373 assert( pathLen < strlen( fileName ) );
379 memPtr -=
sizeof( LONG );
380 length =
DEBUG_PRINT(
"FREE : %s:%s:%d", fileName, fnName, lineNo );
393 #ifdef CONFIG_FAULT_MALLOC
395 static int currentAllocCount = 0, failAllocCount = 8;
398 void clFaultSet(
const int number )
400 currentAllocCount = 0;
401 failAllocCount = number;
405 void *clFaultAllocFn(
const char *fileName,
const char *fnName,
406 const int lineNo,
size_t size )
414 DEBUG_PRINT(
"\n<<< Further allocation call from thread %X after "
415 "previous call failed, called from %s line %d in "
416 "%s.>>>\n", GetCurrentThreadId(), fnName, lineNo,
419 DEBUG_PRINT(
"\n<<< Further allocation call after previous call "
420 "failed, called from %s line %d in %s.>>>\n", fnName,
423 if( failAllocCount < 15 )
425 DEBUG_PRINT(
"<<< (This could be because of a multithreaded "
433 if( currentAllocCount < failAllocCount )
436 return( malloc( size ) );
441 DEBUG_PRINT(
"\n<<< Failing allocation call #%d for thread %X, called "
442 "from %s line %d in %s.>>>\n\n", failAllocCount + 1,
443 GetCurrentThreadId(), fnName, lineNo, fileName );
445 DEBUG_PRINT(
"\n<<< Failing at allocation call #%d, called from %s line "
446 "%d in %s.>>>\n\n", failAllocCount + 1, fnName, lineNo,