49
49
import java .util .List ;
50
50
51
51
import com .oracle .truffle .api .TruffleFile ;
52
+ import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
52
53
import com .oracle .truffle .api .TruffleLanguage .Env ;
53
54
54
55
/**
@@ -82,45 +83,52 @@ public PosixResources() {
82
83
files .add (null );
83
84
}
84
85
86
+ @ TruffleBoundary
85
87
public Channel getFileChannel (int fd ) {
86
88
if (files .size () > fd ) {
87
89
return files .get (fd );
88
90
}
89
91
return null ;
90
92
}
91
93
94
+ @ TruffleBoundary
92
95
public String getFilePath (int fd ) {
93
96
if (filePaths .size () > fd ) {
94
97
return filePaths .get (fd );
95
98
}
96
99
return null ;
97
100
}
98
101
102
+ @ TruffleBoundary
99
103
public void close (int fd ) {
100
104
if (filePaths .size () > fd ) {
101
105
files .set (fd , null );
102
106
filePaths .set (fd , null );
103
107
}
104
108
}
105
109
110
+ @ TruffleBoundary
106
111
public void fdopen (int fd , Channel fc ) {
107
112
files .set (fd , fc );
108
113
}
109
114
115
+ @ TruffleBoundary
110
116
public int open (TruffleFile path , Channel fc ) {
111
117
int fd = nextFreeFd ();
112
118
files .set (fd , fc );
113
119
filePaths .set (fd , path .getAbsoluteFile ().getPath ());
114
120
return fd ;
115
121
}
116
122
123
+ @ TruffleBoundary
117
124
public int dup (int fd ) {
118
125
int dupFd = nextFreeFd ();
119
126
files .set (dupFd , getFileChannel (fd ));
120
127
filePaths .set (dupFd , getFilePath (fd ));
121
128
return dupFd ;
122
129
}
123
130
131
+ @ TruffleBoundary
124
132
public int [] pipe () throws IOException {
125
133
Pipe pipe = Pipe .open ();
126
134
int read = nextFreeFd ();
@@ -130,6 +138,7 @@ public int[] pipe() throws IOException {
130
138
return new int []{read , write };
131
139
}
132
140
141
+ @ TruffleBoundary
133
142
synchronized private int nextFreeFd () {
134
143
for (int i = 0 ; i < filePaths .size (); i ++) {
135
144
String openPath = filePaths .get (i );
@@ -143,18 +152,21 @@ synchronized private int nextFreeFd() {
143
152
return filePaths .size () - 1 ;
144
153
}
145
154
155
+ @ TruffleBoundary
146
156
public void setEnv (Env env ) {
147
157
files .set (0 , Channels .newChannel (env .in ()));
148
158
files .set (1 , Channels .newChannel (env .out ()));
149
159
files .set (2 , Channels .newChannel (env .err ()));
150
160
}
151
161
162
+ @ TruffleBoundary
152
163
public int registerChild (Process child ) {
153
164
int pid = nextFreePid ();
154
165
children .set (pid , child );
155
166
return pid ;
156
167
}
157
168
169
+ @ TruffleBoundary
158
170
synchronized private int nextFreePid () {
159
171
for (int i = 0 ; i < children .size (); i ++) {
160
172
Process openPath = children .get (i );
@@ -166,6 +178,7 @@ synchronized private int nextFreePid() {
166
178
return children .size () - 1 ;
167
179
}
168
180
181
+ @ TruffleBoundary
169
182
public int waitpid (int pid ) throws ArrayIndexOutOfBoundsException , InterruptedException {
170
183
Process process = children .get (pid );
171
184
int exitStatus = process .waitFor ();
0 commit comments