Commit Graph

158 Commits

Author SHA1 Message Date
Jiyong Park d970ccb56e Fix nullpointer dereference in libnativeloader
The `char* path` argument of OpenNativeLibrary() can be nullptr. We are
constructing std::string from the path, which is a bug. Fixing it by
using char* without converting it to std::string.

Test: run-gtests.sh
JniCompilerTest.CompileAndRunIntMethodThroughStubNormalCompiler
is successful.

Change-Id: I91249da7c1a72a2dff9bc77e477b465e0c7ee056
2019-05-17 18:51:44 +09:00
Jiyong Park fe4fb2b76c Add README file for libnativeloader
Bug: 130388701
Test: N/A
Change-Id: Idb6ef31d72041759d42b9e8fb504af2103c149e3
2019-05-16 08:55:11 +09:00
Jiyong Park 16a9896ff7 Fix style around header inclusion
This change is to be in sync with other libraries in system/core.

External headers are included via #include <...> rather
than #include "...", which is for headers from the current library.

Bug: 130388701
Test: build & pass presubmit tests

Change-Id: Ifb87ebaea1b0ff95e2e79352e6a42e3bfd949c52
2019-05-16 08:55:11 +09:00
Jiyong Park 8537781cc7 Hide non-bridged/bridged namespaces behind NativeLoaderNamespace class
NativeLoaderNamespace fully abstracts the non-bridged (so called
android-) and bridged namespaces.

Bug: 130388701
Test: build & pass presubmit tests
Change-Id: I3d5ca7515711e7638f4a5ab4d3a150185c3d17ac
2019-05-16 08:55:04 +09:00
Jiyong Park 4b5a37c8bd Refactor public_libraries.cpp more
- *_public_libraries() are now thread-safe
- removed some of the duplicated code

Bug: 130388701
Test: build & pass presubmit tests
Change-Id: I34b5149f75e28bb892cffe8fd9070be886d2f9bd
2019-05-10 00:12:03 +09:00
Jiyong Park 5b8b306b42 Refactor public_libraries.*
- shorten the long const variables
- merge {oem|product}_public_libraries into extended_public_libraries

Bug: 130388701
Test: build & pass presubmit tests

Change-Id: I43be555041466118f2b2d188f5da3ff0d8ed7d8d
2019-05-08 13:51:43 +09:00
Jiyong Park f8802e5f0a Introduce utils.h
Introduce utils.h to have common routines.

Bug: 130388701
Test: build & pass presubmit tests
Change-Id: Ic40da64fefc1f2216bdea9ea93a15e5abb8f23a4
2019-05-08 13:49:49 +09:00
Jiyong Park 40a6077244 Move public libraries list to a separate source file
Functions for reading the public libraries list are moved out of
library_namespace.cpp to public_libraries.cpp.

In addition, library-local symbols are moved from android namespace to
android::nativeloader namespace.

Bug: 130388701
Test: build & pass presubmit tests
Change-Id: If82419598304d56d29bfec4ef553443c788d0f53
2019-05-08 13:49:42 +09:00
Jiyong Park 6291da2936 move classes out of native_loader.cpp
native_loader.cpp is too crowded. Move the classes
NativeLoaderNamespaces and LibraryNamespaces out of native_loader.cpp to
their own source files.

This change does not alter any functionality.

Bug: 130388701
Test: m, presubmit tests
Change-Id: Ibc61ec0dc6727af7cac865b1971ebf1befac6855
2019-05-04 01:10:42 +09:00
Martin Stjernholm c57ed29dd5 Reland: Fix libnativeloader to correctly link to the platform namespace.
This relands http://r.android.com/951440:

This affected binaries in the Runtime APEX, where the platform namespace is
"platform" rather than "default".

Also extend ANDROID_ADDITIONAL_PUBLIC_LIBRARIES to create links to both to
platform and runtime namespaces, so that it can be used to open up access to
internal libraries in the Runtime APEX as well, which is used by ART gtests
and run tests.

Also update some comments in the ld.config*.txt files to accurately explain
why some namespaces need to be visible, and some other minor changes for
consistency. There are no semantically significant changes in those files.

Test: Flash and boot
Test: Run an ART run test with the internal libarttest.so library
Test: lunch aosp_cf_x86_phone-eng;
  atest android.compilation.cts.AdbRootDependentCompilationTest#testCompile_curProfile \
    com.android.cts.dexmetadata.InstallDexMetadataHostTest#testProfileSnapshotAfterInstall \
    installd_dexopt_test
Bug: 130293232
Bug: 121117762
Change-Id: I3d9f2102a03e83843e15bc78b5ad347220c52769
2019-05-01 16:46:06 +01:00
Treehugger Robot 68cf801ad9 Merge "Revert "Fix libnativeloader to correctly link to the platform namespace."" 2019-04-30 00:13:22 +00:00
Martin Stjernholm b9259a9cbe Revert "Fix libnativeloader to correctly link to the platform namespace."
This reverts commit 4ca0ca67bf.

Reason for revert: Breaks android.compilation.cts.AdbRootDependentCompilationTest#testCompile_curProfile and others: http://g/art-team/R2nEDA1Ka_s

Change-Id: Ia6285648133d21e61040efafc73cac97d702a7c4
2019-04-29 20:57:16 +00:00
Treehugger Robot d21a090f79 Merge "Nativeloader: Restrict anonymous namespace creation" 2019-04-29 16:08:15 +00:00
Martin Stjernholm 4ca0ca67bf Fix libnativeloader to correctly link to the platform namespace.
This affected binaries in the Runtime APEX, where the platform namespace is
"platform" rather than "default".

Also extend ANDROID_ADDITIONAL_PUBLIC_LIBRARIES to create links to both to
platform and runtime namespaces, so that it can be used to open up access to
internal libraries in the Runtime APEX as well, which is used by ART gtests
and run tests.

Also update some comments in the ld.config*.txt files to accurately explain
why some namespaces need to be visible, and some other minor changes for
consistency. There are no semantically significant changes in those files.

Test: Flash and boot
Test: Run an ART run test with the internal libarttest.so library
Bug: 130293232
Bug: 121117762
Change-Id: I7ebaf5370dd0f533b1bb5f0e67e7c3c1df48e512
2019-04-29 13:09:08 +01:00
Andreas Gampe b9df7d936c Nativeloader: Restrict anonymous namespace creation
Create the anonymous namespace only from a non-empty library path.

This is a better heuristic than the current "first-come" one. It
allows creating classloaders that are not directly related to an
app's "main" classloader, that is, do not have any library path.
This is the case, for example, for shared libraries, including
preloaded ones.

Longer-term, the anonymous namespace creation should be made
explicit, so that the framework can have full control.

Bug: 130623656
Test: m
Test: manual
Change-Id: I8251363b372e365d10ae09d23df93d76388ac7f9
2019-04-26 08:55:53 -07:00
dimitry 0c11941468 Add dependency on libdl_android
platform private symbols have been moved to libdl_android.so
since they are not intended to be accessible from apps.

Test: make
Bug: http://b/129387775
Change-Id: I883a6d2ca588a258dd43efa766fad4e07428594e
(cherry picked from commit e3d0383d38)
2019-03-28 12:52:27 +01:00
Kiyoung Kim 23ff8eb9c2 Do not fail when there is no vndk namespace
Some of the legacy devices may not have vndk namespace. To make this
work, libnativeloader should not fail when it fails to search for vndk
namespace.

Bug: 129011845
Test: m -j
Change-Id: I6f68aeb6ae84a00985cc20561b2fcdb461be9724
Merged-In: Id9147d4aeee9ba2b301b6893dea5884dce9c14fa
2019-03-25 13:59:40 +09:00
Kiyoung Kim 4639f6946a Add product apk support from libnativeloader
Currently libnativeloader appends vendor lib path if apk is from vendor
partition. Similar to this we should add product lib path if apk if from product partition.

Bug: 124705551
Test: m -j && tested from crosshatch with product apps (such as Wallpaper)
Change-Id: I8c3473f1f70b1c22dcaed7eb2d5f9c3deee9e1a5
Merged-In: I8690167ca8098015c8ae4bbb4f028404c5e94dc0
2019-03-07 15:01:52 +09:00
Martin Stjernholm 7888b5cdd7 Avoid runtime namespace becoming parent for classloader-namespace.
Passing nullptr as parent namespace to android_create_namespace makes it use
the namespace of the caller as parent, which typically is the runtime
namespace. That in turn causes classloader-namespace to inherit any
libraries in the shared group of the runtime namespace, i.e. any libraries
that have been loaded in it with RTLD_GLOBAL or DF_1_GLOBAL up to that
point.

Let's instead pass the platform namespace from the linker config as fallback
when a parent namespace cannot be found. That is also what happened before
libnativeloader moved into the runtime namespace.

Test: Flash and boot
Test: atest CtsJniTestCases (on cuttlefish and taimen)
Bug: 124501296
Change-Id: If2faee74e2bdcf95d19516faec340fedcdd07e29
2019-02-23 03:46:27 +00:00
Orion Hodson 34b126b98b Remove dependency on libcutils
libnativeloader is in the Runtime Module, libcutils is not.

Dependency was on property_get so moving to libbase equivalent.

Bug: b/125323247
Test: m -j100
Change-Id: I295ffa14b475a193a851db89dbb3b4c9cc0183d2
2019-02-22 08:55:48 +00:00
vichang ce912aadda Merge changes from topic "dup_icu4c"
* changes:
  Linker namespace changes for moving ICU4C to APEX
  Remove the public libs in runtime namespace
2019-02-19 10:14:31 +00:00
Jiyong Park 00f2ebe9cc shim libraries for libnativeloader and libnativebridge
libnativeloader_lazy and libnativebridge_lazy are shim libraries for
libnativeloader and libnativebridge, respectively.

The shim libraries provides the same APIs as their counterparts, but
when the APIs are called, the APIs from the real libraries are
loaded/linked/and executed using dlopen/dlsym.

Bug: 123403798
Bug: 124250621
Test: m
Test: device boots to the UI
Test: mma under system/core/libnativebridge with aosp_cf_x86
adb sync; execute all tests under
/data/nativetest/libnativebridge-lazy-tests
All passes except NativeBridgeTest.V2_Signal which is also failing
in /data/nativetest/libnativebridge-tests.

Change-Id: Ic6484784eaa7872dcdd2decbb30943fb34c1abd7
2019-02-12 19:35:45 +09:00
Victor Chang f70a2fe4c1 Remove the public libs in runtime namespace
These libs are listed in public.android.txt, but not exposed in the default namespace

Bug: 120786417
Bug: 121372395
Test: app can still DT_NEEDED libicuuc.so
Change-Id: I03dc51f04e29c2d15679c4daf82b05a812efb2db
2019-02-08 13:34:09 +00:00
Martin Stjernholm a015ad2779 Revert^2 "Enable APEX stubs for libnativeloader."
This reverts commit 5c8c6a90fd.

Reason for revert: Another try with http://r.android.com/892234 in place.

Test: Flash and boot
Bug: 113373927
Change-Id: I508c217a177e9cdd65d8a405d1315aeeacabe18d
2019-02-07 15:23:49 +00:00
Martin Stjernholm b78f6ec7ef Add some overview docs for classloader-namespace.
Courtesy of jiyong@.

Test: n/a
Change-Id: I4ee239c63a5b5f90516b05af25b32ff22b147d53
2019-02-06 21:51:27 +00:00
Victor Chang 7a20a907a5 Expose public libraries from runtime namepsace to classloader namespace
Bug: 121248172
Bug: 121372395
Test: DT_NEEDED libicuuc.so
Test: dlopen("libicuuc.so")
Test: dlopen("/system/lib64/libicuuc.so") for targetSdkVersion < Q
Test: dlopen("/apex/com.android.runtime/lib64/libicuuc.so")
Change-Id: Ib4a255696ed474b7993acc952a8d07e7d64604a5
2019-02-04 17:45:22 +00:00
dimitry d2ace387f5 Add getExportedNamespace NB callback
This callback replaces getVendorNamespace(). Fix nativeloader
to use NativeBridgeGetExportedNamespace instead of
NativeBridgeGetVendorNamespace.

Bug: http://b/121248172
Bug: http://b/121372395
Test: make
Change-Id: I8fa2081e37815f6f65490c9536bed0687b7f1e77
2019-02-04 15:06:43 +01:00
Martin Stjernholm 5c8c6a90fd Revert "Enable APEX stubs for libnativeloader."
This reverts commit 0daa405272.

Reason for revert: Breaks cf_x86_phone-userdebug: https://android-build.googleplex.com/builds/build-details/5273735/targets/cf_x86_phone-userdebug

Bug: 123700170
Change-Id: Id82a91f845120dd41ce02b6d7fef886a87eb23a8
2019-02-01 13:13:56 +00:00
Martin Stjernholm 0daa405272 Enable APEX stubs for libnativeloader.
Test: Flash and boot
Bug: 113373927
Change-Id: I61783b947031bb13f415e561e19cb90fa98d0ddd
2019-01-30 14:44:55 +00:00
Nicolas Geoffray 88bdf80d17 Conscrypt should only link against bionic.
Also remove useless code in native_loader.cpp

Test: m
Change-Id: Id176256cc36fa32d3f722e1443429cb9fbec05f2
2019-01-22 15:32:23 +00:00
Nicolas Geoffray 890e3bf4e7 Revert "Revert "Introduce conscrypt linker namespace.""
This reverts commit 5701a47685.

Bug: 123185917
Test: CtsJdwpTestCases
Test: android.signature.cts.api.killswitch_debug_class

Reason for revert: Fixed CtsJdwpTestCases and KillSwitchTest.

Change-Id: I6a074038a4e974875d68ca6a371f6a87ad48bce9
2019-01-22 09:15:22 +00:00
Nicolas Geoffray 5701a47685 Revert "Introduce conscrypt linker namespace."
This reverts commit 67a09e5791.
Exempt-From-Owner-Approval: Fixes P0 failures.

Bug: 123185917


Reason for revert: media namespace needs to be introduced.

Change-Id: I0c28798a3143c1e627278c3a908207e670171416
2019-01-21 17:23:31 +00:00
Nicolas Geoffray 67a09e5791 Introduce conscrypt linker namespace.
And have the linker translate a java library path from an apex
to a linker namespace.

Bug: 122874359
Test: m, boots, gtest, run-test, CtsJdwpTests
Change-Id: I216c3509c45589d28acdac068aec53877aeb104a
Exempt-From-Owner-Approval: Carrying Jiyong's +2
2019-01-21 12:05:13 +00:00
Nicolas Geoffray 5353502062 Pass the Java caller's location to OpenNativeLibrary.
Will be used to find the linker namespace to use.

Bug: 122874359
Test: m, gtest, run-test, CtsJdwpTests

Change-Id: I3f3be4a1d864741d585ab3ed9ffb93fab262516e
2019-01-18 14:07:27 +00:00
Nicolas Geoffray ec6bd00f33 Merge "Add runtime module members to owners." 2019-01-17 06:58:06 +00:00
Nicolas Geoffray 7338ef5f5c Add runtime module members to owners.
Test: N/A
Change-Id: Id6cdf1a1b643df7744bf476e6e745ecc384708d7
2019-01-16 22:00:48 +00:00
Nicolas Geoffray d06cb94d25 libnativeloader: remove stubs for now.
Seems to break VMDebug test.

Also add missed strdup in returned error message.

bug: 122957265
Test: VMDebug
Change-Id: I64727d707f20c0e6afcb5455edf20c99011a81dc
2019-01-16 21:40:34 +00:00
Nicolas Geoffray c3a73dcd27 Move to C API of libnativeloader.
Test: m
Bug: 119840313
Bug: 122710865

(cherry picked from commit e1d970df09)

Merged-In: Id5b08ef5de0d38cb678a50e45d38dfb8107c4a1c
Change-Id: Ic82baa885caa5125dd3c8b5de854128c75f48caf

Exempt-From-Owner-Approval: Cherry-pick of approved CL in master.
2019-01-16 13:40:28 +00:00
Pete Bentley 632f142c42 Propagate dlopen errors to callers of OpenNativeLibrary.
Bug: 119867084
Test: make && flashall
Change-Id: If98082db39796f0097ce7ef1d095c9f202c3a95e
2018-12-19 13:48:01 +00:00
dimitry 3150f7c7af Add error_msg argument to CloseNativeLibrary
error_msg is set when dlclose/NativeBridgeUnloadLibrary fails.

Bug: https://issuetracker.google.com/79126103
Test: make
Change-Id: I043580209538ff47320e8d9a304a21c00c4b149f
2018-09-12 01:36:06 +02:00
Victor Khimenko 1443ec4972 Separate namespace acquisition from library loading
This way native bridge namespace could be acquired in advance and when
library must be loaded JNIEnv is not needed.

Bug: http://b/79940628

Test: cts-tradefed run commandAndExit cts -m CtsGpuToolsHostTestCases

Change-Id: If8bff272fc5245eb4e418807c3bdd29e82833ab8
2018-07-12 15:44:35 +02:00
Elliott Hughes 0ca7c79dfb libnativeloader: add jiyong to OWNERS.
Bug: N/A
Test: N/A
Change-Id: I892bfff4bcf28482588582a1045dcae720b121db
2018-05-31 18:09:20 -07:00
Inseob Kim 67cb05654c Support product-specific libraries
Product-specific libraries in /product/lib can be exposed to Android
apps by adding the list of the libs into
/product/etc/public.libraries-<companyname>.txt. The libs MUST be named
as lib<name>.<companyname>.so.

Bug: 73095206
Test: with taimen
mma -j and runtest.sh. The libs are all loaded in system, but not in
vendor. After reinstalling app using adb -r and reopening app, only
libraries listed in .txt are loaded

Change-Id: I7c386813c72a7b225a7f244b6c5fec4ac0660fd3
2018-05-16 01:36:25 +00:00
Elliott Hughes dc699a269f bpfmt.
Bug: N/A
Test: builds
Change-Id: I89ad00e1c4c7e0767bc80a7ac7935a4d55e090ac
2018-02-16 17:58:14 -08:00
Jiyong Park e031994f2f Don't shared oem-defined libs to vendor apks
OEM-defined libs in /system/etc/public.libraries-<companyname>.txt files
are not available to apks in the vendor partition, otherwise we are
allowing vendor -> system dependency, which is a Treble violation.

Bug: 71561542
Test: mm -j under system/core/libnativeloader/test and runtest.sh
the four libs (lib[foo|bar].[oem1|oem2].so are all loaded in
android.app.test.system app but not in android.app.test.vendor app

Change-Id: Ie5d9160ae4dc2a64beb6507602ee5a1db6518875
2018-01-15 22:08:21 +09:00
Treehugger Robot 01ccde321f Merge "Nativeloader: Add minimal effort for host library path" 2018-01-08 09:40:50 +00:00
Treehugger Robot 2fdf9da669 Merge "Don't install unnecessary VNDK libs" 2018-01-04 13:36:14 +00:00
Andreas Gampe 5c7d582be4 Nativeloader: Add minimal effort for host library path
Attempt to (somewhat) support the given library path on a non-Android
device. Iterate through the given list and construct a complete path.
This will of course not handle dependencies correctly and is best
effort.

Required (and enough) for agent-related testing in ART.

Bug: 70901841
Test: m
Change-Id: I9ecb27d662c8a2c79a70b6c5464483c449c5d034
2018-01-02 09:05:55 -08:00
Elliott Hughes 579e682628 Add std::string StartsWith*/EndsWith* overloads.
We should have done this from the beginning. Thanks to Windows, we're not
going to be able to switch libbase over to std::string_view any time soon.

Bug: N/A
Test: ran tests
Change-Id: Iff2f56986e39de53f3ac484415378af17dacf26b
2017-12-20 09:42:22 -08:00
Jiyong Park d1006fe659 Support partners to expose their own system libs to Android apps
Partners (entities other than AOSP) can expose their own system
libraries which are in /system/lib[64] to Android apps. This can be done
by adding the name of the libs into the files
/system/etc/public.libraries-<companyname>.txt.

There can be multiple of the txt files on a device, which is for the
case that multiple partners contributing to the same system image
have their own set of public libraries.

The public libraries MUST be named as lib<name>.<companyname>.so. This
is to prevent accidental exposure of AOSP-defined system private libs.

Note 1:
<companyname> doesn't need to be the same as the value of the sysprop
ro.product.manufacturer or anything that can be part of a file path.

Note 2:
This feature is not for exposing SoC-specific libs to Android apps. That
is already done by /vendor/etc/public.libraries.txt and is only for
libs in /vendor/lib[64].

Bug: 68280171
Test: mm -j under /system/core/libnativeloader/test
cts-tradefed run commandAndExit cts-dev -m CtsJniTestCases -t
android.jni.cts.JniStaticTest#test_linker_namespaces

Change-Id: I7d32ec27c7858e35b96c7c98223cc110acb35b81
2017-12-19 23:35:09 +09:00