Changeset 739
- Timestamp:
- 07/07/08 15:23:30 (2 months ago)
- Location:
- Whitix/trunk/memory
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
Whitix/trunk/memory/mmap.c
r694 r739 28 28 #include <sys.h> 29 29 #include <print.h> 30 #include <preempt.h> 30 31 31 32 extern struct Cache* areaCache,*mapCache; … … 53 54 struct PhysPage* newPage; 54 55 int ret; 55 56 // KePrint("VmHandleNoPage(%#X)\n", address);57 56 58 57 if (area->areaOps && area->areaOps->handleNoPage) … … 69 68 MachineHalt(); 70 69 }else{ 70 PreemptDisable(); /* Needed? */ 71 71 newPage=PageAlloc(); 72 72 73 73 if (!newPage) 74 { 75 PreemptEnable(); 74 76 return -ENOMEM; 77 } 75 78 76 79 VirtMemMapPage(address,newPage->physAddr,area->protection); 80 81 PreemptEnable(); 77 82 78 83 if (area->vNode->fileOps->mMap) … … 154 159 } 155 160 156 /***********************************************************************157 *158 * FUNCTION: MMapAddArea159 *160 * DESCRIPTION: Add an area to the process's area list. The list is161 * sorted by start address, as this makes it much easier162 * for MMapFindAddress.163 *164 * PARAMETERS: process - process in question.165 * area - area to be added.166 *167 * RETURNS: Usual error codes.168 *169 ***********************************************************************/170 171 161 int MmapHandleFault(struct Process* process,DWORD address,int error) 172 162 { … … 218 208 ***********************************************************************/ 219 209 220 static void MMapAddArea(struct Process* process,struct VMArea* area) 221 { 222 struct VMArea* curr=NULL; 223 210 static void MMapAddArea(struct Process* process, struct VMArea* area) 211 { 224 212 if (ListEmpty(&process->areaList)) 225 213 ListAdd(&area->list,&process->areaList); 226 214 else 227 215 { 216 struct VMArea* curr=NULL; 217 228 218 ListForEachEntry(curr,&process->areaList,list) 229 219 if (curr->start > area->start) … … 299 289 void MmapProcessRemove(struct Process* process) 300 290 { 301 struct VMArea* curr, *curr2;291 struct VMArea* curr, *curr2; 302 292 DWORD i; 293 DWORD flags; 294 295 IrqSaveFlags(flags); 303 296 304 297 ListForEachEntrySafe(curr, curr2, &process->areaList, list) … … 309 302 MMapRemoveArea(curr); 310 303 } 304 305 IrqRestoreFlags(flags); 311 306 } 312 307 … … 365 360 ***********************************************************************/ 366 361 367 void MMapMerge(struct VMArea* first, struct VMArea* second,int isAnon)362 void MMapMerge(struct VMArea* first, struct VMArea* second) 368 363 { 369 364 if (first->start+first->length != second->start) … … 376 371 return; 377 372 378 if (!(isAnon))379 /* Check offsets */380 if (second->offset != first->offset+first->length)381 return;382 383 373 if (first->flags != second->flags) 384 374 return; 385 375 376 /* Check offsets */ 377 if (second->offset != first->offset+first->length) 378 return; 379 386 380 /* Ok to merge now */ 387 388 381 first->length+=second->length; 389 390 382 MMapRemoveArea(second); 391 383 } 392 384 393 void MMapMergeMappings(struct Process* process, struct VMArea* area,int isAnon)385 void MMapMergeMappings(struct Process* process, struct VMArea* area) 394 386 { 395 387 /* Get neighbours of this area (in terms of memory), and see whether they are … … 401 393 402 394 if (area->list.next != &process->areaList) 403 MMapMerge(area, next,isAnon);395 MMapMerge(area, next); 404 396 405 397 if (area->list.prev != &process->areaList) 406 MMapMerge(prev, area,isAnon);398 MMapMerge(prev, area); 407 399 } 408 400 … … 430 422 { 431 423 struct VMArea* area=(struct VMArea*)MemCacheAlloc(areaCache); 432 int isAnon=!vNode;433 424 434 425 if (!process || !length || !area) … … 455 446 if (NameToVNode(&vNode,DEVICES_PATH "Special/Zero",0)) 456 447 return 0; 448 449 flags |= MMAP_ANON; 457 450 } 458 451 … … 469 462 470 463 MMapAddArea(process,area); 471 MMapMergeMappings(process, area,isAnon);464 MMapMergeMappings(process, area); 472 465 473 466 return address; … … 603 596 } 604 597 605 int SysMemoryProtect(DWORD address, size_t length, int protection) 606 { 607 KePrint("SysMemoryProtect(%#X, %d)\n", address, length); 608 return -ENOTIMPL; 598 int MMapProtectionFixAll(struct VMArea* area, int protection) 599 { 600 area->protection=protection; 601 return 0; 602 } 603 604 int MMapProtectionChange(struct VMArea* area, DWORD start, DWORD end, int protection) 605 { 606 int error=-ENOTIMPL; 607 608 if (protection == area->protection) 609 return 0; 610 611 if (start == area->start) 612 { 613 if (end == area->start+area->length) 614 error=MMapProtectionFixAll(area, protection); 615 else 616 KePrint("MMapProtectionChange: TODO\n"); 617 }else{ 618 KePrint("MMapProtectionChange: TODO\n"); 619 } 620 621 if (error) 622 return error; 623 624 VirtChangeProtection(start, end, protection); 625 626 return 0; 627 } 628 629 int SysMemoryProtect(DWORD start, size_t length, int protection) 630 { 631 int error=-EINVAL; 632 size_t end; 633 size_t address; 634 struct VMArea* area, *next; 635 636 PreemptDisable(); 637 638 /* Can only deal with changing the protection of whole pages. */ 639 if (PAGE_OFFSET(start)) 640 goto out; 641 642 length=PAGE_ALIGN_UP(length); 643 end=start+length; 644 645 if (end < start) 646 goto out; 647 648 /* Check protection bits. */ 649 650 error=0; 651 652 /* A zero length is valid, but useless. */ 653 if (start == end) 654 goto out; 655 656 area=VmLookupAddress(current, start); 657 658 error=-EFAULT; 659 660 if (!area) 661 goto out; 662 663 /* The change of protection may extend over one or more mappings. */ 664 address=start; 665 666 while (1) 667 { 668 if ((area->start + area->length) >= end) 669 { 670 error=MMapProtectionChange(area, address, end, protection); 671 break; 672 } 673 674 KePrint("SysMemoryProtect: todo\n"); 675 } 676 677 // MMapMergeMappings(current, start, end); 678 679 out: 680 PreemptEnable(); 681 return error; 609 682 } 610 683 -
Whitix/trunk/memory/shmem.c
r694 r739 27 27 #include <sys.h> 28 28 #include <module.h> 29 #include <print.h> 29 30 30 31 #define SHMEM_MAX_DESCS 10
