VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibMisc.cpp@ 10626

Last change on this file since 10626 was 10626, checked in by vboxsync, 17 years ago

Windows guest logging R3: Bugfix for const-modifier.

  • Property svn:eol-style set to native
  • Property svn:keyword set to Id
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1/* $Id: VBoxGuestR3LibMisc.cpp 10626 2008-07-15 07:38:26Z 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 */
40VBGLR3DECL(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 */
55VBGLR3DECL(int) VbglR3WriteLog(const char *pch, size_t cb)
56{
57#if defined(RT_OS_WINDOWS) /** @todo more OSes could take this route (solaris and freebsd for instance). */
58 /*
59 * Handle the entire request in one go.
60 */
61 if (!pch || !cb)
62 return VINF_SUCCESS;
63
64 void *pvTmp = RTMemDup(pch, cb);
65 if (!pvTmp)
66 return VERR_NO_MEMORY;
67 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cb), pvTmp, cb);
68 RTMemFree(pvTmp);
69 return rc;
70
71#else
72 /*
73 * *BSD does not accept more than 4KB per ioctl request, while
74 * Linux can't express sizes above 8KB, so, split it up into 2KB chunks.
75 */
76# define STEP 2048
77 int rc = VINF_SUCCESS;
78 for (size_t off = 0; off < cb && RT_SUCCESS(rc); off += STEP)
79 {
80 size_t cbStep = RT_MIN(cb - off, STEP);
81 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cbStep), (char *)pch + off, cbStep);
82 }
83# undef STEP
84 return rc;
85#endif
86}
87
88
89/**
90 * Change the IRQ filter mask.
91 *
92 * @returns IPRT status code
93 * @param fOr The OR mask.
94 * @param fNo The NOT mask.
95 */
96VBGLR3DECL(int) VbglR3CtlFilterMask(uint32_t fOr, uint32_t fNot)
97{
98#if defined(RT_OS_WINDOWS)
99 /** @todo Not yet implemented. */
100 return VERR_NOT_SUPPORTED;
101
102#else
103
104 VBoxGuestFilterMaskInfo Info;
105 Info.u32OrMask = fOr;
106 Info.u32NotMask = fNot;
107 return vbglR3DoIOCtl(VBOXGUEST_IOCTL_CTL_FILTER_MASK, &Info, sizeof(Info));
108#endif
109}
110
111
112/**
113 * Report a change in the capabilities that we support to the host.
114 *
115 * @returns IPRT status value
116 * @param fOr Capabilities which have been added.
117 * @param fNot Capabilities which have been removed.
118 *
119 * @todo Move to a different file.
120 */
121VBGLR3DECL(int) VbglR3SetGuestCaps(uint32_t fOr, uint32_t fNot)
122{
123 VMMDevReqGuestCapabilities2 vmmreqGuestCaps;
124 int rc;
125
126 vmmdevInitRequest(&vmmreqGuestCaps.header, VMMDevReq_SetGuestCapabilities);
127 vmmreqGuestCaps.u32OrMask = fOr;
128 vmmreqGuestCaps.u32NotMask = fNot;
129 rc = vbglR3GRPerform(&vmmreqGuestCaps.header);
130#ifdef DEBUG
131 if (RT_SUCCESS(rc))
132 LogRel(("Successfully changed guest capabilities: or mask 0x%x, not mask 0x%x.\n",
133 fOr, fNot));
134 else
135 LogRel(("Failed to change guest capabilities: or mask 0x%x, not mask 0x%x. rc = %Rrc.\n",
136 fOr, fNot, rc));
137#endif
138 return rc;
139}
140
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette