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

@@ -32,6 +32,7 @@
//usage: "\n -H HWTYPE Hardware address type"
#include "libbb.h"
#include "common_bufsiz.h"
#include "inet_common.h"
#include <arpa/inet.h>
@@ -69,7 +70,7 @@ struct globals {
const char *device; /* current device */
smallint hw_set; /* flag if hw-type was set (-H) */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define ap (G.ap )
#define hw (G.hw )
#define device (G.device )

View File

@@ -28,6 +28,7 @@
#include <netpacket/packet.h>
#include "libbb.h"
#include "common_bufsiz.h"
/* We don't expect to see 1000+ seconds delay, unsigned is enough */
#define MONOTONIC_US() ((unsigned)monotonic_us())
@@ -60,7 +61,7 @@ struct globals {
unsigned brd_recv;
unsigned req_recv;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define src (G.src )
#define dst (G.dst )
#define me (G.me )

View File

@@ -29,6 +29,7 @@
//usage: "\n DIR Change root to this directory"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#include <netinet/tcp.h>
@@ -123,7 +124,7 @@ struct globals {
char msg_ok [(sizeof("NNN " MSG_OK ) + 3) & 0xfffc];
char msg_err[(sizeof("NNN " MSG_ERR) + 3) & 0xfffc];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
/* Moved to main */ \
/*strcpy(G.msg_ok + 4, MSG_OK );*/ \

View File

@@ -50,6 +50,7 @@
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
struct globals {
const char *user;
@@ -60,7 +61,7 @@ struct globals {
int do_continue;
char buf[4]; /* actually [BUFSZ] */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
#define user (G.user )
#define password (G.password )

View File

@@ -125,6 +125,7 @@
//usage: "\n -d STRING URL decode STRING"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_PAM
/* PAM may include <locale.h>. We may need to undefine bbox's stub define: */
# undef setlocale
@@ -307,7 +308,8 @@ struct globals {
Htaccess *script_i; /* config script interpreters */
#endif
char *iobuf; /* [IOBUF_SIZE] */
#define hdr_buf bb_common_bufsiz1
#define hdr_buf bb_common_bufsiz1
#define sizeof_hdr_buf COMMON_BUFSIZE
char *hdr_ptr;
int hdr_cnt;
#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
@@ -1066,7 +1068,7 @@ static int get_line(void)
alarm(HEADER_READ_TIMEOUT);
while (1) {
if (hdr_cnt <= 0) {
hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
if (hdr_cnt <= 0)
break;
hdr_ptr = hdr_buf;
@@ -1191,9 +1193,9 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post
/* We expect data, prev data portion is eaten by CGI
* and there *is* data to read from the peer
* (POSTDATA) */
//count = post_len > (int)sizeof(hdr_buf) ? (int)sizeof(hdr_buf) : post_len;
//count = post_len > (int)sizeof_hdr_buf ? (int)sizeof_hdr_buf : post_len;
//count = safe_read(STDIN_FILENO, hdr_buf, count);
count = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
count = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
if (count > 0) {
hdr_cnt = count;
hdr_ptr = hdr_buf;

View File

@@ -44,6 +44,7 @@
//usage: "\n -f Force de/configuration"
#include "libbb.h"
#include "common_bufsiz.h"
/* After libbb.h, since it needs sys/types.h on some systems */
#include <sys/utsname.h>
#include <fnmatch.h>
@@ -129,7 +130,7 @@ struct globals {
const char *startup_PATH;
char *shell;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)

View File

@@ -170,6 +170,7 @@
#include <sys/un.h>
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_INETD_RPC
# if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__)
@@ -327,7 +328,7 @@ struct globals {
/* Used in next_line(), and as scratch read buffer */
char line[256]; /* _at least_ 256, see LINE_SIZE */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) };
#define rlim_ofile_cur (G.rlim_ofile_cur )
#define rlim_ofile (G.rlim_ofile )

View File

@@ -18,6 +18,7 @@
//usage: "\n STRING Ident answer string (default: nobody)"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#include "isrv.h"
@@ -28,7 +29,8 @@ typedef struct identd_buf_t {
char buf[64 - sizeof(int)];
} identd_buf_t;
#define bogouser bb_common_bufsiz1
#define bogouser bb_common_bufsiz1
#define sizeof_bogouser COMMON_BUFSIZE
static int new_peer(isrv_state_t *state, int fd)
{
@@ -118,7 +120,7 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv)
opt = getopt32(argv, "fiwb:", &bind_address);
strcpy(bogouser, "nobody");
if (argv[optind])
strncpy(bogouser, argv[optind], sizeof(bogouser) - 1);
strncpy(bogouser, argv[optind], sizeof_bogouser - 1);
/* Daemonize if no -f and no -i and no -w */
if (!(opt & OPT_fiw))

View File

@@ -13,6 +13,7 @@
#include <net/if_arp.h>
#include "ip_common.h" /* #include "libbb.h" is inside */
#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
@@ -39,7 +40,7 @@ struct filter_t {
} FIX_ALIASING;
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)&bb_common_bufsiz1)
#define G_filter (*(filter_t*)bb_common_bufsiz1)
static void print_link_flags(unsigned flags, unsigned mdown)

View File

@@ -8,6 +8,7 @@
*/
#include "ip_common.h" /* #include "libbb.h" is inside */
#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
#include <linux/neighbour.h>
@@ -40,7 +41,7 @@ struct filter_t {
} FIX_ALIASING;
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)&bb_common_bufsiz1)
#define G_filter (*(filter_t*)bb_common_bufsiz1)
static int flush_update(void)
{

View File

@@ -11,6 +11,7 @@
*/
#include "ip_common.h" /* #include "libbb.h" is inside */
#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
@@ -43,7 +44,7 @@ struct filter_t {
} FIX_ALIASING;
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)&bb_common_bufsiz1)
#define G_filter (*(filter_t*)bb_common_bufsiz1)
static int flush_update(void)
{

View File

@@ -8,6 +8,7 @@
*/
#include "libbb.h"
#include "common_bufsiz.h"
//config:config NC
//config: bool "nc"
@@ -252,7 +253,7 @@ int nc_main(int argc, char **argv)
fd = STDIN_FILENO;
while (1) {
if (FD_ISSET(fd, &testfds)) {
nread = safe_read(fd, iobuf, sizeof(iobuf));
nread = safe_read(fd, iobuf, COMMON_BUFSIZE);
if (fd == cfd) {
if (nread < 1)
exit(EXIT_SUCCESS);

View File

@@ -28,6 +28,7 @@
#include <net/if.h>
#include <netinet/ip_icmp.h>
#include "libbb.h"
#include "common_bufsiz.h"
#ifdef __BIONIC__
/* should be in netinet/ip_icmp.h */
@@ -186,7 +187,7 @@ struct globals {
char *hostname;
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void noresp(int ign UNUSED_PARAM)
@@ -378,7 +379,7 @@ struct globals {
} pingaddr;
unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define if_index (G.if_index )
#define source_lsa (G.source_lsa )
#define str_I (G.str_I )

View File

@@ -27,6 +27,7 @@
//usage: "\n -F Disable RTS/CTS flow control"
#include "libbb.h"
#include "common_bufsiz.h"
#include "libiproute/utils.h" /* invarg_1_to_2() */
struct globals {
@@ -34,7 +35,7 @@ struct globals {
int saved_disc;
struct termios saved_state;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define handle (G.handle )
#define saved_disc (G.saved_disc )
#define saved_state (G.saved_state )

View File

@@ -29,6 +29,7 @@
//usage: "filter show [ dev STRING ] [ root | parent CLASSID ]"
#include "libbb.h"
#include "common_bufsiz.h"
#include "libiproute/utils.h"
#include "libiproute/ip_common.h"
@@ -63,7 +64,7 @@ struct globals {
uint32_t filter_prio;
uint32_t filter_proto;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define filter_ifindex (G.filter_ifindex)
#define filter_qdisc (G.filter_qdisc)
#define filter_parent (G.filter_parent)

View File

@@ -67,6 +67,7 @@
//usage: "\n -v Verbose"
#include "libbb.h"
#include "common_bufsiz.h"
/* Wants <limits.h> etc, thus included after libbb.h: */
#ifdef __linux__
@@ -91,7 +92,7 @@ struct globals {
char **env_cur;
char *env_var[1]; /* actually bigger */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define verbose (G.verbose )
#define max_per_host (G.max_per_host)
#define cur_per_host (G.cur_per_host)

View File

@@ -39,6 +39,7 @@
#include <arpa/telnet.h>
#include <netinet/in.h>
#include "libbb.h"
#include "common_bufsiz.h"
#ifdef __BIONIC__
/* should be in arpa/telnet.h */
@@ -108,7 +109,7 @@ struct globals {
struct termios termios_def;
struct termios termios_raw;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)

View File

@@ -44,6 +44,7 @@
#define DEBUG 0
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#if DEBUG
@@ -82,7 +83,7 @@ struct globals {
const char *issuefile;
int maxfd;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.loginpath = "/bin/login"; \
G.issuefile = "/etc/issue.net"; \

View File

@@ -51,6 +51,7 @@
//usage: "\n -l Log to syslog (inetd mode requires this)"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT
@@ -128,7 +129,7 @@ struct globals {
bb_progress_t pmt;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
@@ -757,7 +758,8 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv)
{
len_and_sockaddr *our_lsa;
len_and_sockaddr *peer_lsa;
char *local_file, *mode, *user_opt;
char *mode, *user_opt;
char *local_file = local_file;
const char *error_msg;
int opt, result, opcode;
IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;)

View File

@@ -9,6 +9,7 @@
#define UDHCP_COMMON_H 1
#include "libbb.h"
#include "common_bufsiz.h"
#include <netinet/udp.h>
#include <netinet/ip.h>

View File

@@ -57,7 +57,7 @@ struct server_config_t {
struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
} FIX_ALIASING;
#define server_config (*(struct server_config_t*)&bb_common_bufsiz1)
#define server_config (*(struct server_config_t*)bb_common_bufsiz1)
/* client_config sits in 2nd half of bb_common_bufsiz1 */
#if ENABLE_FEATURE_UDHCP_PORT

View File

@@ -33,7 +33,7 @@ struct xid_item {
struct xid_item *next;
} FIX_ALIASING;
#define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1)
#define dhcprelay_xid_list (*(struct xid_item*)bb_common_bufsiz1)
static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
{

View File

@@ -57,33 +57,35 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
struct config_keyword {
const char *keyword;
int (*handler)(const char *line, void *var) FAST_FUNC;
void *var;
unsigned ofs;
const char *def;
};
#define OFS(field) offsetof(struct server_config_t, field)
static const struct config_keyword keywords[] = {
/* keyword handler variable address default */
{"start" , udhcp_str2nip , &server_config.start_ip , "192.168.0.20"},
{"end" , udhcp_str2nip , &server_config.end_ip , "192.168.0.254"},
{"interface" , read_str , &server_config.interface , "eth0"},
{"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"},
{"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"},
{"interface" , read_str , OFS(interface ), "eth0"},
/* Avoid "max_leases value not sane" warning by setting default
* to default_end_ip - default_start_ip + 1: */
{"max_leases" , read_u32 , &server_config.max_leases , "235"},
{"auto_time" , read_u32 , &server_config.auto_time , "7200"},
{"decline_time" , read_u32 , &server_config.decline_time , "3600"},
{"conflict_time", read_u32 , &server_config.conflict_time, "3600"},
{"offer_time" , read_u32 , &server_config.offer_time , "60"},
{"min_lease" , read_u32 , &server_config.min_lease_sec, "60"},
{"lease_file" , read_str , &server_config.lease_file , LEASES_FILE},
{"pidfile" , read_str , &server_config.pidfile , "/var/run/udhcpd.pid"},
{"siaddr" , udhcp_str2nip , &server_config.siaddr_nip , "0.0.0.0"},
{"max_leases" , read_u32 , OFS(max_leases ), "235"},
{"auto_time" , read_u32 , OFS(auto_time ), "7200"},
{"decline_time" , read_u32 , OFS(decline_time ), "3600"},
{"conflict_time", read_u32 , OFS(conflict_time), "3600"},
{"offer_time" , read_u32 , OFS(offer_time ), "60"},
{"min_lease" , read_u32 , OFS(min_lease_sec), "60"},
{"lease_file" , read_str , OFS(lease_file ), LEASES_FILE},
{"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"},
{"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"},
/* keywords with no defaults must be last! */
{"option" , udhcp_str2optset, &server_config.options , ""},
{"opt" , udhcp_str2optset, &server_config.options , ""},
{"notify_file" , read_str , &server_config.notify_file , NULL},
{"sname" , read_str , &server_config.sname , NULL},
{"boot_file" , read_str , &server_config.boot_file , NULL},
{"static_lease" , read_staticlease, &server_config.static_leases, ""},
{"option" , udhcp_str2optset, OFS(options ), ""},
{"opt" , udhcp_str2optset, OFS(options ), ""},
{"notify_file" , read_str , OFS(notify_file ), NULL},
{"sname" , read_str , OFS(sname ), NULL},
{"boot_file" , read_str , OFS(boot_file ), NULL},
{"static_lease" , read_staticlease, OFS(static_leases), ""},
};
enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
@@ -95,17 +97,17 @@ void FAST_FUNC read_config(const char *file)
char *token[2];
for (i = 0; i < KWS_WITH_DEFAULTS; i++)
keywords[i].handler(keywords[i].def, keywords[i].var);
keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
parser = config_open(file);
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
if (strcasecmp(token[0], k->keyword) == 0) {
if (!k->handler(token[1], k->var)) {
if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
bb_error_msg("can't parse line %u in %s",
parser->lineno, file);
/* reset back to the default value */
k->handler(k->def, k->var);
k->handler(k->def, (char*)&server_config + k->ofs);
}
break;
}

View File

@@ -40,6 +40,7 @@
//usage: "\nexits only on I/O errors (link down etc)"
#include "libbb.h"
#include "common_bufsiz.h"
#include <netinet/ether.h>
#include <net/if.h>
#include <net/if_arp.h>
@@ -90,7 +91,7 @@ struct globals {
struct ether_addr our_ethaddr;
uint32_t localnet_ip;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)