mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-23 06:46:02 +00:00
fix(vkbridge): AHB sharing takes the handle fd that holds the memory
Mali's gralloc can put several fds in an AHardwareBuffer's native handle; the one handed to the client is now the first at least as large as the allocation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1U9H1evGNjHRQ3wRUdv5V
This commit is contained in:
1 parent
8c050f43b6
commit
de1f1f26d0
1 file changed
+16
-1
@@ -301,7 +301,22 @@ static VkResult alloc_shared(const vkb_dispatch *dt, VkDevice dev, uint32_t s, c
|
|||||||
r = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
r = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*out_fd = fcntl(nh->data[0], F_DUPFD_CLOEXEC, 0);
|
/* Mali's gralloc can put more than one fd in the handle (metadata beside the pages): the
|
||||||
|
* memory is the one at least as large as the allocation. */
|
||||||
|
int pick = -1;
|
||||||
|
for (int i = 0; i < nh->numFds && pick < 0; i++) {
|
||||||
|
off_t end = lseek(nh->data[i], 0, SEEK_END);
|
||||||
|
if (end >= (off_t)sz) pick = nh->data[i];
|
||||||
|
if (nh->numFds > 1) VKB_INFO("ahb: handle fd %d of %d is %lld bytes", i + 1, nh->numFds, (long long)end);
|
||||||
|
}
|
||||||
|
if (pick < 0) {
|
||||||
|
VKB_INFO("ahb: no fd in the handle covers %llu bytes", (unsigned long long)sz);
|
||||||
|
dt->vkFreeMemory(dev, m->mem, NULL);
|
||||||
|
m->mem = VK_NULL_HANDLE;
|
||||||
|
r = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*out_fd = fcntl(pick, F_DUPFD_CLOEXEC, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in new issue
Block a user