1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // MappedSubresourceVerifier11.h: Defines the rx::MappedSubresourceVerifier11
8 // class, a simple wrapper to D3D11 Texture2D mapped memory so that ASAN
9 // MSAN can catch memory errors done with a pointer to the mapped texture
10 // memory.
11 
12 #ifndef LIBANGLE_RENDERER_D3D_D3D11_MAPPED_SUBRESOURCE_VERIFIER11_H_
13 #define LIBANGLE_RENDERER_D3D_D3D11_MAPPED_SUBRESOURCE_VERIFIER11_H_
14 
15 #include "common/MemoryBuffer.h"
16 #include "common/angleutils.h"
17 
18 namespace rx
19 {
20 
21 class MappedSubresourceVerifier11 final : angle::NonCopyable
22 {
23   public:
24     MappedSubresourceVerifier11();
25     ~MappedSubresourceVerifier11();
26 
27     void setDesc(const D3D11_TEXTURE2D_DESC &desc);
28     void setDesc(const D3D11_TEXTURE3D_DESC &desc);
29     void reset();
30 
31     bool wrap(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map);
32     void unwrap();
33 
34   private:
35 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || defined(ANGLE_ENABLE_ASSERTS)
36     UINT D3D11_MAPPED_SUBRESOURCE::*mPitchType = nullptr;
37     size_t mPitchCount                         = 0;
38     angle::MemoryBuffer mWrapData;
39     uint8_t *mOrigData = nullptr;
40 #endif
41 };
42 
43 #if !(defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || defined(ANGLE_ENABLE_ASSERTS))
44 
45 inline MappedSubresourceVerifier11::MappedSubresourceVerifier11()  = default;
46 inline MappedSubresourceVerifier11::~MappedSubresourceVerifier11() = default;
47 
setDesc(const D3D11_TEXTURE2D_DESC & desc)48 inline void MappedSubresourceVerifier11::setDesc(const D3D11_TEXTURE2D_DESC &desc) {}
setDesc(const D3D11_TEXTURE3D_DESC & desc)49 inline void MappedSubresourceVerifier11::setDesc(const D3D11_TEXTURE3D_DESC &desc) {}
reset()50 inline void MappedSubresourceVerifier11::reset() {}
51 
wrap(D3D11_MAP mapType,D3D11_MAPPED_SUBRESOURCE * map)52 inline bool MappedSubresourceVerifier11::wrap(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map)
53 {
54     return true;
55 }
56 
unwrap()57 inline void MappedSubresourceVerifier11::unwrap() {}
58 
59 #endif
60 
61 }  // namespace rx
62 
63 #endif  // LIBANGLE_RENDERER_D3D_D3D11_MAPPED_SUBRESOURCE_VERIFIER11_H_
64