RFC: Using fixed-length strings for version[] and osrelease[]
Colin Percival
cperciva at freebsd.org
Fri May 20 14:18:15 PDT 2005
John-Mark Gurney wrote:
> Colin Percival wrote this message on Thu, May 19, 2005 at 16:52 -0700:
>>The lengths 512 and 64 are chosen as being considerably more than double the
>>likely lengths of these strings; on my system, these two strings are 12 bytes
>>and 134 bytes long respectively.
>
> Nope, but I would say make them just a bit larger than necessary right
> now, and add the necessary CTASSERT lines to make sure we don't overflow..
>
> I'd say no more than 256 bytes for the VERSION string, since CTASSERT will
> prevent the overflow...
>
> Though you might want to make the fixed size dependent upon the release
> kernel and not for custom compiled kernels... No point in penalizing
> kernels that don't need this...
I don't think there's much point worrying about saving a few hundred bytes,
but I've put together a patch which allows the strings to be lengthened if
necessary. The lengths are now 256 bytes and 32 bytes.
I've also added a BRANCH_OVERRIDE variable which can bs set in the
environment; this is probably not going to be useful to many people, but
it will allow me to identify the osrelease[] string and avoid distributing
a new kernel when the patch number is bumped due to a userland-only fix.
Any objections to the following patch?
@@ -33,6 +33,9 @@
TYPE="FreeBSD"
REVISION="6.0"
BRANCH="CURRENT"
+if [ "X${BRANCH_OVERRIDE}" != "X" ]; then
+ BRANCH=${BRANCH_OVERRIDE}
+fi
RELEASE="${REVISION}-${BRANCH}"
VERSION="${TYPE} ${RELEASE}"
@@ -85,11 +88,14 @@ v=`cat version` u=${USER:-root} d=`pwd`
i=`${MAKE:-make} -V KERN_IDENT`
cat << EOF > vers.c
$COPYRIGHT
+#define VERSTR "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n"
+#define RELSTR "${RELEASE}"
+
char sccspad[32 - 4 /* sizeof(sccs) */] = { '\\0' };
char sccs[4] = { '@', '(', '#', ')' };
-char version[] = "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n";
+char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR;
char ostype[] = "${TYPE}";
-char osrelease[] = "${RELEASE}";
+char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR;
int osreldate = ${RELDATE};
char kern_ident[] = "${i}";
EOF
Colin Percival
More information about the freebsd-arch
mailing list