From owner-freebsd-hackers@FreeBSD.ORG Thu May 6 14:35:20 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 96C1316A4CE for ; Thu, 6 May 2004 14:35:20 -0700 (PDT) Received: from duchess.speedfactory.net (duchess.speedfactory.net [66.23.201.84]) by mx1.FreeBSD.org (Postfix) with SMTP id 5BBB343D1D for ; Thu, 6 May 2004 14:35:19 -0700 (PDT) (envelope-from ups@tree.com) Received: (qmail 28671 invoked by uid 89); 6 May 2004 21:25:59 -0000 Received: from duchess.speedfactory.net (66.23.201.84) by duchess.speedfactory.net with SMTP; 6 May 2004 21:25:58 -0000 Received: (qmail 17565 invoked by uid 89); 6 May 2004 21:04:17 -0000 Received: from unknown (HELO tree.com) (66.23.216.50) by duchess.speedfactory.net with SMTP; 6 May 2004 21:04:17 -0000 Received: from tree.com (localhost [127.0.0.1]) by tree.com (8.9.3/8.9.3) with ESMTP id RAA12984; Thu, 6 May 2004 17:03:54 -0400 Message-Id: <200405062103.RAA12984@tree.com> X-Mailer: exmh version 2.0.2 To: Artis Caune In-Reply-To: Message from Artis Caune of "Thu, 06 May 2004 10:57:25 +0300." <20040506075725.GA1056@fbsd.lv> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 06 May 2004 17:03:54 -0400 From: Stephan Uphoff cc: freebsd-hackers@freebsd.org 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 21:35:20 -0000 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!!! The copyout() is just hidden. The ioctl request codes are magic and contain the size of the argument and if the argument should be copied in/out by the kernel ioctl function. ( see ioctl(td, uap) in sys_generic.c ) Stephan > > 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, > > -- > Artis > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" >