Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencsr.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * PURPOSE: Interface to csrss 00005 * FILE: subsys/win32k/ntuser/csr.c 00006 * PROGRAMER: Ge van Geldorp (ge@gse.nl) 00007 */ 00008 00009 #include <win32k.h> 00010 00011 static HANDLE WindowsApiPort = NULL; 00012 PEPROCESS CsrProcess = NULL; 00013 00014 NTSTATUS FASTCALL 00015 CsrInit(void) 00016 { 00017 NTSTATUS Status; 00018 UNICODE_STRING PortName; 00019 ULONG ConnectInfoLength; 00020 SECURITY_QUALITY_OF_SERVICE Qos; 00021 00022 RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort"); 00023 ConnectInfoLength = 0; 00024 Qos.Length = sizeof(Qos); 00025 Qos.ImpersonationLevel = SecurityDelegation; 00026 Qos.ContextTrackingMode = SECURITY_STATIC_TRACKING; 00027 Qos.EffectiveOnly = FALSE; 00028 00029 Status = ZwConnectPort(&WindowsApiPort, 00030 &PortName, 00031 &Qos, 00032 NULL, 00033 NULL, 00034 NULL, 00035 NULL, 00036 &ConnectInfoLength); 00037 if (! NT_SUCCESS(Status)) 00038 { 00039 return Status; 00040 } 00041 00042 CsrProcess = PsGetCurrentProcess(); 00043 00044 return STATUS_SUCCESS; 00045 } 00046 00047 00048 NTSTATUS FASTCALL 00049 co_CsrNotify(PCSR_API_MESSAGE Request) 00050 { 00051 NTSTATUS Status; 00052 PEPROCESS OldProcess; 00053 00054 if (NULL == CsrProcess) 00055 { 00056 return STATUS_INVALID_PORT_HANDLE; 00057 } 00058 00059 Request->Header.u2.ZeroInit = 0; 00060 Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); 00061 Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); 00062 00063 /* Switch to the process in which the WindowsApiPort handle is valid */ 00064 OldProcess = PsGetCurrentProcess(); 00065 if (CsrProcess != OldProcess) 00066 { 00067 KeAttachProcess(&CsrProcess->Pcb); 00068 } 00069 00070 UserLeaveCo(); 00071 00072 Status = ZwRequestWaitReplyPort(WindowsApiPort, 00073 &Request->Header, 00074 &Request->Header); 00075 00076 UserEnterCo(); 00077 00078 if (CsrProcess != OldProcess) 00079 { 00080 KeDetachProcess(); 00081 } 00082 00083 if (NT_SUCCESS(Status)) 00084 { 00085 Status = Request->Status; 00086 } 00087 00088 return Status; 00089 } 00090 00091 00092 NTSTATUS 00093 APIENTRY 00094 CsrInsertObject(HANDLE ObjectHandle, 00095 ACCESS_MASK DesiredAccess, 00096 PHANDLE Handle) 00097 { 00098 NTSTATUS Status; 00099 HANDLE CsrProcessHandle; 00100 OBJECT_ATTRIBUTES ObjectAttributes; 00101 CLIENT_ID Cid; 00102 00103 /* Put CSR'S CID */ 00104 Cid.UniqueProcess = CsrProcess->UniqueProcessId; 00105 Cid.UniqueThread = 0; 00106 00107 /* Empty Attributes */ 00108 InitializeObjectAttributes(&ObjectAttributes, 00109 NULL, 00110 0, 00111 NULL, 00112 NULL); 00113 00114 /* Get a Handle to Csrss */ 00115 Status = ZwOpenProcess(&CsrProcessHandle, 00116 PROCESS_DUP_HANDLE, 00117 &ObjectAttributes, 00118 &Cid); 00119 00120 if ((NT_SUCCESS(Status))) 00121 { 00122 /* Duplicate the Handle */ 00123 Status = ZwDuplicateObject(NtCurrentProcess(), 00124 ObjectHandle, 00125 CsrProcessHandle, 00126 Handle, 00127 DesiredAccess, 00128 OBJ_INHERIT, 00129 0); 00130 00131 /* Close our handle to CSRSS */ 00132 ZwClose(CsrProcessHandle); 00133 } 00134 00135 return Status; 00136 } 00137 00138 NTSTATUS FASTCALL 00139 CsrCloseHandle(HANDLE Handle) 00140 { 00141 NTSTATUS Status; 00142 PEPROCESS OldProcess; 00143 00144 /* Switch to the process in which the handle is valid */ 00145 OldProcess = PsGetCurrentProcess(); 00146 if (CsrProcess != OldProcess) 00147 { 00148 KeAttachProcess(&CsrProcess->Pcb); 00149 } 00150 00151 Status = ZwClose(Handle); 00152 00153 if (CsrProcess != OldProcess) 00154 { 00155 KeDetachProcess(); 00156 } 00157 00158 return Status; 00159 } 00160 00161 /* EOF */ Generated on Sun May 27 2012 04:38:30 for ReactOS by
1.7.6.1
|