Add the infrastructure and expected sizeof() values for each supported

architecture to implement size-guards on the vimage vnet_* structures.

As CTASSERT_EQUAL() needs special compile time options we back it
by CTASSERT() in the default case. Unfortunately CTASSERT() triggers
first, thus add an option to allow compilation with CTASSERT_EQUAL() only.

See the comments how to get new values if you trigger the assert
and what to do in that case.

Reviewed by:	rwatson, zec (earlier versions)
This commit is contained in:
Bjoern A. Zeeb 2009-03-01 09:51:50 +00:00
parent c4d4bcdaf6
commit 3cf840d540

View File

@ -112,6 +112,79 @@ struct vnet_modlink {
int vi_symlookup(struct kld_sym_lookup *, char *);
void vnet_mod_register(const struct vnet_modinfo *);
/*
* Size-guards for the vimage structures.
* If you need to update the values you MUST increment __FreeBSD_version.
* See description further down to see how to get the new values.
*/
#ifdef __amd64__
#define SIZEOF_vnet_net 464
#define SIZEOF_vnet_net_LINT 5144
#define SIZEOF_vnet_inet 4160
#define SIZEOF_vnet_inet6 8800
#define SIZEOF_vnet_ipsec 31160
#endif
#ifdef __arm__
#define SIZEOF_vnet_net 236
#define SIZEOF_vnet_net_LINT 1 /* No LINT kernel yet. */
#define SIZEOF_vnet_inet 2396
#define SIZEOF_vnet_inet6 8536
#define SIZEOF_vnet_ipsec 1
#endif
#ifdef __i386__ /* incl. pc98 */
#define SIZEOF_vnet_net 236
#define SIZEOF_vnet_net_LINT 2576
#define SIZEOF_vnet_inet 2396
#define SIZEOF_vnet_inet6 8528
#define SIZEOF_vnet_ipsec 31016
#endif
#ifdef __ia64__
#define SIZEOF_vnet_net 464
#define SIZEOF_vnet_net_LINT 5144
#define SIZEOF_vnet_inet 4160
#define SIZEOF_vnet_inet6 8800
#define SIZEOF_vnet_ipsec 31160
#endif
#ifdef __mips__
#define SIZEOF_vnet_net 236
#define SIZEOF_vnet_net_LINT 1 /* No LINT kernel yet. */
#define SIZEOF_vnet_inet 2432
#define SIZEOF_vnet_inet6 8552
#define SIZEOF_vnet_ipsec 1
#endif
#ifdef __powerpc__
#define SIZEOF_vnet_net 236
#define SIZEOF_vnet_net_LINT 2576
#define SIZEOF_vnet_inet 2432
#define SIZEOF_vnet_inet6 8536
#define SIZEOF_vnet_ipsec 31048
#endif
#ifdef __sparc64__ /* incl. sun4v */
#define SIZEOF_vnet_net 464
#define SIZEOF_vnet_net_LINT 5144
#define SIZEOF_vnet_inet 4160
#define SIZEOF_vnet_inet6 8800
#define SIZEOF_vnet_ipsec 31160
#endif
#ifdef COMPILING_LINT
#undef SIZEOF_vnet_net
#define SIZEOF_vnet_net SIZEOF_vnet_net_LINT
#endif
#ifndef SIZEOF_vnet_net
#error "SIZEOF_vnet_net no defined for this architecture."
#endif
#ifndef SIZEOF_vnet_inet
#error "SIZEOF_vnet_inet no defined for this architecture."
#endif
#ifndef SIZEOF_vnet_inet6
#error "SIZEOF_vnet_inet6 no defined for this architecture."
#endif
#ifndef SIZEOF_vnet_ipsec
#error "SIZEOF_vnet_ipsec no defined for this architecture."
#endif
/*
* x must be a positive integer constant (expected value),
* y must be compile-time evaluated to a positive integer,
@ -136,4 +209,30 @@ void vnet_mod_register(const struct vnet_modinfo *);
} \
struct __hack
/*
* x shall be the expected value (SIZEOF_vnet_* from above)
* and y shall be the real size (sizeof(struct vnet_*)).
* If you run into the CTASSERT() you want to compile a universe
* with COPTFLAGS+="-O -Wuninitialized -DVIMAGE_CHECK_SIZES".
* This should give you the errors for the proper values defined above.
* Make sure to re-run universe with the proper values afterwards -
* -DMAKE_JUST_KERNELS should be enough.
*
* Note:
* CTASSERT() takes precedence in the current FreeBSD world thus the
* CTASSERT_EQUAL() will not neccessarily trigger if one uses both.
* But as CTASSERT_EQUAL() needs special compile time options, we
* want the default case to be backed by CTASSERT().
*/
#ifndef VIMAGE_CTASSERT
#ifdef VIMAGE_CHECK_SIZES
#define VIMAGE_CTASSERT(x, y) \
CTASSERT_EQUAL(x, y)
#else
#define VIMAGE_CTASSERT(x, y) \
CTASSERT_EQUAL(x, y); \
CTASSERT(x == 0 || x == y)
#endif
#endif
#endif /* !_SYS_VIMAGE_H_ */