Re: visibility of symbols defined in a kld module ?

From: Danny Braniss <danny_at_cs.huji.ac.il>
Date: Wed, 24 Jan 2007 15:06:24 +0200
> 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
Received on Wed Jan 24 2007 - 12:36:17 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:05 UTC