Workplace Widget 5.10.23
This commit is contained in:
135
hmi-docs/cheerpj/NativeLoaderSmoke.java
Normal file
135
hmi-docs/cheerpj/NativeLoaderSmoke.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package com.widgetworkbench.cheerpj;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Java 11/55 classfile, browser-only troubleshooting program. No proprietary
|
||||
* libraries, MES calls, credentials, or changes to JVM/UnixSystem classes.
|
||||
* Every invocation tests exactly ONE mode in a fresh browser page.
|
||||
*
|
||||
* direct - native method via cheerpjInit({natives}); no loadLibrary call
|
||||
* wwprobe - System.loadLibrary("wwprobe")
|
||||
* jaas - System.loadLibrary("jaas")
|
||||
* unix - construct the real JDK UnixSystem, hitting its native load
|
||||
* bridge - validate the Java helper independently of native loading;
|
||||
* an instance allocated WITHOUT UnixSystem's constructor is
|
||||
* used ONLY for this standalone diagnostic. Not a login path.
|
||||
* environment - benign JDK/module settings (no usernames printed)
|
||||
* sysprop - check whether user.name is present (never print its value)
|
||||
*/
|
||||
public final class NativeLoaderSmoke {
|
||||
private NativeLoaderSmoke() {}
|
||||
private static native int ping();
|
||||
|
||||
public static void main(String[] args) {
|
||||
final String mode = args.length > 0 ? args[0] : "environment";
|
||||
System.out.println("[NATIVE-LOADER] JAVA_VERSION=" + System.getProperty("java.version"));
|
||||
System.out.println("[NATIVE-LOADER] JAVA_LIBRARY_PATH=" + System.getProperty("java.library.path"));
|
||||
System.out.println("[NATIVE-LOADER] MODE=" + mode);
|
||||
try {
|
||||
switch (mode) {
|
||||
case "direct":
|
||||
System.out.println("[NATIVE-LOADER] DIRECT_NATIVES: ping WITHOUT System.loadLibrary");
|
||||
verifyPing();
|
||||
pass("DIRECT_NATIVES");
|
||||
break;
|
||||
case "wwprobe":
|
||||
case "jaas":
|
||||
System.out.println("[NATIVE-LOADER] LOAD_ATTEMPT=" + mode);
|
||||
System.loadLibrary(mode);
|
||||
System.out.println("[NATIVE-LOADER] LOAD_SUCCESS=" + mode);
|
||||
if ("wwprobe".equals(mode)) verifyPing();
|
||||
pass("MODULE_LOADER_" + mode);
|
||||
break;
|
||||
case "unix":
|
||||
testUnixConstructor();
|
||||
break;
|
||||
case "bridge":
|
||||
testBridgeWithoutUnixConstructor();
|
||||
break;
|
||||
case "sysprop":
|
||||
final String user = System.getProperty("user.name");
|
||||
System.out.println("[NATIVE-LOADER] USER_NAME_PRESENT=" + (user != null && !user.isEmpty()));
|
||||
System.out.println("[NATIVE-LOADER] OS_NAME_PRESENT=" + (System.getProperty("os.name") != null));
|
||||
pass("SYSTEM_PROPERTIES");
|
||||
break;
|
||||
case "environment":
|
||||
System.out.println("[NATIVE-LOADER] JAVA_VENDOR=" + System.getProperty("java.vendor"));
|
||||
System.out.println("[NATIVE-LOADER] JAVA_HOME=" + System.getProperty("java.home"));
|
||||
System.out.println("[NATIVE-LOADER] JAVA_CLASS_VERSION=" + System.getProperty("java.class.version"));
|
||||
Class<?> cls = Class.forName("com.sun.security.auth.module.UnixSystem", false,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
System.out.println("[NATIVE-LOADER] UNIX_CLASS_PRESENT=" + (cls != null));
|
||||
System.out.println("[NATIVE-LOADER] UNIX_MODULE=" + cls.getModule().getName());
|
||||
System.out.println("[NATIVE-LOADER] UNIX_MODULE_EXPORTED=" + cls.getModule()
|
||||
.isExported("com.sun.security.auth.module"));
|
||||
pass("ENVIRONMENT");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unbekannter Testmodus");
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
System.err.println("[NATIVE-LOADER] FAIL " + mode + ": " + error.getClass().getName());
|
||||
// Reflective wrappers are printed, including their full cause chain.
|
||||
error.printStackTrace(System.err);
|
||||
if (error instanceof InvocationTargetException) {
|
||||
Throwable root = ((InvocationTargetException) error).getTargetException();
|
||||
if (root != null) {
|
||||
System.err.println("[NATIVE-LOADER] ROOT_CAUSE=" + root.getClass().getName());
|
||||
root.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
System.exit(31);
|
||||
}
|
||||
}
|
||||
|
||||
private static void pass(String label) {
|
||||
System.out.println("[NATIVE-LOADER] PASS " + label);
|
||||
}
|
||||
|
||||
private static void verifyPing() {
|
||||
int value = ping();
|
||||
System.out.println("[NATIVE-LOADER] NATIVE_CALL_RESULT=" + value);
|
||||
if (value != 42) throw new IllegalStateException("Expected 42, got " + value);
|
||||
}
|
||||
|
||||
private static void testUnixConstructor() throws Exception {
|
||||
Class<?> type = Class.forName("com.sun.security.auth.module.UnixSystem");
|
||||
System.out.println("[NATIVE-LOADER] UNIX_CONSTRUCTOR_ATTEMPT");
|
||||
Constructor<?> constructor = type.getConstructor();
|
||||
Object instance = constructor.newInstance();
|
||||
Method getter = type.getMethod("getUsername");
|
||||
Object name = getter.invoke(instance);
|
||||
// Do not print the operating-system identity to the diagnostic log.
|
||||
System.out.println("[NATIVE-LOADER] UNIX_USERNAME_PRESENT=" + (name != null));
|
||||
pass("UNIX_CONSTRUCTOR");
|
||||
}
|
||||
|
||||
private static void testBridgeWithoutUnixConstructor() throws Exception {
|
||||
System.out.println("[NATIVE-LOADER] BRIDGE: Unsafe.allocateInstance only for test");
|
||||
Class<?> unsafeType = Class.forName("sun.misc.Unsafe");
|
||||
Field singleton = unsafeType.getDeclaredField("theUnsafe");
|
||||
if (!singleton.trySetAccessible()) throw new IllegalStateException("Unsafe unavailable");
|
||||
Object unsafe = singleton.get(null);
|
||||
Class<?> unixType = Class.forName("com.sun.security.auth.module.UnixSystem", false,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
// This test deliberately never calls UnixSystem.<init> or System.loadLibrary.
|
||||
Object object = unsafeType.getMethod("allocateInstance", Class.class)
|
||||
.invoke(unsafe, unixType);
|
||||
String value = JaasIdentityBridge.populate(object);
|
||||
if (!JaasIdentityBridge.VIRTUAL_USER.equals(value)) {
|
||||
throw new IllegalStateException("Synthetic identity did not match");
|
||||
}
|
||||
long uid = ((Number) unixType.getMethod("getUid").invoke(object)).longValue();
|
||||
long gid = ((Number) unixType.getMethod("getGid").invoke(object)).longValue();
|
||||
long[] groups = (long[]) unixType.getMethod("getGroups").invoke(object);
|
||||
if (uid != 65534L || gid != 65534L || groups.length != 0) {
|
||||
throw new IllegalStateException("Synthetic UnixSystem fields incomplete");
|
||||
}
|
||||
System.out.println("[NATIVE-LOADER] BRIDGE_IDENTITY_FIELDS_OK=true");
|
||||
pass("BRIDGE_WITHOUT_CONSTRUCTOR");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user