From 6b1d8ceabee0e9b0776203658ff54d73a0791071 Mon Sep 17 00:00:00 2001 From: Jeroen Ruigrok van der Werven Date: Wed, 8 Nov 2000 16:59:25 +0000 Subject: [PATCH] Fix CMSG and ALIGN macro usage. Previously we had to include or bogusly due to the fact that CMSG macros needed the ALIGN macro, which was defined in param.h. However, including param.h was a disaster for namespace pollution. This solution, as contributed by shin a while ago, fixes it elegantly by wrapping the definitions around some namespace pollution preventer definitions. This patch was long overdue. This should allow any network programmer to use as before. PR: 19971, 20530 Submitted by: Martin Kaeske Mark Andrews Patch submitted by: shin Reviewed by: bde --- sys/alpha/include/param.h | 54 +++++++++++++++++++++++++++------------ sys/i386/include/param.h | 38 +++++++++++++++++---------- sys/sys/socket.h | 20 ++++++++++----- 3 files changed, 76 insertions(+), 36 deletions(-) diff --git a/sys/alpha/include/param.h b/sys/alpha/include/param.h index ae641f65c5ed..7c0f1af3eafa 100644 --- a/sys/alpha/include/param.h +++ b/sys/alpha/include/param.h @@ -46,15 +46,43 @@ /* * Machine dependent constants for the Alpha. */ + +/* + * Round p (pointer or byte index) up to a correctly-aligned value for all + * data types (int, long, ...). The result is u_long and must be cast to + * any desired pointer type. + * + * ALIGNED_POINTER is a boolean macro that checks whether an address + * is valid to fetch data elements of type t from on this architecture. + * This does not reflect the optimal alignment, just the possibility + * (within reasonable limits). + * + */ +#ifndef _ALIGNBYTES +#define _ALIGNBYTES 7 +#endif +#ifndef _ALIGN +#define _ALIGN(p) (((u_long)(p) + _ALIGNBYTES) &~ _ALIGNBYTES) +#endif +#ifndef _ALIGNED_POINTER +#define _ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t)-1)) == 0) +#endif + #ifndef _MACHINE #define _MACHINE alpha #endif -#ifndef MACHINE -#define MACHINE "alpha" -#endif #ifndef _MACHINE_ARCH #define _MACHINE_ARCH alpha #endif + +#ifndef _NO_NAMESPACE_POLLUTION + +#ifndef _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#ifndef MACHINE +#define MACHINE "alpha" +#endif #ifndef MACHINE_ARCH #define MACHINE_ARCH "alpha" #endif @@ -76,20 +104,9 @@ #define MAXCPU 1 #endif -/* - * Round p (pointer or byte index) up to a correctly-aligned value for all - * data types (int, long, ...). The result is u_long and must be cast to - * any desired pointer type. - * - * ALIGNED_POINTER is a boolean macro that checks whether an address - * is valid to fetch data elements of type t from on this architecture. - * This does not reflect the optimal alignment, just the possibility - * (within reasonable limits). - * - */ -#define ALIGNBYTES 7 -#define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES) -#define ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t)-1)) == 0) +#define ALIGNBYTES _ALIGNBYTES +#define ALIGN(p) _ALIGN(p) +#define ALIGNED_POINTER(p,t) _ALIGNED_POINTER(p,t) #define PAGE_SIZE (1 << ALPHA_PGSHIFT) /* bytes/page */ #define PAGE_SHIFT ALPHA_PGSHIFT @@ -157,3 +174,6 @@ #define alpha_ptob(x) ((unsigned long)(x) << PAGE_SHIFT) #define pgtok(x) ((x) * (PAGE_SIZE / 1024)) + +#endif /* !_MACHINE_PARAM_H_ */ +#endif /* !_NO_NAMESPACE_POLLUTION */ diff --git a/sys/i386/include/param.h b/sys/i386/include/param.h index 0d1729733876..dffc6485be4f 100644 --- a/sys/i386/include/param.h +++ b/sys/i386/include/param.h @@ -37,21 +37,37 @@ * $FreeBSD$ */ -#ifndef _MACHINE_PARAM_H_ -#define _MACHINE_PARAM_H_ - /* * Machine dependent constants for Intel 386. */ + +/* + * Round p (pointer or byte index) up to a correctly-aligned value + * for all data types (int, long, ...). The result is unsigned int + * and must be cast to any desired pointer type. + */ +#ifndef _ALIGNBYTES +#define _ALIGNBYTES (sizeof(int) - 1) +#endif +#ifndef _ALIGN +#define _ALIGN(p) (((unsigned)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) +#endif + #ifndef _MACHINE #define _MACHINE i386 #endif -#ifndef MACHINE -#define MACHINE "i386" -#endif #ifndef _MACHINE_ARCH #define _MACHINE_ARCH i386 #endif + +#ifndef _NO_NAMESPACE_POLLUTION + +#ifndef _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#ifndef MACHINE +#define MACHINE "i386" +#endif #ifndef MACHINE_ARCH #define MACHINE_ARCH "i386" #endif @@ -70,13 +86,8 @@ #define MAXCPU 1 #endif /* SMP */ -/* - * Round p (pointer or byte index) up to a correctly-aligned value - * for all data types (int, long, ...). The result is unsigned int - * and must be cast to any desired pointer type. - */ -#define ALIGNBYTES (sizeof(int) - 1) -#define ALIGN(p) (((unsigned)(p) + ALIGNBYTES) & ~ALIGNBYTES) +#define ALIGNBYTES _ALIGNBYTES +#define ALIGN(p) _ALIGN(p) #define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ #define PAGE_SIZE (1< +#else +#define _NO_NAMESPACE_POLLUTION +#include +#undef _NO_NAMESPACE_POLLUTION +#endif + /* * Definitions related to sockets: types, address families, options. */ @@ -358,22 +366,22 @@ struct cmsgcred { /* given pointer to struct cmsghdr, return pointer to data */ #define CMSG_DATA(cmsg) ((u_char *)(cmsg) + \ - ALIGN(sizeof(struct cmsghdr))) + _ALIGN(sizeof(struct cmsghdr))) /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ #define CMSG_NXTHDR(mhdr, cmsg) \ - (((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len) + \ - ALIGN(sizeof(struct cmsghdr)) > \ + (((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \ + _ALIGN(sizeof(struct cmsghdr)) > \ (caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \ (struct cmsghdr *)NULL : \ - (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len))) + (struct cmsghdr *)((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len))) #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) /* RFC 2292 additions */ -#define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l)) -#define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l)) +#define CMSG_SPACE(l) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l)) +#define CMSG_LEN(l) (_ALIGN(sizeof(struct cmsghdr)) + (l)) /* "Socket"-level control message types: */ #define SCM_RIGHTS 0x01 /* access rights (array of int) */