Changeset 541 for Whitix/branches/hybrid

Show
Ignore:
Timestamp:
05/24/08 09:55:50 (3 months ago)
Author:
mwhitworth
Message:

Update build process.

Location:
Whitix/branches/hybrid/memory
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/hybrid/memory/Makefile

    r222 r541  
    22include ../make.inc 
    33 
    4 OBJS = pg_alloc.o slab.o mmap.o shmem.o 
     4OBJS = pg_alloc.o 
     5MODULES = slab.sys mmap.sys shmem.sys vmm.sys 
    56 
    6 build: $(OBJS) 
     7build: $(OBJS) $(MODULES) 
     8 
     9modules_install: 
     10        cp *.sys ../CdRoot/System/Modules/Core 
    711 
    812clean: 
    9         rm -f *.o 
     13        rm -f *.o *.sys 
  • Whitix/branches/hybrid/memory/mmap.c

    r494 r541  
    2626#include <slab.h> 
    2727#include <user_acc.h> 
    28  
    29 struct Cache* areaCache,*mapCache; 
    30  
    31 /*********************************************************************** 
    32  * 
    33  * FUNCTION: VmLookupAddress 
    34  * 
    35  * DESCRIPTION: Look up an address in the process's region list. 
    36  * 
    37  * PARAMETERS: process - the process in question. 
    38  *                         address - the address in question. 
    39  * 
    40  * RETURNS: area that the address is contained in. 
    41  * 
    42  ***********************************************************************/ 
    43  
    44 struct VMArea* VmLookupAddress(struct Process* process,DWORD address) 
    45 { 
    46         struct VMArea* curr; 
    47  
    48         ListForEachEntry(curr,&process->areaList,list) 
    49         {  
    50                 /* Ordered by vm area start address, so don't have to search through 
    51                 the whole list if the address has already been passed. */ 
    52                 if (curr->start > address) 
    53                         break; 
    54  
    55                 /* Is the address in the virtual mapping? */ 
    56                 if (address >= curr->start && address < (curr->start+curr->length)) 
    57                         return curr; 
    58         } 
    59  
    60         return NULL; 
    61 } 
    62  
    63 SYMBOL_EXPORT(VmLookupAddress); 
    64  
    65 /*********************************************************************** 
    66  * 
    67  * FUNCTION: VmLookupPage 
    68  * 
    69  * DESCRIPTION: Looks up a page in a vNode by file offset to see if anyone 
    70  *                              has mapped the page already. 
    71  * 
    72  * PARAMETERS: vNode - vNode that contains the shared list. 
    73  *                         offset - file offset needed. 
    74  * 
    75  * RETURNS: the virtual page containing the file data. 
    76  * 
    77  ***********************************************************************/ 
    78  
    79 static struct VMMapPage* VmLookupPage(struct VNode* vNode,DWORD offset) 
    80 { 
    81         struct VMMapPage* page; 
    82  
    83         /* Has anyone else mapped it in? */ 
    84         if (!vNode || vNode->refs == 1 || ListEmpty(&vNode->sharedList)) 
    85                 return NULL; 
    86  
    87         /* Loop through the shared list and return the one with the offset we need. */ 
    88         ListForEachEntry(page,&vNode->sharedList,list)   
    89                 if (page->offset == offset) 
    90                         return page; 
    91  
    92         /* Not found - it will be mapped in and added to the shared list */ 
    93         return NULL; 
    94 } 
    95  
    96 /*********************************************************************** 
    97  * 
    98  * FUNCTION: VmCreateMappedPage 
    99  * 
    100  * DESCRIPTION: Looks up a page in a vNode by file offset. 
    101  * 
    102  * PARAMETERS: vNode - vNode that contains the shared list. 
    103  *                         offset - file offset needed. 
    104  * 
    105  * RETURNS: the virtual page containing the file data. 
    106  * 
    107  ***********************************************************************/ 
    108  
    109 static struct VMMapPage* VmCreateMappedPage(DWORD offset,struct PhysPage* page) 
    110 { 
    111         struct VMMapPage* mappedPage=(struct VMMapPage*)MemCacheAlloc(mapCache); 
    112  
    113         if (!mappedPage) 
    114                 return NULL; 
    115  
    116         mappedPage->offset=offset; 
    117         mappedPage->page=page; 
    118  
    119         return mappedPage; 
    120 } 
    121  
    122 /*********************************************************************** 
    123  * 
    124  * FUNCTION: VmFreeMappedPage 
    125  * 
    126  * DESCRIPTION: Free a mapped page by physical address. 
    127  * 
    128  * PARAMETERS: vNode - VFS node containing the reference to the page. 
    129  *                         physAddr - physical address of the page. 
    130  * 
    131  * RETURNS: Usual error codes. 
    132  * 
    133  ***********************************************************************/ 
    134  
    135 static int VmFreeMappedPage(struct VNode* vNode,DWORD physAddr) 
    136 { 
    137         struct VMMapPage* page=NULL; 
    138  
    139         if (!vNode) 
    140                 return -EFAULT; 
    141  
    142         /* Remove a physical page from the list, because there are no references and it will be freed */ 
    143  
    144         ListForEachEntry(page,&vNode->sharedList,list) 
    145                 if (page->page->physAddr == physAddr) 
    146                 { 
    147                         ListRemove(&page->list); 
    148                         return 0; 
    149                 } 
    150  
    151         return -ENOENT; 
    152 } 
    153  
    154 /*********************************************************************** 
    155  * 
    156  * FUNCTION:    VmWaitOnPage 
    157  * 
    158  * DESCRIPTION: Wait for another thread to stop altering the page.  
    159  *                              A single waitqueue is shared between a number of pages  
    160  *                              (one per 4mb+ or so) since there are not many conflicts  
    161  *                              for a single page - it is very unlikely that a page will  
    162  *                              be locked and someone else try to access it. 
    163  * 
    164  * PARAMETERS:  page - page in question. 
    165  * 
    166  * RETURNS:             Nothing. 
    167  * 
    168  ***********************************************************************/ 
    169  
    170 static void VmWaitOnPage(struct VMMapPage* page) 
    171 { 
    172         WaitQueue* waitQueue; 
    173          
    174         if (!(page->flags & MPAGE_BUSY)) 
    175                 return; 
    176  
    177         waitQueue=PageGetWaitQueue(page->page); 
    178  
    179         if (UNLIKELY(page->flags & MPAGE_BUSY)) 
    180                 WAIT_ON(*waitQueue,!(page->flags & MPAGE_BUSY)); 
    181 } 
    182  
    183 /*********************************************************************** 
    184  * 
    185  * FUNCTION: VmLockPage 
    186  * 
    187  * DESCRIPTION: Locks a page to alter data. 
    188  * 
    189  * PARAMETERS: page - page in question. 
    190  * 
    191  * RETURNS: Nothing. 
    192  * 
    193  ***********************************************************************/ 
    194  
    195 static void VmLockPage(struct VMMapPage* page) 
    196 { 
    197         VmWaitOnPage(page); 
    198         page->flags |= MPAGE_BUSY; 
    199 } 
    200  
    201 /*********************************************************************** 
    202  * 
    203  * FUNCTION: VmUnlockPage 
    204  * 
    205  * DESCRIPTION: Unlock the page, let any thread access it. 
    206  * 
    207  * PARAMETERS: page - page in question. 
    208  * 
    209  * RETURNS: Nothing. 
    210  * 
    211  ***********************************************************************/ 
    212  
    213 static void VmUnlockPage(struct VMMapPage* page) 
    214 { 
    215         page->flags &= ~MPAGE_BUSY; 
    216         WakeUp(PageGetWaitQueue(page->page)); 
    217 } 
     28#include <sys.h> 
     29 
     30extern struct Cache* areaCache,*mapCache; 
     31 
     32/* FIXME: Move more functions into vmm.c */ 
    21833 
    21934/*********************************************************************** 
     
    25065                if (area->flags & MMAP_SHARED) 
    25166                { 
    252                         printf("Shared page...\n"); 
     67                        KePrint("Shared page...\n"); 
    25368                        MachineHalt(); 
    25469                }else{ 
     
    309124fail: 
    310125        /* Failed to read in the page, and cannot continue */ 
    311         printf("VmHandleNoPage failed: killing process\n"); 
     126        KePrint("VmHandleNoPage failed: killing process\n"); 
    312127        /* Not reached */ 
    313128        return -EIO; 
     
    332147static int VmProtFault(struct VMArea* area,DWORD address) 
    333148{ 
    334         printf("Protection fault at %#X, area = %#X, area->start = %#X, area->end = %#X", 
     149        KePrint("Protection fault at %#X, area = %#X, area->start = %#X, area->end = %#X", 
    335150                address,area,area->start,area->start+area->length); 
    336151 
     
    494309        } 
    495310} 
     311 
     312SYMBOL_EXPORT(MmapProcessRemove); 
    496313 
    497314/*********************************************************************** 
     
    656473} 
    657474 
     475SYMBOL_EXPORT(MMapDo); 
     476 
    658477void MMapUnmapArea(struct Process* process,struct VMArea* area,DWORD start,DWORD len) 
    659478{ 
     
    716535 
    717536        /* Several sanity checks */ 
    718         if (PAGE_OFFSET(start) || start > MMAP_END|| len > MMAP_END-start || !len) 
     537        if (PAGE_OFFSET(start) || start > MMAP_END || len > MMAP_END-start || !len) 
    719538                return -EINVAL; 
    720539 
    721         area=VmLookupAddress(process,start); 
     540        area=VmLookupAddress(process, start); 
    722541 
    723542        if (!area) 
     
    785604int SysMemoryProtect(DWORD address, size_t length, int protection) 
    786605{ 
    787         printf("SysMemoryProtect(%#X, %d)\n", address, length); 
     606        KePrint("SysMemoryProtect(%#X, %d)\n", address, length); 
    788607        return -ENOTIMPL; 
    789608} 
     
    807626} 
    808627 
    809 int VirtCheckArea(void* beginAddr,DWORD size,int mask) 
    810 { 
    811         DWORD begin=(DWORD)beginAddr; 
    812         struct VMArea* area,*next; 
    813  
    814         /* Don't have to check */ 
    815         if (!size) 
    816                 return 0; 
    817  
    818         area=VmLookupAddress(current,begin); 
    819  
    820         if (!area) 
    821                 return -EFAULT; 
    822  
    823         /* Cannot write to a read-only area */ 
    824         if (!(area->protection & PAGE_RW) && (mask & VER_WRITE)) 
    825                 return -EFAULT; 
    826  
    827         /* Doesn't overrun */ 
    828         if ((area->start+area->length)-begin >= size) 
    829                 return 0; 
    830  
    831         /* Check when size overruns the area */ 
    832         while (1) 
    833         { 
    834                 /* Assumes all areas are at least readable */ 
    835                 if (!(area->protection & PAGE_RW) && (mask & VER_WRITE)) 
    836                         return -EFAULT; 
    837  
    838                 /* Cannot let the user let the kernel write to it's own pages */ 
    839                 if (!(area->protection & PAGE_USER)) 
    840                         return -EFAULT; 
    841  
    842                 if ((area->start+area->length)-begin >= size) 
    843                         break; 
    844  
    845                 next=ListEntry(area->list.next,struct VMArea,list); 
    846                 if (area->list.next == &current->areaList || next->start == area->start+area->length) /* Does next even exist? */ 
    847                         return -EFAULT; 
    848  
    849                 area=next; 
    850         } 
    851  
    852         return 0; 
    853 } 
    854  
     628/* FIXME: Legacy system call. */ 
    855629void* SysMoreCore(int len) 
    856630{ 
     
    862636        if (len < 0) 
    863637        { 
    864                 printf("TODO: len = %d\n",len); 
    865                 //cli(); hlt(); 
     638                KePrint("TODO: len = %d\n",len); 
    866639                /* TODO: Actually release the memory. Use memoryMap */ 
    867640                current->memManager->end=PAGE_ALIGN(current->memManager->end); 
     
    881654} 
    882655 
    883 /*********************************************************************** 
    884  * 
    885  * FUNCTION: MMapInit 
    886  * 
    887  * DESCRIPTION: Setup caches for memory mapping. 
    888  * 
    889  * PARAMETERS: None. 
    890  * 
    891  * RETURNS: Usual error codes in error.h 
    892  * 
    893  ***********************************************************************/ 
     656DWORD functions[]={ 
     657        MmapHandleFault, 
     658        MMapDo 
     659}; 
     660 
     661struct SysCall mmapSysCalls[]= 
     662{ 
     663        { SysMoreCore, sizeof(int) }, 
     664        { SysMemoryMap, 24 }, 
     665        { SysMemoryProtect, 12 }, 
     666        { SysMemoryUnmap, 8 }, 
     667        { 0, 0 } 
     668}; 
     669 
     670#define MMAP_SYSCALL_BEGIN      25 
    894671 
    895672int MMapInit() 
    896673{ 
    897         /* Create caches */ 
    898         areaCache=MemCacheCreate("VMArea Cache",sizeof(struct VMArea),NULL,NULL,0); 
    899         mapCache=MemCacheCreate("Mapped Page Cache",sizeof(struct VMMapPage),NULL,NULL,0); 
    900  
    901         if (!areaCache || !mapCache) 
    902                 return -ENOMEM; 
    903  
     674        ResolveSetVmFunctions(functions); 
     675        SysRegisterRange(MMAP_SYSCALL_BEGIN, mmapSysCalls); 
    904676        return 0; 
    905677} 
     678 
     679ModuleInit(MMapInit); 
  • Whitix/branches/hybrid/memory/slab.c

    r495 r541  
    2222#include <error.h> 
    2323#include <i386/i386.h> 
     24#include <imports.h> 
    2425 
    2526/*  
     
    9798        if (i == count(cacheSizes)) /* Too big */ 
    9899        { 
    99                 printf("malloc(%u) failed\n",size); 
     100                KePrint("malloc(%u) failed\n",size); 
    100101                IrqRestoreFlags(flags); 
    101102                return NULL; 
     
    165166 
    166167/* FIXME! */ 
    167         printf("free did not free %#X (from %#X)\n",p,__builtin_return_address(0)); 
     168        KePrint("free did not free %#X (from %#X)\n",p,__builtin_return_address(0)); 
    168169        cli(); hlt(); 
    169170} 
     
    326327        } 
    327328 
    328         printf("MemCacheAlloc(%#X) - failed to allocate memory\n",cache); 
     329        KePrint("MemCacheAlloc(%#X) - failed to allocate memory\n",cache); 
    329330        IrqRestoreFlags(flags); 
    330331        /* Shouldn't get here, as all memory requests should be satifisted by adding slabs */ 
     
    413414SYMBOL_EXPORT(MemCacheCreate); 
    414415 
     416DWORD functions[]= 
     417{ 
     418        (DWORD)malloc, 
     419        (DWORD)free, 
     420        (DWORD)MemCacheCreate, 
     421        (DWORD)MemCacheAlloc, 
     422        (DWORD)MemCacheFree, 
     423}; 
     424 
    415425int SlabInit() 
    416426{ 
     
    418428 
    419429        /* Set up the cache cache */ 
    420         ListAdd(&cacheList,&cacheCache.list); 
     430        ListAdd(&cacheList, &cacheCache.list); 
    421431 
    422432        /* Now start allocating caches */ 
     
    430440                if (!cacheSizes[i].cache) 
    431441                { 
    432                         printf("Malloc slab allocation failed!\n"); 
     442                        KePrint("Malloc slab allocation failed!\n"); 
    433443                        return -ENOMEM; 
    434444                } 
    435445        } 
    436446 
     447        ResolveSetMemFunctions(functions); 
     448 
    437449        return 0; 
    438450} 
     451 
     452ModuleInit(SlabInit);