Min. API version to 26 (8.0) and use ASharedMemory

Move Minimum API version to Android 8.0 and switch from /dev/ashmem to ASharedMemory APIs.
This commit is contained in:
◱ PixelyIon 2019-11-15 23:44:40 +05:30
parent 423540328a
commit 0d141b71e9
2 changed files with 4 additions and 9 deletions

View File

@ -5,7 +5,7 @@ android {
buildToolsVersion '29.0.2'
defaultConfig {
applicationId "skyline.emu"
minSdkVersion 24
minSdkVersion 26
targetSdkVersion 29
versionCode 3
versionName "0.3"

View File

@ -1,22 +1,17 @@
#include "KSharedMemory.h"
#include <nce.h>
#include <fcntl.h>
#include <android/sharedmem.h>
#include <unistd.h>
constexpr const char *ASHMEM_NAME_DEF = "dev/ashmem";
constexpr int ASHMEM_SET_SIZE = 0x40087703;
namespace skyline::kernel::type {
u64 MapSharedFunc(u64 address, size_t size, u64 perms, u64 fd) {
return reinterpret_cast<u64>(mmap(reinterpret_cast<void *>(address), size, static_cast<int>(perms), MAP_SHARED | ((address) ? MAP_FIXED : 0), static_cast<int>(fd), 0)); // NOLINT(hicpp-signed-bitwise)
}
KSharedMemory::KSharedMemory(const DeviceState &state, pid_t pid, u64 kaddress, size_t ksize, const memory::Permission localPermission, const memory::Permission remotePermission, memory::Type type) : kaddress(kaddress), ksize(ksize), localPermission(localPermission), remotePermission(remotePermission), type(type), owner(pid), KObject(state, KType::KSharedMemory) {
fd = open(ASHMEM_NAME_DEF, O_RDWR | O_CLOEXEC); // NOLINT(hicpp-signed-bitwise)
fd = ASharedMemory_create("", ksize);
if (fd < 0)
throw exception("An error occurred while opening {}: {}", ASHMEM_NAME_DEF, fd);
if (ioctl(fd, ASHMEM_SET_SIZE, ksize) < 0) // NOLINT(hicpp-signed-bitwise)
throw exception("An error occurred while setting shared memory size: {}", ksize);
throw exception("An error occurred while creating shared memory: {}", fd);
kaddress = MapSharedFunc(kaddress, ksize, static_cast<u64>(pid ? remotePermission.Get() : localPermission.Get()), static_cast<u64>(fd));
if (kaddress == reinterpret_cast<u64>(MAP_FAILED)) // NOLINT(hicpp-signed-bitwise)
throw exception("An occurred while mapping shared region: {}", strerror(errno));