VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemAlloc.c@ 59865

最後變更 在這個檔案從59865是 58814,由 vboxsync 提交於 9 年 前

bs3kit: Solved the FLAT fixup issue for OMF files, while for COFF/ELF (64-bit only) we cannot do absolute fixups in places we care about (like just won't do what we want it to). Made the object converter check for COFF relocation we don't want, found 4 in one file and convinced the compiler to use RIP relative addressing instead of image relative addressing. (There's an alternative I've been avoiding, which is linking LX and using RTLdr to do the final linking.)

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.6 KB
 
1/* $Id: bs3-cmn-MemAlloc.c 58814 2015-11-22 06:50:50Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3MemAlloc
4 */
5
6/*
7 * Copyright (C) 2007-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*********************************************************************************************************************************
28* Header Files *
29*********************************************************************************************************************************/
30#include "bs3kit-template-header.h"
31#include "bs3-cmn-memory.h"
32#include <iprt/asm.h>
33
34
35BS3_DECL(void BS3_FAR *) Bs3MemAlloc(BS3MEMKIND enmKind, size_t cb)
36{
37 void BS3_FAR *pvRet;
38 uint8_t idxSlabList = bs3MemSizeToSlabListIndex(cb);
39 if (idxSlabList < BS3_MEM_SLAB_LIST_COUNT)
40 {
41 /*
42 * Try allocate a chunk from the list.
43 */
44 PBS3SLABHEAD pHead = enmKind == BS3MEMKIND_REAL
45 ? &BS3_MSC64_FIXUP_HACK(BS3SLABHEAD, BS3_DATA_NM(g_aBs3LowSlabLists))[idxSlabList]
46 : &BS3_MSC64_FIXUP_HACK(BS3SLABHEAD, BS3_DATA_NM(g_aBs3UpperTiledSlabLists))[idxSlabList];
47
48 BS3_ASSERT(BS3_MSC64_FIXUP_HACK(BS3SLABHEAD, BS3_DATA_NM(g_aBs3LowSlabLists))[idxSlabList].cbChunk >= cb);
49 pvRet = Bs3SlabListAlloc(pHead);
50 if (pvRet)
51 { /* likely */ }
52 else
53 {
54 /*
55 * Grow the list.
56 */
57 PBS3SLABCTL pNew = (PBS3SLABCTL)Bs3SlabAlloc( enmKind == BS3MEMKIND_REAL
58 ? &BS3_DATA_NM(g_Bs3Mem4KLow).Core
59 : &BS3_DATA_NM(g_Bs3Mem4KUpperTiled).Core);
60 BS3_ASSERT(((uintptr_t)pNew & 0xfff) == 0);
61 if (pNew)
62 {
63 uint16_t const cbHdr = BS3_DATA_NM(g_cbBs3SlabCtlSizesforLists)[idxSlabList];
64 BS3_XPTR_AUTO(void, pvNew);
65 BS3_XPTR_SET(void, pvNew, pNew);
66
67 Bs3SlabInit(pNew, cbHdr, BS3_XPTR_GET_FLAT(void, pvNew) + cbHdr, _4K - cbHdr, pHead->cbChunk);
68 Bs3SlabListAdd(pHead, pNew);
69
70 pvRet = Bs3SlabListAlloc(pHead);
71 }
72 }
73 }
74 else
75 {
76 /*
77 * Allocate one or more pages.
78 */
79 size_t const cbAligned = RT_ALIGN_Z(cb, _4K);
80 uint16_t const cPages = cbAligned >> 12 /* div _4K */;
81
82 pvRet = Bs3SlabAllocEx(enmKind == BS3MEMKIND_REAL
83 ? &BS3_DATA_NM(g_Bs3Mem4KLow).Core : &BS3_DATA_NM(g_Bs3Mem4KUpperTiled).Core,
84 cPages,
85 cPages <= _64K / _4K ? BS3_SLAB_ALLOC_F_SAME_TILE : 0);
86 }
87 return pvRet;
88}
89
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette