aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-04-14 01:01:36 +0200
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-04-20 19:14:50 +0200
commit60d284141d301647e4fdfd0d6d0f792ba984df33 (patch)
treea53e9e85598ed872695886da987019f7fc8e657b /shell
parent5364221c96375acf96cf7914ef5be75eb174b7c1 (diff)
downloadbusybox-w32-60d284141d301647e4fdfd0d6d0f792ba984df33.tar.gz
busybox-w32-60d284141d301647e4fdfd0d6d0f792ba984df33.tar.bz2
busybox-w32-60d284141d301647e4fdfd0d6d0f792ba984df33.zip
win32: ash: forkshell_init()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c
index f320f26c3..767c095e7 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13178,6 +13178,7 @@ static const forkpoint_fn forkpoints[] = {
13178}; 13178};
13179 13179
13180static struct forkshell* forkshell_prepare(struct forkshell *fs); 13180static struct forkshell* forkshell_prepare(struct forkshell *fs);
13181static void forkshell_init(const char *idstr);
13181#endif 13182#endif
13182 13183
13183/* 13184/*
@@ -13247,6 +13248,15 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
13247 13248
13248 init(); 13249 init();
13249 setstackmark(&smark); 13250 setstackmark(&smark);
13251
13252#if ENABLE_PLATFORM_MINGW32
13253 if (argc == 3 && !strcmp(argv[1], "--forkshell")) {
13254 forkshell_init(argv[2]);
13255
13256 /* NOTREACHED */
13257 bb_error_msg_and_die("subshell ended unexpectedly");
13258 }
13259#endif
13250 procargs(argv); 13260 procargs(argv);
13251 13261
13252#if ENABLE_FEATURE_EDITING_SAVEHISTORY 13262#if ENABLE_FEATURE_EDITING_SAVEHISTORY
@@ -13769,6 +13779,64 @@ forkshell_prepare(struct forkshell *fs)
13769 new->hMapFile = h; 13779 new->hMapFile = h;
13770 return new; 13780 return new;
13771} 13781}
13782
13783#undef exception_handler
13784#undef trap
13785#undef trap_ptr
13786static void
13787forkshell_init(const char *idstr)
13788{
13789 struct forkshell *fs;
13790 int map_handle;
13791 HANDLE h;
13792 struct globals_var **gvpp;
13793 struct globals_misc **gmpp;
13794 int i;
13795
13796 if (sscanf(idstr, "%x", &map_handle) != 1)
13797 bb_error_msg_and_die("invalid forkshell ID");
13798
13799 h = (HANDLE)map_handle;
13800 fs = (struct forkshell *)MapViewOfFile(h, FILE_MAP_WRITE, 0,0, 0);
13801 if (!fs)
13802 bb_error_msg_and_die("Invalid forkshell memory");
13803
13804 /* pointer fixup */
13805 nodeptr = (int*)((char*)fs + fs->nodeptr_offset);
13806 while (*nodeptr) {
13807 int *ptr = (int*)((char*)fs + (*nodeptr - (int)fs->old_base));
13808 if (*ptr)
13809 *ptr -= ((int)fs->old_base - (int)fs);
13810 nodeptr++;
13811 }
13812 /* Now fix up stuff that can't be transferred */
13813 fs->fp = forkpoints[fs->fpid];
13814 for (i = 0; i < ARRAY_SIZE(varinit_data); i++)
13815 fs->gvp->varinit[i].func = varinit_data[i].func;
13816 for (i = 0; i < CMDTABLESIZE; i++) {
13817 struct tblentry *e = fs->cmdtable[i];
13818 while (e) {
13819 if (e->cmdtype == CMDBUILTIN)
13820 e->param.cmd = builtintab + (int)e->param.cmd;
13821 e = e->next;
13822 }
13823 }
13824 fs->gmp->exception_handler = ash_ptr_to_globals_misc->exception_handler;
13825 for (i = 0; i < NSIG; i++)
13826 fs->gmp->trap[i] = ash_ptr_to_globals_misc->trap[i];
13827 fs->gmp->trap_ptr = ash_ptr_to_globals_misc->trap_ptr;
13828
13829 /* Switch global variables */
13830 gvpp = (struct globals_var **)&ash_ptr_to_globals_var;
13831 *gvpp = fs->gvp;
13832 gmpp = (struct globals_misc **)&ash_ptr_to_globals_misc;
13833 *gmpp = fs->gmp;
13834 localvars = fs->localvars;
13835 cmdtable = fs->cmdtable;
13836
13837 fs->fp(fs);
13838}
13839
13772/*- 13840/*-
13773 * Copyright (c) 1989, 1991, 1993, 1994 13841 * Copyright (c) 1989, 1991, 1993, 1994
13774 * The Regents of the University of California. All rights reserved. 13842 * The Regents of the University of California. All rights reserved.