0003-Rename-poll-h-into-vm_poll-h-to-fix-build-failure-on-musl.patch 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. From 1dfab46d367d11e9132506ee0f7d3eb2ceff5f3c Mon Sep 17 00:00:00 2001
  2. Message-Id: <1dfab46d367d11e9132506ee0f7d3eb2ceff5f3c.1652913832.git.stefan@agner.ch>
  3. From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  4. Date: Mon, 30 Sep 2019 13:32:35 +0200
  5. Subject: [PATCH] Rename poll.h into vm_poll.h to fix build failure on musl
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. musl libc redirects include of sys/poll.h to poll.h. But since poll.h is
  10. also a local header file, the musl libc header is never included. This
  11. leads to the following build failure:
  12. In file included from asyncsocket.c:73:0:
  13. .../host/i586-buildroot-linux-musl/sysroot/usr/include/sys/poll.h:1:2: warning: #warning redirecting incorrect #include <sys/poll.h> to <poll.h> [-Wcpp]
  14. #warning redirecting incorrect #include <sys/poll.h> to <poll.h>
  15. asyncsocket.c: In function ‘AsyncTCPSocketPollWork’:
  16. asyncsocket.c:2537:13: error: invalid use of undefined type ‘struct pollfd’
  17. pfd[i].fd = asock[i]->fd;
  18. ^
  19. asyncsocket.c:2537:13: error: dereferencing pointer to incomplete type ‘struct pollfd’
  20. asyncsocket.c:2538:13: error: invalid use of undefined type ‘struct pollfd’
  21. pfd[i].events = read ? POLLIN : POLLOUT;
  22. ^
  23. asyncsocket.c:2538:33: error: ‘POLLIN’ undeclared (first use in this function); did you mean ‘POLL_IN’?
  24. pfd[i].events = read ? POLLIN : POLLOUT;
  25. So rename poll.h into vm_poll.h as suggested by srowe in
  26. https://github.com/vmware/open-vm-tools/issues/359#issuecomment-533529956
  27. Fixes:
  28. - http://autobuild.buildroot.org/results/4f575ef42bbc4387a07e396205052b2da081c64d
  29. Fix #359
  30. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  31. [Upstream status: https://github.com/vmware/open-vm-tools/pull/383]
  32. ---
  33. lib/asyncsocket/asyncsocket.c | 4 +-
  34. lib/hgfsServer/hgfsServer.c | 2 +-
  35. lib/include/asyncsocket.h | 2 +-
  36. lib/include/poll.h | 337 --------------------
  37. lib/include/pollImpl.h | 2 +-
  38. lib/include/vm_poll.h | 337 ++++++++++++++++++++
  39. lib/rpcIn/rpcin.c | 2 +-
  40. 7 files changed, 343 insertions(+), 343 deletions(-)
  41. delete mode 100644 lib/include/poll.h
  42. create mode 100644 lib/include/vm_poll.h
  43. diff --git a/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c
  44. index 05147d2e..16949567 100644
  45. --- a/lib/asyncsocket/asyncsocket.c
  46. +++ b/lib/asyncsocket/asyncsocket.c
  47. @@ -70,8 +70,8 @@
  48. #else
  49. #include <stddef.h>
  50. #include <ctype.h>
  51. +#include <poll.h>
  52. #include <sys/types.h>
  53. -#include <sys/poll.h>
  54. #include <sys/socket.h>
  55. #include <sys/un.h>
  56. #include <netdb.h>
  57. @@ -87,7 +87,7 @@
  58. #include "random.h"
  59. #include "asyncsocket.h"
  60. #include "asyncSocketBase.h"
  61. -#include "poll.h"
  62. +#include "vm_poll.h"
  63. #include "log.h"
  64. #include "err.h"
  65. #include "hostinfo.h"
  66. diff --git a/lib/hgfsServer/hgfsServer.c b/open-vm-tools/lib/hgfsServer/hgfsServer.c
  67. index 98f5b3f0..b436f0c7 100644
  68. --- a/lib/hgfsServer/hgfsServer.c
  69. +++ b/lib/hgfsServer/hgfsServer.c
  70. @@ -51,7 +51,7 @@
  71. #include "hgfsDirNotify.h"
  72. #include "hgfsThreadpool.h"
  73. #include "userlock.h"
  74. -#include "poll.h"
  75. +#include "vm_poll.h"
  76. #include "mutexRankLib.h"
  77. #include "vm_basic_asm.h"
  78. #include "unicodeOperations.h"
  79. diff --git a/lib/include/asyncsocket.h b/open-vm-tools/lib/include/asyncsocket.h
  80. index 47b5b873..b8b0149e 100644
  81. --- a/lib/include/asyncsocket.h
  82. +++ b/lib/include/asyncsocket.h
  83. @@ -171,7 +171,7 @@ typedef struct AsyncSocket AsyncSocket;
  84. * Or the client can specify its favorite poll class and locking behavior.
  85. * Use of IVmdbPoll is only supported for regular sockets and for Attach.
  86. */
  87. -#include "poll.h"
  88. +#include "vm_poll.h"
  89. struct IVmdbPoll;
  90. typedef struct AsyncSocketPollParams {
  91. int flags; /* Default 0, only POLL_FLAG_NO_BULL is valid */
  92. diff --git a/lib/include/poll.h b/open-vm-tools/lib/include/poll.h
  93. deleted file mode 100644
  94. index c90f5dcd..00000000
  95. --- a/lib/include/poll.h
  96. +++ /dev/null
  97. @@ -1,337 +0,0 @@
  98. -/*********************************************************
  99. - * Copyright (C) 1998-2020 VMware, Inc. All rights reserved.
  100. - *
  101. - * This program is free software; you can redistribute it and/or modify it
  102. - * under the terms of the GNU Lesser General Public License as published
  103. - * by the Free Software Foundation version 2.1 and no later version.
  104. - *
  105. - * This program is distributed in the hope that it will be useful, but
  106. - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  107. - * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
  108. - * License for more details.
  109. - *
  110. - * You should have received a copy of the GNU Lesser General Public License
  111. - * along with this program; if not, write to the Free Software Foundation, Inc.,
  112. - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  113. - *
  114. - *********************************************************/
  115. -
  116. -/*********************************************************
  117. - * The contents of this file are subject to the terms of the Common
  118. - * Development and Distribution License (the "License") version 1.0
  119. - * and no later version. You may not use this file except in
  120. - * compliance with the License.
  121. - *
  122. - * You can obtain a copy of the License at
  123. - * http://www.opensource.org/licenses/cddl1.php
  124. - *
  125. - * See the License for the specific language governing permissions
  126. - * and limitations under the License.
  127. - *
  128. - *********************************************************/
  129. -
  130. -
  131. -#ifndef _POLL_H_
  132. -#define _POLL_H_
  133. -
  134. -#define INCLUDE_ALLOW_USERLEVEL
  135. -#define INCLUDE_ALLOW_VMCORE
  136. -#include "includeCheck.h"
  137. -
  138. -#include "vm_basic_types.h"
  139. -#include "vm_basic_defs.h"
  140. -#include "vmware.h"
  141. -#include "userlock.h"
  142. -
  143. -#if defined(__cplusplus)
  144. -extern "C" {
  145. -#endif
  146. -
  147. -#ifdef _WIN32
  148. -#define HZ 100
  149. -#elif defined __linux__
  150. -#include <asm/param.h>
  151. -#elif __APPLE__
  152. -#include <TargetConditionals.h>
  153. -/*
  154. - * Old SDKs don't define TARGET_OS_IPHONE at all.
  155. - * New ones define it to 0 on Mac OS X, 1 on iOS.
  156. - */
  157. -#if !defined(TARGET_OS_IPHONE) || TARGET_OS_IPHONE == 0
  158. -#include <sys/kernel.h>
  159. -#endif
  160. -#include <sys/poll.h>
  161. -#define HZ 100
  162. -#endif
  163. -#ifdef __ANDROID__
  164. -/*
  165. - * <poll.h> of android should be included, but its name is same
  166. - * with this file. So its content is put here to avoid conflict.
  167. - */
  168. -#include <asm/poll.h>
  169. -#define HZ 100
  170. -typedef unsigned int nfds_t;
  171. -int poll(struct pollfd *, nfds_t, long);
  172. -#endif
  173. -
  174. -
  175. -/*
  176. - * Poll event types: each type has a different reason for firing,
  177. - * or condition that must be met before firing.
  178. - */
  179. -
  180. -typedef enum {
  181. - /*
  182. - * Actual Poll queue types against which you can register callbacks.
  183. - */
  184. - POLL_VIRTUALREALTIME = -1, /* Negative because it doesn't have its own Q */
  185. - POLL_VTIME = 0,
  186. - POLL_REALTIME,
  187. - POLL_DEVICE,
  188. - POLL_MAIN_LOOP,
  189. - POLL_NUM_QUEUES
  190. -} PollEventType;
  191. -
  192. -
  193. -/*
  194. - * Classes of events
  195. - *
  196. - * These are the predefined classes. More can be declared
  197. - * with Poll_AllocClass().
  198. - */
  199. -
  200. -typedef enum PollClass {
  201. - POLL_CLASS_MAIN,
  202. - POLL_CLASS_PAUSE,
  203. - POLL_CLASS_IPC,
  204. - POLL_CLASS_CPT,
  205. - POLL_CLASS_MKS,
  206. - POLL_FIXED_CLASSES,
  207. - POLL_DEFAULT_FIXED_CLASSES,
  208. - /* Size enum to maximum */
  209. - POLL_MAX_CLASSES = 31,
  210. -} PollClass;
  211. -
  212. -/*
  213. - * Do not use; Special pseudo private poll class supported by
  214. - * PollDefault only
  215. - */
  216. -#define POLL_DEFAULT_CLASS_NET POLL_FIXED_CLASSES
  217. -#define POLL_DEFAULT_CS_NET PollClassSet_Singleton(POLL_DEFAULT_CLASS_NET)
  218. -
  219. -/*
  220. - * Each callback is registered in a set of classes
  221. - */
  222. -
  223. -typedef struct PollClassSet {
  224. - uintptr_t bits;
  225. -} PollClassSet;
  226. -
  227. -/* An empty PollClassSet. */
  228. -static INLINE PollClassSet
  229. -PollClassSet_Empty(void)
  230. -{
  231. - PollClassSet set = { 0 };
  232. - return set;
  233. -}
  234. -
  235. -/* A PollClassSet with the single member. */
  236. -static INLINE PollClassSet
  237. -PollClassSet_Singleton(PollClass c)
  238. -{
  239. - PollClassSet s = PollClassSet_Empty();
  240. -
  241. - ASSERT_ON_COMPILE(POLL_MAX_CLASSES < sizeof s.bits * 8);
  242. - ASSERT(c < POLL_MAX_CLASSES);
  243. -
  244. - s.bits = CONST3264U(1) << c;
  245. - return s;
  246. -}
  247. -
  248. -/* Combine two PollClassSets. */
  249. -static INLINE PollClassSet
  250. -PollClassSet_Union(PollClassSet lhs, PollClassSet rhs)
  251. -{
  252. - PollClassSet set;
  253. - set.bits = lhs.bits | rhs.bits;
  254. - return set;
  255. -}
  256. -
  257. -/* Add single class to PollClassSet. */
  258. -static INLINE PollClassSet
  259. -PollClassSet_Include(PollClassSet set, PollClass c)
  260. -{
  261. - return PollClassSet_Union(set, PollClassSet_Singleton(c));
  262. -}
  263. -
  264. -
  265. -#define POLL_CS_MAIN PollClassSet_Singleton(POLL_CLASS_MAIN)
  266. -#define POLL_CS_PAUSE PollClassSet_Union(POLL_CS_MAIN, \
  267. - PollClassSet_Singleton(POLL_CLASS_PAUSE))
  268. -#define POLL_CS_CPT PollClassSet_Union(POLL_CS_PAUSE, \
  269. - PollClassSet_Singleton(POLL_CLASS_CPT))
  270. -#define POLL_CS_IPC PollClassSet_Union(POLL_CS_CPT, \
  271. - PollClassSet_Singleton(POLL_CLASS_IPC))
  272. -#define POLL_CS_VMDB POLL_CS_PAUSE /* POLL_CLASS_VMDB is retired */
  273. -#define POLL_CS_MKS PollClassSet_Singleton(POLL_CLASS_MKS)
  274. -/*
  275. - * DANGER. You don't need POLL_CS_ALWAYS. Really. So don't use it.
  276. - */
  277. -#define POLL_CS_ALWAYS PollClassSet_Union(POLL_CS_CPT, POLL_CS_IPC)
  278. -
  279. -/*
  280. - * Poll class-set taxonomy:
  281. - * POLL_CS_MAIN
  282. - * - Unless you NEED another class, use POLL_CS_MAIN.
  283. - * POLL_CS_PAUSE
  284. - * - For callbacks that must occur even if the guest is paused.
  285. - * Most VMDB or Foundry commands are in this category.
  286. - * POLL_CS_CPT
  287. - * - Only for callbacks which can trigger intermediate Checkpoint
  288. - * transitions.
  289. - * The ONLY such callback is Migrate.
  290. - * POLL_CS_IPC
  291. - * - Only for callbacks which can contain Msg_(Post|Hint|Question)
  292. - * responses, and for signal handlers (why)?
  293. - * Vigor, VMDB, and Foundry can contain Msg_* responses.
  294. - * POLL_CS_MKS
  295. - * - Callback runs in MKS thread.
  296. - * POLL_CS_ALWAYS
  297. - * - Only for events that must be processed immediately.
  298. - * The ONLY such callback is OvhdMemVmxSizeCheck.
  299. - */
  300. -
  301. -
  302. -/*
  303. - * Poll_Callback flags
  304. - */
  305. -
  306. -#define POLL_FLAG_PERIODIC 0x01 // keep after firing
  307. -#define POLL_FLAG_REMOVE_AT_POWEROFF 0x02 // self-explanatory
  308. -#define POLL_FLAG_READ 0x04 // device is ready for reading
  309. -#define POLL_FLAG_WRITE 0x08 // device is ready for writing
  310. -#define POLL_FLAG_SOCKET 0x10 // device is a Windows socket
  311. -#define POLL_FLAG_NO_BULL 0x20 // callback does its own locking
  312. -#define POLL_FLAG_WINSOCK 0x40 // Winsock style write events
  313. -#define POLL_FLAG_FD 0x80 // device is a Windows file descriptor.
  314. -#define POLL_FLAG_ACCEPT_INVALID_FDS 0x100 // For broken 3rd party libs, e.g. curl
  315. -#define POLL_FLAG_THUNK_TO_WND 0x200 // thunk callback to window message loop
  316. -
  317. -
  318. -typedef void (*PollerFunction)(void *clientData);
  319. -typedef void (*PollerFireWrapper)(PollerFunction func,
  320. - void *funcData,
  321. - void *wrapperData);
  322. -typedef Bool (*PollerErrorFn)(const char *errorStr);
  323. -
  324. -/*
  325. - * Initialisers:
  326. - *
  327. - * For the sake of convenience, we declare the initialisers
  328. - * for custom implmentations here, even though the actual
  329. - * implementations are distinct from the core poll code.
  330. - */
  331. -
  332. -
  333. -/* Socket pair created with non-blocking mode */
  334. -#define POLL_OPTIONS_SOCKET_PAIR_NONBLOCK_CONN 0x01
  335. -
  336. -typedef unsigned int SocketSpecialOpts;
  337. -
  338. -typedef struct PollOptions {
  339. - Bool locked; // Use internal MXUser for locking
  340. - Bool allowFullQueue; // Don't assert when device event queue is full.
  341. - VThreadID windowsMsgThread; // thread that processes Windows messages
  342. - PollerFireWrapper fireWrapperFn; // optional; may be useful for stats
  343. - void *fireWrapperData; // optional
  344. - PollerErrorFn errorFn; // optional; called upon unrecoverable error
  345. - SocketSpecialOpts pollSocketOpts;
  346. -} PollOptions;
  347. -
  348. -
  349. -void Poll_InitDefault(void);
  350. -void Poll_InitDefaultEx(const PollOptions *opts);
  351. -void Poll_InitGtk(void); // On top of glib for Linux
  352. -void Poll_InitCF(void); // On top of CoreFoundation for OSX
  353. -
  354. -
  355. -/*
  356. - * Functions
  357. - */
  358. -int Poll_SocketPair(Bool vmci, Bool stream, int fds[2], SocketSpecialOpts opts);
  359. -void Poll_Loop(Bool loop, Bool *exit, PollClass c);
  360. -void Poll_LoopTimeout(Bool loop, Bool *exit, PollClass c, int timeout);
  361. -Bool Poll_LockingEnabled(void);
  362. -void Poll_Exit(void);
  363. -
  364. -
  365. -/*
  366. - * Poll_Callback adds a callback regardless of whether an identical one exists.
  367. - * The exception to this rule is POLL_DEVICE callbacks: there is a maximum of
  368. - * one read and one write callback per fd.
  369. - *
  370. - * Poll_CallbackRemove removes one callback. If there are multiple identical
  371. - * callbacks, which one is removed is an implementation detail. Note that in
  372. - * the case of POLL_DEVICE and POLL_REALTIME callbacks, the fd/delay used to
  373. - * create the callback is not specified when removing, so all callbacks
  374. - * of those types with the same flags, function, and clientData are considered
  375. - * "identical" even if their fd/delay differed.
  376. - */
  377. -
  378. -VMwareStatus Poll_Callback(PollClassSet classSet,
  379. - int flags,
  380. - PollerFunction f,
  381. - void *clientData,
  382. - PollEventType type,
  383. - PollDevHandle info, // fd/microsec delay
  384. - MXUserRecLock *lck);
  385. -Bool Poll_CallbackRemove(PollClassSet classSet,
  386. - int flags,
  387. - PollerFunction f,
  388. - void *clientData,
  389. - PollEventType type);
  390. -Bool Poll_CallbackRemoveOneByCB(PollClassSet classSet,
  391. - int flags,
  392. - PollerFunction f,
  393. - PollEventType type,
  394. - void **clientData);
  395. -
  396. -void Poll_NotifyChange(PollClassSet classSet);
  397. -
  398. -/*
  399. - * Wrappers for Poll_Callback and Poll_CallbackRemove that present
  400. - * simpler subsets of those interfaces.
  401. - */
  402. -
  403. -VMwareStatus Poll_CB_Device(PollerFunction f,
  404. - void *clientData,
  405. - PollDevHandle device,
  406. - Bool periodic);
  407. -
  408. -Bool Poll_CB_DeviceRemove(PollerFunction f,
  409. - void *clientData,
  410. - Bool periodic);
  411. -
  412. -
  413. -VMwareStatus Poll_CB_RTime(PollerFunction f,
  414. - void *clientData,
  415. - int64 delay, // microseconds
  416. - Bool periodic,
  417. - MXUserRecLock *lock);
  418. -
  419. -Bool Poll_CB_RTimeRemove(PollerFunction f,
  420. - void *clientData,
  421. - Bool periodic);
  422. -
  423. -
  424. -#ifdef _WIN32
  425. -void Poll_SetPumpsWindowsMessages(Bool pumps);
  426. -void Poll_SetWindowMessageRecipient(HWND hWnd, UINT msg, Bool alwaysThunk);
  427. -Bool Poll_FireWndCallback(void *lparam);
  428. -#endif
  429. -
  430. -#if defined(__cplusplus)
  431. -} // extern "C"
  432. -#endif
  433. -
  434. -#endif // _POLL_H_
  435. diff --git a/lib/include/pollImpl.h b/open-vm-tools/lib/include/pollImpl.h
  436. index 46442e55..8bc66997 100644
  437. --- a/lib/include/pollImpl.h
  438. +++ b/lib/include/pollImpl.h
  439. @@ -44,7 +44,7 @@
  440. #define INCLUDE_ALLOW_USERLEVEL
  441. #include "includeCheck.h"
  442. -#include "poll.h"
  443. +#include "vm_poll.h"
  444. #include "vm_basic_asm.h"
  445. #if defined(__cplusplus)
  446. diff --git a/lib/include/vm_poll.h b/open-vm-tools/lib/include/vm_poll.h
  447. new file mode 100644
  448. index 00000000..c90f5dcd
  449. --- /dev/null
  450. +++ b/lib/include/vm_poll.h
  451. @@ -0,0 +1,337 @@
  452. +/*********************************************************
  453. + * Copyright (C) 1998-2020 VMware, Inc. All rights reserved.
  454. + *
  455. + * This program is free software; you can redistribute it and/or modify it
  456. + * under the terms of the GNU Lesser General Public License as published
  457. + * by the Free Software Foundation version 2.1 and no later version.
  458. + *
  459. + * This program is distributed in the hope that it will be useful, but
  460. + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  461. + * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
  462. + * License for more details.
  463. + *
  464. + * You should have received a copy of the GNU Lesser General Public License
  465. + * along with this program; if not, write to the Free Software Foundation, Inc.,
  466. + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  467. + *
  468. + *********************************************************/
  469. +
  470. +/*********************************************************
  471. + * The contents of this file are subject to the terms of the Common
  472. + * Development and Distribution License (the "License") version 1.0
  473. + * and no later version. You may not use this file except in
  474. + * compliance with the License.
  475. + *
  476. + * You can obtain a copy of the License at
  477. + * http://www.opensource.org/licenses/cddl1.php
  478. + *
  479. + * See the License for the specific language governing permissions
  480. + * and limitations under the License.
  481. + *
  482. + *********************************************************/
  483. +
  484. +
  485. +#ifndef _POLL_H_
  486. +#define _POLL_H_
  487. +
  488. +#define INCLUDE_ALLOW_USERLEVEL
  489. +#define INCLUDE_ALLOW_VMCORE
  490. +#include "includeCheck.h"
  491. +
  492. +#include "vm_basic_types.h"
  493. +#include "vm_basic_defs.h"
  494. +#include "vmware.h"
  495. +#include "userlock.h"
  496. +
  497. +#if defined(__cplusplus)
  498. +extern "C" {
  499. +#endif
  500. +
  501. +#ifdef _WIN32
  502. +#define HZ 100
  503. +#elif defined __linux__
  504. +#include <asm/param.h>
  505. +#elif __APPLE__
  506. +#include <TargetConditionals.h>
  507. +/*
  508. + * Old SDKs don't define TARGET_OS_IPHONE at all.
  509. + * New ones define it to 0 on Mac OS X, 1 on iOS.
  510. + */
  511. +#if !defined(TARGET_OS_IPHONE) || TARGET_OS_IPHONE == 0
  512. +#include <sys/kernel.h>
  513. +#endif
  514. +#include <sys/poll.h>
  515. +#define HZ 100
  516. +#endif
  517. +#ifdef __ANDROID__
  518. +/*
  519. + * <poll.h> of android should be included, but its name is same
  520. + * with this file. So its content is put here to avoid conflict.
  521. + */
  522. +#include <asm/poll.h>
  523. +#define HZ 100
  524. +typedef unsigned int nfds_t;
  525. +int poll(struct pollfd *, nfds_t, long);
  526. +#endif
  527. +
  528. +
  529. +/*
  530. + * Poll event types: each type has a different reason for firing,
  531. + * or condition that must be met before firing.
  532. + */
  533. +
  534. +typedef enum {
  535. + /*
  536. + * Actual Poll queue types against which you can register callbacks.
  537. + */
  538. + POLL_VIRTUALREALTIME = -1, /* Negative because it doesn't have its own Q */
  539. + POLL_VTIME = 0,
  540. + POLL_REALTIME,
  541. + POLL_DEVICE,
  542. + POLL_MAIN_LOOP,
  543. + POLL_NUM_QUEUES
  544. +} PollEventType;
  545. +
  546. +
  547. +/*
  548. + * Classes of events
  549. + *
  550. + * These are the predefined classes. More can be declared
  551. + * with Poll_AllocClass().
  552. + */
  553. +
  554. +typedef enum PollClass {
  555. + POLL_CLASS_MAIN,
  556. + POLL_CLASS_PAUSE,
  557. + POLL_CLASS_IPC,
  558. + POLL_CLASS_CPT,
  559. + POLL_CLASS_MKS,
  560. + POLL_FIXED_CLASSES,
  561. + POLL_DEFAULT_FIXED_CLASSES,
  562. + /* Size enum to maximum */
  563. + POLL_MAX_CLASSES = 31,
  564. +} PollClass;
  565. +
  566. +/*
  567. + * Do not use; Special pseudo private poll class supported by
  568. + * PollDefault only
  569. + */
  570. +#define POLL_DEFAULT_CLASS_NET POLL_FIXED_CLASSES
  571. +#define POLL_DEFAULT_CS_NET PollClassSet_Singleton(POLL_DEFAULT_CLASS_NET)
  572. +
  573. +/*
  574. + * Each callback is registered in a set of classes
  575. + */
  576. +
  577. +typedef struct PollClassSet {
  578. + uintptr_t bits;
  579. +} PollClassSet;
  580. +
  581. +/* An empty PollClassSet. */
  582. +static INLINE PollClassSet
  583. +PollClassSet_Empty(void)
  584. +{
  585. + PollClassSet set = { 0 };
  586. + return set;
  587. +}
  588. +
  589. +/* A PollClassSet with the single member. */
  590. +static INLINE PollClassSet
  591. +PollClassSet_Singleton(PollClass c)
  592. +{
  593. + PollClassSet s = PollClassSet_Empty();
  594. +
  595. + ASSERT_ON_COMPILE(POLL_MAX_CLASSES < sizeof s.bits * 8);
  596. + ASSERT(c < POLL_MAX_CLASSES);
  597. +
  598. + s.bits = CONST3264U(1) << c;
  599. + return s;
  600. +}
  601. +
  602. +/* Combine two PollClassSets. */
  603. +static INLINE PollClassSet
  604. +PollClassSet_Union(PollClassSet lhs, PollClassSet rhs)
  605. +{
  606. + PollClassSet set;
  607. + set.bits = lhs.bits | rhs.bits;
  608. + return set;
  609. +}
  610. +
  611. +/* Add single class to PollClassSet. */
  612. +static INLINE PollClassSet
  613. +PollClassSet_Include(PollClassSet set, PollClass c)
  614. +{
  615. + return PollClassSet_Union(set, PollClassSet_Singleton(c));
  616. +}
  617. +
  618. +
  619. +#define POLL_CS_MAIN PollClassSet_Singleton(POLL_CLASS_MAIN)
  620. +#define POLL_CS_PAUSE PollClassSet_Union(POLL_CS_MAIN, \
  621. + PollClassSet_Singleton(POLL_CLASS_PAUSE))
  622. +#define POLL_CS_CPT PollClassSet_Union(POLL_CS_PAUSE, \
  623. + PollClassSet_Singleton(POLL_CLASS_CPT))
  624. +#define POLL_CS_IPC PollClassSet_Union(POLL_CS_CPT, \
  625. + PollClassSet_Singleton(POLL_CLASS_IPC))
  626. +#define POLL_CS_VMDB POLL_CS_PAUSE /* POLL_CLASS_VMDB is retired */
  627. +#define POLL_CS_MKS PollClassSet_Singleton(POLL_CLASS_MKS)
  628. +/*
  629. + * DANGER. You don't need POLL_CS_ALWAYS. Really. So don't use it.
  630. + */
  631. +#define POLL_CS_ALWAYS PollClassSet_Union(POLL_CS_CPT, POLL_CS_IPC)
  632. +
  633. +/*
  634. + * Poll class-set taxonomy:
  635. + * POLL_CS_MAIN
  636. + * - Unless you NEED another class, use POLL_CS_MAIN.
  637. + * POLL_CS_PAUSE
  638. + * - For callbacks that must occur even if the guest is paused.
  639. + * Most VMDB or Foundry commands are in this category.
  640. + * POLL_CS_CPT
  641. + * - Only for callbacks which can trigger intermediate Checkpoint
  642. + * transitions.
  643. + * The ONLY such callback is Migrate.
  644. + * POLL_CS_IPC
  645. + * - Only for callbacks which can contain Msg_(Post|Hint|Question)
  646. + * responses, and for signal handlers (why)?
  647. + * Vigor, VMDB, and Foundry can contain Msg_* responses.
  648. + * POLL_CS_MKS
  649. + * - Callback runs in MKS thread.
  650. + * POLL_CS_ALWAYS
  651. + * - Only for events that must be processed immediately.
  652. + * The ONLY such callback is OvhdMemVmxSizeCheck.
  653. + */
  654. +
  655. +
  656. +/*
  657. + * Poll_Callback flags
  658. + */
  659. +
  660. +#define POLL_FLAG_PERIODIC 0x01 // keep after firing
  661. +#define POLL_FLAG_REMOVE_AT_POWEROFF 0x02 // self-explanatory
  662. +#define POLL_FLAG_READ 0x04 // device is ready for reading
  663. +#define POLL_FLAG_WRITE 0x08 // device is ready for writing
  664. +#define POLL_FLAG_SOCKET 0x10 // device is a Windows socket
  665. +#define POLL_FLAG_NO_BULL 0x20 // callback does its own locking
  666. +#define POLL_FLAG_WINSOCK 0x40 // Winsock style write events
  667. +#define POLL_FLAG_FD 0x80 // device is a Windows file descriptor.
  668. +#define POLL_FLAG_ACCEPT_INVALID_FDS 0x100 // For broken 3rd party libs, e.g. curl
  669. +#define POLL_FLAG_THUNK_TO_WND 0x200 // thunk callback to window message loop
  670. +
  671. +
  672. +typedef void (*PollerFunction)(void *clientData);
  673. +typedef void (*PollerFireWrapper)(PollerFunction func,
  674. + void *funcData,
  675. + void *wrapperData);
  676. +typedef Bool (*PollerErrorFn)(const char *errorStr);
  677. +
  678. +/*
  679. + * Initialisers:
  680. + *
  681. + * For the sake of convenience, we declare the initialisers
  682. + * for custom implmentations here, even though the actual
  683. + * implementations are distinct from the core poll code.
  684. + */
  685. +
  686. +
  687. +/* Socket pair created with non-blocking mode */
  688. +#define POLL_OPTIONS_SOCKET_PAIR_NONBLOCK_CONN 0x01
  689. +
  690. +typedef unsigned int SocketSpecialOpts;
  691. +
  692. +typedef struct PollOptions {
  693. + Bool locked; // Use internal MXUser for locking
  694. + Bool allowFullQueue; // Don't assert when device event queue is full.
  695. + VThreadID windowsMsgThread; // thread that processes Windows messages
  696. + PollerFireWrapper fireWrapperFn; // optional; may be useful for stats
  697. + void *fireWrapperData; // optional
  698. + PollerErrorFn errorFn; // optional; called upon unrecoverable error
  699. + SocketSpecialOpts pollSocketOpts;
  700. +} PollOptions;
  701. +
  702. +
  703. +void Poll_InitDefault(void);
  704. +void Poll_InitDefaultEx(const PollOptions *opts);
  705. +void Poll_InitGtk(void); // On top of glib for Linux
  706. +void Poll_InitCF(void); // On top of CoreFoundation for OSX
  707. +
  708. +
  709. +/*
  710. + * Functions
  711. + */
  712. +int Poll_SocketPair(Bool vmci, Bool stream, int fds[2], SocketSpecialOpts opts);
  713. +void Poll_Loop(Bool loop, Bool *exit, PollClass c);
  714. +void Poll_LoopTimeout(Bool loop, Bool *exit, PollClass c, int timeout);
  715. +Bool Poll_LockingEnabled(void);
  716. +void Poll_Exit(void);
  717. +
  718. +
  719. +/*
  720. + * Poll_Callback adds a callback regardless of whether an identical one exists.
  721. + * The exception to this rule is POLL_DEVICE callbacks: there is a maximum of
  722. + * one read and one write callback per fd.
  723. + *
  724. + * Poll_CallbackRemove removes one callback. If there are multiple identical
  725. + * callbacks, which one is removed is an implementation detail. Note that in
  726. + * the case of POLL_DEVICE and POLL_REALTIME callbacks, the fd/delay used to
  727. + * create the callback is not specified when removing, so all callbacks
  728. + * of those types with the same flags, function, and clientData are considered
  729. + * "identical" even if their fd/delay differed.
  730. + */
  731. +
  732. +VMwareStatus Poll_Callback(PollClassSet classSet,
  733. + int flags,
  734. + PollerFunction f,
  735. + void *clientData,
  736. + PollEventType type,
  737. + PollDevHandle info, // fd/microsec delay
  738. + MXUserRecLock *lck);
  739. +Bool Poll_CallbackRemove(PollClassSet classSet,
  740. + int flags,
  741. + PollerFunction f,
  742. + void *clientData,
  743. + PollEventType type);
  744. +Bool Poll_CallbackRemoveOneByCB(PollClassSet classSet,
  745. + int flags,
  746. + PollerFunction f,
  747. + PollEventType type,
  748. + void **clientData);
  749. +
  750. +void Poll_NotifyChange(PollClassSet classSet);
  751. +
  752. +/*
  753. + * Wrappers for Poll_Callback and Poll_CallbackRemove that present
  754. + * simpler subsets of those interfaces.
  755. + */
  756. +
  757. +VMwareStatus Poll_CB_Device(PollerFunction f,
  758. + void *clientData,
  759. + PollDevHandle device,
  760. + Bool periodic);
  761. +
  762. +Bool Poll_CB_DeviceRemove(PollerFunction f,
  763. + void *clientData,
  764. + Bool periodic);
  765. +
  766. +
  767. +VMwareStatus Poll_CB_RTime(PollerFunction f,
  768. + void *clientData,
  769. + int64 delay, // microseconds
  770. + Bool periodic,
  771. + MXUserRecLock *lock);
  772. +
  773. +Bool Poll_CB_RTimeRemove(PollerFunction f,
  774. + void *clientData,
  775. + Bool periodic);
  776. +
  777. +
  778. +#ifdef _WIN32
  779. +void Poll_SetPumpsWindowsMessages(Bool pumps);
  780. +void Poll_SetWindowMessageRecipient(HWND hWnd, UINT msg, Bool alwaysThunk);
  781. +Bool Poll_FireWndCallback(void *lparam);
  782. +#endif
  783. +
  784. +#if defined(__cplusplus)
  785. +} // extern "C"
  786. +#endif
  787. +
  788. +#endif // _POLL_H_
  789. diff --git a/lib/rpcIn/rpcin.c b/open-vm-tools/lib/rpcIn/rpcin.c
  790. index 8b1fe759..f22fcd40 100644
  791. --- a/lib/rpcIn/rpcin.c
  792. +++ b/lib/rpcIn/rpcin.c
  793. @@ -57,7 +57,7 @@
  794. #if defined(VMTOOLS_USE_VSOCKET)
  795. # include <glib.h>
  796. -# include "poll.h"
  797. +# include "vm_poll.h"
  798. # include "asyncsocket.h"
  799. # include "vmci_defs.h"
  800. #include "dataMap.h"
  801. --
  802. 2.36.1