Mesa (main): asahi: Make track_free safer
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Jul 11 18:58:29 UTC 2021
Module: Mesa
Branch: main
Commit: 0b35a8f81a0adb04b973fab1181cd1482cd7f35b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0b35a8f81a0adb04b973fab1181cd1482cd7f35b
Author: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Date: Sat Jul 10 11:16:56 2021 -0400
asahi: Make track_free safer
Ensure that we don't free the same BO multiple times, which can lead to later
segfaults in decode.
Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11815>
---
src/asahi/lib/decode.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c
index 4abad19470c..d6cbfa6f155 100644
--- a/src/asahi/lib/decode.c
+++ b/src/asahi/lib/decode.c
@@ -453,20 +453,31 @@ void
agxdecode_track_alloc(struct agx_bo *alloc)
{
assert((mmap_count + 1) < MAX_MAPPINGS);
+
+ for (unsigned i = 0; i < mmap_count; ++i) {
+ struct agx_bo *bo = &mmap_array[i];
+ bool match = (bo->handle == alloc->handle && bo->type == alloc->type);
+ assert(!match && "tried to alloc already allocated BO");
+ }
+
mmap_array[mmap_count++] = *alloc;
}
void
agxdecode_track_free(struct agx_bo *bo)
{
+ bool found = false;
+
for (unsigned i = 0; i < mmap_count; ++i) {
if (mmap_array[i].handle == bo->handle && mmap_array[i].type == bo->type) {
- mmap_array[i].ptr.cpu = 0;
- mmap_array[i].ptr.gpu = 0;
- mmap_array[i].size = 0;
- break;
+ assert(!found && "mapped multiple times!");
+ found = true;
+
+ memset(&mmap_array[i], 0, sizeof(mmap_array[i]));
}
}
+
+ assert(found && "freed unmapped memory");
}
static int agxdecode_dump_frame_count = 0;
More information about the mesa-commit
mailing list