libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for it

The config item is FEATURE_USE_BSS_TAIL. When it is off (default):

function                                             old     new   delta
read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
push                                                  46      44      -2
inetd_main                                          2136    2134      -2
uevent_main                                          421     418      -3
addLines                                              97      92      -5
bb_common_bufsiz1                                   8193    1024   -7169
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/5 up/down: 62/-7181)        Total: -7119 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829901	   4086	   1904	 835891	  cc133	busybox_unstripped

FEATURE_USE_BSS_TAIL=y:

read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
inetd_main                                          2136    2134      -2
bb_common_bufsiz1                                   8193       -   -8193
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 8/1 up/down: 62/-8195)        Total: -8133 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829911	   4086	    880	 834877	  cbd3d	busybox_unstripped

FIXME: setup_common_bufsiz() calls are missing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2016-04-21 16:26:30 +02:00
parent 5598bdf0d3
commit e6a2f4cc5a
91 changed files with 414 additions and 131 deletions

View File

@@ -17,6 +17,7 @@
//usage: "chat '' ATZ OK ATD123456 CONNECT '' ogin: pppuser word: ppppass '~'"
#include "libbb.h"
#include "common_bufsiz.h"
// default timeout: 45 sec
#define DEFAULT_CHAT_TIMEOUT 45*1000

View File

@@ -42,6 +42,7 @@
//usage: "\n -y LINE Starting line"
#include "libbb.h"
#include "common_bufsiz.h"
#include <sys/kd.h>
#define ESC "\033"
@@ -363,7 +364,8 @@ int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int conspy_main(int argc UNUSED_PARAM, char **argv)
{
char tty_name[sizeof(DEV_TTY "NN")];
#define keybuf bb_common_bufsiz1
#define keybuf bb_common_bufsiz1
#define sizeof_keybuf COMMON_BUFSIZE
struct termios termbuf;
unsigned opts;
unsigned ttynum;
@@ -513,7 +515,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
default:
// Read the keys pressed
k = keybuf + G.key_count;
bytes_read = read(G.kbd_fd, k, sizeof(keybuf) - G.key_count);
bytes_read = read(G.kbd_fd, k, sizeof_keybuf - G.key_count);
if (bytes_read < 0)
goto abort;

View File

@@ -60,6 +60,7 @@
//usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
/* glibc frees previous setenv'ed value when we do next setenv()
@@ -140,7 +141,7 @@ struct globals {
char *env_var_logname;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.log_level = 8; \
G.crontab_dir_name = CRONTABS; \

View File

@@ -4,6 +4,7 @@
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include <math.h>
//usage:#define dc_trivial_usage
@@ -47,7 +48,7 @@ struct globals {
double stack[1];
} FIX_ALIASING;
enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) };
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define pointer (G.pointer )
#define base (G.base )
#define stack (G.stack )

View File

@@ -34,6 +34,7 @@
//usage: "\n commands: 'NN' (% for progress bar) or 'exit'"
#include "libbb.h"
#include "common_bufsiz.h"
#include <linux/fb.h>
/* If you want logging messages on /tmp/fbsplash.log... */
@@ -372,11 +373,12 @@ static void fb_drawimage(void)
* - A raster of Width * Height pixels in triplets of rgb
* in pure binary by 1 or 2 bytes. (we support only 1 byte)
*/
#define concat_buf bb_common_bufsiz1
#define concat_buf bb_common_bufsiz1
#define sizeof_concat_buf COMMON_BUFSIZE
read_ptr = concat_buf;
while (1) {
int w, h, max_color_val;
int rem = concat_buf + sizeof(concat_buf) - read_ptr;
int rem = concat_buf + sizeof_concat_buf - read_ptr;
if (rem < 2
|| fgets(read_ptr, rem, theme_file) == NULL
) {

View File

@@ -63,6 +63,7 @@
//usage: "\n -z Reread partition table"
#include "libbb.h"
#include "common_bufsiz.h"
/* must be _after_ libbb.h: */
#include <linux/hdreg.h>
#include <sys/mount.h>
@@ -367,7 +368,7 @@ struct globals {
unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 };
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define get_identity (G.get_identity )
#define get_geom (G.get_geom )
#define do_flush (G.do_flush )

View File

@@ -60,6 +60,7 @@
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include <linux/i2c.h>
#include <linux/i2c-dev.h>

View File

@@ -56,6 +56,7 @@
//usage: "\nWhen x event happens for all FILEs, inotifyd exits."
#include "libbb.h"
#include "common_bufsiz.h"
#include <sys/inotify.h>
static const char mask_names[] ALIGN1 =
@@ -162,8 +163,9 @@ int inotifyd_main(int argc, char **argv)
// read out all pending events
// (NB: len must be int, not ssize_t or long!)
xioctl(pfd.fd, FIONREAD, &len);
#define eventbuf bb_common_bufsiz1
ie = buf = (len <= sizeof(eventbuf)) ? eventbuf : xmalloc(len);
#define eventbuf bb_common_bufsiz1
#define sizeof_eventbuf COMMON_BUFSIZE
ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len);
len = full_read(pfd.fd, buf, len);
// process events. N.B. events may vary in length
while (len > 0) {

View File

@@ -127,6 +127,7 @@
#include <sched.h> /* sched_yield() */
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_LESS_REGEXP
#include "xregex.h"
#endif
@@ -439,7 +440,8 @@ static int at_end(void)
*/
static void read_lines(void)
{
#define readbuf bb_common_bufsiz1
#define readbuf bb_common_bufsiz1
#define sizeof_readbuf COMMON_BUFSIZE
char *current_line, *p;
int w = width;
char last_terminated = terminated;
@@ -480,7 +482,7 @@ static void read_lines(void)
time_t t;
errno = 0;
eof_error = safe_read(STDIN_FILENO, readbuf, sizeof(readbuf));
eof_error = safe_read(STDIN_FILENO, readbuf, sizeof_readbuf);
if (errno != EAGAIN)
break;
t = time(NULL);

View File

@@ -19,6 +19,7 @@
//usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin"
#include "libbb.h"
#include "common_bufsiz.h"
// set raw tty mode
static void xget1(int fd, struct termios *t, struct termios *oldt)
@@ -155,10 +156,11 @@ int microcom_main(int argc UNUSED_PARAM, char **argv)
skip_write: ;
}
if (pfd[0].revents) {
#define iobuf bb_common_bufsiz1
#define iobuf bb_common_bufsiz1
#define sizeof_iobuf COMMON_BUFSIZE
ssize_t len;
// read from device -> write to stdout
len = safe_read(sfd, iobuf, sizeof(iobuf));
len = safe_read(sfd, iobuf, sizeof_iobuf);
if (len > 0)
full_write(STDOUT_FILENO, iobuf, len);
else {