ReactOS  0.4.14-dev-614-gbfd8a84
wintirpc.c File Reference
#include <wintirpc.h>
#include <rpc/rpc.h>
#include <stdio.h>
#include <winsock.h>
Include dependency graph for wintirpc.c:

Go to the source code of this file.

Functions

void multithread_init (void)
 
VOID tirpc_report (LPTSTR lpszMsg)
 
void tirpc_criticalsection_init (void)
 
BOOL winsock_init (void)
 
BOOL winsock_fini (void)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 
int tirpc_exit (void)
 
void wintirpc_debug (char *fmt,...)
 

Variables

WSADATA WSAData
 
static int init = 0
 
static DWORD dwTlsIndex
 

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 96 of file wintirpc.c.

99 {
100  LPVOID lpvData;
101  BOOL fIgnore;
102 
103 // if (init++)
104 // return TRUE;
105 
106  // Deal with Thread Local Storage initialization!!
107  switch (fdwReason)
108  {
109  // The DLL is loading due to process
110  // initialization or a call to LoadLibrary.
111  case DLL_PROCESS_ATTACH:
112 
113  // Initialize socket library
114  if (winsock_init() == FALSE)
115  return FALSE;
116 
117  // Initialize CriticalSections
119 
120  // Allocate a TLS index.
121  if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
122  return FALSE;
123 
124  // No break: Initialize the index for first thread.
125 
126  // The attached process creates a new thread.
127  case DLL_THREAD_ATTACH:
128 
129  // Initialize the TLS index for this thread
130  lpvData = (LPVOID) LocalAlloc(LPTR, 256);
131  if (lpvData != NULL)
132  fIgnore = TlsSetValue(dwTlsIndex, lpvData);
133 
134  break;
135 
136  // The thread of the attached process terminates.
137  case DLL_THREAD_DETACH:
138 
139  // Release the allocated memory for this thread.
140  lpvData = TlsGetValue(dwTlsIndex);
141  if (lpvData != NULL)
142  LocalFree((HLOCAL) lpvData);
143 
144  break;
145 
146  // DLL unload due to process termination or FreeLibrary.
147  case DLL_PROCESS_DETACH:
148 
149  // Release the allocated memory for this thread.
150  lpvData = TlsGetValue(dwTlsIndex);
151  if (lpvData != NULL)
152  LocalFree((HLOCAL) lpvData);
153 
154  // Release the TLS index.
156 
157  // Clean up winsock stuff
158  winsock_fini();
159 
160  break;
161 
162  default:
163  break;
164  }
165 
166 
167  return TRUE;
168 }
#define TRUE
Definition: types.h:120
void tirpc_criticalsection_init(void)
Definition: wintirpc.c:73
BOOL winsock_fini(void)
Definition: wintirpc.c:90
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1264
#define DLL_THREAD_ATTACH
Definition: compat.h:121
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define DLL_THREAD_DETACH
Definition: compat.h:122
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define DLL_PROCESS_DETACH
Definition: compat.h:119
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1154
#define LPVOID
Definition: nt_native.h:45
DWORD WINAPI TlsAlloc(VOID)
Definition: thread.c:1088
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:530
static DWORD dwTlsIndex
Definition: wintirpc.c:34
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1228
#define LPTR
Definition: winbase.h:362
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
BOOL winsock_init(void)
Definition: wintirpc.c:77

◆ multithread_init()

void multithread_init ( void  )

◆ tirpc_criticalsection_init()

void tirpc_criticalsection_init ( void  )

Definition at line 73 of file wintirpc.c.

73  {
75 }
void multithread_init(void)

Referenced by DllMain().

◆ tirpc_exit()

int tirpc_exit ( void  )

Definition at line 170 of file wintirpc.c.

171 {
172  if (init == 0 || --init > 0)
173  return 0;
174 
175  return WSACleanup();
176 }
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
static int init
Definition: wintirpc.c:33

◆ tirpc_report()

VOID tirpc_report ( LPTSTR  lpszMsg)

Definition at line 39 of file wintirpc.c.

40 {
41  WCHAR chMsg[256];
42  HANDLE hEventSource;
43  LPCWSTR lpszStrings[2];
44 
45  // Use event logging to log the error.
46  //
47  hEventSource = RegisterEventSource(NULL,
48  TEXT("tirpc.dll"));
49 
50 #ifndef __REACTOS__
51  swprintf_s(chMsg, sizeof(chMsg), L"tirpc report: %d", GetLastError());
52 #else
53  _snwprintf(chMsg, sizeof(chMsg) / sizeof(WCHAR), L"tirpc report: %d", GetLastError());
54 #endif
55  lpszStrings[0] = (LPCWSTR)chMsg;
56  lpszStrings[1] = lpszMsg;
57 
58  if (hEventSource != NULL) {
59  ReportEvent(hEventSource, // handle of event source
60  EVENTLOG_WARNING_TYPE, // event type
61  0, // event category
62  0, // event ID
63  NULL, // current user's SID
64  2, // strings in lpszStrings
65  0, // no bytes of raw data
66  lpszStrings, // array of error strings
67  NULL); // no raw data
68 
69  (VOID) DeregisterEventSource(hEventSource);
70  }
71 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2631
static const WCHAR L[]
Definition: oid.c:1250
#define VOID
Definition: acefi.h:82
#define ReportEvent
Definition: winbase.h:3733
#define RegisterEventSource
Definition: winbase.h:3728
#define TEXT(s)
Definition: k32.h:26
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473

Referenced by winsock_init().

◆ winsock_fini()

BOOL winsock_fini ( void  )

Definition at line 90 of file wintirpc.c.

91 {
92  WSACleanup();
93  return TRUE;
94 }
#define TRUE
Definition: types.h:120
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60

Referenced by DllMain().

◆ winsock_init()

BOOL winsock_init ( void  )

Definition at line 77 of file wintirpc.c.

78 {
79  int err;
80  err = WSAStartup(MAKEWORD( 3, 3 ), &WSAData); // XXX THIS SHOULD BE FAILING!!!!!!!!!!!!!!!!!
81  if (err != 0) {
82  init = 0;
83  tirpc_report(L"WSAStartup failed!\n");
84  WSACleanup();
85  return FALSE;
86  }
87  return TRUE;
88 }
#define TRUE
Definition: types.h:120
#define MAKEWORD(a, b)
Definition: typedefs.h:247
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
static int init
Definition: wintirpc.c:33
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
static const WCHAR L[]
Definition: oid.c:1250
#define err(...)
VOID tirpc_report(LPTSTR lpszMsg)
Definition: wintirpc.c:39

Referenced by DllMain().

◆ wintirpc_debug()

void wintirpc_debug ( char fmt,
  ... 
)

Definition at line 179 of file wintirpc.c.

180 {
181 #ifdef _DEBUG
182  char buffer[2048];
183 #else
184  static int triedToOpen = 0;
185  static FILE *dbgFile = NULL;
186 #endif
187 
188  va_list vargs;
189  va_start(vargs, fmt);
190 
191 #ifdef _DEBUG
192  vsprintf(buffer, fmt, vargs);
194 #else
195  if (dbgFile == NULL && triedToOpen == 0) {
196  triedToOpen = 1;
197  dbgFile = fopen("c:\\etc\\rpcsec_gss_debug.txt", "w");
198  }
199  if (dbgFile != NULL) {
200  vfprintf(dbgFile, fmt, vargs);
201  fflush(dbgFile);
202  }
203 #endif
204 
205  va_end(vargs);
206 }
GLuint buffer
Definition: glext.h:5915
#define va_end(ap)
Definition: acmsvcex.h:90
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
Definition: dsound.c:943
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18

Variable Documentation

◆ dwTlsIndex

DWORD dwTlsIndex
static

◆ init

◆ WSAData

Definition at line 31 of file wintirpc.c.

Referenced by main().