VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h@ 92667

Last change on this file since 92667 was 92662, checked in by vboxsync, 3 years ago

VBoxService: Sketch for a trick for passing UTF-8 argv to child VBoxServices process - disabled and untested. bugref:10153

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/* $Id: VBoxServiceInternal.h 92662 2021-12-01 02:42:28Z vboxsync $ */
2/** @file
3 * VBoxService - Guest Additions Services.
4 */
5
6/*
7 * Copyright (C) 2007-2020 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
18#ifndef GA_INCLUDED_SRC_common_VBoxService_VBoxServiceInternal_h
19#define GA_INCLUDED_SRC_common_VBoxService_VBoxServiceInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <stdio.h>
25#ifdef RT_OS_WINDOWS
26# include <iprt/win/windows.h>
27# include <process.h> /* Needed for file version information. */
28#endif
29
30#include <iprt/list.h>
31#include <iprt/critsect.h>
32#include <iprt/path.h> /* RTPATH_MAX */
33#include <iprt/stdarg.h>
34
35#include <VBox/VBoxGuestLib.h>
36#include <VBox/HostServices/GuestControlSvc.h>
37
38
39#if 0 //!defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
40/** Special argv[1] value that indicates that argv is UTF-8.
41 * This causes RTR3Init to be called with RTR3INIT_FLAGS_UTF8_ARGV and helps
42 * work around potential issues caused by a user's locale config not being
43 * UTF-8. See @bugref{10153}.
44 *
45 * @note We don't need this on windows and it would be harmful to enable it
46 * as the argc/argv vs __argc/__argv comparison would fail and we would
47 * not use the unicode command line to create a UTF-8 argv. Since the
48 * original argv is ANSI, it may be missing codepoints not present in
49 * the ANSI code page of the process. */
50# define VBOXSERVICE_ARG1_UTF8_ARGV "--utf8-argv"
51#endif
52/** RTProcCreateEx flags corresponding to VBOXSERVICE_ARG1_UTF8_ARGV. */
53#ifdef VBOXSERVICE_ARG1_UTF8_ARGV
54# define VBOXSERVICE_PROC_F_UTF8_ARGV 0 /** @todo TBD */
55#else
56# define VBOXSERVICE_PROC_F_UTF8_ARGV 0
57#endif
58
59
60/**
61 * A service descriptor.
62 */
63typedef struct
64{
65 /** The short service name. */
66 const char *pszName;
67 /** The longer service name. */
68 const char *pszDescription;
69 /** The usage options stuff for the --help screen. */
70 const char *pszUsage;
71 /** The option descriptions for the --help screen. */
72 const char *pszOptions;
73
74 /**
75 * Called before parsing arguments.
76 * @returns VBox status code.
77 */
78 DECLCALLBACKMEMBER(int, pfnPreInit,(void));
79
80 /**
81 * Tries to parse the given command line option.
82 *
83 * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
84 * @param ppszShort If not NULL it points to the short option iterator. a short argument.
85 * If NULL examine argv[*pi].
86 * @param argc The argument count.
87 * @param argv The argument vector.
88 * @param pi The argument vector index. Update if any value(s) are eaten.
89 */
90 DECLCALLBACKMEMBER(int, pfnOption,(const char **ppszShort, int argc, char **argv, int *pi));
91
92 /**
93 * Called before parsing arguments.
94 * @returns VBox status code.
95 */
96 DECLCALLBACKMEMBER(int, pfnInit,(void));
97
98 /** Called from the worker thread.
99 *
100 * @returns VBox status code.
101 * @retval VINF_SUCCESS if exitting because *pfShutdown was set.
102 * @param pfShutdown Pointer to a per service termination flag to check
103 * before and after blocking.
104 */
105 DECLCALLBACKMEMBER(int, pfnWorker,(bool volatile *pfShutdown));
106
107 /**
108 * Stops a service.
109 */
110 DECLCALLBACKMEMBER(void, pfnStop,(void));
111
112 /**
113 * Does termination cleanups.
114 *
115 * @remarks This may be called even if pfnInit hasn't been called!
116 */
117 DECLCALLBACKMEMBER(void, pfnTerm,(void));
118} VBOXSERVICE;
119/** Pointer to a VBOXSERVICE. */
120typedef VBOXSERVICE *PVBOXSERVICE;
121/** Pointer to a const VBOXSERVICE. */
122typedef VBOXSERVICE const *PCVBOXSERVICE;
123
124/* Default call-backs for services which do not need special behaviour. */
125DECLCALLBACK(int) VGSvcDefaultPreInit(void);
126DECLCALLBACK(int) VGSvcDefaultOption(const char **ppszShort, int argc, char **argv, int *pi);
127DECLCALLBACK(int) VGSvcDefaultInit(void);
128DECLCALLBACK(void) VGSvcDefaultTerm(void);
129
130/** The service name.
131 * @note Used on windows to name the service as well as the global mutex. */
132#define VBOXSERVICE_NAME "VBoxService"
133
134#ifdef RT_OS_WINDOWS
135/** The friendly service name. */
136# define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
137/** The service description (only W2K+ atm) */
138# define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, guest control execution and miscellaneous utilities for guest operating systems."
139/** The following constant may be defined by including NtStatus.h. */
140# define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
141#endif /* RT_OS_WINDOWS */
142
143#ifdef VBOX_WITH_GUEST_PROPS
144/**
145 * A guest property cache.
146 */
147typedef struct VBOXSERVICEVEPROPCACHE
148{
149 /** The client ID for HGCM communication. */
150 uint32_t uClientID;
151 /** Head in a list of VBOXSERVICEVEPROPCACHEENTRY nodes. */
152 RTLISTANCHOR NodeHead;
153 /** Critical section for thread-safe use. */
154 RTCRITSECT CritSect;
155} VBOXSERVICEVEPROPCACHE;
156/** Pointer to a guest property cache. */
157typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
158
159/**
160 * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
161 */
162typedef struct VBOXSERVICEVEPROPCACHEENTRY
163{
164 /** Node to successor.
165 * @todo r=bird: This is not really the node to the successor, but
166 * rather the OUR node in the list. If it helps, remember that
167 * its a doubly linked list. */
168 RTLISTNODE NodeSucc;
169 /** Name (and full path) of guest property. */
170 char *pszName;
171 /** The last value stored (for reference). */
172 char *pszValue;
173 /** Reset value to write if property is temporary. If NULL, it will be
174 * deleted. */
175 char *pszValueReset;
176 /** Flags. */
177 uint32_t fFlags;
178} VBOXSERVICEVEPROPCACHEENTRY;
179/** Pointer to a cached guest property. */
180typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
181
182#endif /* VBOX_WITH_GUEST_PROPS */
183
184RT_C_DECLS_BEGIN
185
186extern char *g_pszProgName;
187extern unsigned g_cVerbosity;
188extern char g_szLogFile[RTPATH_MAX + 128];
189extern uint32_t g_DefaultInterval;
190extern VBOXSERVICE g_TimeSync;
191#ifdef VBOX_WITH_VBOXSERVICE_CLIPBOARD
192extern VBOXSERVICE g_Clipboard;
193#endif
194extern VBOXSERVICE g_Control;
195extern VBOXSERVICE g_VMInfo;
196extern VBOXSERVICE g_CpuHotPlug;
197#ifdef VBOX_WITH_VBOXSERVICE_MANAGEMENT
198extern VBOXSERVICE g_MemBalloon;
199extern VBOXSERVICE g_VMStatistics;
200#endif
201#ifdef VBOX_WITH_VBOXSERVICE_PAGE_SHARING
202extern VBOXSERVICE g_PageSharing;
203#endif
204#ifdef VBOX_WITH_SHARED_FOLDERS
205extern VBOXSERVICE g_AutoMount;
206#endif
207#ifdef DEBUG
208extern RTCRITSECT g_csLog; /* For guest process stdout dumping. */
209#endif
210
211extern RTEXITCODE VGSvcSyntax(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
212extern RTEXITCODE VGSvcError(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
213extern void VGSvcVerbose(unsigned iLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
214extern int VGSvcLogCreate(const char *pszLogFile);
215extern void VGSvcLogV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
216extern void VGSvcLogDestroy(void);
217extern int VGSvcArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
218 uint32_t u32Min, uint32_t u32Max);
219
220/* Exposing the following bits because of windows: */
221extern int VGSvcStartServices(void);
222extern int VGSvcStopServices(void);
223extern void VGSvcMainWait(void);
224extern int VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus);
225#ifdef RT_OS_WINDOWS
226extern void VGSvcWinResolveApis(void);
227extern RTEXITCODE VGSvcWinInstall(void);
228extern RTEXITCODE VGSvcWinUninstall(void);
229extern RTEXITCODE VGSvcWinEnterCtrlDispatcher(void);
230extern void VGSvcWinSetStopPendingStatus(uint32_t uCheckPoint);
231# ifdef TH32CS_SNAPHEAPLIST
232extern decltype(CreateToolhelp32Snapshot) *g_pfnCreateToolhelp32Snapshot;
233extern decltype(Process32First) *g_pfnProcess32First;
234extern decltype(Process32Next) *g_pfnProcess32Next;
235extern decltype(Module32First) *g_pfnModule32First;
236extern decltype(Module32Next) *g_pfnModule32Next;
237# endif
238extern decltype(GetSystemTimeAdjustment) *g_pfnGetSystemTimeAdjustment;
239extern decltype(SetSystemTimeAdjustment) *g_pfnSetSystemTimeAdjustment;
240# ifdef IPRT_INCLUDED_nt_nt_h
241extern decltype(ZwQuerySystemInformation) *g_pfnZwQuerySystemInformation;
242# endif
243extern ULONG (WINAPI *g_pfnGetAdaptersInfo)(struct _IP_ADAPTER_INFO *, PULONG);
244#ifdef WINSOCK_VERSION
245extern decltype(WSAStartup) *g_pfnWSAStartup;
246extern decltype(WSACleanup) *g_pfnWSACleanup;
247extern decltype(WSASocketA) *g_pfnWSASocketA;
248extern decltype(WSAIoctl) *g_pfnWSAIoctl;
249extern decltype(WSAGetLastError) *g_pfnWSAGetLastError;
250extern decltype(closesocket) *g_pfnclosesocket;
251extern decltype(inet_ntoa) *g_pfninet_ntoa;
252# endif /* WINSOCK_VERSION */
253
254#ifdef SE_INTERACTIVE_LOGON_NAME
255extern decltype(LsaNtStatusToWinError) *g_pfnLsaNtStatusToWinError;
256#endif
257
258# ifdef VBOX_WITH_GUEST_PROPS
259extern int VGSvcVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, char **ppszUserList, uint32_t *pcUsersInList);
260extern int VGSvcVMInfoWinGetComponentVersions(uint32_t uClientID);
261# endif /* VBOX_WITH_GUEST_PROPS */
262
263#endif /* RT_OS_WINDOWS */
264
265#ifdef VBOX_WITH_VBOXSERVICE_MANAGEMENT
266extern uint32_t VGSvcBalloonQueryPages(uint32_t cbPage);
267#endif
268#if defined(VBOX_WITH_VBOXSERVICE_PAGE_SHARING)
269extern RTEXITCODE VGSvcPageSharingWorkerChild(void);
270#endif
271extern int VGSvcVMInfoSignal(void);
272
273RT_C_DECLS_END
274
275#endif /* !GA_INCLUDED_SRC_common_VBoxService_VBoxServiceInternal_h */
276
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