ReactOS 0.4.16-dev-338-g34e76ad
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 99 of file wintirpc.c.

102{
103 LPVOID lpvData;
104 BOOL fIgnore;
105
106// if (init++)
107// return TRUE;
108
109 // Deal with Thread Local Storage initialization!!
110 switch (fdwReason)
111 {
112 // The DLL is loading due to process
113 // initialization or a call to LoadLibrary.
115#ifdef __REACTOS__
117 return FALSE;
118
119 lstrcatA(NETCONFIG, "\\drivers\\etc\\netconfig");
120#endif
121
122 // Initialize socket library
123 if (winsock_init() == FALSE)
124 return FALSE;
125
126 // Initialize CriticalSections
128
129 // Allocate a TLS index.
131 return FALSE;
132
133 // No break: Initialize the index for first thread.
134
135 // The attached process creates a new thread.
136 case DLL_THREAD_ATTACH:
137
138 // Initialize the TLS index for this thread
139 lpvData = (LPVOID) LocalAlloc(LPTR, 256);
140 if (lpvData != NULL)
141 fIgnore = TlsSetValue(dwTlsIndex, lpvData);
142
143 break;
144
145 // The thread of the attached process terminates.
146 case DLL_THREAD_DETACH:
147
148 // Release the allocated memory for this thread.
149 lpvData = TlsGetValue(dwTlsIndex);
150 if (lpvData != NULL)
151 LocalFree((HLOCAL) lpvData);
152
153 break;
154
155 // DLL unload due to process termination or FreeLibrary.
156 case DLL_PROCESS_DETACH:
157
158 // Release the allocated memory for this thread.
159 lpvData = TlsGetValue(dwTlsIndex);
160 if (lpvData != NULL)
161 LocalFree((HLOCAL) lpvData);
162
163 // Release the TLS index.
165
166 // Clean up winsock stuff
167 winsock_fini();
168
169 break;
170
171 default:
172 break;
173 }
174
175
176 return TRUE;
177}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1240
DWORD WINAPI TlsAlloc(VOID)
Definition: thread.c:1100
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1276
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1166
unsigned int BOOL
Definition: ntddk_ex.h:94
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
#define NETCONFIG
Definition: netconfig.h:11
#define LPVOID
Definition: nt_native.h:45
#define LPTR
Definition: winbase.h:407
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:575
BOOL winsock_init(void)
Definition: wintirpc.c:77
void tirpc_criticalsection_init(void)
Definition: wintirpc.c:73
BOOL winsock_fini(void)
Definition: wintirpc.c:90
static DWORD dwTlsIndex
Definition: wintirpc.c:34

◆ 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 179 of file wintirpc.c.

180{
181 if (init == 0 || --init > 0)
182 return 0;
183
184 return WSACleanup();
185}
int PASCAL FAR 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}
#define VOID
Definition: acefi.h:82
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
#define TEXT(s)
Definition: k32.h:26
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
#define L(x)
Definition: ntvdm.h:50
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ReportEvent
Definition: winbase.h:3924
#define RegisterEventSource
Definition: winbase.h:3919
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2864
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

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}

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}
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define err(...)
#define MAKEWORD(a, b)
Definition: typedefs.h:248
VOID tirpc_report(LPTSTR lpszMsg)
Definition: wintirpc.c:39

Referenced by DllMain(), and WinHttpOpen().

◆ wintirpc_debug()

void wintirpc_debug ( char fmt,
  ... 
)

Definition at line 188 of file wintirpc.c.

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

Variable Documentation

◆ dwTlsIndex

DWORD dwTlsIndex
static

◆ init

int init ( void  ) = 0
static

Definition at line 33 of file wintirpc.c.

Referenced by WDFCXDEVICE_INIT::_AllocateCxDeviceInit(), _Stl_get_classic_locale(), _Stl_get_global_locale(), basic_fstream< _CharT, _Traits >::basic_fstream(), basic_ifstream< _CharT, _Traits >::basic_ifstream(), basic_iostream< _CharT, _Traits >::basic_iostream(), basic_istream< _CharT, _Traits >::basic_istream(), basic_istringstream< _CharT, _Traits, _Alloc >::basic_istringstream(), basic_ofstream< _CharT, _Traits >::basic_ofstream(), basic_ostream< _CharT, _Traits >::basic_ostream(), basic_ostringstream< _CharT, _Traits, _Alloc >::basic_ostringstream(), basic_stringstream< _CharT, _Traits, _Alloc >::basic_stringstream(), cache_InstallAssembly(), cache_UninstallAssembly(), CFn_WMInitDialog(), check(), create_doc_with_string(), FxChildList::CreateDevice(), DECLARE_INTERFACE_(), doc_load_string(), fill_window(), GetExeFromLnk(), init_key(), init_registry(), init_texthost(), IntCreateDIBitmap(), is_firewall_enabled(), istrstream::istrstream(), load_string(), MAPIInitialize(), MCIWND_Create(), MsiGetShortcutTargetW(), netif_add(), netif_add_noaddr(), ostrstream::ostrstream(), reset_document(), RpcStream_Create(), run_script(), run_test(), runProg(), ServiceMain(), set_firewall(), show_cert_dialog(), SnmpExtensionInit(), START_TEST(), CProgressDialog::StartProgressDialog(), strstream::strstream(), test_InitializePrintMonitor2(), test_menu_iteminfo(), test_StreamInitNew(), test_StreamLoad(), TIFFRegisterCODEC(), tirpc_exit(), WICCreateColorTransform_Proxy(), widGetDevCaps(), WINHELP_InitFonts(), winsock_init(), and XMLStorage::XPath::XPath().

◆ WSAData

Definition at line 31 of file wintirpc.c.