diff options
author | Alyssa Rosenzweig <alyssa@rosenzweig.io> | 2021-07-10 11:16:56 -0400 |
---|---|---|
committer | Alyssa Rosenzweig <alyssa@rosenzweig.io> | 2021-07-10 11:16:56 -0400 |
commit | 0b35a8f81a0adb04b973fab1181cd1482cd7f35b (patch) | |
tree | 45f6a80fa48743934f4717777191808e112065f0 /src/asahi | |
parent | 9b6ca87672be842a21dfe33863c93a57b981f4e3 (diff) |
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@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11815>
Diffstat (limited to 'src/asahi')
-rw-r--r-- | src/asahi/lib/decode.c | 19 |
1 files 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; |