Hash :
2ebd583e
Author :
Date :
2021-12-22T11:24:43
Android: Remove setenv from common path In Android production stress testing, the setenv call was causing a race condition. To fix, only use setenv in the paths that need it as a performance optimization. Specifically, FrameCapture makes use of it every frame. Bug: angleproject:6822 Change-Id: I452f1ef8607ca9baf15d69246932c47454a3ce46 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3353893 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Ian Elliott <ianelliott@google.com> Commit-Queue: Cody Northrop <cnorthrop@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// system_utils.cpp: Implementation of common functions
#include "common/system_utils.h"
#include <stdlib.h>
#if defined(ANGLE_PLATFORM_ANDROID)
# include <sys/system_properties.h>
#endif
namespace angle
{
std::string GetExecutableName()
{
#if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 21
// Support for "getprogname" function in bionic was introduced in L (API level 21)
const char *executableName = getprogname();
return (executableName) ? std::string(executableName) : "ANGLE";
#else
std::string executableName = GetExecutablePath();
size_t lastPathSepLoc = executableName.find_last_of(GetPathSeparator());
return (lastPathSepLoc > 0 ? executableName.substr(lastPathSepLoc + 1, executableName.length())
: "ANGLE");
#endif // ANGLE_PLATFORM_ANDROID
}
// On Android return value cached in the process environment, if none, call
// GetEnvironmentVarOrUnCachedAndroidProperty if not in environment.
std::string GetEnvironmentVarOrAndroidProperty(const char *variableName, const char *propertyName)
{
#if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 21
// Can't use GetEnvironmentVar here because that won't allow us to distinguish between the
// environment being set to an empty string vs. not set at all.
const char *variableValue = getenv(variableName);
if (variableValue != nullptr)
{
std::string value(variableValue);
return value;
}
#endif
return GetEnvironmentVarOrUnCachedAndroidProperty(variableName, propertyName);
}
// On Android call out to 'getprop' on a shell to get an Android property. On desktop, return
// the value of the environment variable.
std::string GetEnvironmentVarOrUnCachedAndroidProperty(const char *variableName,
const char *propertyName)
{
#if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 26
std::string propertyValue;
const prop_info *propertyInfo = __system_property_find(propertyName);
if (propertyInfo != nullptr)
{
__system_property_read_callback(
propertyInfo,
[](void *cookie, const char *, const char *value, unsigned) {
auto propertyValue = reinterpret_cast<std::string *>(cookie);
*propertyValue = value;
},
&propertyValue);
}
return propertyValue;
#else
// Return the environment variable's value.
return GetEnvironmentVar(variableName);
#endif // ANGLE_PLATFORM_ANDROID
}
// Look up a property and add it to the application's environment.
// Adding to the env is a performance optimization, as getting properties is expensive.
// This should only be used in non-Release paths, i.e. when using FrameCapture or DebugUtils.
// It can cause race conditions in stress testing. See http://anglebug.com/6822
std::string GetAndSetEnvironmentVarOrUnCachedAndroidProperty(const char *variableName,
const char *propertyName)
{
std::string value = GetEnvironmentVarOrUnCachedAndroidProperty(variableName, propertyName);
#if defined(ANGLE_PLATFORM_ANDROID)
if (!value.empty())
{
// Set the environment variable with the value to improve future lookups (avoids
SetEnvironmentVar(variableName, value.c_str());
}
#endif
return value;
}
bool GetBoolEnvironmentVar(const char *variableName)
{
std::string envVarString = GetEnvironmentVar(variableName);
return (!envVarString.empty() && envVarString == "1");
}
bool PrependPathToEnvironmentVar(const char *variableName, const char *path)
{
std::string oldValue = GetEnvironmentVar(variableName);
const char *newValue = nullptr;
std::string buf;
if (oldValue.empty())
{
newValue = path;
}
else
{
buf = path;
buf += GetPathSeparatorForEnvironmentVar();
buf += oldValue;
newValue = buf.c_str();
}
return SetEnvironmentVar(variableName, newValue);
}
bool IsFullPath(std::string dirName)
{
if (dirName.find(GetRootDirectory()) == 0)
{
return true;
}
return false;
}
std::string ConcatenatePath(std::string first, std::string second)
{
if (first.empty())
{
return second;
}
if (second.empty())
{
return first;
}
if (IsFullPath(second))
{
return second;
}
bool firstRedundantPathSeparator = first.find_last_of(GetPathSeparator()) == first.length() - 1;
bool secondRedundantPathSeparator = second.find(GetPathSeparator()) == 0;
if (firstRedundantPathSeparator && secondRedundantPathSeparator)
{
return first + second.substr(1);
}
else if (firstRedundantPathSeparator || secondRedundantPathSeparator)
{
return first + second;
}
return first + GetPathSeparator() + second;
}
PageFaultHandler::PageFaultHandler(PageFaultCallback callback) : mCallback(callback) {}
PageFaultHandler::~PageFaultHandler() {}
} // namespace angle