Turnstone Operating System
Loading...
Searching...
No Matches
memory.xx.c File Reference

main memory interface and functions implementation More...

#include <types.h>
#include <memory.h>
#include <cpu/task.h>
#include <cpu/sync.h>

Typedefs

typedef task_t *(* memory_current_task_getter_f) (void)
 
typedef void(* memory_backtrace_f) (void)
 

Functions

 MODULE ("turnstone.lib.memory")
 
void memory_set_current_task_getter (memory_current_task_getter_f getter)
 
static task_tmemory_get_current_task (void)
 
memory_heap_tmemory_set_default_heap (memory_heap_t *heap)
 sets default heap More...
 
memory_heap_tmemory_get_default_heap (void)
 
memory_heap_tmemory_get_heap (memory_heap_t *heap)
 returns heap, finds correct heap for task. More...
 
void * memory_malloc_ext (memory_heap_t *heap, size_t size, size_t align)
 malloc memory More...
 
int8_t memory_free_ext (memory_heap_t *heap, void *address)
 frees memory More...
 
void memory_get_heap_stat_ext (memory_heap_t *heap, memory_heap_stat_t *stat)
 returns stats for heap More...
 
int8_t memory_memset (void *address, uint8_t value, size_t size)
 sets memory with value More...
 
int8_t memory_memcopy (const void *source, void *destination, size_t size)
 copy source to destination with length bytes from source More...
 
int8_t memory_memcompare (const void *mem1, const void *mem2, size_t size)
 compares first length bytes of mem1 with mem2 More...
 
int8_t memory_memclean (void *address, size_t size)
 zeros memory More...
 
void memory_heap_backtrace (void)
 

Variables

memory_heap_tmemory_heap_default = NULL
 
memory_current_task_getter_f memory_current_task_getter = NULL
 
memory_backtrace_f memory_heap_backtrace_func = NULL
 

Detailed Description

main memory interface and functions implementation

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Function Documentation

◆ memory_free_ext()

int8_t memory_free_ext ( memory_heap_t heap,
void *  address 
)

frees memory

Parameters
[in]heapthe heap where the address is.
[in]addressaddress to free
Returns
0 if successed.

if heap is NULL, address will be freed at default heap

◆ memory_get_heap()

memory_heap_t * memory_get_heap ( memory_heap_t heap)

returns heap, finds correct heap for task.

Returns
correct heap for task

◆ memory_get_heap_stat_ext()

void memory_get_heap_stat_ext ( memory_heap_t heap,
memory_heap_stat_t stat 
)

returns stats for heap

Parameters
[in]heapheap which stats will be collected
[out]statreturned stats

◆ memory_malloc_ext()

void * memory_malloc_ext ( memory_heap_t heap,
size_t  size,
size_t  align 
)

malloc memory

Parameters
[in]heapthe heap used for malloc
[in]sizesize of variable
[in]alignaddress of variable aligned at.
Returns
address of variable

if heap is NULL, variable allocated at default heap.

◆ memory_memclean()

int8_t memory_memclean ( void *  address,
size_t  size 
)

zeros memory

Parameters
[in]athe address to be zerod.
[in]srepeat count
Returns
0

◆ memory_memcompare()

int8_t memory_memcompare ( const void *  mem1,
const void *  mem2,
size_t  size 
)

compares first length bytes of mem1 with mem2

Parameters
mem1first memory address
mem2second memory address
sizecount of bytes for compare
Returns
<0 if mem1>mem2, 0 if mem1=mem2, >0 if mem1>mem2

◆ memory_memcopy()

int8_t memory_memcopy ( const void *  source,
void *  destination,
size_t  size 
)

copy source to destination with length bytes from source

Parameters
[in]sourcesource address
[in]destinationdestination address
[in]sizehow many bytes will be copied
Returns
0

if destination is smaller then length a memory corruption will be happend

◆ memory_memset()

int8_t memory_memset ( void *  address,
uint8_t  value,
size_t  size 
)

sets memory with value

Parameters
[in]addressthe address to be setted.
[in]valuethe value
[in]sizerepeat count
Returns
0

◆ memory_set_default_heap()

memory_heap_t * memory_set_default_heap ( memory_heap_t heap)

sets default heap

Parameters
[in]heapthe heap will be the default one
Returns
old default heap

Variable Documentation

◆ memory_heap_default

memory_heap_t* memory_heap_default = NULL

default heap variable