From 2b916f61214e741f9f047f4865628495165051ee Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 17 Jul 2024 13:40:16 -0400 Subject: [PATCH] kernel/image: Report image removals on team destruction or exec. We can't call user_debug_image_deleted with the lock held, so clear the list and remove all images before unlocking and looping again. This also means we free() without the lock held, which should reduce contention. --- src/system/kernel/image.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/system/kernel/image.cpp b/src/system/kernel/image.cpp index c3bad82ab1..457eb90ebf 100644 --- a/src/system/kernel/image.cpp +++ b/src/system/kernel/image.cpp @@ -210,20 +210,28 @@ count_images(Team *team) status_t remove_images(Team *team) { - struct image *image; + struct image *image = NULL; ASSERT(team != NULL); mutex_lock(&sImageMutex); - while ((image = (struct image*)list_remove_head_item(&team->image_list)) - != NULL) { + struct list images = {}; + list_move_to_list(&team->image_list, &images); + while ((image = (struct image*)list_get_next_item(&images, + image)) != NULL) { sImageTable->Remove(image); - free(image); } mutex_unlock(&sImageMutex); + while ((image = (struct image*)list_remove_head_item(&images)) + != NULL) { + user_debug_image_deleted(&image->info.basic_info); + sNotificationService.Notify(IMAGE_REMOVED, image); + free(image); + } + return B_OK; }