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

Commit 0a33671e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix use after free issue found with ASAN build"

parents b22db0fd 30ad2abf
Loading
Loading
Loading
Loading
+2 −35
Original line number Diff line number Diff line
@@ -145,11 +145,11 @@ long GraphicsEnv::getAngleRulesLength() {
    return mAngleRulesLength;
}

const std::string GraphicsEnv::getLayerPaths(){
const std::string& GraphicsEnv::getLayerPaths() {
    return mLayerPaths;
}

const std::string GraphicsEnv::getDebugLayers() {
const std::string& GraphicsEnv::getDebugLayers() {
    return mDebugLayers;
}

@@ -196,36 +196,3 @@ android_namespace_t* GraphicsEnv::getAngleNamespace() {
}

} // namespace android

extern "C" {
android_namespace_t* android_getDriverNamespace() {
    return android::GraphicsEnv::getInstance().getDriverNamespace();
}
android_namespace_t* android_getAngleNamespace() {
    return android::GraphicsEnv::getInstance().getAngleNamespace();
}
const char* android_getAngleAppName() {
    return android::GraphicsEnv::getInstance().getAngleAppName();
}
bool android_getAngleDeveloperOptIn() {
    return android::GraphicsEnv::getInstance().getAngleDeveloperOptIn();
}
const char* android_getAngleAppPref() {
    return android::GraphicsEnv::getInstance().getAngleAppPref();
}
int android_getAngleRulesFd() {
   return android::GraphicsEnv::getInstance().getAngleRulesFd();
}
long android_getAngleRulesOffset() {
   return android::GraphicsEnv::getInstance().getAngleRulesOffset();
}
long android_getAngleRulesLength() {
   return android::GraphicsEnv::getInstance().getAngleRulesLength();
}
const char* android_getLayerPaths() {
    return android::GraphicsEnv::getInstance().getLayerPaths().c_str();
}
const char* android_getDebugLayers() {
    return android::GraphicsEnv::getInstance().getDebugLayers().c_str();
}
}
+2 −26
Original line number Diff line number Diff line
@@ -58,10 +58,10 @@ public:
    void setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths);
    NativeLoaderNamespace* getAppNamespace();

    const std::string getLayerPaths();
    const std::string& getLayerPaths();

    void setDebugLayers(const std::string layers);
    const std::string getDebugLayers();
    const std::string& getDebugLayers();

private:
    GraphicsEnv() = default;
@@ -82,28 +82,4 @@ private:

} // namespace android

/* FIXME
 * Export an un-mangled function that just does
 *     return android::GraphicsEnv::getInstance().getDriverNamespace();
 * This allows libEGL to get the function pointer via dlsym, since it can't
 * directly link against libgui. In a future release, we'll fix this so that
 * libgui does not depend on graphics API libraries, and libEGL can link
 * against it. The current dependencies from libgui -> libEGL are:
 *  - the GLConsumer class, which should be moved to its own library
 *  - the EGLsyncKHR synchronization in BufferQueue, which is deprecated and
 *    will be removed soon.
 */
extern "C" {
    android_namespace_t* android_getDriverNamespace();
    android_namespace_t* android_getAngleNamespace();
    const char* android_getAngleAppName();
    const char* android_getAngleAppPref();
    bool android_getAngleDeveloperOptIn();
    int android_getAngleRulesFd();
    long android_getAngleRulesOffset();
    long android_getAngleRulesLength();
    const char* android_getLayerPaths();
    const char* android_getDebugLayers();
}

#endif // ANDROID_UI_GRAPHICS_ENV_H
+10 −9
Original line number Diff line number Diff line
@@ -529,12 +529,12 @@ static void* load_angle(const char* kind, android_namespace_t* ns, egl_connectio
    std::string name;
    char prop[PROPERTY_VALUE_MAX];

    const char* app_name = android_getAngleAppName();
    const char* app_pref = android_getAngleAppPref();
    bool developer_opt_in = android_getAngleDeveloperOptIn();
    const int rules_fd = android_getAngleRulesFd();
    const long rules_offset = android_getAngleRulesOffset();
    const long rules_length = android_getAngleRulesLength();
    const char* app_name = android::GraphicsEnv::getInstance().getAngleAppName();
    const char* app_pref = android::GraphicsEnv::getInstance().getAngleAppPref();
    bool developer_opt_in = android::GraphicsEnv::getInstance().getAngleDeveloperOptIn();
    const int rules_fd = android::GraphicsEnv::getInstance().getAngleRulesFd();
    const long rules_offset = android::GraphicsEnv::getInstance().getAngleRulesOffset();
    const long rules_length = android::GraphicsEnv::getInstance().getAngleRulesLength();

    // Determine whether or not to use ANGLE:
    ANGLEPreference developer_option = developer_opt_in ? ANGLE_PREFER_ANGLE : ANGLE_NO_PREFERENCE;
@@ -596,7 +596,8 @@ static void* load_angle(const char* kind, android_namespace_t* ns, egl_connectio
                fpANGLEUseForApplication ANGLEUseForApplication =
                        (fpANGLEUseForApplication)dlsym(so, "ANGLEUseForApplication");
                if (ANGLEUseForApplication) {
                    ANGLEPreference app_preference = getAnglePref(android_getAngleAppPref());
                    ANGLEPreference app_preference =
                            getAnglePref(android::GraphicsEnv::getInstance().getAngleAppPref());
                    use_angle = (ANGLEUseForApplication)(app_name_str.c_str(), manufacturer, model,
                                                         developer_option, app_preference);
                    ALOGV("Result of opt-in/out logic is %s", use_angle ? "true" : "false");
@@ -688,13 +689,13 @@ void *Loader::load_driver(const char* kind,
    ATRACE_CALL();

    void* dso = nullptr;
    android_namespace_t* ns = android_getAngleNamespace();
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
    if (ns) {
        dso = load_angle(kind, ns, cnx);
    }
#ifndef __ANDROID_VNDK__
    if (!dso) {
        android_namespace_t* ns = android_getDriverNamespace();
        android_namespace_t* ns = android::GraphicsEnv::getInstance().getDriverNamespace();
        if (ns) {
            dso = load_updated_driver(kind, ns);
        }
+1 −1
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ static bool addAnglePlatformAttributes(egl_connection_t* const cnx,
// Initialize function ptrs for ANGLE PlatformMethods struct, used for systrace
bool initializeAnglePlatform(EGLDisplay dpy) {
    // Since we're inside libEGL, use dlsym to lookup fptr for ANGLEGetDisplayPlatform
    android_namespace_t* ns = android_getAngleNamespace();
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
    const android_dlextinfo dlextinfo = {
            .flags = ANDROID_DLEXT_USE_NAMESPACE,
            .library_namespace = ns,
+4 −2
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ const char kSystemLayerLibraryDir[] = "/data/local/debug/gles";
std::string LayerLoader::GetDebugLayers() {
    // Layers can be specified at the Java level in GraphicsEnvironemnt
    // gpu_debug_layers = layer1:layer2:layerN
    std::string debug_layers = android_getDebugLayers();
    std::string debug_layers = android::GraphicsEnv::getInstance().getDebugLayers();

    if (debug_layers.empty()) {
        // Only check system properties if Java settings are empty
@@ -339,7 +339,9 @@ void LayerLoader::LoadLayers() {
    // Load the layers in reverse order so we start with the driver's entrypoint and work our way up
    for (int32_t i = layers.size() - 1; i >= 0; i--) {
        // Check each layer path for the layer
        std::vector<std::string> paths = android::base::Split(android_getLayerPaths(), ":");
        std::vector<std::string> paths =
                android::base::Split(android::GraphicsEnv::getInstance().getLayerPaths().c_str(),
                                     ":");

        if (!system_path.empty()) {
            // Prepend the system paths so they override other layers