Fail the module loading process if the currently executing kernel

was not compiled with 'options HWPMC_HOOKS' or if the compiled-in
version numbers of the kernel and module are out of sync.

Reported by:	cracauer
MFC after:	3 days
This commit is contained in:
Joseph Koshy 2005-07-30 09:02:42 +00:00
parent 77d2ce5d21
commit fadcc6e201
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=148562
3 changed files with 29 additions and 7 deletions

View File

@ -3917,6 +3917,18 @@ pmc_initialize(void)
PMCDBG(MOD,INI,0, "PMC Initialize (version %x)", PMC_VERSION);
/* check kernel version */
if (pmc_kernel_version != PMC_VERSION) {
if (pmc_kernel_version == 0)
printf("hwpmc: this kernel has not been compiled with "
"'options HWPMC_HOOKS'.\n");
else
printf("hwpmc: kernel version (0x%x) does not match "
"module version (0x%x).\n", pmc_kernel_version,
PMC_VERSION);
return EPROGMISMATCH;
}
/*
* check sysctl parameters
*/

View File

@ -26,10 +26,20 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "opt_hwpmc_hooks.h"
#include <sys/types.h>
#include <sys/pmc.h>
#include <sys/pmckern.h>
#include <sys/smp.h>
struct sx pmc_sx;
#if HWPMC_HOOKS
#define PMC_KERNEL_VERSION PMC_VERSION
#else
#define PMC_KERNEL_VERSION 0
#endif
const int pmc_kernel_version = PMC_KERNEL_VERSION;
/* Hook variable. */
int (*pmc_hook)(struct thread *td, int function, void *arg) = NULL;
@ -37,13 +47,13 @@ int (*pmc_hook)(struct thread *td, int function, void *arg) = NULL;
/* Interrupt handler */
int (*pmc_intr)(int cpu, uintptr_t pc, int usermode) = NULL;
/* Bitmask of CPUs requiring servicing at hardclock time */
volatile cpumask_t pmc_cpumask;
/*
* A global count of SS mode PMCs. When non-zero, this means that
* we have processes that are sampling the system as a whole.
*/
volatile int pmc_ss_count;
/*
@ -55,14 +65,11 @@ volatile int pmc_ss_count;
* shared (sx) lock -- thus making the process of calling into PMC(4)
* somewhat more expensive than a simple 'if' check and indirect call.
*/
struct sx pmc_sx;
SX_SYSINIT(pmc, &pmc_sx, "pmc shared lock");
/*
* pmc_cpu_is_disabled
*
* return TRUE if the cpu specified has been disabled.
* Helper functions
*/
int

View File

@ -62,6 +62,9 @@ extern volatile cpumask_t pmc_cpumask;
/* Count of system-wide sampling PMCs in existence */
extern volatile int pmc_ss_count;
/* kernel version number */
extern const int pmc_kernel_version;
/* Hook invocation; for use within the kernel */
#define PMC_CALL_HOOK(t, cmd, arg) \
do { \