-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProcess.xs
More file actions
471 lines (428 loc) · 8.55 KB
/
Process.xs
File metadata and controls
471 lines (428 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#include <stdlib.h> // avoid BCC-5.0 brainmelt
#include <math.h> // avoid VC-5.0 brainmelt
#include "Process.hpp"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#if defined(__cplusplus)
# include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.H"
#include "ppport.h"
#ifndef ABOVE_NORMAL_PRIORITY_CLASS
# define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
#endif
#ifndef BELOW_NORMAL_PRIORITY_CLASS
# define BELOW_NORMAL_PRIORITY_CLASS 0x00004000
#endif
static BOOL
Create(cProcess* &cP, char* szAppName, char* szCommLine, DWORD Inherit,
DWORD CreateFlags, char* szCurrDir)
{
BOOL bRetVal;
void *env = NULL;
#ifdef PERL_IMPLICIT_SYS
env = PerlEnv_get_childenv();
#endif
cP = NULL;
try {
cP = (cProcess*)new cProcess(szAppName,szCommLine,Inherit,CreateFlags,
env,szCurrDir);
bRetVal = cP->bRetVal;
}
catch (...) {
bRetVal = FALSE;
}
#ifdef PERL_IMPLICIT_SYS
PerlEnv_free_childenv(env);
#endif
return bRetVal;
}
static BOOL
Open_(cProcess * &cP, DWORD pid, DWORD Inherit)
{
cP = NULL;
try {
cP = (cProcess *) new cProcess(pid, Inherit);
}
catch (...) {
return(FALSE);
}
return(cP->bRetVal);
}
static double
constant(char* name)
{
errno = 0;
switch (*name) {
case 'A':
if (strEQ(name, "ABOVE_NORMAL_PRIORITY_CLASS"))
#ifdef ABOVE_NORMAL_PRIORITY_CLASS
return ABOVE_NORMAL_PRIORITY_CLASS;
#else
goto not_there;
#endif
break;
case 'B':
if (strEQ(name, "BELOW_NORMAL_PRIORITY_CLASS"))
#ifdef BELOW_NORMAL_PRIORITY_CLASS
return BELOW_NORMAL_PRIORITY_CLASS;
#else
goto not_there;
#endif
break;
case 'C':
if (strEQ(name, "CREATE_DEFAULT_ERROR_MODE"))
#ifdef CREATE_DEFAULT_ERROR_MODE
return CREATE_DEFAULT_ERROR_MODE;
#else
goto not_there;
#endif
if (strEQ(name, "CREATE_NEW_CONSOLE"))
#ifdef CREATE_NEW_CONSOLE
return CREATE_NEW_CONSOLE;
#else
goto not_there;
#endif
if (strEQ(name, "CREATE_NEW_PROCESS_GROUP"))
#ifdef CREATE_NEW_PROCESS_GROUP
return CREATE_NEW_PROCESS_GROUP;
#else
goto not_there;
#endif
if (strEQ(name, "CREATE_NO_WINDOW"))
#ifdef CREATE_NO_WINDOW
return CREATE_NO_WINDOW;
#else
goto not_there;
#endif
if (strEQ(name, "CREATE_SEPARATE_WOW_VDM"))
#ifdef CREATE_SEPARATE_WOW_VDM
return CREATE_SEPARATE_WOW_VDM;
#else
goto not_there;
#endif
if (strEQ(name, "CREATE_SUSPENDED"))
#ifdef CREATE_SUSPENDED
return CREATE_SUSPENDED;
#else
goto not_there;
#endif
if (strEQ(name, "CREATE_UNICODE_ENVIRONMENT"))
#ifdef CREATE_UNICODE_ENVIRONMENT
return CREATE_UNICODE_ENVIRONMENT;
#else
goto not_there;
#endif
break;
case 'D':
if (strEQ(name, "DEBUG_ONLY_THIS_PROCESS"))
#ifdef DEBUG_ONLY_THIS_PROCESS
return DEBUG_ONLY_THIS_PROCESS;
#else
goto not_there;
#endif
if (strEQ(name, "DEBUG_PROCESS"))
#ifdef DEBUG_PROCESS
return DEBUG_PROCESS;
#else
goto not_there;
#endif
if (strEQ(name, "DETACHED_PROCESS"))
#ifdef DETACHED_PROCESS
return DETACHED_PROCESS;
#else
goto not_there;
#endif
break;
case 'E':
break;
case 'F':
break;
case 'G':
break;
case 'H':
if (strEQ(name, "HIGH_PRIORITY_CLASS"))
#ifdef HIGH_PRIORITY_CLASS
return HIGH_PRIORITY_CLASS;
#else
goto not_there;
#endif
break;
case 'I':
if (strEQ(name, "IDLE_PRIORITY_CLASS"))
#ifdef IDLE_PRIORITY_CLASS
return IDLE_PRIORITY_CLASS;
#else
goto not_there;
#endif
if (strEQ(name, "INFINITE"))
#ifdef INFINITE
return INFINITE;
#else
goto not_there;
#endif
break;
case 'J':
break;
case 'K':
break;
case 'L':
break;
case 'M':
break;
case 'N':
if (strEQ(name, "NORMAL_PRIORITY_CLASS"))
#ifdef NORMAL_PRIORITY_CLASS
return NORMAL_PRIORITY_CLASS;
#else
goto not_there;
#endif
break;
case 'O':
break;
case 'P':
break;
case 'Q':
break;
case 'R':
if (strEQ(name, "REALTIME_PRIORITY_CLASS"))
#ifdef REALTIME_PRIORITY_CLASS
return REALTIME_PRIORITY_CLASS;
#else
goto not_there;
#endif
break;
case 'S':
if (strEQ(name, "STILL_ACTIVE"))
#ifdef STILL_ACTIVE
return STILL_ACTIVE;
#else
goto not_there;
#endif
break;
case 'T':
if (strEQ(name, "THREAD_PRIORITY_ABOVE_NORMAL"))
#ifdef THREAD_PRIORITY_ABOVE_NORMAL
return THREAD_PRIORITY_ABOVE_NORMAL;
#else
goto not_there;
#endif
if (strEQ(name, "THREAD_PRIORITY_BELOW_NORMAL"))
#ifdef THREAD_PRIORITY_BELOW_NORMAL
return THREAD_PRIORITY_BELOW_NORMAL;
#else
goto not_there;
#endif
if (strEQ(name, "THREAD_PRIORITY_ERROR_RETURN"))
#ifdef THREAD_PRIORITY_ERROR_RETURN
return THREAD_PRIORITY_ERROR_RETURN;
#else
goto not_there;
#endif
if (strEQ(name, "THREAD_PRIORITY_HIGHEST"))
#ifdef THREAD_PRIORITY_HIGHEST
return THREAD_PRIORITY_HIGHEST;
#else
goto not_there;
#endif
if (strEQ(name, "THREAD_PRIORITY_IDLE"))
#ifdef THREAD_PRIORITY_IDLE
return THREAD_PRIORITY_IDLE;
#else
goto not_there;
#endif
if (strEQ(name, "THREAD_PRIORITY_LOWEST"))
#ifdef THREAD_PRIORITY_LOWEST
return THREAD_PRIORITY_LOWEST;
#else
goto not_there;
#endif
if (strEQ(name, "THREAD_PRIORITY_NORMAL"))
#ifdef THREAD_PRIORITY_NORMAL
return THREAD_PRIORITY_NORMAL;
#else
goto not_there;
#endif
if (strEQ(name, "THREAD_PRIORITY_TIME_CRITICAL"))
#ifdef THREAD_PRIORITY_TIME_CRITICAL
return THREAD_PRIORITY_TIME_CRITICAL;
#else
goto not_there;
#endif
break;
case 'U':
break;
case 'V':
break;
case 'W':
break;
case 'X':
break;
case 'Y':
break;
case 'Z':
break;
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}
#if defined(__cplusplus)
}
#endif
MODULE = Win32::Process PACKAGE = Win32::Process
PROTOTYPES: DISABLE
BOOL
Create(cP,appname_sv,cmdline_sv,inherit,flags,curdir)
cProcess *cP = NULL;
SV *appname_sv
SV *cmdline_sv
BOOL inherit
DWORD flags
char *curdir
INIT:
char *appname = SvOK(appname_sv) ? SvPV_nolen(appname_sv) : NULL;
char *cmdline = SvOK(cmdline_sv) ? SvPV_nolen(cmdline_sv) : NULL;
CODE:
RETVAL = Create(cP, appname, cmdline, inherit, flags, curdir);
OUTPUT:
cP
RETVAL
BOOL
Open(cP,pid,inherit)
cProcess *cP = NULL;
DWORD pid
BOOL inherit
CODE:
RETVAL = Open_(cP, pid, inherit);
OUTPUT:
cP
RETVAL
double
constant(name)
char *name
BOOL
Kill(cP,exitcode)
cProcess *cP
unsigned int exitcode
CODE:
RETVAL = cP->Kill(exitcode);
OUTPUT:
RETVAL
BOOL
Suspend(cP)
cProcess *cP
CODE:
RETVAL = cP->Suspend();
OUTPUT:
RETVAL
BOOL
Resume(cP)
cProcess *cP
CODE:
RETVAL = cP->Resume();
OUTPUT:
RETVAL
BOOL
GetPriorityClass(cP,priorityclass)
cProcess *cP
DWORD priorityclass = NO_INIT
CODE:
RETVAL = cP->GetPriorityClass(&priorityclass);
OUTPUT:
priorityclass
RETVAL
BOOL
SetPriorityClass(cP,priorityclass)
cProcess *cP
DWORD priorityclass
CODE:
RETVAL = cP->SetPriorityClass(priorityclass);
OUTPUT:
RETVAL
BOOL
GetProcessAffinityMask(cP,processAffinityMask,systemAffinityMask)
cProcess *cP
DWORD_PTR processAffinityMask = NO_INIT
DWORD_PTR systemAffinityMask = NO_INIT
CODE:
RETVAL = cP->GetProcessAffinityMask(&processAffinityMask,&systemAffinityMask);
OUTPUT:
processAffinityMask
systemAffinityMask
RETVAL
BOOL
SetProcessAffinityMask(cP,processAffinityMask)
cProcess *cP
DWORD processAffinityMask
CODE:
RETVAL = cP->SetProcessAffinityMask(processAffinityMask);
OUTPUT:
RETVAL
BOOL
GetExitCode(cP,exitcode)
cProcess *cP
DWORD exitcode = NO_INIT
CODE:
RETVAL = cP->GetExitCode(&exitcode);
OUTPUT:
exitcode
RETVAL
void
DESTROY(cP)
cProcess *cP
CODE:
delete cP;
BOOL
Wait(cP,timeout)
cProcess *cP
DWORD timeout
CODE:
RETVAL = (cP->Wait(timeout) == WAIT_OBJECT_0);
OUTPUT:
RETVAL
IV
get_process_handle(cP)
cProcess *cP
CODE:
RETVAL = reinterpret_cast<IV>(cP->GetProcessHandle());
OUTPUT:
RETVAL
DWORD
GetProcessID(cP)
cProcess *cP
CODE:
RETVAL = cP->GetProcessID();
OUTPUT:
RETVAL
BOOL
KillProcess(pid, exitcode)
DWORD pid
unsigned int exitcode
CODE:
{
HANDLE ph = OpenProcess(PROCESS_DUP_HANDLE |
PROCESS_QUERY_INFORMATION |
PROCESS_SET_INFORMATION |
PROCESS_TERMINATE |
SYNCHRONIZE,
0, pid);
if (ph) {
RETVAL = TerminateProcess(ph, exitcode);
if (RETVAL)
CloseHandle(ph);
}
}
OUTPUT:
RETVAL
DWORD
GetCurrentProcessID()
CODE:
RETVAL = GetCurrentProcessId();
OUTPUT:
RETVAL