annotate src/process-nt.c @ 340:497cb5bff1c4 xemacs-21-0

Added tag r21-0-67 for changeset 336b97f03633
author cvs
date Mon, 13 Aug 2007 10:51:28 +0200
parents 4f79e16b1112
children 182f72e8cd0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1 /* Asynchronous subprocess implemenation for Win32
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
5 Copyright (C) 1995, 1996 Ben Wing.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
6
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
7 This file is part of XEmacs.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
8
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
12 later version.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
13
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
17 for more details.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
18
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
23
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
24 /* Written by Kirill M. Katsnelson <kkm@kis.ru>, April 1998 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
25
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
26 #include <config.h>
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
27 #include "lisp.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
28
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
29 #include "hash.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
30 #include "lstream.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
31 #include "process.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
32 #include "procimpl.h"
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
33 #include "sysdep.h"
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
34
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
35 #include <windows.h>
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
36 #include <shellapi.h>
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
37 #include <signal.h>
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
38 #ifdef HAVE_SOCKETS
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
39 #include <winsock.h>
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
40 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
41
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
42 /* Arbitrary size limit for code fragments passed to run_in_other_process */
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
43 #define FRAGMENT_CODE_SIZE 32
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
44
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
45 /* Bound by winnt.el */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
46 Lisp_Object Qnt_quote_process_args;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
47
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
48 /* Implemenation-specific data. Pointed to by Lisp_Process->process_data */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
49 struct nt_process_data
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
50 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
51 HANDLE h_process;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
52 };
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
53
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
54 #define NT_DATA(p) ((struct nt_process_data*)((p)->process_data))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
55
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
56 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
57 /* Process helpers */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
58 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
59
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
60 /* This one breaks process abstraction. Prototype is in console-msw.h,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
61 used by select_process method in event-msw.c */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
62 HANDLE
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
63 get_nt_process_handle (struct Lisp_Process *p)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
64 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
65 return (NT_DATA (p)->h_process);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
66 }
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
67
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
68 /*-----------------------------------------------------------------------*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
69 /* Running remote threads. See Microsoft Systems Journal 1994 Number 5 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
70 /* Jeffrey Richter, Load Your 32-bit DLL into Another Process's Address..*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
71 /*-----------------------------------------------------------------------*/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
72
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
73 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
74 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
75 HANDLE h_process;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
76 HANDLE h_thread;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
77 LPVOID address;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
78 } process_memory;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
79
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
80 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
81 * Allocate SIZE bytes in H_PROCESS address space. Fill in PMC used
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
82 * further by other routines. Return nonzero if successful.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
83 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
84 * The memory in other process is allocated by creating a suspended
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
85 * thread. Initial stack of that thread is used as the memory
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
86 * block. The thread entry point is the routine ExitThread in
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
87 * kernel32.dll, so the allocated memory is freed just by resuming the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
88 * thread, which immediately terminates after that.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
89 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
90
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
91 static int
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
92 alloc_process_memory (HANDLE h_process, size_t size,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
93 process_memory* pmc)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
94 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
95 LPTHREAD_START_ROUTINE adr_ExitThread =
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
96 (LPTHREAD_START_ROUTINE)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
97 GetProcAddress (GetModuleHandle ("kernel32"), "ExitThread");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
98 DWORD dw_unused;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
99 CONTEXT context;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
100 MEMORY_BASIC_INFORMATION mbi;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
101
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
102 pmc->h_process = h_process;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
103 pmc->h_thread = CreateRemoteThread (h_process, NULL, size,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
104 adr_ExitThread, NULL,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
105 CREATE_SUSPENDED, &dw_unused);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
106 if (pmc->h_thread == NULL)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
107 return 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
108
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
109 /* Get context, for thread's stack pointer */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
110 context.ContextFlags = CONTEXT_CONTROL;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
111 if (!GetThreadContext (pmc->h_thread, &context))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
112 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
113
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
114 /* Determine base address of the committed range */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
115 if (sizeof(mbi) != VirtualQueryEx (h_process,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
116 #if defined (_X86_)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
117 (LPDWORD)context.Esp - 1,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
118 #elif defined (_ALPHA_)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
119 (LPDWORD)context.IntSp - 1,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
120 #else
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
121 #error Unknown processor architecture
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
122 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
123 &mbi, sizeof(mbi)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
124 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
125
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
126 /* Change the page protection of the allocated memory to executable,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
127 read, and write. */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
128 if (!VirtualProtectEx (h_process, mbi.BaseAddress, size,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
129 PAGE_EXECUTE_READWRITE, &dw_unused))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
130 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
131
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
132 pmc->address = mbi.BaseAddress;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
133 return 1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
134
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
135 failure:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
136 ResumeThread (pmc->h_thread);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
137 pmc->address = 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
138 return 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
139 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
140
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
141 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
142 free_process_memory (process_memory* pmc)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
143 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
144 ResumeThread (pmc->h_thread);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
145 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
146
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
147 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
148 * Run ROUTINE in the context of process determined by H_PROCESS. The
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
149 * routine is passed the address of DATA as parameter. The ROUTINE must
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
150 * not be longer than ROUTINE_CODE_SIZE bytes. DATA_SIZE is the size of
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
151 * DATA structure.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
152 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
153 * Note that the code must be positionally independent, and compiled
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
154 * without stack checks (they cause implicit calls into CRT so will
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
155 * fail). DATA should not refer any data in calling process, as both
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
156 * routine and its data are copied into remote process. Size of data
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
157 * and code together should not exceed one page (4K on x86 systems).
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
158 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
159 * Return the value returned by ROUTINE, or (DWORD)-1 if call failed.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
160 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
161 static DWORD
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
162 run_in_other_process (HANDLE h_process,
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
163 LPTHREAD_START_ROUTINE routine,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
164 LPVOID data, size_t data_size)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
165 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
166 process_memory pm;
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
167 CONST size_t code_size = FRAGMENT_CODE_SIZE;
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
168 /* Need at most 3 extra bytes of memory, for data alignment */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
169 size_t total_size = code_size + data_size + 3;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
170 LPVOID remote_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
171 HANDLE h_thread;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
172 DWORD dw_unused;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
173
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
174 /* Allocate memory */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
175 if (!alloc_process_memory (h_process, total_size, &pm))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
176 return (DWORD)-1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
177
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
178 /* Copy code */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
179 if (!WriteProcessMemory (h_process, pm.address, (LPVOID)routine,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
180 code_size, NULL))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
181 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
182
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
183 /* Copy data */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
184 if (data_size)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
185 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
186 remote_data = (LPBYTE)pm.address + ((code_size + 4) & ~3);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
187 if (!WriteProcessMemory (h_process, remote_data, data, data_size, NULL))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
188 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
189 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
190 else
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
191 remote_data = NULL;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
192
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
193 /* Execute the remote copy of code, passing it remote data */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
194 h_thread = CreateRemoteThread (h_process, NULL, 0,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
195 (LPTHREAD_START_ROUTINE) pm.address,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
196 remote_data, 0, &dw_unused);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
197 if (h_thread == NULL)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
198 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
199
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
200 /* Wait till thread finishes */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
201 WaitForSingleObject (h_thread, INFINITE);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
202
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
203 /* Free remote memory */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
204 free_process_memory (&pm);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
205
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
206 /* Return thread's exit code */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
207 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
208 DWORD exit_code;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
209 GetExitCodeThread (h_thread, &exit_code);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
210 CloseHandle (h_thread);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
211 return exit_code;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
212 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
213
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
214 failure:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
215 free_process_memory (&pm);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
216 return (DWORD)-1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
217 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
218
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
219 /*-----------------------------------------------------------------------*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
220 /* Sending signals */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
221 /*-----------------------------------------------------------------------*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
222
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
223 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
224 * We handle the following signals:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
225 *
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
226 * SIGKILL, SIGTERM, SIGQUIT, SIGHUP - These four translate to ExitProcess
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
227 * executed by the remote process
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
228 * SIGINT - The remote process is sent CTRL_BREAK_EVENT
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
229 *
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
230 * The MSVC5.0 compiler feels free to re-order functions within a
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
231 * compilation unit, so we have no way of finding out the size of the
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
232 * following functions. Therefore these functions must not be larger than
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
233 * FRAGMENT_CODE_SIZE.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
234 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
235
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
236 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
237 * Sending SIGKILL
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
238 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
239 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
240 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
241 void (WINAPI *adr_ExitProcess) (UINT);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
242 } sigkill_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
243
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
244 static DWORD WINAPI
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
245 sigkill_proc (sigkill_data* data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
246 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
247 (*data->adr_ExitProcess)(255);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
248 return 1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
249 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
250
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
251 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
252 * Sending break or control c
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
253 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
254 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
255 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
256 BOOL (WINAPI *adr_GenerateConsoleCtrlEvent) (DWORD, DWORD);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
257 DWORD event;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
258 } sigint_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
259
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
260 static DWORD WINAPI
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
261 sigint_proc (sigint_data* data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
262 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
263 return (*data->adr_GenerateConsoleCtrlEvent) (data->event, 0);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
264 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
265
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
266 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
267 * Enabling signals
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
268 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
269 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
270 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
271 BOOL (WINAPI *adr_SetConsoleCtrlHandler) (LPVOID, BOOL);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
272 } sig_enable_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
273
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
274 static DWORD WINAPI
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
275 sig_enable_proc (sig_enable_data* data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
276 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
277 (*data->adr_SetConsoleCtrlHandler) (NULL, FALSE);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
278 return 1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
279 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
281 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
282 * Send signal SIGNO to process H_PROCESS.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
283 * Return nonzero if successful.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
284 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
285
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
286 /* This code assigns a return value of GetProcAddress to function pointers
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
287 of many different types. Instead of heavy obscure casts, we just disable
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
288 warnings about assignments to different function pointer types. */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
289 #pragma warning (disable : 4113)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
290
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
291 static int
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
292 send_signal (HANDLE h_process, int signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
293 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
294 HMODULE h_kernel = GetModuleHandle ("kernel32");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
295 DWORD retval;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
296
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
297 assert (h_kernel != NULL);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
298
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
299 switch (signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
300 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
301 case SIGKILL:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
302 case SIGTERM:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
303 case SIGQUIT:
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
304 case SIGHUP:
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
305 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
306 sigkill_data d;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
307 d.adr_ExitProcess = GetProcAddress (h_kernel, "ExitProcess");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
308 assert (d.adr_ExitProcess);
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
309 retval = run_in_other_process (h_process, sigkill_proc,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
310 &d, sizeof (d));
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
311 break;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
312 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
313 case SIGINT:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
314 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
315 sigint_data d;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
316 d.adr_GenerateConsoleCtrlEvent =
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
317 GetProcAddress (h_kernel, "GenerateConsoleCtrlEvent");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
318 assert (d.adr_GenerateConsoleCtrlEvent);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
319 d.event = CTRL_C_EVENT;
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
320 retval = run_in_other_process (h_process, sigint_proc,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
321 &d, sizeof (d));
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
322 break;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
323 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
324 default:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
325 assert (0);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
326 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
327
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
328 return (int)retval > 0 ? 1 : 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
329 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
330
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
331 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
332 * Enable CTRL_C_EVENT handling in a new child process
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
333 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
334 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
335 enable_child_signals (HANDLE h_process)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
336 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
337 HMODULE h_kernel = GetModuleHandle ("kernel32");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
338 sig_enable_data d;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
339
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
340 assert (h_kernel != NULL);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
341 d.adr_SetConsoleCtrlHandler =
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
342 GetProcAddress (h_kernel, "SetConsoleCtrlHandler");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
343 assert (d.adr_SetConsoleCtrlHandler);
318
afd57c14dfc8 Import from CVS: tag r21-0b57
cvs
parents: 298
diff changeset
344 run_in_other_process (h_process, sig_enable_proc,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
345 &d, sizeof (d));
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
346 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
347
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
348 #pragma warning (default : 4113)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
349
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
350 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
351 * Signal error if SIGNO is not supported
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
352 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
353 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
354 validate_signal_number (int signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
355 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
356 if (signo != SIGKILL && signo != SIGTERM
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
357 && signo != SIGQUIT && signo != SIGINT
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
358 && signo != SIGHUP)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
359 signal_simple_error ("Signal number not supported", make_int (signo));
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
360 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
361
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
362 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
363 /* Process methods */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
364 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
365
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
366 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
367 * Allocate and initialize Lisp_Process->process_data
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
368 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
369
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
370 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
371 nt_alloc_process_data (struct Lisp_Process *p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
372 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
373 p->process_data = xnew_and_zero (struct nt_process_data);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
374 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
375
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
376 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
377 nt_finalize_process_data (struct Lisp_Process *p, int for_disksave)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
378 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
379 assert (!for_disksave);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
380 if (NT_DATA(p)->h_process)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
381 CloseHandle (NT_DATA(p)->h_process);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
382 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
383
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
384 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
385 * Initialize XEmacs process implemenation once
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
386 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
387 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
388 nt_init_process (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
389 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
390 /* Initialize winsock */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
391 WSADATA wsa_data;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
392 /* Request Winsock v1.1 Note the order: (minor=1, major=1) */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
393 WSAStartup (MAKEWORD (1,1), &wsa_data);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
394 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
395
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
396 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
397 * Fork off a subprocess. P is a pointer to newly created subprocess
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
398 * object. If this function signals, the caller is responsible for
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
399 * deleting (and finalizing) the process object.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
400 *
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
401 * The method must return PID of the new proces, a (positive??? ####) number
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
402 * which fits into Lisp_Int. No return value indicates an error, the method
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
403 * must signal an error instead.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
404 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
405
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
406 /* #### This function completely ignores Vprocess_environment */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
407
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
408 static void
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
409 signal_cannot_launch (Lisp_Object image_file, DWORD err)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
410 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
411 mswindows_set_errno (err);
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
412 signal_simple_error_2 ("Error starting", image_file, lisp_strerror (errno));
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
413 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
414
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
415 static int
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
416 nt_create_process (struct Lisp_Process *p,
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
417 Lisp_Object *argv, int nargv,
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
418 Lisp_Object program, Lisp_Object cur_dir)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
419 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
420 HANDLE hmyshove, hmyslurp, hprocin, hprocout;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
421 LPTSTR command_line;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
422 BOOL do_io, windowed;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
423
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
424 /* Find out whether the application is windowed or not */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
425 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
426 /* SHGetFileInfo tends to return ERROR_FILE_NOT_FOUND on most
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
427 errors. This leads to bogus error message. */
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
428 DWORD image_type;
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
429 char *p = strrchr ((char *)XSTRING_DATA (program), '.');
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
430 if (p != NULL &&
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
431 (stricmp (p, ".exe") == 0 ||
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
432 stricmp (p, ".com") == 0 ||
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
433 stricmp (p, ".bat") == 0 ||
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
434 stricmp (p, ".cmd") == 0))
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
435 {
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
436 image_type = SHGetFileInfo ((char *)XSTRING_DATA (program), 0,NULL,
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
437 0, SHGFI_EXETYPE);
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
438 }
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
439 else
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
440 {
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
441 char progname[MAX_PATH];
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
442 sprintf (progname, "%s.exe", (char *)XSTRING_DATA (program));
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
443 image_type = SHGetFileInfo (progname, 0, NULL, 0, SHGFI_EXETYPE);
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
444 }
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
445 if (image_type == 0)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
446 signal_cannot_launch (program, (GetLastError () == ERROR_FILE_NOT_FOUND
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
447 ? ERROR_BAD_FORMAT : GetLastError ()));
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
448 windowed = HIWORD (image_type) != 0;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
449 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
450
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
451 /* Decide whether to do I/O on process handles, or just mark the
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
452 process exited immediately upon successful launching. We do I/O if the
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
453 process is a console one, or if it is windowed but windowed_process_io
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
454 is non-zero */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
455 do_io = !windowed || windowed_process_io ;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
456
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
457 if (do_io)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
458 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
459 /* Create two unidirectional named pipes */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
460 HANDLE htmp;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
461 SECURITY_ATTRIBUTES sa;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
462
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
463 sa.nLength = sizeof(sa);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
464 sa.bInheritHandle = TRUE;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
465 sa.lpSecurityDescriptor = NULL;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
466
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
467 CreatePipe (&hprocin, &hmyshove, &sa, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
468 CreatePipe (&hmyslurp, &hprocout, &sa, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
469
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
470 /* Stupid Win32 allows to create a pipe with *both* ends either
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
471 inheritable or not. We need process ends inheritable, and local
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
472 ends not inheritable. */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
473 DuplicateHandle (GetCurrentProcess(), hmyshove, GetCurrentProcess(), &htmp,
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
474 0, FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
475 hmyshove = htmp;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
476 DuplicateHandle (GetCurrentProcess(), hmyslurp, GetCurrentProcess(), &htmp,
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
477 0, FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
478 hmyslurp = htmp;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
479 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
480
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
481 /* Convert an argv vector into Win32 style command line by a call to
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
482 lisp function `nt-quote-process-args' which see (in winnt.el)*/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
483 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
484 int i;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
485 Lisp_Object args_or_ret = Qnil;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
486 struct gcpro gcpro1;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
487
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
488 GCPRO1 (args_or_ret);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
489
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
490 for (i = 0; i < nargv; ++i)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
491 args_or_ret = Fcons (*argv++, args_or_ret);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
492 args_or_ret = Fnreverse (args_or_ret);
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
493 args_or_ret = Fcons (program, args_or_ret);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
494
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
495 args_or_ret = call1 (Qnt_quote_process_args, args_or_ret);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
496
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
497 if (!STRINGP (args_or_ret))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
498 /* Luser wrote his/her own clever version */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
499 error ("Bogus return value from `nt-quote-process-args'");
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
500
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
501 command_line = alloca_array (char, (XSTRING_LENGTH (program)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
502 + XSTRING_LENGTH (args_or_ret) + 2));
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
503 strcpy (command_line, XSTRING_DATA (program));
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
504 strcat (command_line, " ");
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
505 strcat (command_line, XSTRING_DATA (args_or_ret));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
506
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
507 UNGCPRO; /* args_or_ret */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
508 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
509
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
510 /* Create process */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
511 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
512 STARTUPINFO si;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
513 PROCESS_INFORMATION pi;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
514 DWORD err;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
515
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
516 xzero (si);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
517 si.dwFlags = STARTF_USESHOWWINDOW;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
518 si.wShowWindow = windowed ? SW_SHOWNORMAL : SW_HIDE;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
519 if (do_io)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
520 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
521 si.hStdInput = hprocin;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
522 si.hStdOutput = hprocout;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
523 si.hStdError = hprocout;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
524 si.dwFlags |= STARTF_USESTDHANDLES;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
525 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
526
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
527 err = (CreateProcess (NULL, command_line, NULL, NULL, TRUE,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
528 CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
529 | CREATE_SUSPENDED,
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
530 NULL, (char *) XSTRING_DATA (cur_dir), &si, &pi)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
531 ? 0 : GetLastError ());
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
532
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
533 if (do_io)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
534 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
535 /* These just have been inherited; we do not need a copy */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
536 CloseHandle (hprocin);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
537 CloseHandle (hprocout);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
538 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
539
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
540 /* Handle process creation failure */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
541 if (err)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
542 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
543 if (do_io)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
544 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
545 CloseHandle (hmyshove);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
546 CloseHandle (hmyslurp);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
547 }
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
548 signal_cannot_launch (program, GetLastError ());
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
549 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
550
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
551 /* The process started successfully */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
552 if (do_io)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
553 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
554 NT_DATA(p)->h_process = pi.hProcess;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
555 init_process_io_handles (p, (void*)hmyslurp, (void*)hmyshove, 0);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
556 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
557 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
558 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
559 /* Indicate as if the process has exited immediately. */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
560 p->status_symbol = Qexit;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
561 CloseHandle (pi.hProcess);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
562 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
563
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
564 if (!windowed)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
565 enable_child_signals (pi.hProcess);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
566
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
567 ResumeThread (pi.hThread);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
568 CloseHandle (pi.hThread);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
569
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
570 /* Hack to support Windows 95 negative pids */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
571 return ((int)pi.dwProcessId < 0
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
572 ? -(int)pi.dwProcessId : (int)pi.dwProcessId);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
573 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
574 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
575
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
576 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
577 * This method is called to update status fields of the process
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
578 * structure. If the process has not existed, this method is expected
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
579 * to do nothing.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
580 *
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
581 * The method is called only for real child processes.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
582 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
583
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
584 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
585 nt_update_status_if_terminated (struct Lisp_Process* p)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
586 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
587 DWORD exit_code;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
588 if (GetExitCodeProcess (NT_DATA(p)->h_process, &exit_code)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
589 && exit_code != STILL_ACTIVE)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
590 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
591 p->tick++;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
592 p->core_dumped = 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
593 /* The exit code can be a code returned by process, or an
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
594 NTSTATUS value. We cannot accurately handle the latter since
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
595 it is a full 32 bit integer */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
596 if (exit_code & 0xC0000000)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
597 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
598 p->status_symbol = Qsignal;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
599 p->exit_code = exit_code & 0x1FFFFFFF;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
600 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
601 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
602 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
603 p->status_symbol = Qexit;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
604 p->exit_code = exit_code;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
605 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
606 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
607 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
608
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
609 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
610 * Stuff the entire contents of LSTREAM to the process ouptut pipe
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
611 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
612
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
613 /* #### If only this function could be somehow merged with
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
614 unix_send_process... */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
615
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
616 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
617 nt_send_process (Lisp_Object proc, struct lstream* lstream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
618 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
619 struct Lisp_Process *p = XPROCESS (proc);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
620
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
621 /* use a reasonable-sized buffer (somewhere around the size of the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
622 stream buffer) so as to avoid inundating the stream with blocked
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
623 data. */
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents: 318
diff changeset
624 Bufbyte chunkbuf[128];
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
625 Bytecount chunklen;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
626
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
627 while (1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
628 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
629 int writeret;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
630
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents: 318
diff changeset
631 chunklen = Lstream_read (lstream, chunkbuf, 128);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
632 if (chunklen <= 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
633 break; /* perhaps should abort() if < 0?
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
634 This should never happen. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
635
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
636 /* Lstream_write() will never successfully write less than the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
637 amount sent in. In the worst case, it just buffers the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
638 unwritten data. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
639 writeret = Lstream_write (XLSTREAM (DATA_OUTSTREAM(p)), chunkbuf,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
640 chunklen);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
641 Lstream_flush (XLSTREAM (DATA_OUTSTREAM(p)));
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
642 if (writeret < 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
643 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
644 p->status_symbol = Qexit;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
645 p->exit_code = ERROR_BROKEN_PIPE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
646 p->core_dumped = 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
647 p->tick++;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
648 process_tick++;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
649 deactivate_process (proc);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
650 error ("Broken pipe error sending to process %s; closed it",
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
651 XSTRING_DATA (p->name));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
652 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
653
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
654 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
655 int wait_ms = 25;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
656 while (Lstream_was_blocked_p (XLSTREAM (p->pipe_outstream)))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
657 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
658 /* Buffer is full. Wait, accepting input; that may allow
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
659 the program to finish doing output and read more. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
660 Faccept_process_output (Qnil, Qzero, make_int (wait_ms));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
661 Lstream_flush (XLSTREAM (p->pipe_outstream));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
662 wait_ms = min (1000, 2 * wait_ms);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
663 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
664 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
665 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
666 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
667
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
668 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
669 * Send a signal number SIGNO to PROCESS.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
670 * CURRENT_GROUP means send to the process group that currently owns
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
671 * the terminal being used to communicate with PROCESS.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
672 * This is used for various commands in shell mode.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
673 * If NOMSG is zero, insert signal-announcements into process's buffers
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
674 * right away.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
675 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
676 * If we can, we try to signal PROCESS by sending control characters
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
677 * down the pty. This allows us to signal inferiors who have changed
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
678 * their uid, for which killpg would return an EPERM error.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
679 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
680 * The method signals an error if the given SIGNO is not valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
681 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
682
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
683 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
684 nt_kill_child_process (Lisp_Object proc, int signo,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
685 int current_group, int nomsg)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
686 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
687 struct Lisp_Process *p = XPROCESS (proc);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
688
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
689 /* Signal error if SIGNO cannot be sent */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
690 validate_signal_number (signo);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
691
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
692 /* Send signal */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
693 if (!send_signal (NT_DATA(p)->h_process, signo))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
694 error ("Cannot send signal to process");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
695 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
696
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
697 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
698 * Kill any process in the system given its PID.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
699 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
700 * Returns zero if a signal successfully sent, or
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
701 * negative number upon failure
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
702 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
703 static int
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
704 nt_kill_process_by_pid (int pid, int signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
705 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
706 HANDLE h_process;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
707 int send_result;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
708
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
709 /* Signal error if SIGNO cannot be sent */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
710 validate_signal_number (signo);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
711
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
712 /* Try to open the process with required privileges */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
713 h_process = OpenProcess (PROCESS_CREATE_THREAD
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
714 | PROCESS_QUERY_INFORMATION
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
715 | PROCESS_VM_OPERATION
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
716 | PROCESS_VM_WRITE,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
717 FALSE, pid);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
718 if (h_process == NULL)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
719 return -1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
720
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
721 send_result = send_signal (h_process, signo);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
722
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
723 CloseHandle (h_process);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
724
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
725 return send_result ? 0 : -1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
726 }
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
727
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
728 /*-----------------------------------------------------------------------*/
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
729 /* Sockets connections */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
730 /*-----------------------------------------------------------------------*/
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
731 #ifdef HAVE_SOCKETS
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
732
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
733 /* #### Hey MS, how long Winsock 2 for '95 will be in beta? */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
734
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
735 #define SOCK_TIMER_ID 666
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
736 #define XM_SOCKREPLY (WM_USER + 666)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
737
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
738 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
739 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
740 Error_behavior errb)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
741 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
742 char buf [MAXGETHOSTSTRUCT];
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
743 HWND hwnd;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
744 HANDLE hasync;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
745 int success = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
746
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
747 address->sin_family = AF_INET;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
748
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
749 /* First check if HOST is already a numeric address */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
750 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
751 unsigned long inaddr = inet_addr (XSTRING_DATA (host));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
752 if (inaddr != INADDR_NONE)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
753 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
754 address->sin_addr.s_addr = inaddr;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
755 return 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
756 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
757 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
758
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
759 /* Create a window which will receive completion messages */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
760 hwnd = CreateWindow ("STATIC", NULL, WS_OVERLAPPED, 0, 0, 1, 1,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
761 NULL, NULL, NULL, NULL);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
762 assert (hwnd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
763
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
764 /* Post name resolution request */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
765 hasync = WSAAsyncGetHostByName (hwnd, XM_SOCKREPLY, XSTRING_DATA (host),
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
766 buf, sizeof (buf));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
767 if (hasync == NULL)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
768 goto done;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
769
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
770 /* Set a timer to poll for quit every 250 ms */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
771 SetTimer (hwnd, SOCK_TIMER_ID, 250, NULL);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
772
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
773 while (1)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
774 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
775 MSG msg;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
776 GetMessage (&msg, hwnd, 0, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
777 if (msg.message == XM_SOCKREPLY)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
778 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
779 /* Ok, got an answer */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
780 if (WSAGETASYNCERROR(msg.lParam) == NO_ERROR)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
781 success = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
782 goto done;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
783 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
784 else if (msg.message == WM_TIMER && msg.wParam == SOCK_TIMER_ID)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
785 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
786 if (QUITP)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
787 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
788 WSACancelAsyncRequest (hasync);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
789 KillTimer (hwnd, SOCK_TIMER_ID);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
790 DestroyWindow (hwnd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
791 REALLY_QUIT;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
792 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
793 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
794 DispatchMessage (&msg);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
795 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
796
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
797 done:
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
798 KillTimer (hwnd, SOCK_TIMER_ID);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
799 DestroyWindow (hwnd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
800 if (success)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
801 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
802 /* BUF starts with struct hostent */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
803 struct hostent* he = (struct hostent*) buf;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
804 address->sin_addr.s_addr = *(unsigned long*)he->h_addr_list[0];
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
805 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
806 return success;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
807 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
808
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
809 static Lisp_Object
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
810 nt_canonicalize_host_name (Lisp_Object host)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
811 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
812 struct sockaddr_in address;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
813
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
814 if (!get_internet_address (host, &address, ERROR_ME_NOT))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
815 return host;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
816
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
817 if (address.sin_family == AF_INET)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
818 return build_string (inet_ntoa (address.sin_addr));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
819 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
820 return host;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
821 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
822
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
823 /* open a TCP network connection to a given HOST/SERVICE. Treated
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
824 exactly like a normal process when reading and writing. Only
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
825 differences are in status display and process deletion. A network
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
826 connection has no PID; you cannot signal it. All you can do is
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
827 deactivate and close it via delete-process */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
828
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
829 static void
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
830 nt_open_network_stream (Lisp_Object name, Lisp_Object host, Lisp_Object service,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
831 Lisp_Object family, void** vinfd, void** voutfd)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
832 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
833 struct sockaddr_in address;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
834 SOCKET s;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
835 int port;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
836 int retval;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
837
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
838 CHECK_STRING (host);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
839
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
840 if (!EQ (family, Qtcpip))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
841 error ("Unsupported protocol family \"%s\"",
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
842 string_data (symbol_name (XSYMBOL (family))));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
843
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
844 if (INTP (service))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
845 port = htons ((unsigned short) XINT (service));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
846 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
847 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
848 struct servent *svc_info;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
849 CHECK_STRING (service);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
850 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
851 if (svc_info == 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
852 error ("Unknown service \"%s\"", XSTRING_DATA (service));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
853 port = svc_info->s_port;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
854 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
855
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
856 get_internet_address (host, &address, ERROR_ME);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
857 address.sin_port = port;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
858
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
859 s = socket (address.sin_family, SOCK_STREAM, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
860 if (s < 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
861 report_file_error ("error creating socket", list1 (name));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
862
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
863 /* We don't want to be blocked on connect */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
864 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
865 unsigned int nonblock = 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
866 ioctlsocket (s, FIONBIO, &nonblock);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
867 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
868
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
869 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
870 if (retval != NO_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
871 goto connect_failed;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
872
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
873 /* Wait while connection is established */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
874 while (1)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
875 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
876 fd_set fdset;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
877 struct timeval tv;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
878 int nsel;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
879
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
880 if (QUITP)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
881 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
882 closesocket (s);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
883 REALLY_QUIT;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
884 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
885
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
886 /* Poll for quit every 250 ms */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
887 tv.tv_sec = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
888 tv.tv_usec = 250 * 1000;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
889
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
890 FD_ZERO (&fdset);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
891 FD_SET (s, &fdset);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
892 nsel = select (0, NULL, &fdset, &fdset, &tv);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
893
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
894 if (nsel > 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
895 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
896 /* Check was connnection successful or not */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
897 tv.tv_usec = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
898 nsel = select (0, NULL, NULL, &fdset, &tv);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
899 if (nsel > 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
900 goto connect_failed;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
901 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
902 break;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
903 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
904 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
905
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
906 /* We are connected at this point */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
907 *vinfd = (void*)s;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
908 DuplicateHandle (GetCurrentProcess(), (HANDLE)s,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
909 GetCurrentProcess(), (LPHANDLE)voutfd,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
910 0, FALSE, DUPLICATE_SAME_ACCESS);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
911 return;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
912
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
913 connect_failed:
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
914 closesocket (s);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
915 report_file_error ("connection failed", list2 (host, name));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
916 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
917
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
918 #endif
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
919
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
920 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
921 /* Initialization */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
922 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
923
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
924 void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
925 process_type_create_nt (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
926 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
927 PROCESS_HAS_METHOD (nt, alloc_process_data);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
928 PROCESS_HAS_METHOD (nt, finalize_process_data);
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
929 PROCESS_HAS_METHOD (nt, init_process);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
930 PROCESS_HAS_METHOD (nt, create_process);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
931 PROCESS_HAS_METHOD (nt, update_status_if_terminated);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
932 PROCESS_HAS_METHOD (nt, send_process);
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
933 PROCESS_HAS_METHOD (nt, kill_child_process);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
934 PROCESS_HAS_METHOD (nt, kill_process_by_pid);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
935 #ifdef HAVE_SOCKETS
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
936 PROCESS_HAS_METHOD (nt, canonicalize_host_name);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
937 PROCESS_HAS_METHOD (nt, open_network_stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
938 #ifdef HAVE_MULTICAST
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
939 #error I won't do this until '95 has winsock2
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
940 PROCESS_HAS_METHOD (nt, open_multicast_group);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
941 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
942 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
943 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
944
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
945 void
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
946 syms_of_process_nt (void)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
947 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
948 defsymbol (&Qnt_quote_process_args, "nt-quote-process-args");
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
949 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
950
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
951 void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
952 vars_of_process_nt (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
953 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
954 }