--- /usr/src/sys/sys/cdefs.h Wed Dec 5 12:00:35 2007 +++ sys/sys/cdefs.h Thu Dec 20 01:16:27 2007 @@ -403,7 +403,11 @@ */ #ifndef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) +#define __FBSDID(s) \ + __asm__(".section set_srcid,\"a\",@progbits"); \ + __asm__(".p2align 0"); \ + __asm__(".asciz " #s ); \ + __asm__(".previous") #else #define __FBSDID(s) struct __hack #endif --- /usr/src/sys/kern/kern_mib.c Wed Dec 5 12:00:30 2007 +++ sys/kern/kern_mib.c Thu Dec 20 01:30:27 2007 @@ -38,6 +38,7 @@ #include __FBSDID("$FreeBSD: src/sys/kern/kern_mib.c,v 1.85 2007/12/04 12:28:07 kib Exp $"); +#include "opt_ddb.h" #include "opt_posix.h" #include "opt_config.h" @@ -307,6 +308,99 @@ SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl, "I", "Current secure level"); + +/* + * We're going to use __start* and __end magic symbols brought to us by + * gcc(1). + */ +SET_DECLARE(srcid_strs, const char); + +/* + * Based on __FBSDID format, skip common parts that bring no valueable + * information in this context. + */ +static void __unused +srcid_fname(char *id, char **ret, int *retlen) +{ + char *p = NULL; + int l = 0; + + KASSERT(id != NULL, ("id == NULL")); + KASSERT(ret != NULL, ("p == NULL")); + KASSERT(retlen != NULL, ("len == NULL")); + + p = strstr(id, "$FreeBSD: "); + if (p != NULL) + id += strlen("$FreeBSD: "); + l = strlen(id); + p = strstr(id, " Exp $"); + if (p != NULL) + l = p - id; + *ret = id; + *retlen = l; +} + +/* + * Magic generated by the gcc(1) to mark the section ranges with special + * variable names. + */ +extern char __start_set_srcid[]; +extern char __stop_set_srcid[]; + +#define FBSDID_BEGIN (&__start_set_srcid[0]) +#define FBSDID_END (&__stop_set_srcid[0]) + +/* + * Return all __FBSDID tags. The output is huge. + */ +static int +sysctl_kern_srcids(SYSCTL_HANDLER_ARGS) +{ + char *bid = FBSDID_BEGIN; + char *eid = FBSDID_END; + char *s; + int idlen; + char *id; + int error = 0; + + for (s = bid; s < eid; s++) { + srcid_fname(s, &id, &idlen); + error = sysctl_handle_opaque(oidp, "\n", 1, req); + if (error) + break; + error = sysctl_handle_opaque(oidp, id, idlen, req); + if (error) + break; + s += strlen(s); + } + error = sysctl_handle_opaque(oidp, "\0", 1, req); + if (error) + return (error); + return (error); +} +SYSCTL_PROC(_kern, OID_AUTO, srcids, CTLTYPE_STRING|CTLFLAG_RD, 0, 0, + sysctl_kern_srcids, "A", "Revision control tags for kernel sources"); + +#ifdef DDB +#include + +DB_SHOW_COMMAND(srcids, db_srcid_list) +{ + char *bid = FBSDID_BEGIN; + char *eid = FBSDID_END; + char *s; + int slen; + int idlen; + char *id; + + for (s = bid; s < eid; s++) { + srcid_fname(s, &id, &idlen); + db_printf("%.*s\n", idlen, id); + slen = strlen(s); + s += slen; + } +} +#endif #ifdef INCLUDE_CONFIG_FILE /* Actual kernel configuration options. */