Search in sources :

Example 6 with WCharPointer

use of com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer in project graal by oracle.

the class WindowsSystemPropertiesFeature method userHomeValue.

@Override
protected String userHomeValue() {
    WinBase.LPHANDLE tokenHandle = StackValue.get(WinBase.LPHANDLE.class);
    if (Process.NoTransitions.OpenProcessToken(Process.NoTransitions.GetCurrentProcess(), Process.TOKEN_QUERY(), tokenHandle) == 0) {
        // matches openjdk
        return "C:\\";
    }
    int initialLen = WinBase.MAX_PATH + 1;
    CIntPointer buffLenPointer = StackValue.get(CIntPointer.class);
    buffLenPointer.write(initialLen);
    WCharPointer userHome = StackValue.get(initialLen, WCharPointer.class);
    // The following call does not support retry on failures if the content does not fit in the
    // buffer.
    // For now this is the intended implementation as it simplifies it and it will be revised in
    // the future
    int result = WinBase.GetUserProfileDirectoryW(tokenHandle.read(), userHome, buffLenPointer);
    WinBase.CloseHandle(tokenHandle.read());
    if (result == 0) {
        // matches openjdk
        return "C:\\";
    }
    return toJavaString(userHome, buffLenPointer.read() - 1);
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WinBase(com.oracle.svm.core.windows.headers.WinBase) WCharPointer(com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer)

Aggregations

WCharPointer (com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer)6 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)2 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)1 WinBase (com.oracle.svm.core.windows.headers.WinBase)1 HANDLE (com.oracle.svm.core.windows.headers.WinBase.HANDLE)1 UnsignedWord (org.graalvm.word.UnsignedWord)1