在解释完linux/include/linux/compiler.h后,回到本来的初衷linux/include/linux/init.h。在此贴上代码: 1 #ifndef _LINUX_INIT_H 2 #define _LINUX_INIT_H 3 4 #include <linux/compiler.h> 5 6 /* These macros are used to mark some functions or 7 * initialized data (doesn't apply to uninitialized data) 8 * as `initialization' functions. The kernel can take this 9 * as hint that the function is used only during the initialization 10 * phase and free up used memory resources after 11 * 12 * Usage: 13 * For functions: 14 * 15 * You should add __init immediately before the function name, like: 16 * 17 * static void __init initme(int x, int y) 18 * { 19 * extern int z; z = x * y; 20 * } 21 * 22 * If the function has a prototype somewhere, you can also add 23 * __init between closing brace of the prototype and semicolon: 24 * 25 * extern int initialize_foobar_device(int, int, int) __init; 26 * 27 * For initialized data: 28 * You should insert __initdata between the variable name and equal 29 * sign followed by value, e.g.: 30 * 31 * static int init_variable __initdata = 0; 32 * static const char linux_logo[] __initconst = { 0x32, 0x36, ... }; 33 * 34 * Don't forget to initialize data not at file scope, i.e. within a function, 35 * as gcc otherwise puts the data into the bss section and not into the init 36 * section. 37 * 38 * Also note, that this data cannot be "const". 39 */ 40 41 /* These are for everybody (although not all archs will actually 42 discard it in modules) */ 43 #define __init __section(.init.text) __cold notrace 44 #define __initdata __section(.init.data) 45 #define __initconst __section(.init.rodata) 46 #define __exitdata __section(.exit.data) 47 #define __exit_call __used __section(.exitcall.exit) 48 49 /* modpost check for section mismatches during the kernel build. 50 * A section mismatch happens when there are references from a 51 * code or data section to an init section (both code or data). 52 * The init sections are (for most archs) discarded by the kernel 53 * when early init has completed so all such references are potential bugs. 54 * For exit sections the same issue exists. 55 * The following markers are used for the cases where the reference to 56 * the *init / *exit section (code or data) is valid and will teach 57 * modpost not to issue a warning. 58 * The markers follow same syntax rules as __init / __initdata. */ 59 #define __ref __section(.ref.text) noinline 60 #define __refdata __section(.ref.data) 61 #define __refconst __section(.ref.rodata) 62 63 /* compatibility defines */ 64 #define __init_refok __ref 65 #define __initdata_refok __refdata 66 #define __exit_refok __ref 67 68 69 #ifdef MODULE 70 #define __exitused 71 #else 72 #define __exitused __used 73 #endif 74 75 #define __exit __section(.exit.text) __exitused __cold 76 77 /* Used for HOTPLUG */ 78 #define __devinit __section(.devinit.text) __cold 79 #define __devinitdata __section(.devinit.data) 80 #define __devinitconst __section(.devinit.rodata) 81 #define __devexit __section(.devexit.text) __exitused __cold 82 #define __devexitdata __section(.devexit.data) 83 #define __devexitconst __section(.devexit.rodata) 84 85 /* Used for HOTPLUG_CPU */ 86 #define __cpuinit __section(.cpuinit.text) __cold 87 #define __cpuinitdata __section(.cpuinit.data) 88 #define __cpuinitconst __section(.cpuinit.rodata) 89 #define __cpuexit __section(.cpuexit.text) __exitused __cold 90 #define __cpuexitdata __section(.cpuexit.data) 91 #define __cpuexitconst __section(.cpuexit.rodata) 92 93 /* Used for MEMORY_HOTPLUG */ 94 #define __meminit __section(.meminit.text) __cold 95 #define __m