Skip to content

Commit

Permalink
Lesson 23, step 4, size_t usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cfenollosa committed Aug 18, 2015
1 parent de3d442 commit 6f09492
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
9 changes: 4 additions & 5 deletions 23-fixes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ C99 introduces standard fixed-width data types like `uint32_t`
We need to include `<stdint.h>` which works even in `-ffreestanding` (but requires stdlibs)
and use those data types instead of our own, then delete them on `type.h`

<stddef.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`. `<stddef.h>` is required for `size_t`

5. Missing functions
--------------------
Expand All @@ -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`
-------------------------------


2 changes: 1 addition & 1 deletion 23-fixes/libc/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion 23-fixes/libc/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define MEM_H

#include <stdint.h>
#include <stddef.h>

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

0 comments on commit 6f09492

Please sign in to comment.