use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class JavaUtilZipSubstitutions method update.
// CRC32.c-Java_java_util_zip_CRC32_update(JNIEnv *env, jclass cls, jint crc, jint b)
@Substitute
private static int update(int crc, int b) {
// Only the low eight bits of the argument b should be used
CCharPointer bytes = StackValue.get(SizeOf.get(CCharPointer.class));
bytes.write((byte) b);
return (int) ZLib.crc32(WordFactory.unsigned(crc), bytes, 1).rawValue();
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class Target_com_sun_security_auth_module_UnixSystem method getUnixInfo.
@Substitute
void getUnixInfo() {
int realUid = Unistd.getuid();
Word pwsize = WordFactory.signed(Unistd.sysconf(Unistd._SC_GETPW_R_SIZE_MAX()));
if (pwsize.lessThan(0)) {
// indicates no definitive bound: try different sizes
pwsize = WordFactory.signed(1024);
}
CCharPointer pwbuf = LibC.malloc(pwsize);
try {
passwd pwent = StackValue.get(SizeOf.get(passwd.class));
passwdPointer p = StackValue.get(SizeOf.get(passwdPointer.class));
int result;
do {
if (pwbuf.isNull()) {
throw new OutOfMemoryError("Native heap");
}
p.write(WordFactory.nullPointer());
result = Pwd.getpwuid_r(realUid, pwent, pwbuf, pwsize, p);
if (result == Errno.ERANGE()) {
pwsize = pwsize.add(pwsize);
pwbuf = LibC.realloc(pwbuf, pwsize);
} else if (result < 0 && result != Errno.EINTR()) {
throw new RuntimeException("getpwuid_r error: " + Errno.errno());
}
} while (result != 0);
this.uid = pwent.pw_uid();
this.gid = pwent.pw_gid();
this.username = CTypeConversion.toJavaString(pwent.pw_name());
} finally {
LibC.free(pwbuf);
}
int ngroups = Unistd.getgroups(0, WordFactory.nullPointer());
int[] groupIds = new int[ngroups];
try (PinnedObject pinnedGroupIds = PinnedObject.create(groupIds)) {
ngroups = Unistd.getgroups(groupIds.length, pinnedGroupIds.addressOfArrayElement(0));
}
this.groups = new long[ngroups];
for (int i = 0; i < this.groups.length; i++) {
this.groups[i] = groupIds[i];
}
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class PosixJavaIOSubstitutions method getSpace.
@Substitute
public long getSpace(File f, int t) {
statvfs statvfs = StackValue.get(SizeOf.get(statvfs.class));
LibC.memset(statvfs, WordFactory.zero(), WordFactory.unsigned(SizeOf.get(statvfs.class)));
try (CCharPointerHolder pathPin = CTypeConversion.toCString(f.getPath())) {
CCharPointer pathPtr = pathPin.get();
if (statvfs(pathPtr, statvfs) == 0) {
final long frsize = statvfs.f_frsize();
if (t == Target_java_io_FileSystem.SPACE_TOTAL) {
return frsize * statvfs.f_blocks();
} else if (t == Target_java_io_FileSystem.SPACE_FREE) {
return frsize * statvfs.f_bfree();
} else if (t == Target_java_io_FileSystem.SPACE_USABLE) {
return frsize * statvfs.f_bavail();
} else {
throw VMError.shouldNotReachHere("illegal space mode");
}
}
}
return 0L;
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class PosixJavaIOSubstitutions method createFileExclusively.
@Substitute
public boolean createFileExclusively(String path) throws IOException {
int fd;
if (path.equals("/")) {
return false;
} else {
try (CCharPointerHolder pathPin = CTypeConversion.toCString(PosixUtils.removeTrailingSlashes(path))) {
CCharPointer pathPtr = pathPin.get();
fd = open(pathPtr, O_RDWR() | O_CREAT(), 0666);
}
}
if (fd < 0) {
if (fd != EEXIST()) {
throw new IOException(lastErrorString(path));
}
} else {
close(fd);
return true;
}
return false;
}
use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.
the class PosixJavaIOSubstitutions method available.
@Substitute
public int available() throws IOException {
int handle = PosixUtils.getFDHandle(fd);
SignedWord ret = WordFactory.zero();
boolean av = false;
stat stat = StackValue.get(SizeOf.get(stat.class));
if (fstat(handle, stat) >= 0) {
int mode = stat.st_mode();
if (Util_java_io_FileInputStream.isChr(mode) || Util_java_io_FileInputStream.isFifo(mode) || Util_java_io_FileInputStream.isSock(mode)) {
CIntPointer np = StackValue.get(SizeOf.get(CIntPointer.class));
if (ioctl(handle, FIONREAD(), np) >= 0) {
ret = WordFactory.signed(np.read());
av = true;
}
}
}
if (!av) {
SignedWord cur;
SignedWord end;
if ((cur = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) {
av = false;
} else if ((end = lseek(handle, WordFactory.zero(), SEEK_END())).equal(WordFactory.signed(-1))) {
av = false;
} else if (lseek(handle, cur, SEEK_SET()).equal(WordFactory.signed(-1))) {
av = false;
} else {
ret = end.subtract(cur);
av = true;
}
}
if (av) {
long r = ret.rawValue();
if (r > Integer.MAX_VALUE) {
r = Integer.MAX_VALUE;
}
return (int) r;
}
throw new IOException(lastErrorString(""));
}
Aggregations