diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2026-01-24 05:21:10 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-01-24 05:22:33 +0100 |
| commit | 43982ed49962526f7f042bcd9c5eb05ab4e586de (patch) | |
| tree | f4ae8a35c49117808a833cd1ddc1a6280e71ed5c | |
| parent | 1a64fe3594b80dabcc7ccb7dce5b3391b27b0d24 (diff) | |
| download | busybox-w32-43982ed49962526f7f042bcd9c5eb05ab4e586de.tar.gz busybox-w32-43982ed49962526f7f042bcd9c5eb05ab4e586de.tar.bz2 busybox-w32-43982ed49962526f7f042bcd9c5eb05ab4e586de.zip | |
httpd: code shrink via "split-globals" trick
function old new delta
httpd_main 957 968 +11
log_and_exit 25 26 +1
send_headers 712 708 -4
handle_incoming_and_exit 2292 2285 -7
sigalrm_handler 102 93 -9
parse_conf 1332 1323 -9
send_cgi_and_exit 803 790 -13
cgi_io_loop_and_exit 656 635 -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/6 up/down: 12/-63) Total: -51 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | include/libbb.h | 15 | ||||
| -rw-r--r-- | networking/httpd.c | 6 |
2 files changed, 18 insertions, 3 deletions
diff --git a/include/libbb.h b/include/libbb.h index 8d252d455..17c9bc785 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -457,6 +457,11 @@ void *xmmap_anon(size_t size) FAST_FUNC; | |||
| 457 | //sparc64,alpha,openrisc: fixed 8k pages | 457 | //sparc64,alpha,openrisc: fixed 8k pages |
| 458 | #endif | 458 | #endif |
| 459 | 459 | ||
| 460 | #if defined(__x86_64__) || defined(i386) | ||
| 461 | /* 0x7f would be better, but it causes alignment problems */ | ||
| 462 | # define ARCH_GLOBAL_PTR_OFF 0x80 | ||
| 463 | #endif | ||
| 464 | |||
| 460 | #if defined BB_ARCH_FIXED_PAGESIZE | 465 | #if defined BB_ARCH_FIXED_PAGESIZE |
| 461 | # define IF_VARIABLE_ARCH_PAGESIZE(...) /*nothing*/ | 466 | # define IF_VARIABLE_ARCH_PAGESIZE(...) /*nothing*/ |
| 462 | # define bb_getpagesize() BB_ARCH_FIXED_PAGESIZE | 467 | # define bb_getpagesize() BB_ARCH_FIXED_PAGESIZE |
| @@ -2423,6 +2428,16 @@ void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; | |||
| 2423 | } \ | 2428 | } \ |
| 2424 | } while (0) | 2429 | } while (0) |
| 2425 | 2430 | ||
| 2431 | #if defined(ARCH_GLOBAL_PTR_OFF) | ||
| 2432 | # define SET_OFFSET_PTR_TO_GLOBALS(x) \ | ||
| 2433 | ASSIGN_CONST_PTR(&ptr_to_globals, (char*)(x) + ARCH_GLOBAL_PTR_OFF) | ||
| 2434 | # define OFFSET_PTR_TO_GLOBALS \ | ||
| 2435 | ((struct globals*)((char*)ptr_to_globals - ARCH_GLOBAL_PTR_OFF)) | ||
| 2436 | #else | ||
| 2437 | # define SET_OFFSET_PTR_TO_GLOBALS(x) SET_PTR_TO_GLOBALS(x) | ||
| 2438 | # define OFFSET_PTR_TO_GLOBALS ptr_to_globals | ||
| 2439 | #endif | ||
| 2440 | |||
| 2426 | 2441 | ||
| 2427 | /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, | 2442 | /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, |
| 2428 | * use bb_default_login_shell and following defines. | 2443 | * use bb_default_login_shell and following defines. |
diff --git a/networking/httpd.c b/networking/httpd.c index ce557c1bf..176eb244b 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
| @@ -484,7 +484,6 @@ static const struct { | |||
| 484 | }; | 484 | }; |
| 485 | 485 | ||
| 486 | struct globals { | 486 | struct globals { |
| 487 | int verbose; /* must be int (used by getopt32) */ | ||
| 488 | smallint flg_deny_all; | 487 | smallint flg_deny_all; |
| 489 | #if ENABLE_FEATURE_HTTPD_GZIP | 488 | #if ENABLE_FEATURE_HTTPD_GZIP |
| 490 | /* client can handle gzip / we are going to send gzip */ | 489 | /* client can handle gzip / we are going to send gzip */ |
| @@ -494,6 +493,7 @@ struct globals { | |||
| 494 | #if ENABLE_FEATURE_HTTPD_CGI | 493 | #if ENABLE_FEATURE_HTTPD_CGI |
| 495 | smallint cgi_output; | 494 | smallint cgi_output; |
| 496 | #endif | 495 | #endif |
| 496 | int verbose; /* must be int (used by getopt32) */ | ||
| 497 | time_t last_mod; | 497 | time_t last_mod; |
| 498 | #if ENABLE_FEATURE_HTTPD_ETAG | 498 | #if ENABLE_FEATURE_HTTPD_ETAG |
| 499 | char *if_none_match; | 499 | char *if_none_match; |
| @@ -555,7 +555,7 @@ struct globals { | |||
| 555 | #endif | 555 | #endif |
| 556 | char iobuf[IOBUF_SIZE] ALIGN8; | 556 | char iobuf[IOBUF_SIZE] ALIGN8; |
| 557 | }; | 557 | }; |
| 558 | #define G (*ptr_to_globals) | 558 | #define G (*OFFSET_PTR_TO_GLOBALS) |
| 559 | #define verbose (G.verbose ) | 559 | #define verbose (G.verbose ) |
| 560 | #define flg_deny_all (G.flg_deny_all ) | 560 | #define flg_deny_all (G.flg_deny_all ) |
| 561 | #if ENABLE_FEATURE_HTTPD_GZIP | 561 | #if ENABLE_FEATURE_HTTPD_GZIP |
| @@ -598,7 +598,7 @@ enum { | |||
| 598 | #define iobuf (G.iobuf ) | 598 | #define iobuf (G.iobuf ) |
| 599 | #define INIT_G() do { \ | 599 | #define INIT_G() do { \ |
| 600 | setup_common_bufsiz(); \ | 600 | setup_common_bufsiz(); \ |
| 601 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 601 | SET_OFFSET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
| 602 | IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ | 602 | IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ |
| 603 | IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ | 603 | IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ |
| 604 | bind_addr_or_port = STR(CONFIG_FEATURE_HTTPD_PORT_DEFAULT); \ | 604 | bind_addr_or_port = STR(CONFIG_FEATURE_HTTPD_PORT_DEFAULT); \ |
