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.

137 lines
3.3 KiB

  1. // IOPLock.cpp: implementation of the CIOPLock class.
  2. //
  3. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  4. // 2000. This computer program includes Confidential, Proprietary
  5. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  6. // use, disclosure, and/or reproduction is prohibited unless authorized
  7. // in writing. All Rights Reserved.
  8. //////////////////////////////////////////////////////////////////////
  9. #include "NoWarning.h"
  10. #include <scuOsExc.h>
  11. #include <scuOsVersion.h>
  12. #include "IOPLock.h"
  13. #include "iopExc.h"
  14. #include "iop.h"
  15. #include "SmartCard.h"
  16. using namespace std;
  17. using namespace iop;
  18. RMHangProcDeathSynchObjects::RMHangProcDeathSynchObjects(SECURITY_ATTRIBUTES *psa,
  19. LPCTSTR lpMutexName)
  20. : m_hMutex(INVALID_HANDLE_VALUE)
  21. {
  22. InitializeCriticalSection(&m_cs);
  23. // Set up Mutex
  24. m_hMutex = CreateMutex(psa, FALSE, lpMutexName);
  25. if (!m_hMutex)
  26. {
  27. DWORD dwLastError = GetLastError();
  28. DeleteCriticalSection(&m_cs);
  29. throw scu::OsException(dwLastError);
  30. }
  31. }
  32. RMHangProcDeathSynchObjects::~RMHangProcDeathSynchObjects()
  33. {
  34. try
  35. {
  36. // Be sure that the calling thread is the owner (if any) of the locks
  37. EnterCriticalSection(&m_cs);
  38. CloseHandle(m_hMutex);
  39. }
  40. catch (...)
  41. {
  42. }
  43. try
  44. {
  45. LeaveCriticalSection(&m_cs);
  46. DeleteCriticalSection(&m_cs);
  47. }
  48. catch (...)
  49. {
  50. }
  51. }
  52. CRITICAL_SECTION *
  53. RMHangProcDeathSynchObjects::CriticalSection()
  54. {
  55. return &m_cs;
  56. }
  57. HANDLE
  58. RMHangProcDeathSynchObjects::Mutex() const
  59. {
  60. return m_hMutex;
  61. }
  62. //////////////////////////////////////////////////////////////////////
  63. // Construction/Destruction
  64. //////////////////////////////////////////////////////////////////////
  65. CIOPLock::CIOPLock(const char *szReaderName)
  66. : m_apRMHangProcDeathSynchObjects(0),
  67. m_pSmartCard(0)
  68. {
  69. m_iRefCount = 0;
  70. #if defined(SLBIOP_RM_HANG_AT_PROCESS_DEATH)
  71. SECURITY_ATTRIBUTES *psa = NULL;
  72. #if defined(SLBIOP_USE_SECURITY_ATTRIBUTES)
  73. CSecurityAttributes *sa = new CSecurityAttributes;
  74. CIOP::InitIOPSecurityAttrs(sa);
  75. psa = &(sa->sa);
  76. #endif
  77. // Set up mutex name
  78. char szMutexName[RMHangProcDeathSynchObjects::cMaxMutexNameLength]
  79. = "SLBIOP_MUTEX_";
  80. if (strlen(szMutexName) + strlen(szReaderName) + 1 >
  81. RMHangProcDeathSynchObjects::cMaxMutexNameLength)
  82. throw Exception(ccSynchronizationObjectNameTooLong);
  83. strcat(szMutexName, szReaderName);
  84. m_apRMHangProcDeathSynchObjects =
  85. auto_ptr<RMHangProcDeathSynchObjects>(new
  86. RMHangProcDeathSynchObjects(psa,
  87. szMutexName));
  88. #if defined(SLBIOP_USE_SECURITY_ATTRIBUTES)
  89. delete sa;
  90. #endif
  91. #endif // defined(SLBIOP_RM_HANG_AT_PROCESS_DEATH)
  92. }
  93. CIOPLock::~CIOPLock()
  94. {
  95. }
  96. CRITICAL_SECTION *
  97. CIOPLock::CriticalSection()
  98. {
  99. return m_apRMHangProcDeathSynchObjects->CriticalSection();
  100. }
  101. void CIOPLock::Init(CSmartCard *pSmartCard)
  102. {
  103. m_pSmartCard = pSmartCard;
  104. }
  105. HANDLE
  106. CIOPLock::MutexHandle()
  107. {
  108. return m_apRMHangProcDeathSynchObjects->Mutex();
  109. }