use of org.graalvm.nativeimage.c.type.VoidPointer in project graal by oracle.
the class WindowsSystemPropertiesFeature method getOsNameAndVersion.
public Pair<String, String> getOsNameAndVersion() {
/*
* Reimplementation of code from java_props_md.c
*/
SysinfoAPI.OSVERSIONINFOEXA ver = StackValue.get(SysinfoAPI.OSVERSIONINFOEXA.class);
ver.dwOSVersionInfoSize(SizeOf.get(SysinfoAPI.OSVERSIONINFOEXA.class));
SysinfoAPI.GetVersionExA(ver);
boolean is64bit = ImageSingletons.lookup(Platform.class).getArchitecture().endsWith("64");
boolean isWorkstation = ver.wProductType() == VER_NT_WORKSTATION;
int platformId = ver.dwPlatformId();
int majorVersion = ver.dwMajorVersion();
int minorVersion = ver.dwMinorVersion();
int buildNumber = ver.dwBuildNumber();
do {
/* Get the full path to \Windows\System32\kernel32.dll ... */
WindowsLibC.WCharPointer kernel32Path = StackValue.get(WinBase.MAX_PATH, WindowsLibC.WCharPointer.class);
WindowsLibC.WCharPointer kernel32Dll = NonmovableArrays.addressOf(NonmovableArrays.fromImageHeap(KERNEL32_DLL), 0);
int len = WinBase.MAX_PATH - (int) WindowsLibC.wcslen(kernel32Dll).rawValue() - 1;
int ret = SysinfoAPI.GetSystemDirectoryW(kernel32Path, len);
if (ret == 0 || ret > len) {
break;
}
WindowsLibC.wcsncat(kernel32Path, kernel32Dll, WordFactory.unsigned(WinBase.MAX_PATH - ret));
/* ... and use that for determining what version of Windows we're running on. */
int versionSize = WinVer.GetFileVersionInfoSizeW(kernel32Path, WordFactory.nullPointer());
if (versionSize == 0) {
break;
}
VoidPointer versionInfo = LibC.malloc(WordFactory.unsigned(versionSize));
if (versionInfo.isNull()) {
break;
}
if (WinVer.GetFileVersionInfoW(kernel32Path, 0, versionSize, versionInfo) == 0) {
LibC.free(versionInfo);
break;
}
WindowsLibC.WCharPointer rootPath = NonmovableArrays.addressOf(NonmovableArrays.fromImageHeap(ROOT_PATH), 0);
WordPointer fileInfoPointer = StackValue.get(WordPointer.class);
CIntPointer lengthPointer = StackValue.get(CIntPointer.class);
if (WinVer.VerQueryValueW(versionInfo, rootPath, fileInfoPointer, lengthPointer) == 0) {
LibC.free(versionInfo);
break;
}
VerRsrc.VS_FIXEDFILEINFO fileInfo = fileInfoPointer.read();
// HIWORD
majorVersion = (short) (fileInfo.dwProductVersionMS() >> 16);
// LOWORD
minorVersion = (short) fileInfo.dwProductVersionMS();
// HIWORD
buildNumber = (short) (fileInfo.dwProductVersionLS() >> 16);
LibC.free(versionInfo);
} while (false);
String osVersion = majorVersion + "." + minorVersion;
String osName;
switch(platformId) {
case VER_PLATFORM_WIN32_WINDOWS:
if (majorVersion == 4) {
switch(minorVersion) {
case 0:
osName = "Windows 95";
break;
case 10:
osName = "Windows 98";
break;
case 90:
osName = "Windows Me";
break;
default:
osName = "Windows 9X (unknown)";
break;
}
} else {
osName = "Windows 9X (unknown)";
}
break;
case VER_PLATFORM_WIN32_NT:
if (majorVersion <= 4) {
osName = "Windows NT";
} else if (majorVersion == 5) {
switch(minorVersion) {
case 0:
osName = "Windows 2000";
break;
case 1:
osName = "Windows XP";
break;
case 2:
if (isWorkstation && is64bit) {
osName = "Windows XP";
/* 64 bit */
} else {
osName = "Windows 2003";
}
break;
default:
osName = "Windows NT (unknown)";
break;
}
} else if (majorVersion == 6) {
if (isWorkstation) {
switch(minorVersion) {
case 0:
osName = "Windows Vista";
break;
case 1:
osName = "Windows 7";
break;
case 2:
osName = "Windows 8";
break;
case 3:
osName = "Windows 8.1";
break;
default:
osName = "Windows NT (unknown)";
}
} else {
switch(minorVersion) {
case 0:
osName = "Windows Server 2008";
break;
case 1:
osName = "Windows Server 2008 R2";
break;
case 2:
osName = "Windows Server 2012";
break;
case 3:
osName = "Windows Server 2012 R2";
break;
default:
osName = "Windows NT (unknown)";
}
}
} else if (majorVersion == 10) {
if (isWorkstation) {
switch(minorVersion) {
case 0:
osName = "Windows 10";
break;
default:
osName = "Windows NT (unknown)";
}
} else {
switch(minorVersion) {
case 0:
if (buildNumber > 17762) {
osName = "Windows Server 2019";
} else {
osName = "Windows Server 2016";
}
break;
default:
osName = "Windows NT (unknown)";
}
}
} else {
osName = "Windows NT (unknown)";
}
break;
default:
osName = "Windows (unknown)";
break;
}
return Pair.create(osName, osVersion);
}
use of org.graalvm.nativeimage.c.type.VoidPointer in project graal by oracle.
the class TruffleToLibGraalEntryPoints method dumpChannelWrite.
@TruffleToLibGraal(DumpChannelWrite)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_dumpChannelWrite")
@SuppressWarnings({ "unused", "try" })
public static int dumpChannelWrite(JNIEnv env, JClass hsClass, @CEntryPoint.IsolateThreadContext long isolateThreadId, long channelHandle, JObject hsSource, int capacity, int position, int limit) {
try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, DumpChannelWrite, env)) {
WritableByteChannel channel = LibGraalObjectHandles.resolve(channelHandle, WritableByteChannel.class);
VoidPointer baseAddr = JNIUtil.GetDirectBufferAddress(env, hsSource);
ByteBuffer source = CTypeConversion.asByteBuffer(baseAddr, capacity);
source.position(position);
source.limit(limit);
return channel.write(source);
} catch (Throwable t) {
JNIExceptionWrapper.throwInHotSpot(env, t);
return -1;
}
}
Aggregations