1 | /* $Id: VBoxGuestR3LibMisc.cpp 10638 2008-07-15 10:01:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Misc.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007 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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include <iprt/mem.h>
|
---|
27 | #include <VBox/log.h>
|
---|
28 |
|
---|
29 | #include "VBGLR3Internal.h"
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Cause any pending WaitEvent calls (VBOXGUEST_IOCTL_WAITEVENT) to return
|
---|
33 | * with a VERR_INTERRUPTED status.
|
---|
34 | *
|
---|
35 | * Can be used in combination with a termination flag variable for interrupting
|
---|
36 | * event loops. Avoiding race conditions is the responsibility of the caller.
|
---|
37 | *
|
---|
38 | * @returns IPRT status code
|
---|
39 | */
|
---|
40 | VBGLR3DECL(int) VbglR3InterruptEventWaits(void)
|
---|
41 | {
|
---|
42 | return vbglR3DoIOCtl(VBOXGUEST_IOCTL_CANCEL_ALL_WAITEVENTS, 0, 0);
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Write to the backdoor logger from ring 3 guest code.
|
---|
48 | *
|
---|
49 | * @returns IPRT status code
|
---|
50 | *
|
---|
51 | * @remarks This currently does not accept more than 255 bytes of data at
|
---|
52 | * one time. It should probably be rewritten to use pass a pointer
|
---|
53 | * in the IOCtl.
|
---|
54 | */
|
---|
55 | VBGLR3DECL(int) VbglR3WriteLog(const char *pch, size_t cb)
|
---|
56 | {
|
---|
57 | /*
|
---|
58 | * Quietly skip NULL strings.
|
---|
59 | * (Happens in the RTLogBackdoorPrintf case.)
|
---|
60 | */
|
---|
61 | if (!cb)
|
---|
62 | return VINF_SUCCESS;
|
---|
63 | if (!VALID_PTR(pch))
|
---|
64 | return VERR_INVALID_POINTER;
|
---|
65 |
|
---|
66 | #ifdef RT_OS_WINDOWS
|
---|
67 | /*
|
---|
68 | * Duplicate the string as it may be read only (a C string).
|
---|
69 | */
|
---|
70 | void *pvTmp = RTMemDup(pch, cb);
|
---|
71 | if (!pvTmp)
|
---|
72 | return VERR_NO_MEMORY;
|
---|
73 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cb), pvTmp, cb);
|
---|
74 | RTMemFree(pvTmp);
|
---|
75 | return rc;
|
---|
76 |
|
---|
77 | #elif 0 /** @todo Several OSes could take this route (solaris and freebsd for instance). */
|
---|
78 | /*
|
---|
79 | * Handle the entire request in one go.
|
---|
80 | */
|
---|
81 | return vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cb), pvTmp, cb);
|
---|
82 |
|
---|
83 | #else
|
---|
84 | /*
|
---|
85 | * *BSD does not accept more than 4KB per ioctl request, while
|
---|
86 | * Linux can't express sizes above 8KB, so, split it up into 2KB chunks.
|
---|
87 | */
|
---|
88 | # define STEP 2048
|
---|
89 | int rc = VINF_SUCCESS;
|
---|
90 | for (size_t off = 0; off < cb && RT_SUCCESS(rc); off += STEP)
|
---|
91 | {
|
---|
92 | size_t cbStep = RT_MIN(cb - off, STEP);
|
---|
93 | rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cbStep), (char *)pch + off, cbStep);
|
---|
94 | }
|
---|
95 | # undef STEP
|
---|
96 | return rc;
|
---|
97 | #endif
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Change the IRQ filter mask.
|
---|
103 | *
|
---|
104 | * @returns IPRT status code
|
---|
105 | * @param fOr The OR mask.
|
---|
106 | * @param fNo The NOT mask.
|
---|
107 | */
|
---|
108 | VBGLR3DECL(int) VbglR3CtlFilterMask(uint32_t fOr, uint32_t fNot)
|
---|
109 | {
|
---|
110 | #if defined(RT_OS_WINDOWS)
|
---|
111 | /** @todo Not yet implemented. */
|
---|
112 | return VERR_NOT_SUPPORTED;
|
---|
113 |
|
---|
114 | #else
|
---|
115 |
|
---|
116 | VBoxGuestFilterMaskInfo Info;
|
---|
117 | Info.u32OrMask = fOr;
|
---|
118 | Info.u32NotMask = fNot;
|
---|
119 | return vbglR3DoIOCtl(VBOXGUEST_IOCTL_CTL_FILTER_MASK, &Info, sizeof(Info));
|
---|
120 | #endif
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Report a change in the capabilities that we support to the host.
|
---|
126 | *
|
---|
127 | * @returns IPRT status value
|
---|
128 | * @param fOr Capabilities which have been added.
|
---|
129 | * @param fNot Capabilities which have been removed.
|
---|
130 | *
|
---|
131 | * @todo Move to a different file.
|
---|
132 | */
|
---|
133 | VBGLR3DECL(int) VbglR3SetGuestCaps(uint32_t fOr, uint32_t fNot)
|
---|
134 | {
|
---|
135 | VMMDevReqGuestCapabilities2 vmmreqGuestCaps;
|
---|
136 | int rc;
|
---|
137 |
|
---|
138 | vmmdevInitRequest(&vmmreqGuestCaps.header, VMMDevReq_SetGuestCapabilities);
|
---|
139 | vmmreqGuestCaps.u32OrMask = fOr;
|
---|
140 | vmmreqGuestCaps.u32NotMask = fNot;
|
---|
141 | rc = vbglR3GRPerform(&vmmreqGuestCaps.header);
|
---|
142 | #ifdef DEBUG
|
---|
143 | if (RT_SUCCESS(rc))
|
---|
144 | LogRel(("Successfully changed guest capabilities: or mask 0x%x, not mask 0x%x.\n",
|
---|
145 | fOr, fNot));
|
---|
146 | else
|
---|
147 | LogRel(("Failed to change guest capabilities: or mask 0x%x, not mask 0x%x. rc = %Rrc.\n",
|
---|
148 | fOr, fNot, rc));
|
---|
149 | #endif
|
---|
150 | return rc;
|
---|
151 | }
|
---|
152 |
|
---|