diff --git a/23-fixes/README.md b/23-fixes/README.md index 2f2f477..8a976c9 100644 --- a/23-fixes/README.md +++ b/23-fixes/README.md @@ -39,9 +39,11 @@ C99 introduces standard fixed-width data types like `uint32_t` We need to include `` which works even in `-ffreestanding` (but requires stdlibs) and use those data types instead of our own, then delete them on `type.h` - to provide size\_t - +4. Improperly aligned `kmalloc` +------------------------------- +First, since `kmalloc` uses a size parameter, we'll use the correct data type `size_t` instead +of `u32int_t`. `` is required for `size_t` 5. Missing functions -------------------- @@ -54,7 +56,4 @@ and use those data types instead of our own, then delete them on `type.h` 7. Structs and attributes ------------------------- -8. Improperly aligned `kmalloc` -------------------------------- - diff --git a/23-fixes/libc/mem.c b/23-fixes/libc/mem.c index 86dc869..4a29549 100644 --- a/23-fixes/libc/mem.c +++ b/23-fixes/libc/mem.c @@ -18,7 +18,7 @@ void memory_set(uint8_t *dest, uint8_t val, uint32_t len) { uint32_t free_mem_addr = 0x10000; /* Implementation is just a pointer to some free memory which * keeps growing */ -uint32_t kmalloc(uint32_t size, int align, uint32_t *phys_addr) { +uint32_t kmalloc(size_t size, int align, uint32_t *phys_addr) { /* Pages are aligned to 4K, or 0x1000 */ if (align == 1 && (free_mem_addr & 0xFFFFF000)) { free_mem_addr &= 0xFFFFF000; diff --git a/23-fixes/libc/mem.h b/23-fixes/libc/mem.h index 11e3c7e..75eb522 100644 --- a/23-fixes/libc/mem.h +++ b/23-fixes/libc/mem.h @@ -2,11 +2,12 @@ #define MEM_H #include +#include void memory_copy(uint8_t *source, uint8_t *dest, int nbytes); void memory_set(uint8_t *dest, uint8_t val, uint32_t len); /* At this stage there is no 'free' implemented. */ -uint32_t kmalloc(uint32_t size, int align, uint32_t *phys_addr); +uint32_t kmalloc(size_t size, int align, uint32_t *phys_addr); #endif