i have a problem with my current project.
Here my header:
#define SHARED_MEMORY_NAME "/osmpmemory"
#define OSMP_MAX_MESSAGES_PROC 16
#define OSMP_MAX_SLOTS 256
#define OSMP_MAX_PAYLOAD_LENGTH 128
typedef struct {
char msg[OSMP_MAX_PAYLOAD_LENGTH];
} osmp_msg;
typedef struct {
size_t memory_size;
int process_count;
osmp_msg slots[OSMP_MAX_SLOTS];
} shm_conf;
And here my code:
shm_conf* memory_conf;
size_t shm_size = sizeof(shm_conf) + sizeof(int[count][2]) + sizeof(osmp_msg[count][OSMP_MAX_MESSAGES_PROC]);
int fd;
if((fd = shm_open(SHARED_MEMORY_NAME, O_CREAT | O_RDWR, 0640)) == -1) {
return -1;
}
if(ftruncate(fd, shm_size) == -1) {
printf("%s\n", strerror(errno));
return -1;
}
if((memory_conf = (shm_conf*)mmap(NULL, shm_size , PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
printf("%s\n", strerror(errno));
return 0;
}
memory_conf->process_count = count;
memory_conf->memory_size = shm_size;
int process_numbers[memory_conf->process_count][2];
for(int i = 0; i < memory_conf->process_count; i++) {
process_numbers[i][0] = 0;
process_numbers[i][1] = i;
}
memcpy(memory_conf + sizeof(shm_conf), process_numbers, sizeof(process_numbers));
I want to store a two dimensional array after the shm_conf struct. But memcpy gives me a segmentation fault and i don't know why, can you help me?
After this array i want store another array, this is why shm_size is bigger than i need currently.