--native-test LIB [SYMBOL...] loads a library through the bridge and calls its functions. Done:
the loader, with DT_ANDROID_RELA (packed) and DT_RELR relocations, dlopen, dlsym and
dl_iterate_phdr,
the JIT, whose cache makes a second load of a 362 MB engine library and its 864 constructors take 1.8 s (170 s the first time). The code window is at a fixed address (256 GiB), since the cache is keyed by the code's addresses,
each thread's CPU state, guest stack and bionic TLS slots, pthread_create, keys with destructors,
libc's string, memory, stdio, file, socket, time and math functions, most of them the host's own, with the
conversions of struct stat, the open flags, sysconf, epoll_event, addrinfo, sigset_t and the system call
numbers, and the guest's printf and scanf.
setjmp and longjmp as guest code in the code window (hle_code.c): they move the guest's own registers and
stack, which a host function can't,
the imports that are objects: __sF and stdin to stderr, _ctype_, environ, getopt's and the time zone's,
OpenSL ES's interface IDs (its engine reports that OpenSL ES is not there, for now) and libmediandk's format keys.
JNI: the guest's JNIEnv and JavaVM are tables of exports over the host JVM's functions, called through one
adapter (hle_call) that passes x0 to x5 and v0 to v7 as the host's integer and floating registers, which
AAPCS64 and the System V ABI fill in the same order. The calls with variable arguments read them by the signature
that GetMethodID recorded. FindClass falls back to the app's class loader within the app's native methods and
the loads of its libraries, as Android's uses the loader of the class whose native method runs; on a thread with
none (one the app attached) it has the system class loader alone, and an app's class is a ClassNotFoundException,
as on ART. GetVersion is Android's JNI 1.6, not the host JDK's. The string functions' modified UTF-8 is ART's:
a supplementary character is UTF-8's 4 bytes both ways, where HotSpot's CESU-8 has 6 (and its NewStringUTF ends
the string at a 4-byte sequence). RegisterNatives records the guest's functions.
The translator gives each native method a body that calls NativeBridge.invoke* with its key, the object and its
parameters (primitives as bits in a long[], references in an Object[]). The bridge finds the function by
RegisterNatives or by its JNI name, and passes the parameters as AAPCS64 does.
All 24 libraries of the Unity game load and run their constructors. From Java, System.loadLibrary loads them and
runs their JNI_OnLoad: the game's crash reporter initializes its native side. An import without an HLE yet is an export that
says so once when called and returns 0, in x0 and in v0.
The recompiler's android target (a64.profile) is a phone's Armv8.2 CPU without pointer authentication, and
getauxval(AT_HWCAP) reports the same features.
libandroid: ANativeWindow is the SurfaceView's surface, which is the host window at the view's size. The looper
is an epoll set, the sensor manager has no sensors, and AAssetManager reads the assets of the APK and its splits.
A stored asset opens as its APK's file descriptor with the asset's place in it.
the Vulkan pass-through (hle_vulkan.c): each vk* command the guest names is the host loader's, called with the
guest's arguments by hle_call_wide (up to 12 integers, the guest's stack slots past x7). The instance's
VK_KHR_android_surface becomes SDL's surface extensions or VK_EXT_headless_surface, the surface is the SDL
window's (ScarletNX's renderer gives the window up), the guest's allocation callbacks and debug messengers are left
out, and the device reports itself a Mali-G710 with ARM's vendor and driver IDs, its limits and features the
host's. A present blends the windows of the app's Java side over the image when one shows (HWUI's layer). A surface's current extent is the native window's size, as an Android surface's always is (a Wayland or
headless surface leaves it to the swapchain). A Unity game's engine reaches it, makes its swapchain on the window
and presents its first frames (lavapipe here),
EGL gives the GPU's identity alone: a display, contexts without a config or a surface, and glGetString with the
device that Vulkan reports, which engines read before they choose an API. Nothing draws through GLES, on purpose.
--sample also prints the count of the guest's Vulkan presents, and asks each thread in guest code
for its pc at its next poll, so a loop's pc is its own and not that of its last call.
Next: OpenSL ES and the media codecs.
Made from docs/platforms/android-apps/native.md at 69237645142c. GPL-3.0-or-later.