aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-01-16 12:33:29 +0000
committerRon Yorston <rmy@pobox.com>2024-01-16 12:33:29 +0000
commitf27442f8e9a9a8ef706e2c0b4b0c15453f64e080 (patch)
tree9b34652ff3dbcaaca7ccfc635e59bf6d85743a31
parentbd49abf3eff91bbf93d05923df0227c5987cca1d (diff)
downloadbusybox-w32-f27442f8e9a9a8ef706e2c0b4b0c15453f64e080.tar.gz
busybox-w32-f27442f8e9a9a8ef706e2c0b4b0c15453f64e080.tar.bz2
busybox-w32-f27442f8e9a9a8ef706e2c0b4b0c15453f64e080.zip
ash: further reduce forkshell relocation block
Following on from commit c84b81ce4 (ash: reduce size of forkshell relocation block): - Store the flags to indicate if annotations should be freed in a separate array. This only affects builds with forkshell debug enabled. - Use a bitmap to indicate which pointers need relocation (instead of an array of bytes). This reduces the size of the forkshell data block by a few hundred bytes. Adds 32-64 bytes.
-rw-r--r--shell/ash.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 00018387c..3c57c4577 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9846,6 +9846,7 @@ static void *fs_start;
9846# if FORKSHELL_DEBUG 9846# if FORKSHELL_DEBUG
9847static void *fs_funcstring; 9847static void *fs_funcstring;
9848static const char **annot; 9848static const char **annot;
9849static char *annot_free;
9849# endif 9850# endif
9850#endif 9851#endif
9851 9852
@@ -9994,25 +9995,24 @@ static union node *copynode(union node *);
9994 9995
9995#if ENABLE_PLATFORM_MINGW32 9996#if ENABLE_PLATFORM_MINGW32
9996# if FORKSHELL_DEBUG 9997# if FORKSHELL_DEBUG
9997# define FREE 1
9998# define NO_FREE 2
9999# define MARK_PTR(dst,note,flag) forkshell_mark_ptr((void *)&dst, note, flag) 9998# define MARK_PTR(dst,note,flag) forkshell_mark_ptr((void *)&dst, note, flag)
10000# else 9999# else
10001# define FREE 1 10000# define MARK_PTR(dst,note,flag) forkshell_mark_ptr((void *)&dst)
10002# define NO_FREE 1
10003# define MARK_PTR(dst,note,flag) forkshell_mark_ptr((void *)&dst, flag)
10004# endif 10001# endif
10005 10002
10003#define NO_FREE 0
10004#define FREE 1
10005
10006#if FORKSHELL_DEBUG 10006#if FORKSHELL_DEBUG
10007static void forkshell_mark_ptr(void *dst, const char *note, int flag) 10007static void forkshell_mark_ptr(void *dst, const char *note, int flag)
10008#else 10008#else
10009static void forkshell_mark_ptr(void *dst, int flag) 10009static void forkshell_mark_ptr(void *dst)
10010#endif 10010#endif
10011{ 10011{
10012 char *lrelocate = (char *)fs_start + fs_size; 10012 char *lrelocate = (char *)fs_start + fs_size;
10013 int index = ((char *)dst - (char *)fs_start)/sizeof(char *); 10013 int index = ((char *)dst - (char *)fs_start)/sizeof(char *);
10014 10014
10015 lrelocate[index] = flag; 10015 lrelocate[index/8] |= 1 << (index % 8);
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) {
@@ -10025,6 +10025,7 @@ static void forkshell_mark_ptr(void *dst, int flag)
10025 annot[index], note); 10025 annot[index], note);
10026 } 10026 }
10027 annot[index] = note; 10027 annot[index] = note;
10028 annot_free[index] = flag;
10028 } 10029 }
10029#endif 10030#endif
10030} 10031}
@@ -17106,7 +17107,7 @@ forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes)
17106 char *lfuncstring; 17107 char *lfuncstring;
17107 char *lrelocate; 17108 char *lrelocate;
17108 char *s; 17109 char *s;
17109 int count, i, total; 17110 int count, i, total, bitmapsize;
17110 int size[NUM_BLOCKS]; 17111 int size[NUM_BLOCKS];
17111 char *lptr[NUM_BLOCKS+1]; 17112 char *lptr[NUM_BLOCKS+1];
17112 const char *fsname[] = { 17113 const char *fsname[] = {
@@ -17129,12 +17130,13 @@ forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes)
17129 return; 17130 return;
17130 } 17131 }
17131 17132
17133 bitmapsize = (fs->relocatesize + 7)/8;
17132 total = sizeof(struct forkshell) + fs->funcblocksize + 17134 total = sizeof(struct forkshell) + fs->funcblocksize +
17133 fs->funcstringsize + fs->relocatesize; 17135 fs->funcstringsize + bitmapsize;
17134 fprintf(fp, "total size %6d = %d + %d + %d + %d = %d\n", 17136 fprintf(fp, "total size %6d = %d + %d + %d + %d = %d\n",
17135 fs->size + fs->relocatesize, 17137 fs->size + bitmapsize,
17136 (int)sizeof(struct forkshell), fs->funcblocksize, 17138 (int)sizeof(struct forkshell), fs->funcblocksize,
17137 fs->funcstringsize, fs->relocatesize, total); 17139 fs->funcstringsize, bitmapsize, total);
17138 17140
17139 lfuncblock = (char *)(fs + 1); 17141 lfuncblock = (char *)(fs + 1);
17140 lfuncstring = (char *)lfuncblock + fs->funcblocksize; 17142 lfuncstring = (char *)lfuncblock + fs->funcblocksize;
@@ -17179,7 +17181,7 @@ forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes)
17179 fprintf(fp, "--- relocate ---\n"); 17181 fprintf(fp, "--- relocate ---\n");
17180 count = 0; 17182 count = 0;
17181 for (i = 0; i < fs->relocatesize; ++i) { 17183 for (i = 0; i < fs->relocatesize; ++i) {
17182 if (lrelocate[i]) { 17184 if (lrelocate[i/8] & (1 << i % 8)) {
17183 char **ptr = (char **)((char *)fs + i * sizeof(char *)); 17185 char **ptr = (char **)((char *)fs + i * sizeof(char *));
17184 fprintf(fp, "%p %p %s\n", ptr, *ptr, 17186 fprintf(fp, "%p %p %s\n", ptr, *ptr,
17185 notes && notes[i] ? notes[i] : ""); 17187 notes && notes[i] ? notes[i] : "");
@@ -17212,7 +17214,7 @@ forkshell_prepare(struct forkshell *fs)
17212{ 17214{
17213 struct forkshell *new; 17215 struct forkshell *new;
17214 struct datasize ds; 17216 struct datasize ds;
17215 int size, relocatesize; 17217 int size, relocatesize, bitmapsize;
17216 HANDLE h; 17218 HANDLE h;
17217 SECURITY_ATTRIBUTES sa; 17219 SECURITY_ATTRIBUTES sa;
17218#if FORKSHELL_DEBUG 17220#if FORKSHELL_DEBUG
@@ -17226,6 +17228,7 @@ forkshell_prepare(struct forkshell *fs)
17226 ds = forkshell_size(fs); 17228 ds = forkshell_size(fs);
17227 size = sizeof(struct forkshell) + ds.funcblocksize + ds.funcstringsize; 17229 size = sizeof(struct forkshell) + ds.funcblocksize + ds.funcstringsize;
17228 relocatesize = (sizeof(struct forkshell) + ds.funcblocksize)/sizeof(char *); 17230 relocatesize = (sizeof(struct forkshell) + ds.funcblocksize)/sizeof(char *);
17231 bitmapsize = (relocatesize + 7)/8;
17229 17232
17230 /* Allocate shared memory region */ 17233 /* Allocate shared memory region */
17231 memset(&sa, 0, sizeof(sa)); 17234 memset(&sa, 0, sizeof(sa));
@@ -17233,7 +17236,7 @@ forkshell_prepare(struct forkshell *fs)
17233 sa.lpSecurityDescriptor = NULL; 17236 sa.lpSecurityDescriptor = NULL;
17234 sa.bInheritHandle = TRUE; 17237 sa.bInheritHandle = TRUE;
17235 h = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, 17238 h = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0,
17236 size+relocatesize, NULL); 17239 size+bitmapsize, NULL);
17237 17240
17238 /* Initialise pointers */ 17241 /* Initialise pointers */
17239 new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); 17242 new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0);
@@ -17247,6 +17250,7 @@ forkshell_prepare(struct forkshell *fs)
17247 fs_funcstring = (char *)new + sizeof(struct forkshell) + ds.funcblocksize; 17250 fs_funcstring = (char *)new + sizeof(struct forkshell) + ds.funcblocksize;
17248 relocate = (char *)new + size; 17251 relocate = (char *)new + size;
17249 annot = (const char **)xzalloc(sizeof(char *)*relocatesize); 17252 annot = (const char **)xzalloc(sizeof(char *)*relocatesize);
17253 annot_free = xzalloc(relocatesize);
17250#endif 17254#endif
17251 17255
17252 /* Now pack them all */ 17256 /* Now pack them all */
@@ -17272,16 +17276,17 @@ forkshell_prepare(struct forkshell *fs)
17272 new->funcstringsize); 17276 new->funcstringsize);
17273 if ((char *)funcblock != funcstring_end) 17277 if ((char *)funcblock != funcstring_end)
17274 fprintf(fp, " funcstring != end funcblock + 1 %p\n", funcblock); 17278 fprintf(fp, " funcstring != end funcblock + 1 %p\n", funcblock);
17275 fprintf(fp, "relocate %p %6d\n\n", relocate, new->relocatesize); 17279 fprintf(fp, "relocate %p %6d\n\n", relocate, bitmapsize);
17276 17280
17277 forkshell_print(fp, new, annot); 17281 forkshell_print(fp, new, annot);
17278 17282
17279 for (i = 0; i < relocatesize; ++i) { 17283 for (i = 0; i < relocatesize; ++i) {
17280 if (relocate[i] == FREE) { 17284 if (annot_free[i]) {
17281 free((void *)annot[i]); 17285 free((void *)annot[i]);
17282 } 17286 }
17283 } 17287 }
17284 free(annot); 17288 free(annot);
17289 free(annot_free);
17285 annot = NULL; 17290 annot = NULL;
17286 fclose(fp); 17291 fclose(fp);
17287 } 17292 }
@@ -17316,7 +17321,7 @@ forkshell_init(const char *idstr)
17316 /* pointer fixup */ 17321 /* pointer fixup */
17317 lrelocate = (char *)fs + fs->size; 17322 lrelocate = (char *)fs + fs->size;
17318 for (i = 0; i < fs->relocatesize; i++) { 17323 for (i = 0; i < fs->relocatesize; i++) {
17319 if (lrelocate[i]) { 17324 if (lrelocate[i/8] & (1 << i % 8)) {
17320 ptr = (char **)((char *)fs + i * sizeof(char *)); 17325 ptr = (char **)((char *)fs + i * sizeof(char *));
17321 if (*ptr) 17326 if (*ptr)
17322 *ptr = (char *)fs + (*ptr - fs->old_base); 17327 *ptr = (char *)fs + (*ptr - fs->old_base);