aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-01-15 12:40:49 +0000
committerRon Yorston <rmy@pobox.com>2024-01-15 13:16:23 +0000
commitc84b81ce49d6032fba4d543ae4e484fa2d7432f9 (patch)
treea1c9033be9931322c453a0c3e115cdd79d7fa9ac
parent7b345e7e35a613fe2a947017c01341a25ef99752 (diff)
downloadbusybox-w32-c84b81ce49d6032fba4d543ae4e484fa2d7432f9.tar.gz
busybox-w32-c84b81ce49d6032fba4d543ae4e484fa2d7432f9.tar.bz2
busybox-w32-c84b81ce49d6032fba4d543ae4e484fa2d7432f9.zip
ash: reduce size of forkshell relocation block
The forkshell relocation block had one byte for each byte of the forkshell structure and funcblock. It's only necessary to allow one byte for each pointer. (One or two bits would be enough, but would make the code more complex.) The impact of this change depends on the data and whether the CPU is 32- or 64-bit. It typically saves a few Kbytes. Costs 16-52 bytes.
-rw-r--r--shell/ash.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 8a8f84a8f..00018387c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9842,8 +9842,8 @@ static void *funcblock; /* block to allocate function from */
9842static char *funcstring_end; /* end of block to allocate strings from */ 9842static char *funcstring_end; /* end of block to allocate strings from */
9843#if ENABLE_PLATFORM_MINGW32 9843#if ENABLE_PLATFORM_MINGW32
9844static int fs_size; 9844static int fs_size;
9845# if FORKSHELL_DEBUG
9846static void *fs_start; 9845static void *fs_start;
9846# if FORKSHELL_DEBUG
9847static void *fs_funcstring; 9847static void *fs_funcstring;
9848static const char **annot; 9848static const char **annot;
9849# endif 9849# endif
@@ -10009,10 +10009,10 @@ static void forkshell_mark_ptr(void *dst, const char *note, int flag)
10009static void forkshell_mark_ptr(void *dst, int flag) 10009static void forkshell_mark_ptr(void *dst, int flag)
10010#endif 10010#endif
10011{ 10011{
10012 /* The relocation map is offset from the start of the forkshell data 10012 char *lrelocate = (char *)fs_start + fs_size;
10013 * block by 'fs_size' bytes. The flag relating to a particular 10013 int index = ((char *)dst - (char *)fs_start)/sizeof(char *);
10014 * destination pointer is thus at (dst+fs_size). */ 10014
10015 *((char *)dst + fs_size) = flag; 10015 lrelocate[index] = flag;
10016 10016
10017#if FORKSHELL_DEBUG 10017#if FORKSHELL_DEBUG
10018 if (dst < fs_start || dst >= fs_funcstring) { 10018 if (dst < fs_start || dst >= fs_funcstring) {
@@ -10020,11 +10020,11 @@ static void forkshell_mark_ptr(void *dst, int flag)
10020 dst, fs_start, fs_funcstring); 10020 dst, fs_start, fs_funcstring);
10021 } 10021 }
10022 if (annot) { 10022 if (annot) {
10023 if (annot[(char *)dst - (char *)fs_start]) { 10023 if (annot[index]) {
10024 fprintf(stderr, "duplicate annotation: %s %s\n", 10024 fprintf(stderr, "duplicate annotation: %s %s\n",
10025 annot[(char *)dst - (char *)fs_start], note); 10025 annot[index], note);
10026 } 10026 }
10027 annot[(char *)dst - (char *)fs_start] = note; 10027 annot[index] = note;
10028 } 10028 }
10029#endif 10029#endif
10030} 10030}
@@ -17180,7 +17180,7 @@ forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes)
17180 count = 0; 17180 count = 0;
17181 for (i = 0; i < fs->relocatesize; ++i) { 17181 for (i = 0; i < fs->relocatesize; ++i) {
17182 if (lrelocate[i]) { 17182 if (lrelocate[i]) {
17183 char **ptr = (char **)((char *)fs + i); 17183 char **ptr = (char **)((char *)fs + i * sizeof(char *));
17184 fprintf(fp, "%p %p %s\n", ptr, *ptr, 17184 fprintf(fp, "%p %p %s\n", ptr, *ptr,
17185 notes && notes[i] ? notes[i] : ""); 17185 notes && notes[i] ? notes[i] : "");
17186 ++count; 17186 ++count;
@@ -17225,7 +17225,7 @@ forkshell_prepare(struct forkshell *fs)
17225 /* calculate size of structure, funcblock and funcstring */ 17225 /* calculate size of structure, funcblock and funcstring */
17226 ds = forkshell_size(fs); 17226 ds = forkshell_size(fs);
17227 size = sizeof(struct forkshell) + ds.funcblocksize + ds.funcstringsize; 17227 size = sizeof(struct forkshell) + ds.funcblocksize + ds.funcstringsize;
17228 relocatesize = sizeof(struct forkshell) + ds.funcblocksize; 17228 relocatesize = (sizeof(struct forkshell) + ds.funcblocksize)/sizeof(char *);
17229 17229
17230 /* Allocate shared memory region */ 17230 /* Allocate shared memory region */
17231 memset(&sa, 0, sizeof(sa)); 17231 memset(&sa, 0, sizeof(sa));
@@ -17240,10 +17240,10 @@ forkshell_prepare(struct forkshell *fs)
17240 if (new == NULL) 17240 if (new == NULL)
17241 return NULL; 17241 return NULL;
17242 fs_size = size; 17242 fs_size = size;
17243 fs_start = new;
17243 funcblock = (char *)(new + 1); 17244 funcblock = (char *)(new + 1);
17244 funcstring_end = (char *)new + size; 17245 funcstring_end = (char *)new + size;
17245#if FORKSHELL_DEBUG 17246#if FORKSHELL_DEBUG
17246 fs_start = new;
17247 fs_funcstring = (char *)new + sizeof(struct forkshell) + ds.funcblocksize; 17247 fs_funcstring = (char *)new + sizeof(struct forkshell) + ds.funcblocksize;
17248 relocate = (char *)new + size; 17248 relocate = (char *)new + size;
17249 annot = (const char **)xzalloc(sizeof(char *)*relocatesize); 17249 annot = (const char **)xzalloc(sizeof(char *)*relocatesize);
@@ -17317,7 +17317,7 @@ forkshell_init(const char *idstr)
17317 lrelocate = (char *)fs + fs->size; 17317 lrelocate = (char *)fs + fs->size;
17318 for (i = 0; i < fs->relocatesize; i++) { 17318 for (i = 0; i < fs->relocatesize; i++) {
17319 if (lrelocate[i]) { 17319 if (lrelocate[i]) {
17320 ptr = (char **)((char *)fs + i); 17320 ptr = (char **)((char *)fs + i * sizeof(char *));
17321 if (*ptr) 17321 if (*ptr)
17322 *ptr = (char *)fs + (*ptr - fs->old_base); 17322 *ptr = (char *)fs + (*ptr - fs->old_base);
17323 } 17323 }