SYSCALL_MODULE() macro and modfind() issues

Sergey Kandaurov pluknet at gmail.com
Wed Oct 27 11:12:20 UTC 2010


On 26 October 2010 17:34, John Baldwin <jhb at freebsd.org> wrote:
> On Tuesday, October 26, 2010 4:00:14 am Selphie Keller wrote:
>> Thanks Andriy,
>>
>> Took a look at the change to src/sys/sys/sysent.h
>>
>> @@ -149,7 +149,7 @@ static struct syscall_module_data name##
>>  };                                                             \
>>                                                                 \
>>  static moduledata_t name##_mod = {                             \
>> -       #name,                                                  \
>> +       "sys/" #name,                                           \
>>         syscall_module_handler,                                 \
>>         &name##_syscall_mod                                     \
>>  };                                                             \
>>
>> applied the MFC prefix to pmap port:
>>
>> --- /usr/ports/sysutils/pmap/work/pmap/pmap/pmap.c.orig 2010-10-26
>> 00:55:32.000000000 -0700
>> +++ /usr/ports/sysutils/pmap/work/pmap/pmap/pmap.c      2010-10-26
>> 00:56:10.000000000 -0700
>> @@ -86,12 +86,12 @@ main(int argc, char **argv)
>>      struct kinfo_proc *kp;
>>      int        pmap_helper_syscall;
>>
>> -    if ((modid = modfind("pmap_helper")) == -1) {
>> +    if ((modid = modfind("sys/pmap_helper")) == -1) {
>>                 /* module not found, try to load */
>>                 modid = kldload("pmap_helper.ko");
>>                 if (modid == -1)
>>                         err(1, "unable to load pmap_helper module");
>> -               modid = modfind("pmap_helper");
>> +               modid = modfind("sys/pmap_helper");
>>                 if (modid == -1)
>>                         err(1, "pmap_helper module loaded but not found");
>>         }
>>
>> which restored functionality on freebsd 8.1.
>
> The best approach might be to have something like this:
>
> static int
> pmap_find(void)
> {
>        int modid;
>
>        modid = modfind("pmap_helper");
>        if (modid == -1)
>                modid = modfind("sys/pmap_helper");
>        return (modid);
> }
>
> then in the original main() routine use this:
>
>        if ((modid = pmap_find()) == -1) {
>                /* module not found, try to load */
>                modid  = kldload("pmap_helper.ko");
>                if (modid == -1)
>                        err(1, "unable to load pmap_helper module");
>                modid = pmap_find();
>                if (modid == -1)
>                        err(1, "pmap_helper module loaded but not found");
>        }
>
> This would make the code work for both old and new versions.


Just another foo of many which I use at work generally.
It lacks compat32 syscalls handling though (we don't use them).

        /*
         * We have to extract __FreeBSD_version from live kernel
         * as we depend on kernel feature and can run on an older world.
         */
        if (sysctlbyname("kern.osreldate", &osreldate, &intlen, NULL, 0) < 0)
                err(-2, "sysctl(kern.osreldate)");
        if (osreldate >= 800505)        /* See r206346 in stable/8. */
                strcpy(modname, "sys/foo");
        else
                strcpy(modname, "foo");

-- 
wbr,
pluknet


More information about the freebsd-hackers mailing list