> when you have this code in wrapper.c it still crash ?
No.
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_functionsusage
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