I'm trying to execute a bit bunch of pre-compiled binary on the device. The code seems like reads okay, and the content is correct as well, I've also move the memory to IRAM, which I think is executable. But the code crashes with InstrFetchProhibited, which is quite confusing here. What might be the cause of the error?
here's the code to load the binary
Code: Select all
void *data;
//size_t alloc;
//MP_PLAT_ALLOC_EXEC(len, &data, &alloc);
data = malloc(len);
read_bytes(reader, data, len);
void *iram_data = heap_caps_realloc(data,len,MALLOC_CAP_EXEC);
free(data);
char* entry = iram_data+28;
printf("func start %p from %p,content is ",entry,iram_data);
for(int i =0;i<10;i++)
{
printf("%02x ",*(entry+i));
}
and this is the crash info.
the location where it crashes PC seems exactly equals the location I realloc for execution, And this is the disassembly of the code where it starts.len number is 336
func start 0x3ffececc from 0x3ffeceb0,content is 36 41 00 38 02 a1 f7 ff 42 23 rc loaded 0x3f95bf30
point 1
point 2
point 3
point 4
point 5
Guru Meditation Error: Core 0 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x3ffececc PS : 0x00060630 A0 : 0x800dc6e0 A1 : 0x3ffc9130
A2 : 0x3f95be90 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x3ffececc A7 : 0x00000000 A8 : 0x800e02f5 A9 : 0x3ffc9110
A10 : 0x3f95bf00 A11 : 0x00000000 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000001a EXCCAUSE: 0x00000014
EXCVADDR: 0x3ffececc LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffe
Backtrace: 0x3ffececc:0x3ffc9130 0x400dc6dd:0x3ffc9160 0x400dc70a:0x3ffc9180 0x400e6e5f:0x3ffc91a0 0x400e6ed6:0x3ffc9230 0x400e722e:0x3ffc9260 0x400dd063:0x3ffc9340 0x400e9be8:0x3ffc9380 0x400e04f8:0x3ffc9420 0x400dc6dd:0x3ffc9480 0x400dc70a:0x3ffc94a0 0x40101c6e:0x3ffc94c0 0x40101eb0:0x3ffc9560 0x400ef635:0x3ffc95a0
Which I believe is the same with the code it loaded" func start 0x3ffececc from 0x3ffeceb0,content is 36 41 00 38 02 a1 f7 ff 42 23 rc loaded 0x3f95bf30"0000002c <init>:
2c: 004136 entry a1, 32
2f: 0238 l32i.n a3, a2, 0
31: fff7a1 l32r a10, 10 <header+0x10>
34: 2a2342 l32i a4, a3, 168
37: 1238 l32i.n a3, a2, 4
If there are any linker problem I would expect it crashes after the entrance of the function, but looks like it did crashes in before enter the function, what might be the cause here?