1
/* $Revision: 87431 $ */
3
* VBoxGuestLibR0 - Generic VMMDev request management.
7
* Copyright (C) 2006-2013 Oracle Corporation
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.
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.
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.
27
#include "VBGLInternal.h"
29
#include <iprt/asm-amd64-x86.h>
30
#include <iprt/assert.h>
31
#include <iprt/string.h>
33
DECLVBGL(int) VbglGRVerify (const VMMDevRequestHeader *pReq, size_t cbReq)
37
if (!pReq || cbReq < sizeof (VMMDevRequestHeader))
39
dprintf(("VbglGRVerify: Invalid parameter: pReq = %p, cbReq = %d\n", pReq, cbReq));
40
return VERR_INVALID_PARAMETER;
43
if (pReq->size > cbReq)
45
dprintf(("VbglGRVerify: request size %d > buffer size %d\n", pReq->size, cbReq));
46
return VERR_INVALID_PARAMETER;
49
/* The request size must correspond to the request type. */
50
cbReqExpected = vmmdevGetRequestSize(pReq->requestType);
52
if (cbReq < cbReqExpected)
54
dprintf(("VbglGRVerify: buffer size %d < expected size %d\n", cbReq, cbReqExpected));
55
return VERR_INVALID_PARAMETER;
58
if (cbReqExpected == cbReq)
60
/* This is most likely a fixed size request, and in this case the request size
61
* must be also equal to the expected size.
63
if (pReq->size != cbReqExpected)
65
dprintf(("VbglGRVerify: request size %d != expected size %d\n", pReq->size, cbReqExpected));
66
return VERR_INVALID_PARAMETER;
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.
76
* Note: Keep this list sorted for easier human lookup!
78
if ( pReq->requestType == VMMDevReq_ChangeMemBalloon
79
#ifdef VBOX_WITH_64_BITS_GUESTS
80
|| pReq->requestType == VMMDevReq_HGCMCall32
81
|| pReq->requestType == VMMDevReq_HGCMCall64
83
|| pReq->requestType == VMMDevReq_HGCMCall
84
#endif /* VBOX_WITH_64_BITS_GUESTS */
85
|| pReq->requestType == VMMDevReq_RegisterSharedModule
86
|| pReq->requestType == VMMDevReq_ReportGuestUserState
87
|| pReq->requestType == VMMDevReq_LogString
88
|| pReq->requestType == VMMDevReq_SetPointerShape
89
|| pReq->requestType == VMMDevReq_VideoSetVisibleRegion)
91
if (cbReq > VMMDEV_MAX_VMMDEVREQ_SIZE)
93
dprintf(("VbglGRVerify: VMMDevReq_LogString: buffer size %d too big\n", cbReq));
94
return VERR_BUFFER_OVERFLOW; /* @todo is this error code ok? */
99
dprintf(("VbglGRVerify: request size %d > buffer size %d\n", pReq->size, cbReq));
100
return VERR_IO_BAD_LENGTH; /* @todo is this error code ok? */
106
DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType)
108
VMMDevRequestHeader *pReq;
109
int rc = vbglR0Enter ();
114
if (!ppReq || cbSize < sizeof (VMMDevRequestHeader))
116
dprintf(("VbglGRAlloc: Invalid parameter: ppReq = %p, cbSize = %u\n", ppReq, cbSize));
117
return VERR_INVALID_PARAMETER;
120
pReq = (VMMDevRequestHeader *)VbglPhysHeapAlloc (cbSize);
123
AssertMsgFailed(("VbglGRAlloc: no memory\n"));
128
memset(pReq, 0xAA, cbSize);
131
pReq->version = VMMDEV_REQUEST_HEADER_VERSION;
132
pReq->requestType = reqType;
133
pReq->rc = VERR_GENERAL_FAILURE;
143
DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq)
146
int rc = vbglR0Enter ();
152
return VERR_INVALID_PARAMETER;
154
physaddr = VbglPhysHeapGetPhysAddr (pReq);
156
|| (physaddr >> 32) != 0) /* Port IO is 32 bit. */
158
rc = VERR_VBGL_INVALID_ADDR;
162
ASMOutU32(g_vbgldata.portVMMDev + VMMDEV_PORT_OFF_REQUEST, (uint32_t)physaddr);
163
/* Make the compiler aware that the host has changed memory. */
164
ASMCompilerBarrier();
170
DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq)
172
int rc = vbglR0Enter ();
177
VbglPhysHeapFree (pReq);