diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/Tremor/oggmalloc.c rockbox.2/apps/codecs/Tremor/oggmalloc.c
--- rockbox.1/apps/codecs/Tremor/oggmalloc.c	1970-01-01 01:00:00.000000000 +0100
+++ rockbox.2/apps/codecs/Tremor/oggmalloc.c	2006-11-18 23:20:44.000000000 +0100
@@ -0,0 +1,90 @@
+#include <os_types.h>
+
+static unsigned char *mallocbuf;
+static long bufsize, tmp_ptr, mem_ptr;
+static long sum_used;
+
+void ogg_malloc_init(void)
+{
+    mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize);
+    tmp_ptr = bufsize & ~3;
+    mem_ptr = 0;
+    sum_used = 0;
+}
+
+void *ogg_malloc(size_t size)
+{
+    void* x;
+
+    if (mem_ptr + (long)size > tmp_ptr)
+        return NULL;
+    
+    sum_used += (size + 3) & ~3;
+    x = &mallocbuf[mem_ptr];
+    mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */
+
+    return x;
+}
+
+void *ogg_tmpmalloc(size_t size)
+{
+    if (mem_ptr + (long)size > tmp_ptr)
+        return NULL;
+    
+    sum_used += (size + 3) & ~3;
+    tmp_ptr -= (size + 3) & ~3;
+    return &mallocbuf[tmp_ptr];
+}
+
+void *ogg_calloc(size_t nmemb, size_t size)
+{
+    void *x;
+    x = ogg_malloc(nmemb * size);
+    if (x == NULL)
+        return NULL;
+    ci->memset(x, 0, nmemb * size);
+    return x;
+}
+
+void *ogg_tmpcalloc(size_t nmemb, size_t size)
+{
+    void *x;
+    x = ogg_tmpmalloc(nmemb * size);
+    if (x == NULL)
+        return NULL;
+    ci->memset(x, 0, nmemb * size);
+    return x;
+}
+
+void *ogg_realloc(void *ptr, size_t size)
+{
+    void *x;
+    (void)ptr;
+    x = ogg_malloc(size);
+    return x;
+}
+
+long ogg_tmpmalloc_pos(void)
+{
+    return tmp_ptr;
+}
+
+void ogg_tmpmalloc_free(long pos)
+{
+    tmp_ptr = pos;
+}
+
+long ogg_used_mem(void)
+{
+    return mem_ptr;
+}
+
+long ogg_used_tmp(void)
+{
+    return bufsize - tmp_ptr;
+}
+
+long ogg_used_sum(void)
+{
+    return sum_used;
+}
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/Tremor/os_types.h rockbox.2/apps/codecs/Tremor/os_types.h
--- rockbox.1/apps/codecs/Tremor/os_types.h	2006-11-18 23:10:04.000000000 +0100
+++ rockbox.2/apps/codecs/Tremor/os_types.h	2006-11-18 23:10:27.000000000 +0100
@@ -19,6 +19,9 @@
 #ifndef _OS_TYPES_H
 #define _OS_TYPES_H
 
+#include <stdlib.h>
+#include <codecs.h>
+
 #ifdef _LOW_ACCURACY_
 #  define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9))
 #  define LOOKUP_T const unsigned char  
@@ -29,10 +32,20 @@
 
 /* make it easy on the folks that want to compile the libs with a
    different malloc than stdlib */
-#define _ogg_malloc  malloc
-#define _ogg_calloc  calloc
-#define _ogg_realloc realloc
-#define _ogg_free    free
+
+#define _ogg_malloc  ogg_malloc
+#define _ogg_calloc  ogg_calloc
+#define _ogg_realloc ogg_realloc
+#define _ogg_free(x) do { } while(0)
+
+void ogg_malloc_init(void);
+void *ogg_malloc(size_t size);
+void *ogg_tmpmalloc(size_t size);
+void *ogg_calloc(size_t nmemb, size_t size);
+void *ogg_tmpcalloc(size_t nmemb, size_t size);
+void *ogg_realloc(void *ptr, size_t size);
+long ogg_tmpmalloc_pos(void);
+void ogg_tmpmalloc_free(long pos);
 
    typedef short ogg_int16_t;
    typedef int ogg_int32_t;
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/Tremor/sharedbook.c rockbox.2/apps/codecs/Tremor/sharedbook.c
--- rockbox.1/apps/codecs/Tremor/sharedbook.c	2006-11-18 23:10:04.000000000 +0100
+++ rockbox.2/apps/codecs/Tremor/sharedbook.c	2006-11-18 23:10:09.000000000 +0100
@@ -24,19 +24,6 @@
 #include "ivorbiscodec.h"
 #include "codebook.h"
 
-/* Size (in number of entries) for static buffers in book_init_decode, so
- * that large alloca() calls can be avoided, which is needed in Rockbox.
- * This is more than enough for one certain test file (which needs 6561 
- * entries)...
- */
-#define BOOK_INIT_MAXSIZE   8192
-
-/* Max value in static_codebook.dim we expect to find in _book_unquantize.
- * Used to avoid some temporary allocations. Again, enough for some test 
- * files...
- */
-#define BOOK_DIM_MAX        4
- 
 /**** pack/unpack helpers ******************************************/
 int _ilog(unsigned int v){
   int ret=0;
@@ -84,11 +71,7 @@
 ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
   long i,j,count=0;
   ogg_uint32_t marker[33];
-  /* Avoid temporary malloc; _make_words is only called from
-   * vorbis_book_init_decode, and the result is only used for a short while.
-   */
-  static ogg_uint32_t r[BOOK_INIT_MAXSIZE];
-  /* ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r)); */
+  ogg_uint32_t *r=(ogg_uint32_t *)ogg_tmpmalloc((sparsecount?sparsecount:n)*sizeof(*r));
   memset(marker,0,sizeof(marker));
 
   for(i=0;i<n;i++){
@@ -200,17 +183,12 @@
 			      int *maxpoint){
   long j,k,count=0;
   if(b->maptype==1 || b->maptype==2){
-    /* Static buffer to avoid temporary calloc, which Rockbox (currently) 
-     * doesn't handle well 
-     */
-    static int rp_buffer[BOOK_INIT_MAXSIZE*BOOK_DIM_MAX];
     int quantvals;
     int minpoint,delpoint;
     ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint);
     ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint);
     ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r));
-    /* int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); */
-    int* rp=rp_buffer;
+    int *rp=(int *)ogg_tmpcalloc(n*b->dim,sizeof(*rp));
 
     memset(rp, 0, n*b->dim*sizeof(*rp));
     *maxpoint=minpoint;
@@ -347,6 +325,7 @@
 int vorbis_book_init_decode(codebook *c,const static_codebook *s){
   int i,j,n=0,tabn;
   int *sortindex;
+  long pos = ogg_tmpmalloc_pos();
   memset(c,0,sizeof(*c));
   
   /* count actually used entries */
@@ -372,21 +351,11 @@
      by sorted bitreversed codeword to allow treeless decode. */
 
   {
-    /* Static buffers to avoid heavy stack usage */
-    static int sortindex_buffer[BOOK_INIT_MAXSIZE];
-    static ogg_uint32_t* codep_buffer[BOOK_INIT_MAXSIZE];
-
     /* perform sort */
     ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
-    /* ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n); */
-    ogg_uint32_t **codep=codep_buffer;
+    ogg_uint32_t **codep=(ogg_uint32_t **)ogg_tmpmalloc(sizeof(*codep)*n);
 
-    /* We have buffers for these sizes */
-    if ((n>BOOK_INIT_MAXSIZE) 
-      || (n*s->dim>BOOK_INIT_MAXSIZE*BOOK_DIM_MAX))
-      goto err_out;
-
-    if(codes==NULL)goto err_out;
+    if(codes==NULL||codep==NULL)goto err_out;
 
     for(i=0;i<n;i++){
       codes[i]=bitreverse(codes[i]);
@@ -395,8 +364,7 @@
 
     qsort(codep,n,sizeof(*codep),sort32a);
 
-    /* sortindex=(int *)alloca(n*sizeof(*sortindex)); */
-    sortindex=sortindex_buffer;
+    sortindex=(int *)ogg_tmpmalloc(n*sizeof(*sortindex));
     c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist));
     /* the index is a reverse index */
     for(i=0;i<n;i++){
@@ -468,9 +436,10 @@
     }
   }
   
-
+  ogg_tmpmalloc_free(pos);
   return(0);
  err_out:
+  ogg_tmpmalloc_free(pos);
   vorbis_book_clear(c);
   return(-1);
 }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/Tremor/SOURCES rockbox.2/apps/codecs/Tremor/SOURCES
--- rockbox.1/apps/codecs/Tremor/SOURCES	2006-11-18 23:10:04.000000000 +0100
+++ rockbox.2/apps/codecs/Tremor/SOURCES	2006-11-18 23:10:09.000000000 +0100
@@ -14,3 +14,4 @@
 vorbisfile.c
 window.c
 ctype.c
+oggmalloc.c
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/vorbis.c rockbox.2/apps/codecs/vorbis.c
--- rockbox.1/apps/codecs/vorbis.c	2006-11-18 23:10:04.000000000 +0100
+++ rockbox.2/apps/codecs/vorbis.c	2006-11-18 23:10:09.000000000 +0100
@@ -138,6 +138,7 @@
         error = CODEC_ERROR;
         goto exit;
     }
+    ogg_malloc_init();
 
     while (!*ci->taginfo_ready && !ci->stop_codec)
         ci->sleep(1);
Binary files rockbox.1/tools/bmp2rb and rockbox.2/tools/bmp2rb differ
Binary files rockbox.1/tools/codepages and rockbox.2/tools/codepages differ
Binary files rockbox.1/tools/convbdf and rockbox.2/tools/convbdf differ
Binary files rockbox.1/tools/rdf2binary and rockbox.2/tools/rdf2binary differ
