What is EXPORT_SYMBOL_GPL in Linux kernel code?

坚强是说给别人听的谎言 提交于 2019-12-30 01:53:29

问题


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...


回答1:


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.



来源:https://stackoverflow.com/questions/22712114/what-is-export-symbol-gpl-in-linux-kernel-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!