disk: Add sanity checks to cache
diff --git a/limine-pxe.bin b/limine-pxe.bin
index 70eb9556..fe440cf8 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 7517741c..f4d8be52 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 93db3083..d0b5a4fb 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/drivers/disk.c b/stage2/drivers/disk.c
index 1b641449..8f3b6447 100644
--- a/stage2/drivers/disk.c
+++ b/stage2/drivers/disk.c
@@ -12,6 +12,9 @@
#define CACHE_INVALID (~((uint64_t)0))
+#define MAX_CACHE 16384
+
+static int cached_drive = -1;
static uint8_t *cache = NULL;
static uint64_t cached_block = CACHE_INVALID;
@@ -26,7 +29,7 @@ struct dap {
static struct dap *dap = NULL;
static int cache_block(int drive, uint64_t block, int sector_size) {
- if (block == cached_block)
+ if (drive == cached_drive && block == cached_block)
return 0;
if (!dap) {
@@ -36,7 +39,10 @@ static int cache_block(int drive, uint64_t block, int sector_size) {
}
if (!cache)
- cache = conv_mem_alloc_aligned(BLOCK_SIZE, 16);
+ cache = conv_mem_alloc_aligned(MAX_CACHE, 16);
+
+ if (BLOCK_SIZE > MAX_CACHE)
+ panic("Disk cache overflow");
dap->segment = rm_seg(cache);
dap->offset = rm_off(cache);
@@ -56,6 +62,7 @@ static int cache_block(int drive, uint64_t block, int sector_size) {
}
cached_block = block;
+ cached_drive = drive;
return 0;
}
