|
75 | 75 | import static com.oracle.graal.python.runtime.PosixConstants._POSIX_HOST_NAME_MAX; |
76 | 76 | import static com.oracle.graal.python.util.PythonUtils.ARRAY_ACCESSOR; |
77 | 77 | import static com.oracle.graal.python.util.PythonUtils.ARRAY_ACCESSOR_BE; |
| 78 | +import static com.oracle.graal.python.util.PythonUtils.EMPTY_LONG_ARRAY; |
78 | 79 | import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; |
79 | 80 | import static com.oracle.truffle.api.CompilerDirectives.SLOWPATH_PROBABILITY; |
80 | 81 | import static com.oracle.truffle.api.CompilerDirectives.injectBranchProbability; |
@@ -235,6 +236,7 @@ private enum PosixNativeFunction { |
235 | 236 | call_getpgrp("():sint64"), |
236 | 237 | call_getsid("(sint64):sint64"), |
237 | 238 | call_setsid("():sint64"), |
| 239 | + call_getgroups("(sint64, [sint64]):sint32"), |
238 | 240 | call_openpty("([sint32]):sint32"), |
239 | 241 | call_ctermid("([sint8]):sint32"), |
240 | 242 | call_setenv("([sint8], [sint8], sint32):sint32"), |
@@ -1219,6 +1221,25 @@ public long setsid( |
1219 | 1221 | return res; |
1220 | 1222 | } |
1221 | 1223 |
|
| 1224 | + @ExportMessage |
| 1225 | + public long[] getgroups( |
| 1226 | + @Shared("invoke") @Cached InvokeNativeFunction invokeNode) throws PosixException { |
| 1227 | + // The first call gets us the number of groups, so we can allocate the output array |
| 1228 | + int res = invokeNode.callInt(this, PosixNativeFunction.call_getgroups, 0, 0); |
| 1229 | + if (res < 0) { |
| 1230 | + throw getErrnoAndThrowPosixException(invokeNode); |
| 1231 | + } |
| 1232 | + if (res == 0) { |
| 1233 | + return EMPTY_LONG_ARRAY; |
| 1234 | + } |
| 1235 | + long[] groups = new long[res]; |
| 1236 | + res = invokeNode.callInt(this, PosixNativeFunction.call_getgroups, groups.length, wrap(groups)); |
| 1237 | + if (res < 0) { |
| 1238 | + throw getErrnoAndThrowPosixException(invokeNode); |
| 1239 | + } |
| 1240 | + return groups; |
| 1241 | + } |
| 1242 | + |
1222 | 1243 | @ExportMessage |
1223 | 1244 | public OpenPtyResult openpty(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) throws PosixException { |
1224 | 1245 | int[] outvars = new int[2]; |
|
0 commit comments