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.

176 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. DIMM_IMCLock.cpp
  5. Abstract:
  6. This file implements the DIMM_IMCLock / DIMM_IMCCLock Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "imclock2.h"
  13. #include "defs.h"
  14. #include "delay.h"
  15. #include "globals.h"
  16. #include "cdimm.h"
  17. DIMM_IMCLock::DIMM_IMCLock(
  18. HIMC hImc
  19. ) : _IMCLock(hImc)
  20. {
  21. if (hImc) {
  22. /*
  23. * Set m_fUnicde and m_uCodePage
  24. */
  25. DWORD dwProcessId;
  26. CActiveIMM *_this = GetTLS();
  27. if (_this == NULL)
  28. return;
  29. if (!_this->_ContextLookup(hImc, &dwProcessId, &m_fUnicode))
  30. return;
  31. m_hr = _LockIMC(hImc, &m_inputcontext);
  32. }
  33. }
  34. HRESULT
  35. DIMM_IMCLock::_LockIMC(
  36. IN HIMC hIMC,
  37. OUT INPUTCONTEXT_AIMM12 **ppIMC
  38. )
  39. {
  40. TraceMsg(TF_API, "_LockIMC");
  41. if (hIMC == NULL)
  42. return E_INVALIDARG;
  43. /*
  44. * Get Process ID
  45. */
  46. DWORD dwProcessId;
  47. CActiveIMM *_this = GetTLS();
  48. if (_this == NULL)
  49. return E_FAIL;
  50. if (!_this->_ContextLookup(hIMC, &dwProcessId))
  51. return E_ACCESSDENIED;
  52. if (IsOnImm()) {
  53. return Imm32_LockIMC(hIMC, (INPUTCONTEXT**)ppIMC);
  54. }
  55. else {
  56. /*
  57. * Cannot access input context from other process.
  58. */
  59. if (dwProcessId != GetCurrentProcessId())
  60. return E_ACCESSDENIED;
  61. *ppIMC = (INPUTCONTEXT_AIMM12 *)LocalLock(hIMC);
  62. }
  63. return *ppIMC == NULL ? E_FAIL : S_OK;
  64. }
  65. HRESULT
  66. DIMM_IMCLock::_UnlockIMC(
  67. IN HIMC hIMC
  68. )
  69. {
  70. TraceMsg(TF_API, "_UnlockIMC");
  71. if (IsOnImm()) {
  72. return Imm32_UnlockIMC(hIMC);
  73. }
  74. else {
  75. // for now HIMC are LocalAlloc(LHND) handle
  76. if (LocalUnlock(hIMC)) {
  77. // memory object still locked.
  78. return S_OK;
  79. }
  80. else {
  81. DWORD err = GetLastError();
  82. if (err == NO_ERROR)
  83. // memory object is unlocked.
  84. return S_OK;
  85. else if (err == ERROR_NOT_LOCKED)
  86. // memory object is already unlocked.
  87. return S_OK;
  88. }
  89. }
  90. return E_FAIL;
  91. }
  92. DIMM_InternalIMCCLock::DIMM_InternalIMCCLock(
  93. HIMCC hImcc
  94. ) : _IMCCLock(hImcc)
  95. {
  96. if (hImcc) {
  97. m_hr = _LockIMCC(m_himcc, (void**)&m_pimcc);
  98. }
  99. }
  100. HRESULT
  101. DIMM_InternalIMCCLock::_LockIMCC(
  102. HIMCC hIMCC,
  103. void** ppv
  104. )
  105. {
  106. TraceMsg(TF_API, "_LockIMCC");
  107. if (hIMCC == NULL) {
  108. return E_INVALIDARG;
  109. }
  110. if (IsOnImm()) {
  111. return Imm32_LockIMCC(hIMCC, ppv);
  112. }
  113. else {
  114. *ppv = (void *)LocalLock(hIMCC);
  115. }
  116. return *ppv == NULL ? E_FAIL : S_OK;
  117. }
  118. HRESULT
  119. DIMM_InternalIMCCLock::_UnlockIMCC(
  120. HIMCC hIMCC
  121. )
  122. {
  123. TraceMsg(TF_API, "_UnlockIMCC");
  124. if (IsOnImm()) {
  125. return Imm32_UnlockIMCC(hIMCC);
  126. }
  127. else {
  128. if (LocalUnlock(hIMCC)) {
  129. // memory object still locked.
  130. return S_OK;
  131. }
  132. else {
  133. DWORD err = GetLastError();
  134. if (err == NO_ERROR)
  135. // memory object is unlocked.
  136. return S_OK;
  137. else if (err == ERROR_NOT_LOCKED)
  138. // memory object is already unlocked.
  139. return S_OK;
  140. }
  141. }
  142. return E_FAIL;
  143. }