コード例 #1
0
/* ARGSUSED - this line tells the compiler not to warn about unused args. */
Void * MEM_valloc(Int segid, size_t size, size_t align, Char val)
{
    Uns     alignSize;
    Uns     alignBytes;
    Uns     remainBytes;
    Void   *buf;
    Void   *alignBuf;
    Uns     tmpAlign;
    LgUns  *addrPtr;


    /*
     *  Must at least align on 32-bit boundary since we're storing the
     *  32-bit address of the malloc'd buffer.
     */
    alignBytes = (align < PTRSIZE) ? PTRSIZE : align;

    /* alignment must be a power of 2 */
    DBC_require((alignBytes & (alignBytes - 1)) == 0);

    /*
     *  We will allocate a buffer larger than "size", to allow for alignment
     *  and to hold the address of the buffer returned by malloc() at the
     *  end of the buffer.
     *  Make size a multiple of 32-bits so it will be easier to find the
     *  address of the buffer returned by malloc(). 
     */
    alignSize = size;
    if ((remainBytes = alignSize & (PTRSIZE - 1)) != 0) {
        /* size is not a multiple of 32-bits */
        alignSize += PTRSIZE - remainBytes;
        remainBytes = PTRSIZE - remainBytes;
    }

    /* Add 32-bits to store pointer of allocated buffer */
    alignSize += PTRSIZE;

    alignSize += alignBytes;
    buf = malloc(alignSize);

    tmpAlign = (Uns)buf & (alignBytes - 1);
    if (tmpAlign) {
        alignBuf = (Void *)((Uns)buf + alignBytes - tmpAlign);
    }
    else {
        alignBuf = buf;
    }

    /* Store the malloc'd address for freeing later. */
    addrPtr = (LgUns *)((LgUns)alignBuf + size + remainBytes);
    *addrPtr = (LgUns)buf;

    /* Initialize the aligned buffer with 'val' */
    memset(alignBuf, val, size);

    DBC_ensure(!((LgUns)alignBuf & (alignBytes - 1)));

    return (alignBuf);
}
コード例 #2
0
/*
 *  ======== DSPTOOL_TI_delete ========
 *  Ensures:   Failed:  returns RMS_EFREE: couldn't free context object; or
 *             Success: returns RMS_EOK and DSPTOOL_TI_Obj freed.
 */
RMS_STATUS DSPTOOL_TI_delete(NODE_EnvPtr node)
{
    DSPTOOL_TI_Obj  *dsptoolPtr;
    RMS_STATUS    retval = RMS_EOK;

    /* Dereference context structure stored in the node variable. */
    dsptoolPtr = node->moreEnv;

    if (dsptoolPtr != NULL) {

       /* We now have one less DSPTOOL node instance to kick around. */
       DSPTOOL_TI_instances--;

       /* Free DSPTOOL context structure. */
       if (!MEM_free(DSPTOOLMEMSEG, dsptoolPtr, sizeof(DSPTOOL_TI_Obj)))  {
            retval = RMS_EFREE;
       }
    }
    /* Assert Ensures */
    DBC_ensure((retval == RMS_EFREE) || (retval == RMS_EOK));

    return (retval);
}
コード例 #3
0
/*
 *  ======== _ACPY3_init ========
 *  Initialize the ACPY3 module
 */
static void _ACPY3_init(Void)
{

    if (refCount == 0) {

        GT_0trace(ti_sdo_fc_acpy3_GTMask, GT_ENTER, "_ACPY3_init > Enter\n");

#ifndef _ACPY3_CPUCOPY_
        _ACPY3_qdmaInit();
#endif

        initQdmaSettings();
     }
    else {
        GT_0trace(ti_sdo_fc_acpy3_GTMask, GT_ENTER, "_ACPY3_init > Enter\n");
    }

     /* count references even if no allocation is done */
     /* so that memory free is done only when last node requires ACPY3 */
    refCount++;

    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_ELEMENTSIZE,
                            ACPY3_PaRamRegs, acnt));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_NUMELEMENTS,
                            ACPY3_PaRamRegs, bcnt));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_ELEMENTINDEX_SRC,
                            ACPY3_PaRamRegs, srcElementIndex));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_ELEMENTINDEX_DST,
                            ACPY3_PaRamRegs, dstElementIndex));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_FRAMEINDEX_SRC,
                            ACPY3_PaRamRegs, srcFrameIndex));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_FRAMEINDEX_DST,
                            ACPY3_PaRamRegs, dstFrameIndex));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_NUMFRAMES,
                            ACPY3_PaRamRegs, ccnt));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_SRCADDR,
                            ACPY3_PaRamRegs, src));
    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_DSTADDR,
                            ACPY3_PaRamRegs, dst));

    DBC_ensure(verifyOffset(ACPY3_PARAMFIELD_ELEMENTSIZE,
                            ACPY3_PaRamRegs, acnt));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(ACPY3_PARAMFIELD_NUMELEMENTS,
                            ACPY3_PaRamRegs, bcnt));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(
            ACPY3_PARAMFIELD_ELEMENTINDEX_SRC, ACPY3_PaRamRegs, 
            srcElementIndex));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(
            ACPY3_PARAMFIELD_ELEMENTINDEX_DST, ACPY3_PaRamRegs, 
            dstElementIndex));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(
            ACPY3_PARAMFIELD_FRAMEINDEX_SRC, ACPY3_PaRamRegs, srcFrameIndex));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(
            ACPY3_PARAMFIELD_FRAMEINDEX_DST, ACPY3_PaRamRegs, dstFrameIndex));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(ACPY3_PARAMFIELD_NUMFRAMES,
            ACPY3_PaRamRegs, ccnt));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(ACPY3_PARAMFIELD_SRCADDR,
            ACPY3_PaRamRegs, src));
    GT_assert(ti_sdo_fc_acpy3_GTMask, verifyOffset(ACPY3_PARAMFIELD_DSTADDR,
            ACPY3_PaRamRegs, dst));

    GT_0trace(ti_sdo_fc_acpy3_GTMask, GT_ENTER, "_ACPY3_init > Exit\n");
}