Jungo WinDriver  
Official Documentation
utils.h
Go to the documentation of this file.
1/* @JUNGO_COPYRIGHT@ */
2
3#ifndef _WD_UTILS_H_
4#define _WD_UTILS_H_
5
6#if defined(__KERNEL__)
7 #include "kpstdlib.h"
8#else
9 #include <stdio.h>
10#endif
11
12#include "windrvr.h"
13
14#if defined(__cplusplus)
15extern "C" {
16#endif
17
18#if !defined(MAX_PATH)
19 #define MAX_PATH 4096
20#endif
21
22#if defined(WIN32)
23 #define snprintf _snprintf
24 #if !defined(vsnprintf)
25 #define vsnprintf _vsnprintf
26 #endif
27#endif
28
29#if !defined(__KERNEL__)
30#if defined(UNIX)
31#include <sys/time.h>
32 typedef struct timeval TIME_TYPE;
33#else
34 typedef LARGE_INTEGER TIME_TYPE;
35#endif
36#endif /* !defined(__KERNEL__) */
37
38typedef void (DLLCALLCONV *HANDLER_FUNC)(void *pData);
39
40#if !defined(__KERNEL__)
41
57DWORD DLLCALLCONV ThreadStart(_Outptr_ HANDLE *phThread,
58 _In_ HANDLER_FUNC pFunc,
59 _In_ void *pData);
60
70void DLLCALLCONV ThreadWait(_In_ HANDLE hThread);
71#endif /* !defined(__KERNEL__) */
72
84DWORD DLLCALLCONV OsEventCreate(_Outptr_ HANDLE *phOsEvent);
85
95void DLLCALLCONV OsEventClose(_In_ HANDLE hOsEvent);
96
111DWORD DLLCALLCONV OsEventWait(_In_ HANDLE hOsEvent, _In_ DWORD dwSecTimeout);
112
123DWORD DLLCALLCONV OsEventSignal(_In_ HANDLE hOsEvent);
124
135DWORD DLLCALLCONV OsEventReset(_In_ HANDLE hOsEvent);
136
148DWORD DLLCALLCONV OsMutexCreate(_Outptr_ HANDLE *phOsMutex);
149
159void DLLCALLCONV OsMutexClose(_In_ HANDLE hOsMutex);
160
171DWORD DLLCALLCONV OsMutexLock(_In_ HANDLE hOsMutex);
172
183DWORD DLLCALLCONV OsMutexUnlock(_In_ HANDLE hOsMutex);
184
199DWORD DLLCALLCONV OsSemaphoreCreate(_Outptr_ HANDLE *phOsSemaphore,
200 _In_ DWORD dwInitialCount, _In_ DWORD dwMaximumCount);
201
211void DLLCALLCONV OsSemaphoreClose(_In_ HANDLE hOsSemaphore);
212
225DWORD DLLCALLCONV OsSemaphoreWait(_In_ HANDLE hOsSemaphore,
226 _In_ DWORD dwSecTimeout);
227
238DWORD DLLCALLCONV OsSemaphorePost(_In_ HANDLE hOsSemaphore);
239
249void DLLCALLCONV SleepWrapper(_In_ DWORD dwMicroSecs);
250
251#if defined(UNIX)
252 #define OsMemoryBarrier() __sync_synchronize()
253#elif defined(WIN32)
254 #define OsMemoryBarrier() MemoryBarrier()
255#endif
256
257#if !defined(__KERNEL__)
258
259
260int print2wstr(wchar_t *buffer, size_t count, const wchar_t *format , ...);
261
281void DLLCALLCONV vPrintDbgMessage(_In_ DWORD dwLevel, _In_ DWORD dwSection,
282 _In_ const char *format, _In_ va_list ap);
283
303void DLLCALLCONV PrintDbgMessage(DWORD dwLevel, DWORD dwSection,
304 const char *format, ...);
305
314
323
336BOOL DLLCALLCONV UtilGetFileSize(_In_ const PCHAR sFileName,
337 _Outptr_ DWORD *pdwFileSize, _In_ PCHAR sErrString);
338
356 _In_ DWORD dwSizeStr, _In_ const CHAR *pcInputText,
357 _In_ const CHAR *pcDefaultString);
358
359
374DWORD DLLCALLCONV UtilGetFileName(_Out_ PCHAR pcFileName,
375 _In_ DWORD dwFileNameSize, _In_ const CHAR *pcDefaultFileName);
376
388
399
400#endif /* !defined(__KERNEL__) */
401
402#if defined(UNIX)
403 #if !defined(stricmp)
404 #define stricmp strcasecmp
405 #endif
406 #if !defined(strnicmp)
407 #define strnicmp strncasecmp
408 #endif
409#endif
410
421
432
433#if !defined(INFINITE)
434 #define INFINITE 0xffffffff
435#endif
436
437#ifdef __cplusplus
438}
439#endif
440
441#endif /* _WD_UTILS_H_ */
442
int print2wstr(wchar_t *buffer, size_t count, const wchar_t *format,...)
void DLLCALLCONV vPrintDbgMessage(_In_ DWORD dwLevel, _In_ DWORD dwSection, _In_ const char *format, _In_ va_list ap)
Sends debug messages to the Debug Monitor.
void DLLCALLCONV OsSemaphoreClose(_In_ HANDLE hOsSemaphore)
Closes a handle to a semaphore object.
UINT64 UtilGetCurrentTimeInMillisec(void)
Get the current time in milliseconds, relative to a non user determined starting point (Starting poin...
void DLLCALLCONV PrintDbgMessage(DWORD dwLevel, DWORD dwSection, const char *format,...)
Sends debug messages to the Debug Monitor.
void DLLCALLCONV OsMutexClose(_In_ HANDLE hOsMutex)
Closes a handle to a mutex object.
DWORD DLLCALLCONV OsEventReset(_In_ HANDLE hOsEvent)
Resets the specified event object to the non-signaled state.
BOOL UtilGetCurrentTime(_Out_ TIME_TYPE *time)
Retrieves the current time, in OS units.
DWORD DLLCALLCONV OsEventSignal(_In_ HANDLE hOsEvent)
Sets the specified event object to the signaled state.
DWORD DLLCALLCONV ThreadStart(_Outptr_ HANDLE *phThread, _In_ HANDLER_FUNC pFunc, _In_ void *pData)
Creates a thread.
DWORD DLLCALLCONV OsMutexCreate(_Outptr_ HANDLE *phOsMutex)
Creates a mutex object.
DWORD DLLCALLCONV OsSemaphoreWait(_In_ HANDLE hOsSemaphore, _In_ DWORD dwSecTimeout)
Waits until the specified semaphore object is in the signaled state or the time-out interval elapses.
void DLLCALLCONV ThreadWait(_In_ HANDLE hThread)
Waits for a thread to exit.
void(DLLCALLCONV * HANDLER_FUNC)(void *pData)
Definition: utils.h:38
DWORD DLLCALLCONV OsSemaphorePost(_In_ HANDLE hOsSemaphore)
Releases (posts) a locked semaphore object.
DWORD DLLCALLCONV UtilGetStringFromUser(_Out_ PCHAR pcString, _In_ DWORD dwSizeStr, _In_ const CHAR *pcInputText, _In_ const CHAR *pcDefaultString)
Gets a string from user input and out it in pcString.
DWORD DLLCALLCONV OsSemaphoreCreate(_Outptr_ HANDLE *phOsSemaphore, _In_ DWORD dwInitialCount, _In_ DWORD dwMaximumCount)
Creates a semaphore object.
void DLLCALLCONV SleepWrapper(_In_ DWORD dwMicroSecs)
Wrapper to WD_Sleep, Sleeps dwMicroSecs microseconds.
double UtilGetTimeDiff(_In_ TIME_TYPE *end, _In_ TIME_TYPE *start)
Calculates the time difference in milliseconds.
LARGE_INTEGER TIME_TYPE
Definition: utils.h:34
BOOL DLLCALLCONV UtilGetFileSize(_In_ const PCHAR sFileName, _Outptr_ DWORD *pdwFileSize, _In_ PCHAR sErrString)
Writes the file size with name sFileName in dwFileSize.
DWORD DLLCALLCONV UtilGetFileName(_Out_ PCHAR pcFileName, _In_ DWORD dwFileNameSize, _In_ const CHAR *pcDefaultFileName)
Gets a file name from user input and out it in pcFileName.
DWORD DLLCALLCONV OsMutexLock(_In_ HANDLE hOsMutex)
Locks the specified mutex object.
int DLLCALLCONV GetNumberOfProcessors(void)
Returns the number of processors currently online (available)
int DLLCALLCONV GetPageSize(void)
Returns the page size in the OS.
DWORD DLLCALLCONV OsEventWait(_In_ HANDLE hOsEvent, _In_ DWORD dwSecTimeout)
Waits until a specified event object is in the signaled state or the time-out interval elapses.
void DLLCALLCONV OsEventClose(_In_ HANDLE hOsEvent)
Closes a handle to an event object.
DWORD DLLCALLCONV EnableVTMode(void)
Enables Virtual Terminal Mode in Windows, allows color prints in the terminal.
DWORD DLLCALLCONV OsMutexUnlock(_In_ HANDLE hOsMutex)
Releases (unlocks) a locked mutex object.
DWORD DLLCALLCONV OsEventCreate(_Outptr_ HANDLE *phOsEvent)
Creates an event object.
#define _Outptr_
Definition: windrvr.h:40
#define _Out_
Definition: windrvr.h:39
#define _In_
Definition: windrvr.h:37
unsigned __int64 UINT64
Definition: windrvr.h:318
#define DLLCALLCONV
Definition: windrvr.h:32