PERFORCE change 214748 for review

Robert Watson rwatson at FreeBSD.org
Sun Jul 22 12:42:18 UTC 2012


http://p4web.freebsd.org/@@214748?ac=10

Change 214748 by rwatson at rwatson_lethe on 2012/07/22 12:42:14

	Revise OpenBSM configuration logic for detecting and using endian.h
	variations -- recent Ubuntu includes a partial BSD endian.h, with
	be32toh() and friends, but not be32enc() and its associates.  Prefer
	a notion of USE_foo to HAVE_foo in order to centralise decision
	logic in configure.ac rather than putting it in each .c file, which
	is good practice regardless.  This involves breaking our compat
	endian.h into two different files, to be included independently
	depending on what is required locally.

Affected files ...

.. //depot/projects/trustedbsd/openbsm/compat/endian.h#9 edit
.. //depot/projects/trustedbsd/openbsm/compat/endian_enc.h#1 add
.. //depot/projects/trustedbsd/openbsm/configure.ac#57 edit
.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#70 edit
.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#98 edit

Differences ...

==== //depot/projects/trustedbsd/openbsm/compat/endian.h#9 (text+ko) ====

@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * Derived from FreeBSD src/sys/sys/endian.h:1.6.
- * $P4: //depot/projects/trustedbsd/openbsm/compat/endian.h#8 $
+ * $P4: //depot/projects/trustedbsd/openbsm/compat/endian.h#9 $
  */
 
 #ifndef _COMPAT_ENDIAN_H_
@@ -150,112 +150,4 @@
 #define	le64toh(x)	bswap64((x))
 #endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
 
-/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
-
-static __inline uint16_t
-be16dec(const void *pp)
-{
-	unsigned char const *p = (unsigned char const *)pp;
-
-	return ((p[0] << 8) | p[1]);
-}
-
-static __inline uint32_t
-be32dec(const void *pp)
-{
-	unsigned char const *p = (unsigned char const *)pp;
-
-	return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
-}
-
-static __inline uint64_t
-be64dec(const void *pp)
-{
-	unsigned char const *p = (unsigned char const *)pp;
-
-	return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
-}
-
-static __inline uint16_t
-le16dec(const void *pp)
-{
-	unsigned char const *p = (unsigned char const *)pp;
-
-	return ((p[1] << 8) | p[0]);
-}
-
-static __inline uint32_t
-le32dec(const void *pp)
-{
-	unsigned char const *p = (unsigned char const *)pp;
-
-	return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
-}
-
-static __inline uint64_t
-le64dec(const void *pp)
-{
-	unsigned char const *p = (unsigned char const *)pp;
-
-	return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
-}
-
-static __inline void
-be16enc(void *pp, uint16_t u)
-{
-	unsigned char *p = (unsigned char *)pp;
-
-	p[0] = (u >> 8) & 0xff;
-	p[1] = u & 0xff;
-}
-
-static __inline void
-be32enc(void *pp, uint32_t u)
-{
-	unsigned char *p = (unsigned char *)pp;
-
-	p[0] = (u >> 24) & 0xff;
-	p[1] = (u >> 16) & 0xff;
-	p[2] = (u >> 8) & 0xff;
-	p[3] = u & 0xff;
-}
-
-static __inline void
-be64enc(void *pp, uint64_t u)
-{
-	unsigned char *p = (unsigned char *)pp;
-
-	be32enc(p, u >> 32);
-	be32enc(p + 4, u & 0xffffffff);
-}
-
-static __inline void
-le16enc(void *pp, uint16_t u)
-{
-	unsigned char *p = (unsigned char *)pp;
-
-	p[0] = u & 0xff;
-	p[1] = (u >> 8) & 0xff;
-}
-
-static __inline void
-le32enc(void *pp, uint32_t u)
-{
-	unsigned char *p = (unsigned char *)pp;
-
-	p[0] = u & 0xff;
-	p[1] = (u >> 8) & 0xff;
-	p[2] = (u >> 16) & 0xff;
-	p[3] = (u >> 24) & 0xff;
-}
-
-static __inline void
-le64enc(void *pp, uint64_t u)
-{
-	unsigned char *p = (unsigned char *)pp;
-
-	le32enc(p, u & 0xffffffff);
-	le32enc(p + 4, u >> 32);
-}
-
 #endif	/* _COMPAT_ENDIAN_H_ */

==== //depot/projects/trustedbsd/openbsm/configure.ac#57 (text+ko) ====

@@ -3,7 +3,7 @@
 
 AC_PREREQ(2.59)
 AC_INIT([OpenBSM], [1.2alpha1], [trustedbsd-audit at TrustesdBSD.org],[openbsm])
-AC_REVISION([$P4: //depot/projects/trustedbsd/openbsm/configure.ac#56 $])
+AC_REVISION([$P4: //depot/projects/trustedbsd/openbsm/configure.ac#57 $])
 AC_CONFIG_SRCDIR([bin/auditreduce/auditreduce.c])
 AC_CONFIG_AUX_DIR(config)
 AC_CONFIG_MACRO_DIR([m4])
@@ -36,7 +36,7 @@
 # Checks for header files.
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([endian.h mach/mach.h machine/endian.h sys/endian.h stdint.h])
+AC_CHECK_HEADERS([mach/mach.h stdint.h])
 
 AC_DEFINE([_GNU_SOURCE],,[Use extended API on platforms that require it])
 
@@ -125,17 +125,75 @@
 AM_CONDITIONAL(HAVE_AUDIT_SYSCALLS, $have_audit_syscalls)
 
 #
-# There are a wide variety of endian macros and functions in the wild; we try
-# to use the native support if it defines be32enc(), but otherwise have to
-# use our own.
+# We rely on the BSD be32toh() and be32enc()-style endian macros to perform
+# byte order conversions.  Availability of these varies considerably -- in
+# general, a system might have neither, be32toh(), or be32toh() and be32enc().
+# There is also variation in which headers are even present, and whether they
+# are macros or functions.  Try to organise the world into some simpler cases.
+# The following macros may be set at the end:
+#
+# USE_ENDIAN_H
+# USE_SYS_ENDIAN_H
+# USE_COMPAT_ENDIAN_H
+# USE_COMPAT_ENDIAN_ENC_H
+#
+# First, decide which system endian.h to use.
+#
+AC_CHECK_HEADERS([endian.h], [
+	have_endian_h=yes
+	AC_DEFINE(HAVE_ENDIAN_H,, Define if endian.h is present)
+], [
+	have_endian_h=no
+])
+
+AC_CHECK_HEADERS([sys/endian.h], [
+	have_sys_endian_h=yes
+	AC_DEFINE(HAVE_SYS_ENDIAN_H, , Define if sys/endian.h is present)
+], [
+	have_sys_endian_h=no
+])
+
+if test $have_endian_h; then
+	AC_DEFINE(USE_ENDIAN_H,, Define if endian should be included)
+elif test $have_sys_endian_h; then
+	AC_DEFINE(USE_SYS_ENDIAN_H,, Define if sys/endian.h should be included)
+else
+	AC_MSG_ERROR([no endian.h])
+fi
+
+#
+# Next, decide if we need to supplement with compat headers.
 #
 AC_TRY_LINK([
+	#ifdef USE_ENDIAN_H
+	#include <endian.h>
+	#endif
+	#ifdef USE_SYS_ENDIAN_H
 	#include <sys/endian.h>
+	#endif
+], [
+	be32toh(0);
+], [], [
+	AC_DEFINE(USE_COMPAT_ENDIAN_H,, Define if compat/endian.h is required)
+	AC_MSG_RESULT([using compat/endian.h])
+])
+
+AC_TRY_LINK([
+	#ifdef USE_ENDIAN_H
+	#include <endian.h>
+	#endif
+	#ifdef USE_SYS_ENDIAN_H
+	#include <sys/endian.h>
+	#endif
+	#ifdef USE_COMPAT_ENDIAN_H
+	#include <compat/endian.h>
+	#endif
 	#include <stdlib.h>
 ], [
-	be32enc(NULL, 1);
-], [
-AC_DEFINE(HAVE_BE32ENC,, Define if be32enc is present)
+	be32enc(NULL, 0);
+], [], [
+	AC_DEFINE(USE_COMPAT_ENDIAN_ENC_H,, Define if compat/endian_enc.h is required)
+	AC_MSG_RESULT([using compat/endian_enc.h])
 ])
 
 # Check to see if Mach IPC is used for trigger messages.  If so, use Mach IPC

==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#70 (text+ko) ====

@@ -32,26 +32,26 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#69 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#70 $
  */
 
 #include <sys/types.h>
 
 #include <config/config.h>
-#if defined(HAVE_SYS_ENDIAN_H) && defined(HAVE_BE32ENC)
+
+#ifdef USE_ENDIAN_H
+#include <endian.h>
+#endif
+#ifdef USE_SYS_ENDIAN_H
 #include <sys/endian.h>
-#else /* !HAVE_SYS_ENDIAN_H || !HAVE_BE32ENC */
-#ifdef HAVE_MACHINE_ENDIAN_H
-#include <machine/endian.h>
-#else /* !HAVE_MACHINE_ENDIAN_H */
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#else /* !HAVE_ENDIAN_H */
-#error "No supported endian.h"
-#endif /* !HAVE_ENDIAN_H */
-#endif /* !HAVE_MACHINE_ENDIAN_H */
+#endif
+#ifdef USE_COMPAT_ENDIAN_H
 #include <compat/endian.h>
-#endif /* !HAVE_SYS_ENDIAN_H || !HAVE_BE32ENC */
+#endif
+#ifdef USE_COMPAT_ENDIAN_ENC_H
+#include <compat/endian_enc.h>
+#endif
+
 #ifdef HAVE_FULL_QUEUE_H
 #include <sys/queue.h>
 #else /* !HAVE_FULL_QUEUE_H */

==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#98 (text+ko) ====

@@ -30,26 +30,26 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#97 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#98 $
  */
 
 #include <sys/types.h>
 
 #include <config/config.h>
-#if defined(HAVE_SYS_ENDIAN_H) && defined(HAVE_BE32ENC)
+
+#ifdef USE_ENDIAN_H
+#include <endian.h>
+#endif
+#ifdef USE_SYS_ENDIAN_H
 #include <sys/endian.h>
-#else /* !HAVE_SYS_ENDIAN_H || !HAVE_BE32ENC */
-#ifdef HAVE_MACHINE_ENDIAN_H
-#include <machine/endian.h>
-#else /* !HAVE_MACHINE_ENDIAN_H */
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#else /* !HAVE_ENDIAN_H */
-#error "No supported endian.h"
-#endif /* !HAVE_ENDIAN_H */
-#endif /* !HAVE_MACHINE_ENDIAN_H */
+#endif
+#ifdef USE_COMPAT_ENDIAN_H
 #include <compat/endian.h>
-#endif /* !HAVE_SYS_ENDIAN_H || !HAVE_BE32ENC */
+#endif
+#ifdef USE_COMPAT_ENDIAN_ENC_H
+#include <compat/endian_enc.h>
+#endif
+
 #ifdef HAVE_FULL_QUEUE_H
 #include <sys/queue.h>
 #else /* !HAVE_FULL_QUEUE_H */


More information about the p4-projects mailing list