From: Oliver Kurth Date: Tue, 30 Apr 2019 20:24:25 +0000 (-0700) Subject: vm_basic_defs.h: include stddef.h X-Git-Tag: stable-11.0.0~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e89c751f0045f163c468c49b71db70478581c85c;p=thirdparty%2Fopen-vm-tools.git vm_basic_defs.h: include stddef.h The stddef.h header has existed since C89. It includes interesting things like an offsetof definition, and a definition of NULL. Let's stop re-inventing this long-standardized header. Except in vmkernel, where bogus __FreeBSD__ values break gcc's . (Detail: vmkernel networking likes to define __FreeBSD__ to empty or 1, whereas ABI requires "FreeBSD major version". This change is deliberately minimal as touching headers included everywhere is inherently fragile. Further cleanups (like removing vmw_offsetof) can be done in follow-up changes. The stddef.h header is a 'freestanding' header, which means it's part of the language and not a "system" header. It is thus safe to include (modulo vmkernel-networking problem above). --- diff --git a/open-vm-tools/lib/include/vm_basic_defs.h b/open-vm-tools/lib/include/vm_basic_defs.h index cea886074..30b2b3250 100644 --- a/open-vm-tools/lib/include/vm_basic_defs.h +++ b/open-vm-tools/lib/include/vm_basic_defs.h @@ -83,12 +83,44 @@ #endif #define __IS_FREEBSD_VER__(ver) (__IS_FREEBSD__ && __FreeBSD_version >= (ver)) +/* + * provides definitions for: + * NULL, offsetof + * References: + * C90 7.17, C99 7.19, C11 7.19 + */ +#if !defined(VMKERNEL) +# include +#else + /* + * Vmkernel's bogus __FreeBSD__ value causes gcc to break. + * Work around by doing similar things. Bug 2116887 and 2229647. + */ +# ifndef offsetof + /* + * We use the builtin offset for gcc/clang, except when we're running + * under the vmkernel's GDB macro preprocessor, since gdb doesn't + * understand __builtin_offsetof. + */ +# if defined VMKERNEL_GDB_MACRO_BUILDER +# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +# else +# define offsetof __builtin_offsetof +# endif +# endif + +# ifndef NULL +# ifdef __cplusplus +# define NULL 0 +# else +# define NULL ((void *)0) +# endif +# endif + +#endif // VMKERNEL + #if defined _WIN32 && defined USERLEVEL - #include /* - * We redefine offsetof macro from stddef; make - * sure that it's already defined before we do that. - */ - #include // for Sleep() and LOWORD() etc. + #include // for Sleep() and LOWORD() etc. #undef GetFreeSpace // Unpollute preprocessor namespace. #endif @@ -97,40 +129,12 @@ * Simple macros */ -#ifndef vmw_offsetof -#define vmw_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) -#endif -#if (defined __APPLE__ || defined __FreeBSD__) && \ - (!defined KERNEL && !defined _KERNEL && !defined VMKERNEL && !defined __KERNEL__) -# include -#else -#ifndef offsetof -#define VMW_DEFINED_OFFSETOF - -/* - * XXX While the _WIN32 implementation appears to be identical to vmw_offsetof - * in terms of behavior, they need to be separate to match verbatim the - * definition used by the respective compilers, to avoid a redefinition warning. - * - * This is necessary until we eliminate the inclusion of above. - */ -#ifdef _WIN32 -#define offsetof(s,m) (size_t)&(((s *)0)->m) -/* - * We use the builtin offset for gcc/clang, except when we're running under the - * vmkernel's GDB macro preprocessor, since gdb doesn't understand - * __builtin_offsetof. - */ -#elif defined __GNUC__ && !defined VMKERNEL_GDB_MACRO_BUILDER -#define offsetof __builtin_offsetof -#else -#define offsetof vmw_offsetof +/* Historical name. Deprecated. TODO: switch to offsetof */ +#ifndef vmw_offsetof +#define vmw_offsetof(TYPE, MEMBER) offsetof(TYPE, MEMBER) #endif -#endif // offsetof -#endif // __APPLE__ - #define VMW_CONTAINER_OF(ptr, type, member) \ ((type *)((char *)(ptr) - vmw_offsetof(type, member))) @@ -198,18 +202,6 @@ Max(int a, int b) #define IMPLIES(a,b) (!(a) || (b)) -/* - * Not everybody (e.g., the monitor) has NULL - */ - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - /* * Token concatenation