forked from PoliEcho-holding-org/kern
66 lines
1.7 KiB
Plaintext
66 lines
1.7 KiB
Plaintext
Memory Management
|
||
=================
|
||
|
||
Memory management is split into three layers: physical, virtual & the heap.
|
||
|
||
pmm.h
|
||
-----
|
||
The **physical memory manager** (PMM) is responsible for allocating physical
|
||
memory. It gives `pmm_*` functions. The `pmm_allocPage()` function allocates a
|
||
4kB page frame and retuns its **physical address**.
|
||
|
||
vmm.h
|
||
-----
|
||
The **virtual memory manager** (VMM) is responsible for allocating virtual
|
||
memory. It provides `vmm_*` functions. The `vmm_alloc()` function takes in a
|
||
number of 4kB pages to allocate and returns the **virtual address** of the
|
||
first page. Userspace can interface with the VMM using the `mmap()` and
|
||
`munmap()` syscalls.
|
||
|
||
kmalloc.h
|
||
---------
|
||
The `kmalloc.h` header provides memory management functions for kernel memory.
|
||
|
||
`void* kmalloc(size_t size)`
|
||
****************************
|
||
**Parameters**
|
||
* `size_t size` - Number of bytes to allocate
|
||
|
||
**Descriptions**
|
||
This function allocates `size` bytes of contiguous memory.
|
||
|
||
**Returns**
|
||
A pointer to allocated memory or NULL.
|
||
|
||
`void* kzalloc(size_t size)`
|
||
****************************
|
||
**Parameters**
|
||
* `size_t size` - Number of bytes to allocate
|
||
|
||
**Description**
|
||
This function allocates `size` bytes of contiguous, zeroed-out memory.
|
||
|
||
**Returns**
|
||
A pointer to allocated memory or NULL.
|
||
|
||
`void* kcalloc(size_t count, size_t size)`
|
||
******************************************
|
||
**Parameters**
|
||
* `size_t count` -
|
||
|
||
**Description**
|
||
This function allocates memory for `count` elements each of `size` bytes, zeroed-out memory.
|
||
|
||
**Returns**
|
||
A pointer to allocated memory or NULL.
|
||
|
||
`void* kfree(void* p)`
|
||
******************************************
|
||
**Parameters**
|
||
* `void* p` -
|
||
|
||
**Description**
|
||
This function frees memory previously allocated using `k[m,z,c]alloc()`
|
||
|
||
**Returns**
|
||
Nothing |