implemented GetConsoleProcessList()
Modified: trunk/reactos/include/csrss/csrss.h
Modified: trunk/reactos/lib/kernel32/misc/console.c
Modified: trunk/reactos/lib/ntdll/csr/lpc.c
Modified: trunk/reactos/subsys/csrss/include/conio.h
Modified: trunk/reactos/subsys/csrss/win32csr/conio.c
Modified: trunk/reactos/subsys/csrss/win32csr/dllmain.c

Modified: trunk/reactos/include/csrss/csrss.h
--- trunk/reactos/include/csrss/csrss.h	2005-02-05 00:20:14 UTC (rev 13413)
+++ trunk/reactos/include/csrss/csrss.h	2005-02-05 01:44:05 UTC (rev 13414)
@@ -11,11 +11,11 @@
 
 typedef struct
 {
-} CSRSS_CONNECT_PROCESS_REQUEST, PCSRSS_CONNECT_PROCESS_REQUEST;
+} CSRSS_CONNECT_PROCESS_REQUEST, *PCSRSS_CONNECT_PROCESS_REQUEST;
 
 typedef struct
 {
-} CSRSS_CONNECT_PROCESS_REPLY, PCSRSS_CONNECT_PROCESS_REPLY;
+} CSRSS_CONNECT_PROCESS_REPLY, *PCSRSS_CONNECT_PROCESS_REPLY;
 
 typedef struct
 {
@@ -33,14 +33,26 @@
 
 typedef struct
 {
-} CSRSS_TERMINATE_PROCESS_REQUEST, PCSRSS_TERMINATE_PROCESS_REQUEST;
+} CSRSS_TERMINATE_PROCESS_REQUEST, *PCSRSS_TERMINATE_PROCESS_REQUEST;
 
 typedef struct
 {
-} CSRSS_TERMINATE_PROCESS_REPLY, PCSRSS_TERMINATE_PROCESS_REPLY;
+} CSRSS_TERMINATE_PROCESS_REPLY, *PCSRSS_TERMINATE_PROCESS_REPLY;
 
 typedef struct
 {
+  ULONG nMaxIds;
+} CSRSS_GET_PROCESS_LIST_REQUEST, *PCSRSS_GET_PROCESS_LIST_REQUEST;
+
+typedef struct
+{
+   ULONG nProcessIdsCopied;
+   ULONG nProcessIdsTotal;
+   HANDLE ProcessId[1];
+} CSRSS_GET_PROCESS_LIST_REPLY, *PCSRSS_GET_PROCESS_LIST_REPLY;
+
+typedef struct
+{
    HANDLE ConsoleHandle;
    BOOL Unicode;
    ULONG NrCharactersToWrite;
@@ -250,12 +262,12 @@
 typedef struct
 {
 	HANDLE	UniqueThread;
-} CSRSS_IDENTIFY_ALERTABLE_THREAD_REQUEST, * PCSRSS_IDENTIFY_ALERTABLE_THREAD_REQUEST;
+} CSRSS_IDENTIFY_ALERTABLE_THREAD_REQUEST, *PCSRSS_IDENTIFY_ALERTABLE_THREAD_REQUEST;
 
 typedef struct
 {
 	CLIENT_ID	Cid;
-} CSRSS_IDENTIFY_ALERTABLE_THREAD_REPLY, * PCSRSS_IDENTIFY_ALERTABLE_THREAD_REPLY;
+} CSRSS_IDENTIFY_ALERTABLE_THREAD_REPLY, *PCSRSS_IDENTIFY_ALERTABLE_THREAD_REPLY;
 
 typedef struct
 {
@@ -687,6 +699,7 @@
 #define CSRSS_GET_CONSOLE_OUTPUT_CP         (0x33)
 #define CSRSS_SET_CONSOLE_OUTPUT_CP         (0x34)
 #define CSRSS_GET_INPUT_WAIT_HANDLE	    (0x35)
+#define CSRSS_GET_PROCESS_LIST              (0x36)
 
 /* Keep in sync with definition below. */
 #define CSRSS_REQUEST_HEADER_SIZE (LPC_MESSAGE_BASE_SIZE + sizeof(ULONG))
@@ -752,6 +765,7 @@
         CSRSS_GET_CONSOLE_OUTPUT_CP_REQUEST GetConsoleOutputCodePage;
         CSRSS_SET_CONSOLE_OUTPUT_CP_REQUEST SetConsoleOutputCodePage;
 	CSRSS_GET_INPUT_WAIT_HANDLE_REQUEST GetConsoleInputWaitHandle;
+	CSRSS_GET_PROCESS_LIST_REQUEST GetProcessListRequest;
       } Data;
     };
   };
@@ -807,6 +821,7 @@
         CSRSS_GET_CONSOLE_OUTPUT_CP_REPLY GetConsoleOutputCodePage;
         CSRSS_SET_CONSOLE_OUTPUT_CP_REPLY SetConsoleOutputCodePage;
 	CSRSS_GET_INPUT_WAIT_HANDLE_REPLY GetConsoleInputWaitHandle;
+	CSRSS_GET_PROCESS_LIST_REPLY GetProcessListReply;
       } Data;
     };
   };

Modified: trunk/reactos/lib/kernel32/misc/console.c
--- trunk/reactos/lib/kernel32/misc/console.c	2005-02-05 00:20:14 UTC (rev 13413)
+++ trunk/reactos/lib/kernel32/misc/console.c	2005-02-05 01:44:05 UTC (rev 13414)
@@ -1569,7 +1569,7 @@
   
   Size = nLength * sizeof(INPUT_RECORD);
 
-  Status = CsrCaptureParameterBuffer((PVOID)lpBuffer, Size, &BufferBase, &BufferTargetBase);
+  Status = CsrCaptureParameterBuffer(NULL, Size, &BufferBase, &BufferTargetBase);
   if(!NT_SUCCESS(Status))
   {
     SetLastErrorByStatus(Status);
@@ -1884,7 +1884,7 @@
   
   Size = dwBufferSize.X * dwBufferSize.Y * sizeof(CHAR_INFO);
 
-  Status = CsrCaptureParameterBuffer((PVOID)lpBuffer, Size, &BufferBase, &BufferTargetBase);
+  Status = CsrCaptureParameterBuffer(NULL, Size, &BufferBase, &BufferTargetBase);
   if(!NT_SUCCESS(Status))
   {
     SetLastErrorByStatus(Status);
@@ -3327,15 +3327,63 @@
 /*--------------------------------------------------------------
  * 	GetConsoleProcessList
  *
- * @unimplemented
+ * @implemented
  */
 DWORD STDCALL
 GetConsoleProcessList(LPDWORD lpdwProcessList,
-                  DWORD dwProcessCount)
+                      DWORD dwProcessCount)
 {
-  DPRINT1("GetConsoleProcessList(0x%x, 0x%x) UNIMPLEMENTED!\n", lpdwProcessList, dwProcessCount);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return 0;
+  CSRSS_API_REQUEST Request;
+  PCSRSS_API_REPLY Reply;
+  ULONG BufferSize, nProcesses;
+  NTSTATUS Status;
+  
+  if(lpdwProcessList == NULL || dwProcessCount == 0)
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return 0;
+  }
+
+  BufferSize = sizeof(CSRSS_API_REQUEST) +
+               (dwProcessCount * sizeof(Reply->Data.GetProcessListReply.ProcessId[0]));
+
+  Reply = RtlAllocateHeap(GetProcessHeap(), 0, BufferSize);
+  if(Reply == NULL)
+  {
+    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+    return 0;
+  }
+
+  Reply->Status = STATUS_SUCCESS;
+  
+  Request.Type = CSRSS_GET_PROCESS_LIST;
+  Request.Data.GetProcessListRequest.nMaxIds = dwProcessCount;
+  
+  Status = CsrClientCallServer(&Request, Reply, sizeof(CSRSS_API_REQUEST),
+                               BufferSize);
+  if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply->Status))
+  {
+    SetLastErrorByStatus (Status);
+    nProcesses = 0;
+  }
+  else
+  {
+    if(dwProcessCount >= Reply->Data.GetProcessListReply.nProcessIdsTotal)
+    {
+      nProcesses = Reply->Data.GetProcessListReply.nProcessIdsCopied;
+      for(nProcesses = 0; nProcesses < Reply->Data.GetProcessListReply.nProcessIdsCopied; nProcesses++)
+      {
+        *(lpdwProcessList++) = (DWORD)Reply->Data.GetProcessListReply.ProcessId[nProcesses];
+      }
+    }
+    else
+    {
+      nProcesses = Reply->Data.GetProcessListReply.nProcessIdsTotal;
+    }
+  }
+  
+  RtlFreeHeap(GetProcessHeap(), 0, Reply);
+  return nProcesses;
 }
 
 

Modified: trunk/reactos/lib/ntdll/csr/lpc.c
--- trunk/reactos/lib/ntdll/csr/lpc.c	2005-02-05 00:20:14 UTC (rev 13413)
+++ trunk/reactos/lib/ntdll/csr/lpc.c	2005-02-05 01:44:05 UTC (rev 13414)
@@ -71,7 +71,10 @@
     {
       return(STATUS_NO_MEMORY);
     }
-  memcpy(Block, ParameterBuffer, ParameterBufferSize);
+  if(ParameterBuffer != NULL)
+  {
+    memcpy(Block, ParameterBuffer, ParameterBufferSize);
+  }
   *ClientAddress = Block;
   *ServerAddress = Block - CsrSectionMapBase + CsrSectionMapServerBase;
   return(STATUS_SUCCESS);

Modified: trunk/reactos/subsys/csrss/include/conio.h
--- trunk/reactos/subsys/csrss/include/conio.h	2005-02-05 00:20:14 UTC (rev 13413)
+++ trunk/reactos/subsys/csrss/include/conio.h	2005-02-05 01:44:05 UTC (rev 13414)
@@ -139,6 +139,7 @@
 CSR_API(CsrSetConsoleCodePage);
 CSR_API(CsrGetConsoleOutputCodePage);
 CSR_API(CsrSetConsoleOutputCodePage);
+CSR_API(CsrGetProcessList);
 
 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))

Modified: trunk/reactos/subsys/csrss/win32csr/conio.c
--- trunk/reactos/subsys/csrss/win32csr/conio.c	2005-02-05 00:20:14 UTC (rev 13413)
+++ trunk/reactos/subsys/csrss/win32csr/conio.c	2005-02-05 01:44:05 UTC (rev 13414)
@@ -3163,4 +3163,51 @@
   return Reply->Status = STATUS_UNSUCCESSFUL;
 }
 
+CSR_API(CsrGetProcessList)
+{
+  PHANDLE Buffer;
+  PCSRSS_CONSOLE Console;
+  PCSRSS_PROCESS_DATA current;
+  PLIST_ENTRY current_entry;
+  ULONG nItems, nCopied;
+  NTSTATUS Status;
+
+  DPRINT("CsrGetProcessList\n");
+  
+  Buffer = Reply->Data.GetProcessListReply.ProcessId;
+  Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
+  Reply->Header.DataSize = Reply->Header.MessageSize - LPC_MESSAGE_BASE_SIZE;
+  
+  nItems = nCopied = 0;
+  Reply->Data.GetProcessListReply.nProcessIdsCopied = 0;
+  Reply->Data.GetProcessListReply.nProcessIdsTotal = 0;
+  
+  Status = ConioConsoleFromProcessData(ProcessData, &Console);
+  if (! NT_SUCCESS(Status))
+  {
+    return Reply->Status = Status;
+  }
+
+  DPRINT1("Console_Api Ctrl-C\n");
+
+  for(current_entry = Console->ProcessList.Flink;
+      current_entry != &Console->ProcessList;
+      current_entry = current_entry->Flink)
+  {
+    current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry);
+    if(nItems++ < Request->Data.GetProcessListRequest.nMaxIds)
+    {
+      *(Buffer++) = current->ProcessId;
+      nCopied++;
+    }
+  }
+
+  ConioUnlockConsole(Console);
+  
+  Reply->Data.GetProcessListReply.nProcessIdsCopied = nCopied;
+  Reply->Data.GetProcessListReply.nProcessIdsTotal = nItems;
+  
+  return Reply->Status = STATUS_SUCCESS;
+}
+
 /* EOF */

Modified: trunk/reactos/subsys/csrss/win32csr/dllmain.c
--- trunk/reactos/subsys/csrss/win32csr/dllmain.c	2005-02-05 00:20:14 UTC (rev 13413)
+++ trunk/reactos/subsys/csrss/win32csr/dllmain.c	2005-02-05 01:44:05 UTC (rev 13414)
@@ -71,6 +71,7 @@
     CSRSS_DEFINE_API(CSRSS_SET_CONSOLE_CP,               CsrSetConsoleCodePage),
     CSRSS_DEFINE_API(CSRSS_GET_CONSOLE_OUTPUT_CP,        CsrGetConsoleOutputCodePage),
     CSRSS_DEFINE_API(CSRSS_SET_CONSOLE_OUTPUT_CP,        CsrSetConsoleOutputCodePage),
+    CSRSS_DEFINE_API(CSRSS_GET_PROCESS_LIST,             CsrGetProcessList),
     { 0, 0, 0, NULL }
   };