c - Linked list issue with ARM processor -
i'm trying create linked list in c run on arm processor (not sure exact processor specs, -mcpu=arm7tdmi
passed compiler) using gcc. here's code:
#include <posapi.h> #include <posapi_all.h> const appinfo appinfo={ "pos-simple example", "app-test", "1.0", "pcteam", "demo program", "", 0, 0, 0, "" }; typedef struct st_dllnode { struct st_dllnode * next; struct st_dllnode * prev; void * data; } dllnode; typedef struct { dllnode* first; dllnode* cur; uchar size; } listcontainer; typedef listcontainer* list; list createlist(void) { list listcontainer; listcontainer = (list) malloc(sizeof(listcontainer)); listcontainer->first = null; listcontainer->cur = null; listcontainer->size = 0; // exception occurs here return listcontainer; } int event_main(st_event_msg *msg) { systeminit(); return 0; } int main(void) { list list; systeminit(); while (1) { list = createlist(); free(list); beep(); } }
for unknown reasons, execution of code stops on line marked, , device i'm using begins dumping exception message:
prefetchaborthandler:2007ffc4,aa...... (more addresses follows) prefetchabort addr: (another addr); status:02020a01
i have no idea why code runs fine in windows, when compiled arm, gives such error. ideas?
solution: try add 1 barrier() or similar macro function in code.
details:
list createlist(void) { list listcontainer; listcontainer = (list) malloc(sizeof(listcontainer)); smb(); // linux memory barrier api. replace os similar api listcontainer->first = null; listcontainer->cur = null; listcontainer->size = 0; // exception occurs here return listcontainer; }
reason: target arm processor may execute code out of order. listcontainer may not alloced successfully, "listcontainer->size = 0" executed first of all.
Comments
Post a Comment