From owner-freebsd-hackers@FreeBSD.ORG Thu May 6 09:40:07 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EBAA116A4CE for ; Thu, 6 May 2004 09:40:07 -0700 (PDT) Received: from mail4.speakeasy.net (mail4.speakeasy.net [216.254.0.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id AF61143D53 for ; Thu, 6 May 2004 09:40:07 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: (qmail 1023 invoked from network); 6 May 2004 16:40:07 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) encrypted SMTP for ; 6 May 2004 16:40:07 -0000 Received: from 10.50.40.205 (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.12.11/8.12.11) with ESMTP id i46Ge3Ct005446; Thu, 6 May 2004 12:40:03 -0400 (EDT) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: freebsd-hackers@FreeBSD.org Date: Thu, 6 May 2004 11:09:48 -0400 User-Agent: KMail/1.6 References: <20040506075725.GA1056@fbsd.lv> In-Reply-To: <20040506075725.GA1056@fbsd.lv> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <200405061109.48244.jhb@FreeBSD.org> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: Artis Caune Subject: Re: ioctl X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2004 16:40:08 -0000 On Thursday 06 May 2004 03:57 am, Artis Caune wrote: > Is it correct to use code like this > instead of copyin() / copyout() ? > Kernel module gets pointer to structure > which resides in userland memory space > and modify it directly!!! No, that's probably bogus. > > userland: ioctl(tp_fd, TP_GET_TP_STATS, &tp_stats) > > kernel: tp_stats->hooked = hooked; > > (freebsd 5.x, KLD) > > > ----- START userland ----- > > #define TP_GET_TP_STATS _IOR('D', 200, struct tp_stats_s) > > struct tp_stats_s { > int hooked; > u_short policer_active_pipes; > } tp_stats; > > if (ioctl(tp_fd, TP_GET_TP_STATS, &tp_stats) != -1) { > > printf("Traffic Policer is %s\n", > tp_stats.hooked ? "enabled" : "disabled"); > printf("statistics:\n"); > printf(" %-30s%u\n", "pipes hash table depth", > tp_stats.policer_pipes_hash_depth); > printf(" %-30s%u\n", "active pipes", > tp_stats.policer_active_pipes); > } else > fprintf(stderr, "IOCTL error\n"); > > ----- END userland ----- > > > > ----- START kernel ----- > > static int > tp_dev_ioctl (dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread > *td) { > switch (cmd) { > case TP_GET_TP_STATS: > err = get_tp_stats((struct tp_stats_s *)addr); > break; > ... > } > > static int > get_tp_stats (struct tp_stats_s *tp_stats) > { > TP_LOCK; > tp_stats->hooked = hooked; > /* hash depth will be gone in -release, just for debug */ > tp_stats->policer_pipes_hash_depth = policer_pipes_hash_depth; > tp_stats->policer_active_pipes = policer_get_active_pipes(); > TP_UNLOCK; > > return (0); > } > ... > ----- END kernel ----- > > > > thanks, -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org