X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fvfs%2Fmmap.c;h=c5015e67f02ffc1b6b3bfda5fb03bcdf75592edf;hb=bd5e8623e509a443d7d6e1b959b79f85b0c285b7;hp=9fe9282c309b4a52cc15dad8e41f5e74f3910099;hpb=51ab5f489bc356940c95cc936fd0508e8f07ea97;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/vfs/mmap.c b/KernelLand/Kernel/vfs/mmap.c index 9fe9282c..c5015e67 100644 --- a/KernelLand/Kernel/vfs/mmap.c +++ b/KernelLand/Kernel/vfs/mmap.c @@ -50,7 +50,7 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, LOG("%i pages anonymous to %p", npages, mapping_dest); for( ; npages --; mapping_dest += PAGE_SIZE, ofs += PAGE_SIZE ) { - if( MM_GetPhysAddr(mapping_dest) ) { + if( MM_GetPhysAddr((void*)mapping_dest) ) { // TODO: Set flags to COW if needed (well, if shared) MM_SetFlags(mapping_dest, MM_PFLAG_COW, MM_PFLAG_COW); LOG("clear from %p, %i bytes", (void*)(mapping_base + ofs), @@ -93,14 +93,13 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, if( !pb || pb->BaseOffset > pagenum ) { void *old_pb = pb; - pb = malloc( sizeof(tVFS_MMapPageBlock) ); + pb = calloc( 1, sizeof(tVFS_MMapPageBlock) ); if(!pb) { Mutex_Release( &h->Node->Lock ); LEAVE_RET('n', NULL); } pb->Next = old_pb; pb->BaseOffset = pagenum - pagenum % MMAP_PAGES_PER_BLOCK; - memset(pb->PhysAddrs, 0, sizeof(pb->PhysAddrs)); if(prev) prev->Next = pb; else @@ -110,7 +109,7 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, // - Map (and allocate) pages while( npages -- ) { - if( MM_GetPhysAddr(mapping_dest) == 0 ) + if( MM_GetPhysAddr( (void*)mapping_dest ) == 0 ) { if( pb->PhysAddrs[pagenum - pb->BaseOffset] == 0 ) { @@ -133,11 +132,12 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, } // TODO: Clip read length read_len = nt->Read(h->Node, pagenum*PAGE_SIZE, PAGE_SIZE, (void*)mapping_dest); -// if( read_len != PAGE_SIZE ) { -// memset( (void*)(mapping_dest+read_len), 0, PAGE_SIZE-read_len ); -// } + // TODO: This was commented out, why? + if( read_len != PAGE_SIZE ) { + memset( (void*)(mapping_dest+read_len), 0, PAGE_SIZE-read_len ); + } } - pb->PhysAddrs[pagenum - pb->BaseOffset] = MM_GetPhysAddr( mapping_dest ); + pb->PhysAddrs[pagenum - pb->BaseOffset] = MM_GetPhysAddr( (void*)mapping_dest ); MM_SetPageNode( pb->PhysAddrs[pagenum - pb->BaseOffset], h->Node ); MM_RefPhys( pb->PhysAddrs[pagenum - pb->BaseOffset] ); LOG("Read and map %X to %p (%P)", pagenum*PAGE_SIZE, mapping_dest, @@ -194,7 +194,6 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, memset(pb->PhysAddrs, 0, sizeof(pb->PhysAddrs)); oldpb->Next = pb; } - pagenum = 0; } }