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