From owner-freebsd-current@FreeBSD.ORG Wed Jan 24 13:36:17 2007 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8BCB016A401 for ; Wed, 24 Jan 2007 13:36:17 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from cs1.cs.huji.ac.il (cs1.cs.huji.ac.il [132.65.16.10]) by mx1.freebsd.org (Postfix) with ESMTP id 333E813C467 for ; Wed, 24 Jan 2007 13:36:17 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from pampa.cs.huji.ac.il ([132.65.80.32]) by cs1.cs.huji.ac.il with esmtp id 1H9hpY-000NMl-Du; Wed, 24 Jan 2007 15:06:24 +0200 X-Mailer: exmh version 2.7.2 01/07/2005 with nmh-1.2 To: Luigi Rizzo In-reply-to: <20070124031216.A54472@xorpc.icir.org> References: <20070124031216.A54472@xorpc.icir.org> Comments: In-reply-to Luigi Rizzo message dated "Wed, 24 Jan 2007 03:12:16 -0800." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 24 Jan 2007 15:06:24 +0200 From: Danny Braniss Message-ID: Cc: current@freebsd.org Subject: Re: visibility of symbols defined in a kld module ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jan 2007 13:36:17 -0000 > I have the following problem while building a compat layer for compiling > linux drivers on FreeBSD: > a piece of code (let's restrict to a kld if it makes things simpler) > needs to register some information to the system calling a function: > > usb_register(&some_data) > > where some_data is a structure containing various info (callbacks etc) > for the code. > The problem is, i need to hook the argument of usb_register() to the kld. > > If i write > > /* in linux_module_header.h */ > extern void *my_module_info; > > #define usb_register(p) my_module_info = p > > /* in linux_driver_stub.c, linked together with the rest of the code */ > > #include "linux_module_header.h" > void *my_module_info; > > I get what i want, but then my_module_info is present in all modules > compiled with the same trick, so what happens when the modules are > kldloaded ? Does this symbol conflict (i.e. is this equivalent to RTLD_GLOBAL) > or each one sees its own symbols (i.e. like RTLD_LOCAL) ? > > And besides, this would almost surely fail if i compile these things > not as modules but as part of the kernel. > > The other trick i can think of is using some preprocessor-magic to > create unique names for the symbol, e.g. compile each kld with > -DDRIVER_NAME=pwc, -DDRIVER_NAME=gspca, -DDRIVER_NAME=dvb and then have > > /* in linux_module_header.h */ > #define MODINFO_NAME module_ ## DRIVER_NAME ## _info > > extern void *MODINFO_NAME; > > #define usb_register(p) MODINFO_NAME = p > > /* in linux_driver_stub.c, linked together with the rest of the code */ > > #include "linux_module_header.h" > void *MODINFO_NAME; > > This way each module has a different symbol and there are no conflict. > Other ideas ? /* in linux_module_header.h */ #define LINUX_MODULE(name) \ static __inline usb_register(p)\ {\ extern void *module_##name##_info;\ module_##name##_info = p;\ } #define LINUX_MODULE_DCL(name)\ LINUX_MODULE(name)\ void *module_##name##_info /* in linux_driver_stub.c */ #include "linux_module_header.h" LINUX_MODULE_DCL(pwc); /* and in the rest of the code */ #include "linux_module_header.h" LINUX_MODULE(pwc); cheers, danny