1 | /* $Id: bs3-cmn-memory.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - Internal Memory Structures, Variables and Functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef BS3KIT_INCLUDED_bs3_cmn_memory_h
|
---|
38 | #define BS3KIT_INCLUDED_bs3_cmn_memory_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include "bs3kit.h"
|
---|
44 | #include <iprt/asm.h>
|
---|
45 |
|
---|
46 | RT_C_DECLS_BEGIN;
|
---|
47 |
|
---|
48 |
|
---|
49 | typedef union BS3SLABCTLLOW
|
---|
50 | {
|
---|
51 | BS3SLABCTL Core;
|
---|
52 | uint32_t au32Alloc[(sizeof(BS3SLABCTL) + (0xA0000 / _4K / 8) ) / 4];
|
---|
53 | } BS3SLABCTLLOW;
|
---|
54 | #ifndef DOXYGEN_RUNNING
|
---|
55 | # define g_Bs3Mem4KLow BS3_DATA_NM(g_Bs3Mem4KLow)
|
---|
56 | #endif
|
---|
57 | extern BS3SLABCTLLOW g_Bs3Mem4KLow;
|
---|
58 |
|
---|
59 |
|
---|
60 | typedef union BS3SLABCTLUPPERTILED
|
---|
61 | {
|
---|
62 | BS3SLABCTL Core;
|
---|
63 | uint32_t au32Alloc[(sizeof(BS3SLABCTL) + ((BS3_SEL_TILED_AREA_SIZE - _1M) / _4K / 8) ) / 4];
|
---|
64 | } BS3SLABCTLUPPERTILED;
|
---|
65 | #ifndef DOXYGEN_RUNNING
|
---|
66 | # define g_Bs3Mem4KUpperTiled BS3_DATA_NM(g_Bs3Mem4KUpperTiled)
|
---|
67 | #endif
|
---|
68 | extern BS3SLABCTLUPPERTILED g_Bs3Mem4KUpperTiled;
|
---|
69 |
|
---|
70 |
|
---|
71 | /** The number of chunk sizes used by the slab list arrays
|
---|
72 | * (g_aBs3LowSlabLists, g_aBs3UpperTiledSlabLists, more?). */
|
---|
73 | #define BS3_MEM_SLAB_LIST_COUNT 6
|
---|
74 |
|
---|
75 | #ifndef DOXYGEN_RUNNING
|
---|
76 | # define g_aiBs3SlabListsByPowerOfTwo BS3_DATA_NM(g_aiBs3SlabListsByPowerOfTwo)
|
---|
77 | # define g_acbBs3SlabLists BS3_DATA_NM(g_acbBs3SlabLists)
|
---|
78 | # define g_aBs3LowSlabLists BS3_DATA_NM(g_aBs3LowSlabLists)
|
---|
79 | # define g_aBs3UpperTiledSlabLists BS3_DATA_NM(g_aBs3UpperTiledSlabLists)
|
---|
80 | # define g_cbBs3SlabCtlSizesforLists BS3_DATA_NM(g_cbBs3SlabCtlSizesforLists)
|
---|
81 | #endif
|
---|
82 | extern uint8_t const g_aiBs3SlabListsByPowerOfTwo[12];
|
---|
83 | extern uint16_t const g_acbBs3SlabLists[BS3_MEM_SLAB_LIST_COUNT];
|
---|
84 | extern BS3SLABHEAD g_aBs3LowSlabLists[BS3_MEM_SLAB_LIST_COUNT];
|
---|
85 | extern BS3SLABHEAD g_aBs3UpperTiledSlabLists[BS3_MEM_SLAB_LIST_COUNT];
|
---|
86 | extern uint16_t const g_cbBs3SlabCtlSizesforLists[BS3_MEM_SLAB_LIST_COUNT];
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Translates a allocation request size to a slab list index.
|
---|
91 | *
|
---|
92 | * @returns Slab list index if small request, UINT8_MAX if large.
|
---|
93 | * @param cbRequest The number of bytes requested.
|
---|
94 | */
|
---|
95 | DECLINLINE(uint8_t) bs3MemSizeToSlabListIndex(size_t cbRequest)
|
---|
96 | {
|
---|
97 | if (cbRequest <= g_acbBs3SlabLists[BS3_MEM_SLAB_LIST_COUNT - 1])
|
---|
98 | {
|
---|
99 | unsigned idx = cbRequest ? ASMBitLastSetU16((uint16_t)(cbRequest - 1)) : 0;
|
---|
100 | return g_aiBs3SlabListsByPowerOfTwo[idx];
|
---|
101 | }
|
---|
102 | return UINT8_MAX;
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | RT_C_DECLS_END;
|
---|
107 |
|
---|
108 | #endif /* !BS3KIT_INCLUDED_bs3_cmn_memory_h */
|
---|
109 |
|
---|