diff --git a/base/src/ashmem.cpp b/base/src/ashmem.cpp index 059cf15b69191d771d45f92a5e96d5aa3d406b6d..6a85f02633c592c70ec19646e2fa8c47bd1ea9ce 100644 --- a/base/src/ashmem.cpp +++ b/base/src/ashmem.cpp @@ -35,84 +35,9 @@ namespace OHOS { static pthread_mutex_t g_ashmemLock = PTHREAD_MUTEX_INITIALIZER; -using openFdFunction = int (*)(); -static openFdFunction g_openFdApi = nullptr; - -openFdFunction ProbeAshmemFdFunction() -{ - auto handle = dlopen("libashmemd_client.so", RTLD_NOW); - if (!handle) { - return nullptr; - } - openFdFunction func = reinterpret_cast(dlsym(handle, "openAshmemdFd")); - if (!func) { - dlclose(handle); - } - return func; -} - -static inline void TrimFromStart(std::string &s) -{ - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {return !std::isspace(ch);})); -} - -static inline void TrimFromEnd(std::string &s) -{ - s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {return !std::isspace(ch);}).base(), s.end()); -} - -static void Trim(std::string &s) -{ - TrimFromStart(s); - TrimFromEnd(s); -} - -static int GetAshmemDeviceFd() -{ - static const std::string bootIdPath = "/proc/sys/kernel/random/boot_id"; - std::string boot_id; - char buf[BUFSIZ]; - ssize_t n; - int fdBoot = -1; - int fdAshmem = -1; - - fdBoot = TEMP_FAILURE_RETRY(open(bootIdPath.c_str(), O_RDONLY | O_CLOEXEC)); - if (fdBoot < 0) { - return -1; - } - - if ((n = TEMP_FAILURE_RETRY(read(fdBoot, &buf[0], sizeof(buf)))) > 0) { - boot_id.append(buf, n); - } else { - close(fdBoot); - return -1; - } - close(fdBoot); - - Trim(boot_id); - - fdAshmem = TEMP_FAILURE_RETRY(open(("/dev/ashmem" + boot_id).c_str(), O_RDWR | O_CLOEXEC)); - return fdAshmem; -} - - static int AshmemOpenLocked() { - int fd = -1; - - if (g_openFdApi == nullptr) { - g_openFdApi = ProbeAshmemFdFunction(); - } - - if (g_openFdApi != nullptr) { - fd = g_openFdApi(); - } else { - fd = GetAshmemDeviceFd(); - } - - if (fd < 0) { - fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR | O_CLOEXEC)); - } + int fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR | O_CLOEXEC)); if (fd < 0) { UTILS_LOGE("%{public}s: fd is invalid, fd = %{public}d", __func__, fd);