Changeset 2033 for Whitix/trunk/memory
- Timestamp:
- 04/02/09 21:33:23 (3 years ago)
- Files:
-
- 1 modified
-
Whitix/trunk/memory/mmap.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/trunk/memory/mmap.c
r1795 r2033 44 44 return -EFAULT; 45 45 46 area =VmLookupAddress(process,address);46 area = VmLookupAddress(process, address); 47 47 48 48 /* Area of memory not currently mapped? */ … … 63 63 return VmProtFault(area,address); 64 64 else 65 return VmHandleNoPage(area, address);65 return VmHandleNoPage(area, address); 66 66 } 67 67 … … 133 133 ***********************************************************************/ 134 134 135 void MMapFreePage( struct VMArea* area,DWORD virt)135 void MMapFreePage(DWORD virt) 136 136 { 137 137 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)); 139 142 return; 140 143 … … 147 150 148 151 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 } 150 158 151 159 if (page->refs <= 0) 152 160 { 153 KePrint("%#X, %#X: page->physAddr = %#X ( %d) pid = %d\n",161 KePrint("%#X, %#X: page->physAddr = %#X (refs = %d) pid = %d\n", 154 162 virt, page, page->physAddr, page->refs, current->pid); 155 163 cli(); hlt(); … … 160 168 } 161 169 170 void 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 162 178 /*********************************************************************** 163 179 * … … 184 200 { 185 201 for (i=curr->start; i< curr->start+curr->length; i+=PAGE_SIZE) 186 MMapFreePage( curr,i);202 MMapFreePage(i); 187 203 188 204 MMapRemoveArea(curr); … … 368 384 DWORD end=start+len; 369 385 struct VMArea* newArea; 370 386 371 387 /* Just unmapping the whole area */ 372 388 if (area->start == start && area->length == len) 373 389 return; 374 390 375 391 if (start >= area->start && end == area->start+area->length) 392 { 376 393 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) 378 395 { 379 396 area->offset+=(end-area->start); … … 394 411 395 412 newArea=(struct VMArea*)MemCacheAlloc(areaCache); 413 396 414 if (!newArea) 397 415 return; … … 417 435 ***********************************************************************/ 418 436 419 int MMapUnmap(struct Process* process,DWORD start, DWORD len)437 int MMapUnmap(struct Process* process,DWORD start, DWORD len) 420 438 { 421 439 struct VMArea* area,*next; 440 struct ListHead* lNext; 422 441 DWORD currLen=len; 423 442 DWORD end; 424 443 int err=0; 444 DWORD flags; 445 446 IrqSaveFlags(flags); 425 447 426 448 /* Several sanity checks */ 427 449 if (PAGE_OFFSET(start) || start > MMAP_END || len > MMAP_END-start || !len) 428 return -EINVAL; 450 { 451 err = -EINVAL; 452 goto error; 453 } 429 454 430 455 area=VmLookupAddress(process, start); 431 456 432 457 if (!area) 433 return -EFAULT; 434 458 { 459 err = -EFAULT; 460 goto error; 461 } 462 435 463 end = start + len; 436 464 437 465 if (area->start >= end) 438 return 0; 466 { 467 err = 0; 468 goto error; 469 } 439 470 440 471 while (currLen) … … 444 475 end=(end > area->start+area->length) ? area->start+area->length : end; 445 476 477 lNext = &area->list.next; 446 478 next=ListEntry(area->list.next, struct VMArea, list); 479 480 /* TODO: Call MMapFreeArea? Check vNode refs are handled properly. */ 447 481 ListRemove(&area->list); 448 482 449 483 MMapUnmapArea(process, area, currStart, end-currStart); 450 484 451 if (area->list.next == &process->areaList && currLen > 0) 485 MemCacheFree(areaCache, area); 486 487 if (lNext == &process->areaList && currLen > 0) 452 488 { 453 MemCacheFree(areaCache,(void*)area);454 489 err=-EINVAL; 455 490 goto error; 456 491 } 457 458 MemCacheFree(areaCache,(void*)area); 459 area=next; 492 493 area = next; 460 494 461 495 currLen-=(end-start); 462 496 } 497 498 MMapFreePages(start, end); 463 499 464 500 error: 501 IrqRestoreFlags(flags); 465 502 return err; 466 503 } … … 524 561 } 525 562 563 int MMapProtectionFixEnd(struct VMArea* area, DWORD start, int protection) 564 { 565 KePrint("MMapProtectionFixEnd\n"); 566 return 0; 567 } 568 569 int MMapProtectionFixMiddle(struct VMArea* area, DWORD start, DWORD end, int protection) 570 { 571 KePrint("MMapProtectionFixMiddle\n"); 572 return 0; 573 } 574 526 575 int MMapProtectionChange(struct VMArea* area, DWORD start, DWORD end, int protection) 527 576 { … … 537 586 else 538 587 error = MMapProtectionFixStart(area, end, protection); 588 }else if (end == area->start + area->length) 589 { 590 error = MMapProtectionFixEnd(area, start, protection); 539 591 }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); 545 593 } 546 594
