aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-04-01 17:06:38 +0100
committerRon Yorston <rmy@pobox.com>2018-04-01 17:06:38 +0100
commitf8199e24f095ccfe87a73217cfe1791f2c6c8e5a (patch)
tree0968e4ae94d0e97079c82942f3108bac72e0daa3
parentbd68ca428e2e94dcff651fef874576b94f4a3ed3 (diff)
downloadbusybox-w32-f8199e24f095ccfe87a73217cfe1791f2c6c8e5a.tar.gz
busybox-w32-f8199e24f095ccfe87a73217cfe1791f2c6c8e5a.tar.bz2
busybox-w32-f8199e24f095ccfe87a73217cfe1791f2c6c8e5a.zip
ash: align funcblocksize handling with upstream
Upstream BusyBox removed the global funcblocksize variable. Instead a local variable with the same name is passed to and returned from all functions that calculate item sizes. Do the same here.
-rw-r--r--shell/ash.c144
1 files changed, 76 insertions, 68 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 78d3d673d..ce2e6f92a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -8999,7 +8999,7 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
8999#endif 8999#endif
9000 9000
9001 9001
9002static int funcblocksize; /* size of structures in function */ 9002/*static int funcblocksize; // size of structures in function */
9003/*static int funcstringsize; // size of strings in node */ 9003/*static int funcstringsize; // size of strings in node */
9004static void *funcblock; /* block to allocate function from */ 9004static void *funcblock; /* block to allocate function from */
9005static char *funcstring_end; /* end of block to allocate strings from */ 9005static char *funcstring_end; /* end of block to allocate strings from */
@@ -9040,41 +9040,42 @@ static const uint8_t nodesize[N_NUMBER] ALIGN1 = {
9040 [NNOT ] = SHELL_ALIGN(sizeof(struct nnot)), 9040 [NNOT ] = SHELL_ALIGN(sizeof(struct nnot)),
9041}; 9041};
9042 9042
9043static void calcsize(union node *n); 9043static int calcsize(int funcblocksize, union node *n);
9044 9044
9045static void 9045static int
9046sizenodelist(struct nodelist *lp) 9046sizenodelist(int funcblocksize, struct nodelist *lp)
9047{ 9047{
9048 while (lp) { 9048 while (lp) {
9049 funcblocksize += SHELL_ALIGN(sizeof(struct nodelist)); 9049 funcblocksize += SHELL_ALIGN(sizeof(struct nodelist));
9050 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9050 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9051 calcsize(lp->n); 9051 funcblocksize = calcsize(funcblocksize, lp->n);
9052 lp = lp->next; 9052 lp = lp->next;
9053 } 9053 }
9054 return funcblocksize;
9054} 9055}
9055 9056
9056static void 9057static int
9057calcsize(union node *n) 9058calcsize(int funcblocksize, union node *n)
9058{ 9059{
9059 if (n == NULL) 9060 if (n == NULL)
9060 return; 9061 return funcblocksize;
9061 funcblocksize += nodesize[n->type]; 9062 funcblocksize += nodesize[n->type];
9062 switch (n->type) { 9063 switch (n->type) {
9063 case NCMD: 9064 case NCMD:
9064 calcsize(n->ncmd.redirect); 9065 funcblocksize = calcsize(funcblocksize, n->ncmd.redirect);
9065 calcsize(n->ncmd.args); 9066 funcblocksize = calcsize(funcblocksize, n->ncmd.args);
9066 calcsize(n->ncmd.assign); 9067 funcblocksize = calcsize(funcblocksize, n->ncmd.assign);
9067 IF_PLATFORM_MINGW32(nodeptrcount += 3); 9068 IF_PLATFORM_MINGW32(nodeptrcount += 3);
9068 break; 9069 break;
9069 case NPIPE: 9070 case NPIPE:
9070 sizenodelist(n->npipe.cmdlist); 9071 funcblocksize = sizenodelist(funcblocksize, n->npipe.cmdlist);
9071 IF_PLATFORM_MINGW32(nodeptrcount++); 9072 IF_PLATFORM_MINGW32(nodeptrcount++);
9072 break; 9073 break;
9073 case NREDIR: 9074 case NREDIR:
9074 case NBACKGND: 9075 case NBACKGND:
9075 case NSUBSHELL: 9076 case NSUBSHELL:
9076 calcsize(n->nredir.redirect); 9077 funcblocksize = calcsize(funcblocksize, n->nredir.redirect);
9077 calcsize(n->nredir.n); 9078 funcblocksize = calcsize(funcblocksize, n->nredir.n);
9078 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9079 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9079 break; 9080 break;
9080 case NAND: 9081 case NAND:
@@ -9082,42 +9083,42 @@ calcsize(union node *n)
9082 case NSEMI: 9083 case NSEMI:
9083 case NWHILE: 9084 case NWHILE:
9084 case NUNTIL: 9085 case NUNTIL:
9085 calcsize(n->nbinary.ch2); 9086 funcblocksize = calcsize(funcblocksize, n->nbinary.ch2);
9086 calcsize(n->nbinary.ch1); 9087 funcblocksize = calcsize(funcblocksize, n->nbinary.ch1);
9087 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9088 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9088 break; 9089 break;
9089 case NIF: 9090 case NIF:
9090 calcsize(n->nif.elsepart); 9091 funcblocksize = calcsize(funcblocksize, n->nif.elsepart);
9091 calcsize(n->nif.ifpart); 9092 funcblocksize = calcsize(funcblocksize, n->nif.ifpart);
9092 calcsize(n->nif.test); 9093 funcblocksize = calcsize(funcblocksize, n->nif.test);
9093 IF_PLATFORM_MINGW32(nodeptrcount += 3); 9094 IF_PLATFORM_MINGW32(nodeptrcount += 3);
9094 break; 9095 break;
9095 case NFOR: 9096 case NFOR:
9096 funcblocksize += SHELL_ALIGN(strlen(n->nfor.var) + 1); /* was funcstringsize += ... */ 9097 funcblocksize += SHELL_ALIGN(strlen(n->nfor.var) + 1); /* was funcstringsize += ... */
9097 calcsize(n->nfor.body); 9098 funcblocksize = calcsize(funcblocksize, n->nfor.body);
9098 calcsize(n->nfor.args); 9099 funcblocksize = calcsize(funcblocksize, n->nfor.args);
9099 IF_PLATFORM_MINGW32(nodeptrcount += 3); 9100 IF_PLATFORM_MINGW32(nodeptrcount += 3);
9100 break; 9101 break;
9101 case NCASE: 9102 case NCASE:
9102 calcsize(n->ncase.cases); 9103 funcblocksize = calcsize(funcblocksize, n->ncase.cases);
9103 calcsize(n->ncase.expr); 9104 funcblocksize = calcsize(funcblocksize, n->ncase.expr);
9104 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9105 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9105 break; 9106 break;
9106 case NCLIST: 9107 case NCLIST:
9107 calcsize(n->nclist.body); 9108 funcblocksize = calcsize(funcblocksize, n->nclist.body);
9108 calcsize(n->nclist.pattern); 9109 funcblocksize = calcsize(funcblocksize, n->nclist.pattern);
9109 calcsize(n->nclist.next); 9110 funcblocksize = calcsize(funcblocksize, n->nclist.next);
9110 IF_PLATFORM_MINGW32(nodeptrcount += 3); 9111 IF_PLATFORM_MINGW32(nodeptrcount += 3);
9111 break; 9112 break;
9112 case NDEFUN: 9113 case NDEFUN:
9113 calcsize(n->ndefun.body); 9114 funcblocksize = calcsize(funcblocksize, n->ndefun.body);
9114 funcblocksize += SHELL_ALIGN(strlen(n->ndefun.text) + 1); 9115 funcblocksize += SHELL_ALIGN(strlen(n->ndefun.text) + 1);
9115 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9116 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9116 break; 9117 break;
9117 case NARG: 9118 case NARG:
9118 sizenodelist(n->narg.backquote); 9119 funcblocksize = sizenodelist(funcblocksize, n->narg.backquote);
9119 funcblocksize += SHELL_ALIGN(strlen(n->narg.text) + 1); /* was funcstringsize += ... */ 9120 funcblocksize += SHELL_ALIGN(strlen(n->narg.text) + 1); /* was funcstringsize += ... */
9120 calcsize(n->narg.next); 9121 funcblocksize = calcsize(funcblocksize, n->narg.next);
9121 IF_PLATFORM_MINGW32(nodeptrcount += 3); 9122 IF_PLATFORM_MINGW32(nodeptrcount += 3);
9122 break; 9123 break;
9123 case NTO: 9124 case NTO:
@@ -9128,27 +9129,28 @@ calcsize(union node *n)
9128 case NFROM: 9129 case NFROM:
9129 case NFROMTO: 9130 case NFROMTO:
9130 case NAPPEND: 9131 case NAPPEND:
9131 calcsize(n->nfile.fname); 9132 funcblocksize = calcsize(funcblocksize, n->nfile.fname);
9132 calcsize(n->nfile.next); 9133 funcblocksize = calcsize(funcblocksize, n->nfile.next);
9133 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9134 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9134 break; 9135 break;
9135 case NTOFD: 9136 case NTOFD:
9136 case NFROMFD: 9137 case NFROMFD:
9137 calcsize(n->ndup.vname); 9138 funcblocksize = calcsize(funcblocksize, n->ndup.vname);
9138 calcsize(n->ndup.next); 9139 funcblocksize = calcsize(funcblocksize, n->ndup.next);
9139 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9140 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9140 break; 9141 break;
9141 case NHERE: 9142 case NHERE:
9142 case NXHERE: 9143 case NXHERE:
9143 calcsize(n->nhere.doc); 9144 funcblocksize = calcsize(funcblocksize, n->nhere.doc);
9144 calcsize(n->nhere.next); 9145 funcblocksize = calcsize(funcblocksize, n->nhere.next);
9145 IF_PLATFORM_MINGW32(nodeptrcount += 2); 9146 IF_PLATFORM_MINGW32(nodeptrcount += 2);
9146 break; 9147 break;
9147 case NNOT: 9148 case NNOT:
9148 calcsize(n->nnot.com); 9149 funcblocksize = calcsize(funcblocksize, n->nnot.com);
9149 IF_PLATFORM_MINGW32(nodeptrcount++); 9150 IF_PLATFORM_MINGW32(nodeptrcount++);
9150 break; 9151 break;
9151 }; 9152 };
9153 return funcblocksize;
9152} 9154}
9153 9155
9154static char * 9156static char *
@@ -9318,10 +9320,8 @@ copyfunc(union node *n)
9318 struct funcnode *f; 9320 struct funcnode *f;
9319 size_t blocksize; 9321 size_t blocksize;
9320 9322
9321 funcblocksize = offsetof(struct funcnode, n);
9322 /*funcstringsize = 0;*/ 9323 /*funcstringsize = 0;*/
9323 calcsize(n); 9324 blocksize = offsetof(struct funcnode, n) + calcsize(0, n);
9324 blocksize = funcblocksize;
9325 f = ckzalloc(blocksize /* + funcstringsize */); 9325 f = ckzalloc(blocksize /* + funcstringsize */);
9326 funcblock = (char *) f + offsetof(struct funcnode, n); 9326 funcblock = (char *) f + offsetof(struct funcnode, n);
9327 funcstring_end = (char *) f + blocksize; 9327 funcstring_end = (char *) f + blocksize;
@@ -15016,8 +15016,8 @@ static int align_len(const char *s)
15016} 15016}
15017 15017
15018#define SLIST_SIZE_BEGIN(name,type) \ 15018#define SLIST_SIZE_BEGIN(name,type) \
15019static void \ 15019static int \
15020name(type *p) \ 15020name(int funcblocksize, type *p) \
15021{ \ 15021{ \
15022 while (p) { \ 15022 while (p) { \
15023 funcblocksize += sizeof(type); 15023 funcblocksize += sizeof(type);
@@ -15026,6 +15026,7 @@ name(type *p) \
15026 nodeptrcount++; \ 15026 nodeptrcount++; \
15027 p = p->next; \ 15027 p = p->next; \
15028 } \ 15028 } \
15029 return funcblocksize; \
15029} 15030}
15030 15031
15031#define SLIST_COPY_BEGIN(name,type) \ 15032#define SLIST_COPY_BEGIN(name,type) \
@@ -15079,20 +15080,21 @@ SLIST_COPY_END()
15079/* 15080/*
15080 * struct tblentry 15081 * struct tblentry
15081 */ 15082 */
15082static void 15083static int
15083tblentry_size(struct tblentry *tep) 15084tblentry_size(int funcblocksize, struct tblentry *tep)
15084{ 15085{
15085 while (tep) { 15086 while (tep) {
15086 funcblocksize += sizeof(struct tblentry) + strlen(tep->cmdname); 15087 funcblocksize += sizeof(struct tblentry) + strlen(tep->cmdname);
15087 /* CMDBUILTIN, e->param.cmd needs no pointer relocation */ 15088 /* CMDBUILTIN, e->param.cmd needs no pointer relocation */
15088 if (tep->cmdtype == CMDFUNCTION) { 15089 if (tep->cmdtype == CMDFUNCTION) {
15089 funcblocksize += offsetof(struct funcnode, n); 15090 funcblocksize += offsetof(struct funcnode, n);
15090 calcsize(&tep->param.func->n); 15091 funcblocksize = calcsize(funcblocksize, &tep->param.func->n);
15091 nodeptrcount++; /* tep->param.func */ 15092 nodeptrcount++; /* tep->param.func */
15092 } 15093 }
15093 nodeptrcount++; /* tep->next */ 15094 nodeptrcount++; /* tep->next */
15094 tep = tep->next; 15095 tep = tep->next;
15095 } 15096 }
15097 return funcblocksize;
15096} 15098}
15097 15099
15098static struct tblentry * 15100static struct tblentry *
@@ -15131,14 +15133,15 @@ tblentry_copy(struct tblentry *tep)
15131 return start; 15133 return start;
15132} 15134}
15133 15135
15134static void 15136static int
15135cmdtable_size(struct tblentry **cmdtablep) 15137cmdtable_size(int funcblocksize, struct tblentry **cmdtablep)
15136{ 15138{
15137 int i; 15139 int i;
15138 nodeptrcount += CMDTABLESIZE; 15140 nodeptrcount += CMDTABLESIZE;
15139 funcblocksize += sizeof(struct tblentry *)*CMDTABLESIZE; 15141 funcblocksize += sizeof(struct tblentry *)*CMDTABLESIZE;
15140 for (i = 0; i < CMDTABLESIZE; i++) 15142 for (i = 0; i < CMDTABLESIZE; i++)
15141 tblentry_size(cmdtablep[i]); 15143 funcblocksize = tblentry_size(funcblocksize, cmdtablep[i]);
15144 return funcblocksize;
15142} 15145}
15143 15146
15144static struct tblentry ** 15147static struct tblentry **
@@ -15158,8 +15161,8 @@ cmdtable_copy(struct tblentry **cmdtablep)
15158/* 15161/*
15159 * char ** 15162 * char **
15160 */ 15163 */
15161static void 15164static int
15162argv_size(char **p) 15165argv_size(int funcblocksize, char **p)
15163{ 15166{
15164 while (p && *p) { 15167 while (p && *p) {
15165 funcblocksize += sizeof(char *); 15168 funcblocksize += sizeof(char *);
@@ -15168,6 +15171,7 @@ argv_size(char **p)
15168 p++; 15171 p++;
15169 } 15172 }
15170 funcblocksize += sizeof(char *); 15173 funcblocksize += sizeof(char *);
15174 return funcblocksize;
15171} 15175}
15172 15176
15173static char ** 15177static char **
@@ -15192,14 +15196,15 @@ argv_copy(char **p)
15192/* 15196/*
15193 * struct redirtab 15197 * struct redirtab
15194 */ 15198 */
15195static void 15199static int
15196redirtab_size(struct redirtab *rdtp) 15200redirtab_size(int funcblocksize, struct redirtab *rdtp)
15197{ 15201{
15198 while (rdtp) { 15202 while (rdtp) {
15199 funcblocksize += sizeof(*rdtp)+sizeof(rdtp->two_fd[0])*rdtp->pair_count; 15203 funcblocksize += sizeof(*rdtp)+sizeof(rdtp->two_fd[0])*rdtp->pair_count;
15200 rdtp = rdtp->next; 15204 rdtp = rdtp->next;
15201 nodeptrcount++; /* rdtp->next */ 15205 nodeptrcount++; /* rdtp->next */
15202 } 15206 }
15207 return funcblocksize;
15203} 15208}
15204 15209
15205static struct redirtab * 15210static struct redirtab *
@@ -15226,18 +15231,19 @@ redirtab_copy(struct redirtab *rdtp)
15226#undef redirlist 15231#undef redirlist
15227#undef varinit 15232#undef varinit
15228#undef vartab 15233#undef vartab
15229static void 15234static int
15230globals_var_size(struct globals_var *gvp) 15235globals_var_size(int funcblocksize, struct globals_var *gvp)
15231{ 15236{
15232 int i; 15237 int i;
15233 15238
15234 funcblocksize += sizeof(struct globals_var); 15239 funcblocksize += sizeof(struct globals_var);
15235 argv_size(gvp->shellparam.p); 15240 funcblocksize = argv_size(funcblocksize, gvp->shellparam.p);
15236 redirtab_size(gvp->redirlist); 15241 funcblocksize = redirtab_size(funcblocksize, gvp->redirlist);
15237 for (i = 0; i < VTABSIZE; i++) 15242 for (i = 0; i < VTABSIZE; i++)
15238 var_size(gvp->vartab[i]); 15243 funcblocksize = var_size(funcblocksize, gvp->vartab[i]);
15239 /* gvp->redirlist, gvp->shellparam.p, vartab */ 15244 /* gvp->redirlist, gvp->shellparam.p, vartab */
15240 nodeptrcount += 2 + VTABSIZE; 15245 nodeptrcount += 2 + VTABSIZE;
15246 return funcblocksize;
15241} 15247}
15242 15248
15243#undef preverrout_fd 15249#undef preverrout_fd
@@ -15277,8 +15283,8 @@ globals_var_copy(struct globals_var *gvp)
15277#undef physdir 15283#undef physdir
15278#undef arg0 15284#undef arg0
15279#undef nullstr 15285#undef nullstr
15280static void 15286static int
15281globals_misc_size(struct globals_misc *p) 15287globals_misc_size(int funcblocksize, struct globals_misc *p)
15282{ 15288{
15283 funcblocksize += sizeof(struct globals_misc); 15289 funcblocksize += sizeof(struct globals_misc);
15284 funcblocksize += align_len(p->minusc); 15290 funcblocksize += align_len(p->minusc);
@@ -15288,6 +15294,7 @@ globals_misc_size(struct globals_misc *p)
15288 funcblocksize += align_len(p->physdir); 15294 funcblocksize += align_len(p->physdir);
15289 funcblocksize += align_len(p->arg0); 15295 funcblocksize += align_len(p->arg0);
15290 nodeptrcount += 4; /* minusc, curdir, physdir, arg0 */ 15296 nodeptrcount += 4; /* minusc, curdir, physdir, arg0 */
15297 return funcblocksize;
15291} 15298}
15292 15299
15293static struct globals_misc * 15300static struct globals_misc *
@@ -15306,21 +15313,22 @@ globals_misc_copy(struct globals_misc *p)
15306 return new; 15313 return new;
15307} 15314}
15308 15315
15309static void 15316static int
15310forkshell_size(struct forkshell *fs) 15317forkshell_size(int funcblocksize, struct forkshell *fs)
15311{ 15318{
15312 globals_var_size(fs->gvp); 15319 funcblocksize = globals_var_size(funcblocksize, fs->gvp);
15313 globals_misc_size(fs->gmp); 15320 funcblocksize = globals_misc_size(funcblocksize, fs->gmp);
15314 cmdtable_size(fs->cmdtable); 15321 funcblocksize = cmdtable_size(funcblocksize, fs->cmdtable);
15315 /* optlist_transfer(sending, fd); */ 15322 /* optlist_transfer(sending, fd); */
15316 /* misc_transfer(sending, fd); */ 15323 /* misc_transfer(sending, fd); */
15317 15324
15318 calcsize(fs->n); 15325 funcblocksize = calcsize(funcblocksize, fs->n);
15319 argv_size(fs->argv); 15326 funcblocksize = argv_size(funcblocksize, fs->argv);
15320 funcblocksize += align_len(fs->string); 15327 funcblocksize += align_len(fs->string);
15321 strlist_size(fs->strlist); 15328 funcblocksize = strlist_size(funcblocksize, fs->strlist);
15322 15329
15323 nodeptrcount += 7; /* gvp, gmp, cmdtable, n, argv, string, strlist */ 15330 nodeptrcount += 7; /* gvp, gmp, cmdtable, n, argv, string, strlist */
15331 return funcblocksize;
15324} 15332}
15325 15333
15326static struct forkshell * 15334static struct forkshell *
@@ -15343,6 +15351,7 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new)
15343static struct forkshell * 15351static struct forkshell *
15344forkshell_prepare(struct forkshell *fs) 15352forkshell_prepare(struct forkshell *fs)
15345{ 15353{
15354 int funcblocksize;
15346 struct forkshell *new; 15355 struct forkshell *new;
15347 int size; 15356 int size;
15348 HANDLE h; 15357 HANDLE h;
@@ -15359,8 +15368,7 @@ forkshell_prepare(struct forkshell *fs)
15359 * The array in the forkshell structure gives us one element for free. 15368 * The array in the forkshell structure gives us one element for free.
15360 */ 15369 */
15361 nodeptrcount = 0; 15370 nodeptrcount = 0;
15362 funcblocksize = 0; 15371 funcblocksize = forkshell_size(0, fs);
15363 forkshell_size(fs);
15364 size = sizeof(struct forkshell) + nodeptrcount*sizeof(char *) + 15372 size = sizeof(struct forkshell) + nodeptrcount*sizeof(char *) +
15365 funcblocksize; 15373 funcblocksize;
15366 15374