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