VirtualBox

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

Last change on this file since 85704 was 82968, checked in by vboxsync, 5 years 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.5 KB
Line 
1/* $Id: HGSMIMemAlloc.h 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VBox Host Guest Shared Memory Interface (HGSMI) - Memory allocator.
4 */
5
6/*
7 * Copyright (C) 2014-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.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#ifndef VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h
28#define VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include "HGSMIDefs.h"
34#include "VBoxVideoIPRT.h"
35
36
37/* Descriptor. */
38#define HGSMI_MA_DESC_OFFSET_MASK UINT32_C(0xFFFFFFE0)
39#define HGSMI_MA_DESC_FREE_MASK UINT32_C(0x00000010)
40#define HGSMI_MA_DESC_ORDER_MASK UINT32_C(0x0000000F)
41
42#define HGSMI_MA_DESC_OFFSET(d) ((d) & HGSMI_MA_DESC_OFFSET_MASK)
43#define HGSMI_MA_DESC_IS_FREE(d) (((d) & HGSMI_MA_DESC_FREE_MASK) != 0)
44#define HGSMI_MA_DESC_ORDER(d) ((d) & HGSMI_MA_DESC_ORDER_MASK)
45
46#define HGSMI_MA_DESC_ORDER_BASE UINT32_C(5)
47
48#define HGSMI_MA_BLOCK_SIZE_MIN (UINT32_C(1) << (HGSMI_MA_DESC_ORDER_BASE + 0))
49#define HGSMI_MA_BLOCK_SIZE_MAX (UINT32_C(1) << (HGSMI_MA_DESC_ORDER_BASE + HGSMI_MA_DESC_ORDER_MASK))
50
51/* HGSMI_MA_DESC_ORDER_BASE must correspond to HGSMI_MA_DESC_OFFSET_MASK. */
52AssertCompile((~HGSMI_MA_DESC_OFFSET_MASK + 1) == HGSMI_MA_BLOCK_SIZE_MIN);
53
54
55typedef struct HGSMIMABLOCK
56{
57 RTLISTNODE nodeBlock;
58 RTLISTNODE nodeFree;
59 HGSMIOFFSET descriptor;
60} HGSMIMABLOCK;
61
62typedef struct HGSMIMADATA
63{
64 HGSMIAREA area;
65 HGSMIENV env;
66 HGSMISIZE cbMaxBlock;
67
68 uint32_t cBlocks; /* How many blocks in the listBlocks. */
69 RTLISTANCHOR listBlocks; /* All memory blocks, sorted. */
70 RTLISTANCHOR aListFreeBlocks[HGSMI_MA_DESC_ORDER_MASK + 1]; /* For free blocks of each order. */
71} HGSMIMADATA;
72
73RT_C_DECLS_BEGIN
74
75int HGSMIMAInit(HGSMIMADATA *pMA, const HGSMIAREA *pArea,
76 HGSMIOFFSET *paDescriptors, uint32_t cDescriptors, HGSMISIZE cbMaxBlock,
77 const HGSMIENV *pEnv);
78void HGSMIMAUninit(HGSMIMADATA *pMA);
79
80void RT_UNTRUSTED_VOLATILE_HSTGST *HGSMIMAAlloc(HGSMIMADATA *pMA, HGSMISIZE cb);
81void HGSMIMAFree(HGSMIMADATA *pMA, void RT_UNTRUSTED_VOLATILE_GUEST *pv);
82
83HGSMIMABLOCK *HGSMIMASearchOffset(HGSMIMADATA *pMA, HGSMIOFFSET off);
84
85uint32_t HGSMIPopCnt32(uint32_t u32);
86
87DECLINLINE(HGSMISIZE) HGSMIMAOrder2Size(HGSMIOFFSET order)
88{
89 return (UINT32_C(1) << (HGSMI_MA_DESC_ORDER_BASE + order));
90}
91
92DECLINLINE(HGSMIOFFSET) HGSMIMASize2Order(HGSMISIZE cb)
93{
94 HGSMIOFFSET order = HGSMIPopCnt32(cb - 1) - HGSMI_MA_DESC_ORDER_BASE;
95#ifdef HGSMI_STRICT
96 Assert(HGSMIMAOrder2Size(order) == cb);
97#endif
98 return order;
99}
100
101RT_C_DECLS_END
102
103#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