ChorusOS 4.0 Porting Guide

prstExtend() Routine

The prstExtend() routine can be used to allocate a new persistent memory device descriptor. Example 4-7 is the prstExtend() routine source code provided in kernel/snippet/nucleus/boot_tools/prstExtend.c.


Example 4-7 prstExtend() Routine

    void
prstExtend(PrstMem* pm, KnHotRebootReq* hreq)
{
    if (hreq->prstMemExtension) {
        if (pm->numChunks == pm->maxChunks) {
            printf ("Hot reboot can't allocate more than %d presistent "
                    "memory devices\n", pm->maxChunks);
        } else {
            int id_len = strlen(hreq->prstMemId) + 1;
            if (pm->curStrLen + id_len > pm->maxStrLen) {
                printf ("Hot reboot can't allocate more than %d bytes "
                        "for persistent memory device ids\n", 
                        pm->maxStrLen);
            } else {
                PrstChunk* ch_cur = pm->chunks+ pm->numChunks;
                ch_cur->status = 0;
                ch_cur->size = (PhSize) hreq->prstMemExtension;
                ch_cur->id = pm->str + pm->curStrLen;
                strcpy(ch_cur->id, hreq->prstMemId);
                pm->curStrLen += id_len;
                pm->numChunks += 1;
            }
        }
    }
}

The prstExtend() routine allocates the next available entry in the chunk array (the array is held within the persistent memory descriptor and is pointed to by the pm argument). The routine also copies the symbolic name of the new memory device from the caller address space into the str buffer (also held within the persistent memory descriptor). Note that the persistent memory descriptor is typically allocated within the reboot program data segment.