diff options
author | Rob Landley <rob@landley.net> | 2005-09-16 14:58:55 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-09-16 14:58:55 +0000 |
commit | a882126feeebb2616910a43ed388a402277434f8 (patch) | |
tree | 86ec29265b5b85648135e1cdefa3c3bcfe29121e /TODO | |
parent | af0dd596a8e3a23cedbc70726e1f17f68491e5c6 (diff) | |
download | busybox-w32-a882126feeebb2616910a43ed388a402277434f8.tar.gz busybox-w32-a882126feeebb2616910a43ed388a402277434f8.tar.bz2 busybox-w32-a882126feeebb2616910a43ed388a402277434f8.zip |
Update TODO with mention of the CONFIG->ENABLE migration and ruminations
about FEATURE_CLEAN_UP.
Diffstat (limited to 'TODO')
-rw-r--r-- | TODO | 67 |
1 files changed, 66 insertions, 1 deletions
@@ -109,9 +109,74 @@ Memory Allocation | |||
109 | allocation on the stack or the heap. Unfortunately, we're not using it much. | 109 | allocation on the stack or the heap. Unfortunately, we're not using it much. |
110 | We need to audit our memory allocations and turn a lot of malloc/free calls | 110 | We need to audit our memory allocations and turn a lot of malloc/free calls |
111 | into RESERVE_CONFIG_BUFFER/RELEASE_CONFIG_BUFFER. | 111 | into RESERVE_CONFIG_BUFFER/RELEASE_CONFIG_BUFFER. |
112 | 112 | ||
113 | And while we're at it, many of the CONFIG_FEATURE_CLEAN_UP #ifdefs will be | 113 | And while we're at it, many of the CONFIG_FEATURE_CLEAN_UP #ifdefs will be |
114 | optimized out by the compiler in the stack allocation case (since there's no | 114 | optimized out by the compiler in the stack allocation case (since there's no |
115 | free for an alloca()), and this means that various cleanup loops that just | 115 | free for an alloca()), and this means that various cleanup loops that just |
116 | call free might also be optimized out by the compiler if written right, so | 116 | call free might also be optimized out by the compiler if written right, so |
117 | we can yank those #ifdefs too, and generally clean up the code. | 117 | we can yank those #ifdefs too, and generally clean up the code. |
118 | --- | ||
119 | Switch CONFIG_SYMBOLS to ENABLE_SYMBOLS | ||
120 | |||
121 | In busybox 1.0 and earlier, configuration was done by CONFIG_SYMBOLS | ||
122 | that were either defined or undefined to indicate whether the symbol was | ||
123 | selected in the .config file. They were used with #ifdefs, ala: | ||
124 | |||
125 | #ifdef CONFIG_SYMBOL | ||
126 | if (other_test) { | ||
127 | do_code(); | ||
128 | } | ||
129 | #endif | ||
130 | |||
131 | In 1.1, we have new ENABLE_SYMBOLS which are always defined (as 0 or 1), | ||
132 | meaning you can still use them for preprocessor tests by replacing | ||
133 | "#ifdef CONFIG_SYMBOL" with "#if ENABLE_SYMBOL". But more importantly, we | ||
134 | can use them as a true or false test in normal C code: | ||
135 | |||
136 | if (ENABLE_SYMBOL && other_test) { | ||
137 | do_code(); | ||
138 | } | ||
139 | |||
140 | (Optimizing away if() statements that resolve to a constant value | ||
141 | is known as "dead code elimination", an optimization so old and simple that | ||
142 | Turbo Pascal for DOS did it twenty years ago. Even modern mini-compilers | ||
143 | like the Tiny C Compiler (tcc) and the Small Device C Compiler (SDCC) | ||
144 | perform dead code elimination.) | ||
145 | |||
146 | Right now, busybox.h is #including both "config.h" (defining the | ||
147 | CONFIG_SYMBOLS) and "bb_config.h" (defining the ENABLE_SYMBOLS). At some | ||
148 | point in the future, it would be nice to wean ourselves off of the | ||
149 | CONFIG versions. (Among other things, some defective build environments | ||
150 | leak the Linux kernel's CONFIG_SYMBOLS into the system's standard #include | ||
151 | files. We've experienced collisions before.) | ||
152 | --- | ||
153 | FEATURE_CLEAN_UP | ||
154 | This is more an unresolved issue than a to-do item. More thought is needed. | ||
155 | |||
156 | Normally we rely on exit() to free memory, close files, and unmap segments | ||
157 | for us. This makes most calls to free(), close(), and unmap() optional in | ||
158 | busybox applets that don't intend to run for very long, and optional stuff | ||
159 | can be omitted to save size. | ||
160 | |||
161 | The idea was raised that we could simulate fork/exit with setjmp/longjmp | ||
162 | for _really_ brainless embedded systems, or speed up the standalone shell | ||
163 | by not forking. Doing so would require a reliable FEATURE_CLEAN_UP. | ||
164 | Unfortunately, this isn't as easy as it sounds. | ||
165 | |||
166 | The problem is, lots of things exit(), sometimes unexpectedly (xmalloc()) | ||
167 | and sometimes reliably (bb_perror_msg_and_die() or show_usage()). This | ||
168 | jumps out of the normal flow control and bypasses any cleanup code we | ||
169 | put at the end of our applets. | ||
170 | |||
171 | It's possible to add hooks to libbb functions like xmalloc() and bb_xopen() | ||
172 | to add their entries to a linked list, which could be traversed and | ||
173 | freed/closed automatically. (This would need to be able to free just the | ||
174 | entries after a checkpoint to be usable for a forkless standalone shell. | ||
175 | You don't want to free the shell's own resources.) | ||
176 | |||
177 | Right now, FEATURE_CLEAN_UP is more or less a debugging aid, to make things | ||
178 | like valgrind happy. It's also documentation of _what_ we're trusting | ||
179 | exit() to clean up for us. But new infrastructure to auto-free stuff would | ||
180 | render the existing FEATURE_CLEAN_UP code redundant. | ||
181 | |||
182 | For right now, exit() handles it just fine. | ||