Merge changes from topic "remove_ashmemd"
* changes: libcutils: route to /dev/ashmem<boot_id> instead of ashmemd ueventd: duplicate /dev/ashmem
This commit is contained in:
commit
f0d17fb50e
6 changed files with 42 additions and 54 deletions
|
@ -441,6 +441,23 @@ void DeviceHandler::HandleDevice(const std::string& action, const std::string& d
|
|||
}
|
||||
}
|
||||
|
||||
void DeviceHandler::HandleAshmemUevent(const Uevent& uevent) {
|
||||
if (uevent.device_name == "ashmem") {
|
||||
static const std::string boot_id_path = "/proc/sys/kernel/random/boot_id";
|
||||
std::string boot_id;
|
||||
if (!ReadFileToString(boot_id_path, &boot_id)) {
|
||||
PLOG(ERROR) << "Cannot duplicate ashmem device node. Failed to read " << boot_id_path;
|
||||
return;
|
||||
};
|
||||
boot_id = Trim(boot_id);
|
||||
|
||||
Uevent dup_ashmem_uevent = uevent;
|
||||
dup_ashmem_uevent.device_name += boot_id;
|
||||
dup_ashmem_uevent.path += boot_id;
|
||||
HandleUevent(dup_ashmem_uevent);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceHandler::HandleUevent(const Uevent& uevent) {
|
||||
if (uevent.action == "add" || uevent.action == "change" || uevent.action == "online") {
|
||||
FixupSysPermissions(uevent.path, uevent.subsystem);
|
||||
|
@ -485,6 +502,10 @@ void DeviceHandler::HandleUevent(const Uevent& uevent) {
|
|||
mkdir_recursive(Dirname(devpath), 0755);
|
||||
|
||||
HandleDevice(uevent.action, devpath, block, uevent.major, uevent.minor, links);
|
||||
|
||||
// Duplicate /dev/ashmem device and name it /dev/ashmem<boot_id>.
|
||||
// TODO(b/111903542): remove once all users of /dev/ashmem are migrated to libcutils API.
|
||||
HandleAshmemUevent(uevent);
|
||||
}
|
||||
|
||||
void DeviceHandler::ColdbootDone() {
|
||||
|
|
|
@ -130,6 +130,7 @@ class DeviceHandler : public UeventHandler {
|
|||
void HandleDevice(const std::string& action, const std::string& devpath, bool block, int major,
|
||||
int minor, const std::vector<std::string>& links) const;
|
||||
void FixupSysPermissions(const std::string& upath, const std::string& subsystem) const;
|
||||
void HandleAshmemUevent(const Uevent& uevent);
|
||||
|
||||
std::vector<Permissions> dev_permissions_;
|
||||
std::vector<SysfsPermissions> sysfs_permissions_;
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
*/
|
||||
#define LOG_TAG "ashmem"
|
||||
|
||||
#ifndef __ANDROID_VNDK__
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/ashmem.h>
|
||||
|
@ -42,11 +39,11 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
|
||||
#define ASHMEM_DEVICE "/dev/ashmem"
|
||||
|
||||
/* Will be added to UAPI once upstream change is merged */
|
||||
#define F_SEAL_FUTURE_WRITE 0x0010
|
||||
|
||||
|
@ -65,32 +62,6 @@ static dev_t __ashmem_rdev;
|
|||
*/
|
||||
static pthread_mutex_t __ashmem_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/*
|
||||
* We use ashmemd to enforce that apps don't open /dev/ashmem directly. Vendor
|
||||
* code can't access system aidl services per Treble requirements. So we limit
|
||||
* ashmemd access to the system variant of libcutils.
|
||||
*/
|
||||
#ifndef __ANDROID_VNDK__
|
||||
using openFdType = int (*)();
|
||||
|
||||
static openFdType openFd;
|
||||
|
||||
openFdType initOpenAshmemFd() {
|
||||
openFdType openFd = nullptr;
|
||||
void* handle = dlopen("libashmemd_client.so", RTLD_NOW);
|
||||
if (!handle) {
|
||||
ALOGE("Failed to dlopen() libashmemd_client.so: %s", dlerror());
|
||||
return openFd;
|
||||
}
|
||||
|
||||
openFd = reinterpret_cast<openFdType>(dlsym(handle, "openAshmemdFd"));
|
||||
if (!openFd) {
|
||||
ALOGE("Failed to dlsym() openAshmemdFd() function: %s", dlerror());
|
||||
}
|
||||
return openFd;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* has_memfd_support() determines if the device can use memfd. memfd support
|
||||
* has been there for long time, but certain things in it may be missing. We
|
||||
|
@ -215,25 +186,31 @@ static bool has_memfd_support() {
|
|||
return memfd_supported;
|
||||
}
|
||||
|
||||
static std::string get_ashmem_device_path() {
|
||||
static const std::string boot_id_path = "/proc/sys/kernel/random/boot_id";
|
||||
std::string boot_id;
|
||||
if (!android::base::ReadFileToString(boot_id_path, &boot_id)) {
|
||||
ALOGE("Failed to read %s: %s.\n", boot_id_path.c_str(), strerror(errno));
|
||||
return "";
|
||||
};
|
||||
boot_id = android::base::Trim(boot_id);
|
||||
|
||||
return "/dev/ashmem" + boot_id;
|
||||
}
|
||||
|
||||
/* logistics of getting file descriptor for ashmem */
|
||||
static int __ashmem_open_locked()
|
||||
{
|
||||
static const std::string ashmem_device_path = get_ashmem_device_path();
|
||||
|
||||
int ret;
|
||||
struct stat st;
|
||||
|
||||
int fd = -1;
|
||||
#ifndef __ANDROID_VNDK__
|
||||
if (!openFd) {
|
||||
openFd = initOpenAshmemFd();
|
||||
if (ashmem_device_path.empty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (openFd) {
|
||||
fd = openFd();
|
||||
}
|
||||
#endif
|
||||
if (fd < 0) {
|
||||
fd = TEMP_FAILURE_RETRY(open(ASHMEM_DEVICE, O_RDWR | O_CLOEXEC));
|
||||
}
|
||||
int fd = TEMP_FAILURE_RETRY(open(ashmem_device_path.c_str(), O_RDWR | O_CLOEXEC));
|
||||
if (fd < 0) {
|
||||
return fd;
|
||||
}
|
||||
|
@ -485,11 +462,3 @@ int ashmem_get_size_region(int fd)
|
|||
|
||||
return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL)));
|
||||
}
|
||||
|
||||
void ashmem_init() {
|
||||
#ifndef __ANDROID_VNDK__
|
||||
pthread_mutex_lock(&__ashmem_lock);
|
||||
openFd = initOpenAshmemFd();
|
||||
pthread_mutex_unlock(&__ashmem_lock);
|
||||
#endif //__ANDROID_VNDK__
|
||||
}
|
||||
|
|
|
@ -94,5 +94,3 @@ int ashmem_get_size_region(int fd)
|
|||
|
||||
return buf.st_size;
|
||||
}
|
||||
|
||||
void ashmem_init() {}
|
||||
|
|
|
@ -26,7 +26,6 @@ int ashmem_set_prot_region(int fd, int prot);
|
|||
int ashmem_pin_region(int fd, size_t offset, size_t len);
|
||||
int ashmem_unpin_region(int fd, size_t offset, size_t len);
|
||||
int ashmem_get_size_region(int fd);
|
||||
void ashmem_init();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ subsystem sound
|
|||
/dev/urandom 0666 root root
|
||||
# Make HW RNG readable by group system to let EntropyMixer read it.
|
||||
/dev/hw_random 0440 root system
|
||||
/dev/ashmem 0666 root root
|
||||
/dev/ashmem* 0666 root root
|
||||
/dev/binder 0666 root root
|
||||
/dev/hwbinder 0666 root root
|
||||
/dev/vndbinder 0666 root root
|
||||
|
|
Loading…
Reference in a new issue