-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmem.c
56 lines (44 loc) · 1.42 KB
/
mem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <sys/memory.h>
#include "mem.h"
#include "inc/vsh_exports.h"
static sys_memory_container_t mc_app = (sys_memory_container_t)-1;
static sys_addr_t heap_mem = 0;
static uint32_t prx_heap = 0;
/***********************************************************************
* create prx heap from memory container 1("app")
***********************************************************************/
int32_t create_heap(int32_t size)
{
mc_app = vsh_memory_container_by_id(1);
if (!mc_app) return(-1);
sys_memory_allocate_from_container(MB(size), mc_app, SYS_MEMORY_PAGE_SIZE_1M, &heap_mem);
if (!heap_mem) return(-1);
prx_heap = (uint32_t)heap_mem;
return(0);
}
/***********************************************************************
*
***********************************************************************/
void destroy_heap(void)
{
sys_memory_free((sys_addr_t)heap_mem);
prx_heap = 0;
mc_app = (sys_memory_container_t)-1;
}
/***********************************************************************
*
***********************************************************************/
void *mem_alloc(uint32_t size)
{
uint32_t add = prx_heap;
prx_heap += size;
return (void*)add;
}
/***********************************************************************
*
***********************************************************************/
int32_t mem_free(uint32_t size)
{
if(prx_heap>=size) prx_heap -= size; else return (-1);
return(0);
}