Question
Linux process generates "Segmentation fault (core dumped)"
Hi everyone,
I'm having the famous "Segmentation fault (core dumped)" error caused by the Linux application, but I can't find the bug.
const int NUM_ELEMENTS = 131072;
void process_receive (int chRPMSG) {
int i;
int data_buff_it = 0;
char msg_RPMSG[SIZE_MSG];
char* hex_string;
int hex_int;
while(1) {
if(read (chRPMSG, msg_RPMSG, SIZE_MSG) < 0) exit(0);
else {
hex_string = strtok(msg_RPMSG, " ");
hex_int = (int)strtol(hex_string, NULL, 16);
data_buff[data_buff_it] = hex_int;
data_buff_it = (data_buff_it + 1) % NUM_ELEMENTS;
for (i = 0; i < DATA_BUFFER - 1; i++) {
hex_string = strtok(NULL, " ");
hex_int = (int)strtol(hex_string, NULL, 16);
data_buff[data_buff_it] = hex_int;
data_buff_it = (data_buff_it + 1) % NUM_ELEMENTS;
}
}
}
}
int main (int argc, char **argv) {
int chRPMSG = open("/dev/ttyRPMSG0", O_RDWR | O_NOCTTY | O_SYNC);
if (chRPMSG < 0) {
int errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
perror("Error printed by perror");
fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
printf("Error: no se ha podido abrir ttyRPMSG0\n");
exit(0);
}
shm_id_buff = shmget(IPC_PRIVATE, NUM_ELEMENTS * sizeof(int), 0777 | IPC_CREAT);
if (fork() == 0) {
// This doesn't matter - is all commented
}
else {
setpriority(PRIO_PROCESS, 0, -15);
data_buff = (int *) shmat(shm_id_buff, 0, 0);
process_receive(chRPMSG);
//shmdt(data_buff);
//shmctl(shm_id_buff, IPC_RMID, 0);
}
return 0;
}This is quite weird, becuase the first execution on STM32MP157F MPU ends fine, however - and after reset - subsequent executions exit with core dumped. I'M GOING CRAZY!!!
Any idea about what is causing the error?
Please help,
Thanks
