diff options
author | Ron Yorston <rmy@pobox.com> | 2020-01-18 10:22:44 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-01-18 11:03:14 +0000 |
commit | fbdd9862764c4693d8d1c1825adbadc0abb3d5ce (patch) | |
tree | 5944474b3547deefb768b381d84606d8267aeffb | |
parent | a52570a15241be7378484a4d88a1099cb60aec1b (diff) | |
download | busybox-w32-fbdd9862764c4693d8d1c1825adbadc0abb3d5ce.tar.gz busybox-w32-fbdd9862764c4693d8d1c1825adbadc0abb3d5ce.tar.bz2 busybox-w32-fbdd9862764c4693d8d1c1825adbadc0abb3d5ce.zip |
ash: simplify MARK_PTR macro
The MARK_PTR macro was unnecessarily complex. Since the relocation
map is a fixed offset from the start of the forkshell structure we
can obtain a pointer to the flag corresponding to a given destination
pointer knowing just the pointer and the offset. Saves 324 bytes.
-rw-r--r-- | shell/ash.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c index 19babb80e..9f4e6a7cb 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -9280,9 +9280,9 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
9280 | static void *funcblock; /* block to allocate function from */ | 9280 | static void *funcblock; /* block to allocate function from */ |
9281 | static char *funcstring_end; /* end of block to allocate strings from */ | 9281 | static char *funcstring_end; /* end of block to allocate strings from */ |
9282 | #if ENABLE_PLATFORM_MINGW32 | 9282 | #if ENABLE_PLATFORM_MINGW32 |
9283 | static char *relocate; | 9283 | static int fs_size; |
9284 | static void *fs_start; | ||
9285 | # if FORKSHELL_DEBUG | 9284 | # if FORKSHELL_DEBUG |
9285 | static void *fs_start; | ||
9286 | static const char **annot; | 9286 | static const char **annot; |
9287 | # endif | 9287 | # endif |
9288 | #endif | 9288 | #endif |
@@ -9441,20 +9441,24 @@ static union node *copynode(union node *); | |||
9441 | #endif | 9441 | #endif |
9442 | 9442 | ||
9443 | #if ENABLE_PLATFORM_MINGW32 | 9443 | #if ENABLE_PLATFORM_MINGW32 |
9444 | # define MARK_PTR(dst,flag) {relocate[(char *)&dst - (char *)fs_start] = flag;} | 9444 | /* The relocation map is offset from the start of the forkshell data |
9445 | * block by 'fs_size' bytes. The flag relating to a particular destination | ||
9446 | * pointer is thus at (dst+fs_size). */ | ||
9447 | # define MARK_PTR(dst,flag) {*((char *)&dst + fs_size) = flag;} | ||
9448 | |||
9445 | # define SAVE_PTR(dst,note,flag) { \ | 9449 | # define SAVE_PTR(dst,note,flag) { \ |
9446 | if (relocate) { \ | 9450 | if (fs_size) { \ |
9447 | MARK_PTR(dst,flag); ANNOT(dst,note); \ | 9451 | MARK_PTR(dst,flag); ANNOT(dst,note); \ |
9448 | } \ | 9452 | } \ |
9449 | } | 9453 | } |
9450 | # define SAVE_PTR2(dst1,note1,flag1,dst2,note2,flag2) { \ | 9454 | # define SAVE_PTR2(dst1,note1,flag1,dst2,note2,flag2) { \ |
9451 | if (relocate) { \ | 9455 | if (fs_size) { \ |
9452 | MARK_PTR(dst1,flag1); MARK_PTR(dst2,flag2); \ | 9456 | MARK_PTR(dst1,flag1); MARK_PTR(dst2,flag2); \ |
9453 | ANNOT(dst1,note1); ANNOT(dst2,note2); \ | 9457 | ANNOT(dst1,note1); ANNOT(dst2,note2); \ |
9454 | } \ | 9458 | } \ |
9455 | } | 9459 | } |
9456 | # define SAVE_PTR3(dst1,note1,flag1,dst2,note2,flag2,dst3,note3,flag3) { \ | 9460 | # define SAVE_PTR3(dst1,note1,flag1,dst2,note2,flag2,dst3,note3,flag3) { \ |
9457 | if (relocate) { \ | 9461 | if (fs_size) { \ |
9458 | MARK_PTR(dst1,flag1); MARK_PTR(dst2,flag2); MARK_PTR(dst3,flag3); \ | 9462 | MARK_PTR(dst1,flag1); MARK_PTR(dst2,flag2); MARK_PTR(dst3,flag3); \ |
9459 | ANNOT(dst1,note1); ANNOT(dst2,note2); ANNOT(dst3,note3); \ | 9463 | ANNOT(dst1,note1); ANNOT(dst2,note2); ANNOT(dst3,note3); \ |
9460 | } \ | 9464 | } \ |
@@ -9633,7 +9637,7 @@ copyfunc(union node *n) | |||
9633 | f = ckzalloc(blocksize /* + funcstringsize */); | 9637 | f = ckzalloc(blocksize /* + funcstringsize */); |
9634 | funcblock = (char *) f + offsetof(struct funcnode, n); | 9638 | funcblock = (char *) f + offsetof(struct funcnode, n); |
9635 | funcstring_end = (char *) f + blocksize; | 9639 | funcstring_end = (char *) f + blocksize; |
9636 | IF_PLATFORM_MINGW32(relocate = NULL); | 9640 | IF_PLATFORM_MINGW32(fs_size = 0); |
9637 | copynode(n); | 9641 | copynode(n); |
9638 | /* f->count = 0; - ckzalloc did it */ | 9642 | /* f->count = 0; - ckzalloc did it */ |
9639 | return f; | 9643 | return f; |
@@ -16054,6 +16058,7 @@ forkshell_prepare(struct forkshell *fs) | |||
16054 | HANDLE h; | 16058 | HANDLE h; |
16055 | SECURITY_ATTRIBUTES sa; | 16059 | SECURITY_ATTRIBUTES sa; |
16056 | #if FORKSHELL_DEBUG | 16060 | #if FORKSHELL_DEBUG |
16061 | char *relocate; | ||
16057 | char name[32]; | 16062 | char name[32]; |
16058 | FILE *fp; | 16063 | FILE *fp; |
16059 | #endif | 16064 | #endif |
@@ -16083,10 +16088,12 @@ forkshell_prepare(struct forkshell *fs) | |||
16083 | 16088 | ||
16084 | /* Initialise pointers */ | 16089 | /* Initialise pointers */ |
16085 | new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); | 16090 | new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); |
16086 | fs_start = new; | 16091 | fs_size = size; |
16087 | funcblock = (char *)(new + 1); | 16092 | funcblock = (char *)(new + 1); |
16088 | funcstring_end = relocate = (char *)new + size; | 16093 | funcstring_end = (char *)new + size; |
16089 | #if FORKSHELL_DEBUG | 16094 | #if FORKSHELL_DEBUG |
16095 | fs_start = new; | ||
16096 | relocate = (char *)new + size; | ||
16090 | annot = (const char **)xzalloc(sizeof(char *)*relocatesize); | 16097 | annot = (const char **)xzalloc(sizeof(char *)*relocatesize); |
16091 | #endif | 16098 | #endif |
16092 | 16099 | ||