shm:// support on Android (#1870)
This commit is contained in:
parent
54b6e53feb
commit
7aa9fb5e51
3 changed files with 27 additions and 5 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#define DEBUGGER @DEBUGGER@
|
||||
#define HAVE_DECL_ADDR_NO_RANDOMIZE @HAVE_DECL_ADDR_NO_RANDOMIZE@
|
||||
#define HAVE_DECL_PROCCTL_ASLR_CTL @HAVE_DECL_PROCCTL_ASLR_CTL@
|
||||
#define HAVE_DECL_ASHMEM_NAME_LEN @HAVE_DECL_ASHMEM_NAME_LEN@
|
||||
#define HAVE_ARC4RANDOM_UNIFORM @HAVE_ARC4RANDOM_UNIFORM@
|
||||
#define HAVE_EXPLICIT_BZERO @HAVE_EXPLICIT_BZERO@
|
||||
#define HAVE_EXPLICIT_MEMSET @HAVE_EXPLICIT_MEMSET@
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@
|
|||
#include "rz_lib.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#if __ANDROID__ || EMSCRIPTEN
|
||||
#if EMSCRIPTEN
|
||||
#undef __UNIX__
|
||||
#define __UNIX__ 0
|
||||
#endif
|
||||
|
||||
#if __UNIX__ && !defined(__QNX__) && !defined(__HAIKU__)
|
||||
#if HAVE_DECL_ASHMEM_NAME_LEN
|
||||
#include <linux/ashmem.h>
|
||||
#endif
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/mman.h>
|
||||
|
|
@ -55,7 +58,7 @@ static int shm__close(RzIODesc *fd) {
|
|||
rz_return_val_if_fail(fd && fd->data, -1);
|
||||
int ret;
|
||||
RzIOShm *shm = fd->data;
|
||||
#if HAVE_SHM_OPEN
|
||||
#if HAVE_SHM_OPEN || HAVE_DECL_ASHMEM_NAME_LEN
|
||||
ret = close(shm->fd);
|
||||
#else
|
||||
if (shm->buf) {
|
||||
|
|
@ -91,7 +94,7 @@ static bool shm__plugin_open(RzIO *io, const char *pathname, bool many) {
|
|||
return (!strncmp(pathname, "shm://", 6));
|
||||
}
|
||||
|
||||
#if !HAVE_SHM_OPEN
|
||||
#if !HAVE_SHM_OPEN && !HAVE_DECL_ASHMEM_NAME_LEN
|
||||
static inline int getshmfd(RzIOShm *shm) {
|
||||
return (((int)(size_t)shm->buf) >> 4) & 0xfff;
|
||||
}
|
||||
|
|
@ -120,9 +123,14 @@ static RzIODesc *shm__open(RzIO *io, const char *uri, int rw, int mode) {
|
|||
}
|
||||
|
||||
shm->name = rz_str_newf("/%s", name);
|
||||
#if HAVE_SHM_OPEN
|
||||
#if HAVE_SHM_OPEN || HAVE_DECL_ASHMEM_NAME_LEN
|
||||
shm->id = rz_str_hash(name);
|
||||
|
||||
#if HAVE_SHM_OPEN
|
||||
shm->fd = shm_open(shm->name, O_CREAT | (rw ? O_RDWR : O_RDONLY), 0644);
|
||||
#else // HAVE_DECL_ASHMEM_NAME_LEN
|
||||
shm->fd = open("/dev/ashmem", O_CREAT | (rw ? O_RDWR : O_RDONLY), 0644);
|
||||
#endif
|
||||
if (shm->fd == -1) {
|
||||
RZ_LOG_ERROR("Cannot connect to shared memory \"%s\" (0x%08x)\n", shm->name, shm->id);
|
||||
free(shm->name);
|
||||
|
|
@ -139,9 +147,20 @@ static RzIODesc *shm__open(RzIO *io, const char *uri, int rw, int mode) {
|
|||
fstat(shm->fd, &st);
|
||||
shm->size = st.st_size;
|
||||
}
|
||||
|
||||
#if HAVE_DECL_ASHMEM_NAME_LEN
|
||||
if (ioctl(shm->fd, ASHMEM_SET_NAME, name) == -1 ||
|
||||
ioctl(shm->fd, ASHMEM_SET_SIZE, shm->size) == -1) {
|
||||
RZ_LOG_ERROR("Cannot set shared memory \"%s\"/%lu (0x%08x)\n", shm->name, (unsigned long)shm->size, shm->id);
|
||||
close(shm->fd);
|
||||
free(shm->name);
|
||||
free(shm);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
shm->buf = mmap(NULL, shm->size, (rw ? (PROT_READ | PROT_WRITE) : PROT_READ), MAP_SHARED, shm->fd, 0);
|
||||
if (shm->buf == MAP_FAILED) {
|
||||
RZ_LOG_ERROR("Cannot mmap shared memory \"%s\" (0x%08x)\n", shm->name, shm->id);
|
||||
RZ_LOG_ERROR("Cannot mmap shared memory \"%s\"/%lu (0x%08x)", shm->name, (unsigned long)shm->size, shm->id);
|
||||
close(shm->fd);
|
||||
free(shm->name);
|
||||
free(shm);
|
||||
|
|
|
|||
|
|
@ -360,6 +360,8 @@ ok = cc.has_header_symbol('sys/personality.h', 'ADDR_NO_RANDOMIZE')
|
|||
userconf.set10('HAVE_DECL_ADDR_NO_RANDOMIZE', ok)
|
||||
ok = cc.has_header_symbol('sys/procctl.h', 'PROC_ASLR_CTL')
|
||||
userconf.set10('HAVE_DECL_PROCCTL_ASLR_CTL', ok)
|
||||
ok = cc.has_header_symbol('linux/ashmem.h', 'ASHMEM_NAME_LEN')
|
||||
userconf.set10('HAVE_DECL_ASHMEM_NAME_LEN', ok)
|
||||
|
||||
if host_machine.system() == 'freebsd' or host_machine.system() == 'dragonfly'
|
||||
add_project_link_arguments('-Wl,--unresolved-symbols,ignore-in-object-files', language: 'c')
|
||||
|
|
|
|||
Loading…
Reference in a new issue