Changeset 2033 for Whitix

Show
Ignore:
Timestamp:
04/02/09 21:33:23 (3 years ago)
Author:
mwhitworth
Message:

Add stubs for memory protection functions/cases.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/memory/mmap.c

    r1795 r2033  
    4444                return -EFAULT; 
    4545 
    46         area=VmLookupAddress(process,address); 
     46        area = VmLookupAddress(process, address); 
    4747         
    4848        /* Area of memory not currently mapped? */ 
     
    6363                return VmProtFault(area,address); 
    6464        else 
    65                 return VmHandleNoPage(area,address); 
     65                return VmHandleNoPage(area, address); 
    6666} 
    6767 
     
    133133 ***********************************************************************/ 
    134134         
    135 void MMapFreePage(struct VMArea* area, DWORD virt) 
     135void MMapFreePage(DWORD virt) 
    136136{ 
    137137        struct PhysPage* page; 
    138  
     138        struct VMArea* area; 
     139 
     140//      KePrint("%s, %d: MMapFreePage(%#X)\n", current->name, current->pid, virt); 
     141//      SymbolPrint(__builtin_return_address(2)); 
    139142        return; 
    140143 
     
    147150 
    148151                if (page->refs == 1) 
    149                         VmFreeMappedPage(area->vNode, page->physAddr); 
     152                { 
     153                        area = VmLookupAddress(current, virt); 
     154                         
     155                        if (area) 
     156                                VmFreeMappedPage(area->vNode, page->physAddr); 
     157                } 
    150158 
    151159                if (page->refs <= 0) 
    152160                { 
    153                         KePrint("%#X, %#X: page->physAddr = %#X (%d) pid = %d\n",  
     161                        KePrint("%#X, %#X: page->physAddr = %#X (refs = %d) pid = %d\n",  
    154162                                virt, page, page->physAddr, page->refs, current->pid); 
    155163                        cli(); hlt(); 
     
    160168} 
    161169 
     170void MMapFreePages(DWORD start, DWORD end) 
     171{ 
     172        DWORD i; 
     173         
     174        for (i = PAGE_ALIGN(start); i < PAGE_ALIGN_UP(end); i += PAGE_SIZE) 
     175                MMapFreePage(i); 
     176} 
     177 
    162178/*********************************************************************** 
    163179 * 
     
    184200        { 
    185201                for (i=curr->start; i< curr->start+curr->length; i+=PAGE_SIZE) 
    186                         MMapFreePage(curr, i); 
     202                        MMapFreePage(i); 
    187203 
    188204                MMapRemoveArea(curr); 
     
    368384        DWORD end=start+len; 
    369385        struct VMArea* newArea; 
    370  
     386         
    371387        /* Just unmapping the whole area */ 
    372388        if (area->start == start && area->length == len) 
    373389                return; 
    374  
     390         
    375391        if (start >= area->start && end == area->start+area->length) 
     392        { 
    376393                area->length-=((area->start+area->length)-start); 
    377         else if (start == area->start && end <= area->start+area->length) 
     394        }else if (start == area->start && end <= area->start+area->length) 
    378395        { 
    379396                area->offset+=(end-area->start); 
     
    394411 
    395412        newArea=(struct VMArea*)MemCacheAlloc(areaCache); 
     413         
    396414        if (!newArea) 
    397415                return; 
     
    417435 ***********************************************************************/ 
    418436 
    419 int MMapUnmap(struct Process* process,DWORD start,DWORD len) 
     437int MMapUnmap(struct Process* process,DWORD start, DWORD len) 
    420438{ 
    421439        struct VMArea* area,*next; 
     440        struct ListHead* lNext; 
    422441        DWORD currLen=len; 
    423442        DWORD end; 
    424443        int err=0; 
     444        DWORD flags; 
     445         
     446        IrqSaveFlags(flags); 
    425447         
    426448        /* Several sanity checks */ 
    427449        if (PAGE_OFFSET(start) || start > MMAP_END || len > MMAP_END-start || !len) 
    428                 return -EINVAL; 
     450        { 
     451                err = -EINVAL; 
     452                goto error; 
     453        } 
    429454 
    430455        area=VmLookupAddress(process, start); 
    431456 
    432457        if (!area) 
    433                 return -EFAULT; 
    434                  
     458        { 
     459                err = -EFAULT; 
     460                goto error; 
     461        } 
     462                         
    435463        end = start + len; 
    436464         
    437465        if (area->start >= end) 
    438                 return 0; 
     466        { 
     467                err = 0; 
     468                goto error; 
     469        } 
    439470 
    440471        while (currLen) 
     
    444475                end=(end > area->start+area->length) ? area->start+area->length : end; 
    445476 
     477                lNext = &area->list.next; 
    446478                next=ListEntry(area->list.next, struct VMArea, list); 
     479 
     480                /* TODO: Call MMapFreeArea? Check vNode refs are handled properly. */ 
    447481                ListRemove(&area->list); 
    448482 
    449483                MMapUnmapArea(process, area, currStart, end-currStart); 
    450484 
    451                 if (area->list.next == &process->areaList && currLen > 0) 
     485                MemCacheFree(areaCache, area); 
     486 
     487                if (lNext == &process->areaList && currLen > 0) 
    452488                { 
    453                         MemCacheFree(areaCache,(void*)area); 
    454489                        err=-EINVAL; 
    455490                        goto error; 
    456491                } 
    457  
    458                 MemCacheFree(areaCache,(void*)area); 
    459                 area=next; 
     492                 
     493                area = next; 
    460494 
    461495                currLen-=(end-start); 
    462496        } 
     497         
     498        MMapFreePages(start, end); 
    463499 
    464500error: 
     501        IrqRestoreFlags(flags); 
    465502        return err; 
    466503} 
     
    524561} 
    525562 
     563int MMapProtectionFixEnd(struct VMArea* area, DWORD start, int protection) 
     564{ 
     565        KePrint("MMapProtectionFixEnd\n"); 
     566        return 0; 
     567} 
     568 
     569int MMapProtectionFixMiddle(struct VMArea* area, DWORD start, DWORD end, int protection) 
     570{ 
     571        KePrint("MMapProtectionFixMiddle\n"); 
     572        return 0; 
     573} 
     574 
    526575int MMapProtectionChange(struct VMArea* area, DWORD start, DWORD end, int protection) 
    527576{ 
     
    537586                else 
    538587                        error = MMapProtectionFixStart(area, end, protection); 
     588        }else if (end == area->start + area->length) 
     589        { 
     590                error = MMapProtectionFixEnd(area, start, protection); 
    539591        }else{ 
    540                 if (protection != 4) 
    541                 { 
    542                 KePrint("TODO: after start, before end, %#X, %#X, %d\n", start, end, protection); 
    543                 cli(); hlt(); 
    544                 } 
     592                error = MMapProtectionFixMiddle(area, start, end, protection); 
    545593        } 
    546594