Merge changes I5e33e5bf,I64237006 am: c37f4a4199

am: 4440f8bc20

Change-Id: I6db77221e12d16280c8578c4ba6d6fb5050c59da
This commit is contained in:
Ryan Prichard 2019-07-15 17:43:22 -07:00 committed by android-build-merger
commit bdbed08c47
3 changed files with 37 additions and 34 deletions

View file

@ -3,7 +3,7 @@ subdirs = ["tests"]
cc_library { cc_library {
name: "libvndksupport", name: "libvndksupport",
native_bridge_supported: true, native_bridge_supported: true,
srcs: ["linker.c"], srcs: ["linker.cpp"],
cflags: [ cflags: [
"-Wall", "-Wall",
"-Werror", "-Werror",

View file

@ -13,38 +13,44 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "vndksupport"
#include "linker.h" #include "linker.h"
#include <android/dlext.h> #include <android/dlext.h>
#include <dlfcn.h> #include <dlfcn.h>
#define LOG_TAG "vndksupport"
#include <log/log.h> #include <log/log.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
__attribute__((weak)) extern struct android_namespace_t* android_get_exported_namespace(const char*); #include <initializer_list>
__attribute__((weak)) extern void* android_dlopen_ext(const char*, int, const android_dlextinfo*);
static const char* namespace_name = NULL; __attribute__((weak)) extern "C" android_namespace_t* android_get_exported_namespace(const char*);
__attribute__((weak)) extern "C" void* android_dlopen_ext(const char*, int,
const android_dlextinfo*);
static struct android_namespace_t* get_vendor_namespace() { namespace {
const char* namespace_names[] = {"sphal", "default", NULL};
static struct android_namespace_t* vendor_namespace = NULL; struct VendorNamespace {
if (vendor_namespace == NULL) { android_namespace_t* ptr = nullptr;
int name_idx = 0; const char* name = nullptr;
while (namespace_names[name_idx] != NULL) { };
if (android_get_exported_namespace != NULL) {
vendor_namespace = android_get_exported_namespace(namespace_names[name_idx]); } // anonymous namespace
static VendorNamespace get_vendor_namespace() {
static VendorNamespace result = ([] {
for (const char* name : {"sphal", "default"}) {
if (android_get_exported_namespace != nullptr) {
if (android_namespace_t* ns = android_get_exported_namespace(name)) {
return VendorNamespace{ns, name};
}
} }
if (vendor_namespace != NULL) {
namespace_name = namespace_names[name_idx];
break;
}
name_idx++;
} }
} return VendorNamespace{};
return vendor_namespace; })();
return result;
} }
int android_is_in_vendor_process() { int android_is_in_vendor_process() {
@ -53,28 +59,30 @@ int android_is_in_vendor_process() {
if (getpid() == 1) { if (getpid() == 1) {
return 0; return 0;
} }
if (android_get_exported_namespace == NULL) { if (android_get_exported_namespace == nullptr) {
ALOGD("android_get_exported_namespace() not available. Assuming system process."); ALOGD("android_get_exported_namespace() not available. Assuming system process.");
return 0; return 0;
} }
// In vendor process, 'vndk' namespace is not visible, whereas in system // In vendor process, 'vndk' namespace is not visible, whereas in system
// process, it is. // process, it is.
return android_get_exported_namespace("vndk") == NULL; return android_get_exported_namespace("vndk") == nullptr;
} }
void* android_load_sphal_library(const char* name, int flag) { void* android_load_sphal_library(const char* name, int flag) {
struct android_namespace_t* vendor_namespace = get_vendor_namespace(); VendorNamespace vendor_namespace = get_vendor_namespace();
if (vendor_namespace != NULL) { if (vendor_namespace.ptr != nullptr) {
const android_dlextinfo dlextinfo = { const android_dlextinfo dlextinfo = {
.flags = ANDROID_DLEXT_USE_NAMESPACE, .library_namespace = vendor_namespace, .flags = ANDROID_DLEXT_USE_NAMESPACE,
.library_namespace = vendor_namespace.ptr,
}; };
void* handle = NULL; void* handle = nullptr;
if (android_dlopen_ext != NULL) { if (android_dlopen_ext != nullptr) {
handle = android_dlopen_ext(name, flag, &dlextinfo); handle = android_dlopen_ext(name, flag, &dlextinfo);
} }
if (!handle) { if (!handle) {
ALOGE("Could not load %s from %s namespace: %s.", name, namespace_name, dlerror()); ALOGE("Could not load %s from %s namespace: %s.", name, vendor_namespace.name,
dlerror());
} }
return handle; return handle;
} else { } else {

View file

@ -21,11 +21,6 @@
#include <vndksupport/linker.h> #include <vndksupport/linker.h>
#include <string> #include <string>
// Since the test executable will be in /data and ld.config.txt does not
// configure sphal namespace for executables in /data, the call to
// android_load_sphal_library will always fallback to the plain dlopen from the
// default namespace.
// Let's use libEGL_<chipset>.so as a SP-HAL in test // Let's use libEGL_<chipset>.so as a SP-HAL in test
static std::string find_sphal_lib() { static std::string find_sphal_lib() {
const char* path = const char* path =