Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is EXPORT_SYMBOL_GPL in Linux kernel code?

Tags:

What is EXPORT_SYMBOL_GPL in Linux kernel code?

Below is a piece of code, which contains EXPORT_SYMBOL_GPL

62 struct resource *platform_get_resource(struct platform_device *dev,
 63                                        unsigned int type, unsigned int num)
 64 {
 65         int i;
 66 
 67         for (i = 0; i < dev->num_resources; i++) {
 68                 struct resource *r = &dev->resource[i];
 69 
 70                 if (type == resource_type(r) && num-- == 0)
 71                         return r;
 72         }
 73         return NULL;
 74 }
 75 EXPORT_SYMBOL_GPL(platform_get_resource);

That macro appears many a times in kernel code...

like image 353
Sagar Jain Avatar asked Mar 28 '14 11:03

Sagar Jain


1 Answers

It is macro to define some symbol (e.g. function) as exportable (seen from kernel loadable modules). If the symbol has no "EXPORT_SYMBOL", it will be not accessible from modules.

EXPORT_SYMBOL_GPL will show the symbol only in GPL-licensed modules, and EXPORT_SYMBOL - in modules with any license.

http://lwn.net/Articles/154602/ - On the value of EXPORT_SYMBOL_GPL (2005, corbet)

When a loadable module is inserted, any references it makes to kernel functions and data structures must be linked to the current running kernel. The module loader does not provide access to all kernel symbols, however; only those which have been explicitly exported are available.

Exports come in two flavors: vanilla (EXPORT_SYMBOL) and GPL-only (EXPORT_SYMBOL_GPL). The former are available to any kernel module, while the latter cannot be used by any modules which do not carry a GPL-compatible license.

like image 136
osgx Avatar answered Oct 08 '22 19:10

osgx