From 0b35a8f81a0adb04b973fab1181cd1482cd7f35b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 10 Jul 2021 11:16:56 -0400 Subject: [PATCH] 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 Part-of: --- 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 4abad19..d6cbfa6 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; -- 2.7.4