[BusyBox] choice for reserving buffers

Larry Doolittle ldoolitt at recycle.lbl.gov
Wed Jan 24 17:47:10 UTC 2001


Just to make my suggestion explicit, here is a patch that
shows how to make a compile-time choice between putting buffers
on the stack vs. xmalloc them.  I only "fixed" the buffer allocation
in cp_mv.c, if y'all like this approach it is easy enough to take
care of the other five cases.

I have not fully tested this patch.  I do know that it compiles fine
for either choice, with gcc-2.7.2.3 and gcc-2.95.2.

      - Larry

diff -ur /home/ldoolitt/cvs/busybox/Config.h busybox-trial/Config.h
--- /home/ldoolitt/cvs/busybox/Config.h	Wed Jan 24 09:03:57 2001
+++ busybox-trial/Config.h	Wed Jan 24 09:41:11 2001
@@ -128,6 +128,11 @@
 // pretty/useful).
 //
 //
+// BusyBox will, by default, malloc space for its buffers.  This
+// costs code size for the call to xmalloc.  You can use the
+// following feature to have them put on the stack.  Please realize
+// that can be deadly for some small machines with limited stack space.
+//#define BB_FEATURE_BUFFERS_GO_ON_STACK
 //
 // Turn this on to use Erik's very cool devps, and devmtab kernel drivers,
 // thereby eliminating the need for the /proc filesystem and thereby saving
diff -ur /home/ldoolitt/cvs/busybox/busybox.h busybox-trial/busybox.h
--- /home/ldoolitt/cvs/busybox/busybox.h	Wed Jan 24 09:03:57 2001
+++ busybox-trial/busybox.h	Wed Jan 24 09:31:15 2001
@@ -266,4 +266,10 @@
 #define GIGABYTE (MEGABYTE*1024)
 #endif
 
+#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
+#define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
+#else
+#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
+#endif
+
 #endif /* _BB_INTERNAL_H_ */
diff -ur /home/ldoolitt/cvs/busybox/cp_mv.c busybox-trial/cp_mv.c
--- /home/ldoolitt/cvs/busybox/cp_mv.c	Wed Jan 24 09:03:57 2001
+++ busybox-trial/cp_mv.c	Wed Jan 24 09:29:14 2001
@@ -175,8 +175,8 @@
 {
 	volatile int i;
 	int c;
-	char baseDestName[BUFSIZ + 1]; /* not declared globally == less bss used */
-	pBaseDestName = baseDestName; /* but available globally */
+	RESERVE_BB_BUFFER(baseDestName,BUFSIZ + 1);
+	pBaseDestName = baseDestName; /* available globally */
 
 	if (*applet_name == 'c' && *(applet_name + 1) == 'p')
 		dz_i = is_cp;





More information about the busybox mailing list