FrostWing
A lightweight raw-control operating system.
Loading...
Searching...
No Matches
memory.h File Reference

Custom memory manipulation functions. More...

#include <basics.h>
#include <limine.h>
Include dependency graph for memory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  memory_context

Functions

void * memcpy (void *dest, const void *src, size_t n)
 Copies a block of memory from a source location to a destination location.
void * memset (void *s, int c, size_t n)
 Sets a block of memory to a specified value.
void * memmove (void *dest, const void *src, size_t n)
 Copies a block of memory from a source location to a destination location, possibly overlapping.
int memcmp (const void *s1, const void *s2, size_t n)
 Compares two blocks of memory.
void memory_dump (const void *start, const void *end)
 Dump memory content from start to end.
void * allocate_memory_at_address (int64 phys_addr, size_t size)
 Allocates memory at an specific address.
void display_memory_formatted (struct memory_context *memory)
 Display the formatted memory context.
void analyze_memory_map (struct memory_context *memory, volatile struct limine_memmap_request memory_map_request)
 Reads the Limine memory map and saves to an usable context.
uint64_t getCR2 ()
 Returns the CR2 register.

Detailed Description

Custom memory manipulation functions.

This header file defines custom memory manipulation functions that are equivalent to the standard C library functions memcpy, memset, memmove, and memcmp.

Definition in file memory.h.

Function Documentation

◆ allocate_memory_at_address()

void * allocate_memory_at_address ( int64 phys_addr,
size_t size )

Allocates memory at an specific address.

Parameters
phys_addrPhysical address to allocate memory.
sizeSize of the memory to allocate.
Returns
Pointer to the allocated memory, or NULL if allocation fails.

◆ analyze_memory_map()

void analyze_memory_map ( struct memory_context * memory,
volatile struct limine_memmap_request memory_map_request )

Reads the Limine memory map and saves to an usable context.

Parameters
memoryThe memory context.
memory_map_requestLimine Memory Mam Request.

◆ display_memory_formatted()

void display_memory_formatted ( struct memory_context * memory)

Display the formatted memory context.

Parameters
memoryThe memory context to display.

◆ getCR2()

uint64_t getCR2 ( )

Returns the CR2 register.

Returns
uint64_t value of CR2.

◆ memcmp()

int memcmp ( const void * s1,
const void * s2,
size_t n )

Compares two blocks of memory.

This function compares the first 'n' bytes of memory in 's1' and 's2'.

Parameters
s1Pointer to the first memory location.
s2Pointer to the second memory location.
nNumber of bytes to compare.
Returns
0 if the memory blocks are equal, a negative value if 's1' is less than 's2, and a positive value if 's1' is greater than 's2'.

◆ memcpy()

void * memcpy ( void * dest,
const void * src,
size_t n )

Copies a block of memory from a source location to a destination location.

This function copies 'n' bytes of memory from 'src' to 'dest'. The source and destination memory areas should not overlap.

Parameters
destPointer to the destination memory location.
srcPointer to the source memory location.
nNumber of bytes to copy.
Returns
A pointer to the destination memory location 'dest'.

◆ memmove()

void * memmove ( void * dest,
const void * src,
size_t n )

Copies a block of memory from a source location to a destination location, possibly overlapping.

This function copies 'n' bytes of memory from 'src' to 'dest'. The source and destination memory areas may overlap. In such cases, it ensures the correct copy by choosing the appropriate copy direction.

Parameters
destPointer to the destination memory location.
srcPointer to the source memory location.
nNumber of bytes to copy.
Returns
A pointer to the destination memory location 'dest'.

◆ memory_dump()

void memory_dump ( const void * start,
const void * end )

Dump memory content from start to end.

This function iterates through the memory addresses from start to end and prints the address and corresponding value in hexadecimal format.

Parameters
startPointer to the start address of the memory to be dumped.
endPointer to the end address of the memory to be dumped.

◆ memset()

void * memset ( void * s,
int c,
size_t n )

Sets a block of memory to a specified value.

This function sets the first 'n' bytes of the memory block at 's' to the value 'c'.

Parameters
sPointer to the memory location.
cValue to set (as an integer).
nNumber of bytes to set.
Returns
A pointer to the memory location 's'.