Leaked source code of windows server 2003
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.

95 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. session.c
  5. Abstract:
  6. This module contains the worker routines called by the Sb API
  7. Request routines in sbapi.c to create and delete sessions. Also
  8. called whenever an application process creates a new child process
  9. within the same session.
  10. Author:
  11. Steve Wood (stevewo) 08-Oct-1990
  12. Revision History:
  13. --*/
  14. #include "csrsrv.h"
  15. NTSTATUS
  16. CsrInitializeNtSessionList( VOID )
  17. {
  18. NTSTATUS Status;
  19. InitializeListHead( &CsrNtSessionList );
  20. Status = RtlInitializeCriticalSection( &CsrNtSessionLock );
  21. return( Status );
  22. }
  23. PCSR_NT_SESSION
  24. CsrAllocateNtSession(
  25. ULONG SessionId
  26. )
  27. {
  28. PCSR_NT_SESSION Session;
  29. Session = RtlAllocateHeap( CsrHeap, MAKE_TAG( SESSION_TAG ), sizeof( CSR_NT_SESSION ) );
  30. ASSERT( Session != NULL );
  31. if (Session != NULL) {
  32. Session->SessionId = SessionId;
  33. Session->ReferenceCount = 1;
  34. LockNtSessionList();
  35. InsertHeadList( &CsrNtSessionList, &Session->SessionLink );
  36. UnlockNtSessionList();
  37. }
  38. return( Session );
  39. }
  40. VOID
  41. CsrReferenceNtSession(
  42. PCSR_NT_SESSION Session
  43. )
  44. {
  45. LockNtSessionList();
  46. ASSERT( !IsListEmpty( &Session->SessionLink ) );
  47. ASSERT( Session->SessionId != 0 );
  48. ASSERT( Session->ReferenceCount != 0 );
  49. Session->ReferenceCount++;
  50. UnlockNtSessionList();
  51. }
  52. VOID
  53. CsrDereferenceNtSession(
  54. PCSR_NT_SESSION Session,
  55. NTSTATUS ExitStatus
  56. )
  57. {
  58. LockNtSessionList();
  59. ASSERT( !IsListEmpty( &Session->SessionLink ) );
  60. ASSERT( Session->SessionId != 0 );
  61. ASSERT( Session->ReferenceCount != 0 );
  62. if (--Session->ReferenceCount == 0) {
  63. RemoveEntryList( &Session->SessionLink );
  64. UnlockNtSessionList();
  65. SmSessionComplete(CsrSmApiPort,Session->SessionId,ExitStatus);
  66. RtlFreeHeap( CsrHeap, 0, Session );
  67. }
  68. else {
  69. UnlockNtSessionList();
  70. }
  71. }