android_packages_modules_Co.../staticlibs/native
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ryan Zuklie 2669e24058 Add BpfRingbuf class to wrap ringbuf access
This implements the bare minimum to read from BPF ring buffers in
userspace. The implementation uses two shared memory regions with
atomic-like access. Currently, the class only guarantees that the
element type has the same size (later can add btf support).

The alternative would be to use libbpf or bcc, but since this is a small
header-only library that seemed like it could end up being more
difficulty than it was worth.

Bug: 246985031
Test: atest libbpf_android_test
Change-Id: I7f08e76db9cb9672ef66c629bccb3db63d3c2229
2023-01-23 08:28:50 -08:00
..
bpf_headers Add BpfRingbuf class to wrap ringbuf access 2023-01-23 08:28:50 -08:00
bpf_syscall_wrappers Add BpfRingbuf class to wrap ringbuf access 2023-01-23 08:28:50 -08:00
bpfmapjni verify java map key/value struct size matches file descriptor 2022-12-21 00:03:37 +00:00
bpfutiljni Bpf Util Lib in Common Location 2022-03-01 09:09:36 -08:00
ip_checksum Add apex_available and min_sdk_version to libip_checksum 2021-12-28 06:01:57 +00:00
netjniutils Use IsAtLeastS SdkLevel utility implementation 2022-06-27 12:53:49 +00:00
nettestutils [LSC] Add LOCAL_LICENSE_KINDS to frameworks/libs/net 2022-01-27 10:46:23 -08:00
tcutils dedup kernelversion.h 2022-12-24 17:17:14 +00:00
README.md Clarify that JNI libraries used for jarjar'd classes must be statically linked. 2021-12-15 02:28:17 +00:00

JNI

As a general rule, jarjar every static library dependency used in a mainline module into the modules's namespace (especially if it is also used by other modules)

Fully-qualified name of java class needs to be hard-coded into the JNI .so, because JNI_OnLoad does not take any parameters. This means that there needs to be a different .so target for each post-jarjared package, so for each module.

This is the guideline to provide JNI library shared with modules:

  • provide a common java library in frameworks/libs/net with the Java class (e.g. BpfMap.java).

  • provide a common native library in frameworks/libs/net with the JNI and provide the native register function with class_name parameter. See register_com_android_net_module_util_BpfMap function in frameworks/libs/net/common/native/bpfmapjni/com_android_net_module_util_BpfMap.cpp as an example.

When you want to use JNI library from frameworks/lib/net:

  • Each module includes the java library (e.g. net-utils-device-common-bpf) and applies its jarjar rules after build.

  • Each module creates a native library in their directory, which statically links against the common native library (e.g. libnet_utils_device_common_bpf), and calls the native registered function by hardcoding the post-jarjar class_name. Linkage MUST be static because common functions in the file (e.g., register_com_android_net_module_util_BpfMap) will appear in the library (.so) file, and different versions of the library loaded in the same process by different modules will in general have different versions. It's important that each of these libraries loads the common function from its own library. Static linkage should guarantee this because static linkage resolves symbols at build time, not runtime.