#include "wv_base.h"\r
\r
volatile LONG WvRef;\r
+HANDLE heap;\r
\r
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
{\r
UNREFERENCED_PARAMETER(hInstance);\r
- UNREFERENCED_PARAMETER(dwReason);\r
UNREFERENCED_PARAMETER(lpReserved);\r
\r
+ switch (dwReason) {\r
+ case DLL_PROCESS_ATTACH:\r
+ heap = HeapCreate(0, 0, 0);\r
+ if (heap == NULL) {\r
+ return FALSE;\r
+ }\r
+ break;\r
+ case DLL_PROCESS_DETACH:\r
+ HeapDestroy(heap);\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+\r
return TRUE;\r
}\r
\r
\r
#include <windows.h>\r
\r
+extern HANDLE heap;\r
+\r
__inline void* __cdecl operator new(size_t size)\r
{\r
- return HeapAlloc(GetProcessHeap(), 0, size);\r
+ return HeapAlloc(heap, 0, size);\r
}\r
\r
__inline void __cdecl operator delete(void *pObj)\r
{\r
- HeapFree(GetProcessHeap(), 0, pObj);\r
+ HeapFree(heap, 0, pObj);\r
}\r
\r
const int WvDefaultBufferSize = 128;\r
void *m_pBuf;\r
};\r
\r
-#endif // _WV_MEMORY_H_
\ No newline at end of file
+#endif // _WV_MEMORY_H_\r
}\r
\r
dapl_os_unlock(&hca_ptr->ib_trans.lock);\r
- free(set);\r
+ dapl_os_free(set, sizeof(struct dapl_fd_set));\r
out:\r
hca_ptr->ib_trans.cr_state = IB_THREAD_EXIT;\r
dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " cr_thread(hca %p) exit\n", hca_ptr);\r
-/*
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
- *
- * This Software is licensed under either one of the following two licenses:
- *
- * 1) under the terms of the "Common Public License 1.0" a copy of which is
- * in the file LICENSE.txt in the root directory. The license is also
- * available from the Open Source Initiative, see
- * http://www.opensource.org/licenses/cpl.php.
- * OR
- *
- * 2) under the terms of the "The BSD License" a copy of which is in the file
- * LICENSE2.txt in the root directory. The license is also available from
- * the Open Source Initiative, see
- * http://www.opensource.org/licenses/bsd-license.php.
- *
- * Licensee has the right to choose either one of the above two licenses.
- *
- * Redistributions of source code must retain both the above copyright
- * notice and either one of the license notices.
- *
- * Redistributions in binary form must reproduce both the above copyright
- * notice, either one of the license notices in the documentation
- * and/or other materials provided with the distribution.
- */
-
-/**********************************************************************
- *
- * MODULE: dapl_osd.c
- *
- * PURPOSE: Operating System Dependent layer
- * Description:
- * Provide OS dependent functions with a canonical DAPL
- * interface. Designed to be portable and hide OS specific quirks
- * of common functions.
- *
- *
- * $Id: dapl_osd.c 33 2005-07-11 19:51:17Z ftillier $
- **********************************************************************/
-
-/*
- * MUST have the Microsoft Platform SDK installed for Windows to build
- * and work properly
- */
-#include "dapl.h"
-#include "dapl_init.h"
-#include "dapl_osd.h"
-#include <sys/timeb.h>
-#include <stdlib.h> /* needed for getenv() */
-
-
-
-/*
- * DllMain
- *
- * Primary Windows entry point
- *
- * Input:
- * hDllHandle handle to DLL module
- * fdwReason reason for calling function
- * lpReserved reserved
- *
- * Returns:
- * DAT_SUCCESS
- */
-
-BOOL WINAPI
-DllMain (
- IN HINSTANCE hDllHandle,
- IN DWORD fdwReason,
- IN LPVOID lpReserved )
-{
- UNREFERENCED_PARAMETER(lpReserved);
-
- switch( fdwReason )
- {
- case DLL_PROCESS_ATTACH:
- /*
- * We don't attach/detach threads that need any sort
- * of initialization, so disable this ability to optimize
- * the working set size of the DLL. Also allows us to
- * remove two case statemens:
- * DLL_THREAD_DETACH and DLL_THREAD_ATTACH
- */
- if ( (DisableThreadLibraryCalls( hDllHandle )) != 0)
- {
-#if 0
- /*
- * Relocated to [dapl_init.c] ..._PROVIDER_INIT() as when called
- * from here calls to dapl_init/dapls_ib_init/ib_open_al() hang
- * in the DLL call context.
- */
- dapl_init ();
-#endif
- }
- else
- {
- DWORD err = GetLastError();
- dapl_os_printf("DAPL Init Failed with code %u\n", err);
- }
- break;
-
- case DLL_PROCESS_DETACH:
- /*
- * Do library cleanup
- */
-#if 0
- /*
- * Relocated to [dapl_init.c] ..._PROVIDER_FINI() as the call to
- * dapl_fini/dapls_ib_release/ib_close_al() hangs in this DLL call
- * context.
- */
- dapl_fini ();
-#endif
- break;
- }
- return TRUE;
-}
-
-
-#ifdef NOT_USED
-/*
- * dapl_osd_init
- *
- * Do Windows specific initialization:
- * - nothing at this time
- *
- * Input:
- * none
- *
- * Returns:
- * none
- */
-void
-dapl_osd_init ( )
-{
- return;
-}
-#endif
-
-/*
- * dapl_os_get_time
- *
- * Return 64 bit value of current time in microseconds.
- *
- * Input:
- * loc User location to place current time
- *
- * Returns:
- * DAT_SUCCESS
- */
-
-DAT_RETURN
-dapl_os_get_time (
- OUT DAPL_OS_TIMEVAL * loc)
-{
- struct _timeb tb;
-
- _ftime ( &tb );
-
- *loc = ((DAT_UINT64) (tb.time * 1000000L) + (DAT_UINT64) tb.millitm * 1000);
-
- return DAT_SUCCESS;
-}
-
-
-/*
- * dapl_os_get_bool_env
- *
- * Return boolean value of passed in environment variable: 1 if present,
- * 0 if not
- *
- * Input:
- *
- *
- * Returns:
- * TRUE or FALSE
- */
-int
-dapl_os_get_env_bool (
- char *env_str )
-{
- char *env_var;
-
- env_var = getenv (env_str);
- if (env_var != NULL)
- {
- return 1;
- }
- return 0;
-}
-
-
-/*
- * dapl_os_get_val_env
- *
- * Update val to value of passed in environment variable if present
- *
- * Input:
- * env_str
- * def_val default value if environment variable does not exist
- *
- * Returns:
- * TRUE or FALSE
- */
-int
-dapl_os_get_env_val (
- char *env_str,
- int def_val )
-{
- char *env_var;
-
- env_var = getenv (env_str);
- if ( env_var != NULL )
- {
- def_val = strtol (env_var, NULL, 0);
- }
-
- return def_val;
-}
-
-
-/*
- * dapls_os_thread_create
- *
- * Create a thread for dapl
- *
- * Input:
- * func function to invoke thread
- * data argument to pass to function
- *
- * Output
- * thread_id handle for thread
- *
- * Returns:
- * DAT_SUCCESS
- */
-DAT_RETURN
-dapl_os_thread_create (
- IN void (*func) (void *),
- IN void *data,
- OUT DAPL_OS_THREAD *thread_id )
-{
-
- *thread_id = CreateThread(
- NULL, /* &thread security attrs */
- 8 * 1024, /* initial thread stack size */
- (LPTHREAD_START_ROUTINE)func, /* &thread function */
- data, /* argument for new thread */
- 0, /* creation flags */
- NULL); /* thread ID (ignore) */
-
- if ( *thread_id == NULL )
- {
- return DAT_ERROR (DAT_INSUFFICIENT_RESOURCES, 0);
- }
-
- return DAT_SUCCESS;
-}
-
-
-/*
- * Local variables:
- * c-indent-level: 4
- * c-basic-offset: 4
- * tab-width: 8
- * End:
- */
+/*\r
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
+ *\r
+ * This Software is licensed under either one of the following two licenses:\r
+ *\r
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
+ * in the file LICENSE.txt in the root directory. The license is also\r
+ * available from the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/cpl.php.\r
+ * OR\r
+ *\r
+ * 2) under the terms of the "The BSD License" a copy of which is in the file\r
+ * LICENSE2.txt in the root directory. The license is also available from\r
+ * the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/bsd-license.php.\r
+ *\r
+ * Licensee has the right to choose either one of the above two licenses.\r
+ *\r
+ * Redistributions of source code must retain both the above copyright\r
+ * notice and either one of the license notices.\r
+ *\r
+ * Redistributions in binary form must reproduce both the above copyright\r
+ * notice, either one of the license notices in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ */\r
+\r
+/**********************************************************************\r
+ * \r
+ * MODULE: dapl_osd.c\r
+ *\r
+ * PURPOSE: Operating System Dependent layer\r
+ * Description: \r
+ * Provide OS dependent functions with a canonical DAPL\r
+ * interface. Designed to be portable and hide OS specific quirks\r
+ * of common functions.\r
+ * \r
+ *\r
+ * $Id: dapl_osd.c 33 2005-07-11 19:51:17Z ftillier $\r
+ **********************************************************************/\r
+\r
+/*\r
+ * MUST have the Microsoft Platform SDK installed for Windows to build\r
+ * and work properly\r
+ */\r
+#include "dapl.h"\r
+#include "dapl_init.h"\r
+#include "dapl_osd.h"\r
+#include <sys/timeb.h>\r
+#include <stdlib.h> /* needed for getenv() */\r
+\r
+HANDLE heap;\r
+\r
+/*\r
+ * DllMain\r
+ *\r
+ * Primary Windows entry point\r
+ *\r
+ * Input:\r
+ * hDllHandle handle to DLL module\r
+ * fdwReason reason for calling function\r
+ * lpReserved reserved\r
+ *\r
+ * Returns:\r
+ * DAT_SUCCESS\r
+ */\r
+\r
+BOOL WINAPI\r
+DllMain (\r
+ IN HINSTANCE hDllHandle,\r
+ IN DWORD fdwReason,\r
+ IN LPVOID lpReserved )\r
+{\r
+ UNREFERENCED_PARAMETER(lpReserved);\r
+\r
+ switch( fdwReason ) \r
+ { \r
+ case DLL_PROCESS_ATTACH:\r
+ heap = HeapCreate(0, 0, 0);\r
+ if (heap == NULL) {\r
+ return FALSE;\r
+ }\r
+ /*\r
+ * We don't attach/detach threads that need any sort\r
+ * of initialization, so disable this ability to optimize\r
+ * the working set size of the DLL. Also allows us to\r
+ * remove two case statemens:\r
+ * DLL_THREAD_DETACH and DLL_THREAD_ATTACH\r
+ */\r
+ if ( (DisableThreadLibraryCalls( hDllHandle )) != 0)\r
+ {\r
+#if 0\r
+ /*\r
+ * Relocated to [dapl_init.c] ..._PROVIDER_INIT() as when called\r
+ * from here calls to dapl_init/dapls_ib_init/ib_open_al() hang\r
+ * in the DLL call context.\r
+ */\r
+ dapl_init ();\r
+#endif\r
+ }\r
+ else\r
+ {\r
+ DWORD err = GetLastError();\r
+ dapl_os_printf("DAPL Init Failed with code %u\n", err);\r
+ }\r
+ break;\r
+\r
+ case DLL_PROCESS_DETACH:\r
+ /* \r
+ * Do library cleanup\r
+ */\r
+#if 0\r
+ /*\r
+ * Relocated to [dapl_init.c] ..._PROVIDER_FINI() as the call to\r
+ * dapl_fini/dapls_ib_release/ib_close_al() hangs in this DLL call\r
+ * context.\r
+ */\r
+ dapl_fini ();\r
+#endif\r
+ HeapDestroy(heap);\r
+ break;\r
+ }\r
+ return TRUE; \r
+}\r
+\r
+\r
+#ifdef NOT_USED\r
+/*\r
+ * dapl_osd_init\r
+ *\r
+ * Do Windows specific initialization:\r
+ * - nothing at this time\r
+ *\r
+ * Input:\r
+ * none\r
+ *\r
+ * Returns:\r
+ * none\r
+ */\r
+void\r
+dapl_osd_init ( )\r
+{\r
+ return;\r
+}\r
+#endif\r
+\r
+/*\r
+ * dapl_os_get_time\r
+ *\r
+ * Return 64 bit value of current time in microseconds.\r
+ *\r
+ * Input:\r
+ * loc User location to place current time\r
+ *\r
+ * Returns:\r
+ * DAT_SUCCESS\r
+ */\r
+\r
+DAT_RETURN\r
+dapl_os_get_time (\r
+ OUT DAPL_OS_TIMEVAL * loc)\r
+{\r
+ struct _timeb tb;\r
+ \r
+ _ftime ( &tb );\r
+\r
+ *loc = ((DAT_UINT64) (tb.time * 1000000L) + (DAT_UINT64) tb.millitm * 1000);\r
+ \r
+ return DAT_SUCCESS;\r
+}\r
+\r
+\r
+/*\r
+ * dapl_os_get_bool_env\r
+ *\r
+ * Return boolean value of passed in environment variable: 1 if present,\r
+ * 0 if not\r
+ *\r
+ * Input:\r
+ * \r
+ *\r
+ * Returns:\r
+ * TRUE or FALSE\r
+ */\r
+int\r
+dapl_os_get_env_bool (\r
+ char *env_str )\r
+{\r
+ char *env_var;\r
+\r
+ env_var = getenv (env_str);\r
+ if (env_var != NULL)\r
+ {\r
+ return 1;\r
+ }\r
+ return 0;\r
+}\r
+\r
+\r
+/*\r
+ * dapl_os_get_val_env\r
+ *\r
+ * Update val to value of passed in environment variable if present\r
+ *\r
+ * Input:\r
+ * env_str\r
+ * def_val default value if environment variable does not exist\r
+ *\r
+ * Returns:\r
+ * TRUE or FALSE\r
+ */\r
+int\r
+dapl_os_get_env_val (\r
+ char *env_str,\r
+ int def_val )\r
+{\r
+ char *env_var;\r
+\r
+ env_var = getenv (env_str);\r
+ if ( env_var != NULL )\r
+ {\r
+ def_val = strtol (env_var, NULL, 0);\r
+ }\r
+\r
+ return def_val;\r
+}\r
+\r
+\r
+/*\r
+ * dapls_os_thread_create\r
+ *\r
+ * Create a thread for dapl\r
+ *\r
+ * Input:\r
+ * func function to invoke thread\r
+ * data argument to pass to function\r
+ *\r
+ * Output\r
+ * thread_id handle for thread\r
+ *\r
+ * Returns:\r
+ * DAT_SUCCESS\r
+ */\r
+DAT_RETURN \r
+dapl_os_thread_create (\r
+ IN void (*func) (void *),\r
+ IN void *data,\r
+ OUT DAPL_OS_THREAD *thread_id )\r
+{\r
+\r
+ *thread_id = CreateThread(\r
+ NULL, /* &thread security attrs */\r
+ 8 * 1024, /* initial thread stack size */\r
+ (LPTHREAD_START_ROUTINE)func, /* &thread function */\r
+ data, /* argument for new thread */\r
+ 0, /* creation flags */\r
+ NULL); /* thread ID (ignore) */\r
+\r
+ if ( *thread_id == NULL )\r
+ {\r
+ return DAT_ERROR (DAT_INSUFFICIENT_RESOURCES, 0);\r
+ }\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+\r
+/*\r
+ * Local variables:\r
+ * c-indent-level: 4\r
+ * c-basic-offset: 4\r
+ * tab-width: 8\r
+ * End:\r
+ */\r
-/*
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
- *
- * This Software is licensed under either one of the following two licenses:
- *
- * 1) under the terms of the "Common Public License 1.0" a copy of which is
- * in the file LICENSE.txt in the root directory. The license is also
- * available from the Open Source Initiative, see
- * http://www.opensource.org/licenses/cpl.php.
- * OR
- *
- * 2) under the terms of the "The BSD License" a copy of which is in the file
- * LICENSE2.txt in the root directory. The license is also available from
- * the Open Source Initiative, see
- * http://www.opensource.org/licenses/bsd-license.php.
- *
- * Licensee has the right to choose either one of the above two licenses.
- *
- * Redistributions of source code must retain both the above copyright
- * notice and either one of the license notices.
- *
- * Redistributions in binary form must reproduce both the above copyright
- * notice, either one of the license notices in the documentation
- * and/or other materials provided with the distribution.
- */
-
-/**********************************************************************
- *
- * HEADER: dapl_osd.h
- *
- * PURPOSE: Operating System Dependent layer
- * Description:
- * Provide OS dependent data structures & functions with
- * a canonical DAPL interface. Designed to be portable
- * and hide OS specific quirks of common functions.
- *
- * $Id: dapl_osd.h 33 2005-07-11 19:51:17Z ftillier $
- **********************************************************************/
-
-#ifndef _DAPL_OSD_H_
-#define _DAPL_OSD_H_
-
-/*
- * This file is defined for Windows systems only, including it on any
- * other build will cause an error
- */
-#if !defined(_WIN32) && !defined(_WIN64)
-#error UNDEFINED OS TYPE
-#endif /* WIN32 */
-
-#include <stddef.h>
-#include <complib/cl_types.h>
-#pragma warning ( push, 3 )
-#include <winioctl.h>
-#include <stdio.h>
-#include <string.h>
-#include <winsock2.h>
-#include <Ws2tcpip.h>
-#include <process.h>
-#include <stdlib.h>
-#pragma warning ( pop )
-
-#include "dapl_debug.h"
-
-/* Export Header */
-#ifdef EXPORT_DAPL_SYMBOLS /* 1 when building DAPL DLL, 0 for clients */
-#define DAPL_EXPORT __declspec( dllexport )
-#else
-#define DAPL_EXPORT __declspec( dllimport )
-#endif
-
-/* Useful debug definitions */
-#ifndef STATIC
-#define STATIC static
-#endif /* STATIC */
-
-#ifndef _INLINE_
-#define _INLINE_ __inline
-#endif /* _INLINE_ */
-
-#define dapl_os_panic(str) \
- { \
- fprintf(stderr, "PANIC in %s:%i:%s\n", __FILE__, __LINE__); \
- fprintf(stderr, str); \
- exit(1); \
- }
-
-#define openlog(...)
-#define closelog(...)
-
-/*
- * Atomic operations
- */
-
-typedef volatile DAT_COUNT DAPL_ATOMIC;
-
-/* atomic function prototypes */
-STATIC __inline DAT_COUNT
-dapl_os_atomic_inc (
- INOUT DAPL_ATOMIC *v);
-
-STATIC __inline DAT_COUNT
-dapl_os_atomic_dec (
- INOUT DAPL_ATOMIC *v);
-
-STATIC __inline DAT_COUNT
-dapl_os_atomic_assign (
- INOUT DAPL_ATOMIC *v,
- IN DAT_COUNT match_value,
- IN DAT_COUNT new_value );
-
-#define dapl_os_atomic_read(v) (*v)
-#define dapl_os_atomic_set(v,i) (*v = i)
-
-int dapl_os_get_env_bool (
- char *env_str );
-
-int dapl_os_get_env_val (
- char *env_str,
- int def_val );
-
-
-/* atomic functions */
-
-/* dapl_os_atomic_inc
- *
- * get the current value of '*v', and then increment it.
- *
- * This is equivalent to an IB atomic fetch and add of 1,
- * except that a DAT_COUNT might be 32 bits, rather than 64
- * and it occurs in local memory.
- */
-
-STATIC __inline DAT_COUNT
-dapl_os_atomic_inc (
- INOUT DAPL_ATOMIC *v)
-{
- return InterlockedIncrement( v );
-}
-
-
-/* dapl_os_atomic_dec
- *
- * decrement the current value of '*v'. No return value is required.
- */
-
-STATIC __inline DAT_COUNT
-dapl_os_atomic_dec (
- INOUT DAPL_ATOMIC *v)
-{
- return InterlockedDecrement( v );
-}
-
-
-/* dapl_os_atomic_assign
- *
- * assign 'new_value' to '*v' if the current value
- * matches the provided 'match_value'.
- *
- * Make no assignment if there is no match.
- *
- * Return the current value in any case.
- *
- * This matches the IBTA atomic operation compare & swap
- * except that it is for local memory and a DAT_COUNT may
- * be only 32 bits, rather than 64.
- */
-
-STATIC __inline DAT_COUNT
-dapl_os_atomic_assign (
- INOUT DAPL_ATOMIC *v,
- IN DAT_COUNT match_value,
- IN DAT_COUNT new_value )
-{
- return InterlockedCompareExchange((LPLONG)v,
- new_value,
- match_value);
-}
-
-
-/*
- * Thread Functions
- */
-typedef HANDLE DAPL_OS_THREAD;
-
-DAT_RETURN
-dapl_os_thread_create (
- IN void (*func) (void *),
- IN void *data,
- OUT DAPL_OS_THREAD *thread_id );
-
-
-/*
- * Lock Functions
- */
-typedef HANDLE DAPL_OS_LOCK;
-
-/* function prototypes */
-/* lock functions */
-STATIC __inline DAT_RETURN
-dapl_os_lock_init (
- IN DAPL_OS_LOCK *m)
-{
- *m = CreateMutex (0, FALSE, 0);
-
- return *m ? DAT_SUCCESS : (DAT_CLASS_ERROR | DAT_INSUFFICIENT_RESOURCES);
-}
-
-STATIC __inline DAT_RETURN
-dapl_os_lock (
- IN DAPL_OS_LOCK *m)
-{
- WaitForSingleObject (*m, INFINITE);
-
- return DAT_SUCCESS;
-}
-
-STATIC __inline DAT_RETURN
-dapl_os_unlock (
- IN DAPL_OS_LOCK *m)
-{
- ReleaseMutex (*m);
-
- return DAT_SUCCESS;
-}
-
-STATIC __inline DAT_RETURN
-dapl_os_lock_destroy (
- IN DAPL_OS_LOCK *m)
-{
- CloseHandle (*m);
-
- return DAT_SUCCESS;
-}
-
-
-/*
- * Wait Objects
- */
-
-/*
- * The wait object invariant: Presuming a call to dapl_os_wait_object_wait
- * occurs at some point, there will be at least one wakeup after each call
- * to dapl_os_wait_object_signal. I.e. Signals are not ignored, though
- * they may be coallesced.
- */
-
-/* wait_object functions */
-
-typedef HANDLE DAPL_OS_WAIT_OBJECT;
-
-/* Initialize a wait object to an empty state
- */
-
-STATIC __inline DAT_RETURN
-dapl_os_wait_object_init (
- IN DAPL_OS_WAIT_OBJECT *wait_obj)
-{
- *wait_obj = CreateEvent(NULL,FALSE,FALSE,NULL);
-
- if ( *wait_obj == NULL )
- {
- return DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;
- }
-
- return DAT_SUCCESS;
-}
-
-
-/* Wait on the supplied wait object, up to the specified time_out,
- * and reacquiring it after the wait ends.
- * A timeout of DAT_TIMEOUT_INFINITE will wait indefinitely.
- * Timeout should be specified in micro seconds.
- *
- * Functional returns:
- * DAT_SUCCESS -- another thread invoked dapl_os_wait object_wakeup
- * DAT_INVALID_STATE -- someone else is already waiting in this wait
- * object.
- * only one waiter is allowed at a time.
- * DAT_ABORT -- another thread invoked dapl_os_wait_object_destroy
- * DAT_TIMEOUT -- the specified time limit was reached.
- */
-
-STATIC __inline DAT_RETURN
-dapl_os_wait_object_wait (
- IN DAPL_OS_WAIT_OBJECT *wait_obj,
- IN DAT_TIMEOUT timeout_val)
-{
- DAT_RETURN status;
- DWORD op_status;
-
- status = DAT_SUCCESS;
-
- if ( DAT_TIMEOUT_INFINITE == timeout_val )
- {
- op_status = WaitForSingleObject(*wait_obj, INFINITE);
- }
- else
- {
- /* convert to milliseconds */
- op_status = WaitForSingleObject(*wait_obj, timeout_val/1000);
- }
-
- if (op_status == WAIT_TIMEOUT)
- {
- status = DAT_CLASS_ERROR | DAT_TIMEOUT_EXPIRED;
- }
- else if ( op_status == WAIT_FAILED)
- {
- status = DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;
- }
-
- return status;
-}
-
-STATIC __inline DAT_RETURN
-dapl_os_wait_object_wakeup (
- IN DAPL_OS_WAIT_OBJECT *wait_obj)
-{
- DWORD op_status;
-
- op_status = SetEvent(*wait_obj);
- if ( op_status == 0 )
- {
- return DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;
- }
-
- return DAT_SUCCESS;
-}
-
-STATIC __inline DAT_RETURN
-dapl_os_wait_object_destroy (
- IN DAPL_OS_WAIT_OBJECT *wait_obj)
-{
- DWORD op_status;
- DAT_RETURN status = DAT_SUCCESS;
-
- op_status = CloseHandle(*wait_obj);
-
- if ( op_status == 0 )
- {
- status = DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;
- }
-
- return status;
-}
-
-
-/*
- * Memory Functions
- */
-
-/* function prototypes */
-STATIC __inline void *dapl_os_alloc (int size);
-
-STATIC __inline void *dapl_os_realloc (void *ptr, int size);
-
-STATIC __inline void dapl_os_free (void *ptr, int size);
-
-STATIC __inline void * dapl_os_memzero (void *loc, int size);
-
-STATIC __inline void * dapl_os_memcpy (void *dest, const void *src, int len);
-
-STATIC __inline int dapl_os_memcmp (const void *mem1, const void *mem2, int len);
-
-/*
- * Memory coherency functions
- * For i386/x86_64 Windows, there are no coherency issues - just return success.
- */
-STATIC __inline DAT_RETURN
-dapl_os_sync_rdma_read (
- IN const DAT_LMR_TRIPLET *local_segments,
- IN DAT_VLEN num_segments)
-{
- return DAT_SUCCESS;
-}
-
-STATIC __inline DAT_RETURN
-dapl_os_sync_rdma_write (
- IN const DAT_LMR_TRIPLET *local_segments,
- IN DAT_VLEN num_segments)
-{
- return DAT_SUCCESS;
-}
-
-
-/* memory functions */
-
-
-STATIC __inline void *dapl_os_alloc (int size)
-{
- return malloc (size);
-}
-
-STATIC __inline void *dapl_os_realloc (void *ptr, int size)
-{
- return realloc(ptr, size);
-}
-
-STATIC __inline void dapl_os_free (void *ptr, int size)
-{
- size = size;
- free (ptr);
- ptr = NULL;
-}
-
-STATIC __inline void * dapl_os_memzero (void *loc, int size)
-{
- return memset (loc, 0, size);
-}
-
-STATIC __inline void * dapl_os_memcpy (void *dest, const void *src, int len)
-{
- return memcpy (dest, src, len);
-}
-
-STATIC __inline int dapl_os_memcmp (const void *mem1, const void *mem2, int len)
-{
- return memcmp (mem1, mem2, len);
-}
-
-
-STATIC __inline unsigned int dapl_os_strlen(const char *str)
-{
- return ((unsigned int)strlen(str));
-}
-
-STATIC __inline char * dapl_os_strdup(const char *str)
-{
- return _strdup(str);
-}
-
-
-/*
- * Timer Functions
- */
-
-typedef DAT_UINT64 DAPL_OS_TIMEVAL;
-typedef struct dapl_timer_entry DAPL_OS_TIMER;
-typedef unsigned long DAPL_OS_TICKS;
-
-/* function prototypes */
-
-/*
- * Sleep for the number of micro seconds specified by the invoking
- * function
- */
-STATIC __inline void dapl_os_sleep_usec (int sleep_time)
-{
- Sleep(sleep_time/1000); // convert to milliseconds
-}
-
-STATIC __inline DAPL_OS_TICKS dapl_os_get_ticks (void);
-
-STATIC __inline int dapl_os_ticks_to_seconds (DAPL_OS_TICKS ticks);
-
-DAT_RETURN dapl_os_get_time (DAPL_OS_TIMEVAL *);
-/* timer functions */
-
-STATIC __inline DAPL_OS_TICKS dapl_os_get_ticks (void)
-{
- return GetTickCount ();
-}
-
-STATIC __inline int dapl_os_ticks_to_seconds (DAPL_OS_TICKS ticks)
-{
- ticks = ticks;
- /* NOT YET IMPLEMENTED IN USER-SPACE */
- return 0;
-}
-
-
-/*
- *
- * Name Service Helper functions
- *
- */
-#ifdef IBHOSTS_NAMING
-#define dapls_osd_getaddrinfo(name, addr_ptr) getaddrinfo(name,NULL,NULL,addr_ptr)
-#define dapls_osd_freeaddrinfo(addr) freeaddrinfo (addr)
-
-#endif /* IBHOSTS_NAMING */
-
-/*
- * *printf format helpers. We use the C string constant concatenation
- * ability to define 64 bit formats, which unfortunatly are non standard
- * in the C compiler world. E.g. %llx for gcc, %I64x for Windows
- */
-#define F64d "%I64d"
-#define F64u "%I64u"
-#define F64x "%I64x"
-#define F64X "%I64X"
-
-/*
- * Conversion Functions
- */
-
-STATIC __inline long int
-dapl_os_strtol(const char *nptr, char **endptr, int base)
-{
- return strtol(nptr, endptr, base);
-}
-
-#define dapl_os_getpid (DAT_UINT32)GetCurrentProcessId
-#define dapl_os_gettid (DAT_UINT32)GetCurrentThreadId
-
-/*
- * Debug Helper Functions
- */
-
-#define dapl_os_assert(expression) CL_ASSERT(expression)
-
-#define dapl_os_printf printf
-#define dapl_os_vprintf(fmt,args) vprintf(fmt,args)
-#define dapl_os_syslog(fmt,args) /* XXX Need log routine call */
-
-#endif /* _DAPL_OSD_H_ */
-
-/*
- * Local variables:
- * c-indent-level: 4
- * c-basic-offset: 4
- * tab-width: 8
- * End:
- */
+/*\r
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
+ *\r
+ * This Software is licensed under either one of the following two licenses:\r
+ *\r
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
+ * in the file LICENSE.txt in the root directory. The license is also\r
+ * available from the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/cpl.php.\r
+ * OR\r
+ *\r
+ * 2) under the terms of the "The BSD License" a copy of which is in the file\r
+ * LICENSE2.txt in the root directory. The license is also available from\r
+ * the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/bsd-license.php.\r
+ *\r
+ * Licensee has the right to choose either one of the above two licenses.\r
+ *\r
+ * Redistributions of source code must retain both the above copyright\r
+ * notice and either one of the license notices.\r
+ *\r
+ * Redistributions in binary form must reproduce both the above copyright\r
+ * notice, either one of the license notices in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ */\r
+\r
+/**********************************************************************\r
+ * \r
+ * HEADER: dapl_osd.h\r
+ *\r
+ * PURPOSE: Operating System Dependent layer\r
+ * Description:\r
+ * Provide OS dependent data structures & functions with\r
+ * a canonical DAPL interface. Designed to be portable\r
+ * and hide OS specific quirks of common functions.\r
+ *\r
+ * $Id: dapl_osd.h 33 2005-07-11 19:51:17Z ftillier $\r
+ **********************************************************************/\r
+\r
+#ifndef _DAPL_OSD_H_\r
+#define _DAPL_OSD_H_\r
+\r
+/*\r
+ * This file is defined for Windows systems only, including it on any\r
+ * other build will cause an error\r
+ */\r
+#if !defined(_WIN32) && !defined(_WIN64)\r
+#error UNDEFINED OS TYPE\r
+#endif /* WIN32 */\r
+\r
+#include <stddef.h>\r
+#include <complib/cl_types.h>\r
+#pragma warning ( push, 3 )\r
+#include <winioctl.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <winsock2.h>\r
+#include <Ws2tcpip.h>\r
+#include <process.h>\r
+#include <stdlib.h>\r
+#pragma warning ( pop )\r
+\r
+#include "dapl_debug.h"\r
+\r
+/* Export Header */\r
+#ifdef EXPORT_DAPL_SYMBOLS /* 1 when building DAPL DLL, 0 for clients */\r
+#define DAPL_EXPORT __declspec( dllexport )\r
+#else\r
+#define DAPL_EXPORT __declspec( dllimport )\r
+#endif\r
+\r
+/* Useful debug definitions */\r
+#ifndef STATIC\r
+#define STATIC static\r
+#endif /* STATIC */\r
+\r
+#ifndef _INLINE_\r
+#define _INLINE_ __inline\r
+#endif /* _INLINE_ */\r
+\r
+#define dapl_os_panic(str) \\r
+ { \\r
+ fprintf(stderr, "PANIC in %s:%i:%s\n", __FILE__, __LINE__); \\r
+ fprintf(stderr, str); \\r
+ exit(1); \\r
+ }\r
+\r
+#define openlog(...)\r
+#define closelog(...)\r
+\r
+/*\r
+ * Atomic operations\r
+ */\r
+\r
+typedef volatile DAT_COUNT DAPL_ATOMIC;\r
+\r
+/* atomic function prototypes */\r
+STATIC __inline DAT_COUNT\r
+dapl_os_atomic_inc (\r
+ INOUT DAPL_ATOMIC *v);\r
+\r
+STATIC __inline DAT_COUNT\r
+dapl_os_atomic_dec ( \r
+ INOUT DAPL_ATOMIC *v);\r
+\r
+STATIC __inline DAT_COUNT\r
+dapl_os_atomic_assign (\r
+ INOUT DAPL_ATOMIC *v,\r
+ IN DAT_COUNT match_value,\r
+ IN DAT_COUNT new_value );\r
+\r
+#define dapl_os_atomic_read(v) (*v)\r
+#define dapl_os_atomic_set(v,i) (*v = i)\r
+\r
+int dapl_os_get_env_bool (\r
+ char *env_str );\r
+\r
+int dapl_os_get_env_val (\r
+ char *env_str,\r
+ int def_val );\r
+\r
+\r
+/* atomic functions */\r
+\r
+/* dapl_os_atomic_inc\r
+ *\r
+ * get the current value of '*v', and then increment it.\r
+ *\r
+ * This is equivalent to an IB atomic fetch and add of 1,\r
+ * except that a DAT_COUNT might be 32 bits, rather than 64\r
+ * and it occurs in local memory.\r
+ */\r
+\r
+STATIC __inline DAT_COUNT\r
+dapl_os_atomic_inc (\r
+ INOUT DAPL_ATOMIC *v)\r
+{\r
+ return InterlockedIncrement( v );\r
+}\r
+\r
+\r
+/* dapl_os_atomic_dec\r
+ *\r
+ * decrement the current value of '*v'. No return value is required.\r
+ */\r
+\r
+STATIC __inline DAT_COUNT\r
+dapl_os_atomic_dec ( \r
+ INOUT DAPL_ATOMIC *v)\r
+{\r
+ return InterlockedDecrement( v );\r
+}\r
+\r
+\r
+/* dapl_os_atomic_assign\r
+ *\r
+ * assign 'new_value' to '*v' if the current value\r
+ * matches the provided 'match_value'.\r
+ *\r
+ * Make no assignment if there is no match.\r
+ *\r
+ * Return the current value in any case.\r
+ *\r
+ * This matches the IBTA atomic operation compare & swap\r
+ * except that it is for local memory and a DAT_COUNT may\r
+ * be only 32 bits, rather than 64.\r
+ */\r
+\r
+STATIC __inline DAT_COUNT\r
+dapl_os_atomic_assign (\r
+ INOUT DAPL_ATOMIC *v,\r
+ IN DAT_COUNT match_value,\r
+ IN DAT_COUNT new_value )\r
+{\r
+ return InterlockedCompareExchange((LPLONG)v, \r
+ new_value,\r
+ match_value);\r
+}\r
+\r
+\r
+/*\r
+ * Thread Functions\r
+ */\r
+typedef HANDLE DAPL_OS_THREAD;\r
+\r
+DAT_RETURN \r
+dapl_os_thread_create (\r
+ IN void (*func) (void *),\r
+ IN void *data,\r
+ OUT DAPL_OS_THREAD *thread_id );\r
+\r
+\r
+/*\r
+ * Lock Functions\r
+ */\r
+typedef HANDLE DAPL_OS_LOCK;\r
+\r
+/* function prototypes */\r
+/* lock functions */\r
+STATIC __inline DAT_RETURN \r
+dapl_os_lock_init (\r
+ IN DAPL_OS_LOCK *m)\r
+{\r
+ *m = CreateMutex (0, FALSE, 0);\r
+\r
+ return *m ? DAT_SUCCESS : (DAT_CLASS_ERROR | DAT_INSUFFICIENT_RESOURCES);\r
+}\r
+\r
+STATIC __inline DAT_RETURN \r
+dapl_os_lock (\r
+ IN DAPL_OS_LOCK *m)\r
+{\r
+ WaitForSingleObject (*m, INFINITE);\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+STATIC __inline DAT_RETURN \r
+dapl_os_unlock (\r
+ IN DAPL_OS_LOCK *m)\r
+{\r
+ ReleaseMutex (*m);\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+STATIC __inline DAT_RETURN \r
+dapl_os_lock_destroy (\r
+ IN DAPL_OS_LOCK *m)\r
+{\r
+ CloseHandle (*m);\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+\r
+/*\r
+ * Wait Objects\r
+ */\r
+\r
+/*\r
+ * The wait object invariant: Presuming a call to dapl_os_wait_object_wait\r
+ * occurs at some point, there will be at least one wakeup after each call\r
+ * to dapl_os_wait_object_signal. I.e. Signals are not ignored, though\r
+ * they may be coallesced.\r
+ */\r
+\r
+/* wait_object functions */\r
+\r
+typedef HANDLE DAPL_OS_WAIT_OBJECT;\r
+\r
+/* Initialize a wait object to an empty state\r
+ */\r
+\r
+STATIC __inline DAT_RETURN \r
+dapl_os_wait_object_init (\r
+ IN DAPL_OS_WAIT_OBJECT *wait_obj)\r
+{\r
+ *wait_obj = CreateEvent(NULL,FALSE,FALSE,NULL);\r
+\r
+ if ( *wait_obj == NULL )\r
+ {\r
+ return DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;\r
+ }\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+\r
+/* Wait on the supplied wait object, up to the specified time_out,\r
+ * and reacquiring it after the wait ends.\r
+ * A timeout of DAT_TIMEOUT_INFINITE will wait indefinitely.\r
+ * Timeout should be specified in micro seconds.\r
+ *\r
+ * Functional returns:\r
+ * DAT_SUCCESS -- another thread invoked dapl_os_wait object_wakeup\r
+ * DAT_INVALID_STATE -- someone else is already waiting in this wait\r
+ * object.\r
+ * only one waiter is allowed at a time.\r
+ * DAT_ABORT -- another thread invoked dapl_os_wait_object_destroy\r
+ * DAT_TIMEOUT -- the specified time limit was reached.\r
+ */\r
+\r
+STATIC __inline DAT_RETURN \r
+dapl_os_wait_object_wait (\r
+ IN DAPL_OS_WAIT_OBJECT *wait_obj, \r
+ IN DAT_TIMEOUT timeout_val)\r
+{\r
+ DAT_RETURN status;\r
+ DWORD op_status;\r
+\r
+ status = DAT_SUCCESS;\r
+\r
+ if ( DAT_TIMEOUT_INFINITE == timeout_val )\r
+ {\r
+ op_status = WaitForSingleObject(*wait_obj, INFINITE);\r
+ }\r
+ else\r
+ {\r
+ /* convert to milliseconds */\r
+ op_status = WaitForSingleObject(*wait_obj, timeout_val/1000);\r
+ }\r
+\r
+ if (op_status == WAIT_TIMEOUT)\r
+ {\r
+ status = DAT_CLASS_ERROR | DAT_TIMEOUT_EXPIRED;\r
+ }\r
+ else if ( op_status == WAIT_FAILED)\r
+ {\r
+ status = DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;\r
+ }\r
+\r
+ return status;\r
+}\r
+\r
+STATIC __inline DAT_RETURN \r
+dapl_os_wait_object_wakeup (\r
+ IN DAPL_OS_WAIT_OBJECT *wait_obj)\r
+{\r
+ DWORD op_status;\r
+\r
+ op_status = SetEvent(*wait_obj);\r
+ if ( op_status == 0 )\r
+ {\r
+ return DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;\r
+ }\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+STATIC __inline DAT_RETURN \r
+dapl_os_wait_object_destroy (\r
+ IN DAPL_OS_WAIT_OBJECT *wait_obj)\r
+{\r
+ DWORD op_status;\r
+ DAT_RETURN status = DAT_SUCCESS;\r
+\r
+ op_status = CloseHandle(*wait_obj);\r
+\r
+ if ( op_status == 0 )\r
+ {\r
+ status = DAT_CLASS_ERROR | DAT_INTERNAL_ERROR;\r
+ }\r
+\r
+ return status;\r
+}\r
+\r
+\r
+/*\r
+ * Memory Functions\r
+ */\r
+\r
+extern HANDLE heap;\r
+\r
+/* function prototypes */\r
+STATIC __inline void *dapl_os_alloc (int size);\r
+\r
+STATIC __inline void *dapl_os_realloc (void *ptr, int size);\r
+\r
+STATIC __inline void dapl_os_free (void *ptr, int size);\r
+\r
+STATIC __inline void * dapl_os_memzero (void *loc, int size);\r
+\r
+STATIC __inline void * dapl_os_memcpy (void *dest, const void *src, int len);\r
+\r
+STATIC __inline int dapl_os_memcmp (const void *mem1, const void *mem2, int len);\r
+\r
+/*\r
+ * Memory coherency functions\r
+ * For i386/x86_64 Windows, there are no coherency issues - just return success.\r
+ */\r
+STATIC __inline DAT_RETURN\r
+dapl_os_sync_rdma_read (\r
+ IN const DAT_LMR_TRIPLET *local_segments,\r
+ IN DAT_VLEN num_segments)\r
+{\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+STATIC __inline DAT_RETURN\r
+dapl_os_sync_rdma_write (\r
+ IN const DAT_LMR_TRIPLET *local_segments,\r
+ IN DAT_VLEN num_segments)\r
+{\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+\r
+/* memory functions */\r
+\r
+\r
+STATIC __inline void *dapl_os_alloc (int size)\r
+{\r
+ return HeapAlloc(heap, 0, size);\r
+}\r
+\r
+STATIC __inline void *dapl_os_realloc (void *ptr, int size)\r
+{\r
+ return HeapReAlloc(heap, 0, ptr, size);\r
+}\r
+\r
+STATIC __inline void dapl_os_free (void *ptr, int size)\r
+{\r
+ UNREFERENCED_PARAMETER(size);\r
+ HeapFree(heap, 0, ptr);\r
+}\r
+\r
+STATIC __inline void * dapl_os_memzero (void *loc, int size)\r
+{\r
+ return memset (loc, 0, size);\r
+}\r
+\r
+STATIC __inline void * dapl_os_memcpy (void *dest, const void *src, int len)\r
+{\r
+ return memcpy (dest, src, len);\r
+}\r
+\r
+STATIC __inline int dapl_os_memcmp (const void *mem1, const void *mem2, int len)\r
+{\r
+ return memcmp (mem1, mem2, len);\r
+}\r
+\r
+\r
+STATIC __inline unsigned int dapl_os_strlen(const char *str)\r
+{\r
+ return ((unsigned int)strlen(str));\r
+}\r
+\r
+STATIC __inline char * dapl_os_strdup(const char *str)\r
+{\r
+ char *dup;\r
+\r
+ dup = dapl_os_alloc(strlen(str) + 1);\r
+ if (!dup)\r
+ return NULL;\r
+ strcpy(dup, str);\r
+ return dup;\r
+}\r
+\r
+\r
+/*\r
+ * Timer Functions\r
+ */\r
+\r
+typedef DAT_UINT64 DAPL_OS_TIMEVAL;\r
+typedef struct dapl_timer_entry DAPL_OS_TIMER;\r
+typedef unsigned long DAPL_OS_TICKS;\r
+\r
+/* function prototypes */\r
+\r
+/*\r
+ * Sleep for the number of micro seconds specified by the invoking\r
+ * function\r
+ */\r
+STATIC __inline void dapl_os_sleep_usec (int sleep_time)\r
+{\r
+ Sleep(sleep_time/1000); // convert to milliseconds\r
+}\r
+\r
+STATIC __inline DAPL_OS_TICKS dapl_os_get_ticks (void);\r
+\r
+STATIC __inline int dapl_os_ticks_to_seconds (DAPL_OS_TICKS ticks);\r
+\r
+DAT_RETURN dapl_os_get_time (DAPL_OS_TIMEVAL *);\r
+/* timer functions */\r
+\r
+STATIC __inline DAPL_OS_TICKS dapl_os_get_ticks (void)\r
+{\r
+ return GetTickCount ();\r
+}\r
+\r
+STATIC __inline int dapl_os_ticks_to_seconds (DAPL_OS_TICKS ticks)\r
+{\r
+ ticks = ticks;\r
+ /* NOT YET IMPLEMENTED IN USER-SPACE */\r
+ return 0;\r
+}\r
+\r
+\r
+/*\r
+ *\r
+ * Name Service Helper functions\r
+ *\r
+ */\r
+#ifdef IBHOSTS_NAMING\r
+#define dapls_osd_getaddrinfo(name, addr_ptr) getaddrinfo(name,NULL,NULL,addr_ptr)\r
+#define dapls_osd_freeaddrinfo(addr) freeaddrinfo (addr)\r
+\r
+#endif /* IBHOSTS_NAMING */\r
+\r
+/*\r
+ * *printf format helpers. We use the C string constant concatenation\r
+ * ability to define 64 bit formats, which unfortunatly are non standard\r
+ * in the C compiler world. E.g. %llx for gcc, %I64x for Windows\r
+ */\r
+#define F64d "%I64d"\r
+#define F64u "%I64u"\r
+#define F64x "%I64x"\r
+#define F64X "%I64X"\r
+\r
+/*\r
+ * Conversion Functions\r
+ */\r
+\r
+STATIC __inline long int\r
+dapl_os_strtol(const char *nptr, char **endptr, int base)\r
+{\r
+ return strtol(nptr, endptr, base);\r
+}\r
+\r
+#define dapl_os_getpid (DAT_UINT32)GetCurrentProcessId\r
+#define dapl_os_gettid (DAT_UINT32)GetCurrentThreadId\r
+\r
+/*\r
+ * Debug Helper Functions\r
+ */\r
+\r
+#define dapl_os_assert(expression) CL_ASSERT(expression)\r
+\r
+#define dapl_os_printf printf\r
+#define dapl_os_vprintf(fmt,args) vprintf(fmt,args)\r
+#define dapl_os_syslog(fmt,args) /* XXX Need log routine call */\r
+\r
+#endif /* _DAPL_OSD_H_ */\r
+\r
+/*\r
+ * Local variables:\r
+ * c-indent-level: 4\r
+ * c-basic-offset: 4\r
+ * tab-width: 8\r
+ * End:\r
+ */\r
-/*
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
- *
- * This Software is licensed under either one of the following two licenses:
- *
- * 1) under the terms of the "Common Public License 1.0" a copy of which is
- * in the file LICENSE.txt in the root directory. The license is also
- * available from the Open Source Initiative, see
- * http://www.opensource.org/licenses/cpl.php.
- * OR
- *
- * 2) under the terms of the "The BSD License" a copy of which is in the file
- * LICENSE2.txt in the root directory. The license is also available from
- * the Open Source Initiative, see
- * http://www.opensource.org/licenses/bsd-license.php.
- *
- * Licensee has the right to choose either one of the above two licenses.
- *
- * Redistributions of source code must retain both the above copyright
- * notice and either one of the license notices.
- *
- * Redistributions in binary form must reproduce both the above copyright
- * notice, either one of the license notices in the documentation
- * and/or other materials provided with the distribution.
- */
-
-/**********************************************************************
- *
- * MODULE: dat_osd.c
- *
- * PURPOSE: Operating System Dependent layer
- * Description:
- * Provide OS dependent functions with a canonical DAPL
- * interface. Designed to be portable and hide OS specific quirks
- * of common functions.
- *
- * $Id: dat_osd.c 33 2005-07-11 19:51:17Z ftillier $
- **********************************************************************/
-
-#include "dat_osd.h"
-#include "dat_init.h"
-
-
-/*********************************************************************
- * *
- * Constants *
- * *
- *********************************************************************/
-
-#define DAT_DBG_LEVEL_ENV "DAT_DBG_LEVEL"
-#define DAT_DBG_DEST_ENV "DAT_DBG_DEST"
-
-
-/*********************************************************************
- * *
- * Enumerations *
- * *
- *********************************************************************/
-
-typedef int DAT_OS_DBG_DEST;
-
-typedef enum
-{
- DAT_OS_DBG_DEST_STDOUT = 0x1,
-} DAT_OS_DBG_DEST_TYPE;
-
-
-/*********************************************************************
- * *
- * Global Variables *
- * *
- *********************************************************************/
-
-static DAT_OS_DBG_TYPE_VAL g_dbg_type = DAT_OS_DBG_TYPE_ERROR;
-static DAT_OS_DBG_DEST g_dbg_dest = DAT_OS_DBG_DEST_STDOUT;
-
-
-/***********************************************************************
- * Function: dat_os_dbg_set_level
- ***********************************************************************/
-
-void
-dat_os_dbg_init ( void )
-{
- char *dbg_type;
- char *dbg_dest;
-
- dbg_type = dat_os_getenv (DAT_DBG_LEVEL_ENV);
- if ( dbg_type != NULL )
- {
- g_dbg_type = dat_os_strtol(dbg_type, NULL, 0);
- }
-
- dbg_dest = dat_os_getenv (DAT_DBG_DEST_ENV);
- if ( dbg_dest != NULL )
- {
- g_dbg_dest = dat_os_strtol(dbg_dest, NULL, 0);
- }
-}
-
-
-/***********************************************************************
- * Function: dat_os_dbg_print
- ***********************************************************************/
-
-void
-dat_os_dbg_print (
- DAT_OS_DBG_TYPE_VAL type,
- const char * fmt,
- ...)
-{
- if ( (DAT_OS_DBG_TYPE_ERROR == type) || (type & g_dbg_type) )
- {
- va_list args;
-
- if ( DAT_OS_DBG_DEST_STDOUT & g_dbg_dest )
- {
- va_start(args, fmt);
- vfprintf(stdout, fmt, args);
- fflush(stdout);
- va_end(args);
- }
- /* no syslog() susport in Windows */
- }
-}
-
-
-BOOL APIENTRY
-DllMain(
- IN HINSTANCE h_module,
- IN DWORD ul_reason_for_call,
- IN LPVOID lp_reserved )
-{
- extern DAT_BOOLEAN udat_check_state ( void );
-
- UNREFERENCED_PARAMETER( lp_reserved );
-
- switch( ul_reason_for_call )
- {
- case DLL_PROCESS_ATTACH:
- DisableThreadLibraryCalls( h_module );
- udat_check_state();
- break;
-
- case DLL_PROCESS_DETACH:
- dat_fini();
- }
-
- return TRUE;
-}
-
-char *
-dat_os_library_error(void)
-{
- DWORD rc;
- LPVOID lpMsgBuf;
-
- if (errno == 0)
- return NULL;
-
- // consider formatmessage()?
- rc = GetLastError();
-
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- rc,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf,
- 0, NULL );
-
- //LocalFree(lpMsgBuf); error condition - will exit anyway.
-
- return (char*)lpMsgBuf;
-}
-
-#ifndef INLINE_LIB_LOAD
-
-DAT_RETURN
-dat_os_library_load ( const char *library_path,
- DAT_OS_LIBRARY_HANDLE *library_handle_ptr )
-{
- DAT_OS_LIBRARY_HANDLE library_handle;
- DAT_RETURN rc = DAT_SUCCESS;
-
- if ( NULL != (library_handle = LoadLibrary(library_path)) )
- {
- if ( NULL != library_handle_ptr )
- {
- *library_handle_ptr = library_handle;
- }
- }
- else
- {
- dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR,
- "DAT: library %s load failure\n",library_path);
- rc = DAT_INTERNAL_ERROR;
- }
- return rc;
-}
-#endif
+/*\r
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
+ *\r
+ * This Software is licensed under either one of the following two licenses:\r
+ *\r
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
+ * in the file LICENSE.txt in the root directory. The license is also\r
+ * available from the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/cpl.php.\r
+ * OR\r
+ *\r
+ * 2) under the terms of the "The BSD License" a copy of which is in the file\r
+ * LICENSE2.txt in the root directory. The license is also available from\r
+ * the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/bsd-license.php.\r
+ *\r
+ * Licensee has the right to choose either one of the above two licenses.\r
+ *\r
+ * Redistributions of source code must retain both the above copyright\r
+ * notice and either one of the license notices.\r
+ *\r
+ * Redistributions in binary form must reproduce both the above copyright\r
+ * notice, either one of the license notices in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ */\r
+\r
+/**********************************************************************\r
+ * \r
+ * MODULE: dat_osd.c\r
+ *\r
+ * PURPOSE: Operating System Dependent layer\r
+ * Description: \r
+ * Provide OS dependent functions with a canonical DAPL\r
+ * interface. Designed to be portable and hide OS specific quirks\r
+ * of common functions.\r
+ *\r
+ * $Id: dat_osd.c 33 2005-07-11 19:51:17Z ftillier $\r
+ **********************************************************************/\r
+\r
+#include "dat_osd.h"\r
+#include "dat_init.h"\r
+\r
+\r
+/*********************************************************************\r
+ * *\r
+ * Constants *\r
+ * *\r
+ *********************************************************************/\r
+\r
+#define DAT_DBG_LEVEL_ENV "DAT_DBG_LEVEL"\r
+#define DAT_DBG_DEST_ENV "DAT_DBG_DEST"\r
+\r
+\r
+/*********************************************************************\r
+ * *\r
+ * Enumerations *\r
+ * *\r
+ *********************************************************************/\r
+\r
+typedef int DAT_OS_DBG_DEST;\r
+\r
+typedef enum\r
+{\r
+ DAT_OS_DBG_DEST_STDOUT = 0x1,\r
+} DAT_OS_DBG_DEST_TYPE;\r
+\r
+\r
+/*********************************************************************\r
+ * *\r
+ * Global Variables *\r
+ * *\r
+ *********************************************************************/\r
+\r
+static DAT_OS_DBG_TYPE_VAL g_dbg_type = DAT_OS_DBG_TYPE_ERROR;\r
+static DAT_OS_DBG_DEST g_dbg_dest = DAT_OS_DBG_DEST_STDOUT;\r
+\r
+\r
+/***********************************************************************\r
+ * Function: dat_os_dbg_set_level\r
+ ***********************************************************************/\r
+\r
+void\r
+dat_os_dbg_init ( void )\r
+{\r
+ char *dbg_type;\r
+ char *dbg_dest;\r
+\r
+ dbg_type = dat_os_getenv (DAT_DBG_LEVEL_ENV);\r
+ if ( dbg_type != NULL )\r
+ {\r
+ g_dbg_type = dat_os_strtol(dbg_type, NULL, 0);\r
+ }\r
+\r
+ dbg_dest = dat_os_getenv (DAT_DBG_DEST_ENV);\r
+ if ( dbg_dest != NULL )\r
+ {\r
+ g_dbg_dest = dat_os_strtol(dbg_dest, NULL, 0);\r
+ }\r
+}\r
+\r
+\r
+/***********************************************************************\r
+ * Function: dat_os_dbg_print\r
+ ***********************************************************************/\r
+\r
+void \r
+dat_os_dbg_print ( \r
+ DAT_OS_DBG_TYPE_VAL type, \r
+ const char * fmt, \r
+ ...)\r
+{\r
+ if ( (DAT_OS_DBG_TYPE_ERROR == type) || (type & g_dbg_type) )\r
+ {\r
+ va_list args;\r
+ \r
+ if ( DAT_OS_DBG_DEST_STDOUT & g_dbg_dest )\r
+ {\r
+ va_start(args, fmt);\r
+ vfprintf(stdout, fmt, args);\r
+ fflush(stdout);\r
+ va_end(args);\r
+ }\r
+ /* no syslog() susport in Windows */\r
+ }\r
+}\r
+\r
+HANDLE heap;\r
+\r
+BOOL APIENTRY\r
+DllMain(\r
+ IN HINSTANCE h_module,\r
+ IN DWORD ul_reason_for_call, \r
+ IN LPVOID lp_reserved )\r
+{\r
+ extern DAT_BOOLEAN udat_check_state ( void );\r
+\r
+ UNREFERENCED_PARAMETER( lp_reserved );\r
+\r
+ switch( ul_reason_for_call )\r
+ {\r
+ case DLL_PROCESS_ATTACH:\r
+ heap = HeapCreate(0, 0, 0);\r
+ if (heap == NULL)\r
+ return FALSE;\r
+ DisableThreadLibraryCalls( h_module );\r
+ udat_check_state();\r
+ break;\r
+\r
+ case DLL_PROCESS_DETACH:\r
+ dat_fini();\r
+ HeapDestroy(heap);\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+char *\r
+dat_os_library_error(void)\r
+{\r
+ DWORD rc;\r
+ LPVOID lpMsgBuf;\r
+\r
+ if (errno == 0)\r
+ return NULL;\r
+\r
+ // consider formatmessage()?\r
+ rc = GetLastError();\r
+\r
+ FormatMessage(\r
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | \r
+ FORMAT_MESSAGE_FROM_SYSTEM |\r
+ FORMAT_MESSAGE_IGNORE_INSERTS,\r
+ NULL,\r
+ rc,\r
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),\r
+ (LPTSTR) &lpMsgBuf,\r
+ 0, NULL );\r
+\r
+ //LocalFree(lpMsgBuf); error condition - will exit anyway.\r
+\r
+ return (char*)lpMsgBuf;\r
+}\r
+\r
+#ifndef INLINE_LIB_LOAD\r
+\r
+DAT_RETURN\r
+dat_os_library_load ( const char *library_path,\r
+ DAT_OS_LIBRARY_HANDLE *library_handle_ptr )\r
+{\r
+ DAT_OS_LIBRARY_HANDLE library_handle;\r
+ DAT_RETURN rc = DAT_SUCCESS;\r
+\r
+ if ( NULL != (library_handle = LoadLibrary(library_path)) )\r
+ {\r
+ if ( NULL != library_handle_ptr ) \r
+ { \r
+ *library_handle_ptr = library_handle; \r
+ }\r
+ }\r
+ else\r
+ { \r
+ dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR,\r
+ "DAT: library %s load failure\n",library_path);\r
+ rc = DAT_INTERNAL_ERROR;\r
+ }\r
+ return rc;\r
+}\r
+#endif\r
-/*
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
- *
- * This Software is licensed under either one of the following two licenses:
- *
- * 1) under the terms of the "Common Public License 1.0" a copy of which is
- * in the file LICENSE.txt in the root directory. The license is also
- * available from the Open Source Initiative, see
- * http://www.opensource.org/licenses/cpl.php.
- * OR
- *
- * 2) under the terms of the "The BSD License" a copy of which is in the file
- * LICENSE2.txt in the root directory. The license is also available from
- * the Open Source Initiative, see
- * http://www.opensource.org/licenses/bsd-license.php.
- *
- * Licensee has the right to choose either one of the above two licenses.
- *
- * Redistributions of source code must retain both the above copyright
- * notice and either one of the license notices.
- *
- * Redistributions in binary form must reproduce both the above copyright
- * notice, either one of the license notices in the documentation
- * and/or other materials provided with the distribution.
- */
-
-/**********************************************************************
- *
- * HEADER: dat_osd.h
- *
- * PURPOSE: Operating System Dependent layer
- * Description:
- * Provide OS dependent data structures & functions with
- * a canonical DAPL interface. Designed to be portable
- * and hide OS specific quirks of common functions.
- *
- * $Id: dat_osd.h 33 2005-07-11 19:51:17Z ftillier $
- **********************************************************************/
-
-#ifndef _DAT_OSD_H_
-#define _DAT_OSD_H_
-
-/*
- * This file is defined for Windows systems only, including it on any
- * other build will cause an error
- */
-#if !defined(WIN32) && !defined(WIN64)
-#error "UNDEFINED OS TYPE"
-#endif /* WIN32/64 */
-
-#include <dat2/udat.h>
-#include <dat2/dat_registry.h>
-
-#include <windows.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-#ifndef STATIC
-#define STATIC static
-#endif /* STATIC */
-
-#ifndef INLINE
-#define INLINE __inline
-#endif /* INLINE */
-
-#ifndef __inline__
-#define __inline__ __inline
-#endif /* __inline */
-
-/*********************************************************************
- * *
- * Debuging *
- * *
- *********************************************************************/
-
-#define dat_os_assert(expr) assert(expr)
-
-typedef int DAT_OS_DBG_TYPE_VAL;
-
-typedef enum
-{
- DAT_OS_DBG_TYPE_ERROR = 0x1,
- DAT_OS_DBG_TYPE_GENERIC = 0x2,
- DAT_OS_DBG_TYPE_SR = 0x4,
- DAT_OS_DBG_TYPE_DR = 0x8,
- DAT_OS_DBG_TYPE_PROVIDER_API = 0x10,
- DAT_OS_DBG_TYPE_CONSUMER_API = 0x20,
- DAT_OS_DBG_TYPE_ALL = 0xff
-} DAT_OS_DBG_TYPE_TYPE;
-
-extern void
-dat_os_dbg_init ( void );
-
-extern void
-dat_os_dbg_print (
- DAT_OS_DBG_TYPE_VAL type,
- const char * fmt,
- ...);
-
-
-/*********************************************************************
- * *
- * Utility Functions *
- * *
- *********************************************************************/
-
-#define DAT_ERROR(Type,SubType) ((DAT_RETURN)(DAT_CLASS_ERROR | Type | SubType))
-
-typedef size_t DAT_OS_SIZE;
-typedef HMODULE DAT_OS_LIBRARY_HANDLE;
-
-#ifdef INLINE_LIB_LOAD
-
-STATIC INLINE DAT_RETURN
-dat_os_library_load (
- const char *library_path,
- DAT_OS_LIBRARY_HANDLE *library_handle_ptr)
-{
- DAT_OS_LIBRARY_HANDLE library_handle;
-
- if ( NULL != (library_handle = LoadLibrary(library_path)) )
- {
- if ( NULL != library_handle_ptr )
- {
- *library_handle_ptr = library_handle;
- }
- return DAT_SUCCESS;
- }
- else
- {
- dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR,
- "DAT: library load failure\n");
- return DAT_INTERNAL_ERROR;
- }
-}
-#else
-
-DAT_RETURN
-dat_os_library_load (
- const char *library_path,
- DAT_OS_LIBRARY_HANDLE *library_handle_ptr);
-
-#endif
-
-extern char *dat_os_library_error(void);
-
-#ifdef WIN32_LEAN_AND_MEAN
-#define dat_os_library_sym GetProcAddress
-#else
-STATIC INLINE
-dat_os_library_sym (
- DAT_OS_LIBRARY_HANDLE library_handle,
- const char *sym)
-{
- return GetProcAddress(library_handle, (LPCSTR)sym);
-}
-#endif /* WIN32_LEAN_AND_MEAN */
-
-STATIC INLINE DAT_RETURN
-dat_os_library_unload (
- const DAT_OS_LIBRARY_HANDLE library_handle)
-{
- if ( 0 == FreeLibrary(library_handle) )
- {
- return DAT_INTERNAL_ERROR;
- }
- else
- {
- return DAT_SUCCESS;
- }
-}
-
-STATIC INLINE char *
-dat_os_getenv (
- const char *name)
-{
- return getenv(name);
-}
-
-STATIC INLINE long int
-dat_os_strtol (
- const char *nptr,
- char **endptr,
- int base)
-{
- return strtol(nptr, endptr, base);
-}
-
-STATIC INLINE DAT_OS_SIZE
-dat_os_strlen (
- const char *s )
-{
- return strlen(s);
-}
-
-STATIC INLINE int
-dat_os_strncmp (
- const char *s1,
- const char *s2,
- DAT_OS_SIZE n)
-{
- return strncmp(s1, s2, n);
-}
-
-STATIC INLINE void *
-dat_os_strncpy (
- char *dest,
- const char *src,
- DAT_OS_SIZE len)
-{
- return strncpy (dest, src, len);
-}
-
-STATIC INLINE DAT_BOOLEAN
-dat_os_isblank(
- int c)
-{
- if ( (' ' == c) || ('\t' == c) ) { return DAT_TRUE; }
- else { return DAT_FALSE; }
-}
-
-STATIC INLINE DAT_BOOLEAN
-dat_os_isdigit(
- int c)
-{
- if ( isdigit(c) ) { return DAT_TRUE; }
- else { return DAT_FALSE; }
-}
-
-STATIC INLINE void
-dat_os_usleep(
- unsigned long usec)
-{
- Sleep(usec/1000);
-}
-
-
-/*********************************************************************
- * *
- * Memory Functions *
- * *
- *********************************************************************/
-
-STATIC INLINE void *
-dat_os_alloc (
- int size)
-{
- return malloc (size);
-}
-
-STATIC INLINE void
-dat_os_free (
- void *ptr,
- int size)
-{
- free (ptr);
-}
-
-STATIC INLINE void *
-dat_os_memset (void *loc, int c, DAT_OS_SIZE size)
-{
- return memset (loc, c, size);
-}
-
-
-/*********************************************************************
- * *
- * File I/O *
- * *
- *********************************************************************/
-
-typedef FILE DAT_OS_FILE;
-typedef fpos_t DAT_OS_FILE_POS;
-
-
-STATIC INLINE DAT_OS_FILE *
-dat_os_fopen (
- const char * path)
-{
- /* always open files in read only mode*/
- return fopen(path, "r");
-}
-
-STATIC INLINE DAT_RETURN
-dat_os_fgetpos (
- DAT_OS_FILE *file,
- DAT_OS_FILE_POS *pos)
-{
- if ( 0 == fgetpos(file, pos) )
- {
- return DAT_SUCCESS;
- }
- else
- {
- return DAT_INTERNAL_ERROR;
- }
-}
-
-STATIC INLINE DAT_RETURN
-dat_os_fsetpos (
- DAT_OS_FILE *file,
- DAT_OS_FILE_POS *pos)
-{
- if ( 0 == fsetpos(file, pos) )
- {
- return DAT_SUCCESS;
- }
- else
- {
- return DAT_INTERNAL_ERROR;
- }
-}
-
-/* dat_os_fgetc() returns EOF on error or end of file. */
-STATIC INLINE int
-dat_os_fgetc (
- DAT_OS_FILE *file)
-{
- return fgetc(file);
-}
-
-/* dat_os_ungetc() returns EOF on error or char 'c'.
- * Push char 'c' back into specified stream for subsequent read.
- */
-STATIC INLINE int
-dat_os_ungetc (
- DAT_OS_FILE *file, int c)
-{
- return ungetc(c, file);
-}
-
-/* dat_os_fputc() returns EOF on error or char 'c'. */
-STATIC INLINE int
-dat_os_fputc (
- DAT_OS_FILE *file, int c)
-{
- return fputc(c, file);
-}
-
-/* dat_os_fread returns the number of bytes read from the file. */
-STATIC INLINE DAT_OS_SIZE
-dat_os_fread (
- DAT_OS_FILE *file,
- char *buf,
- DAT_OS_SIZE len)
-{
- return fread(buf, sizeof(char), len, file);
-}
-
-STATIC INLINE DAT_RETURN
-dat_os_fclose (
- DAT_OS_FILE *file)
-{
- if ( 0 == fclose(file) )
- {
- return DAT_SUCCESS;
- }
- else
- {
- return DAT_INTERNAL_ERROR;
- }
-}
-
-
-/*********************************************************************
- * *
- * Locks *
- * *
- *********************************************************************/
-
-typedef HANDLE DAT_OS_LOCK;
-
-/* lock functions */
-STATIC INLINE DAT_RETURN
-dat_os_lock_init (
- IN DAT_OS_LOCK *m)
-{
- *m = CreateMutex (0, FALSE, 0);
- if (*(HANDLE *)m == NULL)
- {
- return DAT_INTERNAL_ERROR;
- }
- return DAT_SUCCESS;
-}
-
-STATIC INLINE DAT_RETURN
-dat_os_lock (
- IN DAT_OS_LOCK *m)
-{
- WaitForSingleObject(*m, INFINITE);
-
- return DAT_SUCCESS;
-}
-
-STATIC INLINE DAT_RETURN
-dat_os_unlock (
- IN DAT_OS_LOCK *m)
-{
- ReleaseMutex (*m);
-
- return DAT_SUCCESS;
-}
-
-STATIC INLINE DAT_RETURN
-dat_os_lock_destroy (
- IN DAT_OS_LOCK *m)
-{
- CloseHandle (*m);
-
- return DAT_SUCCESS;
-}
-
-
-#endif /* _DAT_OSD_H_ */
-
-/*
- * Local variables:
- * c-indent-level: 4
- * c-basic-offset: 4
- * tab-width: 8
- * End:
- */
-
+/*\r
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
+ *\r
+ * This Software is licensed under either one of the following two licenses:\r
+ *\r
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
+ * in the file LICENSE.txt in the root directory. The license is also\r
+ * available from the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/cpl.php.\r
+ * OR\r
+ *\r
+ * 2) under the terms of the "The BSD License" a copy of which is in the file\r
+ * LICENSE2.txt in the root directory. The license is also available from\r
+ * the Open Source Initiative, see\r
+ * http://www.opensource.org/licenses/bsd-license.php.\r
+ *\r
+ * Licensee has the right to choose either one of the above two licenses.\r
+ *\r
+ * Redistributions of source code must retain both the above copyright\r
+ * notice and either one of the license notices.\r
+ *\r
+ * Redistributions in binary form must reproduce both the above copyright\r
+ * notice, either one of the license notices in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ */\r
+\r
+/**********************************************************************\r
+ * \r
+ * HEADER: dat_osd.h\r
+ *\r
+ * PURPOSE: Operating System Dependent layer\r
+ * Description:\r
+ * Provide OS dependent data structures & functions with\r
+ * a canonical DAPL interface. Designed to be portable\r
+ * and hide OS specific quirks of common functions.\r
+ *\r
+ * $Id: dat_osd.h 33 2005-07-11 19:51:17Z ftillier $\r
+ **********************************************************************/\r
+\r
+#ifndef _DAT_OSD_H_\r
+#define _DAT_OSD_H_\r
+\r
+/*\r
+ * This file is defined for Windows systems only, including it on any\r
+ * other build will cause an error\r
+ */\r
+#if !defined(WIN32) && !defined(WIN64)\r
+#error "UNDEFINED OS TYPE"\r
+#endif /* WIN32/64 */\r
+\r
+#include <dat2/udat.h>\r
+#include <dat2/dat_registry.h>\r
+\r
+#include <windows.h>\r
+#include <assert.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdarg.h>\r
+\r
+#ifndef STATIC\r
+#define STATIC static\r
+#endif /* STATIC */\r
+\r
+#ifndef INLINE\r
+#define INLINE __inline\r
+#endif /* INLINE */\r
+\r
+#ifndef __inline__\r
+#define __inline__ __inline\r
+#endif /* __inline */\r
+\r
+/*********************************************************************\r
+ * *\r
+ * Debuging *\r
+ * *\r
+ *********************************************************************/\r
+\r
+#define dat_os_assert(expr) assert(expr)\r
+\r
+typedef int DAT_OS_DBG_TYPE_VAL;\r
+\r
+typedef enum\r
+{\r
+ DAT_OS_DBG_TYPE_ERROR = 0x1,\r
+ DAT_OS_DBG_TYPE_GENERIC = 0x2,\r
+ DAT_OS_DBG_TYPE_SR = 0x4,\r
+ DAT_OS_DBG_TYPE_DR = 0x8,\r
+ DAT_OS_DBG_TYPE_PROVIDER_API = 0x10,\r
+ DAT_OS_DBG_TYPE_CONSUMER_API = 0x20,\r
+ DAT_OS_DBG_TYPE_ALL = 0xff\r
+} DAT_OS_DBG_TYPE_TYPE;\r
+\r
+extern void\r
+dat_os_dbg_init ( void );\r
+\r
+extern void \r
+dat_os_dbg_print ( \r
+ DAT_OS_DBG_TYPE_VAL type, \r
+ const char * fmt, \r
+ ...);\r
+\r
+\r
+/*********************************************************************\r
+ * *\r
+ * Utility Functions *\r
+ * *\r
+ *********************************************************************/\r
+\r
+#define DAT_ERROR(Type,SubType) ((DAT_RETURN)(DAT_CLASS_ERROR | Type | SubType))\r
+\r
+typedef size_t DAT_OS_SIZE;\r
+typedef HMODULE DAT_OS_LIBRARY_HANDLE;\r
+\r
+#ifdef INLINE_LIB_LOAD\r
+\r
+STATIC INLINE DAT_RETURN\r
+dat_os_library_load (\r
+ const char *library_path,\r
+ DAT_OS_LIBRARY_HANDLE *library_handle_ptr)\r
+{\r
+ DAT_OS_LIBRARY_HANDLE library_handle;\r
+\r
+ if ( NULL != (library_handle = LoadLibrary(library_path)) )\r
+ {\r
+ if ( NULL != library_handle_ptr ) \r
+ { \r
+ *library_handle_ptr = library_handle; \r
+ }\r
+ return DAT_SUCCESS;\r
+ }\r
+ else\r
+ { \r
+ dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR,\r
+ "DAT: library load failure\n");\r
+ return DAT_INTERNAL_ERROR;\r
+ }\r
+}\r
+#else\r
+\r
+DAT_RETURN\r
+dat_os_library_load (\r
+ const char *library_path,\r
+ DAT_OS_LIBRARY_HANDLE *library_handle_ptr);\r
+\r
+#endif\r
+\r
+extern char *dat_os_library_error(void);\r
+\r
+#ifdef WIN32_LEAN_AND_MEAN\r
+#define dat_os_library_sym GetProcAddress\r
+#else\r
+STATIC INLINE\r
+dat_os_library_sym (\r
+ DAT_OS_LIBRARY_HANDLE library_handle,\r
+ const char *sym)\r
+{\r
+ return GetProcAddress(library_handle, (LPCSTR)sym);\r
+}\r
+#endif /* WIN32_LEAN_AND_MEAN */\r
+\r
+STATIC INLINE DAT_RETURN\r
+dat_os_library_unload (\r
+ const DAT_OS_LIBRARY_HANDLE library_handle)\r
+{\r
+ if ( 0 == FreeLibrary(library_handle) )\r
+ {\r
+ return DAT_INTERNAL_ERROR;\r
+ }\r
+ else \r
+ {\r
+ return DAT_SUCCESS;\r
+ }\r
+}\r
+\r
+STATIC INLINE char *\r
+dat_os_getenv (\r
+ const char *name)\r
+{\r
+ return getenv(name);\r
+}\r
+\r
+STATIC INLINE long int\r
+dat_os_strtol (\r
+ const char *nptr, \r
+ char **endptr, \r
+ int base)\r
+{\r
+ return strtol(nptr, endptr, base);\r
+}\r
+\r
+STATIC INLINE DAT_OS_SIZE\r
+dat_os_strlen (\r
+ const char *s )\r
+{\r
+ return strlen(s);\r
+}\r
+\r
+STATIC INLINE int\r
+dat_os_strncmp (\r
+ const char *s1, \r
+ const char *s2, \r
+ DAT_OS_SIZE n)\r
+{\r
+ return strncmp(s1, s2, n);\r
+}\r
+\r
+STATIC INLINE void * \r
+dat_os_strncpy (\r
+ char *dest, \r
+ const char *src, \r
+ DAT_OS_SIZE len)\r
+{\r
+ return strncpy (dest, src, len);\r
+}\r
+\r
+STATIC INLINE DAT_BOOLEAN\r
+dat_os_isblank( \r
+ int c)\r
+{\r
+ if ( (' ' == c) || ('\t' == c) ) { return DAT_TRUE; }\r
+ else { return DAT_FALSE; }\r
+}\r
+\r
+STATIC INLINE DAT_BOOLEAN\r
+dat_os_isdigit( \r
+ int c)\r
+{\r
+ if ( isdigit(c) ) { return DAT_TRUE; }\r
+ else { return DAT_FALSE; }\r
+}\r
+\r
+STATIC INLINE void \r
+dat_os_usleep( \r
+ unsigned long usec)\r
+{\r
+ Sleep(usec/1000);\r
+}\r
+\r
+\r
+/*********************************************************************\r
+ * *\r
+ * Memory Functions *\r
+ * *\r
+ *********************************************************************/\r
+\r
+extern HANDLE heap;\r
+\r
+STATIC INLINE void *\r
+dat_os_alloc (\r
+ int size)\r
+{\r
+ return HeapAlloc(heap, 0, size);\r
+}\r
+\r
+STATIC INLINE void \r
+dat_os_free (\r
+ void *ptr, \r
+ int size)\r
+{\r
+ UNREFERENCED_PARAMETER(size);\r
+ HeapFree(heap, 0, ptr);\r
+}\r
+\r
+STATIC INLINE void * \r
+dat_os_memset (void *loc, int c, DAT_OS_SIZE size)\r
+{\r
+ return memset (loc, c, size);\r
+}\r
+\r
+\r
+/*********************************************************************\r
+ * *\r
+ * File I/O *\r
+ * *\r
+ *********************************************************************/\r
+\r
+typedef FILE DAT_OS_FILE;\r
+typedef fpos_t DAT_OS_FILE_POS;\r
+\r
+\r
+STATIC INLINE DAT_OS_FILE *\r
+dat_os_fopen (\r
+ const char * path)\r
+{\r
+ /* always open files in read only mode*/\r
+ return fopen(path, "r");\r
+}\r
+\r
+STATIC INLINE DAT_RETURN\r
+dat_os_fgetpos ( \r
+ DAT_OS_FILE *file, \r
+ DAT_OS_FILE_POS *pos)\r
+{\r
+ if ( 0 == fgetpos(file, pos) )\r
+ {\r
+ return DAT_SUCCESS;\r
+ }\r
+ else\r
+ {\r
+ return DAT_INTERNAL_ERROR;\r
+ }\r
+}\r
+\r
+STATIC INLINE DAT_RETURN\r
+dat_os_fsetpos ( \r
+ DAT_OS_FILE *file, \r
+ DAT_OS_FILE_POS *pos)\r
+{\r
+ if ( 0 == fsetpos(file, pos) )\r
+ {\r
+ return DAT_SUCCESS;\r
+ }\r
+ else\r
+ {\r
+ return DAT_INTERNAL_ERROR;\r
+ }\r
+}\r
+\r
+/* dat_os_fgetc() returns EOF on error or end of file. */\r
+STATIC INLINE int\r
+dat_os_fgetc ( \r
+ DAT_OS_FILE *file)\r
+{\r
+ return fgetc(file);\r
+}\r
+\r
+/* dat_os_ungetc() returns EOF on error or char 'c'.\r
+ * Push char 'c' back into specified stream for subsequent read.\r
+ */\r
+STATIC INLINE int\r
+dat_os_ungetc ( \r
+ DAT_OS_FILE *file, int c)\r
+{\r
+ return ungetc(c, file);\r
+}\r
+\r
+/* dat_os_fputc() returns EOF on error or char 'c'. */\r
+STATIC INLINE int\r
+dat_os_fputc ( \r
+ DAT_OS_FILE *file, int c)\r
+{\r
+ return fputc(c, file);\r
+}\r
+\r
+/* dat_os_fread returns the number of bytes read from the file. */\r
+STATIC INLINE DAT_OS_SIZE\r
+dat_os_fread (\r
+ DAT_OS_FILE *file,\r
+ char *buf, \r
+ DAT_OS_SIZE len)\r
+{\r
+ return fread(buf, sizeof(char), len, file);\r
+}\r
+\r
+STATIC INLINE DAT_RETURN \r
+dat_os_fclose (\r
+ DAT_OS_FILE *file)\r
+{\r
+ if ( 0 == fclose(file) )\r
+ {\r
+ return DAT_SUCCESS;\r
+ }\r
+ else\r
+ {\r
+ return DAT_INTERNAL_ERROR;\r
+ }\r
+}\r
+\r
+\r
+/*********************************************************************\r
+ * *\r
+ * Locks *\r
+ * *\r
+ *********************************************************************/\r
+\r
+typedef HANDLE DAT_OS_LOCK;\r
+\r
+/* lock functions */\r
+STATIC INLINE DAT_RETURN \r
+dat_os_lock_init (\r
+ IN DAT_OS_LOCK *m)\r
+{\r
+ *m = CreateMutex (0, FALSE, 0);\r
+ if (*(HANDLE *)m == NULL)\r
+ {\r
+ return DAT_INTERNAL_ERROR;\r
+ }\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+STATIC INLINE DAT_RETURN \r
+dat_os_lock (\r
+ IN DAT_OS_LOCK *m)\r
+{\r
+ WaitForSingleObject(*m, INFINITE);\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+STATIC INLINE DAT_RETURN \r
+dat_os_unlock (\r
+ IN DAT_OS_LOCK *m)\r
+{\r
+ ReleaseMutex (*m);\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+STATIC INLINE DAT_RETURN \r
+dat_os_lock_destroy (\r
+ IN DAT_OS_LOCK *m)\r
+{\r
+ CloseHandle (*m);\r
+\r
+ return DAT_SUCCESS;\r
+}\r
+\r
+\r
+#endif /* _DAT_OSD_H_ */\r
+\r
+/*\r
+ * Local variables:\r
+ * c-indent-level: 4\r
+ * c-basic-offset: 4\r
+ * tab-width: 8\r
+ * End:\r
+ */\r
+\r
#include <windows.h>\r
\r
extern CRITICAL_SECTION lock;\r
+HANDLE heap;\r
\r
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
{\r
UNREFERENCED_PARAMETER(hInstance);\r
- UNREFERENCED_PARAMETER(dwReason);\r
UNREFERENCED_PARAMETER(lpReserved);\r
\r
switch (dwReason) {\r
case DLL_PROCESS_ATTACH:\r
+ heap = HeapCreate(0, 0, 0);\r
+ if (heap == NULL) {\r
+ return FALSE;\r
+ }\r
InitializeCriticalSection(&lock);\r
break;\r
case DLL_PROCESS_DETACH:\r
DeleteCriticalSection(&lock);\r
+ HeapDestroy(heap);\r
break;\r
default:\r
break;\r
#define IB_VERBS_H\r
\r
extern COMP_MANAGER comp_mgr;\r
+extern HANDLE heap;\r
\r
__inline void* __cdecl operator new(size_t size)\r
{\r
- return HeapAlloc(GetProcessHeap(), 0, size);\r
+ return HeapAlloc(heap, 0, size);\r
}\r
\r
__inline void __cdecl operator delete(void *pObj)\r
{\r
- HeapFree(GetProcessHeap(), 0, pObj);\r
+ HeapFree(heap, 0, pObj);\r
}\r
\r
#endif /* IB_VERBS_H */\r
#define CMA_H\r
\r
extern CRITICAL_SECTION lock;\r
+extern HANDLE heap;\r
\r
__inline void* __cdecl operator new(size_t size)\r
{\r
- return HeapAlloc(GetProcessHeap(), 0, size);\r
+ return HeapAlloc(heap, 0, size);\r
}\r
\r
__inline void __cdecl operator delete(void *pObj)\r
{\r
- HeapFree(GetProcessHeap(), 0, pObj);\r
+ HeapFree(heap, 0, pObj);\r
}\r
\r
#endif /* CMA_H */\r
#include "cma.h"\r
\r
CRITICAL_SECTION lock;\r
+HANDLE heap;\r
\r
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
{\r
UNREFERENCED_PARAMETER(hInstance);\r
- UNREFERENCED_PARAMETER(dwReason);\r
UNREFERENCED_PARAMETER(lpReserved);\r
\r
switch (dwReason) {\r
case DLL_PROCESS_ATTACH:\r
+ heap = HeapCreate(0, 0, 0);\r
+ if (heap == NULL) {\r
+ return FALSE;\r
+ }\r
InitializeCriticalSection(&lock);\r
break;\r
case DLL_PROCESS_DETACH:\r
DeleteCriticalSection(&lock);\r
+ HeapDestroy(heap);\r
break;\r
default:\r
break;\r