Allocate block cache in .bss rather than heap
Bug: 130560272
Change-Id: I1759d20ed75914de7f20010ef0369a7f89fec342
diff --git a/block_cache.c b/block_cache.c
index de6f0b2..5870775 100644
--- a/block_cache.c
+++ b/block_cache.c
@@ -49,7 +49,8 @@
#define BLOCK_CACHE_GUARD_2 (0xdead0005dead0007)
static struct list_node block_cache_lru = LIST_INITIAL_VALUE(block_cache_lru);
-static struct block_cache_entry* block_cache_entries;
+static struct block_cache_entry block_cache_entries[BLOCK_CACHE_SIZE];
+static bool block_cache_init_called = false;
/**
* block_cache_queue_io_op - Helper function to start a read or write operation
@@ -654,30 +655,28 @@
void block_cache_init(void) {
int i;
struct obj_ref ref;
- struct block_cache_entry* entry;
- assert(!block_cache_entries);
+ assert(!block_cache_init_called);
- entry = malloc(sizeof(block_cache_entries[0]) * BLOCK_CACHE_SIZE);
- assert(entry);
- full_assert(memset(entry, 1,
- sizeof(block_cache_entries[0]) * BLOCK_CACHE_SIZE));
- block_cache_entries = entry;
+ block_cache_init_called = true;
- for (i = 0; i < BLOCK_CACHE_SIZE; i++, entry++) {
- entry->guard1 = BLOCK_CACHE_GUARD_1;
- entry->guard2 = BLOCK_CACHE_GUARD_2;
- entry->dev = NULL;
- entry->block = DATA_BLOCK_INVALID;
- entry->dirty = false;
- entry->dirty_ref = false;
- entry->dirty_mac = false;
- entry->dirty_tr = NULL;
- entry->io_op = BLOCK_CACHE_IO_OP_NONE;
- obj_init(&entry->obj, &ref);
- list_clear_node(&entry->io_op_node);
- list_add_head(&block_cache_lru, &entry->lru_node);
- obj_del_ref(&entry->obj, &ref, block_cache_entry_destroy);
+ full_assert(memset(block_cache_entries, 1, sizeof(block_cache_entries)));
+
+ for (i = 0; i < BLOCK_CACHE_SIZE; i++) {
+ block_cache_entries[i].guard1 = BLOCK_CACHE_GUARD_1;
+ block_cache_entries[i].guard2 = BLOCK_CACHE_GUARD_2;
+ block_cache_entries[i].dev = NULL;
+ block_cache_entries[i].block = DATA_BLOCK_INVALID;
+ block_cache_entries[i].dirty = false;
+ block_cache_entries[i].dirty_ref = false;
+ block_cache_entries[i].dirty_mac = false;
+ block_cache_entries[i].dirty_tr = NULL;
+ block_cache_entries[i].io_op = BLOCK_CACHE_IO_OP_NONE;
+ obj_init(&block_cache_entries[i].obj, &ref);
+ list_clear_node(&block_cache_entries[i].io_op_node);
+ list_add_head(&block_cache_lru, &block_cache_entries[i].lru_node);
+ obj_del_ref(&block_cache_entries[i].obj, &ref,
+ block_cache_entry_destroy);
}
}
diff --git a/manifest.c b/manifest.c
index 0d07347..b3de33e 100644
--- a/manifest.c
+++ b/manifest.c
@@ -16,8 +16,6 @@
#include <trusty_app_manifest.h>
-#include "block_cache_priv.h"
-
trusty_app_manifest_t TRUSTY_APP_MANIFEST_ATTRS trusty_app_manifest = {
.uuid =
{/* cea8706d-6cb4-49f3-b994-29e0e478bd29 */
@@ -27,7 +25,6 @@
{0xb9, 0x94, 0x29, 0xe0, 0xe4, 0x78, 0xbd, 0x29}},
{
TRUSTY_APP_CONFIG_MIN_STACK_SIZE(4 * 4096),
- TRUSTY_APP_CONFIG_MIN_HEAP_SIZE(8 * 4096 +
- BLOCK_CACHE_SIZE_BYTES),
+ TRUSTY_APP_CONFIG_MIN_HEAP_SIZE(8 * 4096),
},
};