1996-09-04 07:17:43 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
1997-09-04 06:45:56 -07:00
|
|
|
/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
1996-09-04 07:17:43 -07:00
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1996-09-04 07:17:43 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include "unixsupport.h"
|
|
|
|
#include <sys/types.h>
|
2007-11-06 07:16:56 -08:00
|
|
|
#include <signals.h>
|
1996-09-04 07:17:43 -07:00
|
|
|
|
1997-09-04 06:45:56 -07:00
|
|
|
static value alloc_process_status(HANDLE pid, int status)
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
1997-09-03 07:38:02 -07:00
|
|
|
value res, st;
|
1996-09-04 07:17:43 -07:00
|
|
|
|
1997-09-04 06:45:56 -07:00
|
|
|
st = alloc(1, 0);
|
|
|
|
Field(st, 0) = Val_int(status);
|
1997-05-26 10:16:31 -07:00
|
|
|
Begin_root (st);
|
1998-10-26 11:19:32 -08:00
|
|
|
res = alloc_small(2, 0);
|
2005-09-22 07:21:50 -07:00
|
|
|
Field(res, 0) = Val_long((intnat) pid);
|
1997-05-26 10:16:31 -07:00
|
|
|
Field(res, 1) = st;
|
|
|
|
End_roots();
|
1996-09-04 07:17:43 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-12-01 05:07:31 -08:00
|
|
|
enum { CAML_WNOHANG = 1, CAML_WUNTRACED = 2 };
|
|
|
|
|
|
|
|
static int wait_flag_table[] = { CAML_WNOHANG, CAML_WUNTRACED };
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value win_waitpid(value vflags, value vpid_req)
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
2002-06-07 02:49:45 -07:00
|
|
|
int flags;
|
2006-09-21 01:04:13 -07:00
|
|
|
DWORD status, retcode;
|
1997-09-04 06:45:56 -07:00
|
|
|
HANDLE pid_req = (HANDLE) Long_val(vpid_req);
|
2006-10-18 01:26:54 -07:00
|
|
|
DWORD err = 0;
|
1997-09-04 06:45:56 -07:00
|
|
|
|
2000-12-01 05:07:31 -08:00
|
|
|
flags = convert_flag_list(vflags, wait_flag_table);
|
2001-06-25 06:07:15 -07:00
|
|
|
if ((flags & CAML_WNOHANG) == 0) {
|
2006-09-21 01:04:13 -07:00
|
|
|
enter_blocking_section();
|
|
|
|
retcode = WaitForSingleObject(pid_req, INFINITE);
|
2006-10-18 01:26:54 -07:00
|
|
|
if (retcode == WAIT_FAILED) err = GetLastError();
|
2006-09-21 01:04:13 -07:00
|
|
|
leave_blocking_section();
|
2006-10-18 01:26:54 -07:00
|
|
|
if (err) {
|
|
|
|
win32_maperr(err);
|
2000-12-01 05:07:31 -08:00
|
|
|
uerror("waitpid", Nothing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! GetExitCodeProcess(pid_req, &status)) {
|
2001-08-28 07:47:48 -07:00
|
|
|
win32_maperr(GetLastError());
|
1997-09-04 06:45:56 -07:00
|
|
|
uerror("waitpid", Nothing);
|
|
|
|
}
|
2000-12-01 05:07:31 -08:00
|
|
|
if (status == STILL_ACTIVE)
|
|
|
|
return alloc_process_status((HANDLE) 0, 0);
|
2008-01-11 08:13:18 -08:00
|
|
|
else {
|
|
|
|
CloseHandle(pid_req);
|
2000-12-01 05:07:31 -08:00
|
|
|
return alloc_process_status(pid_req, status);
|
2008-01-11 08:13:18 -08:00
|
|
|
}
|
1996-09-04 07:17:43 -07:00
|
|
|
}
|