Ignore:
Timestamp:
Sep 14, 2010, 2:30:30 AM (15 years ago)
Author:
bird
Message:

kash: implemented opendir/readdir/closedir for windows (NT). Fixed windows forking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/shfork-win.c

    r2377 r2416  
    66#include <string.h>
    77#include <locale.h>
     8#include <assert.h>
    89#include "shinstance.h"
    910#include <Windows.h>
     
    2930
    3031/* in shforkA-win.asm: */
     32extern pid_t shfork_do_it(shinstance *psh);
    3133extern void shfork_resume(void *cur, void *base, void *limit);
    3234
     
    3436void *shfork_maybe_forked(int argc, char **argv, char **envp);
    3537extern int shfork_body(shinstance *psh, void *stack_ptr);
    36 
    37 
    38 /***
     38extern void init_syntax(void);
     39
     40
     41/**
    3942 * Called by shforkA-win.asm to check whether we're a forked child
    4043 * process or not.
     
    6467    {
    6568        char *stack;
    66         shheap_init();
    67         stack = (char *)sh_malloc(NULL, SHFORK_STACK_SIZE) + SHFORK_STACK_SIZE;
    68         g_stack_base = stack + SHFORK_STACK_SIZE;
    69         g_stack_limit = stack;
     69        shheap_init(NULL);
     70        g_stack_limit = stack = (char *)sh_malloc(NULL, SHFORK_STACK_SIZE);
     71        g_stack_base = stack += SHFORK_STACK_SIZE;
    7072        return stack;
    7173    }
     
    8385    g_stack_base  = shfork_string_to_ptr(argv[5], argv[0], "--stack-base");
    8486    g_stack_limit = shfork_string_to_ptr(argv[7], argv[0], "--stack-limit");
     87    assert((uintptr_t)stack_ptr < (uintptr_t)g_stack_base);
     88    assert((uintptr_t)stack_ptr > (uintptr_t)g_stack_limit);
    8589
    8690    /*
     
    137141}
    138142
    139 /***
     143/**
     144 * Do the fork.
     145 * @returns same as fork().
     146 * @param   psh             The shell that's forking.
     147 */
     148int shfork_do(shinstance *psh)
     149{
     150    /* save globals */
     151    void *pheap_head = shheap_get_head();
     152    pid_t pid = shfork_do_it(psh);
     153    if (pid == 0)
     154    {
     155        /* reinit stuff, only the heap is copied! */
     156        shthread_set_shell(psh);
     157        shheap_init(pheap_head);
     158        setlocale(LC_ALL, "");
     159        init_syntax();
     160    }
     161    return pid;
     162}
     163
     164/**
    140165 * Create the child process making sure it inherits all our handles,
    141166 * copy of the forkable heap and kick it off.
     
    156181    DWORD cch;
    157182    int rc = 0;
     183
     184    assert((uintptr_t)stack_ptr < (uintptr_t)g_stack_base);
     185    assert((uintptr_t)stack_ptr > (uintptr_t)g_stack_limit);
    158186
    159187    /*
     
    178206                       stack_ptr, g_stack_base, g_stack_limit);
    179207        szCmdLine[cch+1] = '\0';
     208        TRACE2((NULL, "shfork_body: szCmdLine=%s\n", szCmdLine));
    180209
    181210        memset(&StrtInfo, '\0', sizeof(StrtInfo)); /* just in case. */
Note: See TracChangeset for help on using the changeset viewer.