PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
Memory Descriptor List

Memory Descriptor List. More...

Collaboration diagram for Memory Descriptor List:

Detailed Description

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.

I/O Operations

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.
 

Macro Definition Documentation

◆ MDL_SEGS_SMALL_MAX

#define MDL_SEGS_SMALL_MAX   2

Amount of memory segments statically allocated for small MDLs.

Definition at line 37 of file mdl.h.

◆ MDL_ITER_CREATE

#define MDL_ITER_CREATE (   _mdl)
Value:
{ \
.mdl = (_mdl), \
.segIndex = 0, \
.segOffset = 0, \
}

Create a Memory Descriptor List Iterator initializer.

Parameters
_mdlPointer to the MDL to iterate over.
Returns
MDL Iterator initializer.

Definition at line 162 of file mdl.h.

◆ MDL_FOR_EACH

#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.

Parameters
_byteThe iterator variable.
_mdlPointer to the MDL.

Definition at line 203 of file mdl.h.

Function Documentation

◆ mdl_init()

static void mdl_init ( mdl_t next,
mdl_t prev 
)
inlinestatic

Initialize a Memory Descriptor List.

Parameters
nextPointer to the MDL.
prevPointer to the previous MDL in the chain, or NULL if none.

Definition at line 69 of file mdl.h.

Here is the caller graph for this function:

◆ mdl_deinit()

void mdl_deinit ( mdl_t mdl)

Deinitialize a Memory Descriptor List.

Parameters
mdlPointer to the MDL.

Definition at line 11 of file mdl.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mdl_free_chain()

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.

Parameters
mdlPointer to the first MDL in the chain.
freeFunction to free the MDL structure itself, or NULL to only deinitialize.

Definition at line 34 of file mdl.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mdl_from_region()

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.

Parameters
mdlPointer to the MDL.
prevPointer to the previous MDL in the chain, or NULL if none.
spaceThe address space of the region.
addrThe virtual address of the memory region.
sizeThe size of the memory region in bytes.
Returns
On success, 0. On failure, ERR and errno is set:

Definition at line 48 of file mdl.c.

Here is the call graph for this function:

◆ mdl_add()

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.

Parameters
mdlPointer to the MDL.
spaceThe address space of the user process.
addrThe virtual address of the memory region.
sizeThe size of the memory region in bytes.
Returns
On success, 0. On failure, ERR and errno is set to:

Definition at line 125 of file mdl.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mdl_read()

uint64_t mdl_read ( mdl_t mdl,
void *  buffer,
size_t  count,
size_t  offset 
)

Read from a Memory Descriptor List into a buffer.

Parameters
mdlThe MDL to read from.
bufferThe buffer to read into.
countNumber of bytes to read.
offsetOffset within the MDL to start reading from.
Returns
The number of bytes read.

Definition at line 153 of file mdl.c.

Here is the call graph for this function:

◆ mdl_write()

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.

Parameters
mdlThe MDL to write to.
bufferThe buffer to write from.
countNumber of bytes to write.
offsetOffset within the MDL to start writing to.
Returns
The number of bytes written.

Definition at line 192 of file mdl.c.

Here is the call graph for this function:

◆ mdl_iter_next()

static bool mdl_iter_next ( mdl_iter_t iter,
uint8_t byte 
)
inlinestatic

Get the next byte from a Memory Descriptor List Iterator.

Parameters
iterPointer to the MDL Iterator.
bytePointer to store the retrieved byte.
Returns
true if a byte was retrieved, false if the end of the MDL was reached.

Definition at line 176 of file mdl.h.