Transform signlink code for loading and unloading native libraries in the client #107

Open
opened 4 years ago by gpe · 0 comments
gpe commented 4 years ago
Owner

There are some problems with the current code.

The client invokes Runtime.load0() and Runtime.loadLibrary0() with reflection:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by Class196 (file:/home/gpe/code/openrs2/openrs2/nonfree/signlink/out/production/classes/) to method java.lang.Runtime.load0(java.lang.Class,java.lang.String)
WARNING: Please consider reporting this to the maintainers of Class196
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

This will break in future versions of Java.

I think the client does this because the signlink, which runs in the loader's ClassLoader, is used to load the library, but it actually needs to be loaded in the client's ClassLoader. As far as I can see, there's no public API for doing this, necessitating the use of reflection.

Simply replacing the calls with Runtime.load() and Runtime.loadLibrary() might break the client when it is run by the loader in an applet. This is something I care about because I intend to run the client inside an applet viewer.

I'm not yet sure of the best way to fix this.

Desetude spotted that the code for unloading native libraries doesn't work in current versions of Java, as the nativeLibraries field in the ClassLoader class is no longer a Vector (it is now a ConcurrentHashMap).

This isn't particularly problematic, as the code is only called when the client is exiting, but I think it'd be nice to make the code a no-op. Apparently native libraries are unloaded automatically when the ClassLoader is garbage-collected, so we can just rely on that.

There are some problems with the current code. The client invokes `Runtime.load0()` and `Runtime.loadLibrary0()` with reflection: ``` WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by Class196 (file:/home/gpe/code/openrs2/openrs2/nonfree/signlink/out/production/classes/) to method java.lang.Runtime.load0(java.lang.Class,java.lang.String) WARNING: Please consider reporting this to the maintainers of Class196 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release ``` This will break in future versions of Java. I think the client does this because the signlink, which runs in the loader's ClassLoader, is used to load the library, but it actually needs to be loaded in the client's ClassLoader. As far as I can see, there's no public API for doing this, necessitating the use of reflection. Simply replacing the calls with `Runtime.load()` and `Runtime.loadLibrary()` might break the client when it is run by the loader in an applet. This is something I care about because I intend to run the client inside an applet viewer. I'm not yet sure of the best way to fix this. Desetude spotted that the code for unloading native libraries doesn't work in current versions of Java, as the `nativeLibraries` field in the `ClassLoader` class is no longer a `Vector` (it is now a `ConcurrentHashMap`). This isn't particularly problematic, as the code is only called when the client is exiting, but I think it'd be nice to make the code a no-op. Apparently native libraries are unloaded automatically when the `ClassLoader` is garbage-collected, so we can just rely on that.
gpe added the
patcher
improvement
labels 4 years ago
Sign in to join this conversation.
Loading…
There is no content yet.