From: Oliver Kurth Date: Mon, 6 Jan 2020 23:46:20 +0000 (-0800) Subject: Changes to common header files. X-Git-Tag: stable-11.1.0~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4c6d05537d8ac2a3f6b0513c54b419fa159ceab;p=thirdparty%2Fopen-vm-tools.git Changes to common header files. 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. --- diff --git a/open-vm-tools/lib/include/vm_atomic.h b/open-vm-tools/lib/include/vm_atomic.h index dd03c91c7..11dba32d2 100644 --- a/open-vm-tools/lib/include/vm_atomic.h +++ b/open-vm-tools/lib/include/vm_atomic.h @@ -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 /* diff --git a/open-vm-tools/lib/include/vm_basic_types.h b/open-vm-tools/lib/include/vm_basic_types.h index 0e57ce594..eeacbc38f 100644 --- a/open-vm-tools/lib/include/vm_basic_types.h +++ b/open-vm-tools/lib/include/vm_basic_types.h @@ -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