VirtualBox

Changeset 1167 in kBuild for trunk/src/kmk/w32


Ignore:
Timestamp:
Sep 30, 2007 9:37:09 AM (18 years ago)
Author:
bird
Message:

skip some unnecessary system calls during process creation and termination.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/w32/subproc/sub_proc.c

    r1166 r1167  
    4848} sub_process;
    4949
     50static long process_file_io_private(sub_process *pproc, BOOL fNeedToWait); /* bird */
     51
    5052/* keep track of children so we can implement a waitpid-like routine */
    5153static sub_process *proc_array[MAXIMUM_WAIT_OBJECTS];
     
    184186                 * Ouch! can't tell caller if this fails directly. Caller
    185187                 * will have to use process_last_err()
    186                  */
     188                 */
     189#ifdef KMK
     190                (void) process_file_io_private(pproc, FALSE);
     191#else
    187192                (void) process_file_io(pproc);
     193#endif
    188194                return ((HANDLE) pproc);
    189195        }
     
    353359        char *fname;
    354360        char *ext;
    355 
     361#ifdef KMK
     362        size_t exec_path_len;
     363
     364        /*
     365         * if there is an .exe extension there already, don't waste time here.
     366         * If .exe scripts become common, they can be handled in a CreateProcess
     367         * failure path instead of here.
     368         */
     369        exec_path_len = strlen(exec_path);
     370        if (    exec_path_len > 4
     371                &&      exec_path[exec_path_len - 4] == '.'
     372                &&  !stricmp(exec_path + exec_path_len - 3, "exe")){
     373                return((HANDLE)HFILE_ERROR);
     374        }
     375
     376        fname = malloc(exec_path_len + 5);
     377#else
    356378        fname = malloc(strlen(exec_path) + 5);
     379#endif
    357380        strcpy(fname, exec_path);
    358381        ext = fname + strlen(fname);
     
    525548         */
    526549        GetStartupInfo(&startInfo);
     550#ifndef KMK
    527551        startInfo.dwFlags = STARTF_USESTDHANDLES;
     552#endif
    528553        startInfo.lpReserved = 0;
    529554        startInfo.cbReserved2 = 0;
    530555        startInfo.lpReserved2 = 0;
    531556        startInfo.lpTitle = shell_name ? shell_name : exec_path;
     557#ifndef KMK
    532558        startInfo.hStdInput = (HANDLE)pproc->sv_stdin[1];
    533559        startInfo.hStdOutput = (HANDLE)pproc->sv_stdout[1];
    534560        startInfo.hStdError = (HANDLE)pproc->sv_stderr[1];
     561#else
     562        if (    pproc->sv_stdin[1]
     563                ||  pproc->sv_stdout[1]
     564                ||  pproc->sv_stderr[1]) {
     565                startInfo.dwFlags = STARTF_USESTDHANDLES;
     566                startInfo.hStdInput = (HANDLE)pproc->sv_stdin[1];
     567                startInfo.hStdOutput = (HANDLE)pproc->sv_stdout[1];
     568                startInfo.hStdError = (HANDLE)pproc->sv_stderr[1];
     569        } else {
     570                startInfo.dwFlags = 0;
     571                startInfo.hStdInput = 0;
     572                startInfo.hStdOutput = 0;
     573                startInfo.hStdError = 0;
     574        }
     575#endif
    535576
    536577        if (as_user) {
     
    568609
    569610        /* Close the halves of the pipes we don't need */
    570         CloseHandle((HANDLE)pproc->sv_stdin[1]);
    571         CloseHandle((HANDLE)pproc->sv_stdout[1]);
    572         CloseHandle((HANDLE)pproc->sv_stderr[1]);
    573         pproc->sv_stdin[1] = 0;
    574         pproc->sv_stdout[1] = 0;
    575         pproc->sv_stderr[1] = 0;
     611#ifndef KMK
     612        CloseHandle((HANDLE)pproc->sv_stdin[1]);
     613        CloseHandle((HANDLE)pproc->sv_stdout[1]);
     614        CloseHandle((HANDLE)pproc->sv_stderr[1]);
     615        pproc->sv_stdin[1] = 0;
     616        pproc->sv_stdout[1] = 0;
     617        pproc->sv_stderr[1] = 0;
     618#else
     619        if ((HANDLE)pproc->sv_stdin[1]) {
     620                CloseHandle((HANDLE)pproc->sv_stdin[1]);
     621                pproc->sv_stdin[1] = 0;
     622        }
     623        if ((HANDLE)pproc->sv_stdout[1]) {
     624                CloseHandle((HANDLE)pproc->sv_stdout[1]);
     625                pproc->sv_stdout[1] = 0;
     626        }
     627        if ((HANDLE)pproc->sv_stderr[1]) {
     628                CloseHandle((HANDLE)pproc->sv_stderr[1]);
     629                pproc->sv_stderr[1] = 0;
     630        }
     631#endif
    576632
    577633        free( command_line );
     
    842898{
    843899        sub_process *pproc;
    844         HANDLE childhand;
    845         DWORD wait_return;
    846         BOOL GetExitCodeResult;
    847         DWORD ierr;
    848 
    849900        if (proc == NULL)
    850901                pproc = process_wait_for_any_private();
     
    856907                return -1;
    857908
     909        return process_file_io_private(proc, TRUE);
     910}
     911
     912/* private function, avoid some kernel calls. (bird) */
     913static long
     914process_file_io_private(
     915        sub_process *pproc,
     916        BOOL fNeedToWait)
     917{
     918        HANDLE childhand;
     919        DWORD wait_return;
     920        BOOL GetExitCodeResult;
     921        DWORD ierr;
     922
    858923        childhand = (HANDLE) pproc->pid;
    859924
     
    877942
    878943        /*
    879          *  Wait for the child process to exit
    880          */
    881 
    882         wait_return = WaitForSingleObject(childhand, INFINITE);
    883 
    884         if (wait_return != WAIT_OBJECT_0) {
    885 /*              map_windows32_error_to_string(GetLastError());*/
    886                 pproc->last_err = GetLastError();
    887                 pproc->lerrno = E_SCALL;
    888                 goto done2;
     944         *  Wait for the child process to exit it we didn't do that already.
     945         */
     946        if (fNeedToWait) {
     947                wait_return = WaitForSingleObject(childhand, INFINITE);
     948                if (wait_return != WAIT_OBJECT_0) {
     949/*                      map_windows32_error_to_string(GetLastError());*/
     950                        pproc->last_err = GetLastError();
     951                        pproc->lerrno = E_SCALL;
     952                        goto done2;
     953                }
    889954        }
    890955
     
    12041269        char **envp)
    12051270{
     1271#ifndef KMK
    12061272  HANDLE hIn;
    12071273  HANDLE hOut;
    12081274  HANDLE hErr;
     1275#endif
    12091276  HANDLE hProcess;
    12101277
     
    12131280        return INVALID_HANDLE_VALUE;
    12141281  }
     1282#ifndef KMK
    12151283  if (DuplicateHandle(GetCurrentProcess(),
    12161284                      GetStdHandle(STD_INPUT_HANDLE),
     
    12511319
    12521320  hProcess = process_init_fd(hIn, hOut, hErr);
     1321#else
     1322  hProcess = process_init_fd(0, 0, 0);
     1323#endif /* !KMK */
    12531324
    12541325  if (process_begin(hProcess, argv, envp, argv[0], NULL)) {
     
    12591330    ((sub_process*) hProcess)->exit_code = process_last_err(hProcess);
    12601331
     1332#ifndef KMK
    12611333    /* close up unused handles */
    12621334    CloseHandle(hIn);
    12631335    CloseHandle(hOut);
    12641336    CloseHandle(hErr);
     1337#endif
    12651338  }
    12661339
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette