Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 3b315ff

Browse files
committed
upd memm
1 parent 037cb61 commit 3b315ff

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/kernel/mem/manager.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static void *kmalloc_internal(uint32_t size, int retry_count) {
164164
/* Calculate actual user bytes allocated (might be larger than wanted) */
165165
uint32_t actual_user_bytes =
166166
cur->size - sizeof(block_header_t);
167-
167+
168168
uint32_t total_free = 0;
169169
uint32_t largest = 0;
170170
block_header_t *it = free_list;
@@ -188,13 +188,15 @@ static void *kmalloc_internal(uint32_t size, int retry_count) {
188188
}
189189

190190
/* Place canary at end of allocated space (before alignment padding) */
191-
uint32_t *canary =
192-
(uint32_t *)((uintptr_t)user_ptr + wanted_with_canary - sizeof(uint32_t));
191+
uint32_t *canary = (uint32_t *)((uintptr_t)user_ptr +
192+
wanted_with_canary -
193+
sizeof(uint32_t));
193194
*canary = KMALLOC_CANARY;
194195
if (size >= 256) {
195196
printk("mem: set canary at %p (user_ptr=%p wanted=%u wanted_with_canary=%u actual_allocated=%u) value=0x%08x\n",
196-
canary, user_ptr,
197-
wanted, wanted_with_canary, actual_user_bytes, *canary);
197+
canary, user_ptr, wanted,
198+
wanted_with_canary, actual_user_bytes,
199+
*canary);
198200
}
199201
spin_unlock_irqrestore(&heap_lock, flags);
200202
return user_ptr;
@@ -257,8 +259,7 @@ void kfree(void *ptr) {
257259
hdr->size - sizeof(block_header_t);
258260
uint32_t *canary =
259261
(uint32_t *)((uintptr_t)hdr + sizeof(block_header_t) +
260-
user_bytes_with_canary -
261-
sizeof(uint32_t));
262+
user_bytes_with_canary - sizeof(uint32_t));
262263
if (*canary != KMALLOC_CANARY) {
263264
uint32_t got = *canary;
264265
uint32_t tag = hdr->tag;
@@ -269,9 +270,10 @@ void kfree(void *ptr) {
269270
uint8_t *user_ptr =
270271
(uint8_t *)hdr + sizeof(block_header_t);
271272
uint8_t *ctx_start =
272-
user_ptr + (user_bytes_with_canary > 16 ?
273-
user_bytes_with_canary - 16 :
274-
0);
273+
user_ptr +
274+
(user_bytes_with_canary > 16 ?
275+
user_bytes_with_canary - 16 :
276+
0);
275277
uint32_t ctx_len = (user_bytes_with_canary > 16) ?
276278
24 :
277279
(user_bytes_with_canary + 8);

0 commit comments

Comments
 (0)