pagefault.c
vmm/vmm.h
ubixos/sched.h
ubixos/kpanic.h
ubixos/spinlock.h
lib/kprintf.h
sys/thread.h
ubixos/kpanic.h
ubixos/sched.h
ubixos/spinlock.h
ubixos/types.h
sys/_types.h
vmm/paging.h
vfs/file.h
sys/tss.h
vmm/vmm.h
vfs/mount.h
lib/kprintf.h
ubixfs/dirCache.h
src/sys/vmm/pagefault.c
sys/sysproto.h
sys/signal.h
ubixos/tty.h
void void vmm_pageFault (uInt32 memAddr, uInt32 eip, uInt32 esp) vmm_pageFault uInt32 memAddr uInt32 eip uInt32 esp _current adjustCowCounter endTask taskStruct::id kpanic kprintf PAGE_COW PAGE_DEFAULT pageEntries pageFaultSpinLock parentPageDirAddr spinLock spinUnlock tablesBaseAddress taskStruct::td thread::vm_daddr thread::vm_dsize vmm_getPhysicalAddr vmmFindFreePage vmmGetFreeVirtualPage vmmUnmapPage x1 x1000
spinLock_t spinLock_t pageFaultSpinLock pageFaultSpinLock SPIN_LOCK_INITIALIZER vmm_pageFault

    /*****************************************************************************************
    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.

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

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

    #include<vmm/vmm.h>
    #include<ubixos/sched.h>
    #include<ubixos/kpanic.h>
    #include<ubixos/spinlock.h>
    #include<lib/kprintf.h>

    staticspinLock_tpageFaultSpinLock=SPIN_LOCK_INITIALIZER;

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

    Function:voidvmm_pageFault(uInt32memAddr,uInt32eip,uInt32esp);
    Description:Thisisthepagefaulthandler,itwillhandleCOWandtrapallother
    exceptionsandsegfaultthethread.

    Notes:

    07/30/02-FixedCOWHoweverINeedToThinkOfAWayToImpliment
    APagingSystemAlsoStartToAddSecurityLevels

    07/27/04-Addedspinlockingtoensurethatwearethreadsafe.Iknowthatspininga
    cpuisawasteofresourcesbutfornowitpreventserrors.

    *****************************************************************************************/
    voidvmm_pageFault(uInt32memAddr,uInt32eip,uInt32esp){
    uInt32i=0x0,pageTableIndex=0x0,pageDirectoryIndex=0x0;
    uInt32*pageDir=0x0,*pageTable=0x0;
    uInt32*src=0x0,*dst=0x0;

    /*Trytoaquirelockotherwisespintillwedo*/
    spinLock(&pageFaultSpinLock);

    /*Setpagedirpointertotheaddressofthevisablepagedirectory*/
    pageDir=(uInt32*)parentPageDirAddr;

    /*UBU-Thisisatemppanicfor0x0readwritelateronIwillhandlethisdifferently*/
    if(memAddr==0x0){
    kprintf("SegfaultAtAddress:[0x%X][0x%X][%i][0x%X]\n",memAddr,esp,_current->id,eip);
    kpanic("ErrorWeWroteTo0x0\n");
    }

    /*CalculateThePageDirectoryIndex*/
    pageDirectoryIndex=(memAddr>>22);

    /*CalculateThePageTableIndex*/
    pageTableIndex=((memAddr>>12)&0x3FF);

    /*UBU-Thisisatemporaryroutineforhandlingaccesstoapageofanonexistantpagetable*/
    if(pageDir[pageDirectoryIndex]==0x0){
    kprintf("SegfaultAtAddress:[0x%X][0x%X][%i][0x%X],NotAValidPageTable\n",memAddr,esp,_current->id,eip);
    spinUnlock(&pageFaultSpinLock);
    endTask(_current->id);
    }
    else{
    /*SetpageTableToPointToVirtualAddressOfPageTable*/
    pageTable=(uInt32*)(tablesBaseAddress+(0x1000*pageDirectoryIndex));

    /*TestifthisisaCOWonpage*/
    if(((uInt32)pageTable[pageTableIndex]&PAGE_COW)==PAGE_COW){
    /*SetSrcToBaseAddressOfPageToCopy*/
    src=(uInt32*)(memAddr&0xFFFFF000);
    /*AllocateAFreePageForDestination*/
    /*USEvmInfo*/
    dst=(uInt32*)vmmGetFreeVirtualPage(_current->id,1,0x1);
    /*CopyMemory*/
    for(i=0;i<pageEntries;i++){
    dst[i]=src[i];
    }
    /*AdjustTheCOWCounterForPhysicalPage*/
    adjustCowCounter(((uInt32)pageTable[pageTableIndex]&0xFFFFF000),-1);
    /*RemapInNewPage*/
    pageTable[pageTableIndex]=(uInt32)(vmm_getPhysicalAddr((uInt32)dst)|(memAddr&0xFFF));
    /*UnlinkFromMemoryMapAllocatedPage*/
    vmmUnmapPage((uInt32)dst,1);
    }
    elseif(pageTable[pageTableIndex]!=0x0){
    kprintf("Securityfailedpagetablenotuserpermission\n");
    kprintf("pageTable:[0x%X:0x%X:0x%X:0x%X]\n",pageTable[pageTableIndex],pageTableIndex,pageDirectoryIndex,eip);
    kprintf("SegfaultAtAddress:[0x%X][0x%X][%i][0x%X]NonMapped\n",memAddr,esp,_current->id,eip);
    spinUnlock(&pageFaultSpinLock);
    endTask(_current->id);
    }
    elseif(memAddr<(_current->td.vm_dsize+_current->td.vm_daddr)){
    pageTable[pageTableIndex]=(uInt32)vmmFindFreePage(_current->id)|PAGE_DEFAULT;
    }
    else{
    spinUnlock(&pageFaultSpinLock);
    /*NeedToCreateARoutineForAttemptingToAccessNonMappedMemory*/
    kprintf("SegfaultAtAddress:[0x%X][0x%X][%i][0x%X]NonMapped\n",memAddr,esp,_current->id,eip);
    kprintf("OutOfStackSpace:[0x%X]\n",memAddr&0xFF0000);
    spinUnlock(&pageFaultSpinLock);
    endTask(_current->id);
    }
    }
    asmvolatile(
    "movl%cr3,%eax\n"
    "movl%eax,%cr3\n"
    );

    /*Releasethespinlock*/
    spinUnlock(&pageFaultSpinLock);
    return;
    }

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

    Revision1.62006/12/0514:10:21reddawg
    WorkignDistro

    Revision1.52006/12/0105:12:35reddawg
    We'realmostthere...:)

    Revision1.42006/11/2113:25:49reddawg
    Ahandfulofchanges;)

    Revision1.32006/11/0619:10:12reddawg
    LotsOfUpdates...Stillhavingissueswithbrk();

    Revision1.22006/10/3120:44:19reddawg
    Lotsofchanges

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

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

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

    Revision1.142004/08/2522:02:41reddawg
    taskswitching-WenowareusingsoftwareswitchingtobeconsistantwiththerestoftheworldbecauseallofthisopensourcefreaksgavemeahardtimeaboutsomethingIliked.Theredoesn'tseemtobeanygaininperformancebutitisworkingfineandflawlessly

    Revision1.132004/08/2405:24:37reddawg
    TCAIsABONER!!!!

    Revision1.122004/08/1411:23:03reddawg
    Changes

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

    Revision1.102004/07/2800:22:56reddawg
    bah

    Revision1.92004/07/2800:17:05reddawg
    Major:
    Disconnectedpage0x0fromthesystem...Unfortunatelythisbrokemanythings
    allofwhichhavebeenfixed.ThiswasgoodbecausenothingdeferencesNULL
    anymore.

    Thingsaffected:
    malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file

    Revision1.82004/07/2707:09:38reddawg
    Putinatestfor0x0

    Revision1.72004/07/2619:15:49reddawg
    testcode,fixesandthelike

    Revision1.62004/07/2423:04:44reddawg
    Changes...markletmeknowifyoufaultatpid185whenyoutypestress

    Revision1.52004/07/2420:00:51reddawg
    Lotsofchangestothevmmsubsystem....Pagefaultshavebeenadjusttonowbeblockingonaperthreadbasisnotsystemwide.Thishasresultedinnomoredeadlocks..alsotheadditionofperthreadlockinghasremovedsegfaultsasaresultofCOWinwhichtwotasksfaultthesameCOWpageandtrytomodifyit.

    Revision1.42004/07/2417:47:28reddawg
    vmm_pageFault:deadlockresolvedthankstoaproppersolutionsuggestedbygeist

    Revision1.32004/07/1902:05:26reddawg
    vmmPageFault:hadapotentialmemoryleakhereforonepageitwasstillusingsysIDoncertainCOWscenarios

    Revision1.22004/06/1022:23:56reddawg
    Volatiles

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

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

    END
    ***/