version 1.13, 2025/04/16 17:36:12
|
version 1.15, 2025/05/09 19:44:50
|
Line 24
|
Line 24
|
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* |
* |
* $Log$ |
* $Log$ |
|
* Revision 1.15 2025/05/09 19:44:50 snw |
|
* Begin shm rework |
|
* |
|
* Revision 1.14 2025/05/08 14:47:26 snw |
|
* Break everything to begin shared memory rewrite |
|
* |
* Revision 1.13 2025/04/16 17:36:12 snw |
* Revision 1.13 2025/04/16 17:36:12 snw |
* Add FreeBSD shm cleanup script |
* Add FreeBSD shm cleanup script |
* |
* |
Line 184 short shm_init(const size_t seg_size)
|
Line 190 short shm_init(const size_t seg_size)
|
logprintf (FM_LOG_FATAL, "shm_init: could not attach to shared memory semaphore [%s]", strerror (errno)); |
logprintf (FM_LOG_FATAL, "shm_init: could not attach to shared memory semaphore [%s]", strerror (errno)); |
} |
} |
|
|
/* we are NOT the initial process. if addresses don't match, re-attach! */ |
|
/* (again, borrowed from RSM) */ |
|
if (shm_config->hdr->shmad != shm_config->dta) { |
|
|
|
/* grab the pointers we need */ |
|
void *old_addr = shm_config->dta; |
|
void *new_addr = shm_config->hdr->shmad; |
|
|
|
logprintf (FM_LOG_INFO, "shmmgr: remapping shared memory from virtual address %p to %p", old_addr, new_addr); |
|
|
|
/* detach and reattach */ |
|
if (shmdt (old_addr) == -1) { |
|
logprintf (FM_LOG_FATAL, "shm_init: detach failed during detach/reattach [shmdt error %s]", strerror (errno)); |
|
} |
|
|
|
if ((shm_config->dta = shmat (shm_config->seg_id, new_addr, 0)) == -1) { |
|
switch (errno) { |
|
|
|
case EINVAL: |
|
logprintf (FM_LOG_FATAL, "shm_init: shmat() failed; no matching shared memory segment exists or shared memory address invalid"); |
|
break; |
|
|
|
case ENOMEM: |
|
logprintf (FM_LOG_ERROR, "shm_init: shmat() failed; specified address cannot be used for mapping"); |
|
exit (1); |
|
break; |
|
|
|
case EMFILE: |
|
logprintf (FM_LOG_FATAL, "shm_init: shmat() failed; per-process shared memory segment limit reached; check kernel tuning parameters"); |
|
break; |
|
|
|
default: |
|
logprintf (FM_LOG_FATAL, "shm_init: shmat() failed; error code %d [%s]", errno, strerror (errno)); |
|
break; |
|
|
|
} |
|
} |
|
|
|
shm_config->hdr = (shm_hdr_t *) shm_config->dta; |
|
|
|
/* allocator buffer at the next page-aligned address after the header and allocation map */ |
shm_config->buf = SBM(SHMALIGN(SOM(shm_config->dta) + (sizeof (shm_hdr_t) * shm_config->pgct))); |
shm_config->buf = SHMALIGN(shm_config->dta + (sizeof (shm_hdr_t) * shm_config->pgct)); |
|
} |
|
else { |
|
shm_config->buf = SHMALIGN(shm_config->dta + (sizeof (shm_hdr_t) * shm_config->pgct)); |
|
} |
|
|
|
} |
} |
|
|