|
PatchworkOS
19e446b
A non-POSIX operating system.
|
Memory Descriptor List. More...
Memory Descriptor List.
The Memory Descriptor List (MDL) is a structure used to describe non-contiguous physical memory, allowing it be accessed as a single contiguous block regardless of the loaded address space.
The MDL structure is primarily used to describe memory regions for I/O operations. For example, if a process specifies a buffer to write to but that I/O operation is later completed while a different address space is loaded, the kernel would be unable to access the buffer directly.
Instead, the kernel can create an MDL for the buffer, which describes the physical memory pages backing that buffer, allowing the I/O operation to be completed regardless of the currently loaded address space.
Data Structures | |
| struct | mdl_seg_t |
| Memory Descriptor List Segment structure. More... | |
| struct | mdl_t |
| Memory Descriptor List structure. More... | |
| struct | mdl_iter_t |
| Memory Descriptor List Iterator structure. More... | |
Macros | |
| #define | MDL_SEGS_SMALL_MAX 2 |
| Amount of memory segments statically allocated for small MDLs. | |
| #define | MDL_ITER_CREATE(_mdl) |
| Create a Memory Descriptor List Iterator initializer. | |
| #define | MDL_FOR_EACH(_byte, _mdl) for (mdl_iter_t _iter = MDL_ITER_CREATE(_mdl); mdl_iter_next(&_iter, (_byte));) |
| Iterate over bytes within a Memory Descriptor List. | |
Functions | |
| static void | mdl_init (mdl_t *next, mdl_t *prev) |
| Initialize a Memory Descriptor List. | |
| void | mdl_deinit (mdl_t *mdl) |
| Deinitialize a Memory Descriptor List. | |
| void | mdl_free_chain (mdl_t *mdl, void(*free)(void *)) |
| Free a Memory Descriptor List chain. | |
| uint64_t | mdl_from_region (mdl_t *mdl, mdl_t *prev, space_t *space, const void *addr, size_t size) |
| Initialize a Memory Descriptor List from a memory region. | |
| uint64_t | mdl_add (mdl_t *mdl, space_t *space, const void *addr, size_t size) |
| Add a memory region to the Memory Descriptor List. | |
| uint64_t | mdl_read (mdl_t *mdl, void *buffer, size_t count, size_t offset) |
| Read from a Memory Descriptor List into a buffer. | |
| uint64_t | mdl_write (mdl_t *mdl, const void *buffer, size_t count, size_t offset) |
| Write to a Memory Descriptor List from a buffer. | |
| static bool | mdl_iter_next (mdl_iter_t *iter, uint8_t *byte) |
| Get the next byte from a Memory Descriptor List Iterator. | |
| #define MDL_SEGS_SMALL_MAX 2 |
| #define MDL_ITER_CREATE | ( | _mdl | ) |
| #define MDL_FOR_EACH | ( | _byte, | |
| _mdl | |||
| ) | for (mdl_iter_t _iter = MDL_ITER_CREATE(_mdl); mdl_iter_next(&_iter, (_byte));) |
| void mdl_deinit | ( | mdl_t * | mdl | ) |
| void mdl_free_chain | ( | mdl_t * | mdl, |
| void(*)(void *) | free | ||
| ) |
Free a Memory Descriptor List chain.
Will traverse the entire chain to deinitialize and free each MDL structure using the provided free function.
| mdl | Pointer to the first MDL in the chain. |
| free | Function to free the MDL structure itself, or NULL to only deinitialize. |
Definition at line 34 of file mdl.c.
| uint64_t mdl_from_region | ( | mdl_t * | mdl, |
| mdl_t * | prev, | ||
| space_t * | space, | ||
| const void * | addr, | ||
| size_t | size | ||
| ) |
Initialize a Memory Descriptor List from a memory region.
| mdl | Pointer to the MDL. |
| prev | Pointer to the previous MDL in the chain, or NULL if none. |
| space | The address space of the region. |
| addr | The virtual address of the memory region. |
| size | The size of the memory region in bytes. |
0. On failure, ERR and errno is set:mdl_add() for possible error codes. Definition at line 48 of file mdl.c.
Add a memory region to the Memory Descriptor List.
| mdl | Pointer to the MDL. |
| space | The address space of the user process. |
| addr | The virtual address of the memory region. |
| size | The size of the memory region in bytes. |
0. On failure, ERR and errno is set to:mdl_add() for possible error codes. Definition at line 125 of file mdl.c.
Read from a Memory Descriptor List into a buffer.
| mdl | The MDL to read from. |
| buffer | The buffer to read into. |
| count | Number of bytes to read. |
| offset | Offset within the MDL to start reading from. |
Definition at line 153 of file mdl.c.
Write to a Memory Descriptor List from a buffer.
| mdl | The MDL to write to. |
| buffer | The buffer to write from. |
| count | Number of bytes to write. |
| offset | Offset within the MDL to start writing to. |
Definition at line 192 of file mdl.c.
|
inlinestatic |