示例#1
0
文件: vm.c 项目: Marvenlee/cheviot
SYSCALL vm_addr VirtualAllocPhys (vm_addr addr, ssize_t len, bits32_t flags, vm_addr paddr)
{
    struct Segment *seg;
    struct Process *current;


    current = GetCurrentProcess();

    addr = ALIGN_DOWN (addr, PAGE_SIZE);
    paddr = ALIGN_DOWN (paddr, PAGE_SIZE);
    len = ALIGN_UP (len, PAGE_SIZE);
    flags = (flags & ~VM_SYSTEM_MASK) | MEM_PHYS;

    if (!(current->flags & PROCF_ALLOW_IO))
        return (vm_addr)NULL;

    if (PmapSupportsCachePolicy (flags) == -1)
        return (vm_addr)NULL;

    DisablePreemption();

    if (EnoughSegments() == FALSE)
        ReclaimSegments();
        
    if ((seg = SegmentAlloc (paddr, len, flags)) == NULL)
        return (vm_addr)NULL;
  
    return seg->base;
}
示例#2
0
文件: vm.c 项目: Marvenlee/cheviot
SYSCALL vm_addr VirtualAlloc (vm_addr addr, ssize_t len, bits32_t flags)
{
    struct Segment *seg;

    
    addr = ALIGN_DOWN (addr, PAGE_SIZE);
    len = ALIGN_UP (len, PAGE_SIZE);

    if ((flags & CACHE_MASK) != CACHE_DEFAULT)
        return (vm_addr)NULL;
        
    flags = (flags & ~VM_SYSTEM_MASK) | MEM_ALLOC;
    
    DisablePreemption();
    
    if (EnoughSpace() == FALSE)
        RequestCompaction (len);
    
    if ((seg = SegmentAlloc ((vm_addr)NULL, len, flags)) == NULL)
            return (vm_addr)NULL;
    
    return seg->base;
}
示例#3
0
/*
 * HndCreateHandleTable
 *
 * Alocates and initializes a handle table.
 *
 */
HHANDLETABLE HndCreateHandleTable(UINT *pTypeFlags, UINT uTypeCount, UINT uADIndex)
{
    // sanity
    _ASSERTE(uTypeCount);

    // verify that we can handle the specified number of types
    if (uTypeCount > HANDLE_MAX_PUBLIC_TYPES)
    {
        // may need to increase HANDLE_MAX_INTERNAL_TYPES (by 4)
        _ASSERTE(FALSE);
        return NULL;
    }

    // verify that segment header layout we're using fits expected size
    if (sizeof(_TableSegmentHeader) > HANDLE_HEADER_SIZE)
    {
        // if you hit this then TABLE LAYOUT IS BROKEN                                             
        _ASSERTE(FALSE);
        return NULL;
    }

    // compute the size of the handle table allocation
    ULONG32 dwSize = sizeof(HandleTable) + (uTypeCount * sizeof(HandleTypeCache));

    // allocate the table
    HandleTable *pTable = (HandleTable *)HeapAlloc(g_hProcessHeap, HEAP_ZERO_MEMORY, dwSize);

    // if that failed then we are out of business
    if (!pTable)
    {
        // not much we can do really
        _ASSERTE(FALSE);
        return NULL;
    }

    // allocate the initial handle segment
    pTable->pSegmentList = SegmentAlloc(pTable);

    // if that failed then we are also out of business
    if (!pTable->pSegmentList)
    {
        // free the table's memory and get out
        HeapFree(g_hProcessHeap, 0, (HLOCAL)pTable);
        return NULL;
    }

    // initialize the table's lock
    pTable->pLock = new (pTable->_LockInstance) Crst("GC Heap Handle Table Lock", CrstHandleTable, TRUE, FALSE);

    // remember how many types we are supporting
    pTable->uTypeCount = uTypeCount;

    // Store user data
    pTable->uTableIndex = (UINT) -1;
    pTable->uADIndex = uADIndex;

    // loop over various arrays an initialize them
    UINT u;

    // initialize the type flags for the types we were passed
    for (u = 0; u < uTypeCount; u++)
        pTable->rgTypeFlags[u] = pTypeFlags[u];

    // preinit the rest to HNDF_NORMAL
    while (u < HANDLE_MAX_INTERNAL_TYPES)
        pTable->rgTypeFlags[u++] = HNDF_NORMAL;

    // initialize the main cache
    for (u = 0; u < uTypeCount; u++)
    {
        // at init time, the only non-zero field in a type cache is the free index
        pTable->rgMainCache[u].lFreeIndex = HANDLES_PER_CACHE_BANK;
    }

#ifdef _DEBUG
    // set up scanning stats
    pTable->_DEBUG_iMaxGen = -1;

    // Set up for tracking, if requested
    DEBUG_TrackInit();
#endif

    // all done - return the newly created table
    return (HHANDLETABLE)pTable;
}