简体   繁体   English

为Linux内核中的模块设置许可证

[英]Setting the license for modules in the linux kernel

I've written some kernel modules in Ada, and I've hit a bit of a problem. 我已经用Ada编写了一些内核模块,但遇到了一些问题。 License is defined as ac macro, and I can't work out what it actually is. 许可证定义为ac宏,我无法弄清楚它的实际含义。 Is it a suitable solution to simply have some c re-exporting all the c functions which require GPL if both the c and the ada module have GPL compatible licenses? 如果c和ada模块都具有GPL兼容许可证,那么简单地将某些c重新导出所有需要GPL的c函数是否是合适的解决方案? Is there a better way to do this? 有一个更好的方法吗?

Dealing with C macros is a royal PITA. 处理C宏是皇家的PITA。 I have a dream that one day C programmers will do the rest of the world a favor and quit using them. 我有一个梦想,就是有一天C程序员将为世界其他地区提供帮助,并放弃使用它们。

If it were me, I'd run the macro to see what it outputs, then write some Ada code to output the equivalent. 如果是我,我将运行宏以查看其输出,然后编写一些Ada代码以输出等效代码。

From reading through Roland's answer, it looks to me like the implementation-defined pragma linker_section may be required. 通过阅读Roland的答案,在我看来,可能需要实现定义的编译指示linker_section

pragma Linker_Section ( [Entity =>] LOCAL_NAME, [Section =>] static_string_EXPRESSION); pragma Linker_Section([Entity =>] LOCAL_NAME,[Section =>] static_string_EXPRESSION);

LOCAL_NAME must refer to an object that is declared at the library level. LOCAL_NAME必须引用在库级别声明的对象。 This pragma specifies the name of the linker section for the given entity. 此杂注指定给定实体的链接器节的名称。 It is equivalent to __attribute__((section)) in GNU C and causes LOCAL_NAME to be placed in the static_string_EXPRESSION section of the executable (assuming the linker doesn't rename the section). 它等效于GNU C中的__attribute__((section)) ,并且将LOCAL_NAME放置在可执行文件的static_string_EXPRESSION部分中(假设链接器未重命名该部分)。

I'm not sure if this question is a joke or not, but if you're serious about writing kernel modules in Ada, then I can't imagine that setting the module license is much of an obstacle compared to everything else you must have hit. 我不确定这个问题是否在开玩笑,但如果您是认真地用Ada编写内核模块,那么我想像不到的是,与您必须拥有的所有其他功能相比,设置模块许可证是一个很大的障碍击中。

In any case, the module license is just a string like "license=GPL" in the .modinfo section of the .ko file. 无论如何,模块许可证只是.ko文件.modinfo部分中的字符串,例如“ license = GPL”。 In C code, it's built by the __MODULE_INFO() macro from <linux/moduleparam.h> , which just creates an array of char that is set to the string as above, tagged with __attribute__((section(".modinfo"))) . 在C代码中,它是由<linux/moduleparam.h>__MODULE_INFO()宏构建的,该宏仅创建一个char数组,该数组设置为上述字符串,并标有__attribute__((section(".modinfo")))

I would guess that there is probably some analogous way to do this in Ada; 我猜想在Ada中可能有一些类似的方法可以做到这一点。 if not, in the worst case, it should be possible to do with a linker script. 如果不是,在最坏的情况下,应该可以使用链接描述文件。 Presumably, you already have some way of handling this anyway, to set the "vermagic=XXX" part of the .modinfo section. 大概,您已经可以通过某种方式来处理此问题,以设置.modinfo节的“ vermagic = XXX”部分。

As an approach to sidestepping the problem, Could you leave the license part in C and use Annex B (Interfacing with other languages) features to access it ? 作为避免问题的一种方法,您可以将许可证部分保留在C中,并使用附件B (与其他语言的接口)功能进行访问吗?

This should contain the problem at least, and allow you to move on with other modules. 这至少应该包含问题,并允许您继续使用其他模块。

At best it may allow you to examine in Ada, what the license looks like and reverse engineer it that way. 充其量它可能允许您在Ada中检查许可证的外观,然后对它进行反向工程。

由于您可能正在使用GNAT,因此您可以使用pragma许可证 “允许自动检查有关标准GPL和修改后的GPL的适当许可证条件”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM