aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2025-09-10 14:06:07 +0100
committerRon Yorston <rmy@pobox.com>2025-09-10 14:06:07 +0100
commit96377594e24b609de85c184ab3172b2adaab0d0d (patch)
tree299d2eaf0cd563a12157ad2496d1068902f4f9e0 /shell
parent3aaade794f10a7f6a00a63e9472cc316581c80c2 (diff)
downloadbusybox-w32-96377594e24b609de85c184ab3172b2adaab0d0d.tar.gz
busybox-w32-96377594e24b609de85c184ab3172b2adaab0d0d.tar.bz2
busybox-w32-96377594e24b609de85c184ab3172b2adaab0d0d.zip
ash: move 100 bytes off global .data / .bss, no logic changes
Apply upstream commit f6fb3c603. This moves some static data into globals_misc. The Windows port had already moved commandname, so only g_parsefile and basepf are new. Some changes had to be made to the forkshell code. Adds 148-176 bytes.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c159
1 files changed, 79 insertions, 80 deletions
diff --git a/shell/ash.c b/shell/ash.c
index ecea75245..4c6d78a32 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -407,7 +407,6 @@ struct forkshell {
407 unsigned njobs; 407 unsigned njobs;
408 struct job *curjob; 408 struct job *curjob;
409#endif 409#endif
410 /* struct parsefile *g_parsefile; */
411 HANDLE hMapFile; 410 HANDLE hMapFile;
412 char *old_base; 411 char *old_base;
413 int size; 412 int size;
@@ -540,6 +539,65 @@ static const char *const optletters_optnames[] ALIGN_PTR = {
540enum { NOPTS = ARRAY_SIZE(optletters_optnames) }; 539enum { NOPTS = ARRAY_SIZE(optletters_optnames) };
541 540
542 541
542/* ============ Parser data */
543
544struct strlist {
545 struct strlist *next;
546 char *text;
547};
548
549struct alias;
550
551struct strpush {
552 struct strpush *prev; /* preceding string on stack */
553 char *prev_string;
554 int prev_left_in_line;
555#if ENABLE_ASH_ALIAS
556 struct alias *ap; /* if push was associated with an alias */
557#endif
558 char *string; /* remember the string since it may change */
559
560 /* Delay freeing so we can stop nested aliases. */
561 struct strpush *spfree;
562
563 /* Remember last two characters for pungetc. */
564 int lastc[2];
565
566 /* Number of outstanding calls to pungetc. */
567 int unget;
568};
569
570/*
571 * The parsefile structure pointed to by the global variable parsefile
572 * contains information about the current file being read.
573 */
574struct parsefile {
575 struct parsefile *prev; /* preceding file on stack */
576 int linno; /* current line */
577 int pf_fd; /* file descriptor (or -1 if string) */
578 int left_in_line; /* number of chars left in this line */
579 int left_in_buffer; /* number of chars left in this buffer past the line */
580 char *next_to_pgetc; /* next char in buffer */
581 char *buf; /* input buffer */
582 struct strpush *strpush; /* for pushing strings at this level */
583 struct strpush basestrpush; /* so pushing one is fast */
584
585 /* Delay freeing so we can stop nested aliases. */
586 struct strpush *spfree;
587
588 /* Remember last two characters for pungetc. */
589 int lastc[2];
590
591 /* Number of outstanding calls to pungetc. */
592 int unget;
593
594#if ENABLE_PLATFORM_MINGW32
595 /* True if a trailing CR from a previous read was left unprocessed. */
596 int cr;
597#endif
598};
599
600
543/* ============ Misc data */ 601/* ============ Misc data */
544 602
545#define msg_illnum "Illegal number: %s" 603#define msg_illnum "Illegal number: %s"
@@ -590,9 +648,6 @@ struct globals_misc {
590 char *physdir; // = nullstr; /* physical working directory */ 648 char *physdir; // = nullstr; /* physical working directory */
591 649
592 char *arg0; /* value of $0 */ 650 char *arg0; /* value of $0 */
593#if ENABLE_PLATFORM_MINGW32
594 char *commandname;
595#endif
596 651
597 struct jmploc *exception_handler; 652 struct jmploc *exception_handler;
598 653
@@ -678,6 +733,10 @@ struct globals_misc {
678 733
679 char **trap_ptr; /* used only by "trap hack" */ 734 char **trap_ptr; /* used only by "trap hack" */
680 735
736 char *commandname; /* currently executing command */
737 struct parsefile *g_parsefile; /* = &basepf, current input file */
738 struct parsefile basepf; /* top level input file */
739
681 /* Rarely referenced stuff */ 740 /* Rarely referenced stuff */
682 741
683 struct jmploc main_handler; 742 struct jmploc main_handler;
@@ -717,9 +776,6 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc;
717#define curdir (G_misc.curdir ) 776#define curdir (G_misc.curdir )
718#define physdir (G_misc.physdir ) 777#define physdir (G_misc.physdir )
719#define arg0 (G_misc.arg0 ) 778#define arg0 (G_misc.arg0 )
720#if ENABLE_PLATFORM_MINGW32
721#define commandname (G_misc.commandname)
722#endif
723#define exception_handler (G_misc.exception_handler) 779#define exception_handler (G_misc.exception_handler)
724#define exception_type (G_misc.exception_type ) 780#define exception_type (G_misc.exception_type )
725#define suppress_int (G_misc.suppress_int ) 781#define suppress_int (G_misc.suppress_int )
@@ -733,6 +789,9 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc;
733#define may_have_traps (G_misc.may_have_traps ) 789#define may_have_traps (G_misc.may_have_traps )
734#define trap (G_misc.trap ) 790#define trap (G_misc.trap )
735#define trap_ptr (G_misc.trap_ptr ) 791#define trap_ptr (G_misc.trap_ptr )
792#define commandname (G_misc.commandname)
793#define g_parsefile (G_misc.g_parsefile )
794#define basepf (G_misc.basepf )
736#define main_handler (G_misc.main_handler ) 795#define main_handler (G_misc.main_handler )
737#define groupinfo (G_misc.groupinfo ) 796#define groupinfo (G_misc.groupinfo )
738#define random_gen (G_misc.random_gen ) 797#define random_gen (G_misc.random_gen )
@@ -750,6 +809,7 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc;
750 curdir = nullstr; \ 809 curdir = nullstr; \
751 physdir = nullstr; \ 810 physdir = nullstr; \
752 trap_ptr = trap; \ 811 trap_ptr = trap; \
812 g_parsefile = &basepf; \
753 groupinfo.euid = -1; \ 813 groupinfo.euid = -1; \
754 groupinfo.egid = -1; \ 814 groupinfo.egid = -1; \
755} while (0) 815} while (0)
@@ -819,74 +879,6 @@ reset_exception_handler(void)
819} 879}
820 880
821 881
822/* ============ Parser data */
823
824/*
825 * ash_vmsg() needs parsefile->fd, hence parsefile definition is moved up.
826 */
827struct strlist {
828 struct strlist *next;
829 char *text;
830};
831
832struct alias;
833
834struct strpush {
835 struct strpush *prev; /* preceding string on stack */
836 char *prev_string;
837 int prev_left_in_line;
838#if ENABLE_ASH_ALIAS
839 struct alias *ap; /* if push was associated with an alias */
840#endif
841 char *string; /* remember the string since it may change */
842
843 /* Delay freeing so we can stop nested aliases. */
844 struct strpush *spfree;
845
846 /* Remember last two characters for pungetc. */
847 int lastc[2];
848
849 /* Number of outstanding calls to pungetc. */
850 int unget;
851};
852
853/*
854 * The parsefile structure pointed to by the global variable parsefile
855 * contains information about the current file being read.
856 */
857struct parsefile {
858 struct parsefile *prev; /* preceding file on stack */
859 int linno; /* current line */
860 int pf_fd; /* file descriptor (or -1 if string) */
861 int left_in_line; /* number of chars left in this line */
862 int left_in_buffer; /* number of chars left in this buffer past the line */
863 char *next_to_pgetc; /* next char in buffer */
864 char *buf; /* input buffer */
865 struct strpush *strpush; /* for pushing strings at this level */
866 struct strpush basestrpush; /* so pushing one is fast */
867
868 /* Delay freeing so we can stop nested aliases. */
869 struct strpush *spfree;
870
871 /* Remember last two characters for pungetc. */
872 int lastc[2];
873
874 /* Number of outstanding calls to pungetc. */
875 int unget;
876
877#if ENABLE_PLATFORM_MINGW32
878 /* True if a trailing CR from a previous read was left unprocessed. */
879 int cr;
880#endif
881};
882
883static struct parsefile basepf; /* top level input file */
884static struct parsefile *g_parsefile = &basepf; /* current input file */
885#if ENABLE_PLATFORM_POSIX
886static char *commandname; /* currently executing command */
887#endif
888
889
890/* ============ Interrupts / exceptions */ 882/* ============ Interrupts / exceptions */
891 883
892static void exitshell(void) NORETURN; 884static void exitshell(void) NORETURN;
@@ -16196,11 +16188,13 @@ init(void)
16196{ 16188{
16197#if ENABLE_PLATFORM_MINGW32 16189#if ENABLE_PLATFORM_MINGW32
16198 int import = 0; 16190 int import = 0;
16199#else 16191#endif
16192
16200 /* we will never free this */ 16193 /* we will never free this */
16201 basepf.next_to_pgetc = basepf.buf = ckzalloc(IBUFSIZ); 16194 basepf.next_to_pgetc = basepf.buf = ckzalloc(IBUFSIZ);
16202 basepf.linno = 1; 16195 basepf.linno = 1;
16203 16196
16197#if !ENABLE_PLATFORM_MINGW32
16204 sigmode[SIGCHLD - 1] = S_DFL; /* ensure we install handler even if it is SIG_IGNed */ 16198 sigmode[SIGCHLD - 1] = S_DFL; /* ensure we install handler even if it is SIG_IGNed */
16205 setsignal(SIGCHLD); 16199 setsignal(SIGCHLD);
16206#endif 16200#endif
@@ -16463,10 +16457,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
16463#if ENABLE_PLATFORM_MINGW32 16457#if ENABLE_PLATFORM_MINGW32
16464 INIT_G_memstack(); 16458 INIT_G_memstack();
16465 16459
16466 /* from init() */
16467 basepf.next_to_pgetc = basepf.buf = ckzalloc(IBUFSIZ);
16468 basepf.linno = 1;
16469
16470 if (argc == 3 && !strcmp(argv[1], "--fs")) { 16460 if (argc == 3 && !strcmp(argv[1], "--fs")) {
16471 forkshell_init(argv[2]); 16461 forkshell_init(argv[2]);
16472 /* only reached in case of error */ 16462 /* only reached in case of error */
@@ -17326,6 +17316,8 @@ globals_misc_size(struct datasize ds)
17326#undef physdir 17316#undef physdir
17327#undef arg0 17317#undef arg0
17328#undef commandname 17318#undef commandname
17319#undef g_parsefile
17320#undef basepf
17329#undef nullstr 17321#undef nullstr
17330#undef trap 17322#undef trap
17331static struct globals_misc * 17323static struct globals_misc *
@@ -17354,6 +17346,8 @@ globals_misc_copy(void)
17354 new->trap[i] = nodeckstrdup(p->trap[i]); 17346 new->trap[i] = nodeckstrdup(p->trap[i]);
17355 SAVE_PTR(new->trap[i], xasprintf("trap[%d]", i), FREE); 17347 SAVE_PTR(new->trap[i], xasprintf("trap[%d]", i), FREE);
17356 } 17348 }
17349 new->g_parsefile = NULL;
17350 memset(&new->basepf, 0, sizeof(struct parsefile));
17357 return new; 17351 return new;
17358} 17352}
17359 17353
@@ -17685,6 +17679,11 @@ forkshell_init(const char *idstr)
17685 } 17679 }
17686 fs->gmp->trap_ptr = fs->gmp->trap; 17680 fs->gmp->trap_ptr = fs->gmp->trap;
17687 17681
17682 /* from init() */
17683 fs->gmp->basepf.next_to_pgetc = fs->gmp->basepf.buf = ckzalloc(IBUFSIZ);
17684 fs->gmp->basepf.linno = 1;
17685 fs->gmp->g_parsefile = &fs->gmp->basepf;
17686
17688 /* Set global variables */ 17687 /* Set global variables */
17689 ASSIGN_CONST_PTR(&ash_ptr_to_globals_misc, fs->gmp); 17688 ASSIGN_CONST_PTR(&ash_ptr_to_globals_misc, fs->gmp);
17690 ASSIGN_CONST_PTR(&ash_ptr_to_globals_var, fs->gvp); 17689 ASSIGN_CONST_PTR(&ash_ptr_to_globals_var, fs->gvp);