diff options
author | bz <bz@FreeBSD.org> | 2009-03-01 09:51:50 +0000 |
---|---|---|
committer | bz <bz@FreeBSD.org> | 2009-03-01 09:51:50 +0000 |
commit | 09ea36e39bdb3780880351eb02b6ebba2bdedff2 (patch) | |
tree | 5d51795984f63eb908894dd855398ad800126fa1 | |
parent | 45be9ed4334db5c7016a3cfd17a5bbd1bc8026bc (diff) | |
download | FreeBSD-src-09ea36e39bdb3780880351eb02b6ebba2bdedff2.zip FreeBSD-src-09ea36e39bdb3780880351eb02b6ebba2bdedff2.tar.gz |
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)
-rw-r--r-- | sys/sys/vimage.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/sys/sys/vimage.h b/sys/sys/vimage.h index 90cdf2f..fd70bc4 100644 --- a/sys/sys/vimage.h +++ b/sys/sys/vimage.h @@ -113,6 +113,79 @@ 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, * e.g. CTASSERT_EQUAL(FOO_EXPECTED_SIZE, sizeof (struct foo)); @@ -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_ */ |