22 #define RANDOM_BUFSIZE 4096
28 static DWORD threadID;
50 FILETIME creationTime, exitTime, kernelTime, userTime;
51 LARGE_INTEGER performanceCount;
52 SYSTEM_POWER_STATUS_EX2 powerStatus;
53 MEMORYSTATUS memoryStatus;
66 if( pCeGenRandom == NULL )
70 if( ( hCoreDLL = GetModuleHandle(
TEXT(
"Coredll.dll" ) ) ) != NULL )
71 pCeGenRandom = (
CEGENRANDOM ) GetProcAddress( hCoreDLL,
TEXT(
"CeGenRandom" ) );
73 if( pGetSystemPowerStatusEx2 == NULL )
77 if( ( hGetpower = GetModuleHandle(
TEXT(
"Getpower.dll" ) ) ) != NULL )
79 GetProcAddress( hGetpower,
TEXT(
"GetSystemPowerStatusEx2" ) );
116 GetCaretPos( &point );
117 addRandomData( randomState, &point,
sizeof( POINT ) );
118 GetCursorPos( &point );
119 addRandomData( randomState, &point,
sizeof( POINT ) );
124 memoryStatus.dwLength =
sizeof( MEMORYSTATUS );
125 GlobalMemoryStatus( &memoryStatus );
126 addRandomData( randomState, &memoryStatus,
sizeof( MEMORYSTATUS ) );
130 handle = GetCurrentThread();
131 GetThreadTimes( handle, &creationTime, &exitTime, &kernelTime, &userTime );
132 addRandomData( randomState, &creationTime,
sizeof( FILETIME ) );
133 addRandomData( randomState, &exitTime,
sizeof( FILETIME ) );
134 addRandomData( randomState, &kernelTime,
sizeof( FILETIME ) );
135 addRandomData( randomState, &userTime,
sizeof( FILETIME ) );
140 if( pGetSystemPowerStatusEx2 != NULL && \
142 pGetSystemPowerStatusEx2( &powerStatus,
143 sizeof( SYSTEM_POWER_STATUS_EX2 ),
145 addRandomData( randomState, &powerStatus, length );
150 if( pCeGenRandom != NULL )
152 BYTE randomBuffer[ 32 ];
154 if( pCeGenRandom( 32, randomBuffer ) )
155 addRandomData( randomState, randomBuffer, 32 );
160 if( !addedFixedItems )
162 SYSTEM_INFO systemInfo;
164 GetSystemInfo( &systemInfo );
165 addRandomData( randomState, &systemInfo,
sizeof( SYSTEM_INFO ) );
166 addedFixedItems =
TRUE;
176 if( QueryPerformanceCounter( &performanceCount ) )
177 addRandomData( randomState, &performanceCount,
178 sizeof( LARGE_INTEGER ) );
182 endRandomData( randomState, 34 );
199 typedef BOOL ( WINAPI *HEAPNEXT )(
HANDLE hSnapshot, LPHEAPENTRY32
lphe );
201 typedef BOOL ( WINAPI *CLOSESNAPSHOT )(
HANDLE hSnapshot );
206 static CREATESNAPSHOT pCreateToolhelp32Snapshot = NULL;
207 static CLOSESNAPSHOT pCloseToolhelp32Snapshot = NULL;
208 static MODULEWALK pModule32First = NULL;
209 static MODULEWALK pModule32Next = NULL;
210 static PROCESSWALK pProcess32First = NULL;
211 static PROCESSWALK pProcess32Next = NULL;
212 static THREADWALK pThread32First = NULL;
213 static THREADWALK pThread32Next = NULL;
214 static HEAPLISTWALK pHeap32ListFirst = NULL;
215 static HEAPLISTWALK pHeap32ListNext = NULL;
216 static HEAPFIRST pHeap32First = NULL;
217 static HEAPNEXT pHeap32Next = NULL;
222 #define BIG_RANDOM_BUFSIZE ( RANDOM_BUFSIZE * 4 )
224 static void slowPollWinCE(
void )
238 if( hToolHelp32 == NULL )
242 if( ( hToolHelp32 = LoadLibrary(
TEXT(
"Toolhelp.dll" ) ) ) == NULL )
251 pCreateToolhelp32Snapshot = ( CREATESNAPSHOT ) GetProcAddress( hToolHelp32,
TEXT(
"CreateToolhelp32Snapshot" ) );
252 pCloseToolhelp32Snapshot = ( CLOSESNAPSHOT ) GetProcAddress( hToolHelp32,
TEXT(
"CloseToolhelp32Snapshot" ) );
253 pModule32First = ( MODULEWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Module32First" ) );
254 pModule32Next = ( MODULEWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Module32Next" ) );
255 pProcess32First = ( PROCESSWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Process32First" ) );
256 pProcess32Next = ( PROCESSWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Process32Next" ) );
257 pThread32First = ( THREADWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Thread32First" ) );
258 pThread32Next = ( THREADWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Thread32Next" ) );
259 pHeap32ListFirst = ( HEAPLISTWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Heap32ListFirst" ) );
260 pHeap32ListNext = ( HEAPLISTWALK ) GetProcAddress( hToolHelp32,
TEXT(
"Heap32ListNext" ) );
261 pHeap32First = ( HEAPFIRST ) GetProcAddress( hToolHelp32,
TEXT(
"Heap32First" ) );
262 pHeap32Next = ( HEAPNEXT ) GetProcAddress( hToolHelp32,
TEXT(
"Heap32Next" ) );
265 if( pModule32First == NULL || pModule32Next == NULL || \
266 pProcess32First == NULL || pProcess32Next == NULL || \
267 pThread32First == NULL || pThread32Next == NULL || \
268 pHeap32ListFirst == NULL || pHeap32ListNext == NULL || \
269 pHeap32First == NULL || pHeap32Next == NULL || \
270 pCreateToolhelp32Snapshot == NULL )
274 pCreateToolhelp32Snapshot = NULL;
310 hSnapshot = pCreateToolhelp32Snapshot( TH32CS_SNAPHEAPLIST, 0 );
311 if( hSnapshot == INVALID_HANDLE_VALUE )
316 hl32.dwSize =
sizeof( HEAPLIST32 );
317 if( pHeap32ListFirst( hSnapshot, &hl32 ) )
329 pCloseToolhelp32Snapshot( hSnapshot );
332 addRandomData( randomState, &hl32,
sizeof( HEAPLIST32 ) );
336 he32.dwSize =
sizeof( HEAPENTRY32 );
337 if( pHeap32First( hSnapshot, &he32, hl32.th32ProcessID, hl32.th32HeapID ) )
345 pCloseToolhelp32Snapshot( hSnapshot );
348 addRandomData( randomState, &he32,
349 sizeof( HEAPENTRY32 ) );
351 while( entryCount++ < 20 && pHeap32Next( hSnapshot, &he32 ) );
354 while( listCount++ < 20 && pHeap32ListNext( hSnapshot, &hl32 ) );
356 pCloseToolhelp32Snapshot( hSnapshot );
361 hSnapshot = pCreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
362 if( hSnapshot == INVALID_HANDLE_VALUE )
364 endRandomData( randomState, 40 );
367 pe32.dwSize =
sizeof( PROCESSENTRY32 );
369 if( pProcess32First( hSnapshot, &pe32 ) )
375 pCloseToolhelp32Snapshot( hSnapshot );
378 addRandomData( randomState, &pe32,
sizeof( PROCESSENTRY32 ) );
380 while( pProcess32Next( hSnapshot, &pe32 ) && \
383 pCloseToolhelp32Snapshot( hSnapshot );
388 hSnapshot = pCreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
389 if( hSnapshot == INVALID_HANDLE_VALUE )
391 endRandomData( randomState, 60 );
394 te32.dwSize =
sizeof( THREADENTRY32 );
396 if( pThread32First( hSnapshot, &te32 ) )
402 pCloseToolhelp32Snapshot( hSnapshot );
405 addRandomData( randomState, &te32,
sizeof( THREADENTRY32 ) );
407 while( pThread32Next( hSnapshot, &te32 ) && \
410 pCloseToolhelp32Snapshot( hSnapshot );
415 hSnapshot = pCreateToolhelp32Snapshot( TH32CS_SNAPMODULE, 0 );
416 if( hSnapshot == INVALID_HANDLE_VALUE )
418 endRandomData( randomState, 80 );
421 me32.dwSize =
sizeof( MODULEENTRY32 );
423 if( pModule32First( hSnapshot, &me32 ) )
429 pCloseToolhelp32Snapshot( hSnapshot );
432 addRandomData( randomState, &me32,
sizeof( MODULEENTRY32 ) );
434 while( pModule32Next( hSnapshot, &me32 ) && \
437 pCloseToolhelp32Snapshot( hSnapshot );
442 endRandomData( randomState, 100 );
481 const DWORD timeout = force ? 2000 : 300000L;
491 if( hThread == NULL )
498 dwResult = WaitForSingleObject( hThread, timeout );
499 if( dwResult == WAIT_FAILED )
506 assert( dwResult != WAIT_FAILED );
512 if( hThread != NULL )
514 CloseHandle( hThread );
527 hToolHelp32 = hThread = NULL;
532 assert( hThread == NULL );
535 FreeLibrary( hToolHelp32 );