~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to modules/linux/shared/vmci_kernel_if.h

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *********************************************************/
18
18
 
19
19
/*
20
 
 * vmci_kernel_if.h -- 
21
 
 * 
 
20
 * vmci_kernel_if.h --
 
21
 *
22
22
 *      This file defines helper functions for VMCI host _and_ guest
23
23
 *      kernel code. It must work for Windows, Mac OS, vmkernel, Linux and
24
24
 *      Solaris kernels, i.e. using defines where necessary.
25
25
 */
26
 
 
 
26
 
27
27
#ifndef _VMCI_KERNEL_IF_H_
28
28
#define _VMCI_KERNEL_IF_H_
29
29
 
30
30
#if !defined(linux) && !defined(_WIN32) && !defined(__APPLE__) && \
31
31
    !defined(VMKERNEL) && !defined(SOLARIS)
32
 
#error "Platform not supported."
 
32
#  error "Platform not supported."
33
33
#endif
34
34
 
35
35
#if defined(_WIN32)
36
 
#include <ntddk.h>
37
 
#endif 
 
36
#  include <ntddk.h>
 
37
#endif
38
38
 
39
39
#if defined(linux) && !defined(VMKERNEL)
 
40
#  include "driver-config.h"
 
41
#  include "compat_cred.h"
 
42
#  include "compat_module.h"
 
43
#  include "compat_semaphore.h"
 
44
#  include "compat_spinlock.h"
40
45
#  include "compat_version.h"
41
 
#  include "compat_wait.h"
42
 
#  include "compat_spinlock.h"
43
 
#  include "compat_semaphore.h"
 
46
#  include <linux/wait.h>
44
47
#endif // linux
45
48
 
46
49
#ifdef __APPLE__
47
50
#  include <IOKit/IOLib.h>
48
 
#include <mach/task.h>
49
 
#include <mach/semaphore.h>
 
51
#  include <mach/task.h>
 
52
#  include <mach/semaphore.h>
 
53
#  include <sys/kauth.h>
50
54
#endif
51
55
 
52
56
#ifdef VMKERNEL
53
 
#include "splock.h"
54
 
#include "semaphore_ext.h"
 
57
#  include "splock.h"
 
58
#  include "semaphore_ext.h"
 
59
#  include "vmkapi.h"
55
60
#endif
56
61
 
57
62
#ifdef SOLARIS
 
63
#  include <sys/ddi.h>
 
64
#  include <sys/kmem.h>
58
65
#  include <sys/mutex.h>
59
66
#  include <sys/poll.h>
60
67
#  include <sys/semaphore.h>
61
 
#  include <sys/kmem.h>
 
68
#  include <sys/sunddi.h>
 
69
#  include <sys/types.h>
62
70
#endif
63
71
 
64
72
#include "vm_basic_types.h"
65
73
#include "vmci_defs.h"
66
74
 
67
 
#if defined(__APPLE__)
 
75
#if defined(VMKERNEL)
 
76
#  include "list.h"
 
77
#else
68
78
#  include "dbllnklst.h"
69
79
#endif
70
80
 
76
86
/* Platform specific type definitions. */
77
87
 
78
88
#if defined(VMKERNEL)
 
89
#  define VMCI_EXPORT_SYMBOL(_SYMBOL)  VMK_MODULE_EXPORT_SYMBOL(_SYMBOL);
 
90
#elif defined(linux)
 
91
#  define VMCI_EXPORT_SYMBOL(_symbol)  EXPORT_SYMBOL(_symbol);
 
92
#elif defined(__APPLE__)
 
93
#  define VMCI_EXPORT_SYMBOL(_symbol)  __attribute__((visibility("default")))
 
94
#else
 
95
#  define VMCI_EXPORT_SYMBOL(_symbol)
 
96
#endif
 
97
 
 
98
#if defined(VMKERNEL)
79
99
  typedef SP_SpinLock VMCILock;
80
100
  typedef SP_IRQL VMCILockFlags;
81
101
  typedef Semaphore VMCIEvent;
82
102
  typedef Semaphore VMCIMutex;
83
103
  typedef World_ID VMCIHostVmID;
 
104
  typedef uint32 VMCIHostUser;
84
105
#elif defined(linux)
85
106
  typedef spinlock_t VMCILock;
86
107
  typedef unsigned long VMCILockFlags;
87
108
  typedef wait_queue_head_t VMCIEvent;
88
109
  typedef struct semaphore VMCIMutex;
89
110
  typedef PPN *VMCIPpnList; /* List of PPNs in produce/consume queue. */
 
111
  typedef uid_t VMCIHostUser;
90
112
#elif defined(__APPLE__)
91
113
  typedef IOLock *VMCILock;
92
114
  typedef unsigned long VMCILockFlags;
97
119
  } VMCIEvent;
98
120
  typedef IOLock *VMCIMutex;
99
121
  typedef void *VMCIPpnList; /* Actually a pointer to the C++ Object IOMemoryDescriptor */
 
122
  typedef uid_t VMCIHostUser;
100
123
#elif defined(_WIN32)
101
124
  typedef KSPIN_LOCK VMCILock;
102
125
  typedef KIRQL VMCILockFlags;
103
126
  typedef KEVENT VMCIEvent;
104
127
  typedef FAST_MUTEX VMCIMutex;
105
128
  typedef PMDL VMCIPpnList; /* MDL to map the produce/consume queue. */
 
129
  typedef PSID VMCIHostUser;
106
130
#elif defined(SOLARIS)
107
131
  typedef kmutex_t VMCILock;
108
132
  typedef unsigned long VMCILockFlags;
109
133
  typedef ksema_t VMCIEvent;
110
134
  typedef kmutex_t VMCIMutex;
111
135
  typedef PPN *VMCIPpnList; /* List of PPNs in produce/consume queue. */
 
136
  typedef uid_t VMCIHostUser;
112
137
#endif // VMKERNEL
113
138
 
114
139
/* Callback needed for correctly waiting on events. */
117
142
/*
118
143
 * The VMCI locks use a ranking scheme similar to the one used by
119
144
 * vmkernel. While holding a lock L1 with rank R1, only locks with
120
 
 * rank higher than R1 may be grabbed. The available ranks for VMCI 
 
145
 * rank higher than R1 may be grabbed. The available ranks for VMCI
121
146
 * locks are (in descending order):
122
147
 * - VMCI_LOCK_RANK_HIGH_BH : to be used for locks grabbed while executing
123
148
 *   in a bottom half and not held while grabbing other locks.
197
222
#elif defined(__APPLE__)
198
223
   struct Socket *socket; /* vmci Socket object on Mac OS. */
199
224
#elif defined(_WIN32)
200
 
   KEVENT *callEvent; /* Ptr to userlevel event used when signalling 
 
225
   KEVENT *callEvent; /* Ptr to userlevel event used when signalling
201
226
                       * new pending guestcalls in kernel.
202
227
                       */
203
228
#elif defined(SOLARIS)
204
229
   struct pollhead pollhead; /* Per datagram handle pollhead structure to
205
 
                              * be treated as a black-box. None of its 
 
230
                              * be treated as a black-box. None of its
206
231
                              * fields should be referenced.
207
232
                              */
208
233
#endif
209
234
} VMCIHost;
210
235
 
 
236
/*
 
237
 * Guest device port I/O.
 
238
 */
 
239
 
 
240
#if defined(linux)
 
241
   typedef unsigned short int VMCIIoPort;
 
242
   typedef int VMCIIoHandle;
 
243
#elif defined(_WIN32)
 
244
   typedef PUCHAR VMCIIoPort;
 
245
   typedef int VMCIIoHandle;
 
246
#elif defined(SOLARIS)
 
247
   typedef uint8_t * VMCIIoPort;
 
248
   typedef ddi_acc_handle_t VMCIIoHandle;
 
249
#elif defined(__APPLE__)
 
250
   typedef unsigned short int VMCIIoPort;
 
251
   typedef void *VMCIIoHandle;
 
252
#endif // __APPLE__
 
253
 
 
254
void VMCI_ReadPortBytes(VMCIIoHandle handle, VMCIIoPort port, uint8 *buffer,
 
255
                        size_t bufferLength);
 
256
 
211
257
 
212
258
void VMCI_InitLock(VMCILock *lock, char *name, VMCILockRank rank);
213
259
void VMCI_CleanupLock(VMCILock *lock);
235
281
void VMCIHost_SignalBitmap(VMCIHost *hostContext);
236
282
#endif
237
283
 
 
284
#if defined(_WIN32)
 
285
   /*
 
286
    * On Windows, Driver Verifier will panic() if we leak memory when we are
 
287
    * unloaded.  It dumps the leaked blocks for us along with callsites, which
 
288
    * it handily tracks, but if we embed ExAllocate() inside a function, then
 
289
    * the callsite is useless.  So make this a macro on this platform only.
 
290
    */
 
291
#  define VMCI_AllocKernelMem(_sz, _f)                       \
 
292
      ExAllocatePoolWithTag((((_f) & VMCI_MEMORY_NONPAGED) ? \
 
293
                             NonPagedPool : PagedPool),      \
 
294
                            (_sz), 'MMTC')
 
295
#else // _WIN32
238
296
void *VMCI_AllocKernelMem(size_t size, int flags);
 
297
#endif // _WIN32
239
298
void VMCI_FreeKernelMem(void *ptr, size_t size);
240
 
VMCIBuffer VMCI_AllocBuffer(size_t size, int flags);
241
 
void *VMCI_MapBuffer(VMCIBuffer buf);
242
 
void VMCI_ReleaseBuffer(void *ptr);
243
 
void VMCI_FreeBuffer(VMCIBuffer buf, size_t size);
244
 
#ifdef SOLARIS
245
 
int VMCI_CopyToUser(VA64 dst, const void *src, size_t len, int mode);
246
 
#else
 
299
 
247
300
int VMCI_CopyToUser(VA64 dst, const void *src, size_t len);
248
 
/*
249
 
 * Don't need the following for guests, hence no Solaris code for this
250
 
 * function.
251
 
 */
252
301
Bool VMCIWellKnownID_AllowMap(VMCIId wellKnownID,
253
302
                              VMCIPrivilegeFlags privFlags);
254
 
#endif
 
303
 
 
304
int VMCIHost_CompareUser(VMCIHostUser *user1, VMCIHostUser *user2);
255
305
 
256
306
void VMCI_CreateEvent(VMCIEvent *event);
257
307
void VMCI_DestroyEvent(VMCIEvent *event);
258
308
void VMCI_SignalEvent(VMCIEvent *event);
259
 
void VMCI_WaitOnEvent(VMCIEvent *event, VMCIEventReleaseCB releaseCB, 
 
309
void VMCI_WaitOnEvent(VMCIEvent *event, VMCIEventReleaseCB releaseCB,
260
310
                      void *clientData);
261
311
#if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32)) && !defined(VMKERNEL)
262
312
Bool VMCI_WaitOnEventInterruptible(VMCIEvent *event,
269
319
int VMCI_CopyFromUser(void *dst, VA64 src, size_t len);
270
320
#endif
271
321
 
272
 
#if defined(_WIN32)
273
 
void VMCI_InitHelperQueue(void);
274
 
void VMCI_ExitHelperQueue(void);
275
 
#endif // _WIN32
276
 
 
277
322
typedef void (VMCIWorkFn)(void *data);
278
323
Bool VMCI_CanScheduleDelayedWork(void);
279
324
int VMCI_ScheduleDelayedWork(VMCIWorkFn  *workFn,
284
329
void VMCIMutex_Acquire(VMCIMutex *mutex);
285
330
void VMCIMutex_Release(VMCIMutex *mutex);
286
331
 
287
 
#if defined(SOLARIS)
 
332
#if defined(SOLARIS) || defined(_WIN32)
288
333
int VMCIKernelIf_Init(void);
289
334
void VMCIKernelIf_Exit(void);
290
 
#endif          /* SOLARIS  */
 
335
#endif // SOLARIS || _WIN32
291
336
 
292
337
#if !defined(VMKERNEL) && (defined(__linux__) || defined(_WIN32) || \
293
338
                           defined(SOLARIS) || defined(__APPLE__))
306
351
int VMCI_PopulatePPNList(uint8 *callBuf, const PPNSet *ppnSet);
307
352
#endif
308
353
 
309
 
#if !defined(VMX86_TOOLS)
310
354
struct VMCIQueue;
311
355
 
312
 
#if  !defined(VMKERNEL)
 
356
#if !defined(VMKERNEL)
313
357
struct PageStoreAttachInfo;
314
358
struct VMCIQueue *VMCIHost_AllocQueue(uint64 queueSize);
315
359
void VMCIHost_FreeQueue(struct VMCIQueue *queue, uint64 queueSize);
321
365
                                struct VMCIQueue *produceQ,
322
366
                                struct VMCIQueue *detachQ);
323
367
#endif // VMKERNEL
 
368
 
324
369
#ifdef _WIN32
325
 
void VMCIHost_InitQueueMutex(struct VMCIQueue *produceQ,
326
 
                             struct VMCIQueue *consumeQ);
327
 
void VMCIHost_AcquireQueueMutex(struct VMCIQueue *queue);
328
 
void VMCIHost_ReleaseQueueMutex(struct VMCIQueue *queue);
329
 
Bool VMCIHost_EnqueueToDevNull(struct VMCIQueue *queue);
330
 
 
331
370
/*
332
371
 * Special routine used on the Windows platform to save a queue when
333
372
 * its backing memory goes away.
337
376
                           struct VMCIQueue *produceQ,
338
377
                           struct VMCIQueue *detachQ,
339
378
                           const uint64 produceQSize);
 
379
#endif // _WIN32
 
380
 
 
381
#ifdef _WIN32
 
382
void VMCI_InitQueueMutex(struct VMCIQueue *produceQ,
 
383
                             struct VMCIQueue *consumeQ);
 
384
void VMCI_AcquireQueueMutex(struct VMCIQueue *queue);
 
385
void VMCI_ReleaseQueueMutex(struct VMCIQueue *queue);
 
386
Bool VMCI_EnqueueToDevNull(struct VMCIQueue *queue);
 
387
int VMCI_ConvertToLocalQueue(struct VMCIQueue *queueInfo,
 
388
                             struct VMCIQueue *otherQueueInfo,
 
389
                             uint64 size, Bool keepContent,
 
390
                             void **oldQueue);
 
391
void VMCI_RevertToNonLocalQueue(struct VMCIQueue *queueInfo,
 
392
                                void *nonLocalQueue, uint64 size);
 
393
void VMCI_FreeQueueBuffer(void *queue, uint64 size);
 
394
Bool VMCI_CanCreate(void);
340
395
#else // _WIN32
341
 
#  define VMCIHost_InitQueueMutex(_pq, _cq)
342
 
#  define VMCIHost_AcquireQueueMutex(_q)
343
 
#  define VMCIHost_ReleaseQueueMutex(_q)
344
 
#  define VMCIHost_EnqueueToDevNull(_q) FALSE
345
 
#endif // _WIN32
346
 
#endif // !VMX86_TOOLS
347
 
 
 
396
#  define VMCI_InitQueueMutex(_pq, _cq)
 
397
#  define VMCI_AcquireQueueMutex(_q)
 
398
#  define VMCI_ReleaseQueueMutex(_q)
 
399
#  define VMCI_EnqueueToDevNull(_q) FALSE
 
400
#  define VMCI_ConvertToLocalQueue(_pq, _cq, _s, _oq, _kc) VMCI_ERROR_UNAVAILABLE
 
401
#  define VMCI_RevertToNonLocalQueue(_q, _nlq, _s)
 
402
#  define VMCI_FreeQueueBuffer(_q, _s)
 
403
#  define VMCI_CanCreate() TRUE
 
404
#endif // !_WIN32
 
405
Bool VMCI_GuestPersonalityActive(void);
 
406
Bool VMCI_HostPersonalityActive(void);
 
407
 
 
408
 
 
409
#if defined(VMKERNEL)
 
410
  typedef List_Links VMCIListItem;
 
411
  typedef List_Links VMCIList;
 
412
 
 
413
#  define VMCIList_Init(_l)   List_Init(_l)
 
414
#  define VMCIList_InitEntry(_e)  List_InitElement(_e)
 
415
#  define VMCIList_Empty(_l)   List_IsEmpty(_l)
 
416
#  define VMCIList_Insert(_e, _l) List_Insert(_e, LIST_ATREAR(_l))
 
417
#  define VMCIList_Remove(_e, _l) List_Remove(_e)
 
418
#  define VMCIList_Scan(_cur, _l) LIST_FORALL(_l, _cur)
 
419
#  define VMCIList_ScanSafe(_cur, _next, _l) LIST_FORALL_SAFE(_l, _cur, _next)
 
420
#  define VMCIList_Entry(_elem, _type, _field) List_Entry(_elem, _type, _field)
 
421
#  define VMCIList_First(_l) (VMCIList_Empty(_l)?NULL:List_First(_l))
 
422
#else
 
423
  typedef DblLnkLst_Links VMCIListItem;
 
424
  typedef DblLnkLst_Links VMCIList;
 
425
 
 
426
#  define VMCIList_Init(_l)   DblLnkLst_Init(_l)
 
427
#  define VMCIList_InitEntry(_e)   DblLnkLst_Init(_e)
 
428
#  define VMCIList_Empty(_l)   (!DblLnkLst_IsLinked(_l))
 
429
#  define VMCIList_Insert(_e, _l) DblLnkLst_LinkLast(_l, _e)
 
430
#  define VMCIList_Remove(_e, _l) DblLnkLst_Unlink1(_e)
 
431
#  define VMCIList_Scan(_cur, _l) DblLnkLst_ForEach(_cur, _l)
 
432
#  define VMCIList_ScanSafe(_cur, _next, _l) DblLnkLst_ForEachSafe(_cur, _next, _l)
 
433
#  define VMCIList_Entry(_elem, _type, _field) DblLnkLst_Container(_elem, _type, _field)
 
434
#  define VMCIList_First(_l) (VMCIList_Empty(_l)?NULL:(_l)->next)
 
435
#endif
348
436
 
349
437
#endif // _VMCI_KERNEL_IF_H_