FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / apps / codecs / libtremor / oggmalloc.c
blob6da7cfcedcad0abf89918a4bc937229eac0d9c55
1 #include "os_types.h"
3 #if defined(CPU_ARM) || defined(CPU_COLDFIRE)
4 #include <setjmp.h>
5 extern jmp_buf rb_jump_buf;
6 #endif
8 static size_t tmp_ptr;
10 void ogg_malloc_init(void)
12 mallocbuf = ci->codec_get_buffer(&bufsize);
13 tmp_ptr = bufsize & ~3;
14 mem_ptr = 0;
17 void *ogg_malloc(size_t size)
19 void* x;
21 size = (size + 3) & ~3;
23 if (mem_ptr + size > tmp_ptr)
24 #if defined(CPU_ARM) || defined(CPU_COLDFIRE)
25 longjmp(rb_jump_buf, 1);
26 #else
27 return NULL;
28 #endif
30 x = &mallocbuf[mem_ptr];
31 mem_ptr += size; /* Keep memory 32-bit aligned */
33 return x;
36 void *ogg_tmpmalloc(size_t size)
38 size = (size + 3) & ~3;
40 if (mem_ptr + size > tmp_ptr)
41 return NULL;
43 tmp_ptr -= size;
44 return &mallocbuf[tmp_ptr];
47 void *ogg_calloc(size_t nmemb, size_t size)
49 void *x;
50 x = ogg_malloc(nmemb * size);
51 if (x == NULL)
52 return NULL;
53 ci->memset(x, 0, nmemb * size);
54 return x;
57 void *ogg_tmpcalloc(size_t nmemb, size_t size)
59 void *x;
60 x = ogg_tmpmalloc(nmemb * size);
61 if (x == NULL)
62 return NULL;
63 ci->memset(x, 0, nmemb * size);
64 return x;
67 void *ogg_realloc(void *ptr, size_t size)
69 void *x;
70 (void)ptr;
71 x = ogg_malloc(size);
72 return x;
75 long ogg_tmpmalloc_pos(void)
77 return tmp_ptr;
80 void ogg_tmpmalloc_free(long pos)
82 tmp_ptr = pos;
85 /* Allocate IRAM buffer */
86 static unsigned char iram_buff[IRAM_IBSS_SIZE] IBSS_ATTR __attribute__ ((aligned (16)));
87 static size_t iram_remain;
89 void iram_malloc_init(void){
90 iram_remain=IRAM_IBSS_SIZE;
93 void *iram_malloc(size_t size){
94 void* x;
96 /* always ensure 16-byte aligned */
97 if(size&0x0f)
98 size=(size-(size&0x0f))+16;
100 if(size>iram_remain)
101 return NULL;
103 x = &iram_buff[IRAM_IBSS_SIZE-iram_remain];
104 iram_remain-=size;
106 return x;