2012-01-12 5 views

उत्तर

52

include/linux/init.h

/* These macros are used to mark some functions or 
* initialized data (doesn't apply to uninitialized data) 
* as `initialization' functions. The kernel can take this 
* as hint that the function is used only during the initialization 
* phase and free up used memory resources after 
* 
* Usage: 
* For functions: 
* 
* You should add __init immediately before the function name, like: 
* 
* static void __init initme(int x, int y) 
* { 
* extern int z; z = x * y; 
* } 
* 
* If the function has a prototype somewhere, you can also add 
* __init between closing brace of the prototype and semicolon: 
* 
* extern int initialize_foobar_device(int, int, int) __init; 
* 
* For initialized data: 
* You should insert __initdata between the variable name and equal 
* sign followed by value, e.g.: 
* 
* static int init_variable __initdata = 0; 
* static const char linux_logo[] __initconst = { 0x32, 0x36, ... }; 
* 
* Don't forget to initialize data not at file scope, i.e. within a function, 
* as gcc otherwise puts the data into the bss section and not into the init 
* section. 
* 
* Also note, that this data cannot be "const". 
*/ 

/* These are for everybody (although not all archs will actually 
    discard it in modules) */ 
#define __init  __section(.init.text) __cold notrace 
#define __initdata __section(.init.data) 
#define __initconst __section(.init.rodata) 
#define __exitdata __section(.exit.data) 
#define __exit_call __used __section(.exitcall.exit) 
40

अंतिम निष्पादन बाइनरी में विशेष क्षेत्रों में लिनक्स कोड के कुछ हिस्सों को ढूंढने के लिए ये केवल मैक्रोज़ हैं। __init, उदाहरण के लिए (या बेहतर __attribute__ ((__section__ (".init.text"))) यह मैक्रो विस्तारित करता है) इस फ़ंक्शन को विशेष तरीके से चिह्नित करने के लिए संकलक को निर्देश देता है। अंत में लिंकर बाइनरी फ़ाइल के अंत (या शुरू) पर इस चिह्न के साथ सभी कार्यों एकत्र करता है।

जब कर्नेल शुरू होता है, तो यह कोड केवल एक बार (प्रारंभिक) चलाता है। यह चलने के बाद, गिरी यह पुन: उपयोग करने के लिए इस स्मृति मुक्त कर सकते हैं और आप गिरी संदेश देखेंगे:

अप्रयुक्त कर्नेल स्मृति मुक्त: 108k मुक्त कर दिया

इस सुविधा का उपयोग करने के लिए, आप एक की जरूरत है विशेष लिंकर स्क्रिप्ट फ़ाइल, जो लिंकर को बताती है कि सभी चिह्नित कार्यों का पता लगाएं।

+8

चालाक! तो यही है "अप्रयुक्त कर्नेल मेमोरी को मुक्त करना: 108k मुक्त" मतलब था। :-) मैंने इन सभी वर्षों में आश्चर्यचकित किया है। मुझे लगता है कि यह किसी प्रकार का बफर या कुछ था, कोड नहीं। –

2

linux/ini.h में टिप्पणी (और एक ही समय में दस्तावेज़) पढ़ें।

आपको यह भी पता होना चाहिए कि जीसीसी में लिनक्स कर्नेल कोड के लिए विशेष रूप से कुछ एक्सटेंशन बनाए गए हैं और ऐसा लगता है कि यह मैक्रो उनमें से एक का उपयोग करता है।

3

__init एक मैक्रो ./include/linux/init.h जो __attribute__ ((__section__(".init.text"))) के लिए विस्तारित में परिभाषित किया गया है।

यह इस फ़ंक्शन को विशेष तरीके से चिह्नित करने के लिए संकलक को निर्देश देता है। अंत में लिंकर बाइनरी फ़ाइल के अंत (या शुरू) पर इस चिह्न के साथ सभी कार्यों को एकत्र करता है। जब कर्नेल प्रारंभ होता है, तो यह कोड केवल एक बार (प्रारंभिक) चलाता है। इसे चलाने के बाद, कर्नेल इस स्मृति को पुन: उपयोग करने के लिए मुक्त कर सकता है और आप कर्नेल

3

देखेंगे यह कर्नेल 2.2 और बाद में एक विशेषता प्रदर्शित करता है। init और cleanup फ़ंक्शंस की परिभाषाओं में परिवर्तन पर ध्यान दें। __init मैक्रो init फ़ंक्शन को त्यागने का कारण बनता है और init फ़ंक्शन में अंतर्निहित ड्राइवरों के लिए फ़ंक्शन समाप्त होने के बाद इसकी स्मृति मुक्त हो जाती है, लेकिन लोड करने योग्य मॉड्यूल नहीं। यदि आप init फ़ंक्शन का आह्वान करते हैं, तो यह सही समझ में आता है।

source

संबंधित मुद्दे