VirtualBox

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

Last change on this file since 2423 was 2304, checked in by vboxsync, 18 years ago

ASMMemoryClobber -> ASMCompilerBarrier + MSC (untested)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1/** @file
2 *
3 * VBoxGuestLib - A support library for VirtualBox guest additions:
4 * Generic VMMDev request management
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#include <VBox/VBoxGuestLib.h>
24#include "VBGLInternal.h"
25#include <iprt/asm.h>
26#include <iprt/string.h>
27
28DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType)
29{
30 int rc = VbglEnter ();
31 VMMDevRequestHeader *pReq;
32
33 if (VBOX_FAILURE(rc))
34 return rc;
35
36 if (!ppReq || cbSize < sizeof (VMMDevRequestHeader))
37 {
38 dprintf(("VbglGRAlloc: Invalid parameter: ppReq = %p, cbSize = %d\n", ppReq, cbSize));
39 return VERR_INVALID_PARAMETER;
40 }
41
42 pReq = (VMMDevRequestHeader *)VbglPhysHeapAlloc (cbSize);
43 if (!pReq)
44 {
45 dprintf(("VbglGRAlloc: no memory\n"));
46 rc = VERR_NO_MEMORY;
47 }
48 else
49 {
50 memset(pReq, 0xAA, cbSize);
51
52 pReq->size = cbSize;
53 pReq->version = VMMDEV_REQUEST_HEADER_VERSION;
54 pReq->requestType = reqType;
55 pReq->rc = VERR_GENERAL_FAILURE;
56 pReq->reserved1 = 0;
57 pReq->reserved2 = 0;
58
59 *ppReq = pReq;
60 }
61
62 return rc;
63}
64
65DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq)
66{
67 RTCCPHYS physaddr;
68 int rc = VbglEnter ();
69
70 if (VBOX_FAILURE(rc))
71 return rc;
72
73 if (!pReq)
74 return VERR_INVALID_PARAMETER;
75
76 if (g_vbgldata.portVMMDev == 0)
77 return VERR_VBGL_NOT_INITIALIZED;
78
79 physaddr = VbglPhysHeapGetPhysAddr (pReq);
80 if (!physaddr)
81 {
82 rc = VERR_VBGL_INVALID_ADDR;
83 }
84 else
85 {
86 ASMOutU32(g_vbgldata.portVMMDev + PORT_VMMDEV_REQUEST_OFFSET, (uint32_t)physaddr);
87 /* Make the compiler aware that the host has changed memory. */
88 ASMCompilerBarrier();
89 rc = pReq->rc;
90 }
91 return rc;
92}
93
94DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq)
95{
96 int rc = VbglEnter ();
97
98 if (VBOX_FAILURE(rc))
99 return;
100
101 VbglPhysHeapFree (pReq);
102}
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