2008-11-20 11:27:31 +00:00
|
|
|
#include "os_types.h"
|
2012-03-27 14:27:02 +00:00
|
|
|
#include <tlsf.h>
|
2006-11-26 20:56:26 +00:00
|
|
|
|
2009-08-29 12:23:40 +00:00
|
|
|
#if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS)
|
2009-03-08 12:48:58 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
extern jmp_buf rb_jump_buf;
|
2009-08-29 12:23:40 +00:00
|
|
|
#define LONGJMP(x) longjmp(rb_jump_buf, x)
|
|
|
|
#elif defined(SIMULATOR)
|
|
|
|
#define LONGJMP(x) do { DEBUGF("Vorbis: allocation failed!\n"); return NULL; } while (false)
|
|
|
|
#else
|
|
|
|
#define LONGJMP(x) return NULL
|
2009-03-08 12:48:58 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-26 20:56:26 +00:00
|
|
|
void ogg_malloc_init(void)
|
|
|
|
{
|
2009-08-29 12:23:40 +00:00
|
|
|
size_t bufsize;
|
|
|
|
void* buf = ci->codec_get_buffer(&bufsize);
|
|
|
|
init_memory_pool(bufsize, buf);
|
2006-11-26 20:56:26 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 12:23:40 +00:00
|
|
|
void ogg_malloc_destroy()
|
2006-11-26 20:56:26 +00:00
|
|
|
{
|
2009-08-29 12:23:40 +00:00
|
|
|
size_t bufsize;
|
|
|
|
void* buf = ci->codec_get_buffer(&bufsize);
|
|
|
|
destroy_memory_pool(buf);
|
2006-11-26 20:56:26 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 12:23:40 +00:00
|
|
|
void *ogg_malloc(size_t size)
|
2006-11-26 20:56:26 +00:00
|
|
|
{
|
2009-08-29 12:23:40 +00:00
|
|
|
void* x = tlsf_malloc(size);
|
2007-11-08 08:55:01 +00:00
|
|
|
|
2009-08-29 12:23:40 +00:00
|
|
|
if (x == NULL)
|
|
|
|
LONGJMP(1);
|
2006-11-26 20:56:26 +00:00
|
|
|
|
2009-08-29 12:23:40 +00:00
|
|
|
return x;
|
2006-11-26 20:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *ogg_calloc(size_t nmemb, size_t size)
|
|
|
|
{
|
2009-08-29 12:23:40 +00:00
|
|
|
void *x = tlsf_calloc(nmemb, size);
|
2006-11-26 20:56:26 +00:00
|
|
|
|
|
|
|
if (x == NULL)
|
2009-08-29 12:23:40 +00:00
|
|
|
LONGJMP(1);
|
|
|
|
|
2006-11-26 20:56:26 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ogg_realloc(void *ptr, size_t size)
|
|
|
|
{
|
2009-08-29 12:23:40 +00:00
|
|
|
void *x = tlsf_realloc(ptr, size);
|
2006-11-26 20:56:26 +00:00
|
|
|
|
2009-08-29 12:23:40 +00:00
|
|
|
if (x == NULL)
|
|
|
|
LONGJMP(1);
|
|
|
|
|
|
|
|
return x;
|
2006-11-26 20:56:26 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 12:23:40 +00:00
|
|
|
void ogg_free(void* ptr)
|
2006-11-26 20:56:26 +00:00
|
|
|
{
|
2009-08-29 12:23:40 +00:00
|
|
|
tlsf_free(ptr);
|
2006-11-26 20:56:26 +00:00
|
|
|
}
|
2009-04-25 11:25:13 +00:00
|
|
|
|
2011-06-06 13:27:12 +00:00
|
|
|
#ifdef TREMOR_USE_IRAM
|
2009-04-25 11:25:13 +00:00
|
|
|
/* Allocate IRAM buffer */
|
2011-05-08 16:41:23 +00:00
|
|
|
static unsigned char iram_buff[IRAM_IBSS_SIZE] IBSS_ATTR MEM_ALIGN_ATTR;
|
2009-04-25 11:25:13 +00:00
|
|
|
static size_t iram_remain;
|
|
|
|
|
|
|
|
void iram_malloc_init(void){
|
|
|
|
iram_remain=IRAM_IBSS_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *iram_malloc(size_t size){
|
|
|
|
void* x;
|
2011-05-08 16:41:23 +00:00
|
|
|
|
|
|
|
/* always ensure alignment to CACHEALIGN_SIZE byte */
|
|
|
|
size = (size + (CACHEALIGN_SIZE-1)) & ~(CACHEALIGN_SIZE-1);
|
|
|
|
|
2009-04-25 11:25:13 +00:00
|
|
|
if(size>iram_remain)
|
|
|
|
return NULL;
|
2011-05-08 16:41:23 +00:00
|
|
|
|
2009-04-25 11:25:13 +00:00
|
|
|
x = &iram_buff[IRAM_IBSS_SIZE-iram_remain];
|
|
|
|
iram_remain-=size;
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
2011-06-06 13:27:12 +00:00
|
|
|
#endif
|