source: trunk/src/gcc/libjava/java/lang/natWin32Process.cc@ 1755

Last change on this file since 1755 was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.3 KB
Line 
1// natWin32Process.cc - Native side of Win32 process code.
2
3/* Copyright (C) 2003 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11#include <config.h>
12
13#include <stdio.h>
14
15#define WIN32_LEAN_AND_MEAN
16#include <windows.h>
17
18// Conflicts with the definition in "java/lang/reflect/Modifier.h"
19#undef STRICT
20
21#include <gcj/cni.h>
22#include <jvm.h>
23
24#include <java/lang/ConcreteProcess.h>
25#include <java/lang/IllegalThreadStateException.h>
26#include <java/lang/InterruptedException.h>
27#include <java/lang/NullPointerException.h>
28#include <java/lang/Thread.h>
29#include <java/io/File.h>
30#include <java/io/FileDescriptor.h>
31#include <java/io/FileInputStream.h>
32#include <java/io/FileOutputStream.h>
33#include <java/io/IOException.h>
34#include <java/lang/OutOfMemoryError.h>
35
36void
37java::lang::ConcreteProcess::cleanup (void)
38{
39 if (inputStream != NULL)
40 {
41 inputStream->close ();
42 inputStream = NULL;
43 }
44
45 if (outputStream != NULL)
46 {
47 outputStream->close ();
48 outputStream = NULL;
49 }
50
51 if (errorStream != NULL)
52 {
53 errorStream->close ();
54 errorStream = NULL;
55 }
56}
57
58void
59java::lang::ConcreteProcess::destroy (void)
60{
61 if (! hasExited ())
62 {
63 // Kill it forcibly and assign an (arbitrary) exit code of 0.
64 TerminateProcess ((HANDLE) procHandle, 0);
65 exitCode = 0;
66
67 cleanup ();
68 }
69}
70
71jboolean
72java::lang::ConcreteProcess::hasExited (void)
73{
74 DWORD exitStatus;
75
76 if (GetExitCodeProcess ((HANDLE) procHandle, &exitStatus) != 0)
77 {
78 // NOTE: STILL_ACTIVE is defined as "259" by Win32 - if the
79 // child actually exits with this return code, we have a
80 // problem here. See MSDN documentation on GetExitCodeProcess( ).
81
82 if (exitStatus == STILL_ACTIVE)
83 return false;
84 else
85 {
86 cleanup ();
87 exitCode = exitStatus;
88 return true;
89 }
90 }
91 else
92 return true;
93}
94
95jint
96java::lang::ConcreteProcess::waitFor (void)
97{
98 if (! hasExited ())
99 {
100 DWORD exitStatus = 0UL;
101
102 // FIXME: The wait should be interruptible.
103 WaitForSingleObject ((HANDLE) procHandle, INFINITE);
104
105 GetExitCodeProcess ((HANDLE) procHandle, &exitStatus);
106 exitCode = exitStatus;
107
108 cleanup ();
109 }
110
111 return exitCode;
112}
113
114static char *
115new_string (jstring string)
116{
117 jsize s = _Jv_GetStringUTFLength (string);