Skip to content

Comments

sharedgpures: fix dispatch_close decrementing ref_count for handles that never opened a resource#313

Open
avafloww wants to merge 1 commit intoValveSoftware:bleeding-edgefrom
avafloww:fix/sharedgpures-dispatch-close
Open

sharedgpures: fix dispatch_close decrementing ref_count for handles that never opened a resource#313
avafloww wants to merge 1 commit intoValveSoftware:bleeding-edgefrom
avafloww:fix/sharedgpures-dispatch-close

Conversation

@avafloww
Copy link

@avafloww avafloww commented Feb 20, 2026

When a process opens the \Device\SharedGpuResource device but the subsequent IOCTL_SHARED_GPU_RESOURCE_OPEN fails (e.g. invalid KMT handle), FsContext is never updated from its default value of 0. dispatch_close unconditionally computes &resource_pool[FsContext] and decrements ref_count, which erroneously frees whatever resource happens to be at index 0.

This is particularly damaging when DXVK retries failed OPEN ioctls thousands of times via the D3DKMT DDI path (when
NtGdiDdDDIQueryResourceInfo is stubbed), as each open/close cycle decrements resource_pool[0].ref_count.

Fix by initializing FsContext to (UINT_PTR)-1 as a sentinel in dispatch_create, and skipping cleanup in dispatch_close when the sentinel is still set.


This is one of two PRs needed to make Wine/Proton & Spout2PW work with VNyan under Linux. The other PR is #312.

…hat never opened a resource

When a process opens the \Device\SharedGpuResource device but the
subsequent IOCTL_SHARED_GPU_RESOURCE_OPEN fails (e.g. invalid KMT
handle), FsContext is never updated from its default value of 0.
dispatch_close unconditionally computes &resource_pool[FsContext] and
decrements ref_count, which erroneously frees whatever resource happens
to be at index 0.

This is particularly damaging when DXVK retries failed OPEN ioctls
thousands of times via the D3DKMT DDI path (when
NtGdiDdDDIQueryResourceInfo is stubbed), as each open/close cycle
decrements resource_pool[0].ref_count.

Fix by initializing FsContext to (UINT_PTR)-1 as a sentinel in
dispatch_create, and skipping cleanup in dispatch_close when the
sentinel is still set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant