From 85df2a7609d28e442ba1bbd01df99bee224df3f9 Mon Sep 17 00:00:00 2001 From: pointer-to-bios Date: Wed, 31 Jan 2024 21:11:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Draw=5Fallocator=E5=9C=A8?= =?UTF-8?q?=E6=9F=90=E4=BA=9B=E6=97=B6=E5=80=99=E6=AD=BB=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kernel/memm/allocator/raw.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/kernel/memm/allocator/raw.c b/src/kernel/memm/allocator/raw.c index 79ed4e8..ce158de 100644 --- a/src/kernel/memm/allocator/raw.c +++ b/src/kernel/memm/allocator/raw.c @@ -17,17 +17,19 @@ void *raw_allocator_allocate(raw_allocator_t *allocator, usize size, usize align { usize real_size = size; align_to(real_size, 16); - raw_allocator_cell *cell = allocator->cells; - while ((void *)raw_allocator_next_cell(cell) < (void *)allocator + allocator->size) + raw_allocator_cell *cell = &allocator->cells; + while ((void *)cell < raw_allocator_end(allocator)) { while ( // 确保cell指向的内容还在这个allocator内 - (void *)raw_allocator_next_cell(cell) < raw_allocator_end(allocator) && + (void *)cell < raw_allocator_end(allocator) && cell->length != 0) { cell = raw_allocator_next_cell(cell); } if (real_size <= cell->capacity) break; + else + cell = raw_allocator_next_cell(cell); } if ((void *)cell < raw_allocator_end(allocator)) goto fitable_cell_finded;