diff options
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/shell/ash.c b/shell/ash.c index dfdba9316..78d3d673d 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -9000,9 +9000,9 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
| 9000 | 9000 | ||
| 9001 | 9001 | ||
| 9002 | static 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 */ |
| 9004 | static void *funcblock; /* block to allocate function from */ | 9004 | static void *funcblock; /* block to allocate function from */ |
| 9005 | static char *funcstring; /* block to allocate strings from */ | 9005 | static char *funcstring_end; /* end of block to allocate strings from */ |
| 9006 | #if ENABLE_PLATFORM_MINGW32 | 9006 | #if ENABLE_PLATFORM_MINGW32 |
| 9007 | static int nodeptrcount; | 9007 | static int nodeptrcount; |
| 9008 | static char **nodeptr; | 9008 | static char **nodeptr; |
| @@ -9093,7 +9093,7 @@ calcsize(union node *n) | |||
| 9093 | IF_PLATFORM_MINGW32(nodeptrcount += 3); | 9093 | IF_PLATFORM_MINGW32(nodeptrcount += 3); |
| 9094 | break; | 9094 | break; |
| 9095 | case NFOR: | 9095 | case NFOR: |
| 9096 | funcstringsize += strlen(n->nfor.var) + 1; | 9096 | funcblocksize += SHELL_ALIGN(strlen(n->nfor.var) + 1); /* was funcstringsize += ... */ |
| 9097 | calcsize(n->nfor.body); | 9097 | calcsize(n->nfor.body); |
| 9098 | calcsize(n->nfor.args); | 9098 | calcsize(n->nfor.args); |
| 9099 | IF_PLATFORM_MINGW32(nodeptrcount += 3); | 9099 | IF_PLATFORM_MINGW32(nodeptrcount += 3); |
| @@ -9111,12 +9111,12 @@ calcsize(union node *n) | |||
| 9111 | break; | 9111 | break; |
| 9112 | case NDEFUN: | 9112 | case NDEFUN: |
| 9113 | calcsize(n->ndefun.body); | 9113 | calcsize(n->ndefun.body); |
| 9114 | funcstringsize += strlen(n->ndefun.text) + 1; | 9114 | funcblocksize += SHELL_ALIGN(strlen(n->ndefun.text) + 1); |
| 9115 | IF_PLATFORM_MINGW32(nodeptrcount += 2); | 9115 | IF_PLATFORM_MINGW32(nodeptrcount += 2); |
| 9116 | break; | 9116 | break; |
| 9117 | case NARG: | 9117 | case NARG: |
| 9118 | sizenodelist(n->narg.backquote); | 9118 | sizenodelist(n->narg.backquote); |
| 9119 | funcstringsize += strlen(n->narg.text) + 1; | 9119 | funcblocksize += SHELL_ALIGN(strlen(n->narg.text) + 1); /* was funcstringsize += ... */ |
| 9120 | calcsize(n->narg.next); | 9120 | calcsize(n->narg.next); |
| 9121 | IF_PLATFORM_MINGW32(nodeptrcount += 3); | 9121 | IF_PLATFORM_MINGW32(nodeptrcount += 3); |
| 9122 | break; | 9122 | break; |
| @@ -9154,13 +9154,12 @@ calcsize(union node *n) | |||
| 9154 | static char * | 9154 | static char * |
| 9155 | nodeckstrdup(const char *s) | 9155 | nodeckstrdup(const char *s) |
| 9156 | { | 9156 | { |
| 9157 | char *rtn = funcstring; | 9157 | #if ENABLE_PLATFORM_MINGW32 |
| 9158 | 9158 | if(!s) | |
| 9159 | if (!s) | ||
| 9160 | return NULL; | 9159 | return NULL; |
| 9161 | strcpy(funcstring, s); | 9160 | #endif |
| 9162 | funcstring += strlen(s) + 1; | 9161 | funcstring_end -= SHELL_ALIGN(strlen(s) + 1); |
| 9163 | return rtn; | 9162 | return strcpy(funcstring_end, s); |
| 9164 | } | 9163 | } |
| 9165 | 9164 | ||
| 9166 | static union node *copynode(union node *); | 9165 | static union node *copynode(union node *); |
| @@ -9320,15 +9319,15 @@ copyfunc(union node *n) | |||
| 9320 | size_t blocksize; | 9319 | size_t blocksize; |
| 9321 | 9320 | ||
| 9322 | funcblocksize = offsetof(struct funcnode, n); | 9321 | funcblocksize = offsetof(struct funcnode, n); |
| 9323 | funcstringsize = 0; | 9322 | /*funcstringsize = 0;*/ |
| 9324 | calcsize(n); | 9323 | calcsize(n); |
| 9325 | blocksize = funcblocksize; | 9324 | blocksize = funcblocksize; |
| 9326 | f = ckmalloc(blocksize + funcstringsize); | 9325 | f = ckzalloc(blocksize /* + funcstringsize */); |
| 9327 | funcblock = (char *) f + offsetof(struct funcnode, n); | 9326 | funcblock = (char *) f + offsetof(struct funcnode, n); |
| 9328 | funcstring = (char *) f + blocksize; | 9327 | funcstring_end = (char *) f + blocksize; |
| 9329 | IF_PLATFORM_MINGW32(nodeptr = NULL); | 9328 | IF_PLATFORM_MINGW32(nodeptr = NULL); |
| 9330 | copynode(n); | 9329 | copynode(n); |
| 9331 | f->count = 0; | 9330 | /* f->count = 0; - ckzalloc did it */ |
| 9332 | return f; | 9331 | return f; |
| 9333 | } | 9332 | } |
| 9334 | 9333 | ||
| @@ -15002,7 +15001,7 @@ spawn_forkshell(struct job *jp, struct forkshell *fs, int mode) | |||
| 15002 | * forkshell_prepare() and friends | 15001 | * forkshell_prepare() and friends |
| 15003 | * | 15002 | * |
| 15004 | * The sequence is as follows: | 15003 | * The sequence is as follows: |
| 15005 | * - funcblocksize, funcstringsize, nodeptrcount are initialized | 15004 | * - funcblocksize, nodeptrcount are initialized |
| 15006 | * - forkshell_size(fs) is called to calculate the exact memory needed | 15005 | * - forkshell_size(fs) is called to calculate the exact memory needed |
| 15007 | * - a new struct is allocated | 15006 | * - a new struct is allocated |
| 15008 | * - funcblock, funcstring, nodeptr are initialized from the new block | 15007 | * - funcblock, funcstring, nodeptr are initialized from the new block |
| @@ -15011,6 +15010,11 @@ spawn_forkshell(struct job *jp, struct forkshell *fs, int mode) | |||
| 15011 | * | 15010 | * |
| 15012 | * When this memory is mapped elsewhere, pointer fixup will be needed | 15011 | * When this memory is mapped elsewhere, pointer fixup will be needed |
| 15013 | */ | 15012 | */ |
| 15013 | static int align_len(const char *s) | ||
| 15014 | { | ||
| 15015 | return s ? SHELL_ALIGN(strlen(s)+1) : 0; | ||
| 15016 | } | ||
| 15017 | |||
| 15014 | #define SLIST_SIZE_BEGIN(name,type) \ | 15018 | #define SLIST_SIZE_BEGIN(name,type) \ |
| 15015 | static void \ | 15019 | static void \ |
| 15016 | name(type *p) \ | 15020 | name(type *p) \ |
| @@ -15048,7 +15052,7 @@ name(type *vp) \ | |||
| 15048 | * struct var | 15052 | * struct var |
| 15049 | */ | 15053 | */ |
| 15050 | SLIST_SIZE_BEGIN(var_size,struct var) | 15054 | SLIST_SIZE_BEGIN(var_size,struct var) |
| 15051 | funcstringsize += strlen(p->var_text) + 1; | 15055 | funcblocksize += align_len(p->var_text); |
| 15052 | nodeptrcount++; /* p->text */ | 15056 | nodeptrcount++; /* p->text */ |
| 15053 | SLIST_SIZE_END() | 15057 | SLIST_SIZE_END() |
| 15054 | 15058 | ||
| @@ -15063,7 +15067,7 @@ SLIST_COPY_END() | |||
| 15063 | * struct strlist | 15067 | * struct strlist |
| 15064 | */ | 15068 | */ |
| 15065 | SLIST_SIZE_BEGIN(strlist_size,struct strlist) | 15069 | SLIST_SIZE_BEGIN(strlist_size,struct strlist) |
| 15066 | funcstringsize += strlen(p->text) + 1; | 15070 | funcblocksize += align_len(p->text); |
| 15067 | nodeptrcount++; /* p->text */ | 15071 | nodeptrcount++; /* p->text */ |
| 15068 | SLIST_SIZE_END() | 15072 | SLIST_SIZE_END() |
| 15069 | 15073 | ||
| @@ -15159,7 +15163,7 @@ argv_size(char **p) | |||
| 15159 | { | 15163 | { |
| 15160 | while (p && *p) { | 15164 | while (p && *p) { |
| 15161 | funcblocksize += sizeof(char *); | 15165 | funcblocksize += sizeof(char *); |
| 15162 | funcstringsize += strlen(*p)+1; | 15166 | funcblocksize += align_len(*p); |
| 15163 | nodeptrcount++; | 15167 | nodeptrcount++; |
| 15164 | p++; | 15168 | p++; |
| 15165 | } | 15169 | } |
| @@ -15277,12 +15281,12 @@ static void | |||
| 15277 | globals_misc_size(struct globals_misc *p) | 15281 | globals_misc_size(struct globals_misc *p) |
| 15278 | { | 15282 | { |
| 15279 | funcblocksize += sizeof(struct globals_misc); | 15283 | funcblocksize += sizeof(struct globals_misc); |
| 15280 | funcstringsize += p->minusc ? strlen(p->minusc) + 1 : 1; | 15284 | funcblocksize += align_len(p->minusc); |
| 15281 | if (p->curdir != p->nullstr) | 15285 | if (p->curdir != p->nullstr) |
| 15282 | funcstringsize += strlen(p->curdir) + 1; | 15286 | funcblocksize += align_len(p->curdir); |
| 15283 | if (p->physdir != p->nullstr) | 15287 | if (p->physdir != p->nullstr) |
| 15284 | funcstringsize += strlen(p->physdir) + 1; | 15288 | funcblocksize += align_len(p->physdir); |
| 15285 | funcstringsize += strlen(p->arg0) + 1; | 15289 | funcblocksize += align_len(p->arg0); |
| 15286 | nodeptrcount += 4; /* minusc, curdir, physdir, arg0 */ | 15290 | nodeptrcount += 4; /* minusc, curdir, physdir, arg0 */ |
| 15287 | } | 15291 | } |
| 15288 | 15292 | ||
| @@ -15313,7 +15317,7 @@ forkshell_size(struct forkshell *fs) | |||
| 15313 | 15317 | ||
| 15314 | calcsize(fs->n); | 15318 | calcsize(fs->n); |
| 15315 | argv_size(fs->argv); | 15319 | argv_size(fs->argv); |
| 15316 | funcstringsize += (fs->string ? strlen(fs->string) : 0) + 1; | 15320 | funcblocksize += align_len(fs->string); |
| 15317 | strlist_size(fs->strlist); | 15321 | strlist_size(fs->strlist); |
| 15318 | 15322 | ||
| 15319 | nodeptrcount += 7; /* gvp, gmp, cmdtable, n, argv, string, strlist */ | 15323 | nodeptrcount += 7; /* gvp, gmp, cmdtable, n, argv, string, strlist */ |
| @@ -15356,10 +15360,9 @@ forkshell_prepare(struct forkshell *fs) | |||
| 15356 | */ | 15360 | */ |
| 15357 | nodeptrcount = 0; | 15361 | nodeptrcount = 0; |
| 15358 | funcblocksize = 0; | 15362 | funcblocksize = 0; |
| 15359 | funcstringsize = 0; | ||
| 15360 | forkshell_size(fs); | 15363 | forkshell_size(fs); |
| 15361 | size = sizeof(struct forkshell) + nodeptrcount*sizeof(char *) + | 15364 | size = sizeof(struct forkshell) + nodeptrcount*sizeof(char *) + |
| 15362 | funcblocksize + funcstringsize; | 15365 | funcblocksize; |
| 15363 | 15366 | ||
| 15364 | /* Allocate, initialize pointers */ | 15367 | /* Allocate, initialize pointers */ |
| 15365 | memset(&sa, 0, sizeof(sa)); | 15368 | memset(&sa, 0, sizeof(sa)); |
| @@ -15370,7 +15373,7 @@ forkshell_prepare(struct forkshell *fs) | |||
| 15370 | new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); | 15373 | new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); |
| 15371 | nodeptr = new->nodeptr; | 15374 | nodeptr = new->nodeptr; |
| 15372 | funcblock = (char *)nodeptr + (nodeptrcount+1)*sizeof(char *); | 15375 | funcblock = (char *)nodeptr + (nodeptrcount+1)*sizeof(char *); |
| 15373 | funcstring = (char *) funcblock + funcblocksize; | 15376 | funcstring_end = (char *)new + size; |
| 15374 | 15377 | ||
| 15375 | /* Now pack them all */ | 15378 | /* Now pack them all */ |
| 15376 | forkshell_copy(fs, new); | 15379 | forkshell_copy(fs, new); |
