experimental alternate memory allocation - page 6 - General Discussion and Assistance - CHDK Forum

experimental alternate memory allocation

  • 128 Replies
  • 54726 Views
Re: experimental alternate memory allocation
« Reply #50 on: 31 / January / 2011, 05:38:46 »
Advertisements
Wonder if umalloc can be used for script and file browser instead of malloc ?

EDIT:

I did that for gui_fselected_read_dir(),fselect_marked_copy_list() and script_load().

It did not crash but all keys (physw?)  disabled.

Had to remove battery.
« Last Edit: 31 / January / 2011, 05:57:40 by Microfunguy »

Re: experimental alternate memory allocation
« Reply #51 on: 31 / January / 2011, 10:00:24 »
@Microfunguy
>I did that for gui_fselected_read_dir(),fselect_marked_copy_list() and script_load().
>It did not crash but all keys (physw?)  disabled.

there must be something other wrong.As soon i enable opt  OPT_EXMEM_MALLOC in compiler new file get link, and i get same crash, even if i deactivate exmem init, on start.

void core_spytask() {

.......

#ifdef OPT_EXMEM_MALLOC
-       exmem_malloc_init();
+//   exmem_malloc_init();
#endif

please test with that testcode, if you too get crash when exmem_malloc_init is not call.i test this several time, so i am sure IX1000 crash have nothing to do with exmem.exmem file suba.c only show the problem.

I think you get too same crash when you do.With that code old memory alloc is used.
So i think the file browser have a random mem read bug, that is hidden all the time, but now that a new file is link, the problem is show.
« Last Edit: 31 / January / 2011, 10:05:02 by Bernd R »
Ixus 1000 HS

Re: experimental alternate memory allocation
« Reply #52 on: 31 / January / 2011, 10:20:14 »
With that disabled, I can open SCRIPTS directory but keyboard locks when I try to load file.

In File Browser, I can see subfolders but keyboard locks as soon as I choose a subfolder.


Re: experimental alternate memory allocation
« Reply #53 on: 31 / January / 2011, 10:39:01 »
>With that disabled, I can open SCRIPTS directory but keyboard locks when I try to load file.

so you have same problem here.

I test with GCC 4 now, and here load script work, but file browser crash. ;-)

I get it working by remove this lines

void *malloc(unsigned size) {
//   if(exmem_heap)
//      return suba_alloc(exmem_heap,size,0);
//   else
      return _malloc(size);
}

so it seem the C code do due to more variable use a register trash.
when you have exmem_init line disable and deactivate above lines, do this work too on your Cam ?


« Last Edit: 31 / January / 2011, 10:42:18 by Bernd R »
Ixus 1000 HS

Re: experimental alternate memory allocation
« Reply #54 on: 31 / January / 2011, 10:44:32 »
I have now disabled all the Exmem code, as far as I can tell and it still does not work !

The code is looking a mess, I will first get it working again without Exmem code.

At least I know it is not  my S95 SDM build that is causing the problem.



« Last Edit: 31 / January / 2011, 10:46:07 by Microfunguy »

Re: experimental alternate memory allocation
« Reply #55 on: 31 / January / 2011, 12:37:27 »
load script and file browser both crash !

Why does free(void *p) return a value ?

I thought it was good practice to set a pointer to NULL after using it with free().
« Last Edit: 31 / January / 2011, 13:18:01 by Microfunguy »

Re: experimental alternate memory allocation
« Reply #56 on: 31 / January / 2011, 13:15:36 »
>load script and file browser both crash !

this mean, when you have

#ifdef OPT_EXMEM_MALLOC
   //exmem_malloc_init();
#endif

and

when you have this code in wrapper.c it still crash ?


void *malloc(unsigned size) {
//   if(exmem_heap)
//      return suba_alloc(exmem_heap,size,0);
//   else
      return _malloc(size);
}

And when you then do this code, then it crash too ?

void free(void *p) {
//   if(exmem_heap && (p >= exmem_heap))
//      suba_free(exmem_heap,p);
//   else
      _free(p);
}

how many free mem does meminfo show ?
if then chdk not work, its really a file browser bug.seem then need add blink commands, to find the sourceline in file browser that do the crash.
Ixus 1000 HS

Re: experimental alternate memory allocation
« Reply #57 on: 31 / January / 2011, 13:21:26 »

> when you have this code in wrapper.c it still crash ?

No.

Quote
how many free mem does meminfo show ?

581,176

Also, see my comments above added while you were posting

With File Browser on the working version, I see this in root directory :-

CHDK/
DCIM/
DISKBOOT.BIN
DISKBOOT.B>   (my DISKBOOT.BIN.NG)

In the non-working version, I see :-

CHDK/
DCIM/

« Last Edit: 31 / January / 2011, 13:31:04 by Microfunguy »

Re: experimental alternate memory allocation
« Reply #58 on: 31 / January / 2011, 13:58:44 »

> when you have this code in wrapper.c it still crash ?

No.

Quote
how many free mem does meminfo show ?

581,176

Also, see my comments above added while you were posting.

so it seem confirm that with this code,

void *malloc(unsigned size) {
   if(exmem_heap)
      return suba_alloc(exmem_heap,size,0);
   else
      return _malloc(size);
}

register trash happen, because a simple

void *malloc(unsigned size) {
        return _malloc(size);
}

work ?

I test this code, but it still not work, really strange wy that not work.it should preserve all registers but i understand arm asm not much

void *malloc(unsigned size) {
unsigned long ret;
  ASM_SAFE_ENTER;
   if(exmem_heap)
   ret = suba_alloc(exmem_heap,size,0);
   else
      ret = _malloc(size);
   ASM_SAFE_LEAVE;
   return ret;
}

even if only _malloc is call a register trash happen.

I test also this version, when i have init exmem.but still crash on filebrowser

void *malloc(unsigned size) {
      return suba_alloc(exmem_heap,size,0);

}

there is a file asmsafe.h in chdk

see http://chdk.wikia.com/wiki/CHDK_Coding_Guidelines#Naked_functions
usage
    asm volatile (
        ...
        ASM_SAFE("BL my_func\n")
        ...
    )

you can set up arguments for the function inside the ASM_SAFE without worrying about preserving values
e.g
    ASM_SAFE(
        "MOV R0,#1\n"
        "BL my_func\n"
    )
*/

// push all regs except SP and PC
// push CSPR via R0
// restore value for R0 from stack
#define ASM_SAFE_ENTER \
    "STMFD SP!, {R0-R12,LR}\n" \
    "MRS R0, CPSR\n" \
    "STR R0,[SP,#-4]!\n" \
    "LDR R0,[SP,#4]\n"

// pop CSPR via R0
// pop all regs except SP and PC
#define ASM_SAFE_LEAVE \
    "LDR R0,[SP],#4\n" \
    "MSR CPSR_cxsf,R0\n" \
    "LDMFD SP!, {R0-R12,LR}\n"

#define ASM_SAFE(asmcode) \
    ASM_SAFE_ENTER \
    asmcode \
    ASM_SAFE_LEAVE
« Last Edit: 31 / January / 2011, 14:02:11 by Bernd R »
Ixus 1000 HS

Re: experimental alternate memory allocation
« Reply #59 on: 31 / January / 2011, 14:13:28 »
This seems to fix the situation with File Browser and Load Script when no Exmem allocated :-

Code: [Select]
#if defined(CAMERA_s95)
 void *mem_exmem_heap;

  // I set this up to 16 mb and it still booted...
  #define EXMEM_HEAP_SIZE (1024*1024*8)
  // these aren't currently needed elsewhere
 
  /*
  void * exmem_alloc(unsigned pool_id, unsigned size)
  {
          return _exmem_alloc(pool_id,size,0);
  }
 
  void exmem_free(unsigned pool_id)
  {
          _exmem_free(pool_id);
  }
  */

  static  void *exmem_heap=(void *)0;
  void *suba_init(void *heap, unsigned size, unsigned rst, unsigned mincell);
  void *suba_alloc(void *heap, unsigned size, unsigned zero);
  int suba_free(void *heap, void *p);
 
  void exmem_malloc_init()
            {
          // pool zero is EXMEM_RAMDISK on d10
          void *mem = _exmem_alloc(0,EXMEM_HEAP_SIZE,0);
          if(mem)
                     {
                      mem_exmem_heap = mem;
            exmem_heap = suba_init(mem,EXMEM_HEAP_SIZE,1,1024);
           }
  }
 
  void *malloc(unsigned size)
            {
          if(exmem_heap)
               return suba_alloc(exmem_heap,size,0);
          else
               return _malloc(size);
  }
 
  void free(void *p)
            {
          if(exmem_heap)
               suba_free(exmem_heap,p);
          else
                        {
               _free(p);
                         p=(void *)0;
                        }
                   
  }
  // regular malloc
  #else
     

void *malloc(long size)
{
    return _malloc(size);
}

void free(void *p)
{
    return _free(p);
}

  #endif


I changed :-

static  void *exmem_heap=(void *)0;    

and

      _free(p);
      p=(void *)0;

I have not tested if that last change required yet.
« Last Edit: 31 / January / 2011, 14:15:54 by Microfunguy »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal