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.

151 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. apiinit.c
  5. Abstract:
  6. This module contains the code to initialize the ApiPort of the POSIX
  7. Emulation Subsystem.
  8. Author:
  9. Steve Wood (stevewo) 22-Aug-1989
  10. Environment:
  11. User Mode Only
  12. Revision History:
  13. Ellen Aycock-Wright (ellena) 15-Jul-91 Modified for POSIX
  14. --*/
  15. #include "psxsrv.h"
  16. #include "sesport.h"
  17. #include <ntcsrdll.h>
  18. #include <windef.h>
  19. #include <winbase.h>
  20. NTSTATUS
  21. PsxApiPortInitialize( VOID )
  22. {
  23. NTSTATUS Status;
  24. OBJECT_ATTRIBUTES ObjectAttributes;
  25. ULONG i;
  26. CHAR buf[SECURITY_DESCRIPTOR_MIN_LENGTH];
  27. PSECURITY_DESCRIPTOR securityDescriptor;
  28. PSX_GET_SESSION_OBJECT_NAME(&PsxApiPortName, PSX_SS_API_PORT_NAME);
  29. securityDescriptor = (PSECURITY_DESCRIPTOR)buf;
  30. Status = RtlCreateSecurityDescriptor(securityDescriptor,
  31. SECURITY_DESCRIPTOR_REVISION);
  32. ASSERT(NT_SUCCESS(Status));
  33. Status = RtlSetDaclSecurityDescriptor(securityDescriptor, TRUE,
  34. NULL, FALSE);
  35. InitializeObjectAttributes(&ObjectAttributes, &PsxApiPortName, 0,
  36. NULL, securityDescriptor);
  37. IF_PSX_DEBUG(INIT) {
  38. KdPrint(("PSXSS: Creating %wZ port and associated threads\n",
  39. &PsxApiPortName));
  40. }
  41. Status = NtCreatePort(&PsxApiPort, &ObjectAttributes,
  42. sizeof(PSX_API_CONNECTINFO), sizeof(PSX_API_MSG),
  43. 4096 * 16);
  44. ASSERT(NT_SUCCESS(Status));
  45. if (!NT_SUCCESS(Status)) {
  46. NtTerminateProcess(NtCurrentProcess(), 1);
  47. }
  48. for (i = 0; i < PsxNumberApiRequestThreads; i++) {
  49. PsxServerThreadHandles[i + PSX_SS_FIRST_API_REQUEST_THREAD] =
  50. CreateThread(NULL, (DWORD)0,
  51. (LPTHREAD_START_ROUTINE)PsxApiRequestThread,
  52. NULL, CREATE_SUSPENDED,
  53. (LPDWORD)&PsxServerThreadClientIds[i +
  54. PSX_SS_FIRST_API_REQUEST_THREAD]);
  55. if (NULL == PsxServerThreadHandles[i +
  56. PSX_SS_FIRST_API_REQUEST_THREAD]) {
  57. NtTerminateProcess(NtCurrentProcess(), 1);
  58. }
  59. }
  60. for (i = 0; i < PsxNumberApiRequestThreads; i++) {
  61. Status = ResumeThread(PsxServerThreadHandles[i +
  62. PSX_SS_FIRST_API_REQUEST_THREAD]);
  63. if (-1 == Status) {
  64. NtTerminateProcess(NtCurrentProcess(), 1);
  65. }
  66. }
  67. //
  68. // Create the Alarm-handling thread here, 'cuz there's no better
  69. // place. See timer.c for AlarmThreadRoutine.
  70. //
  71. {
  72. ULONG ThreadId;
  73. AlarmThreadHandle = CreateThread(NULL, (DWORD)0,
  74. (LPTHREAD_START_ROUTINE)AlarmThreadRoutine, NULL,
  75. CREATE_SUSPENDED, &ThreadId);
  76. if (NULL == AlarmThreadHandle) {
  77. NtTerminateProcess(NtCurrentProcess(), 1);
  78. return STATUS_INSUFFICIENT_RESOURCES;
  79. }
  80. Status = ResumeThread(AlarmThreadHandle);
  81. }
  82. return Status;
  83. }
  84. #if 0
  85. //
  86. // This thread is here solely to allow NTSD -p to attach to the Posix subsystem
  87. // process to debug it. It is required because all of the other thread in the
  88. // Posix subsystem server are waiting non-alertable in an LPC system servive.
  89. //
  90. NTSTATUS
  91. PsxDebugAttachThread (
  92. IN PVOID Parameter
  93. )
  94. {
  95. LARGE_INTEGER TimeOut;
  96. NTSTATUS Status;
  97. // CsrIdentifyAlertableThread(); // So the debugger can interrupt us
  98. while (TRUE) {
  99. //
  100. // Delay alertable for the longest possible integer relative to now.
  101. //
  102. TimeOut.LowPart = 0x0;
  103. TimeOut.HighPart = 0x80000000;
  104. Status = NtDelayExecution( TRUE, &TimeOut );
  105. //
  106. // Do this forever, so the debugger can attach whenever it wants.
  107. //
  108. }
  109. return 0;
  110. }
  111. #endif