createvirtualspace.c
vmm/vmm.h
sys/thread.h
ubixos/types.h
sys/_types.h
vmm/paging.h
src/sys/vmm/createvirtualspace.c
vmm/vmm.h
sys/sysproto.h
sys/signal.h
void * void* vmmCreateVirtualSpace (pid_t pid) vmmCreateVirtualSpace pid_t pid PAGE_DEFAULT pageEntries parentPageDirAddr tablesBaseAddress vmm_getPhysicalAddr vmmGetFreePage vmmUnmapPage execFile

    /*****************************************************************************************
    Copyright(c)2002TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Log: createvirtualspace_8c.xml,v $
    Revision 1.6  2006/12/19 14:12:50  reddawg
    rtld-elf almost workign

    Revision1.1.1.12006/06/0112:46:13reddawg
    ubix2

    Revision1.22005/10/1200:13:38reddawg
    Removed

    Revision1.1.1.12005/09/2617:24:50reddawg
    nomessage

    Revision1.22004/07/2815:05:43reddawg
    Major:
    Pagesnowhavestrictsecurityenforcement.
    Manynulldereferenceshavebeenresolved.
    Whenappsloadedpermissionssetforpagesrwandro

    Revision1.1.1.12004/04/1512:06:51reddawg
    UbixOSv1.0

    Revision1.82004/04/1316:36:34reddawg
    Changedourcopyright,itisallnowunderaBSD-Stylelicense

    $Id: createvirtualspace_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<vmm/vmm.h>

    /************************************************************************

    Function:void*vmmCreateVirtualSpace(pid_t);
    Description:CreatesAVirtualSpaceForANewTask
    Notes:

    07/30/02-ThisIsGoingToCreateANewVMSpaceHoweverItsGoingTo
    ShareTheSameTop1GBSpaceWithTheKernelsVMAndLower
    1MBOfVMSpaceWithTheKernel

    07/30/02-NoteThisIsGoingToGetTheTop1GigAndLower1MBRegion
    FromTheCurrentlyLoadedPageDirectoryThisIsSafeBecause
    AllVMSpacesWillShareTheseRegions

    07/30/02-NoteIRealizedAMistakeTheFirstPageTableWillNeedToBe
    ACopyButThePageTablesForTheTop1GBWillNotReasonFor
    ThisIsThatWeJustShareTheFirst1MBInTheFirstPageTable
    SoWeWillJustSharePhysicalPages.

    08/02/02-AddedPassingOfpid_tpidForBetterTrackingOfWhoHasWhich
    SetOfPages

    ************************************************************************/
    void*
    vmmCreateVirtualSpace(pid_tpid)
    {
    void*newPageDirectoryAddress=0x0;
    uInt32*parentPageDirectory=0x0,*newPageDirectory=0x0;
    uInt32*parentPageTable=0x0,*newPageTable=0x0;
    intx=0;

    /*SetAddressOfParentPageDirectory*/
    parentPageDirectory=(uInt32*)parentPageDirAddr;
    /*AllocateANewPageForTheNewPageDirectory*/
    newPageDirectory=(uInt32*)vmmGetFreePage(pid);
    /*SetnewPageDirectoryAddressToTheNewlyCreatedPageDirectoriesPage*/
    newPageDirectoryAddress=(void*)vmm_getPhysicalAddr((uInt32)newPageDirectory);
    /*FirstSetUpAFlushedPageDirectory*/
    for(x=0;x<pageEntries;x++){
    (uInt32)newPageDirectory[x]=(uInt32)0x0;
    }
    /*MapTheTop1GBRegionOfTheVMSpace*/
    for(x=768;x<pageEntries;x++){
    newPageDirectory[x]=parentPageDirectory[x];
    }
    /*
    *AllocateANewPageForTheTheFirstPageTableWhereWeWillMapThe
    *LowerRegion
    */
    newPageTable=(uInt32*)vmmGetFreePage(pid);
    /*FlushThePageFromGarbageInMemory*/
    for(x=0;x<pageEntries;x++){
    (uInt32)newPageTable[x]=(uInt32)0x0;
    }
    /*MapThisIntoThePageDirectory*/
    newPageDirectory[0]=(vmm_getPhysicalAddr((uInt32)newPageTable)|PAGE_DEFAULT);
    /*SetAddressOfParentsPageTable*/
    parentPageTable=(uInt32*)tablesBaseAddress;
    /*MapTheFirst1MBWorthOfPages*/
    for(x=0;x<(pageEntries/4);x++){
    newPageTable[x]=parentPageTable[x];
    }
    /*SetVirtualMappingForPageDirectory*/
    newPageTable[256]=(vmm_getPhysicalAddr((uInt32)newPageDirectory)|PAGE_DEFAULT);

    /*
    *NowTheFunStuffBuildTheInitialVirtualPageSpaceSoWeDon'tHave
    *ToWorryAboutMappingThemInLaterHowEverI'mConcernedThisMay
    *BecomeASecurityIssue
    */
    /*FirstLetsUnmapThePreviouslyAllocatedPageTable*/
    vmmUnmapPage((uInt32)newPageTable,1);
    /*AllocateANewPageTable*/
    newPageTable=(uInt32*)vmmGetFreePage(pid);
    /*FirstSetOurPageDirectoryToContainThis*/
    newPageDirectory[767]=vmm_getPhysicalAddr((uInt32)newPageTable)|PAGE_DEFAULT;
    /*NowLetsBuildThePageTable*/
    for(x=0;x<pageEntries;x++){
    newPageTable[x]=newPageDirectory[x];
    }
    /*NowWeAreDoneSoLetsUnmapThisPage*/
    vmmUnmapPage((uInt32)newPageTable,1);
    /*NowWeAreDoneWithThePageDirectorySoLetsUnmapThatToo*/
    vmmUnmapPage((uInt32)newPageDirectory,1);
    /*ReturnPhysicalAddressOfPageDirectory*/
    return(newPageDirectoryAddress);
    }

    /***
    END
    ***/