Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ntrqust.c
  5. Abstract:
  6. This module contains the session requests thread.
  7. Author:
  8. Avi Nathan (avin) 17-Jul-1991
  9. Environment:
  10. User Mode Only
  11. Revision History:
  12. Ellen Aycock-Wright (ellena) 15-Sept-1991 Modified for POSIX
  13. --*/
  14. #include <malloc.h>
  15. #define NTPSX_ONLY
  16. #include "psxses.h"
  17. VOID ScHandleConnectionRequest( PSCREQUESTMSG Message );
  18. DWORD
  19. WINAPI
  20. ServeSessionRequests(
  21. LPVOID Parameter
  22. )
  23. {
  24. SCREQUESTMSG ReceiveMsg, *pReplyMsg;
  25. NTSTATUS Status;
  26. BOOL fCont = TRUE;
  27. pReplyMsg = NULL;
  28. InitializeListHead(&ClientPortsList);
  29. for (;;) {
  30. if (fCont) {
  31. Status = NtReplyWaitReceivePort(PsxSessionPort,
  32. NULL, (PPORT_MESSAGE)pReplyMsg,
  33. (PPORT_MESSAGE)&ReceiveMsg);
  34. if (ReceiveMsg.h.u2.s2.Type == LPC_CONNECTION_REQUEST) {
  35. ASSERT(NT_SUCCESS(Status));
  36. ScHandleConnectionRequest( &ReceiveMsg );
  37. pReplyMsg = NULL;
  38. continue;
  39. }
  40. } else {
  41. Status = NtReplyPort(PsxSessionPort,
  42. (PPORT_MESSAGE)pReplyMsg);
  43. }
  44. if (STATUS_INVALID_CID == Status) {
  45. //
  46. // The client on whose behalf we called read has
  47. // been shot.
  48. //
  49. pReplyMsg = NULL;
  50. continue;
  51. }
  52. if (!NT_SUCCESS(Status)) {
  53. KdPrint(("PSXSES: ntreqst: 0x%x\n", Status));
  54. }
  55. ASSERT(NT_SUCCESS(Status));
  56. if (LPC_PORT_CLOSED == PORT_MSG_TYPE(ReceiveMsg)) {
  57. PLIST_ENTRY pl;
  58. PCLIENT_AND_PORT pc;
  59. for (pl = ClientPortsList.Flink;
  60. pl != &ClientPortsList;
  61. pl = pl->Flink) {
  62. pc = (PVOID)pl;
  63. if (pc->ClientId.UniqueProcess == ReceiveMsg.h.ClientId.UniqueProcess &&
  64. pc->ClientId.UniqueThread == ReceiveMsg.h.ClientId.UniqueThread) {
  65. RemoveEntryList(&pc->Links);
  66. NtClose(pc->CommPort);
  67. free(pc);
  68. break;
  69. }
  70. }
  71. pReplyMsg = NULL;
  72. continue;
  73. }
  74. if (PORT_MSG_TYPE(ReceiveMsg) == LPC_CLIENT_DIED) {
  75. pReplyMsg = NULL;
  76. continue;
  77. }
  78. if (!fCont) {
  79. break;
  80. }
  81. if (PORT_MSG_TYPE(ReceiveMsg) != LPC_REQUEST &&
  82. PORT_MSG_TYPE(ReceiveMsg) != LPC_DATAGRAM) {
  83. KdPrint(("PSXSES: got msg type %d\n",
  84. PORT_MSG_TYPE(ReceiveMsg)));
  85. }
  86. try {
  87. switch (ReceiveMsg.Request) {
  88. case ConRequest:
  89. fCont = ServeConRequest(&ReceiveMsg.d.Con,
  90. &ReceiveMsg.Status);
  91. break;
  92. case TaskManRequest:
  93. fCont = ServeTmRequest(&ReceiveMsg.d.Tm,
  94. &ReceiveMsg.Status);
  95. break;
  96. case TcRequest:
  97. fCont = ServeTcRequest(&ReceiveMsg.d.Tc,
  98. &ReceiveMsg.Status);
  99. break;
  100. default:
  101. KdPrint(("PSXSES: Unknown nt request: 0x%x\n",
  102. ReceiveMsg.Request));
  103. }
  104. } except (EXCEPTION_EXECUTE_HANDLER) {
  105. // BUGBUG! GetExceptionCode;
  106. ReceiveMsg.Status = STATUS_ACCESS_VIOLATION;
  107. // BUGBUG! The client should kill the process
  108. }
  109. pReplyMsg = &ReceiveMsg;
  110. }
  111. ExitProcess(0);
  112. //NOTREACHED
  113. return 0;
  114. }