namespaces_root.cpp revision 42d5fcb9f494eb45de3b6bf759f4a18076e84728
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <dlfcn.h>
18
19static const char* g_local_string = "This string is local to root library";
20extern "C" const char* g_private_extern_string;
21extern "C" const char* g_public_extern_string;
22
23bool g_dlopened = false;
24
25extern "C" const char* ns_get_local_string() {
26  return g_local_string;
27}
28
29extern "C" const char* ns_get_private_extern_string() {
30  return g_private_extern_string;
31}
32
33extern "C" const char* ns_get_public_extern_string() {
34  return g_public_extern_string;
35}
36
37extern "C" const char* ns_get_dlopened_string() {
38  void* handle = dlopen("libnstest_dlopened.so", RTLD_NOW | RTLD_GLOBAL);
39  if (handle == nullptr) {
40    return nullptr;
41  }
42
43  const char* result = *static_cast<const char**>(dlsym(handle, "g_private_dlopened_string"));
44  if (result != nullptr) {
45    g_dlopened = true;
46  }
47
48  return result;
49}
50