Mercurial > hg > xemacs-beta
diff src/process-nt.c @ 371:cc15677e0335 r21-2b1
Import from CVS: tag r21-2b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:03:08 +0200 |
parents | 972bbb6d6ca2 |
children | 6240c7796c7a |
line wrap: on
line diff
--- a/src/process-nt.c Mon Aug 13 11:01:58 2007 +0200 +++ b/src/process-nt.c Mon Aug 13 11:03:08 2007 +0200 @@ -39,9 +39,6 @@ #include <winsock.h> #endif -/* Arbitrary size limit for code fragments passed to run_in_other_process */ -#define FRAGMENT_CODE_SIZE 32 - /* Bound by winnt.el */ Lisp_Object Qnt_quote_process_args; @@ -146,8 +143,8 @@ /* * Run ROUTINE in the context of process determined by H_PROCESS. The - * routine is passed the address of DATA as parameter. The ROUTINE must - * not be longer than ROUTINE_CODE_SIZE bytes. DATA_SIZE is the size of + * routine is passed the address of DATA as parameter. CODE_END is the + * address immediately after ROUTINE's code. DATA_SIZE is the size of * DATA structure. * * Note that the code must be positionally independent, and compiled @@ -160,11 +157,11 @@ */ static DWORD run_in_other_process (HANDLE h_process, - LPTHREAD_START_ROUTINE routine, + LPTHREAD_START_ROUTINE routine, LPVOID code_end, LPVOID data, size_t data_size) { process_memory pm; - CONST size_t code_size = FRAGMENT_CODE_SIZE; + size_t code_size = (LPBYTE)code_end - (LPBYTE)routine; /* Need at most 3 extra bytes of memory, for data alignment */ size_t total_size = code_size + data_size + 3; LPVOID remote_data; @@ -226,11 +223,6 @@ * SIGKILL, SIGTERM, SIGQUIT, SIGHUP - These four translate to ExitProcess * executed by the remote process * SIGINT - The remote process is sent CTRL_BREAK_EVENT - * - * The MSVC5.0 compiler feels free to re-order functions within a - * compilation unit, so we have no way of finding out the size of the - * following functions. Therefore these functions must not be larger than - * FRAGMENT_CODE_SIZE. */ /* @@ -248,6 +240,12 @@ return 1; } +/* Watermark in code space */ +static void +sigkill_code_end (void) +{ +} + /* * Sending break or control c */ @@ -263,6 +261,12 @@ return (*data->adr_GenerateConsoleCtrlEvent) (data->event, 0); } +/* Watermark in code space */ +static void +sigint_code_end (void) +{ +} + /* * Enabling signals */ @@ -278,6 +282,12 @@ return 1; } +/* Watermark in code space */ +static void +sig_enable_code_end (void) +{ +} + /* * Send signal SIGNO to process H_PROCESS. * Return nonzero if successful. @@ -306,7 +316,8 @@ sigkill_data d; d.adr_ExitProcess = GetProcAddress (h_kernel, "ExitProcess"); assert (d.adr_ExitProcess); - retval = run_in_other_process (h_process, sigkill_proc, + retval = run_in_other_process (h_process, + sigkill_proc, sigkill_code_end, &d, sizeof (d)); break; } @@ -317,7 +328,8 @@ GetProcAddress (h_kernel, "GenerateConsoleCtrlEvent"); assert (d.adr_GenerateConsoleCtrlEvent); d.event = CTRL_C_EVENT; - retval = run_in_other_process (h_process, sigint_proc, + retval = run_in_other_process (h_process, + sigint_proc, sigint_code_end, &d, sizeof (d)); break; } @@ -341,7 +353,8 @@ d.adr_SetConsoleCtrlHandler = GetProcAddress (h_kernel, "SetConsoleCtrlHandler"); assert (d.adr_SetConsoleCtrlHandler); - run_in_other_process (h_process, sig_enable_proc, + run_in_other_process (h_process, + sig_enable_proc, sig_enable_code_end, &d, sizeof (d)); } @@ -403,6 +416,8 @@ * must signal an error instead. */ +/* #### This function completely ignores Vprocess_environment */ + static void signal_cannot_launch (Lisp_Object image_file, DWORD err) { @@ -415,10 +430,9 @@ Lisp_Object *argv, int nargv, Lisp_Object program, Lisp_Object cur_dir) { - HANDLE hmyshove, hmyslurp, hprocin, hprocout, hprocerr; + HANDLE hmyshove, hmyslurp, hprocin, hprocout; LPTSTR command_line; BOOL do_io, windowed; - char *proc_env; /* Find out whether the application is windowed or not */ { @@ -466,10 +480,6 @@ CreatePipe (&hprocin, &hmyshove, &sa, 0); CreatePipe (&hmyslurp, &hprocout, &sa, 0); - /* Duplicate the stdout handle for use as stderr */ - DuplicateHandle(GetCurrentProcess(), hprocout, GetCurrentProcess(), &hprocerr, - 0, TRUE, DUPLICATE_SAME_ACCESS); - /* Stupid Win32 allows to create a pipe with *both* ends either inheritable or not. We need process ends inheritable, and local ends not inheritable. */ @@ -510,80 +520,6 @@ UNGCPRO; /* args_or_ret */ } - /* Set `proc_env' to a nul-separated array of the strings in - Vprocess_environment terminated by 2 nuls. */ - - { - extern int compare_env (const char **strp1, const char **strp2); - char **env; - REGISTER Lisp_Object tem; - REGISTER char **new_env; - REGISTER int new_length = 0, i, new_space; - char *penv; - - for (tem = Vprocess_environment; - (CONSP (tem) - && STRINGP (XCAR (tem))); - tem = XCDR (tem)) - new_length++; - - /* new_length + 1 to include terminating 0. */ - env = new_env = alloca_array (char *, new_length + 1); - - /* Copy the Vprocess_environment strings into new_env. */ - for (tem = Vprocess_environment; - (CONSP (tem) - && STRINGP (XCAR (tem))); - tem = XCDR (tem)) - { - char **ep = env; - char *string = (char *) XSTRING_DATA (XCAR (tem)); - /* See if this string duplicates any string already in the env. - If so, don't put it in. - When an env var has multiple definitions, - we keep the definition that comes first in process-environment. */ - for (; ep != new_env; ep++) - { - char *p = *ep, *q = string; - while (1) - { - if (*q == 0) - /* The string is malformed; might as well drop it. */ - goto duplicate; - if (*q != *p) - break; - if (*q == '=') - goto duplicate; - p++, q++; - } - } - *new_env++ = string; - duplicate: ; - } - *new_env = 0; - - /* Sort the environment variables */ - new_length = new_env - env; - qsort (env, new_length, sizeof (char *), compare_env); - - /* Work out how much space to allocate */ - new_space = 0; - for (i = 0; i < new_length; i++) - { - new_space += strlen(env[i]) + 1; - } - new_space++; - - /* Allocate space and copy variables into it */ - penv = proc_env = alloca(new_space); - for (i = 0; i < new_length; i++) - { - strcpy(penv, env[i]); - penv += strlen(env[i]) + 1; - } - *penv = 0; - } - /* Create process */ { STARTUPINFO si; @@ -597,14 +533,14 @@ { si.hStdInput = hprocin; si.hStdOutput = hprocout; - si.hStdError = hprocerr; + si.hStdError = hprocout; si.dwFlags |= STARTF_USESTDHANDLES; } err = (CreateProcess (NULL, command_line, NULL, NULL, TRUE, CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP | CREATE_SUSPENDED, - proc_env, (char *) XSTRING_DATA (cur_dir), &si, &pi) + NULL, (char *) XSTRING_DATA (cur_dir), &si, &pi) ? 0 : GetLastError ()); if (do_io) @@ -612,7 +548,6 @@ /* These just have been inherited; we do not need a copy */ CloseHandle (hprocin); CloseHandle (hprocout); - CloseHandle (hprocerr); } /* Handle process creation failure */ @@ -699,14 +634,14 @@ /* use a reasonable-sized buffer (somewhere around the size of the stream buffer) so as to avoid inundating the stream with blocked data. */ - Bufbyte chunkbuf[128]; + Bufbyte chunkbuf[512]; Bytecount chunklen; while (1) { int writeret; - chunklen = Lstream_read (lstream, chunkbuf, 128); + chunklen = Lstream_read (lstream, chunkbuf, 512); if (chunklen <= 0) break; /* perhaps should abort() if < 0? This should never happen. */