From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 27 11:12:20 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E4E4106564A; Wed, 27 Oct 2010 11:12:20 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-qy0-f175.google.com (mail-qy0-f175.google.com [209.85.216.175]) by mx1.freebsd.org (Postfix) with ESMTP id 15F888FC0A; Wed, 27 Oct 2010 11:12:19 +0000 (UTC) Received: by qyk7 with SMTP id 7so3490064qyk.13 for ; Wed, 27 Oct 2010 04:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=RFyAMaQKU0FDKAngtijD/gUZrOuMc1yhVlrpv0ZG2p8=; b=NW+Ua1opi4erMHVC2ZIcy79YFbXENdMDh3P0Pc1b/q9eL4AX4RyWZo5xbqlEo5wIyg LBmXUwxWlWnmBLot2DZL+IL42X0Okm7A4uhjIEwTtHrx945yUs/xXVScspDi/Gg+g/SN p+Tua7eZK5IRIoi0C0PE6bRPYvBw29aSbKSV4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=capePENnATxKL/+hDt2UyhN8tF36hsb4bUZnjrPzYtKXwvqtqVRXfeIjQmf4KTfMtv ZmtJEd7DmVESdBwVv0S41VFbLcV1uWxEfV1Azzn0Ny0XEfn1PQVYAUbHPLklyd0xZitR nutQJw2x05/h+OZoW/mbIdCdoxTApMc+/8IQw= MIME-Version: 1.0 Received: by 10.229.248.79 with SMTP id mf15mr8764613qcb.181.1288177939355; Wed, 27 Oct 2010 04:12:19 -0700 (PDT) Received: by 10.229.69.135 with HTTP; Wed, 27 Oct 2010 04:12:19 -0700 (PDT) In-Reply-To: <201010260934.57247.jhb@freebsd.org> References: <4CC6830A.10701@icyb.net.ua> <201010260934.57247.jhb@freebsd.org> Date: Wed, 27 Oct 2010 15:12:19 +0400 Message-ID: From: Sergey Kandaurov To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Selphie Keller , Andriy Gapon Subject: Re: SYSCALL_MODULE() macro and modfind() issues X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Oct 2010 11:12:20 -0000 On 26 October 2010 17:34, John Baldwin 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