]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes to common header files.
authorOliver Kurth <okurth@vmware.com>
Mon, 6 Jan 2020 23:46:20 +0000 (15:46 -0800)
committerOliver Kurth <okurth@vmware.com>
Mon, 6 Jan 2020 23:46:20 +0000 (15:46 -0800)
Make ALIGNED() functional for 64-bit Windows

The current implementation of ALIGNED in vm_basic_types.h only
works for compilers that are, or pretend to be, GCC.  However,
it is reasonable to conclude that data specifically aligned
for one OS / compiler should be aligned the same way when built
with other tools or for OSes.

This change updates the ALIGNED macro to correctly function when
building on 64-bit Windows.  If not using GCC-alike, or Windows,
the macro continues to expand to nothing.

The MSVC __declspec construct accepts a limited syntax, basically
requiring an integer literal (see pciPassthruInfo_public.h).  It
must be a prefix operation.

The GCC __attribute__ is more expressive and can be postfix or
prefix, so it is moved to be prefix.

The bulk of the change moves the use of ALIGNED to be prefix in
all places that compile for the Workstation product on Windows.

open-vm-tools/lib/include/vm_atomic.h
open-vm-tools/lib/include/vm_basic_types.h

index dd03c91c77229ccc78b0594c1d8dea9db2575e8a..11dba32d26d7c582c7edb813115d9c7c2ba193fd 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2020 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -122,27 +122,27 @@ extern "C" {
 
 
 /* Basic atomic types: 8, 16, 32, 64 and 128 bits */
-typedef struct Atomic_uint8 {
+typedef ALIGNED(1) struct Atomic_uint8 {
    volatile uint8 value;
-} Atomic_uint8 ALIGNED(1);
+} Atomic_uint8;
 
-typedef struct Atomic_uint16 {
+typedef ALIGNED(2) struct Atomic_uint16 {
    volatile uint16 value;
-} Atomic_uint16 ALIGNED(2);
+} Atomic_uint16;
 
-typedef struct Atomic_uint32 {
+typedef ALIGNED(4) struct Atomic_uint32 {
    volatile uint32 value;
-} Atomic_uint32 ALIGNED(4);
+} Atomic_uint32;
 
-typedef struct Atomic_uint64 {
+typedef ALIGNED(8) struct Atomic_uint64 {
    volatile uint64 value;
-} Atomic_uint64 ALIGNED(8);
+} Atomic_uint64;
 
 #if defined __GNUC__ && defined VM_64BIT && \
      (defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 || defined VM_ARM_64)
-typedef struct Atomic_uint128 {
+typedef ALIGNED(16) struct Atomic_uint128 {
    volatile uint128 value;
-} Atomic_uint128 ALIGNED(16);
+} Atomic_uint128;
 #endif
 
 /*
index 0e57ce5945cb821c006af4b493c5ac0733e611f2..eeacbc38f1f925f5d87ef0240df9eb377aa197dd 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2020 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -903,12 +903,10 @@ typedef void * UserVA;
 #endif
 
 #ifndef UNUSED_TYPE
-// XXX _Pragma would better but doesn't always work right now.
 #  define UNUSED_TYPE(_parm) UNUSED_PARAM(_parm)
 #endif
 
 #ifndef UNUSED_VARIABLE
-// XXX is there a better way?
 #  define UNUSED_VARIABLE(_var) (void)_var
 #endif
 
@@ -923,29 +921,21 @@ typedef void * UserVA;
 
 /*
  * ALIGNED specifies minimum alignment in "n" bytes.
+ *
+ * NOTE: __declspec(align) has limited syntax; it must essentially be
+ *       an integer literal.  Expressions, such as sizeof(), do not
+ *       work.
  */
 
 #ifdef __GNUC__
 #define ALIGNED(n) __attribute__((__aligned__(n)))
+#elif defined(_MSC_VER)
+#define ALIGNED(n) __declspec(align(n))
 #else
 #define ALIGNED(n)
 #endif
 
 
-/*
- * Encapsulate the syntactic differences between gcc and msvc alignment control.
- * BOUNDARY must match in the prefix and suffix.
- */
-
-#ifdef _WIN32
-#define ALIGN_PREFIX(BOUNDRY) __declspec(align(BOUNDRY))
-#define ALIGN_SUFFIX(BOUNDRY)
-#else
-#define ALIGN_PREFIX(BOUNDRY)
-#define ALIGN_SUFFIX(BOUNDRY) __attribute__((__aligned__(BOUNDRY)))
-#endif
-
-
 /*
  * Once upon a time, this was used to silence compiler warnings that
  * get generated when the compiler thinks that a function returns