paging.c
vmm/vmm.h
lib/kprintf.h
lib/kmalloc.h
ubixos/types.h
ubixos/kpanic.h
ubixos/sched.h
ubixos/spinlock.h
string.h
assert.h
sys/thread.h
ubixos/kpanic.h
ubixos/sched.h
ubixos/spinlock.h
src/sys/vmm/paging.c
ubixos/types.h
sys/_types.h
vmm/paging.h
string.h
vfs/file.h
sys/tss.h
lib/kmalloc.h
vmm/vmm.h
vfs/mount.h
lib/kprintf.h
assert.h
ubixfs/dirCache.h
sys/sysproto.h
sys/signal.h
ubixos/tty.h
int int mmap (struct thread *td, struct mmap_args *uap) mmap struct thread * td struct mmap_args * uap _current mmap_args::addr mmap_args::fd mmap_args::flags taskStruct::id kprintf mmap_args::len mmap_args::pad mmap_args::pos mmap_args::prot thread::td_retval VM_TASK vmmGetFreeVirtualPage x1000
int int munmap (struct thread *td, struct munmap_args *uap) munmap struct thread * td struct munmap_args * uap kprintf
int int obreak (struct thread *td, struct obreak_args *uap) obreak struct thread * td struct obreak_args * uap _current btoc ctob taskStruct::id K_PANIC kprintf obreak_args::nsize PAGE_DEFAULT round_page thread::vm_daddr thread::vm_dsize vmm_remapPage vmmFindFreePage
int int vmm_cleanVirtualSpace (uint32_t addr) vmm_cleanVirtualSpace uint32_t addr kprintf PAGE_COW PAGE_PRESENT PAGE_STACK parentPageDirAddr tablesBaseAddress x1000 sysExec
void * void* vmm_getFreeMallocPage (uInt16 count) vmm_getFreeMallocPage uInt16 count fkpSpinLock K_PANIC KERNEL_PAGE_DEFAULT spinLock spinUnlock sysID tablesBaseAddress vmm_remapPage vmmClearVirtualPage vmmFindFreePage x1000 getEmptyDesc
int int vmm_pagingInit () vmm_pagingInit _vmm_pageFault K_PANIC KERNEL_PAGE_DEFAULT kernelPageDirectory kprintf memset numPages pageEntries sysID vmm_remapPage vmmFindFreePage vmmMemoryMap vmmMemoryMapAddr x1 x1000 vmm_init
int int vmm_remapPage (uInt32 source, uInt32 dest, uInt16 perms) vmm_remapPage uInt32 source uInt32 dest uInt16 perms _current freePage taskStruct::id K_PANIC KERNEL_PAGE_DEFAULT kprintf PAGE_COW PAGE_DEFAULT PAGE_PRESENT PAGE_STACK pageEntries parentPageDirAddr rmpSpinLock spinLock spinUnlock tablesBaseAddress vmmFindFreePage x1000 elf_loadfile execFile kmod_load ldEnable obreak sys_exec sysExec vmm_getFreeMallocPage vmm_pagingInit vmmGetFreeKernelPage vmmGetFreePage vmmGetFreeVirtualPage vmmMapFromTask
int int vmmClearVirtualPage (uInt32 pageAddr) vmmClearVirtualPage uInt32 pageAddr pageEntries vmm_getFreeMallocPage vmmGetFreeKernelPage vmmGetFreePage vmmGetFreeVirtualPage
void * void* vmmGetFreeKernelPage (pidType pid, uInt16 count) vmmGetFreeKernelPage pidType pid uInt16 count fkpSpinLock K_PANIC KERNEL_PAGE_DEFAULT spinLock spinUnlock tablesBaseAddress vmm_remapPage vmmClearVirtualPage vmmFindFreePage vmmCopyVirtualSpace
void * void* vmmMapFromTask (pidType pid, void *ptr, uInt32 size) vmmMapFromTask pidType pid void * ptr uInt32 size _current tssStruct::cr3 K_PANIC KERNEL_PAGE_DEFAULT taskStruct::oInfo schedFindTask tablesBaseAddress taskStruct::tss vmm_remapPage vmmUnmapPage osInfo::vmStart x1000
spinLock_t spinLock_t fkpSpinLock fkpSpinLock SPIN_LOCK_INITIALIZER vmm_getFreeMallocPage vmmGetFreeKernelPage
uInt32 * uInt32* kernelPageDirectory kernelPageDirectory 0x0 _int8 execFile execThread idt_init vmm_pagingInit
spinLock_t spinLock_t rmpSpinLock rmpSpinLock SPIN_LOCK_INITIALIZER vmm_remapPage

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    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: paging_8c.xml 88 2016-01-12 00:11:29Z reddawg $

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

    #include<vmm/vmm.h>
    #include<lib/kprintf.h>
    #include<lib/kmalloc.h>
    #include<ubixos/types.h>
    #include<ubixos/kpanic.h>
    #include<ubixos/sched.h>
    #include<ubixos/spinlock.h>
    #include<string.h>
    #include<assert.h>

    uInt32*kernelPageDirectory=0x0;

    staticspinLock_tfkpSpinLock=SPIN_LOCK_INITIALIZER;
    staticspinLock_trmpSpinLock=SPIN_LOCK_INITIALIZER;

    /*****************************************************************************************
    Function:intvmm_pagingInit();

    Description:ThisFunctionWillInitializeTheOperatingSystemsPaging
    Abilities.

    Notes:
    02/20/2004-LookedOverCodeAndHaveApprovedItsQuality
    07/28/3004-Allpagesaresetforring-0onlynomoreuseraccessable

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

    intvmm_pagingInit(){
    uInt32i=0x0;
    uInt32*pageTable=0x0;

    /*AllocateAPageOfMemoryForKernelsPageDirectory*/
    kernelPageDirectory=(uInt32*)vmmFindFreePage(sysID);
    if(kernelPageDirectory==0x0){
    K_PANIC("Error:vmmFindFreePageFailed");
    return(0x1);
    }/*endif*/

    /*ClearTheMemoryToEnsureThereIsNoGarbage*/
    for(i=0;i<pageEntries;i++){
    (uInt32)kernelPageDirectory[i]=(uInt32)0x0;
    }/*endfor*/

    /*Allocateapageforthefirst4MBofmemory*/
    if((pageTable=(uInt32*)vmmFindFreePage(sysID))==0x0)
    K_PANIC("Error:vmmFindFreePageFailed");
    kernelPageDirectory[0]=(uInt32)((uInt32)(pageTable)|KERNEL_PAGE_DEFAULT);

    /*MakeSureThePageTableIsClean*/
    memset(pageTable,0x0,0x1000);

    /*
    *Mapthefirst1MBofMemorytothekernelMMspacebecauseourkernelstarts
    *at0x30000
    *Donotmappageataddress0x0thisisreservedfornull...
    */
    for(i=0x1;i<(pageEntries/0x4);i++){
    pageTable[i]=(uInt32)((i*0x1000)|KERNEL_PAGE_DEFAULT);
    }/*endfor*/

    /*
    *Createpagetablesforthetop1GBofVMspace.Thisspaceissetaside
    *forkernelspaceandwillbesharedwitheachprocess
    */
    for(i=768;i<pageEntries;i++){
    if((pageTable=(uInt32*)vmmFindFreePage(sysID))==0x0)
    K_PANIC("Error:vmmFindFreePageFailed");

    /*MakeSureThePageTableIsClean*/
    memset(pageTable,0x0,0x1000);

    /*MapInThePageDirectory*/
    kernelPageDirectory[i]=(uInt32)((uInt32)(pageTable)|KERNEL_PAGE_DEFAULT);
    }/*endfor*/

    /*SetUpMemoryToBeAllTheAllocatedPageDirectories*/
    if((pageTable=(uInt32*)vmmFindFreePage(sysID))==0x0)
    K_PANIC("Error:vmmFindFreePageFailed");

    /*CleanPageTable*/
    memset(pageTable,0x0,0x1000);

    kernelPageDirectory[767]=((uInt32)pageTable|KERNEL_PAGE_DEFAULT);
    for(i=0;i<pageEntries;i++){
    pageTable[i]=kernelPageDirectory[i];
    }/*endfor*/

    /*AlsoSetUpPageDirectoryToBeTheTheFirstPageIn0xE0400000*/
    pageTable=(uInt32*)(kernelPageDirectory[0]&0xFFFFF000);
    pageTable[256]=(uInt32)((uInt32)(kernelPageDirectory)|KERNEL_PAGE_DEFAULT);

    /*NowLetsTurnOnPagingWithThisInitialPageTable*/
    asmvolatile(
    "movl%0,%%eax\n"
    "movl%%eax,%%cr3\n"
    "movl%%cr0,%%eax\n"
    "orl$0x80010000,%%eax\n"/*Turnonmemoryprotection*/
    "movl%%eax,%%cr0\n"
    :
    :"d"((uInt32*)(kernelPageDirectory))
    );

    /*RemapTheMemoryList*/
    for(i=0x101000;i<=(0x101000+(numPages*sizeof(mMap)));i+=0x1000){
    if((vmm_remapPage(i,(vmmMemoryMapAddr+(i-0x101000)),KERNEL_PAGE_DEFAULT))==0x0)
    K_PANIC("vmmRemapPagefailed\n");
    }
    /*SetNewAddressForMemoryMapSinceItsRelocation*/
    vmmMemoryMap=(mMap*)vmmMemoryMapAddr;

    /*Printinformationonpaging*/
    kprintf("paging0-Address:[0x%X],PagingISRAddress:[0x%X]\n",kernelPageDirectory,&_vmm_pageFault);

    /*Returnsoweknoweverythingwentwell*/
    return(0x0);
    }/*END*/

    /*****************************************************************************************
    Function:intvmmRemapPage(PhysicalSource,VirtualDestination)

    Description:ThisFunctionWillRemapAPhysicalPageIntoVirtualSpace

    Notes:
    07/29/02-RewroteThisToWorkWithOurNewPagingSystem
    07/30/02-ChangedAddressOfPageTablesAndPageDirectory
    07/28/04-Ifperms==0x0settoPAGE_DEFAULT

    *****************************************************************************************/
    intvmm_remapPage(uInt32source,uInt32dest,uInt16perms)
    {
    uInt16destPageDirectoryIndex=0x0,destPageTableIndex=0x0;
    uInt32*pageDir=0x0,*pageTable=0x0;
    shorti=0x0;

    if(source==0x0)
    K_PANIC("source==0x0");
    if(dest==0x0)
    K_PANIC("dest==0x0");

    spinLock(&rmpSpinLock);
    if(perms==0x0)
    perms=KERNEL_PAGE_DEFAULT;

    /*
    *SetPointerpageDirectoryToPointToTheVirtualMappingOfThePage
    *Directory
    */
    pageDir=(uInt32*)parentPageDirAddr;
    /*CheckToSeeIfPageTableExists*/
    if(dest==0x0)
    return(0x0);

    /*GetIndexIntoThePageDirectory*/
    destPageDirectoryIndex=(dest/0x400000);

    if((pageDir[destPageDirectoryIndex]&PAGE_PRESENT)!=PAGE_PRESENT){
    /*IfPageTableIsNonExistantThenSetItUp*/
    /*UBUWhydoesthepagetableneedtobeuserwritable?*/
    pageDir[destPageDirectoryIndex]=(uInt32)vmmFindFreePage(_current->id)|PAGE_DEFAULT;

    /*AlsoAddItToVirtualSpaceSoWeCanMakeChangesLater*/
    pageTable=(uInt32*)(tablesBaseAddress+0x2FF000);
    pageTable[destPageDirectoryIndex]=pageDir[destPageDirectoryIndex];
    /*ReloadPageDirectory*/
    asmvolatile(
    "push%eax\n"
    "mov%cr3,%eax\n"
    "mov%eax,%cr3\n"
    "pop%eax\n"
    );
    pageTable=(uInt32*)(tablesBaseAddress+(0x1000*destPageDirectoryIndex));
    for(i=0x0;i<pageEntries;i++)
    pageTable[i]=0x0;
    }
    /*SetAddressToPageTable*/
    pageTable=(uInt32*)(tablesBaseAddress+(0x1000*destPageDirectoryIndex));

    /*GetTheIndexToThePageTable*/
    destPageTableIndex=((dest-(destPageDirectoryIndex*0x400000))/0x1000);

    /*IfThePageIsMappedInFreeItBeforeWeRemap*/
    if((pageTable[destPageTableIndex]&PAGE_PRESENT)==PAGE_PRESENT){
    if((pageTable[destPageTableIndex]&PAGE_STACK)==PAGE_STACK)
    kprintf("StackPage:[0x%X]\n",dest);

    if((pageTable[destPageTableIndex]&PAGE_COW)!=PAGE_COW){
    kprintf("PageNOTCOW\n");
    kprintf("PagePresent:[0x%X][0x%X]",dest,pageTable[destPageTableIndex]);
    source=0x0;
    gotormDone;
    }
    /*ClearThePageFirstForSecurityReasons*/
    freePage(((uInt32)pageTable[destPageTableIndex]&0xFFFFF000));
    }
    /*SetTheSourceAddressInTheDestination*/
    pageTable[destPageTableIndex]=(uInt32)(source|perms);
    /*ReloadThePageTable;*/
    asmvolatile(
    "push%eax\n"
    "movl%cr3,%eax\n"
    "movl%eax,%cr3\n"
    "pop%eax\n"
    );

    rmDone:
    /*Return*/
    spinUnlock(&rmpSpinLock);
    return(source);
    }

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

    Function:void*vmmGetFreeKernelPage(pidTypepid);
    Description:ReturnsAFreePageMappedToTheVMSpace
    Notes:

    07/30/02-ThisReturnsAFreePageInTheTop1GBForTheKernel

    ************************************************************************/
    void*
    vmmGetFreeKernelPage(pidTypepid,uInt16count)
    {
    intx=0,y=0,c=0;
    uInt32*pageTableSrc=0x0;

    spinLock(&fkpSpinLock);
    /*LetsSearchForAFreePage*/
    for(x=768;x<1024;x++){
    /*SetPageTableAddress*/
    pageTableSrc=(uInt32*)(tablesBaseAddress+(4096*x));
    for(y=0;y<1024;y++){
    /*LoopThroughThePageTableFindAnUnAllocatedPage*/
    if((uInt32)pageTableSrc[y]==(uInt32)0x0){
    if(count>1){
    for(c=0;c<count;c++){
    if(y+c<1024){
    if((uInt32)pageTableSrc[y+c]!=(uInt32)0x0){
    c=-1;
    break;
    }
    }
    }
    if(c!=-1){
    for(c=0;c<count;c++){
    if((vmm_remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+((y+c)*4096)),KERNEL_PAGE_DEFAULT))==0x0)
    K_PANIC("vmmRemapPagefailed:gfkp-1\n");
    vmmClearVirtualPage((uInt32)((x*(1024*4096))+((y+c)*4096)));
    }
    spinUnlock(&fkpSpinLock);
    return((void*)((x*(1024*4096))+(y*4096)));
    }
    }else{
    /*MapAPhysicalPageToTheVirtualPage*/

    if((vmm_remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)),KERNEL_PAGE_DEFAULT))==0x0)
    K_PANIC("vmmRemapPagefailed:gfkp-2\n");
    /*ClearThisPageSoNoGarbageIsThere*/
    vmmClearVirtualPage((uInt32)((x*(1024*4096))+(y*4096)));
    /*ReturnTheAddressOfTheNewlyAllocatePage*/
    spinUnlock(&fkpSpinLock);
    return((void*)((x*(1024*4096))+(y*4096)));
    }
    }
    }
    }
    /*IfNoFreePageWasFoundReturnNULL*/
    spinUnlock(&fkpSpinLock);
    return(0x0);
    }

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

    Function:voidvmmClearVirtualPage(uInt32pageAddr);

    Description:ThisWillNullOutAPageOfMemory

    Notes:

    ************************************************************************/
    int
    vmmClearVirtualPage(uInt32pageAddr)
    {
    uInt32*src=0x0;
    intcounter=0x0;

    /*SetSourcePointerToVirtualPageAddress*/
    src=(uInt32*)pageAddr;

    /*ClearOutThePage*/
    for(counter=0x0;counter<pageEntries;counter++){
    (uInt32)src[counter]=(uInt32)0x0;
    }

    /*Return*/
    return(0x0);
    }

    void*vmmMapFromTask(pidTypepid,void*ptr,uInt32size){
    kTask_t*child=0x0;
    uInt32i=0x0,x=0x0,y=0x0,count=((size+4095)/0x1000),c=0x0;
    uInt16dI=0x0,tI=0x0;
    uInt32baseAddr=0x0,offset=0x0;
    uInt32*childPageDir=(uInt32*)0x5A00000;
    uInt32*childPageTable=0x0;
    uInt32*pageTableSrc=0x0;
    offset=(uInt32)ptr&0xFFF;
    baseAddr=(uInt32)ptr&0xFFFFF000;
    child=schedFindTask(pid);
    //CalculateThePageTableIndexAndPageDirectoryIndex
    dI=(baseAddr/(1024*4096));
    tI=((baseAddr-(dI*(1024*4096)))/4096);
    if(vmm_remapPage(child->tss.cr3,0x5A00000,KERNEL_PAGE_DEFAULT)==0x0)
    K_PANIC("vmmFailed");

    for(i=0;i<0x1000;i++){
    if(vmm_remapPage(childPageDir[i],0x5A01000+(i*0x1000),KERNEL_PAGE_DEFAULT)==0x0)
    K_PANIC("ReturnedNULL");
    }
    for(x=(_current->oInfo.vmStart/(1024*4096));x<1024;x++){
    pageTableSrc=(uInt32*)(tablesBaseAddress+(4096*x));
    for(y=0;y<1024;y++){
    //LoopThroughThePageTableFindAnUnAllocatedPage
    if((uInt32)pageTableSrc[y]==(uInt32)0x0){
    if(count>1){
    for(c=0;((c<count)&&(y+c<1024));c++){
    if((uInt32)pageTableSrc[y+c]!=(uInt32)0x0){
    c=-1;
    break;
    }
    }
    if(c!=-1){
    for(c=0;c<count;c++){
    if((tI+c)>=0x1000){
    dI++;
    tI=0-c;
    }
    childPageTable=(uInt32*)(0x5A01000+(0x1000*dI));
    if(vmm_remapPage(childPageTable[tI+c],((x*(1024*4096))+((y+c)*4096)),KERNEL_PAGE_DEFAULT)==0x0)
    K_PANIC("remap==NULL");
    }
    vmmUnmapPage(0x5A00000,1);
    for(i=0;i<0x1000;i++){
    vmmUnmapPage((0x5A01000+(i*0x1000)),1);
    }
    return((void*)((x*(1024*4096))+(y*4096)+offset));
    }
    }
    else{
    //MapAPhysicalPageToTheVirtualPage
    childPageTable=(uInt32*)(0x5A01000+(0x1000*dI));
    if(vmm_remapPage(childPageTable[tI],((x*(1024*4096))+(y*4096)),KERNEL_PAGE_DEFAULT)==0x0)
    K_PANIC("remapFailed");

    //ReturnTheAddressOfTheMappedInMemory
    vmmUnmapPage(0x5A00000,1);
    for(i=0;i<0x1000;i++){
    vmmUnmapPage((0x5A01000+(i*0x1000)),1);
    }
    return((void*)((x*(1024*4096))+(y*4096)+offset));
    }
    }
    }
    }
    return(0x0);
    }

    void*vmm_getFreeMallocPage(uInt16count){
    uInt16x=0x0,y=0x0;
    intc=0x0;
    uInt32*pageTableSrc=0x0;

    spinLock(&fkpSpinLock);
    /*LetsSearchForAFreePage*/
    for(x=960;x<1024;x++){
    /*SetPageTableAddress*/
    pageTableSrc=(uInt32*)(tablesBaseAddress+(0x1000*x));
    for(y=0;y<1024;y++){
    /*LoopThroughThePageTableFindAnUnAllocatedPage*/
    if((uInt32)pageTableSrc[y]==(uInt32)0x0){
    if(count>1){
    for(c=0;c<count;c++){
    if(y+c<1024){
    if((uInt32)pageTableSrc[y+c]!=(uInt32)0x0){
    c=-1;
    break;
    }
    }
    }
    if(c!=-1){
    for(c=0;c<count;c++){
    if(vmm_remapPage((uInt32)vmmFindFreePage(sysID),((x*0x400000)+((y+c)*0x1000)),KERNEL_PAGE_DEFAULT)==0x0)
    K_PANIC("remapFailed");

    vmmClearVirtualPage((uInt32)((x*0x400000)+((y+c)*0x1000)));
    }
    spinUnlock(&fkpSpinLock);
    return((void*)((x*0x400000)+(y*0x1000)));
    }
    }
    else{
    /*MapAPhysicalPageToTheVirtualPage*/
    if(vmm_remapPage((uInt32)vmmFindFreePage(sysID),((x*0x400000)+(y*0x1000)),KERNEL_PAGE_DEFAULT)==0x0)
    K_PANIC("Failed");

    /*ClearThisPageSoNoGarbageIsThere*/
    vmmClearVirtualPage((uInt32)((x*0x400000)+(y*0x1000)));
    /*ReturnTheAddressOfTheNewlyAllocatePage*/
    spinUnlock(&fkpSpinLock);
    return((void*)((x*0x400000)+(y*0x1000)));
    }
    }
    }
    }
    /*IfNoFreePageWasFoundReturnNULL*/
    spinUnlock(&fkpSpinLock);
    return(0x0);
    }

    intmmap(structthread*td,structmmap_args*uap){
    vm_offset_taddr=0x0;

    addr=(vm_offset_t)uap->addr;

    #ifdefDEBUG
    if(uap->addr!=0x0){
    kprintf("Addresshintsarenotsupportedyet.\n");
    }
    kprintf("uap->flags:[0x%X]\n",uap->flags);
    kprintf("uap->addr:[0x%X]\n",uap->addr);
    kprintf("uap->len:[0x%X]\n",uap->len);
    kprintf("uap->prot:[0x%X]\n",uap->prot);
    kprintf("uap->fd:[%i]\n",uap->fd);
    kprintf("uap->pad:[0x%X]\n",uap->pad);
    kprintf("uap->pos:[0x%X]\n",uap->pos);
    #endif

    if(uap->fd==-1)
    td->td_retval[0]=vmmGetFreeVirtualPage(_current->id,uap->len/0x1000,VM_TASK);
    else
    td->td_retval[0]=0x0;
    return(0x0);
    }

    intobreak(structthread*td,structobreak_args*uap){
    uint32_ti=0x0;
    vm_offset_told=0x0;
    vm_offset_tbase=0x0;
    vm_offset_tnew=0x0;

    #ifdefDEBUG
    kprintf("vm_offset_t:[%i]\n",sizeof(vm_offset_t));
    kprintf("nsize:[0x%X]\n",uap->nsize);
    kprintf("vm_daddr:[0x%X]\n",td->vm_daddr);
    kprintf("vm_dsize:[0x%X]\n",td->vm_dsize);
    kprintf("total:[0x%X]\n",td->vm_daddr+td->vm_dsize);
    #endif

    new=round_page((vm_offset_t)uap->nsize);

    base=round_page((vm_offset_t)td->vm_daddr);

    old=base+ctob(td->vm_dsize);

    if(new<base)
    K_PANIC("EINVAL");

    if(new>old){
    for(i=old;i<new;i+=0x1000){
    if(vmm_remapPage(vmmFindFreePage(_current->id),i,PAGE_DEFAULT)==0x0)
    K_PANIC("remapFailed");
    }
    td->vm_dsize+=btoc(new-old);
    }
    elseif(new<old){
    K_PANIC("new<old");
    td->vm_dsize-=btoc(old-new);
    }

    return(0x0);
    }

    intmunmap(structthread*td,structmunmap_args*uap){
    /*HACK*/
    kprintf("munmap");
    return(0x0);
    }

    intvmm_cleanVirtualSpace(uint32_taddr){
    intx=0x0;
    inty=0x0;
    uint32_t*pageTableSrc=0x0;
    uint32_t*pageDir=0x0;

    pageDir=(uInt32*)parentPageDirAddr;

    #ifdefDEBUG
    kprintf("CVS:[0x%X]\n",addr);
    #endif

    for(x=(addr/(1024*4096));x<770;x++){
    if((pageDir[x]&PAGE_PRESENT)==PAGE_PRESENT){
    pageTableSrc=(uInt32*)(tablesBaseAddress+(0x1000*x));
    for(y=0;y<1024;y++){
    if(pageTableSrc[y]!=0x0){
    if((pageTableSrc[y]&PAGE_COW)==PAGE_COW){
    //kprintf("COWi*");
    pageTableSrc[y]=0x0;
    }
    elseif((pageTableSrc[y]&PAGE_STACK)==PAGE_STACK){
    //pageTableSrc[y]=0x0;
    //kprintf("STACK:(%i:%i)",x,y);
    }
    else{
    //kprintf("+");
    }
    }
    }
    }
    }
    asm(
    "movl%cr3,%eax\n"
    "movl%eax,%cr3\n"
    );
    return(0x0);
    }

    /***
    END
    ***/