Search in sources :

Example 1 with VoidPointer

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);
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) VoidPointer(org.graalvm.nativeimage.c.type.VoidPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) VerRsrc(com.oracle.svm.core.windows.headers.VerRsrc) WCharPointer(com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer) WindowsLibC(com.oracle.svm.core.windows.headers.WindowsLibC) SysinfoAPI(com.oracle.svm.core.windows.headers.SysinfoAPI)

Example 2 with VoidPointer

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;
    }
}
Also used : VoidPointer(org.graalvm.nativeimage.c.type.VoidPointer) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) WritableByteChannel(java.nio.channels.WritableByteChannel) ByteBuffer(java.nio.ByteBuffer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Aggregations

VoidPointer (org.graalvm.nativeimage.c.type.VoidPointer)2 SysinfoAPI (com.oracle.svm.core.windows.headers.SysinfoAPI)1 VerRsrc (com.oracle.svm.core.windows.headers.VerRsrc)1 WindowsLibC (com.oracle.svm.core.windows.headers.WindowsLibC)1 WCharPointer (com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer)1 ByteBuffer (java.nio.ByteBuffer)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)1 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)1 WordPointer (org.graalvm.nativeimage.c.type.WordPointer)1