[PATCH 2/5] d3d8: Sanitize map flags according to resource access flags.

Matteo Bruni mbruni at codeweavers.com
Tue Jan 29 08:28:06 CST 2019


Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
 dlls/d3d8/buffer.c       | 16 ++++++++++++----
 dlls/d3d8/d3d8_private.h |  2 +-
 dlls/d3d8/device.c       | 14 +++++++++++++-
 dlls/d3d8/surface.c      |  2 +-
 dlls/d3d8/volume.c       |  2 +-
 5 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/dlls/d3d8/buffer.c b/dlls/d3d8/buffer.c
index 0a6767be70e..b6d9f58cdc4 100644
--- a/dlls/d3d8/buffer.c
+++ b/dlls/d3d8/buffer.c
@@ -188,6 +188,8 @@ static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, UINT
         BYTE **data, DWORD flags)
 {
     struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
+    struct wined3d_resource *wined3d_resource;
+    struct wined3d_resource_desc wined3d_desc;
     struct wined3d_map_desc wined3d_map_desc;
     struct wined3d_box wined3d_box = {0};
     HRESULT hr;
@@ -198,8 +200,10 @@ static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, UINT
     wined3d_box.left = offset;
     wined3d_box.right = offset + size;
     wined3d_mutex_lock();
-    hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->wined3d_buffer),
-            0, &wined3d_map_desc, &wined3d_box, wined3dmapflags_from_d3dmapflags(flags));
+    wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
+    wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
+    hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc, &wined3d_box,
+            wined3dmapflags_from_d3dmapflags(flags, wined3d_desc.access));
     wined3d_mutex_unlock();
     *data = wined3d_map_desc.data;
 
@@ -509,6 +513,8 @@ static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT o
         BYTE **data, DWORD flags)
 {
     struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
+    struct wined3d_resource *wined3d_resource;
+    struct wined3d_resource_desc wined3d_desc;
     struct wined3d_map_desc wined3d_map_desc;
     struct wined3d_box wined3d_box = {0};
     HRESULT hr;
@@ -519,8 +525,10 @@ static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT o
     wined3d_box.left = offset;
     wined3d_box.right = offset + size;
     wined3d_mutex_lock();
-    hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->wined3d_buffer),
-            0, &wined3d_map_desc, &wined3d_box, wined3dmapflags_from_d3dmapflags(flags));
+    wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
+    wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
+    hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc, &wined3d_box,
+            wined3dmapflags_from_d3dmapflags(flags, wined3d_desc.access));
     wined3d_mutex_unlock();
     *data = wined3d_map_desc.data;
 
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 81f4e2009fd..858fa6b2f4f 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -282,7 +282,7 @@ HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_dev
 
 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
-unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags) DECLSPEC_HIDDEN;
+unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags, unsigned int access) DECLSPEC_HIDDEN;
 void load_local_constants(const DWORD *d3d8_elements, struct wined3d_shader *wined3d_vertex_shader) DECLSPEC_HIDDEN;
 size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN;
 
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index a113e57f580..6151a8b2e8d 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -142,7 +142,7 @@ enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
     }
 }
 
-unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags)
+unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags, unsigned int access)
 {
     static const unsigned int handled = D3DLOCK_NOSYSLOCK
             | D3DLOCK_NOOVERWRITE
@@ -162,6 +162,18 @@ unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags)
     if (flags)
         FIXME("Unhandled flags %#x.\n", flags);
 
+    if ((wined3d_flags & WINED3D_MAP_READ && ~access & WINED3D_RESOURCE_ACCESS_MAP_R)
+            || (wined3d_flags & WINED3D_MAP_WRITE && ~access & WINED3D_RESOURCE_ACCESS_MAP_W))
+    {
+        WARN("Sanitizing map flags %#x, access %#x.\n", flags, access);
+        if (wined3d_flags & WINED3D_MAP_READ && ~access & WINED3D_RESOURCE_ACCESS_MAP_R)
+            wined3d_flags &= ~WINED3D_MAP_READ;
+        if (wined3d_flags & WINED3D_MAP_WRITE && ~access & WINED3D_RESOURCE_ACCESS_MAP_W)
+            wined3d_flags &= ~WINED3D_MAP_WRITE;
+        if (!wined3d_flags)
+            wined3d_flags = WINED3D_MAP_WRITE;
+    }
+
     return wined3d_flags;
 }
 
diff --git a/dlls/d3d8/surface.c b/dlls/d3d8/surface.c
index 0d8793788d7..4fba7c92f2d 100644
--- a/dlls/d3d8/surface.c
+++ b/dlls/d3d8/surface.c
@@ -245,7 +245,7 @@ static HRESULT WINAPI d3d8_surface_LockRect(IDirect3DSurface8 *iface,
     }
 
     hr = wined3d_resource_map(wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx,
-            &map_desc, rect ? &box : NULL, wined3dmapflags_from_d3dmapflags(flags));
+            &map_desc, rect ? &box : NULL, wined3dmapflags_from_d3dmapflags(flags, ~0u));
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
diff --git a/dlls/d3d8/volume.c b/dlls/d3d8/volume.c
index 00dd78a533e..a4d6c0bcd24 100644
--- a/dlls/d3d8/volume.c
+++ b/dlls/d3d8/volume.c
@@ -149,7 +149,7 @@ static HRESULT WINAPI d3d8_volume_LockBox(IDirect3DVolume8 *iface,
     wined3d_mutex_lock();
     if (FAILED(hr = wined3d_resource_map(wined3d_texture_get_resource(volume->wined3d_texture),
             volume->sub_resource_idx, &map_desc, (const struct wined3d_box *)box,
-            wined3dmapflags_from_d3dmapflags(flags))))
+            wined3dmapflags_from_d3dmapflags(flags, ~0u))))
         map_desc.data = NULL;
     wined3d_mutex_unlock();
 
-- 
2.19.2




More information about the wine-devel mailing list