Skip to content

Commit 6f09492

Browse files
committed
Lesson 23, step 4, size_t usage
1 parent de3d442 commit 6f09492

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

23-fixes/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ C99 introduces standard fixed-width data types like `uint32_t`
3939
We need to include `<stdint.h>` which works even in `-ffreestanding` (but requires stdlibs)
4040
and use those data types instead of our own, then delete them on `type.h`
4141

42-
<stddef.h> to provide size\_t
43-
42+
4. Improperly aligned `kmalloc`
43+
-------------------------------
4444

45+
First, since `kmalloc` uses a size parameter, we'll use the correct data type `size_t` instead
46+
of `u32int_t`. `<stddef.h>` is required for `size_t`
4547

4648
5. Missing functions
4749
--------------------
@@ -54,7 +56,4 @@ and use those data types instead of our own, then delete them on `type.h`
5456
7. Structs and attributes
5557
-------------------------
5658

57-
8. Improperly aligned `kmalloc`
58-
-------------------------------
59-
6059

23-fixes/libc/mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void memory_set(uint8_t *dest, uint8_t val, uint32_t len) {
1818
uint32_t free_mem_addr = 0x10000;
1919
/* Implementation is just a pointer to some free memory which
2020
* keeps growing */
21-
uint32_t kmalloc(uint32_t size, int align, uint32_t *phys_addr) {
21+
uint32_t kmalloc(size_t size, int align, uint32_t *phys_addr) {
2222
/* Pages are aligned to 4K, or 0x1000 */
2323
if (align == 1 && (free_mem_addr & 0xFFFFF000)) {
2424
free_mem_addr &= 0xFFFFF000;

23-fixes/libc/mem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define MEM_H
33

44
#include <stdint.h>
5+
#include <stddef.h>
56

67
void memory_copy(uint8_t *source, uint8_t *dest, int nbytes);
78
void memory_set(uint8_t *dest, uint8_t val, uint32_t len);
89

910
/* At this stage there is no 'free' implemented. */
10-
uint32_t kmalloc(uint32_t size, int align, uint32_t *phys_addr);
11+
uint32_t kmalloc(size_t size, int align, uint32_t *phys_addr);
1112

1213
#endif

0 commit comments

Comments
 (0)