diff options
Diffstat (limited to 'applets')
-rw-r--r-- | applets/Kbuild | 18 | ||||
-rw-r--r-- | applets/applet_tables.c | 55 |
2 files changed, 47 insertions, 26 deletions
diff --git a/applets/Kbuild b/applets/Kbuild index b9dba03e1..ef4b76fed 100644 --- a/applets/Kbuild +++ b/applets/Kbuild | |||
@@ -14,20 +14,20 @@ always:= $(hostprogs-y) | |||
14 | 14 | ||
15 | # Generated files need additional love | 15 | # Generated files need additional love |
16 | 16 | ||
17 | quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h | ||
18 | cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets | ||
19 | |||
20 | HOSTCFLAGS_usage.o = -I$(srctree)/include | 17 | HOSTCFLAGS_usage.o = -I$(srctree)/include |
21 | 18 | ||
22 | applets/applets.o: include/usage_compressed.h include/applet_tables.h | 19 | applets/applets.o: include/usage_compressed.h include/applet_tables.h |
23 | 20 | ||
24 | applets/usage: .config $(srctree)/applets/usage_compressed | 21 | applets/usage: .config $(srctree)/applets/usage_compressed |
22 | |||
23 | quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h | ||
24 | cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets | ||
25 | 25 | ||
26 | include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed | 26 | include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed |
27 | $(call cmd,gen_usage_compressed) | 27 | $(call cmd,gen_usage_compressed) |
28 | 28 | ||
29 | # Two-stage file creation, to avoid having target file still created | 29 | quiet_cmd_gen_applet_tables = GEN include/applet_tables.h |
30 | # in case applet_tables fails | 30 | cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h |
31 | |||
31 | include/applet_tables.h: applets/applet_tables | 32 | include/applet_tables.h: applets/applet_tables |
32 | applets/applet_tables >include/applet_tables.h.tmp | 33 | $(call cmd,gen_applet_tables) |
33 | mv include/applet_tables.h.tmp include/applet_tables.h | ||
diff --git a/applets/applet_tables.c b/applets/applet_tables.c index b5df74076..9f42ebf31 100644 --- a/applets/applet_tables.c +++ b/applets/applet_tables.c | |||
@@ -50,45 +50,66 @@ int main(int argc, char **argv) | |||
50 | 50 | ||
51 | qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name); | 51 | qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name); |
52 | 52 | ||
53 | /* Keep in sync with include/busybox.h! */ | ||
54 | |||
55 | puts("const char applet_names[] ALIGN1 ="); | ||
56 | ofs = 0; | 53 | ofs = 0; |
57 | i = 0; | ||
58 | for (i = 0; i < NUM_APPLETS; i++) { | 54 | for (i = 0; i < NUM_APPLETS; i++) { |
59 | offset[i] = ofs; | 55 | offset[i] = ofs; |
60 | ofs += strlen(applets[i].name) + 1; | 56 | ofs += strlen(applets[i].name) + 1; |
57 | } | ||
58 | /* We reuse 4 high-order bits of offset array for other purposes, | ||
59 | * so if they are indeed needed, refuse to proceed */ | ||
60 | if (ofs > 0xfff) | ||
61 | return 1; | ||
62 | if (!argv[1]) | ||
63 | return 1; | ||
64 | |||
65 | i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666); | ||
66 | if (i < 0) | ||
67 | return 1; | ||
68 | dup2(i, 1); | ||
69 | |||
70 | /* Keep in sync with include/busybox.h! */ | ||
71 | |||
72 | puts("/* This is a generated file, don't edit */"); | ||
73 | |||
74 | puts("const char applet_names[] ALIGN1 ="); | ||
75 | for (i = 0; i < NUM_APPLETS; i++) { | ||
61 | printf("\"%s\" \"\\0\"\n", applets[i].name); | 76 | printf("\"%s\" \"\\0\"\n", applets[i].name); |
62 | } | 77 | } |
63 | puts(";"); | 78 | puts(";"); |
64 | 79 | ||
65 | puts("int (*const applet_mains[])(int argc, char **argv) = {"); | 80 | puts("int (*const applet_main[])(int argc, char **argv) = {"); |
66 | for (i = 0; i < NUM_APPLETS; i++) { | 81 | for (i = 0; i < NUM_APPLETS; i++) { |
67 | printf("%s_main,\n", applets[i].main); | 82 | printf("%s_main,\n", applets[i].main); |
68 | } | 83 | } |
69 | puts("};"); | 84 | puts("};"); |
70 | 85 | ||
71 | #if ENABLE_FEATURE_INSTALLER || ENABLE_FEATURE_PREFER_APPLETS | ||
72 | puts("const uint32_t applet_nameofs[] = {"); | ||
73 | #else | ||
74 | puts("const uint16_t applet_nameofs[] ALIGN2 = {"); | 86 | puts("const uint16_t applet_nameofs[] ALIGN2 = {"); |
75 | #endif | ||
76 | for (i = 0; i < NUM_APPLETS; i++) { | 87 | for (i = 0; i < NUM_APPLETS; i++) { |
77 | printf("0x%08x,\n", | 88 | printf("0x%04x,\n", |
78 | offset[i] | 89 | offset[i] |
90 | #if ENABLE_FEATURE_PREFER_APPLETS | ||
91 | + (applets[i].nofork << 12) | ||
92 | + (applets[i].noexec << 13) | ||
93 | #endif | ||
79 | #if ENABLE_FEATURE_SUID | 94 | #if ENABLE_FEATURE_SUID |
80 | + (applets[i].need_suid << 14) /* 2 bits */ | 95 | + (applets[i].need_suid << 14) /* 2 bits */ |
81 | #endif | 96 | #endif |
82 | #if ENABLE_FEATURE_INSTALLER | ||
83 | + (applets[i].install_loc << 16) /* 3 bits */ | ||
84 | #endif | ||
85 | #if ENABLE_FEATURE_PREFER_APPLETS | ||
86 | + (applets[i].nofork << 19) | ||
87 | + (applets[i].noexec << 20) | ||
88 | #endif | ||
89 | ); | 97 | ); |
90 | } | 98 | } |
91 | puts("};"); | 99 | puts("};"); |
92 | 100 | ||
101 | #if ENABLE_FEATURE_INSTALLER | ||
102 | puts("const uint8_t applet_install_loc[] ALIGN1 = {"); | ||
103 | i = 0; | ||
104 | while (i < NUM_APPLETS) { | ||
105 | int v = applets[i].install_loc; /* 3 bits */ | ||
106 | if (++i < NUM_APPLETS) | ||
107 | v |= applets[i].install_loc << 4; /* 3 bits */ | ||
108 | printf("0x%02x,\n", v); | ||
109 | i++; | ||
110 | } | ||
111 | puts("};"); | ||
112 | #endif | ||
113 | |||
93 | return 0; | 114 | return 0; |
94 | } | 115 | } |