Search in sources :

Example 1 with WCharPointer

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

the class WindowsImageHeapProvider method createImageHeapFileMapping.

/**
 * Returns a handle to the image heap file mapping or the null pointer in case of an error.
 */
@Uninterruptible(reason = "Called during isolate initialization.", mayBeInlined = true)
private static HANDLE createImageHeapFileMapping() {
    /* Get the path of the file that contains the image heap. */
    WCharPointer filePath = StackValue.get(WinBase.MAX_PATH, WCharPointer.class);
    int length = LibLoaderAPI.GetModuleFileNameW((HMODULE) IMAGE_BASE.get(), filePath, WinBase.MAX_PATH);
    if (length == 0 || length == WinBase.MAX_PATH) {
        return WordFactory.nullPointer();
    }
    /* Open the file for mapping. */
    HANDLE fileHandle = FileAPI.CreateFileW(filePath, FileAPI.GENERIC_READ(), FileAPI.FILE_SHARE_READ() | FileAPI.FILE_SHARE_DELETE(), WordFactory.nullPointer(), FileAPI.OPEN_EXISTING(), 0, WordFactory.nullPointer());
    if (fileHandle.equal(WinBase.INVALID_HANDLE_VALUE())) {
        return WordFactory.nullPointer();
    }
    /* Create the mapping and close the file. */
    HANDLE fileMapping = MemoryAPI.CreateFileMappingW(fileHandle, WordFactory.nullPointer(), MemoryAPI.PAGE_READONLY(), 0, 0, WordFactory.nullPointer());
    WinBase.CloseHandle(fileHandle);
    return fileMapping;
}
Also used : WCharPointer(com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer) HANDLE(com.oracle.svm.core.windows.headers.WinBase.HANDLE) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 2 with WCharPointer

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

the class WindowsSystemPropertiesFeature method userNameValue.

@Override
protected String userNameValue() {
    WCharPointer userName = WindowsLibC._wgetenv(NonmovableArrays.addressOf(NonmovableArrays.fromImageHeap(USERNAME), 0));
    if (userName.isNonNull()) {
        UnsignedWord length = WindowsLibC.wcslen(userName);
        if (length.aboveThan(0)) {
            return toJavaString(userName, Math.toIntExact(length.rawValue()));
        }
    }
    int maxLength = WinBase.UNLEN + 1;
    userName = StackValue.get(maxLength, WCharPointer.class);
    CIntPointer lengthPointer = StackValue.get(CIntPointer.class);
    lengthPointer.write(maxLength);
    if (WinBase.GetUserNameW(userName, lengthPointer) != 0) {
        return toJavaString(userName, lengthPointer.read() - 1);
    }
    return "unknown";
/* matches openjdk */
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) UnsignedWord(org.graalvm.word.UnsignedWord) WCharPointer(com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer)

Example 3 with WCharPointer

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

the class WindowsSystemPropertiesFeature method tmpdirValue.

@Override
protected String tmpdirValue() {
    int maxLength = WinBase.MAX_PATH + 1;
    WCharPointer tmpdir = StackValue.get(maxLength, WCharPointer.class);
    int length = FileAPI.GetTempPathW(maxLength, tmpdir);
    VMError.guarantee(length > 0, "Could not determine value of java.io.tmpdir");
    return toJavaString(tmpdir, length);
}
Also used : WCharPointer(com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer)

Example 4 with WCharPointer

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

the class WindowsSystemPropertiesFeature method userDirValue.

@Override
protected String userDirValue() {
    int maxLength = WinBase.MAX_PATH;
    WCharPointer userDir = StackValue.get(maxLength, WCharPointer.class);
    int length = WinBase.GetCurrentDirectoryW(maxLength, userDir);
    VMError.guarantee(length > 0 && length < maxLength, "Could not determine value of user.dir");
    return toJavaString(userDir, length);
}
Also used : WCharPointer(com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer)

Example 5 with WCharPointer

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

the class WindowsSystemPropertiesFeature method javaLibraryPathValue.

@Override
protected String javaLibraryPathValue() {
    /*
         * Adapted from `os::init_system_properties_values` in
         * `src/hotspot/os/windows/os_windows.cpp`, but omits HotSpot specifics.
         */
    int tmpLength;
    WCharPointer tmp = StackValue.get(WinBase.MAX_PATH, WCharPointer.class);
    WCharPointer path = WindowsLibC._wgetenv(NonmovableArrays.addressOf(NonmovableArrays.fromImageHeap(PATH), 0));
    int pathLength = path.isNonNull() ? Math.toIntExact(WindowsLibC.wcslen(path).rawValue()) : 0;
    StringBuilder libraryPath = new StringBuilder(3 * WinBase.MAX_PATH + pathLength + 5);
    /* Add the directory from which application is loaded. */
    tmpLength = LibLoaderAPI.GetModuleFileNameW(WordFactory.nullPointer(), tmp, WinBase.MAX_PATH);
    VMError.guarantee(tmpLength > 0 && tmpLength < WinBase.MAX_PATH);
    libraryPath.append(asCharBuffer(tmp, tmpLength));
    /* Get rid of `\<filename>.exe`. */
    libraryPath.setLength(libraryPath.lastIndexOf("\\"));
    /* Add System directory. */
    tmpLength = SysinfoAPI.GetSystemDirectoryW(tmp, WinBase.MAX_PATH);
    VMError.guarantee(tmpLength > 0 && tmpLength < WinBase.MAX_PATH);
    libraryPath.append(';');
    libraryPath.append(asCharBuffer(tmp, tmpLength));
    /* Add Windows directory. */
    tmpLength = SysinfoAPI.GetWindowsDirectoryW(tmp, WinBase.MAX_PATH);
    VMError.guarantee(tmpLength > 0 && tmpLength < WinBase.MAX_PATH);
    libraryPath.append(';');
    libraryPath.append(asCharBuffer(tmp, tmpLength));
    /* Add the PATH environment variable. */
    if (path.isNonNull()) {
        libraryPath.append(';');
        libraryPath.append(asCharBuffer(path, pathLength));
    }
    /* Add the current directory. */
    libraryPath.append(";.");
    return libraryPath.toString();
}
Also used : 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