VirtualBox

source: vbox/trunk/include/VBox/Graphics/HGSMIMemAlloc.h@ 106165

Last change on this file since 106165 was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: HGSMIMemAlloc.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Host Guest Shared Memory Interface (HGSMI) - Memory allocator.
4 */
5
6/*
7 * Copyright (C) 2014-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 VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h
38#define VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include "HGSMIDefs.h"
44#include "VBoxVideoIPRT.h"
45
46
47/* Descriptor. */
48#define HGSMI_MA_DESC_OFFSET_MASK UINT32_C(0xFFFFFFE0)
49#define HGSMI_MA_DESC_FREE_MASK UINT32_C(0x00000010)
50#define HGSMI_MA_DESC_ORDER_MASK UINT32_C(0x0000000F)
51
52#define HGSMI_MA_DESC_OFFSET(d) ((d) & HGSMI_MA_DESC_OFFSET_MASK)
53#define HGSMI_MA_DESC_IS_FREE(d) (((d) & HGSMI_MA_DESC_FREE_MASK) != 0)
54#define HGSMI_MA_DESC_ORDER(d) ((d) & HGSMI_MA_DESC_ORDER_MASK)
55
56#define HGSMI_MA_DESC_ORDER_BASE UINT32_C(5)
57
58#define HGSMI_MA_BLOCK_SIZE_MIN (UINT32_C(1) << (HGSMI_MA_DESC_ORDER_BASE + 0))
59#define HGSMI_MA_BLOCK_SIZE_MAX (UINT32_C(1) << (HGSMI_MA_DESC_ORDER_BASE + HGSMI_MA_DESC_ORDER_MASK))
60
61/* HGSMI_MA_DESC_ORDER_BASE must correspond to HGSMI_MA_DESC_OFFSET_MASK. */
62AssertCompile((~HGSMI_MA_DESC_OFFSET_MASK + 1) == HGSMI_MA_BLOCK_SIZE_MIN);
63
64
65typedef struct HGSMIMABLOCK
66{
67 RTLISTNODE nodeBlock;
68 RTLISTNODE nodeFree;
69 HGSMIOFFSET descriptor;
70} HGSMIMABLOCK;
71
72typedef struct HGSMIMADATA
73{
74 HGSMIAREA area;
75 HGSMIENV env;
76 HGSMISIZE cbMaxBlock;
77
78 uint32_t cBlocks; /* How many blocks in the listBlocks. */
79 RTLISTANCHOR listBlocks; /* All memory blocks, sorted. */
80 RTLISTANCHOR aListFreeBlocks[HGSMI_MA_DESC_ORDER_MASK + 1]; /* For free blocks of each order. */
81} HGSMIMADATA;
82
83RT_C_DECLS_BEGIN
84
85int HGSMIMAInit(HGSMIMADATA *pMA, const HGSMIAREA *pArea,
86 HGSMIOFFSET *paDescriptors, uint32_t cDescriptors, HGSMISIZE cbMaxBlock,
87 const HGSMIENV *pEnv);
88void HGSMIMAUninit(HGSMIMADATA *pMA);
89
90void RT_UNTRUSTED_VOLATILE_HSTGST *HGSMIMAAlloc(HGSMIMADATA *pMA, HGSMISIZE cb);
91void HGSMIMAFree(HGSMIMADATA *pMA, void RT_UNTRUSTED_VOLATILE_GUEST *pv);
92
93HGSMIMABLOCK *HGSMIMASearchOffset(HGSMIMADATA *pMA, HGSMIOFFSET off);
94
95uint32_t HGSMIPopCnt32(uint32_t u32);
96
97DECLINLINE(HGSMISIZE) HGSMIMAOrder2Size(HGSMIOFFSET order)
98{
99 return (UINT32_C(1) << (HGSMI_MA_DESC_ORDER_BASE + order));
100}
101
102DECLINLINE(HGSMIOFFSET) HGSMIMASize2Order(HGSMISIZE cb)
103{
104 HGSMIOFFSET order = HGSMIPopCnt32(cb - 1) - HGSMI_MA_DESC_ORDER_BASE;
105#ifdef HGSMI_STRICT
106 Assert(HGSMIMAOrder2Size(order) == cb);
107#endif
108 return order;
109}
110
111RT_C_DECLS_END
112
113#endif /* !VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h */
Note: See TracBrowser for help on using the repository browser.

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