2004-02-24 21:48:30 +00:00
|
|
|
|
#include "libnazgul.h"
|
|
|
|
|
|
|
|
|
|
|
2004-02-25 07:38:25 +00:00
|
|
|
|
void * msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex) {
|
2004-02-25 08:13:28 +00:00
|
|
|
|
void * resultAddr;
|
|
|
|
|
int bufferSize, bufferNb;
|
|
|
|
|
int poolBufferTabFd;
|
|
|
|
|
msgPoolId poolBufferTabId;
|
|
|
|
|
printf("Mapping buffer (%d,%d)\n",poolIndex,bufferIndex);
|
2004-02-24 21:48:30 +00:00
|
|
|
|
// TODO: r<>cuperer l'ID du BufferInfoTab;
|
2004-02-25 07:38:25 +00:00
|
|
|
|
strcpy(poolBufferTabId, poolDataTab[poolIndex].poolId);
|
|
|
|
|
bufferSize=poolDataTab[poolIndex].bufferSize;
|
|
|
|
|
bufferNb=poolDataTab[poolIndex].bufferNb;
|
2004-02-24 21:48:30 +00:00
|
|
|
|
|
2004-02-25 07:38:25 +00:00
|
|
|
|
poolBufferTabFd=shm_open(poolBufferTabId,O_RDWR,SHM_DEFAULT_MODE);
|
|
|
|
|
if (poolBufferTabFd<0){
|
|
|
|
|
NZG_ERROR("shm_open",poolBufferTabId);
|
2004-02-24 22:04:50 +00:00
|
|
|
|
goto ERROR;
|
2004-02-24 21:48:30 +00:00
|
|
|
|
}
|
2004-02-25 08:13:28 +00:00
|
|
|
|
|
2004-02-25 07:38:25 +00:00
|
|
|
|
// mapper le buffer dans l'espace m<>moire du processus
|
|
|
|
|
/* on s'arrete juste derriere l'index qui nous int<6E>resse */
|
|
|
|
|
resultAddr=mmap(NULL,
|
2004-02-25 08:13:28 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2004-02-25 08:28:20 +00:00
|
|
|
|
printf( "Mapped from 0x%08x to 0x%08x\n",
|
2004-02-25 08:13:28 +00:00
|
|
|
|
(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;
|
2004-02-24 21:48:30 +00:00
|
|
|
|
ERROR:
|
2004-02-25 08:13:28 +00:00
|
|
|
|
return NULL;
|
2004-02-24 21:48:30 +00:00
|
|
|
|
}
|