diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-14 00:59:32 +0200 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-20 19:14:49 +0200 |
commit | 0a871637121709f44fbc006790dc84ef7a086c5a (patch) | |
tree | 2f755ebbce2ccb1328d0b8e7a690192ac415f08d /shell | |
parent | a5a032b052f026adfa9465325e9ee4d06d6bcd98 (diff) | |
download | busybox-w32-0a871637121709f44fbc006790dc84ef7a086c5a.tar.gz busybox-w32-0a871637121709f44fbc006790dc84ef7a086c5a.tar.bz2 busybox-w32-0a871637121709f44fbc006790dc84ef7a086c5a.zip |
win32: ash: forkshell_prepare()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c index a9a900bfd..8802c1315 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -13171,6 +13171,14 @@ static short profile_buf[16384]; | |||
13171 | extern int etext(); | 13171 | extern int etext(); |
13172 | #endif | 13172 | #endif |
13173 | 13173 | ||
13174 | #if ENABLE_PLATFORM_MINGW32 | ||
13175 | static const forkpoint_fn forkpoints[] = { | ||
13176 | NULL | ||
13177 | }; | ||
13178 | |||
13179 | static struct forkshell* forkshell_prepare(struct forkshell *fs); | ||
13180 | #endif | ||
13181 | |||
13174 | /* | 13182 | /* |
13175 | * Main routine. We initialize things, parse the arguments, execute | 13183 | * Main routine. We initialize things, parse the arguments, execute |
13176 | * profiles if we're a login shell, and then call cmdloop to execute | 13184 | * profiles if we're a login shell, and then call cmdloop to execute |
@@ -13314,6 +13322,16 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13314 | 13322 | ||
13315 | /* | 13323 | /* |
13316 | * forkshell_prepare() and friends | 13324 | * forkshell_prepare() and friends |
13325 | * | ||
13326 | * The sequence is as follows: | ||
13327 | * - funcblocksize, funcstringsize, nodeptrsize are initialized | ||
13328 | * - forkshell_size(fs) is called to calculate the exact memory needed | ||
13329 | * - a new struct is allocated | ||
13330 | * - funcblock, funcstring, nodeptr are initialized from the new block | ||
13331 | * - forkshell_copy(fs) is called to copy recursively everything over | ||
13332 | * it will record all pointers along the way, to nodeptr | ||
13333 | * | ||
13334 | * When this memory is mapped elsewhere, pointer fixup will be needed | ||
13317 | */ | 13335 | */ |
13318 | #define SLIST_SIZE_BEGIN(name,type) \ | 13336 | #define SLIST_SIZE_BEGIN(name,type) \ |
13319 | static void \ | 13337 | static void \ |
@@ -13675,6 +13693,58 @@ forkshell_copy(struct forkshell *fs) | |||
13675 | SAVE_PTR4(new->n, new->argv, new->string, new->strlist); | 13693 | SAVE_PTR4(new->n, new->argv, new->string, new->strlist); |
13676 | return new; | 13694 | return new; |
13677 | } | 13695 | } |
13696 | |||
13697 | static struct forkshell * | ||
13698 | forkshell_prepare(struct forkshell *fs) | ||
13699 | { | ||
13700 | struct forkshell *new; | ||
13701 | int size, fp, nodeptr_offset; | ||
13702 | HANDLE h; | ||
13703 | SECURITY_ATTRIBUTES sa; | ||
13704 | |||
13705 | for (fp = 0; forkpoints[fp] && forkpoints[fp] != fs->fp; fp++) | ||
13706 | ; | ||
13707 | |||
13708 | if (!forkpoints[fp]) | ||
13709 | bb_error_msg_and_die("invalid forkpoint %08x", (int)fs->fp); | ||
13710 | fs->fpid = fp; | ||
13711 | |||
13712 | /* Calculate size of "new" */ | ||
13713 | fs->gvp = ash_ptr_to_globals_var; | ||
13714 | fs->gmp = ash_ptr_to_globals_misc; | ||
13715 | fs->cmdtable = cmdtable; | ||
13716 | fs->localvars = localvars; | ||
13717 | |||
13718 | nodeptrsize = 1; /* NULL terminated */ | ||
13719 | funcblocksize = 0; | ||
13720 | funcstringsize = 0; | ||
13721 | forkshell_size(fs); | ||
13722 | size = funcblocksize + funcstringsize + nodeptrsize*sizeof(int); | ||
13723 | |||
13724 | /* Allocate, initialize pointers */ | ||
13725 | memset(&sa, 0, sizeof(sa)); | ||
13726 | sa.nLength = sizeof(sa); | ||
13727 | sa.lpSecurityDescriptor = NULL; | ||
13728 | sa.bInheritHandle = TRUE; | ||
13729 | h = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, size, NULL); | ||
13730 | new = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0); | ||
13731 | /* new = ckmalloc(size); */ | ||
13732 | funcblock = new; | ||
13733 | funcstring = (char *) funcblock + funcblocksize; | ||
13734 | nodeptr = (int*)((char *) funcstring + funcstringsize); | ||
13735 | nodeptr_offset = (int) nodeptr - (int) new; | ||
13736 | |||
13737 | /* Now pack them all */ | ||
13738 | forkshell_copy(fs); | ||
13739 | |||
13740 | /* Finish it up */ | ||
13741 | *nodeptr = 0; | ||
13742 | new->size = size; | ||
13743 | new->nodeptr_offset = nodeptr_offset; | ||
13744 | new->old_base = new; | ||
13745 | new->hMapFile = h; | ||
13746 | return new; | ||
13747 | } | ||
13678 | /*- | 13748 | /*- |
13679 | * Copyright (c) 1989, 1991, 1993, 1994 | 13749 | * Copyright (c) 1989, 1991, 1993, 1994 |
13680 | * The Regents of the University of California. All rights reserved. | 13750 | * The Regents of the University of California. All rights reserved. |