From owner-freebsd-current@FreeBSD.ORG Wed Jan 24 11:12: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 9AB0716A405 for ; Wed, 24 Jan 2007 11:12:17 +0000 (UTC) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (xorpc.icir.org [192.150.187.68]) by mx1.freebsd.org (Postfix) with ESMTP id 89B9A13C4C5 for ; Wed, 24 Jan 2007 11:12:17 +0000 (UTC) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (localhost [127.0.0.1]) by xorpc.icir.org (8.12.11/8.13.6) with ESMTP id l0OBCGeO054949; Wed, 24 Jan 2007 03:12:16 -0800 (PST) (envelope-from rizzo@xorpc.icir.org) Received: (from rizzo@localhost) by xorpc.icir.org (8.12.11/8.12.3/Submit) id l0OBCGfM054948; Wed, 24 Jan 2007 03:12:16 -0800 (PST) (envelope-from rizzo) Date: Wed, 24 Jan 2007 03:12:16 -0800 From: Luigi Rizzo To: current@freebsd.org Message-ID: <20070124031216.A54472@xorpc.icir.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i Cc: Subject: 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 11:12: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 ? cheers luigi