diff options
author | Vic Yang <victoryang@google.com> | 2019-01-09 12:38:24 -0800 |
---|---|---|
committer | Vic Yang <victoryang@google.com> | 2019-02-12 20:28:38 -0800 |
commit | a117f25b4eb5b88a9b7eafefd7e4443a1aab86e4 (patch) | |
tree | f0ca5c3eb6aea83438290be20a5932dfedc68202 /libvndksupport | |
parent | c7b5c4fa6b6f50c8ac14852275141483686895f9 (diff) | |
download | system_core-a117f25b4eb5b88a9b7eafefd7e4443a1aab86e4.tar.gz system_core-a117f25b4eb5b88a9b7eafefd7e4443a1aab86e4.tar.bz2 system_core-a117f25b4eb5b88a9b7eafefd7e4443a1aab86e4.zip |
libvndksupport: Add android_is_in_vendor_process()
In preparation for cleaning up conditionally compiled VNDK libraries,
we need a function that determines if the current process is running in
the system process or the vendor process.
Bug: 119423884
Test: Add a dummy VNDK library that prints different string in system
vs vendor process. Use the library in different processs and
check the output.
Change-Id: Ic00927d8eadd2a21fcba9cb64cc93eaadd5bdd2d
Diffstat (limited to 'libvndksupport')
-rw-r--r-- | libvndksupport/include/vndksupport/linker.h | 10 | ||||
-rw-r--r-- | libvndksupport/libvndksupport.map.txt | 1 | ||||
-rw-r--r-- | libvndksupport/linker.c | 11 |
3 files changed, 22 insertions, 0 deletions
diff --git a/libvndksupport/include/vndksupport/linker.h b/libvndksupport/include/vndksupport/linker.h index f509564e1..5f48c3974 100644 --- a/libvndksupport/include/vndksupport/linker.h +++ b/libvndksupport/include/vndksupport/linker.h @@ -20,6 +20,16 @@ extern "C" { #endif +/* + * Returns whether the current process is a vendor process. + * + * Note that this is only checking what process is running and has nothing to + * do with what namespace the caller is loaded at. For example, a VNDK-SP + * library loaded by SP-HAL calling this function may still get a 'false', + * because it is running in a system process. + */ +int android_is_in_vendor_process(); + void* android_load_sphal_library(const char* name, int flag); int android_unload_sphal_library(void* handle); diff --git a/libvndksupport/libvndksupport.map.txt b/libvndksupport/libvndksupport.map.txt index d3db10faf..ac9a99c3c 100644 --- a/libvndksupport/libvndksupport.map.txt +++ b/libvndksupport/libvndksupport.map.txt @@ -1,5 +1,6 @@ LIBVNDKSUPPORT { global: + android_is_in_vendor_process; # vndk apex android_load_sphal_library; # vndk apex android_unload_sphal_library; # vndk apex local: diff --git a/libvndksupport/linker.c b/libvndksupport/linker.c index bc5620b93..821940ac4 100644 --- a/libvndksupport/linker.c +++ b/libvndksupport/linker.c @@ -45,6 +45,17 @@ static struct android_namespace_t* get_vendor_namespace() { return vendor_namespace; } +int android_is_in_vendor_process() { + if (android_get_exported_namespace == NULL) { + ALOGD("android_get_exported_namespace() not available. Assuming system process."); + return 0; + } + + // In vendor process, 'vndk' namespace is not visible, whereas in system + // process, it is. + return android_get_exported_namespace("vndk") == NULL; +} + void* android_load_sphal_library(const char* name, int flag) { struct android_namespace_t* vendor_namespace = get_vendor_namespace(); if (vendor_namespace != NULL) { |