summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-05-06 11:10:52 +0200
committerAmlal <amlal@nekernel.org>2025-05-06 11:11:34 +0200
commit8ef99527391d2ed35f17c8afbcc1039145692a58 (patch)
tree0a1176c98b3df78915e5f7eda6c1e5ae0967bf12 /dev/kernel
parent0c54169b6517fc7acbe4281399fa8146219a8e2c (diff)
feat(ahci-generic): validate sector_sz when dealing with AHCI I/O.
why? - This will cause math exceptions being raised by the CPU if it happens to be zero. Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel')
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index 3f2cf9e8..cf1841bd 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -132,11 +132,16 @@ STATIC Int32 drv_find_cmd_slot_ahci(HbaPort* port) noexcept {
template <BOOL Write, BOOL CommandOrCTRL, BOOL Identify>
STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz,
SizeT size_buffer) noexcept {
- NE_UNUSED(sector_sz);
+ if (sector_sz == 0) {
+ kout << "Invalid sector size.\r";
+ err_global_get() = kErrorDisk;
+ return;
+ }
lba /= sector_sz;
if (lba > kSATASectorCount) {
+ kout << "Out of range LBA.\r";
err_global_get() = kErrorDisk;
return;
}
@@ -165,6 +170,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
// Clear old command table memory
volatile HbaCmdTbl* command_table =
(volatile HbaCmdTbl*) (((UInt64) command_header->Ctbau << 32) | command_header->Ctba);
+
rt_set_memory((VoidPtr) command_table, 0, sizeof(HbaCmdTbl));
VoidPtr ptr = rtl_dma_alloc(size_buffer, 4096);
@@ -270,7 +276,6 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
ahci_io_end:
rtl_dma_free(size_buffer);
-
err_global_get() = kErrorSuccess;
}
}