Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

csrstubs.c

Go to the documentation of this file.
00001 /***************************** Module Header ******************************\ 00002 * Module Name: csrstubs.c 00003 * 00004 * Copyright (c) 1985 - 1999, Microsoft Corporation 00005 * 00006 * Routines to call CSR 00007 * 00008 * 02-27-95 JimA Created. 00009 * 00010 * Note: This file has been partitioned with #if defines so that the LPC 00011 * marsheling code can be inside 64bit code when running under wow64(32bit on 64bit NT). 00012 * In wow64, the system DLLs for 32bit processes are 32bit. 00013 * 00014 * The marsheling code can only be depedent on functions NTDLL. 00015 \**************************************************************************/ 00016 00017 #include "precomp.h" 00018 #pragma hdrstop 00019 00020 #include "csrmsg.h" 00021 #include "dbt.h" 00022 #include "csrhlpr.h" 00023 00024 #if defined(BUILD_CSRWOW64) 00025 00026 #undef RIPERR0 00027 #undef RIPNTERR0 00028 #undef RIPMSG0 00029 00030 #define RIPNTERR0(status, flags, szFmt) {if (NtCurrentTeb()) NtCurrentTeb()->LastErrorValue = RtlNtStatusToDosError(status);} 00031 #define RIPERR0(idErr, flags, szFmt) {if (NtCurrentTeb()) NtCurrentTeb()->LastErrorValue = (idErr);} 00032 #define RIPMSG0(flags, szFmt) 00033 00034 #endif 00035 00036 #define SET_LAST_ERROR_RETURNED() if (a->dwLastError) RIPERR0(a->dwLastError, RIP_VERBOSE, "") 00037 00038 #if !defined(BUILD_WOW6432) 00039 00040 NTSTATUS 00041 APIENTRY 00042 CallUserpExitWindowsEx( 00043 IN UINT uFlags, 00044 IN DWORD dwReserved, 00045 OUT PBOOL pfSuccess) 00046 { 00047 00048 USER_API_MSG m; 00049 PEXITWINDOWSEXMSG a = &m.u.ExitWindowsEx; 00050 00051 a->uFlags = uFlags; 00052 a->dwReserved = dwReserved; 00053 CsrClientCallServer( (PCSR_API_MSG)&m, 00054 NULL, 00055 CSR_MAKE_API_NUMBER( USERSRV_SERVERDLL_INDEX, 00056 UserpExitWindowsEx 00057 ), 00058 sizeof( *a ) 00059 ); 00060 00061 if (NT_SUCCESS( m.ReturnValue ) || m.ReturnValue == STATUS_CANT_WAIT) { 00062 SET_LAST_ERROR_RETURNED(); 00063 *pfSuccess = a->fSuccess; 00064 } else { 00065 RIPNTERR0(m.ReturnValue, RIP_VERBOSE, ""); 00066 *pfSuccess = FALSE; 00067 } 00068 00069 return m.ReturnValue; 00070 00071 } 00072 00073 #endif 00074 00075 #if !defined(BUILD_CSRWOW64) 00076 00077 typedef struct _EXITWINDOWSDATA { 00078 UINT uFlags; 00079 DWORD dwReserved; 00080 } EXITWINDOWSDATA, *PEXITWINDOWSDATA; 00081 00082 DWORD ExitWindowsThread(PVOID pvParam); 00083 00084 BOOL WINAPI ExitWindowsWorker( 00085 UINT uFlags, 00086 DWORD dwReserved, 00087 BOOL fSecondThread) 00088 { 00089 EXITWINDOWSDATA ewd; 00090 HANDLE hThread; 00091 DWORD dwThreadId; 00092 DWORD dwExitCode; 00093 DWORD idWait; 00094 MSG msg; 00095 BOOL fSuccess; 00096 NTSTATUS Status; 00097 00098 /* 00099 * Force a connection so apps will have a windowstation 00100 * to log off of. 00101 */ 00102 if (PtiCurrent() == NULL) 00103 return FALSE; 00104 00105 /* 00106 * Check for UI restrictions 00107 */ 00108 00109 if (!NtUserCallOneParam((ULONG_PTR)uFlags, SFI_PREPAREFORLOGOFF)) { 00110 RIPMSG0(RIP_WARNING, "ExitWindows called by a restricted thread\n"); 00111 return FALSE; 00112 } 00113 00114 Status = CallUserpExitWindowsEx(uFlags, dwReserved, &fSuccess); 00115 00116 if (NT_SUCCESS( Status )) { 00117 return fSuccess; 00118 } else if (Status == STATUS_CANT_WAIT && !fSecondThread) { 00119 ewd.uFlags = uFlags; 00120 ewd.dwReserved = dwReserved; 00121 hThread = CreateThread(NULL, 0, ExitWindowsThread, &ewd, 00122 0, &dwThreadId); 00123 if (hThread == NULL) { 00124 return FALSE; 00125 } 00126 while (1) { 00127 idWait = MsgWaitForMultipleObjectsEx(1, &hThread, 00128 INFINITE, QS_ALLINPUT, 0); 00129 00130 /* 00131 * If the thread was signaled, we're done. 00132 */ 00133 if (idWait == WAIT_OBJECT_0) 00134 break; 00135 00136 /* 00137 * Process any waiting messages 00138 */ 00139 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 00140 DispatchMessage(&msg); 00141 } 00142 GetExitCodeThread(hThread, &dwExitCode); 00143 NtClose(hThread); 00144 if (dwExitCode == ERROR_SUCCESS) 00145 return TRUE; 00146 else { 00147 RIPERR0(dwExitCode, RIP_VERBOSE, ""); 00148 return FALSE; 00149 } 00150 } else { 00151 RIPNTERR0(Status, RIP_VERBOSE, ""); 00152 return FALSE; 00153 } 00154 } 00155 00156 DWORD ExitWindowsThread( 00157 PVOID pvParam) 00158 { 00159 PEXITWINDOWSDATA pewd = pvParam; 00160 DWORD dwExitCode; 00161 00162 if (ExitWindowsWorker(pewd->uFlags, pewd->dwReserved, TRUE)) 00163 dwExitCode = 0; 00164 else 00165 dwExitCode = GetLastError(); 00166 ExitThread(dwExitCode); 00167 return 0; 00168 } 00169 00170 BOOL WINAPI ExitWindowsEx( 00171 UINT uFlags, 00172 DWORD dwReserved) 00173 { 00174 return ExitWindowsWorker(uFlags, dwReserved, FALSE); 00175 } 00176 00177 #endif 00178 00179 #if !defined(BUILD_WOW6432) 00180 00181 BOOL WINAPI EndTask( 00182 HWND hwnd, 00183 BOOL fShutdown, 00184 BOOL fForce) 00185 { 00186 USER_API_MSG m; 00187 PENDTASKMSG a = &m.u.EndTask; 00188 00189 a->hwnd = hwnd; 00190 a->fShutdown = fShutdown; 00191 a->fForce = fForce; 00192 CsrClientCallServer( (PCSR_API_MSG)&m, 00193 NULL, 00194 CSR_MAKE_API_NUMBER( USERSRV_SERVERDLL_INDEX, 00195 UserpEndTask 00196 ), 00197 sizeof( *a ) 00198 ); 00199 if (NT_SUCCESS( m.ReturnValue )) { 00200 SET_LAST_ERROR_RETURNED(); 00201 return a->fSuccess; 00202 } else { 00203 RIPNTERR0(m.ReturnValue, RIP_VERBOSE, ""); 00204 return FALSE; 00205 } 00206 } 00207 00208 VOID 00209 APIENTRY 00210 Logon( 00211 BOOL fLogon) 00212 { 00213 USER_API_MSG m; 00214 PLOGONMSG a = &m.u.Logon; 00215 00216 a->fLogon = fLogon; 00217 CsrClientCallServer( (PCSR_API_MSG)&m, 00218 NULL, 00219 CSR_MAKE_API_NUMBER( USERSRV_SERVERDLL_INDEX, 00220 UserpLogon 00221 ), 00222 sizeof(*a) 00223 ); 00224 } 00225 00226 NTSTATUS 00227 APIENTRY 00228 CallUserpRegisterLogonProcess( 00229 IN DWORD dwProcessId) 00230 { 00231 00232 USER_API_MSG m; 00233 PLOGONMSG a = &m.u.Logon; 00234 NTSTATUS Status; 00235 00236 m.u.IdLogon = dwProcessId; 00237 Status = CsrClientCallServer( (PCSR_API_MSG)&m, 00238 NULL, 00239 CSR_MAKE_API_NUMBER( USERSRV_SERVERDLL_INDEX, 00240 UserpRegisterLogonProcess), 00241 sizeof(*a)); 00242 00243 return Status; 00244 } 00245 00246 #endif 00247 00248 #if !defined(BUILD_CSRWOW64) 00249 00250 extern BOOL gfLogonProcess; 00251 00252 BOOL RegisterLogonProcess( 00253 DWORD dwProcessId, 00254 BOOL fSecure) 00255 { 00256 gfLogonProcess = (BOOL)NtUserCallTwoParam(dwProcessId, fSecure, 00257 SFI__REGISTERLOGONPROCESS); 00258 00259 /* 00260 * Now, register the logon process into winsrv. 00261 */ 00262 if (gfLogonProcess) { 00263 CallUserpRegisterLogonProcess(dwProcessId); 00264 } 00265 00266 return gfLogonProcess; 00267 } 00268 00269 #endif 00270 00271 #if !defined(BUILD_WOW6432) 00272 00273 BOOL 00274 WINAPI 00275 RegisterServicesProcess( 00276 DWORD dwProcessId) 00277 { 00278 USER_API_MSG m; 00279 PREGISTERSERVICESPROCESSMSG a = &m.u.RegisterServicesProcess; 00280 00281 a->dwProcessId = dwProcessId; 00282 CsrClientCallServer( (PCSR_API_MSG)&m, 00283 NULL, 00284 CSR_MAKE_API_NUMBER( USERSRV_SERVERDLL_INDEX, 00285 UserpRegisterServicesProcess 00286 ), 00287 sizeof( *a ) 00288 ); 00289 if (NT_SUCCESS( m.ReturnValue )) { 00290 SET_LAST_ERROR_RETURNED(); 00291 return a->fSuccess; 00292 } else { 00293 RIPNTERR0(m.ReturnValue, RIP_VERBOSE, ""); 00294 return FALSE; 00295 } 00296 } 00297 00298 HDESK WINAPI GetThreadDesktop( 00299 DWORD dwThreadId) 00300 { 00301 USER_API_MSG m; 00302 PGETTHREADCONSOLEDESKTOPMSG a = &m.u.GetThreadConsoleDesktop; 00303 00304 a->dwThreadId = dwThreadId; 00305 CsrClientCallServer( (PCSR_API_MSG)&m, 00306 NULL, 00307 CSR_MAKE_API_NUMBER( USERSRV_SERVERDLL_INDEX, 00308 UserpGetThreadConsoleDesktop 00309 ), 00310 sizeof( *a ) 00311 ); 00312 if (NT_SUCCESS( m.ReturnValue )) { 00313 return NtUserGetThreadDesktop(dwThreadId, a->hdeskConsole); 00314 } else { 00315 RIPNTERR0(m.ReturnValue, RIP_VERBOSE, ""); 00316 return NULL; 00317 } 00318 } 00319 00320 00321 /**************************************************************************\ 00322 * DeviceEventWorker 00323 * 00324 * This is a private (not publicly exported) interface that the user-mode 00325 * pnp manager calls when it needs to send a WM_DEVICECHANGE message to a 00326 * specific window handle. The user-mode pnp manager is a service within 00327 * services.exe and as such is not on the interactive window station and 00328 * active desktop, so it can't directly call SendMessage. For broadcasted 00329 * messages (messages that go to all top-level windows), the user-mode pnp 00330 * manager calls BroadcastSystemMessage directly. 00331 * 00332 * PaulaT 06/04/97 00333 * 00334 \**************************************************************************/ 00335 00336 ULONG 00337 WINAPI 00338 DeviceEventWorker( 00339 IN HWND hWnd, 00340 IN WPARAM wParam, 00341 IN LPARAM lParam, 00342 IN DWORD dwFlags, 00343 OUT PDWORD pdwResult 00344 ) 00345 { 00346 USER_API_MSG m; 00347 PDEVICEEVENTMSG a = &m.u.DeviceEvent; 00348 PCSR_CAPTURE_HEADER CaptureBuffer = NULL; 00349 int cb = 0; 00350 00351 a->hWnd = hWnd; 00352 a->wParam = wParam; 00353 a->lParam = lParam; 00354 a->dwFlags = dwFlags; 00355 a->dwResult = 0; 00356 00357 // 00358 // If lParam is specified, it must be marshalled (see the defines 00359 // for this structure in dbt.h - the structure always starts with 00360 // DEV_BROADCAST_HDR structure). 00361 // 00362 00363 if (lParam) { 00364 00365 cb = ((PDEV_BROADCAST_HDR)lParam)->dbch_size; 00366 00367 CaptureBuffer = CsrAllocateCaptureBuffer(1, cb); 00368 if (CaptureBuffer == NULL) { 00369 return STATUS_NO_MEMORY; 00370 } 00371 00372 CsrCaptureMessageBuffer(CaptureBuffer, 00373 (PCHAR)lParam, 00374 cb, 00375 (PVOID *)&a->lParam); 00376 00377 // 00378 // This ends up calling SrvDeviceEvent routine in the server. 00379 // 00380 00381 CsrClientCallServer((PCSR_API_MSG)&m, 00382 CaptureBuffer, 00383 CSR_MAKE_API_NUMBER(USERSRV_SERVERDLL_INDEX, 00384 UserpDeviceEvent), 00385 sizeof(*a)); 00386 00387 CsrFreeCaptureBuffer(CaptureBuffer); 00388 00389 } else { 00390 00391 // 00392 // This ends up calling SrvDeviceEvent routine in the server. 00393 // 00394 00395 CsrClientCallServer((PCSR_API_MSG)&m, 00396 NULL, 00397 CSR_MAKE_API_NUMBER(USERSRV_SERVERDLL_INDEX, 00398 UserpDeviceEvent), 00399 sizeof(*a)); 00400 } 00401 00402 00403 if (NT_SUCCESS(m.ReturnValue)) { 00404 *pdwResult = (DWORD)a->dwResult; 00405 } else { 00406 RIPMSG0(RIP_WARNING, "DeviceEventWorker failed."); 00407 } 00408 00409 return m.ReturnValue; 00410 00411 } // DeviceEventWorker 00412 00413 #if DBG 00414 00415 VOID 00416 APIENTRY 00417 CsrWin32HeapFail( 00418 IN DWORD dwFlags, 00419 IN BOOL bFail) 00420 { 00421 USER_API_MSG m; 00422 PWIN32HEAPFAILMSG a = &m.u.Win32HeapFail; 00423 00424 a->dwFlags = dwFlags; 00425 a->bFail = bFail; 00426 00427 CsrClientCallServer((PCSR_API_MSG)&m, 00428 NULL, 00429 CSR_MAKE_API_NUMBER(USERSRV_SERVERDLL_INDEX, 00430 UserpWin32HeapFail), 00431 sizeof(*a)); 00432 00433 if (!NT_SUCCESS(m.ReturnValue)) { 00434 RIPNTERR0(m.ReturnValue, RIP_VERBOSE, "UserpWin32HeapFail failed"); 00435 } 00436 } 00437 00438 UINT 00439 APIENTRY 00440 CsrWin32HeapStat( 00441 PDBGHEAPSTAT phs, 00442 DWORD dwLen) 00443 { 00444 USER_API_MSG m; 00445 PWIN32HEAPSTATMSG a = &m.u.Win32HeapStat; 00446 PCSR_CAPTURE_HEADER CaptureBuffer = NULL; 00447 00448 a->dwLen = dwLen; 00449 00450 CaptureBuffer = CsrAllocateCaptureBuffer(1, dwLen); 00451 if (CaptureBuffer == NULL) { 00452 return 0; 00453 } 00454 00455 CsrCaptureMessageBuffer(CaptureBuffer, 00456 (PCHAR)phs, 00457 dwLen, 00458 (PVOID *)&a->phs); 00459 00460 CsrClientCallServer((PCSR_API_MSG)&m, 00461 CaptureBuffer, 00462 CSR_MAKE_API_NUMBER(USERSRV_SERVERDLL_INDEX, 00463 UserpWin32HeapStat), 00464 sizeof(*a)); 00465 00466 if (!NT_SUCCESS(m.ReturnValue)) { 00467 RIPNTERR0(m.ReturnValue, RIP_VERBOSE, "UserpWin32HeapStat failed"); 00468 a->dwMaxTag = 0; 00469 goto ErrExit; 00470 } 00471 RtlMoveMemory(phs, a->phs, dwLen); 00472 00473 ErrExit: 00474 CsrFreeCaptureBuffer(CaptureBuffer); 00475 00476 return a->dwMaxTag; 00477 } 00478 00479 #endif // DBG 00480 00481 00482 #endif 00483

Generated on Sat May 15 19:39:36 2004 for test by doxygen 1.3.7