Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ef8494c authored by Yiwei Zhang's avatar Yiwei Zhang
Browse files

Game Driver: add required sphal libraries to game driver namespace

Bug: 124448366
Test: Build, flash and boot. Verify if those libraries are loaded.
Change-Id: I2673c47ee75c08d283efdec650a082b742c45768
parent 974085a2
Loading
Loading
Loading
Loading
+26 −5
Original line number Original line Diff line number Diff line
@@ -146,14 +146,18 @@ int GraphicsEnv::getCanLoadSystemLibraries() {
    return 0;
    return 0;
}
}


void GraphicsEnv::setDriverPath(const std::string path) {
void GraphicsEnv::setDriverPathAndSphalLibraries(const std::string path,
    if (!mDriverPath.empty()) {
                                                 const std::string sphalLibraries) {
        ALOGV("ignoring attempt to change driver path from '%s' to '%s'", mDriverPath.c_str(),
    if (!mDriverPath.empty() || !mSphalLibraries.empty()) {
              path.c_str());
        ALOGV("ignoring attempt to change driver path from '%s' to '%s' or change sphal libraries "
              "from '%s' to '%s'",
              mDriverPath.c_str(), path.c_str(), mSphalLibraries.c_str(), sphalLibraries.c_str());
        return;
        return;
    }
    }
    ALOGV("setting driver path to '%s'", path.c_str());
    ALOGV("setting driver path to '%s' and sphal libraries to '%s'", path.c_str(),
          sphalLibraries.c_str());
    mDriverPath = path;
    mDriverPath = path;
    mSphalLibraries = sphalLibraries;
}
}


void GraphicsEnv::setGpuStats(const std::string& driverPackageName,
void GraphicsEnv::setGpuStats(const std::string& driverPackageName,
@@ -536,6 +540,23 @@ android_namespace_t* GraphicsEnv::getDriverNamespace() {
            mDriverNamespace = nullptr;
            mDriverNamespace = nullptr;
            return;
            return;
        }
        }

        if (mSphalLibraries.empty()) return;

        // Make additional libraries in sphal to be accessible
        auto sphalNamespace = android_get_exported_namespace("sphal");
        if (!sphalNamespace) {
            ALOGE("Depend on these libraries[%s] in sphal, but failed to get sphal namespace",
                  mSphalLibraries.c_str());
            mDriverNamespace = nullptr;
            return;
        }

        if (!android_link_namespaces(mDriverNamespace, sphalNamespace, mSphalLibraries.c_str())) {
            ALOGE("Failed to link sphal namespace[%s]", dlerror());
            mDriverNamespace = nullptr;
            return;
        }
    });
    });


    return mDriverNamespace;
    return mDriverNamespace;
+5 −1
Original line number Original line Diff line number Diff line
@@ -77,7 +77,10 @@ public:
    // (drivers must be stored uncompressed and page aligned); such elements
    // (drivers must be stored uncompressed and page aligned); such elements
    // in the search path must have a '!' after the zip filename, e.g.
    // in the search path must have a '!' after the zip filename, e.g.
    //     /data/app/com.example.driver/base.apk!/lib/arm64-v8a
    //     /data/app/com.example.driver/base.apk!/lib/arm64-v8a
    void setDriverPath(const std::string path);
    // Also set additional required sphal libraries to the linker for loading
    // graphics drivers. The string is a list of libraries separated by ':',
    // which is required by android_link_namespaces.
    void setDriverPathAndSphalLibraries(const std::string path, const std::string sphalLibraries);
    android_namespace_t* getDriverNamespace();
    android_namespace_t* getDriverNamespace();
    void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
    void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
                     uint64_t versionCode, int64_t driverBuildTime,
                     uint64_t versionCode, int64_t driverBuildTime,
@@ -118,6 +121,7 @@ private:


    GraphicsEnv() = default;
    GraphicsEnv() = default;
    std::string mDriverPath;
    std::string mDriverPath;
    std::string mSphalLibraries;
    std::mutex mStatsLock;
    std::mutex mStatsLock;
    GpuStats mGpuStats;
    GpuStats mGpuStats;
    std::string mAnglePath;
    std::string mAnglePath;