VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/GenericRequest.cpp@ 28800

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/* $Revision: 28800 $ */
2/** @file
3 * VBoxGuestLibR0 - Generic VMMDev request management.
4 */
5
6/*
7 * Copyright (C) 2006-2009 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#include "VBGLInternal.h"
28#include <iprt/asm.h>
29#include <iprt/assert.h>
30#include <iprt/string.h>
31
32DECLVBGL(int) VbglGRVerify (const VMMDevRequestHeader *pReq, size_t cbReq)
33{
34 if (!pReq || cbReq < sizeof (VMMDevRequestHeader))
35 {
36 dprintf(("VbglGRVerify: Invalid parameter: pReq = %p, cbReq = %d\n", pReq, cbReq));
37 return VERR_INVALID_PARAMETER;
38 }
39
40 if (pReq->size > cbReq)
41 {
42 dprintf(("VbglGRVerify: request size %d > buffer size %d\n", pReq->size, cbReq));
43 return VERR_INVALID_PARAMETER;
44 }
45
46 /* The request size must correspond to the request type. */
47 size_t cbReqExpected = vmmdevGetRequestSize(pReq->requestType);
48
49 if (cbReq < cbReqExpected)
50 {
51 dprintf(("VbglGRVerify: buffer size %d < expected size %d\n", cbReq, cbReqExpected));
52 return VERR_INVALID_PARAMETER;
53 }
54
55 if (cbReqExpected == cbReq)
56 {
57 /* This is most likely a fixed size request, and in this case the request size
58 * must be also equal to the expected size.
59 */
60 if (pReq->size != cbReqExpected)
61 {
62 dprintf(("VbglGRVerify: request size %d != expected size %d\n", pReq->size, cbReqExpected));
63 return VERR_INVALID_PARAMETER;
64 }
65
66 return VINF_SUCCESS;
67 }
68
69 /* This can be a variable size request. Check the request type and limit the size
70 * to VMMDEV_MAX_VMMDEVREQ_SIZE, which is max size supported by the host.
71 */
72 if ( pReq->requestType == VMMDevReq_LogString
73 || pReq->requestType == VMMDevReq_VideoSetVisibleRegion
74 || pReq->requestType == VMMDevReq_SetPointerShape
75#ifdef VBOX_WITH_64_BITS_GUESTS
76 || pReq->requestType == VMMDevReq_HGCMCall32
77 || pReq->requestType == VMMDevReq_HGCMCall64
78#else
79 || pReq->requestType == VMMDevReq_HGCMCall
80#endif /* VBOX_WITH_64_BITS_GUESTS */
81 || pReq->requestType == VMMDevReq_ChangeMemBalloon)
82 {
83 if (cbReq > VMMDEV_MAX_VMMDEVREQ_SIZE)
84 {
85 dprintf(("VbglGRVerify: VMMDevReq_LogString: buffer size %d too big\n", cbReq));
86 return VERR_BUFFER_OVERFLOW; /* @todo is this error code ok? */
87 }
88 }
89 else
90 {
91 dprintf(("VbglGRVerify: request size %d > buffer size %d\n", pReq->size, cbReq));
92 return VERR_IO_BAD_LENGTH; /* @todo is this error code ok? */
93 }
94
95 return VINF_SUCCESS;
96}
97
98DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType)
99{
100 VMMDevRequestHeader *pReq;
101 int rc = vbglR0Enter ();
102
103 if (RT_FAILURE(rc))
104 return rc;
105
106 if (!ppReq || cbSize < sizeof (VMMDevRequestHeader))
107 {
108 dprintf(("VbglGRAlloc: Invalid parameter: ppReq = %p, cbSize = %d\n", ppReq, cbSize));
109 return VERR_INVALID_PARAMETER;
110 }
111
112 pReq = (VMMDevRequestHeader *)VbglPhysHeapAlloc (cbSize);
113 if (!pReq)
114 {
115 AssertMsgFailed(("VbglGRAlloc: no memory\n"));
116 rc = VERR_NO_MEMORY;
117 }
118 else
119 {
120 memset(pReq, 0xAA, cbSize);
121
122 pReq->size = cbSize;
123 pReq->version = VMMDEV_REQUEST_HEADER_VERSION;
124 pReq->requestType = reqType;
125 pReq->rc = VERR_GENERAL_FAILURE;
126 pReq->reserved1 = 0;
127 pReq->reserved2 = 0;
128
129 *ppReq = pReq;
130 }
131
132 return rc;
133}
134
135DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq)
136{
137 RTCCPHYS physaddr;
138 int rc = vbglR0Enter ();
139
140 if (RT_FAILURE(rc))
141 return rc;
142
143 if (!pReq)
144 return VERR_INVALID_PARAMETER;
145
146 physaddr = VbglPhysHeapGetPhysAddr (pReq);
147 if ( !physaddr
148 || (physaddr >> 32) != 0) /* Port IO is 32 bit. */
149 {
150 rc = VERR_VBGL_INVALID_ADDR;
151 }
152 else
153 {
154 ASMOutU32(g_vbgldata.portVMMDev + VMMDEV_PORT_OFF_REQUEST, (uint32_t)physaddr);
155 /* Make the compiler aware that the host has changed memory. */
156 ASMCompilerBarrier();
157 rc = pReq->rc;
158 }
159 return rc;
160}
161
162DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq)
163{
164 int rc = vbglR0Enter ();
165
166 if (RT_FAILURE(rc))
167 return;
168
169 VbglPhysHeapFree (pReq);
170}
171
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