From a5f120b6205c4e22792c818350b33bf57644ed1c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 23 Jan 2026 10:14:04 +0100 Subject: httpd: simplify CGI headers handling, check "HTTP/1.1" prefix, not just "HTTP" function old new delta cgi_io_loop_and_exit 477 498 +21 .rodata 106830 106821 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 21/-9) Total: 12 bytes Signed-off-by: Denys Vlasenko --- include/platform.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/platform.h b/include/platform.h index a5b61757f..c449075b9 100644 --- a/include/platform.h +++ b/include/platform.h @@ -211,6 +211,7 @@ # define IF_LITTLE_ENDIAN(...) /* How do bytes a,b,c,d (sequential in memory) look if fetched into uint32_t? */ # define PACK32_BYTES(a,b,c,d) (uint32_t)((d)+((c)<<8)+((b)<<16)+((a)<<24)) +# define PACK64_LITERAL_STR(s) (((uint64_t)PACK32_BYTES((s)[0],(s)[1],(s)[2],(s)[3])<<32) + PACK32_BYTES((s)[4],(s)[5],(s)[6],(s)[7])) #else # define SWAP_BE16(x) bswap_16(x) # define SWAP_BE32(x) bswap_32(x) @@ -221,6 +222,7 @@ # define IF_BIG_ENDIAN(...) # define IF_LITTLE_ENDIAN(...) __VA_ARGS__ # define PACK32_BYTES(a,b,c,d) (uint32_t)((a)+((b)<<8)+((c)<<16)+((d)<<24)) +# define PACK64_LITERAL_STR(s) (((uint64_t)PACK32_BYTES((s)[4],(s)[5],(s)[6],(s)[7])<<32) + PACK32_BYTES((s)[0],(s)[1],(s)[2],(s)[3])) #endif -- cgit v1.2.3-55-g6feb From 43982ed49962526f7f042bcd9c5eb05ab4e586de Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 24 Jan 2026 05:21:10 +0100 Subject: 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 --- include/libbb.h | 15 +++++++++++++++ networking/httpd.c | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'include') 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; //sparc64,alpha,openrisc: fixed 8k pages #endif +#if defined(__x86_64__) || defined(i386) +/* 0x7f would be better, but it causes alignment problems */ +# define ARCH_GLOBAL_PTR_OFF 0x80 +#endif + #if defined BB_ARCH_FIXED_PAGESIZE # define IF_VARIABLE_ARCH_PAGESIZE(...) /*nothing*/ # define bb_getpagesize() BB_ARCH_FIXED_PAGESIZE @@ -2423,6 +2428,16 @@ void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; } \ } while (0) +#if defined(ARCH_GLOBAL_PTR_OFF) +# define SET_OFFSET_PTR_TO_GLOBALS(x) \ + ASSIGN_CONST_PTR(&ptr_to_globals, (char*)(x) + ARCH_GLOBAL_PTR_OFF) +# define OFFSET_PTR_TO_GLOBALS \ + ((struct globals*)((char*)ptr_to_globals - ARCH_GLOBAL_PTR_OFF)) +#else +# define SET_OFFSET_PTR_TO_GLOBALS(x) SET_PTR_TO_GLOBALS(x) +# define OFFSET_PTR_TO_GLOBALS ptr_to_globals +#endif + /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, * 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 { }; struct globals { - int verbose; /* must be int (used by getopt32) */ smallint flg_deny_all; #if ENABLE_FEATURE_HTTPD_GZIP /* client can handle gzip / we are going to send gzip */ @@ -494,6 +493,7 @@ struct globals { #if ENABLE_FEATURE_HTTPD_CGI smallint cgi_output; #endif + int verbose; /* must be int (used by getopt32) */ time_t last_mod; #if ENABLE_FEATURE_HTTPD_ETAG char *if_none_match; @@ -555,7 +555,7 @@ struct globals { #endif char iobuf[IOBUF_SIZE] ALIGN8; }; -#define G (*ptr_to_globals) +#define G (*OFFSET_PTR_TO_GLOBALS) #define verbose (G.verbose ) #define flg_deny_all (G.flg_deny_all ) #if ENABLE_FEATURE_HTTPD_GZIP @@ -598,7 +598,7 @@ enum { #define iobuf (G.iobuf ) #define INIT_G() do { \ setup_common_bufsiz(); \ - SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ + SET_OFFSET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ bind_addr_or_port = STR(CONFIG_FEATURE_HTTPD_PORT_DEFAULT); \ -- cgit v1.2.3-55-g6feb