ClRcT
cosSysvShmSecurityModeGet(ClOsalShmIdT shmId,ClUint32T* pMode)
{
    struct shmid_ds shmPerm ;
    ClInt32T retCode = CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pMode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    /* Get the current values set and modify it */
    retCode = shmctl ((int)shmId, IPC_STAT, &shmPerm);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_GET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    *pMode = shmPerm.shm_perm.mode;

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
Ejemplo n.º 2
0
ClRcT cosPosixProcessSharedSemInit(ClOsalMutexT *pMutex, ClUint8T *pKey, ClUint32T keyLen, ClInt32T value)
{
    ClRcT rc = CL_OK;
    int err;

    nullChkRet(pKey);
    if(keyLen == 0)
    {
        clDbgCodeError(CL_ERR_INVALID_PARAMETER,("Invalid keylen [%d]\n",keyLen));
        return CL_OSAL_RC(CL_ERR_INVALID_PARAMETER);
    }

    pthread_mutex_lock(&gClSemAccessLock);
    err = sem_init(&pMutex->shared_lock.sem.posSem,1, value);
    if(err < 0)
    {
        pthread_mutex_unlock(&gClSemAccessLock);
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        goto out;
    }
    pthread_mutex_unlock(&gClSemAccessLock);
    
    pMutex->shared_lock.sem.numSems = 1;
    rc = CL_OK;

out:
    return rc;
}
ClRcT
cosSysvShmSizeGet(ClOsalShmIdT shmId,ClUint32T* pSize)
{
    struct shmid_ds shmSize ;
    ClInt32T retCode = CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pSize)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    /* Get the current values set and modifiy it */
    retCode = shmctl ((int)shmId, IPC_STAT, &shmSize);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_SIZE);
        CL_FUNC_EXIT();
        return(retCode);
    }

    *pSize = (ClUint32T)shmSize.shm_segsz;

    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
cosSysvMutexValueSet(ClOsalMutexIdT mutexId, ClInt32T value)
{
    ClOsalMutexT *pMutex = (ClOsalMutexT *) mutexId;
    ClRcT rc = CL_OK;
    ClInt32T semId = pMutex->shared_lock.sem.semId;
    ClInt32T err = 0;
    CosSemCtl_t arg = {0};

    CL_FUNC_ENTER();

    if(value >= SEMVMX)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Error in setting sem value to [%d]\n", value));
        rc = CL_OSAL_RC(CL_ERR_INVALID_PARAMETER);
        goto out;
    }
    arg.val = value;
    err = semctl(semId, 0, SETVAL, arg);
    if(err < 0 )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Mutex value set- semctl error: [%s]\n", strerror(errno)));
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        goto out;
    }

    CL_FUNC_EXIT();
out:
    return rc;
}
ClRcT
cosSysvShmAttach(ClOsalShmIdT shmId,void* pInMem, void** ppOutMem)
{
    ClRcT retCode = 0;
    void* pShared = NULL;

    CL_FUNC_ENTER();
    if(NULL == ppOutMem)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Attach: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    pShared = shmat ((int)shmId, pInMem, 0);

    if((void*)-1 == pShared)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Attach: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_ATTACH);
        CL_FUNC_EXIT();
        return(retCode);
    }
    else
    {
        *ppOutMem = pShared;
    }

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Attach: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
cosSysvShmDetach(void* pMem)
{
    ClInt32T retCode =  CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pMem)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Detach: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    retCode = shmdt (pMem);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Detach: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_DETACH);
        CL_FUNC_EXIT();
        return(retCode);
    }

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Detach: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
Ejemplo n.º 7
0
ClRcT 
__cosPosixMutexLock (ClOsalMutexIdT mutexId, ClBoolT verbose)
{
    ClRcT rc = CL_OK;
    ClOsalMutexT *pMutex = (ClOsalMutexT*)mutexId;
    ClInt32T err=0;

    if(verbose)
    {
        nullChkRet(pMutex);
    }
    else if(!pMutex)
    {
        return CL_OSAL_RC(CL_ERR_NULL_POINTER);
    }

    CL_FUNC_ENTER();   
retry:
    err = sem_wait(&pMutex->shared_lock.sem.posSem);
    if(err < 0 )
    {
        if(errno == EINTR)
            goto retry;
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        if(verbose)
        {
            clDbgCodeError(rc,("sem_wait returned [%s]\n",strerror(errno)));
        }
    }

    CL_FUNC_EXIT();
    return (rc);
}
ClRcT cosSysvProcessSharedSemInit(ClOsalMutexT *pMutex, ClUint8T *pKey, ClUint32T keyLen, ClInt32T value)
{
    ClInt32T semId = 0;
    ClUint32T semKey = 0;
    ClRcT rc = CL_OK;
    ClUint32T flags = 0666;
    ClInt32T err = 0;

    nullChkRet(pKey);
    if(keyLen == 0)
    {
        clDbgCodeError(CL_ERR_INVALID_PARAMETER,("Invalid keylen [%d]\n",keyLen));
        return CL_OSAL_RC(CL_ERR_INVALID_PARAMETER);
    }

    rc = clCrc32bitCompute(pKey, keyLen, &semKey, NULL);
    CL_ASSERT(rc == CL_OK && semKey );

    pthread_mutex_lock(&gClSemAccessLock);
retry:
    semId = semget(semKey, 1, flags);
    if(semId < 0 )
    {
        if(errno == EINTR)
            goto retry;
        if(errno == ENOENT)
        {
            flags |= IPC_CREAT;
            goto retry;
        }
        pthread_mutex_unlock(&gClSemAccessLock);
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        goto out;
    }
    pthread_mutex_unlock(&gClSemAccessLock);
    if( (flags & IPC_CREAT) )
    {
        CosSemCtl_t arg = {0};
        arg.val = value;
retry1:
        err = semctl(semId,0,SETVAL,arg);
        if(err < 0 )
        {
            if(errno == EINTR)
                goto retry1;
            rc = CL_OSAL_RC(CL_ERR_LIBRARY);
            goto out;
        }
    }
    pMutex->shared_lock.sem.semId = semId;
    pMutex->shared_lock.sem.numSems = 1;
    rc = CL_OK;

out:
    return rc;
}
ClRcT
cosSysvSemCreate (ClUint8T* pName, ClUint32T count, ClOsalSemIdT* pSemId)
{
    ClInt32T retCode = CL_OK;
    CosSemCtl_t semArg = {0};
    ClUint32T len = 0;
    ClUint32T key = 0;
    ClInt32T semId = -1;

    nullChkRet(pSemId);
    nullChkRet(pName);

    CL_FUNC_ENTER();
    if ((count == 0) || count > CL_SEM_MAX_VALUE)
    {
        retCode = CL_OSAL_RC(CL_ERR_INVALID_PARAMETER);
        clDbgCodeError(retCode, ("Number of semaphores to create (count) [%d] must be between [1] and [%d]", count,  CL_SEM_MAX_VALUE));
        CL_FUNC_EXIT();
        return(retCode);
    }

    len = (ClUint32T)strlen ((ClCharT*)pName);

#if 0 /* Stone: why this limitation? */
    if(len > 20)
        if(len > 256)
        {
            CL_DEBUG_PRINT (CL_DEBUG_INFO,("Sanity check, semaphore name length is suspiciously long"));
            retCode = CL_OSAL_RC(CL_OSAL_ERR_NAME_TOO_LONG);
            CL_FUNC_EXIT();
            return(retCode);
        }
#endif

    if(len > 256)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("Sanity check, semaphore name [%s] is suspiciously long",pName));
    }

    retCode = (ClInt32T)clCrc32bitCompute (pName, len, &key, NULL);
    CL_ASSERT(retCode == CL_OK); /* There is no possible error except for pName == NULL, which I've already checked, so don't check the retCode */


    sysErrnoChkRet(semId = semget ((key_t)key, (int)count, IPC_CREAT|0666));

    semArg.val = (int)count;

    /* Initialize all the semaphores to 0.  This should never fail, because I just created the semaphores */
    sysErrnoChkRet(semctl (semId, 0, SETVAL, semArg));

    *pSemId = (ClOsalSemIdT)semId;

    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
cosSysvShmIdGet(ClUint8T* pName, ClOsalShmIdT* pShmId)
{
    ClUint32T key = 0;
    ClUint32T len = 0;
    ClUint32T size = 0;
    ClInt32T shmId = 0;
    ClRcT retCode = CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pShmId)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    if(NULL == pName)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    len = (ClUint32T)strlen ((ClCharT*)pName);

    retCode = clCrc32bitCompute (pName, len, &key, NULL);

    if(CL_OK != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_ID_GET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    shmId = shmget ((key_t)key, size, (0666 | IPC_CREAT));

    if(shmId < 0)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_ID_GET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    *pShmId = (ClOsalShmIdT)shmId;

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory ID Get: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
Ejemplo n.º 11
0
ClRcT
cosPosixSemCreate (ClUint8T* pName, ClUint32T count, ClOsalSemIdT* pSemId)
{
    ClInt32T rc = CL_OK;
    sem_t *pSem = NULL;
    ClInt32T semValue = 0;
    ClInt32T i = 0;
    
    nullChkRet(pSemId);
    nullChkRet(pName);

    CL_FUNC_ENTER();
    if ((count == 0) || count > CL_SEM_MAX_VALUE)
    {
        rc = CL_OSAL_RC(CL_ERR_INVALID_PARAMETER);
        clDbgCodeError(rc, ("Number of semaphores to create (count) [%d] must be between [1] and [%d]", count,  CL_SEM_MAX_VALUE));
        CL_FUNC_EXIT();
        return(rc);
    }

    pSem = sem_open((ClCharT*)pName, O_CREAT, 0777, count);
    if(pSem == SEM_FAILED)
    {
        rc = CL_OSAL_RC(CL_ERR_LIBRARY); 
        clDbgCodeError(rc, ("Failed at sem_open. system error code %d.\n", errno));
        return rc;
    }

    sem_getvalue(pSem, &semValue);

    if (semValue < (ClInt32T)count)
    {
        for (i = semValue; i < (ClInt32T)count; ++i)
        {
            sem_post(pSem);
        }
    }
    else
    {
        for (i = count; i < semValue; ++i)
        {
            sem_wait(pSem);
        }
    }

    *pSemId = *(ClOsalSemIdT*)&pSem;

    CL_FUNC_EXIT();
    return (rc);
}
ClRcT
cosSysvShmSecurityModeSet(ClOsalShmIdT shmId,ClUint32T mode)
{
    struct shmid_ds shmPerm ;
    ClInt32T retCode = CL_OK;

    CL_FUNC_ENTER();

    /* Basically we dont want to allow RWX on User,Group and others (Nothing
     * greater than 111 111 111 (0777). Eight is for calculating the number of
     * bytes.9 is the number of bits that will used for RWX RWX RWX for
     * User Group Others.
     */

    if(mode & (((~(1 << ((sizeof(int) *8)- 1))))<< 9))
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_SET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    /* Get the current values set and modify it */
    retCode = shmctl ((int)shmId, IPC_STAT, &shmPerm);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_SET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    shmPerm.shm_perm.mode = (unsigned short int)mode;

    retCode = shmctl ((int)shmId, IPC_SET, &shmPerm);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_SET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
__cosSysvMutexUnlock (ClOsalMutexIdT mutexId, ClBoolT verbose)
{
    ClRcT rc = CL_OK;
    ClOsalMutexT* pMutex = (ClOsalMutexT*) mutexId;
    static struct sembuf sembuf = {0, 1, SEM_UNDO };
    ClInt32T err = 0;

    CL_FUNC_ENTER();

retry:
    err = semop(pMutex->shared_lock.sem.semId,&sembuf,1);
    if(err < 0)
    {
        if(errno == EINTR)
        {
            goto retry;
        }
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        if(verbose)
        {
            clDbgCodeError(rc,("semop unlock returned [%s]\n",strerror(errno)));
        }
    }

    CL_FUNC_EXIT();
    return (rc);
}
Ejemplo n.º 14
0
ClRcT
cosPosixShmSizeGet(ClOsalShmIdT shmId,ClUint32T* pSize)
{
    ClRcT rc = CL_OSAL_RC(CL_ERR_NOT_SUPPORTED);
    clLogError(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED,"\nIn POSIX this operatoin is not supported. error code [0x%x].", rc);

    return rc; 
}
Ejemplo n.º 15
0
ClRcT
cosPosixShmDetach(void* pMem)
{
    ClRcT rc = CL_OSAL_RC(CL_ERR_NOT_SUPPORTED);
    clLogError(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED,"\nIn POSIX this operatoin is not supported. error code [0x%x].", rc);

    return rc; 
}
Ejemplo n.º 16
0
ClRcT
cosPosixMutexValueSet(ClOsalMutexIdT mutexId, ClInt32T value)
{
    ClRcT rc = CL_OSAL_RC(CL_ERR_NOT_SUPPORTED);
    
    CL_FUNC_ENTER();

    clDbgCodeError(rc, ("POSIX semaphores dont support setval operations\n"));

    CL_FUNC_EXIT();
    return rc;
}
Ejemplo n.º 17
0
ClRcT 
__cosPosixMutexUnlock (ClOsalMutexIdT mutexId, ClBoolT verbose)
{
    ClRcT rc = CL_OK;
    ClUint32T retCode = 0;
    ClOsalMutexT* pMutex = (ClOsalMutexT*) mutexId;
    ClInt32T err = 0;
   
    CL_FUNC_ENTER();
    
    if (NULL == pMutex)
	{
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        if(verbose)
        {
            clLogError(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED,"Mutex Unlock : FAILED, mutex is NULL (used after delete?)");
            clDbgPause();
        }
        CL_FUNC_EXIT();
        return(retCode);
	}

    retry:
    err = sem_post(&pMutex->shared_lock.sem.posSem);
    if(err < 0)
    {
        if(errno == EINTR)
        {
            goto retry;
        }
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        if(verbose)
        {
            clDbgCodeError(rc,("sem_post unlock returned [%s]\n",strerror(errno)));
        }
    }

    CL_FUNC_EXIT();
    return (rc);
}
Ejemplo n.º 18
0
ClRcT 
cosPosixMutexDestroy (ClOsalMutexT *pMutex)
{
    ClRcT rc = CL_OK;
    ClUint32T retCode = 0;
    CL_FUNC_ENTER();
    if (NULL == pMutex)
	{
        clLogError(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED,"Mutex Destroy failed, mutex is NULL (double delete?)");
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
	}

    ClInt32T err = sem_destroy(&pMutex->shared_lock.sem.posSem);
    if(err < 0 )
    {
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        clDbgCodeError(CL_ERR_LIBRARY,("sem_destroy() returned [%s]\n",strerror(errno)));
    }

    CL_FUNC_EXIT();
    return (rc);
}
Ejemplo n.º 19
0
ClRcT 
cosPosixMutexTryLock (ClOsalMutexIdT mutexId)
{
    ClOsalMutexT *pMutex = (ClOsalMutexT*)mutexId;
    ClInt32T err=0;

    if(!pMutex)
        return CL_OSAL_RC(CL_ERR_NULL_POINTER);

    CL_FUNC_ENTER();   
retry:
    err = sem_trywait(&pMutex->shared_lock.sem.posSem);
    if(err < 0 )
    {
        if(errno == EINTR)
            goto retry;
        if(errno == EAGAIN)
            return CL_OSAL_RC(CL_ERR_TRY_AGAIN);
        return CL_OSAL_RC(CL_ERR_LIBRARY);
    }

    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
cosSysvMutexDestroy (ClOsalMutexT *pMutex)
{
    ClRcT rc = CL_OK;
    ClInt32T err;
    CL_FUNC_ENTER();

    err = semctl(pMutex->shared_lock.sem.semId,0,IPC_RMID,0);
    if(err < 0 )
    {
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        clDbgCodeError(CL_ERR_LIBRARY,("semctl returned [%s]\n",strerror(errno)));
    }

    CL_FUNC_EXIT();
    return (rc);
}
ClRcT
cosSysvShmDelete(ClOsalShmIdT shmId)
{
    ClUint32T retCode = CL_OK;

    CL_FUNC_ENTER();
    retCode = (ClUint32T)(shmctl ((int)shmId, IPC_RMID, NULL));

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Delete: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_DELETE);
        CL_FUNC_EXIT();
        return(retCode);
    }

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Delete: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
Ejemplo n.º 22
0
ClRcT
cosPosixSemTryLock (ClOsalSemIdT semId)
{
    ClInt32T retCode = CL_OK;
    sem_t *pSem = *(sem_t**)&semId;
 
    CL_FUNC_ENTER();
    retCode = sem_trywait(pSem);
 
    if (-1 == retCode)
    {
      int err = errno;
      if (err == EAGAIN)
          return(CL_OSAL_RC(CL_OSAL_ERR_SEM_LOCK));  /* Taking the lock failed because the lock is taken by someone else */
      else
          sysRetErrChkRet(err);  /* Some unexpected error occurred */
    }
 
    CL_FUNC_EXIT();
    return (CL_OK);  /* It worked, lock was taken */
}
Ejemplo n.º 23
0
ClRcT
cosPosixMutexValueGet(ClOsalMutexIdT mutexId, ClInt32T *pValue)
{
    ClOsalMutexT *pMutex = (ClOsalMutexT*) mutexId;
    ClRcT rc = CL_OK;
    ClInt32T val = 0;
    
    nullChkRet(pMutex);
    CL_FUNC_ENTER();

    val = sem_getvalue(&pMutex->shared_lock.sem.posSem, pValue);
    if(val < 0 )
    {
        clLogError(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED,"Mutex value get- sem_getvalue() failed with [%s]\n", strerror(errno));
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
    }

    CL_FUNC_EXIT();

    return rc;
}
ClRcT
cosSysvSemTryLock (ClOsalSemIdT semId)
{
    ClInt32T retCode = CL_OK;
    struct sembuf semLock[] = {{0, -1, SEM_UNDO | IPC_NOWAIT}};

    CL_FUNC_ENTER();
    retCode = semop ((int)semId, semLock, 1);

    if (-1 == retCode)
    {
        int err = errno;
        if (err == EAGAIN) return(CL_OSAL_RC(CL_OSAL_ERR_SEM_LOCK));  /* Taking the lock failed because the lock is taken by someone else */
        else
        {
            sysRetErrChkRet(err);  /* Some unexpected error occurred */
        }
    }

    CL_FUNC_EXIT();
    return (CL_OK);  /* It worked, lock was taken */
}
ClRcT
cosSysvMutexValueGet(ClOsalMutexIdT mutexId, ClInt32T *pValue)
{
    ClOsalMutexT *pMutex = (ClOsalMutexT*) mutexId;
    ClRcT rc = CL_OK;
    ClInt32T val = 0;
    ClInt32T semId = pMutex->shared_lock.sem.semId;

    CL_FUNC_ENTER();

    val = semctl(semId, 0, GETVAL);
    if(val < 0 )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Mutex value get- semctl failed with [%s]\n", strerror(errno)));
        rc = CL_OSAL_RC(CL_ERR_LIBRARY);
        goto out;
    }
    *pValue = val;

    CL_FUNC_EXIT();

out:
    return rc;
}
ClRcT
cosSysvShmCreate(ClUint8T* pName, ClUint32T size, ClOsalShmIdT* pShmId)
{
    struct shmid_ds shmPerm ;
    ClInt32T retCode = CL_OK;
    ClUint32T len = 0;
    ClUint32T key = 0;
    ClInt32T shmId = -1;

    CL_FUNC_ENTER();

    if(NULL == pShmId)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Create: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    if(NULL == pName)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Create: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    len = (ClUint32T)strlen ((ClCharT*) pName);

    retCode = (ClInt32T)clCrc32bitCompute (pName, len, &key, NULL);

    if(CL_OK != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Create: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_CREATE);
        CL_FUNC_EXIT();
        return(retCode);
    }

    shmId = shmget ((key_t)key, size, (0666 | IPC_CREAT));

    if(shmId < 0)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Create: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_CREATE);
        CL_FUNC_EXIT();
        return(retCode);
    }


    retCode = shmctl (shmId, IPC_STAT, &shmPerm);

    if(0 != retCode)
    {
        retCode = shmctl (shmId, IPC_RMID, NULL);

        if(0 != retCode)
        {
            /*debug messages if any */
        }

        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Create: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_CREATE);
        CL_FUNC_EXIT();
        return(retCode);
    }

    shmPerm.shm_perm.uid = getuid();
    shmPerm.shm_perm.gid = getgid();

    retCode = shmctl (shmId, IPC_SET, &shmPerm);

    if(0 != retCode)
    {
        retCode = shmctl (shmId, IPC_RMID, NULL);

        if(0 != retCode)
        {
            /*debug messages if any */
        }

        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Create: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_CREATE);
        CL_FUNC_EXIT();
        return(retCode);
    }

    *pShmId = (ClOsalSemIdT)shmId;

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Create: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}