Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jan 2007 15:06:24 +0200
From:      Danny Braniss <danny@cs.huji.ac.il>
To:        Luigi Rizzo <rizzo@icir.org>
Cc:        current@freebsd.org
Subject:   Re: visibility of symbols defined in a kld module ? 
Message-ID:  <E1H9hpY-000NMl-Du@cs1.cs.huji.ac.il>
In-Reply-To: <20070124031216.A54472@xorpc.icir.org> 
References:  <20070124031216.A54472@xorpc.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help
> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1H9hpY-000NMl-Du>