diff options
| author | 2022-12-17 23:29:15 -0800 | |
|---|---|---|
| committer | 2023-06-03 00:05:26 -0700 | |
| commit | afdee9abea39637eb145d7ddb98a316a597da1bd (patch) | |
| tree | 1df70bf234ec532bf4f5fa9e8781fb8fc191d3de | |
| parent | android: Minimal JNI for yuzu. (diff) | |
| download | yuzu-afdee9abea39637eb145d7ddb98a316a597da1bd.tar.gz yuzu-afdee9abea39637eb145d7ddb98a316a597da1bd.tar.xz yuzu-afdee9abea39637eb145d7ddb98a316a597da1bd.zip | |
common: host_memory: Implement for Android.
Diffstat (limited to '')
| -rw-r--r-- | src/common/host_memory.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 8e4f1f97a..703ddb4a4 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp | |||
| @@ -11,6 +11,10 @@ | |||
| 11 | 11 | ||
| 12 | #elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv | 12 | #elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv |
| 13 | 13 | ||
| 14 | #ifdef ANDROID | ||
| 15 | #include <android/sharedmem.h> | ||
| 16 | #endif | ||
| 17 | |||
| 14 | #ifndef _GNU_SOURCE | 18 | #ifndef _GNU_SOURCE |
| 15 | #define _GNU_SOURCE | 19 | #define _GNU_SOURCE |
| 16 | #endif | 20 | #endif |
| @@ -366,17 +370,20 @@ public: | |||
| 366 | } | 370 | } |
| 367 | 371 | ||
| 368 | // Backing memory initialization | 372 | // Backing memory initialization |
| 369 | #if defined(__FreeBSD__) && __FreeBSD__ < 13 | 373 | #ifdef ANDROID |
| 374 | fd = ASharedMemory_create("HostMemory", backing_size); | ||
| 375 | #elif defined(__FreeBSD__) && __FreeBSD__ < 13 | ||
| 370 | // XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30 | 376 | // XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30 |
| 371 | fd = shm_open(SHM_ANON, O_RDWR, 0600); | 377 | fd = shm_open(SHM_ANON, O_RDWR, 0600); |
| 372 | #else | 378 | #else |
| 373 | fd = memfd_create("HostMemory", 0); | 379 | fd = memfd_create("HostMemory", 0); |
| 374 | #endif | 380 | #endif |
| 375 | if (fd == -1) { | 381 | if (fd < 0) { |
| 376 | LOG_CRITICAL(HW_Memory, "memfd_create failed: {}", strerror(errno)); | 382 | LOG_CRITICAL(HW_Memory, "memfd_create failed: {}", strerror(errno)); |
| 377 | throw std::bad_alloc{}; | 383 | throw std::bad_alloc{}; |
| 378 | } | 384 | } |
| 379 | 385 | ||
| 386 | #ifndef ANDROID | ||
| 380 | // Defined to extend the file with zeros | 387 | // Defined to extend the file with zeros |
| 381 | int ret = ftruncate(fd, backing_size); | 388 | int ret = ftruncate(fd, backing_size); |
| 382 | if (ret != 0) { | 389 | if (ret != 0) { |
| @@ -384,6 +391,7 @@ public: | |||
| 384 | strerror(errno)); | 391 | strerror(errno)); |
| 385 | throw std::bad_alloc{}; | 392 | throw std::bad_alloc{}; |
| 386 | } | 393 | } |
| 394 | #endif | ||
| 387 | 395 | ||
| 388 | backing_base = static_cast<u8*>( | 396 | backing_base = static_cast<u8*>( |
| 389 | mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); | 397 | mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); |