52 lines
1.3 KiB
C
52 lines
1.3 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;
|
|
|
|
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 0x%08x to 0x%08x\n",
|
|
(int)resultAddr,
|
|
(int)resultAddr+ bufferSize*(bufferIndex+1)
|
|
);
|
|
|
|
resultAddr=resultAddr +( bufferSize*bufferIndex);
|
|
printf( "Moved to 0x%08x\n",(int)resultAddr );
|
|
|
|
/* mprotect(
|
|
resultAddr,
|
|
bufferSize,
|
|
PROT_READ|PROT_WRITE
|
|
);*/
|
|
|
|
close(poolBufferTabFd);
|
|
|
|
return resultAddr;
|
|
ERROR:
|
|
return NULL;
|
|
}
|