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.

167 lines
3.4 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. cmemorystream.cpp
  5. Abstract:
  6. Minimal implementation of IStream over an array of bytes.
  7. Author:
  8. Jay Krell (a-JayK, JayKrell) May 2000
  9. Revision History:
  10. --*/
  11. #include "stdinc.h"
  12. #include "cmemorystream.h"
  13. #include "sxsexceptionhandling.h"
  14. #if defined(FUSION_WIN)
  15. #include "ntrtlmmapio.h"
  16. #endif
  17. /* aka doesn't make sense aka access denied */
  18. #define NOTIMPL ASSERT_NTC(FALSE) ; return E_NOTIMPL
  19. CMemoryStream::~CMemoryStream()
  20. {
  21. ASSERT_NTC(m_cRef == 0);
  22. }
  23. ULONG __stdcall CMemoryStream::AddRef()
  24. {
  25. FN_TRACE_ADDREF(CMemoryStream, m_cRef);
  26. return ::InterlockedIncrement(&m_cRef);
  27. }
  28. ULONG __stdcall CMemoryStream::Release()
  29. {
  30. LONG cRef;
  31. FN_TRACE_RELEASE(CMemoryStream, cRef);
  32. if ((cRef = ::InterlockedDecrement(&m_cRef)) == 0)
  33. {
  34. /*delete this*/;
  35. }
  36. return cRef;
  37. }
  38. HRESULT
  39. __stdcall
  40. CMemoryStream::QueryInterface(
  41. REFIID iid,
  42. void **ppvObj
  43. )
  44. {
  45. FN_PROLOG_HR
  46. IUnknown *punk = NULL;
  47. IUnknown **ppunk = reinterpret_cast<IUnknown **>(ppvObj);
  48. *ppunk = NULL;
  49. if (false) { }
  50. #define QI(i) else if (iid == __uuidof(i)) punk = static_cast<i *>(this);
  51. QI(IUnknown)
  52. QI(ISequentialStream)
  53. QI(IStream)
  54. #undef QI
  55. else
  56. {
  57. ORIGINATE_HR_FAILURE_AND_EXIT(CMemoryStream::QueryInterface, E_NOINTERFACE);
  58. }
  59. AddRef();
  60. *ppunk = punk;
  61. FN_EPILOG
  62. }
  63. HRESULT __stdcall CMemoryStream::Read(void *pv, ULONG cb32, ULONG* pcbRead)
  64. {
  65. HRESULT hr = NOERROR;
  66. NTSTATUS Status = STATUS_SUCCESS;
  67. const BYTE * const pbCurrent = m_pbCurrent; // read this once for near thread safety..
  68. __int64 cb = cb32;
  69. __int64 cbBytesRemaining = (m_pbEnd - pbCurrent);
  70. if (cb > cbBytesRemaining)
  71. cb = cbBytesRemaining;
  72. #if defined(FUSION_WIN)
  73. Status = RtlCopyMappedMemory(pv, pbCurrent, static_cast<SIZE_T>(cb));
  74. #else
  75. CopyMemory(pv, pbCurrent, static_cast<SIZE_T>(cb));
  76. #endif
  77. if (!NT_SUCCESS(Status))
  78. {
  79. hr = HRESULT_FROM_WIN32(FusionpRtlNtStatusToDosError(Status));
  80. goto Exit;
  81. }
  82. m_pbCurrent = pbCurrent + cb; // write this once for near thread safety..
  83. *pcbRead = static_cast<ULONG>(cb);
  84. hr = NOERROR;
  85. Exit:
  86. return hr;
  87. }
  88. HRESULT __stdcall CMemoryStream::Write(void const *pv, ULONG cb, ULONG* pcbWritten)
  89. {
  90. NOTIMPL;
  91. }
  92. HRESULT __stdcall CMemoryStream::Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
  93. {
  94. NOTIMPL;
  95. }
  96. HRESULT __stdcall CMemoryStream::SetSize(ULARGE_INTEGER libNewSize)
  97. {
  98. NOTIMPL;
  99. }
  100. HRESULT __stdcall CMemoryStream::CopyTo(IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
  101. {
  102. NOTIMPL;
  103. }
  104. HRESULT __stdcall CMemoryStream::Commit(DWORD grfCommitFlags)
  105. {
  106. NOTIMPL;
  107. }
  108. HRESULT __stdcall CMemoryStream::Revert()
  109. {
  110. NOTIMPL;
  111. }
  112. HRESULT __stdcall CMemoryStream::LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  113. {
  114. NOTIMPL;
  115. }
  116. HRESULT __stdcall CMemoryStream::UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  117. {
  118. NOTIMPL;
  119. }
  120. HRESULT __stdcall CMemoryStream::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
  121. {
  122. #if 1
  123. NOTIMPL;
  124. #else
  125. we can return size, we can return access==read only
  126. #endif
  127. }
  128. HRESULT __stdcall CMemoryStream::Clone(IStream **ppIStream)
  129. {
  130. NOTIMPL;
  131. }