Date: Wed, 27 Oct 2010 15:12:19 +0400 From: Sergey Kandaurov <pluknet@gmail.com> To: freebsd-hackers@freebsd.org Cc: Selphie Keller <selphie.keller@gmail.com>, Andriy Gapon <avg@icyb.net.ua> Subject: Re: SYSCALL_MODULE() macro and modfind() issues Message-ID: <AANLkTi=%2B1SP2Qi3DNH7MoZuAO_xD6jNUV5M94zbzB8xy@mail.gmail.com> In-Reply-To: <201010260934.57247.jhb@freebsd.org> References: <AANLkTimVUzV3v9=y%2BWuuf%2B1fC4OYxD2Gs4j%2B=SO-M%2BP9@mail.gmail.com> <4CC6830A.10701@icyb.net.ua> <AANLkTikRqHOJ8voweZhDEfNsRAR_pEoXspLQYrVtGsRH@mail.gmail.com> <201010260934.57247.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 26 October 2010 17:34, John Baldwin <jhb@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##
>> =A0}; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \
>> =A0static moduledata_t name##_mod =3D { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 \
>> - =A0 =A0 =A0 #name, =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\
>> + =A0 =A0 =A0 "sys/" #name, =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \
>> =A0 =A0 =A0 =A0 syscall_module_handler, =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \
>> =A0 =A0 =A0 =A0 &name##_syscall_mod =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \
>> =A0}; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \
>>
>> 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 =A0 =A0 =A02010-10-26
>> 00:56:10.000000000 -0700
>> @@ -86,12 +86,12 @@ main(int argc, char **argv)
>> =A0 =A0 =A0struct kinfo_proc *kp;
>> =A0 =A0 =A0int =A0 =A0 =A0 =A0pmap_helper_syscall;
>>
>> - =A0 =A0if ((modid =3D modfind("pmap_helper")) =3D=3D -1) {
>> + =A0 =A0if ((modid =3D modfind("sys/pmap_helper")) =3D=3D -1) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* module not found, try to load */
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 modid =3D kldload("pmap_helper.ko");
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (modid =3D=3D -1)
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err(1, "unable to load p=
map_helper module");
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 modid =3D modfind("pmap_helper");
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 modid =3D modfind("sys/pmap_helper");
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (modid =3D=3D -1)
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err(1, "pmap_helper modu=
le loaded but not found");
>> =A0 =A0 =A0 =A0 }
>>
>> which restored functionality on freebsd 8.1.
>
> The best approach might be to have something like this:
>
> static int
> pmap_find(void)
> {
> =A0 =A0 =A0 =A0int modid;
>
> =A0 =A0 =A0 =A0modid =3D modfind("pmap_helper");
> =A0 =A0 =A0 =A0if (modid =3D=3D -1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0modid =3D modfind("sys/pmap_helper");
> =A0 =A0 =A0 =A0return (modid);
> }
>
> then in the original main() routine use this:
>
> =A0 =A0 =A0 =A0if ((modid =3D pmap_find()) =3D=3D -1) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* module not found, try to load */
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0modid =A0=3D kldload("pmap_helper.ko");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (modid =3D=3D -1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err(1, "unable to load pma=
p_helper module");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0modid =3D pmap_find();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (modid =3D=3D -1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err(1, "pmap_helper module=
loaded but not found");
> =A0 =A0 =A0 =A0}
>
> 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 >=3D 800505) /* See r206346 in stable/8. */
strcpy(modname, "sys/foo");
else
strcpy(modname, "foo");
--=20
wbr,
pluknet
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTi=%2B1SP2Qi3DNH7MoZuAO_xD6jNUV5M94zbzB8xy>
