VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxvideo/hgsmimemalloc.c@ 69346

最後變更 在這個檔案從69346是 69346,由 vboxsync 提交於 7 年 前

vboxvideo: scm updates (mit license formatting, 'this file is based on' instead of 'this code is based on').

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.0 KB
 
1/* $Id: hgsmimemalloc.c 69346 2017-10-26 13:36:28Z vboxsync $ */
2/*
3 * Copyright (C) 2017 Oracle Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following
12 * conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27/*
28 * Memory allocator
29 * ----------------
30 *
31 * Implementation
32 * --------------
33 *
34 * Since the X.Org driver is single threaded and works using an allocate,
35 * submit and free pattern, we replace the generic allocator with a simple
36 * Boolean. Need more be said?
37 */
38
39#include <VBoxVideoIPRT.h>
40#include <HGSMIMemAlloc.h>
41#include <HGSMI.h>
42
43int HGSMIMAInit(HGSMIMADATA *pMA, const HGSMIAREA *pArea,
44 HGSMIOFFSET *paDescriptors, uint32_t cDescriptors, HGSMISIZE cbMaxBlock,
45 const HGSMIENV *pEnv)
46{
47 (void)paDescriptors;
48 (void)cDescriptors;
49 (void)cbMaxBlock;
50 (void)pEnv;
51 if (!(pArea->cbArea < UINT32_C(0x80000000)))
52 return VERR_INVALID_PARAMETER;
53 if (!(pArea->cbArea >= HGSMI_MA_BLOCK_SIZE_MIN))
54 return VERR_INVALID_PARAMETER;
55
56 pMA->area = *pArea;
57 pMA->fAllocated = false;
58 return VINF_SUCCESS;
59}
60
61void HGSMIMAUninit(HGSMIMADATA *pMA)
62{
63 (void)pMA;
64}
65
66static HGSMIOFFSET HGSMIMAPointerToOffset(const HGSMIMADATA *pMA, const void *pv)
67{
68 if (HGSMIAreaContainsPointer(&pMA->area, pv))
69 {
70 return HGSMIPointerToOffset(&pMA->area, pv);
71 }
72
73 AssertFailed();
74 return HGSMIOFFSET_VOID;
75}
76
77static void *HGSMIMAOffsetToPointer(const HGSMIMADATA *pMA, HGSMIOFFSET off)
78{
79 if (HGSMIAreaContainsOffset(&pMA->area, off))
80 {
81 return HGSMIOffsetToPointer(&pMA->area, off);
82 }
83
84 AssertFailed();
85 return NULL;
86}
87
88void *HGSMIMAAlloc(HGSMIMADATA *pMA, HGSMISIZE cb)
89{
90 (void)cb;
91 if (pMA->fAllocated)
92 return NULL;
93 HGSMIOFFSET off = pMA->area.offBase;
94 return HGSMIMAOffsetToPointer(pMA, off);
95 pMA->fAllocated = true;
96}
97
98void HGSMIMAFree(HGSMIMADATA *pMA, void *pv)
99{
100 HGSMIOFFSET off = HGSMIMAPointerToOffset(pMA, pv);
101 if (off != HGSMIOFFSET_VOID)
102 {
103 pMA->fAllocated = false;
104 }
105 else
106 {
107 AssertFailed();
108 }
109}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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