Hooder 35949bce22 gpu: Fix loading gluegen natives on some Windows configurations
This commit works around a bug with loading natives when the user's home
folder contains special characters such as `&`, `^` or `!`.

When Gluegen loads native libraries on Windows, it uses a temporary
directory located in `%appdata%` under the user's home directory, and
Gluegen checks whether files can be executed from this temporary
directory. To perform this check, it writes an executable to the
directory, executes it, and ensures that the return code is zero. The
executable file it writes is by default a `.bat` file, but it can be
told to write an `.exe` file instead by supplying this VM argument:
`-Djogamp.gluegen.UseNativeExeFile=true`.

The default behaviour of writing and executing a `.bat` file is broken
when the path to the temp folder contains a special character, due to a
convoluted trail of calls that leads to undefined behaviour:
- Gluegen attempts to execute the `.bat` file by calling `Runtime.exec()`:
  `Runtime.exec(new String[] { "...absolute path...bat" }, null, null)`
- OpenJDK 11.0.8 passes the command to `ProcessBuilder`, which calls
  `ProcessImpl.start(...)`, which creates a new `ProcessImpl` instance.
- In the `ProcessImpl` constructor, there are two different character
  escape modes:
  - **Legacy mode**, which allows ambiguous commands.
  - **Non-legacy mode**, which does more rigorous escaping.
- Legacy is the default mode as long as `System.getSecurityManager()`
  returns `null`, which is the case for RuneLite currently.
  This mode can be changed by supplying the following VM argument:
  `-Djdk.lang.Process.allowAmbiguousCommands=false`.
  - Incidentally this also fixes the issue of loading natives with
    special characters in the path, however it applies to *all*
    `Runtime.exec()` calls.
- In legacy mode, the command is wrapped in quotes if it contains either
  a space or tab character. The command is then passed along to the
  native function `Java_java_lang_ProcessImpl_create`, which eventually
  passes it along untouched to Microsoft's `CreateProcessW` function as
  the `lpCommandLine` argument.
- In the documentation for this function, it is mentioned that an
  interpreter (i.e. `cmd.exe`) is required in order to run a `.bat`
  file. It is not specified what will happen if you instead pass the
  path to a `.bat` file directly to the function, which is what Gluegen
  ends up doing. However, `CreateProcessW` *does* support supplying the
  path to an `.exe`, which Gluegen will do when
  `jogamp.gluegen.UseNativeExeFile` is set to `true`.

It is unclear why supplying a `.bat` file normally works, yet breaks
when special characters are in the path. It seems like it should not
work in the first place.

This might help with #6509 and #14180.

Some other special characters, like Cyrillic letters, are more
fundamentally broken in RuneLite. This patch only slightly helps with
that.
2022-02-23 11:53:51 -05:00
2021-12-18 15:17:28 -05:00
2017-07-19 20:55:57 -04:00
2022-02-23 11:55:21 +00:00
2022-02-23 11:55:21 +00:00
2022-02-23 11:55:21 +00:00
2022-02-23 11:55:21 +00:00
2022-02-23 11:55:21 +00:00
2020-01-05 17:31:14 +00:00
2021-12-25 14:12:38 -05:00
2017-06-29 17:27:28 -04:00
2022-02-23 11:55:21 +00:00
2021-12-24 13:19:45 -05:00

runelite CI Discord

RuneLite is a free, open source OldSchool RuneScape client.

If you have any questions, please join our IRC channel on irc.rizon.net #runelite or alternatively our Discord server.

Project Layout

  • cache - Libraries used for reading/writing cache files, as well as the data in it
  • runelite-api - RuneLite API, interfaces for accessing the client
  • runelite-client - Game client with plugins

Usage

Open the project in your IDE as a Maven project, build the root module and then run the RuneLite class in runelite-client.
For more information visit the RuneLite Wiki.

License

RuneLite is licensed under the BSD 2-clause license. See the license header in the respective file to be sure.

Contribute and Develop

We've set up a separate document for our contribution guidelines.

Description
No description provided
Readme BSD-2-Clause 107 MiB
Languages
Java 98.9%
GLSL 0.7%
C 0.3%