Compare commits

...
7 changed files with 382 additions and 1 deletions

No files matched your search

@@ -16,7 +16,7 @@ object DeviceInfo {
val vk = VulkanInfo.query()
val gpu = GpuInfo.detect()
return listOf(
chip(), gpu(context, gpu), cpu(), memory(context), system(), vulkan(context, vk), drivers(context, gpu),
chip(), gpu(context, gpu), npu(context), cpu(), memory(context), system(), vulkan(context, vk), drivers(context, gpu),
).filter { it.rows.isNotEmpty() }
}
@@ -51,6 +51,10 @@ object DeviceInfo {
add("Family", read("/sys/devices/soc0/family"))
})
private fun npu(context: Context) = Section("NPU", NpuInfo.rows(
NpuInfo.detect(context.applicationInfo.nativeLibraryDir?.let(::File)),
))
private fun gpu(context: Context, gpu: GpuInfo) = Section("GPU", buildList<Pair<String, String>> {
add("GPU", gpu.name)
add("Family", gpu.family.label(gpu.name))
@@ -0,0 +1,71 @@
package com.droiddeck.launcher.gpu
import java.io.File
/** What this device's Qualcomm Hexagon NPU would offer a neural upscaler, and whether the app can reach it. */
object NpuInfo {
enum class Hexagon(val arch: String, val vtcmMb: Int) {
V68("v68", 4), V69("v69", 4), V73("v73", 4), V75("v75", 8), V79("v79", 8), V81("v81", 8),
}
enum class Access { OPEN, BROKERED, NO_NODE, DENIED }
data class Status(
val hexagon: Hexagon?,
val node: String?,
val access: Access,
val qnnRuntime: Boolean,
) {
val usable: Boolean get() = hexagon != null && (access == Access.OPEN || access == Access.BROKERED) && qnnRuntime
}
private val BY_MODEL = mapOf(
"SM8350" to Hexagon.V68, "SM8450" to Hexagon.V69, "SM8475" to Hexagon.V69,
"SM8550" to Hexagon.V73, "QCS8550" to Hexagon.V73, "SM8650" to Hexagon.V75,
"SM8750" to Hexagon.V79, "SM8850" to Hexagon.V81,
)
private val BY_PLATFORM = mapOf(
"lahaina" to Hexagon.V68, "taro" to Hexagon.V69, "cape" to Hexagon.V69, "kalama" to Hexagon.V73,
"pineapple" to Hexagon.V75, "sun" to Hexagon.V79, "canoe" to Hexagon.V81,
)
// The compute DSP is the one that runs HTP graphs; /dev/adsprpc-smd is the pre-5.x name of the same service.
internal val NODES = listOf("/dev/fastrpc-cdsp", "/dev/adsprpc-smd", "/dev/cdsprpc-smd")
// Qualcomm's dspservice hands an app a FastRPC fd over binder when the node itself is closed to apps.
internal const val DSP_SERVICE_MANIFEST = "/vendor/etc/vintf/manifest/vendor.qti.hardware.dsp-service.xml"
internal val QNN_LIBS = listOf("libQnnHtp.so", "libQnnSystem.so")
fun hexagon(
model: String = SocNames.model(),
platform: String = GpuInfo.systemProperty("ro.board.platform"),
): Hexagon? = BY_MODEL[SocNames.normalizedModel(model)] ?: BY_PLATFORM[platform.trim().lowercase()]
/** `canWrite` is access(2) for the app's own uid, so it answers for DAC but not SELinux. */
internal fun access(nodes: List<File>, broker: File = File(DSP_SERVICE_MANIFEST)): Pair<File?, Access> {
val present = nodes.firstOrNull { it.exists() } ?: return null to Access.NO_NODE
val access = when {
present.canRead() && present.canWrite() -> Access.OPEN
broker.exists() -> Access.BROKERED
else -> Access.DENIED
}
return present to access
}
fun detect(nativeLibDir: File?, hexagon: Hexagon? = hexagon()): Status {
val (node, access) = access(NODES.map(::File))
val qnn = nativeLibDir != null && QNN_LIBS.all { File(nativeLibDir, it).exists() }
return Status(hexagon, node?.path, access, qnn)
}
fun rows(status: Status): List<Pair<String, String>> = buildList {
add("Hexagon" to (status.hexagon?.let { "${it.arch} (${it.vtcmMb} MB VTCM)" } ?: "not recognised"))
add("FastRPC node" to when (status.access) {
Access.NO_NODE -> "none found"
Access.OPEN -> "${status.node} (app can open it)"
Access.BROKERED -> "${status.node} (closed to apps; the DSP service can hand over a descriptor)"
Access.DENIED -> "${status.node} (app cannot open it)"
})
add("QNN runtime" to if (status.qnnRuntime) "bundled" else "not bundled")
add("Neural upscaling" to if (status.usable) "possible" else "not available")
}
}
@@ -0,0 +1,49 @@
package com.droiddeck.launcher.gpu
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
class NpuInfoTest {
@get:Rule val tmp = TemporaryFolder()
@Test fun modelPicksTheHexagonGenerationAndFallsBackToThePlatform() {
assertEquals(NpuInfo.Hexagon.V79, NpuInfo.hexagon("SM8750", "sun"))
assertEquals(NpuInfo.Hexagon.V81, NpuInfo.hexagon("QTI SM8850", ""))
assertEquals(NpuInfo.Hexagon.V73, NpuInfo.hexagon("", "Kalama"))
assertNull(NpuInfo.hexagon("MT6989", "mt6989"))
}
@Test fun nodeAccessSeparatesMissingFromDenied() {
assertEquals(NpuInfo.Access.NO_NODE, NpuInfo.access(listOf(File(tmp.root, "nope"))).second)
val node = tmp.newFile("fastrpc-cdsp")
assertEquals(NpuInfo.Access.OPEN, NpuInfo.access(listOf(File(tmp.root, "nope"), node)).second)
node.setWritable(false)
val absent = File(tmp.root, "no-broker")
if (!node.canWrite()) {
assertEquals(NpuInfo.Access.DENIED, NpuInfo.access(listOf(node), absent).second)
assertEquals(NpuInfo.Access.BROKERED, NpuInfo.access(listOf(node), tmp.newFile("dsp-service.xml")).second)
}
}
@Test fun usableNeedsChipNodeAndRuntime() {
val ok = NpuInfo.Status(NpuInfo.Hexagon.V79, "/dev/fastrpc-cdsp", NpuInfo.Access.OPEN, true)
assertTrue(ok.usable)
assertTrue(ok.copy(access = NpuInfo.Access.BROKERED).usable)
assertFalse(ok.copy(access = NpuInfo.Access.DENIED).usable)
assertFalse(ok.copy(qnnRuntime = false).usable)
assertFalse(ok.copy(hexagon = null).usable)
}
@Test fun runtimeIsBundledOnlyWhenEveryLibraryIsPresent() {
NpuInfo.QNN_LIBS.dropLast(1).forEach { File(tmp.root, it).createNewFile() }
assertFalse(NpuInfo.detect(tmp.root, NpuInfo.Hexagon.V79).qnnRuntime)
File(tmp.root, NpuInfo.QNN_LIBS.last()).createNewFile()
assertTrue(NpuInfo.detect(tmp.root, NpuInfo.Hexagon.V79).qnnRuntime)
}
}
+129
View File
@@ -0,0 +1,129 @@
# Neural upscaling on the Hexagon NPU
Reference: [Winlator-NeuralScale](https://github.com/michaelisomer-cyber/Winlator-NeuralScale), a Winlator fork that
runs AMD FSR 4 on the Qualcomm Hexagon HTP through QNN, with GPU (DP4a) FSR 4 / XeSS / FSR 3.1 fallbacks. This note
records what carries over to DroidDeck, what does not, and what has been built so far.
## How the reference works
A Vulkan layer in the game's process intercepts the game's own upscaler calls (FSR 2/3/4, DLSS through an NGX
bridge, XeSS) via replacement DLLs. Those calls hand over colour, depth, motion vectors, exposure and jitter. The
layer runs the FSR 4 network (INT8, compiled on the device by `libQnnHtpPrepare.so`) on the NPU, with Vulkan passes
before and after it and `AHardwareBuffer` for the hand-off.
## What carries over, what does not
| Piece | In DroidDeck |
|---|---|
| Game-side hook (DLL replacement, NGX/FFX bridges) | The guest runs Steam under FEX and Proton, so the same Windows-side bridge DLLs could apply, but nothing in the repo loads them yet. |
| Temporal inputs (depth, motion vectors, jitter) | Only exist inside the guest. The Wayland compositor (`waylandcomp`, where FSR 1 / SGSR / frame generation run) sees a finished colour frame, so FSR 4 cannot run there. A compositor-side network would have to be a spatial-only super-resolution model, a different thing from FSR 4. |
| QNN runtime and skel libraries | Qualcomm's, not redistributable here. They would come from the user's own QAIRT SDK or a runtime download. |
| FSR 4 weights | AMD's. The reference ships them in its APK; DroidDeck should not copy them without a licence check. |
| DP4a GPU path | Independent of the NPU and the most portable part. Needs the same guest-side hook. |
## Findings: the NPU is reachable from an unprivileged app
Tested on the Retroid Pocket Duo (SM8750, Hexagon v79) and the AYANEO Pocket FIT Elite (SM8750P, stock, no root).
**The node is closed, but there is a supported way around it.**
- `/dev/fastrpc-cdsp` is `0664 system:system` and the two `-secure` nodes are `0644`. A real app uid (checked with
`run-as` as uid 10185) fails `access(W_OK)`. This is Qualcomm's own `ueventd` setting, not an OEM quirk.
- Qualcomm's `libcdsprpc.so` is not loadable by an app on this firmware: `libcdsprpc.so` and even `libOpenCL.so` fail
with "not found" from an app namespace, with or without `<uses-native-library>`, and a copy would need private
system libraries (`libutils`, `libhidlbase`, `libcutils`). So QNN stubs that `dlopen("libcdsprpc.so")` fail today.
- The vendor AIDL service `vendor.qti.hardware.dsp.IDspService/default` (process `dspservice`, uid `system`) opens
the node on behalf of callers. From the app, `AServiceManager_checkService` returns it,
`getNewDSPSession(int)` returns an `IDspManager`, and `openSession(DSPDomain)` returns a `FastrpcDev` whose
`NativeHandle` carries an open descriptor for `/dev/fastrpc-cdsp`. `readlink` on it gives `/dev/fastrpc-cdsp`.
- On that descriptor, from the app: `FASTRPC_IOCTL_GET_DSP_INFO` (`_IOWR('R', 13, ...)`) succeeds and reports
unsigned-PD support (attribute 1 = 1). `FASTRPC_IOCTL_INIT_ATTACH` returns `EACCES`, and the kernel logs "untrusted
app trying to attach to privileged DSP PD". That is the expected outcome: an app must create an unsigned PD
(`INIT_CREATE`) instead of attaching to the root PD.
Wire format that worked (transaction codes are the AIDL order): `IDspService` 1 = `getNewDSPSession(int)`;
`IDspManager` 2 = `openSession`. The `in DSPDomain` argument is written as `[1 (non-null)][size][domain]`; domain 3 is
the compute DSP. The reply is `[status][1][size][int][int][NativeHandle: size, fd count, fds, int count]`.
`tools/experiments/npu-fastrpc-probe` reproduces all of it; results go to logcat tag `NPUPROBE`.
### AYN Thor (QCS8550, Hexagon v73, Android 13, release-keys): closed
- `/dev/adsprpc-smd` is `0664 system:system` and `open(O_RDWR)` from an app gives `EACCES`. There is no
`/dev/fastrpc-cdsp`.
- There is no `IDspService` here. `checkService` returns null, and SELinux logs a `find` denial for
`untrusted_app` on `default_android_service`.
- `dlopen("libcdsprpc.so")` fails with "not found" even with `<uses-native-library>` declared.
- So no route was found on this device without root. SELinux is enforcing here, which is the case the 8 Elite tests
could not cover.
### How BananaNative's PR (moceure/BananaNative #703) gets in
It declares `<uses-native-library android:name="libcdsprpc.so" android:required="false"/>`, then
`dlopen("libcdsprpc.so")`, `remote_handle_control(4, {domain 3, enable 1})` to request an unsigned PD, and an
`ADSP_LIBRARY_PATH` that puts the app's own `adsp` directory first so the DSP can load the HTP skel from the app.
That only works on firmware that exposes the vendor library to apps; its logs are from a Xiaomi phone on a v81 SoC.
It does not work on the three Qualcomm-reference style builds tried here (Duo, FIT Elite, Thor), where the library is
invisible to app namespaces. Useful from it, if the NPU path goes ahead: a process-wide ref-counted QNN HTP runtime
shared by two users, zero-copy `AHardwareBuffer` DMA-BUF registration, a thermal power tier (turbo, balanced, low)
with hysteresis, and clamping the ADPF target duration to the frame-generated output period so the PowerHAL does not
halve a 2x frame-generated game. Its MIT-licensed GLSL for flow, splat and blend is a possible reference for DD-FG.
Its QNN graph binaries come from a companion repo; where they derive from is a licence question.
Caveats:
- SELinux is permissive on both devices (dev-keys builds). On an enforcing production build, `untrusted_app` may not
be allowed to find `IDspService`, and that has not been tried.
- Nothing has run on the NPU yet. A descriptor and a capability query are not a graph execution.
- The reference fork does not need any of this on devices where the node is world-writable.
## vk-fsr4 (han39835/vk-fsr4, GPL-3.0): FSR 4 INT8 on the GPU, no NPU
An implicit Vulkan layer plus a drop-in replacement for AMD's `amd_fidelityfx_upscaler_vk` provider. It runs FSR 4.1.2
as INT8 compute shaders on any Vulkan GPU with `shaderInt8` and `shaderIntegerDotProduct` (DP4a), and keeps the
cooperative-matrix FP8 path for RDNA 3/4. Aimed at AMD and Linux, but nothing in the INT8 path is vendor specific.
- **Assets:** 31 MB of precompiled SPIR-V for INT8 (1080, 2160 and 4320 tiers, each in `native` and `ultraperf`) plus
quantised weights. The DXIL from AMD's DLL was converted to SPIR-V at build time with `dxil-spirv`, which is not
linked into the provider. The tools to repeat that are in the repo (`tools/extract`, `tools/convert`).
- **Two entry points.** As an FFX provider, games that already call FSR 3/4 through the FFX API get FSR 4 with the
game's own motion vectors, depth and jitter: the exact inputs, and the most robust option. As a layer without the
API (`F4_MV=1`), it guesses which descriptor holds the motion vectors by fingerprinting Unreal TSR layouts. The
author says other engines "may or may not match", so only the provider mode is worth building on.
- **Licence, checked:** the author's claim that the 4.1.2 DLL is MIT licensed holds up. AMD's FidelityFX SDK 2.4.0
`license.md` starts with a restrictive default (binary-only redistribution, no reverse engineering) "except as noted
below". It then lists the files "subject to" an MIT licence, and that list includes
`signedbin/amd_fidelityfx_upscaler_dx12.dll` and `amd_fidelityfx_upscaler_vk.dll`. So the 4.1.x shaders and weights
are redistributable with the MIT notice, which removes the AMD half of the earlier licence concern for that version.
Which SDK version a given weights file came from still has to be pinned (the repo pins 4.1.2.4555 by SHA-256).
Qualcomm's QNN libraries are a separate matter. This is a reading of the licence file, not legal advice.
- **Frame generation:** FSR 4.0.2 ML frame generation is bundled but needs RDNA 4 WMMA, so it is not usable here.
- **Fit with DroidDeck:** GPL-3.0, same as DroidDeck. The provider route would sit in the guest, in front of
vkd3d-proton, where the game's FFX calls arrive. It needs no NPU access, so it works on the Thor.
- **Risk to check first:** the INT8 plan marks most passes `require_wave32`. Adreno runs 64 or 128 wide waves, so
either the passes can run at those widths or they need the variants the Winlator fork's Adreno path uses
(`dvj5411/fsr4vk`). Also unmeasured: INT8 FSR 4 on a handheld GPU may cost more than it saves at 1080p to 4K.
## Built so far
- `gpu/NpuInfo.kt`: maps the SoC model or board platform to a Hexagon generation (v68 to v81, with the VTCM size the
reference caps `vtcmSizeInMB` to), checks whether the app's uid can open the FastRPC node (or the DSP service that
can hand it over), and whether the QNN libraries are bundled. Shown as an "NPU" section in Device info.
- `NpuInfoTest`.
## Next steps, in order
1. Create an unsigned PD on the brokered descriptor (`INIT_CREATE`, with the DSP-side `fastrpc_shell_unsigned_3`) and
invoke one remote call. Qualcomm's open-source userspace library (`quic/fastrpc`, BSD-3) implements this; it would
be built as the app's own `libcdsprpc.so`, with the device open replaced by the binder call above. QNN stubs
resolve `libcdsprpc.so` from the app's library directory, so they would pick it up unchanged.
2. Run a QNN HTP graph with the user's own QAIRT libraries (v79 skel for the 8 Elite) to prove an end-to-end NPU run.
3. Check the binder route on an enforcing 8 Elite build and on an 8 Elite Gen 5 device. Thor (v73) has no route at all.
4. Decide the hook point. Guest-side (Winlator's approach) is the only one that can run FSR 4; compositor-side
limits it to spatial super-resolution.
5. GPU-only FSR 4.1.2 INT8 (DP4a) as an FFX provider in the guest (see vk-fsr4), since it needs no NPU access and
exercises the same plumbing. First measure: wave size on Adreno, and cost per frame on the Thor.
6. Per-architecture QNN cache directories (`v73/`, `v75/`, `v79/`, `v81/`) and a fallback to the GPU path whenever
`NpuInfo.usable` is false.
7. Pin the exact AMD SDK version for any weights that ship (4.1.2.4555 is MIT per the SDK 2.4.0 licence file), keep
the MIT notice with them, and review Qualcomm's QNN licence separately before anything of theirs is bundled or
downloaded.
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="dev.probe.npu">
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="34"/>
<application android:label="npuprobe" android:hasCode="false" android:debuggable="true">
<uses-native-library android:name="libcdsprpc.so" android:required="false"/>
<activity android:name="android.app.NativeActivity" android:exported="true">
<meta-data android:name="android.app.lib_name" android:value="npuprobe"/>
<intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter>
</activity>
</application>
</manifest>
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Builds a Java-less NativeActivity APK that asks the vendor dspservice for a FastRPC fd and probes it.
# Usage: build.sh <out.apk>; then: adb install -r out.apk; adb shell am start -n dev.probe.npu/android.app.NativeActivity
# Results go to logcat, tag NPUPROBE.
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
out=${1:?out.apk}
bt=$(ls -d "$ANDROID_HOME"/build-tools/* | sort -V | tail -1)
work=$(mktemp -d "$HOME/.cache/npu-probe-build.XXXXXX")
trap 'rm -rf "$work"' EXIT
mkdir -p "$work/lib/arm64-v8a"
clang=$(ls -d "$NDK"/toolchains/llvm/prebuilt/*/bin)/aarch64-linux-android34-clang
"$clang" -shared -fPIC "$here/probe.c" -o "$work/lib/arm64-v8a/libnpuprobe.so" -llog -landroid -lbinder_ndk -ldl
"$bt/aapt2" link -o "$work/base.apk" --manifest "$here/AndroidManifest.xml" -I "$ANDROID_HOME/platforms/android-34/android.jar"
(cd "$work" && zip -q -u base.apk lib/arm64-v8a/libnpuprobe.so)
"$bt/zipalign" -f 4 "$work/base.apk" "$work/aligned.apk"
"$bt/apksigner" sign --ks "$HOME/.android/debug.keystore" --ks-pass pass:android --key-pass pass:android \
--ks-key-alias androiddebugkey --out "$out" "$work/aligned.apk"
+100
View File
@@ -0,0 +1,100 @@
#include <android/native_activity.h>
#include <android/log.h>
#include <android/binder_ibinder.h>
#include <android/binder_parcel.h>
#include <android/binder_status.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <sys/stat.h>
#define L(...) do { char b[600]; snprintf(b, sizeof b, __VA_ARGS__); __android_log_write(ANDROID_LOG_INFO, "NPUPROBE", b); } while (0)
static void *oc(void *a){return a;} static void od(void *a){} static binder_status_t ot(AIBinder *b, transaction_code_t c, const AParcel *i, AParcel *o){return STATUS_UNKNOWN_TRANSACTION;}
typedef uint32_t remote_handle;
/* Route A: what BananaNative does: dlopen the vendor libcdsprpc from the app namespace. */
static void route_dlopen(void) {
void *h = dlopen("libcdsprpc.so", RTLD_NOW | RTLD_LOCAL);
L("A dlopen(libcdsprpc.so) = %s", h ? "ok" : dlerror());
if (!h) return;
int (*ctl)(int, void *, uint32_t) = dlsym(h, "remote_handle_control");
int (*cap)(int, uint32_t, uint32_t *) = dlsym(h, "fastrpc_get_cap");
int (*opn)(int, const char *, remote_handle *) = dlsym(h, "remote_handle_open_domain");
L("A syms control=%p get_cap=%p open_domain=%p", ctl, cap, opn);
if (ctl) { struct { uint32_t domain, enable; } req = {3, 1}; L("A unsigned-pd control r=%d", ctl(4, &req, sizeof req)); }
if (cap) for (uint32_t i = 0; i < 3; i++) { uint32_t v = 0xdead; int r = cap(3, i, &v); L("A get_cap(cdsp,%u) r=0x%x v=%u", i, r, v); }
if (opn) { remote_handle rh = 0; errno = 0; int r = opn(3, "file:///libhalide_hexagon_remote_skel.so?halide_hexagon_initialize_kernels&_modver=1.0", &rh); L("A open_domain r=0x%x errno=%d", r, errno); }
}
static void dump_dev(AParcel *r) {
int32_t v[16]; int n = 0;
int32_t pos = AParcel_getDataPosition(r), size = AParcel_getDataSize(r);
L("reply pos=%d size=%d", pos, size);
for (int i = 0; i < 12 && AParcel_getDataPosition(r) < size; i++) { int32_t x; if (AParcel_readInt32(r, &x) != STATUS_OK) break; v[n++] = x; L(" int[%d]=%d (0x%x)", i, x, x); }
}
void ANativeActivity_onCreate(ANativeActivity *a, void *s, size_t n) {
L("uid=%d", getuid());
route_dlopen();
{ const char *nodes[] = {"/dev/fastrpc-cdsp", "/dev/adsprpc-smd"};
for (int i = 0; i < 2; i++) { int f = open(nodes[i], O_RDWR | O_CLOEXEC); L("direct open(%s) fd=%d errno=%d", nodes[i], f, errno); if (f >= 0) close(f); } }
const char *name = "vendor.qti.hardware.dsp.IDspService/default";
AIBinder *(*chk)(const char *) = dlsym(RTLD_DEFAULT, "AServiceManager_checkService");
L("dlsym checkService=%p", chk);
if (!chk) return;
AIBinder *svc = chk(name);
L("checkService(%s)=%p", name, svc);
if (!svc) { L("no service (denied or absent)"); return; }
AIBinder_Class *cs = AIBinder_Class_define("vendor.qti.hardware.dsp.IDspService", oc, od, ot);
AIBinder_associateClass(svc, cs);
AIBinder_Class *cm = AIBinder_Class_define("vendor.qti.hardware.dsp.IDspManager", oc, od, ot);
AParcel *in = NULL, *out = NULL;
AIBinder_prepareTransaction(svc, &in);
AParcel_writeInt32(in, 3);
binder_status_t st = AIBinder_transact(svc, 1, &in, &out, 0);
AStatus *as = NULL; AIBinder *mgr = NULL;
if (st == STATUS_OK) { AParcel_readStatusHeader(out, &as); AParcel_readStrongBinder(out, &mgr); }
L("getNewDSPSession: st=%d mgr=%p", st, mgr);
if (!mgr) return;
AIBinder_associateClass(mgr, cm);
int doms[] = {3, 0};
for (int di = 0; di < 2; di++) {
AParcel *i2 = NULL, *o2 = NULL;
AIBinder_prepareTransaction(mgr, &i2);
AParcel_writeInt32(i2, 1); /* non-null */
int32_t start = AParcel_getDataPosition(i2);
AParcel_writeInt32(i2, 0); AParcel_writeInt32(i2, doms[di]);
int32_t end = AParcel_getDataPosition(i2);
AParcel_setDataPosition(i2, start); AParcel_writeInt32(i2, end - start); AParcel_setDataPosition(i2, end);
st = AIBinder_transact(mgr, 2, &i2, &o2, 0);
L("openSession(domain %d): st=%d", doms[di], st);
if (st != STATUS_OK) continue;
AStatus *s2 = NULL; AParcel_readStatusHeader(o2, &s2);
L(" ex=%d", s2 ? AStatus_getExceptionCode(s2) : -1);
int32_t nn, sz, a1, b1, hsz, nf, ni;
AParcel_readInt32(o2, &nn); AParcel_readInt32(o2, &sz); AParcel_readInt32(o2, &a1); AParcel_readInt32(o2, &b1);
AParcel_readInt32(o2, &hsz); AParcel_readInt32(o2, &nf);
L(" nonnull=%d size=%d a=%d b=%d handleSize=%d nfds=%d", nn, sz, a1, b1, hsz, nf);
for (int k = 0; k < nf && k < 4; k++) {
int fd = -1; binder_status_t rs = AParcel_readParcelFileDescriptor(o2, &fd);
char path[256] = "?"; char lp[64]; snprintf(lp, sizeof lp, "/proc/self/fd/%d", fd); ssize_t r = readlink(lp, path, sizeof path - 1); if (r > 0) path[r] = 0;
L(" fd[%d]=%d (rs=%d) -> %s", k, fd, rs, path);
if (fd >= 0) {
struct { uint32_t domain, attr, cap, rsv[4]; } cap;
for (uint32_t at = 0; at < 4; at++) { cap.domain = 3; cap.attr = at; cap.cap = 0xdead; memset(cap.rsv, 0, sizeof cap.rsv); errno = 0;
int ir = ioctl(fd, _IOWR('R', 13, cap), &cap); L(" GET_DSP_INFO attr=%u r=%d errno=%d cap=%u", at, ir, errno, cap.cap); }
errno = 0; int ar = ioctl(fd, _IO('R', 4)); L(" INIT_ATTACH r=%d errno=%d", ar, errno);
uint32_t info = 3; errno = 0; int gr = ioctl(fd, _IOWR('R', 8, uint32_t), &info); L(" GETINFO(R,8) r=%d errno=%d info=%u", gr, errno, info);
}
}
AParcel_readInt32(o2, &ni);
L(" nints=%d", ni);
}
L("done");
}