8 #if HAVE_HEADER_LINUX_ASHMEM_H || HAVE_HEADER_SYS_SHM_H || __WINDOWS__
9 #if HAVE_HEADER_LINUX_ASHMEM_H
10 #include <linux/ashmem.h>
12 #if HAVE_HEADER_SYS_SHM_H
15 #if HAVE_HEADER_SYS_IPC_H
18 #if HAVE_HEADER_SYS_MMAN_H
37 #define SHMATSZ 0x9000;
41 RzIOShm *shm =
fd->data;
46 #if !defined(__WINDOWS__)
55 RzIOShm *shm =
fd->data;
57 if (io->
off > shm->size) {
66 #if !defined(__WINDOWS__)
76 RzIOShm *shm =
fd->data;
78 UnmapViewOfFile(shm->buf);
79 ret = CloseHandle(shm->h);
81 #if HAVE_SHM_OPEN || HAVE_HEADER_LINUX_ASHMEM_H
85 ret = shmdt(((RzIOShm *)(
fd->data))->buf);
98 RzIOShm *shm =
fd->data;
104 return io->
off = shm->size;
109 return io->
off = (shm->size ? shm->size : 0xffffffff) +
offset;
114 static bool shm__plugin_open(
RzIO *io,
const char *
pathname,
bool many) {
115 return (!strncmp(
pathname,
"shm://", 6));
118 #if !HAVE_SHM_OPEN && !HAVE_HEADER_LINUX_ASHMEM_H
119 static inline int getshmfd(RzIOShm *shm) {
120 return (((
int)(
size_t)shm->buf) >> 4) & 0xfff;
125 if (strncmp(uri,
"shm://", 6)) {
128 RzIOShm *shm =
RZ_NEW0(RzIOShm);
132 const char *
name = strstr(uri,
"://");
149 const DWORD desired_access = rw ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ;
150 shm->h = OpenFileMappingW(desired_access,
FALSE, wname);
153 RZ_LOG_ERROR(
"Cannot open shared memory \"%s\"\n", shm->name);
158 size_t given_size = 0;
160 shm->size = given_size;
162 shm->buf = MapViewOfFile(shm->h, desired_access, 0, 0, given_size);
164 RZ_LOG_ERROR(
"Cannot map shared memory \"%s\"\n", shm->name);
170 MEMORY_BASIC_INFORMATION
mi;
171 if (VirtualQuery(shm->buf, &
mi,
sizeof(
mi)) ==
sizeof(
mi)) {
172 shm->size =
mi.RegionSize;
175 RZ_LOG_INFO(
"Connected to shared memory \"%s\" size 0x%x\n",
176 shm->name, shm->size);
178 #if HAVE_SHM_OPEN || HAVE_HEADER_LINUX_ASHMEM_H
187 RZ_LOG_ERROR(
"Cannot connect to shared memory \"%s\" (0x%08x)\n", shm->name, shm->id);
196 shm->size = given_size;
199 if (
fstat(shm->fd, &st)) {
200 RZ_LOG_ERROR(
"Cannot determine the size of shared memory \"%s\" (0x%08x)\n", shm->name, shm->id);
206 shm->size = st.st_size;
209 #if HAVE_HEADER_LINUX_ASHMEM_H
210 if (
ioctl(shm->fd, ASHMEM_SET_NAME,
name) == -1 ||
211 ioctl(shm->fd, ASHMEM_SET_SIZE, shm->size) == -1) {
212 RZ_LOG_ERROR(
"Cannot set shared memory \"%s\"/%lu (0x%08x)\n", shm->name, (
unsigned long)shm->size, shm->id);
220 if (shm->buf == MAP_FAILED) {
221 RZ_LOG_ERROR(
"Cannot mmap shared memory \"%s\"/%lu (0x%08x)", shm->name, (
unsigned long)shm->size, shm->id);
233 shm->buf =
shmat(shm->id, 0, 0);
234 if (shm->buf == (
void *)(
size_t)-1) {
237 shm->fd = getshmfd(shm);
241 RZ_LOG_ERROR(
"Cannot connect to shared memory (%d)\n", shm->id);
247 RZ_LOG_INFO(
"Connected to shared memory \"%s\" (0x%08x) size 0x%x\n",
248 shm->name, shm->id, shm->size);
255 .desc =
"Shared memory resources plugin",
261 .check = shm__plugin_open,
269 .desc =
"shared memory resources",
273 #ifndef RZ_PLUGIN_INCORE
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg shmat
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset fstat
static static sync static getppid static getegid const char static filename ioctl
RZ_API void Ht_() free(HtName_(Ht) *ht)
RzIOPlugin rz_io_plugin_shm
RZ_API RzLibStruct rizin_plugin
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char pathname
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags mmap
#define rz_return_val_if_fail(expr, val)
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
#define RZ_LOG_INFO(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API ut64 rz_str_djb2_hash(const char *str)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
int read(izstream &zs, T *x, Items items)