| 42 | import java.util.concurrent.locks.LockSupport; |
| 43 | |
| 44 | public final class Os { |
| 45 | public static final int ARCH_AARCH64 = 1; |
| 46 | public static final int ARCH_X86_64 = 2; |
| 47 | public static final int DARWIN = 1; |
| 48 | public static final int FREEBSD = 4; |
| 49 | public static final int LINUX = 2; |
| 50 | public static final long PARK_NANOS_MAX = 5 * 1_000_000_000L; |
| 51 | public static final int WINDOWS = 3; |
| 52 | public static final int _32Bit = -2; |
| 53 | public static final int arch; |
| 54 | public static final String archName; |
| 55 | public static final String name; |
| 56 | public static final int type; |
| 57 | |
| 58 | private Os() { |
| 59 | } |
| 60 | |
| 61 | public static native long compareAndSwap(long mem, long oldValue, long newValue); |
| 62 | |
| 63 | public static native long currentTimeMicros(); |
| 64 | |
| 65 | public static native long currentTimeNanos(); |
| 66 | |
| 67 | public static native int errno(); |
| 68 | |
| 69 | public static long forkExec(CharSequence args) { |
| 70 | ObjList<Path> paths = Chars.splitLpsz(args); |
| 71 | int n = paths.size(); |
| 72 | try { |
| 73 | long argv = Unsafe.malloc((n + 1) * 8L, MemoryTag.NATIVE_DEFAULT); |
| 74 | try { |
| 75 | long p = argv; |
| 76 | for (int i = 0; i < n; i++) { |
| 77 | Unsafe.putLong(p, paths.getQuick(i).ptr()); |
| 78 | p += 8; |
| 79 | } |
| 80 | Unsafe.putLong(p, 0); |
| 81 | return forkExec(argv); |
| 82 | } finally { |
| 83 | Unsafe.free(argv, n + 1, MemoryTag.NATIVE_DEFAULT); |
| 84 | } |
| 85 | } finally { |
| 86 | for (int i = 0; i < n; i++) { |
| 87 | paths.getQuick(i).close(); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | public static int forkExecPid(long forkExecT) { |
| 93 | return Unsafe.getInt(forkExecT + 8); |
| 94 | } |
| 95 | |
| 96 | public static int forkExecReadFd(long forkExecT) { |
| 97 | return Unsafe.getInt(forkExecT); |
| 98 | } |
| 99 | |
| 100 | public static int forkExecWriteFd(long forkExecT) { |
| 101 | return Unsafe.getInt(forkExecT + 4); |
nothing calls this directly
no test coverage detected