Skip to content

Commit e64e4a3

Browse files
committed
add boundaries to resources access
1 parent e96a68e commit e64e4a3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixResources.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.List;
5050

5151
import com.oracle.truffle.api.TruffleFile;
52+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5253
import com.oracle.truffle.api.TruffleLanguage.Env;
5354

5455
/**
@@ -82,45 +83,52 @@ public PosixResources() {
8283
files.add(null);
8384
}
8485

86+
@TruffleBoundary
8587
public Channel getFileChannel(int fd) {
8688
if (files.size() > fd) {
8789
return files.get(fd);
8890
}
8991
return null;
9092
}
9193

94+
@TruffleBoundary
9295
public String getFilePath(int fd) {
9396
if (filePaths.size() > fd) {
9497
return filePaths.get(fd);
9598
}
9699
return null;
97100
}
98101

102+
@TruffleBoundary
99103
public void close(int fd) {
100104
if (filePaths.size() > fd) {
101105
files.set(fd, null);
102106
filePaths.set(fd, null);
103107
}
104108
}
105109

110+
@TruffleBoundary
106111
public void fdopen(int fd, Channel fc) {
107112
files.set(fd, fc);
108113
}
109114

115+
@TruffleBoundary
110116
public int open(TruffleFile path, Channel fc) {
111117
int fd = nextFreeFd();
112118
files.set(fd, fc);
113119
filePaths.set(fd, path.getAbsoluteFile().getPath());
114120
return fd;
115121
}
116122

123+
@TruffleBoundary
117124
public int dup(int fd) {
118125
int dupFd = nextFreeFd();
119126
files.set(dupFd, getFileChannel(fd));
120127
filePaths.set(dupFd, getFilePath(fd));
121128
return dupFd;
122129
}
123130

131+
@TruffleBoundary
124132
public int[] pipe() throws IOException {
125133
Pipe pipe = Pipe.open();
126134
int read = nextFreeFd();
@@ -130,6 +138,7 @@ public int[] pipe() throws IOException {
130138
return new int[]{read, write};
131139
}
132140

141+
@TruffleBoundary
133142
synchronized private int nextFreeFd() {
134143
for (int i = 0; i < filePaths.size(); i++) {
135144
String openPath = filePaths.get(i);
@@ -143,18 +152,21 @@ synchronized private int nextFreeFd() {
143152
return filePaths.size() - 1;
144153
}
145154

155+
@TruffleBoundary
146156
public void setEnv(Env env) {
147157
files.set(0, Channels.newChannel(env.in()));
148158
files.set(1, Channels.newChannel(env.out()));
149159
files.set(2, Channels.newChannel(env.err()));
150160
}
151161

162+
@TruffleBoundary
152163
public int registerChild(Process child) {
153164
int pid = nextFreePid();
154165
children.set(pid, child);
155166
return pid;
156167
}
157168

169+
@TruffleBoundary
158170
synchronized private int nextFreePid() {
159171
for (int i = 0; i < children.size(); i++) {
160172
Process openPath = children.get(i);
@@ -166,6 +178,7 @@ synchronized private int nextFreePid() {
166178
return children.size() - 1;
167179
}
168180

181+
@TruffleBoundary
169182
public int waitpid(int pid) throws ArrayIndexOutOfBoundsException, InterruptedException {
170183
Process process = children.get(pid);
171184
int exitStatus = process.waitFor();

0 commit comments

Comments
 (0)