diff --git a/src/apps/processcontroller/MemoryBarMenuItem.cpp b/src/apps/processcontroller/MemoryBarMenuItem.cpp index 4930cd3186..448390262f 100644 --- a/src/apps/processcontroller/MemoryBarMenuItem.cpp +++ b/src/apps/processcontroller/MemoryBarMenuItem.cpp @@ -3,6 +3,7 @@ * Copyright 2022, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ + #include "MemoryBarMenuItem.h" #include "Colors.h" @@ -11,6 +12,7 @@ #include #include +#include #include #include @@ -216,27 +218,44 @@ MemoryBarMenuItem::BarUpdate() int64 lwram_size = 0; bool exists = false; + const bool isAppServer = (strcmp(Label(), "app_server") == 0); + while (get_next_area_info(fTeamID, &cookie, &areaInfo) == B_OK) { exists = true; lram_size += areaInfo.ram_size; - // TODO: this won't work this way anymore under Haiku! -// int zone = (int (areaInfo.address) & 0xf0000000) >> 24; + if (isAppServer && strncmp(areaInfo.name, "a:", 2) == 0) { + // app_server side of client memory (e.g. bitmaps), ignore. + continue; + } + if (fTeamID == B_SYSTEM_TEAM) { + if ((areaInfo.protection & B_KERNEL_WRITE_AREA) != 0) + areaInfo.protection |= B_WRITE_AREA; + } + // TODO: Exclude media buffers + if ((areaInfo.protection & B_WRITE_AREA) != 0) lwram_size += areaInfo.ram_size; -// && (zone & 0xf0) != 0xA0 // Exclude media buffers -// && (fTeamID != gAppServerTeamID || zone != 0x90)) // Exclude app_server side of bitmaps } - if (!exists) { + if (fTeamID == B_SYSTEM_TEAM) { + system_info info; + status_t status = get_system_info(&info); + if (status == B_OK) { + // block_cache memory will be in writable areas + lwram_size -= info.block_cache_pages * B_PAGE_SIZE; + } + } else if (!exists) { team_info info; exists = get_team_info(fTeamID, &info) == B_OK; + if (!exists) { + fWriteMemory = -1; + return; + } } - if (exists) { - fWriteMemory = lwram_size / 1024; - fAllMemory = lram_size / 1024; - DrawBar(false); - } else - fWriteMemory = -1; + + fWriteMemory = lwram_size / 1024; + fAllMemory = lram_size / 1024; + DrawBar(false); }