苹果系统的链接器/usr/lib/dyld 提供了一个叫dyld-interposing的功能(从 Mac OS X 10.4 开始),可以在程序启动时替换掉某个函数的实现。这个功能可以用来实现代码注入(详见:《Mac OS X Internals: A Systems Approach》- Amit Singh - 第二章 2.6.3.4 dyld interposing)
Frame graphs are a design pattern for handling complex rendering pipelines, which are currently used in industry. Their usage is motivated by handling barriers, queue synchronization and memory aliasing in the background by abstracting the rendering pipeline of a frame on a higher level. —— https://github.com/gfx-rs/gfx/wiki/Frame-graphs
解决什么问题?
在传统的渲染管线中,渲染过程通常被划分为多个阶段,如下图所示:
这些阶段之间存在着输入和输出的依赖关系,其中一个阶段的输出作为下一个阶段的输入。
Render Graph 的主要思想是将渲染过程表示为一个有向无环图(DAG),其中节点表示渲染通道(Render pass),边表示依赖关系。每个渲染通道执行特定的渲染操作,可具有输入和输出资源,例如Texture、Frame Buffer和执行的 Shader/Program。例如,假设节点 A 的输出Texture是节点 B 的输入Texture,那么节点 B 就依赖于节点 A。
In this week, I found a great POC to run a pure Java standalone app (command line tool, no apk) on Android. But what about running a standalone application using JNI (with .so files) on Android like this?
Java app with JNI
Imagine there is a Java program that loads the JNI shared native library to run and use some Android APIs :
if (!version) { LOGE("Unable to get version string"); } else { LOGI("Build Version - %s\n", version); (*env)->ReleaseStringUTFChars(env, buildVersion, version); } (*env)->DeleteLocalRef(env, buildVersion);
return (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI " ABI "."); } // ...
The working directory structure
1 2 3
. ├── Helloworld.java └── hello-jni.c
Compile and deploy
Now we need to compile both the Java and C sources for Android.
Using javac and dx to compile for a jar file which Android can read:
1 2 3 4 5 6 7
export BUILD_DIR=$PWD/build export JARFILE=helloworld.jar export JAVAC_OPTS=-source 1.8 -target 1.8 -cp .:$ANDROID_HOME/platforms/android-30/android.jar # Compile .java to .class javac $JAVAC_OPTS -d $BUILD_DIR/classes Helloworld.java # Convert .class file into a dex file and embedded in a jar file $ANDROID_HOME/build-tools/30.0.2/dx --output=$BUILD_DIR/$JARFILE --dex ./$BUILD_DIR/classes
Cross-compile the C to Android shared native library via NDK:
my_tool(38364) MallocStackLogging: stack logs being written to /private/tmp/stack-logs.38364.103f3a000.my_tool.19n2JH.index my_tool(38364) MallocStackLogging: recording malloc and VM allocation stacks to disk using standard recorder
需要注意的是,在程序退出时,这个调用日志文件会被自动删除:
my_tool(38364) MallocStackLogging: stack logs deleted from /private/tmp/stack-logs.38364.103f3a000.my_tool.19n2JH.index
所以需要将程序在结束时最好 block 住,以便分析日志文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream> staticvoidwait_for_input() { std::cout << "Press Enter to exit." << std::endl; char b[1]; std::cin.read(b, 1); } intmain(int argc, constchar **argv) { auto *p = newint(10); // other codes ... p = nullptr; // leaked // ...
// blocking program for analyzing malloc stack history wait_for_input(); return0; }