51 lines
1.4 KiB
C
51 lines
1.4 KiB
C
#include "libnazgul.h"
|
|
|
|
void *msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex)
|
|
{
|
|
void *resultAddr;
|
|
int bufferSize, bufferNb;
|
|
int poolBufferTabFd;
|
|
msgPoolId poolBufferTabId;
|
|
printf("Mapping buffer (%d,%d)\n", poolIndex, bufferIndex);
|
|
// TODO: récuperer l'ID du BufferInfoTab;
|
|
strcpy(poolBufferTabId, poolDataTab[poolIndex].poolId);
|
|
bufferSize = poolDataTab[poolIndex].bufferSize;
|
|
bufferNb = poolDataTab[poolIndex].bufferNb;
|
|
if (bufferNb < 0) {
|
|
// do something with bufferNb
|
|
}
|
|
|
|
poolBufferTabFd = shm_open(poolBufferTabId, O_RDWR, SHM_DEFAULT_MODE);
|
|
if (poolBufferTabFd < 0) {
|
|
NZG_ERROR("shm_open", poolBufferTabId);
|
|
goto ERROR;
|
|
}
|
|
// mapper le buffer dans l'espace mémoire du processus
|
|
/* on s'arrete juste derriere l'index qui nous intéresse */
|
|
resultAddr = mmap(NULL, bufferSize * (bufferIndex + 1), PROT_READ | PROT_WRITE, //PROT_NONE
|
|
MAP_SHARED, poolBufferTabFd, (off_t) 0);
|
|
if (resultAddr == MAP_FAILED) {
|
|
NZG_ERROR("mmap", poolBufferTabId);
|
|
goto ERROR;
|
|
}
|
|
printf("Mapped from %p to %p\n",
|
|
(void *)resultAddr,
|
|
(void *)(resultAddr + bufferSize * (bufferIndex + 1))
|
|
);
|
|
|
|
resultAddr = resultAddr + (bufferSize * bufferIndex);
|
|
printf("Moved to %p\n", (void *)resultAddr);
|
|
|
|
/* mprotect(
|
|
resultAddr,
|
|
bufferSize,
|
|
PROT_READ|PROT_WRITE
|
|
); */
|
|
|
|
close(poolBufferTabFd);
|
|
|
|
return resultAddr;
|
|
ERROR:
|
|
return NULL;
|
|
}
|