From d7030895abb1f8f7a04eac2680cd4cebc38e5ab8 Mon Sep 17 00:00:00 2001 From: glenux Date: Wed, 25 Feb 2004 07:38:25 +0000 Subject: [PATCH] *** empty log message *** --- src/allocate.c | 2 +- src/bufferMap.c | 56 +++++++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/allocate.c b/src/allocate.c index b37ac8a..cce3b92 100644 --- a/src/allocate.c +++ b/src/allocate.c @@ -189,7 +189,7 @@ void * msgAllocate(msgSpace *space, // on mappe la totalité du pool resultAddr = mmap( NULL, - bufferFreeSize, + bufferFreeSize*bufferNb, /* bufferFreeSize*/ PROT_NONE, //prot PROT_READ | PROT_WRITE MAP_SHARED, mSPoolFd, (off_t)0); diff --git a/src/bufferMap.c b/src/bufferMap.c index 419a649..d17c423 100644 --- a/src/bufferMap.c +++ b/src/bufferMap.c @@ -1,41 +1,47 @@ #include "libnazgul.h" -void * msgBufferMap(msgSpace * space, int poolIndex, int bufferIndex) { +void * msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex) { void * resultAddr; - int msPoolFd, buffersize; - - msgBufferInfoTabId bufferInfoTabId; - int bufferInfoTabFd; + int bufferSize, bufferNb; + int poolBufferTabFd; + msgPoolId poolBufferTabId; // TODO: récuperer l'ID du BufferInfoTab; - //strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + strcpy(poolBufferTabId, poolDataTab[poolIndex].poolId); + bufferSize=poolDataTab[poolIndex].bufferSize; + bufferNb=poolDataTab[poolIndex].bufferNb; - - bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); - if (bufferInfoTabFd<0){ - NZG_ERROR("sem_open",bufferInfoTabId); + poolBufferTabFd=shm_open(poolBufferTabId,O_RDWR,SHM_DEFAULT_MODE); + if (poolBufferTabFd<0){ + NZG_ERROR("shm_open",poolBufferTabId); goto ERROR; } - - - if(bufferInfoTabFd == -1) { - NZG_ERROR("shm_open", bufferInfoTabId); - goto ERROR; - } - // mapper le buffer dans l'espace mémoire du processus - resultAddr=mmap(NULL, buffersize, PROT_WRITE|PROT_READ, MAP_SHARED, msPoolFd, (off_t)0); - - // TODO: poolDataTabId + // 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_NONE, + MAP_SHARED, + poolBufferTabFd, + (off_t)0); if(resultAddr == MAP_FAILED) { - //NZG_ERROR("mmap", poolDataTabId); - goto ERROR; + NZG_ERROR("mmap", poolBufferTabId); + goto ERROR; } - close(msPoolFd); - + resultAddr=resultAddr +( bufferSize*bufferIndex); + + mprotect( + resultAddr, + bufferSize, + PROT_READ|PROT_WRITE + ); + + close(poolBufferTabFd); + return resultAddr; ERROR: - return NULL; + return NULL; }