1 | /* $Id: VBoxGuestR3LibMisc.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Misc.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2022 Oracle Corporation
|
---|
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 | * 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.
|
---|
22 | *
|
---|
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.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include <VBox/log.h>
|
---|
32 | #include "VBoxGuestR3LibInternal.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Change the IRQ filter mask.
|
---|
37 | *
|
---|
38 | * @returns IPRT status code.
|
---|
39 | * @param fOr The OR mask.
|
---|
40 | * @param fNot The NOT mask.
|
---|
41 | */
|
---|
42 | VBGLR3DECL(int) VbglR3CtlFilterMask(uint32_t fOr, uint32_t fNot)
|
---|
43 | {
|
---|
44 | VBGLIOCCHANGEFILTERMASK Info;
|
---|
45 | VBGLREQHDR_INIT(&Info.Hdr, CHANGE_FILTER_MASK);
|
---|
46 | Info.u.In.fOrMask = fOr;
|
---|
47 | Info.u.In.fNotMask = fNot;
|
---|
48 | return vbglR3DoIOCtl(VBGL_IOCTL_CHANGE_FILTER_MASK, &Info.Hdr, sizeof(Info));
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Report a change in the capabilities that we support to the host.
|
---|
54 | *
|
---|
55 | * @returns IPRT status code.
|
---|
56 | * @param fOr Capabilities which have been added.
|
---|
57 | * @param fNot Capabilities which have been removed.
|
---|
58 | *
|
---|
59 | * @todo Move to a different file.
|
---|
60 | */
|
---|
61 | VBGLR3DECL(int) VbglR3SetGuestCaps(uint32_t fOr, uint32_t fNot)
|
---|
62 | {
|
---|
63 | VBGLIOCSETGUESTCAPS Info;
|
---|
64 | VBGLREQHDR_INIT(&Info.Hdr, CHANGE_GUEST_CAPABILITIES);
|
---|
65 | Info.u.In.fOrMask = fOr;
|
---|
66 | Info.u.In.fNotMask = fNot;
|
---|
67 | return vbglR3DoIOCtl(VBGL_IOCTL_CHANGE_GUEST_CAPABILITIES, &Info.Hdr, sizeof(Info));
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Acquire capabilities to report to the host.
|
---|
73 | *
|
---|
74 | * The capabilities which can be acquired are the same as those reported by
|
---|
75 | * VbglR3SetGuestCaps, and once a capability has been acquired once is is
|
---|
76 | * switched to "acquire mode" and can no longer be set using VbglR3SetGuestCaps.
|
---|
77 | * Capabilities can also be switched to acquire mode without actually being
|
---|
78 | * acquired. A client can not acquire a capability which has been acquired and
|
---|
79 | * not released by another client. Capabilities acquired are automatically
|
---|
80 | * released on session termination.
|
---|
81 | *
|
---|
82 | * @returns IPRT status code
|
---|
83 | * @returns VERR_RESOURCE_BUSY and acquires nothing if another client has
|
---|
84 | * acquired and not released at least one of the @a fOr capabilities
|
---|
85 | * @param fOr Capabilities to acquire or to switch to acquire mode
|
---|
86 | * @param fNot Capabilities to release
|
---|
87 | * @param fConfig if set, capabilities in @a fOr are switched to acquire mode
|
---|
88 | * but not acquired, and @a fNot is ignored. See
|
---|
89 | * VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE for details.
|
---|
90 | */
|
---|
91 | VBGLR3DECL(int) VbglR3AcquireGuestCaps(uint32_t fOr, uint32_t fNot, bool fConfig)
|
---|
92 | {
|
---|
93 | VBGLIOCACQUIREGUESTCAPS Info;
|
---|
94 | VBGLREQHDR_INIT(&Info.Hdr, ACQUIRE_GUEST_CAPABILITIES);
|
---|
95 | Info.u.In.fFlags = fConfig ? VBGL_IOC_AGC_FLAGS_CONFIG_ACQUIRE_MODE : VBGL_IOC_AGC_FLAGS_DEFAULT;
|
---|
96 | Info.u.In.fOrMask = fOr;
|
---|
97 | Info.u.In.fNotMask = fNot;
|
---|
98 | return vbglR3DoIOCtl(VBGL_IOCTL_ACQUIRE_GUEST_CAPABILITIES, &Info.Hdr, sizeof(Info));
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Query the session ID of this VM.
|
---|
104 | *
|
---|
105 | * The session id is an unique identifier that gets changed for each VM start,
|
---|
106 | * reset or restore. Useful for detection a VM restore.
|
---|
107 | *
|
---|
108 | * @returns IPRT status code.
|
---|
109 | * @param pu64IdSession Session id (out). This is NOT changed on
|
---|
110 | * failure, so the caller can depend on this to
|
---|
111 | * deal with backward compatibility (see
|
---|
112 | * VBoxServiceVMInfoWorker() for an example.)
|
---|
113 | */
|
---|
114 | VBGLR3DECL(int) VbglR3GetSessionId(uint64_t *pu64IdSession)
|
---|
115 | {
|
---|
116 | VMMDevReqSessionId Req;
|
---|
117 |
|
---|
118 | vmmdevInitRequest(&Req.header, VMMDevReq_GetSessionId);
|
---|
119 | Req.idSession = 0;
|
---|
120 | int rc = vbglR3GRPerform(&Req.header);
|
---|
121 | if (RT_SUCCESS(rc))
|
---|
122 | *pu64IdSession = Req.idSession;
|
---|
123 |
|
---|
124 | return rc;
|
---|
125 | }
|
---|