mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2024-10-27 20:34:19 +00:00
Lesson 23, step 4, size_t usage
This commit is contained in:
parent
de3d442569
commit
6f09492f2b
@ -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)
|
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`
|
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
|
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
|
7. Structs and attributes
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
8. Improperly aligned `kmalloc`
|
|
||||||
-------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ void memory_set(uint8_t *dest, uint8_t val, uint32_t len) {
|
|||||||
uint32_t free_mem_addr = 0x10000;
|
uint32_t free_mem_addr = 0x10000;
|
||||||
/* Implementation is just a pointer to some free memory which
|
/* Implementation is just a pointer to some free memory which
|
||||||
* keeps growing */
|
* 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 */
|
/* Pages are aligned to 4K, or 0x1000 */
|
||||||
if (align == 1 && (free_mem_addr & 0xFFFFF000)) {
|
if (align == 1 && (free_mem_addr & 0xFFFFF000)) {
|
||||||
free_mem_addr &= 0xFFFFF000;
|
free_mem_addr &= 0xFFFFF000;
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
#define MEM_H
|
#define MEM_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
void memory_copy(uint8_t *source, uint8_t *dest, int nbytes);
|
void memory_copy(uint8_t *source, uint8_t *dest, int nbytes);
|
||||||
void memory_set(uint8_t *dest, uint8_t val, uint32_t len);
|
void memory_set(uint8_t *dest, uint8_t val, uint32_t len);
|
||||||
|
|
||||||
/* At this stage there is no 'free' implemented. */
|
/* 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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user