Re: The driver vboxdrv.ko, in the port virtualbox-ose-kmod, is not loadable in FreeBSD 13.3-RELEASE.

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Mon, 18 Mar 2024 06:30:29 UTC

> On Mar 15, 2024, at 11:04 PM, Felix Palmen <zirias@FreeBSD.org> wrote:
> 
> * Zhenlei Huang <zlei@FreeBSD.org> [20240315 22:57]:
>> Message from virtualbox-ose-kmod-6.1.50:
>> 
>> --
>> The vboxdrv kernel module uses internal kernel APIs.
>> 
>> To avoid crashes due to kernel incompatibility, this module will only
>> load on FreeBSD 13.2 kernels.
>> ```
> 
> This message is generated, see
> https://cgit.freebsd.org/ports/tree/emulators/virtualbox-ose-kmod/files/pkg-message.in
> 
> So, in a nutshell, it will only load on the kernel it was built for.
> 
> Therefore, for some reason OP just didn't successfully build/install it
> locally.

I think you are right.

The error message
> KLD vboxdrv.ko: depends on kernel - not available or version mismatch
actually hints that the dependency 'kernel' of the module vboxdrv.ko is not satisfied,
from bc6d5725ed6c (emulators/virtualbox-ose-kmod*: Tie to a specific release branch) and
kernel source `sys/kern/kern_linker.c`:
```
error = linker_load_module(NULL, modname, lf, verinfo, NULL);
if (error) {
        printf("KLD %s: depends on %s - not available or"
            " version mismatch\n", lf->filename, modname);
        break;
}
```

The definition of DECLARE_MODULE_WITH_MAXVER is:
```
#define DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, maxver)      \
        MODULE_DEPEND(name, kernel, __FreeBSD_version,                  \
            __FreeBSD_version, maxver);                                 \
        MODULE_METADATA(_md_##name, MDT_MODULE, &data, __XSTRING(name));\
        SYSINIT(name##module, sub, order, module_register_init, &data); \
        struct __hack
```
, then the kernel `version mismatch` means the `__FreeBSD_version` is not 13.3 (or SA / EN).

So if the vitualbox ose kernel module *IS* built from source then it is almost definitely linked
against wrong `__FreeBSD_version` (either /usr/include/osreldate.h is outdated or the module
is linked against wrong header file).

> 
> --
> Felix Palmen <zirias@FreeBSD.org>     {private}   felix@palmen-it.de
> -- ports committer --                     {web}  http://palmen-it.de
> {pgp public key}  http://palmen-it.de/pub.txt
> {pgp fingerprint} 6936 13D5 5BBF 4837 B212  3ACC 54AD E006 9879 F231