VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibMisc.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keyword set to Id
  • Property svn:keywords set to Id Revision
File size: 5.1 KB
Line 
1/* $Id: VBoxGuestR3LibMisc.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Misc.
4 */
5
6/*
7 * Copyright (C) 2007-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <VBox/log.h>
42#include "VBoxGuestR3LibInternal.h"
43
44
45/**
46 * Change the IRQ filter mask.
47 *
48 * @returns IPRT status code.
49 * @param fOr The OR mask.
50 * @param fNot The NOT mask.
51 */
52VBGLR3DECL(int) VbglR3CtlFilterMask(uint32_t fOr, uint32_t fNot)
53{
54 VBGLIOCCHANGEFILTERMASK Info;
55 VBGLREQHDR_INIT(&Info.Hdr, CHANGE_FILTER_MASK);
56 Info.u.In.fOrMask = fOr;
57 Info.u.In.fNotMask = fNot;
58 return vbglR3DoIOCtl(VBGL_IOCTL_CHANGE_FILTER_MASK, &Info.Hdr, sizeof(Info));
59}
60
61
62/**
63 * Report a change in the capabilities that we support to the host.
64 *
65 * @returns IPRT status code.
66 * @param fOr Capabilities which have been added.
67 * @param fNot Capabilities which have been removed.
68 *
69 * @todo Move to a different file.
70 */
71VBGLR3DECL(int) VbglR3SetGuestCaps(uint32_t fOr, uint32_t fNot)
72{
73 VBGLIOCSETGUESTCAPS Info;
74 VBGLREQHDR_INIT(&Info.Hdr, CHANGE_GUEST_CAPABILITIES);
75 Info.u.In.fOrMask = fOr;
76 Info.u.In.fNotMask = fNot;
77 return vbglR3DoIOCtl(VBGL_IOCTL_CHANGE_GUEST_CAPABILITIES, &Info.Hdr, sizeof(Info));
78}
79
80
81/**
82 * Acquire capabilities to report to the host.
83 *
84 * The capabilities which can be acquired are the same as those reported by
85 * VbglR3SetGuestCaps, and once a capability has been acquired once is is
86 * switched to "acquire mode" and can no longer be set using VbglR3SetGuestCaps.
87 * Capabilities can also be switched to acquire mode without actually being
88 * acquired. A client can not acquire a capability which has been acquired and
89 * not released by another client. Capabilities acquired are automatically
90 * released on session termination.
91 *
92 * @returns IPRT status code
93 * @returns VERR_RESOURCE_BUSY and acquires nothing if another client has
94 * acquired and not released at least one of the @a fOr capabilities
95 * @param fOr Capabilities to acquire or to switch to acquire mode
96 * @param fNot Capabilities to release
97 * @param fConfig if set, capabilities in @a fOr are switched to acquire mode
98 * but not acquired, and @a fNot is ignored. See
99 * VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE for details.
100 */
101VBGLR3DECL(int) VbglR3AcquireGuestCaps(uint32_t fOr, uint32_t fNot, bool fConfig)
102{
103 VBGLIOCACQUIREGUESTCAPS Info;
104 VBGLREQHDR_INIT(&Info.Hdr, ACQUIRE_GUEST_CAPABILITIES);
105 Info.u.In.fFlags = fConfig ? VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE : VBGL_IOC_AGC_FLAGS_DEFAULT;
106 Info.u.In.fOrMask = fOr;
107 Info.u.In.fNotMask = fNot;
108 return vbglR3DoIOCtl(VBGL_IOCTL_ACQUIRE_GUEST_CAPABILITIES, &Info.Hdr, sizeof(Info));
109}
110
111
112/**
113 * Query the session ID of this VM.
114 *
115 * The session id is an unique identifier that gets changed for each VM start,
116 * reset or restore. Useful for detection a VM restore.
117 *
118 * @returns IPRT status code.
119 * @param pu64IdSession Session id (out). This is NOT changed on
120 * failure, so the caller can depend on this to
121 * deal with backward compatibility (see
122 * VBoxServiceVMInfoWorker() for an example.)
123 */
124VBGLR3DECL(int) VbglR3GetSessionId(uint64_t *pu64IdSession)
125{
126 VMMDevReqSessionId Req;
127
128 vmmdevInitRequest(&Req.header, VMMDevReq_GetSessionId);
129 Req.idSession = 0;
130 int rc = vbglR3GRPerform(&Req.header);
131 if (RT_SUCCESS(rc))
132 *pu64IdSession = Req.idSession;
133
134 return rc;
135}
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