Commit 1d21d757 authored by Adam Wujek's avatar Adam Wujek 💬

userspace: add version checking while opening hal's shm

Using not compatible versions of shm data can produce unpredictable results.
To be save always check version of shm after opening it.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 74270e76
......@@ -201,6 +201,13 @@ void init_shm(void)
fprintf(stderr, "unable to open shm for HAL!\n");
exit(-1);
}
/* check hal's shm version */
if (hal_head->version != HAL_SHMEM_VERSION) {
fprintf(stderr, "unknown hal's shm version %i (known is %i)\n",
hal_head->version, HAL_SHMEM_VERSION);
exit(-1);
}
h = (void *)hal_head + hal_head->data_off;
/* Assume number of ports does not change in runtime */
hal_nports_local = h->nports;
......
......@@ -139,6 +139,13 @@ int get_nports_from_hal(void)
fprintf(stderr, "unable to open shm for HAL!\n");
exit(-1);
}
/* check hal's shm version */
if (hal_head->version != HAL_SHMEM_VERSION) {
fprintf(stderr, "rtu_stat: unknown hal's shm version %i "
"(known is %i)\n",
hal_head->version, HAL_SHMEM_VERSION);
exit(-1);
}
h = (void *)hal_head + hal_head->data_off;
/* Assume number of ports does not change in runtime */
hal_nports_local = h->nports;
......
......@@ -54,6 +54,13 @@ void init_shm(void)
fprintf(stderr, "unable to open shm for HAL!\n");
exit(-1);
}
/* check hal's shm version */
if (hal_head->version != HAL_SHMEM_VERSION) {
fprintf(stderr, "wr_mon: unknown hal's shm version %i "
"(known is %i)\n",
hal_head->version, HAL_SHMEM_VERSION);
exit(-1);
}
h = (void *)hal_head + hal_head->data_off;
/* Assume number of ports does not change in runtime */
hal_nports_local = h->nports;
......
......@@ -67,6 +67,13 @@ int hal_shm_init(void)
"FATAL: wr_phytool unable to open shm to HAL.\n");
return -1;
}
/* check hal's shm version */
if (hal_head->version != HAL_SHMEM_VERSION) {
fprintf(stderr, "wr_mon: unknown hal's shm version %i "
"(known is %i)\n",
hal_head->version, HAL_SHMEM_VERSION);
return -1;
}
h = (void *)hal_head + hal_head->data_off;
......
......@@ -95,6 +95,14 @@ void init_shm(void)
sleep(1);
}
/* check hal's shm version */
if (hal_head->version != HAL_SHMEM_VERSION) {
fprintf(stderr, "rtu_drv: unknown hal's shm version %i "
"(known is %i)\n",
hal_head->version, HAL_SHMEM_VERSION);
exit(-1);
}
/* Even after HAL restart, HAL will place structures at the same
* addresses. No need to re-dereference pointer at each read. */
hal_ports = wrs_shm_follow(hal_head, h->ports);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment