static int mmio_read_x(int argc, const char *argv[], const struct cmd_info *info) { int ret; data_store data; struct mmap_info mmap_addr; const struct mmap_file_flags *mmf; mmf = info->privdata; mmap_addr.addr = strtoull(argv[1], NULL, 0); if (open_mapping(&mmap_addr, O_RDONLY | mmf->flags, sizeof(data)) < 0) { return -1; } ret = 0; #define DO_READ(mem_, off_, size_)\ data.u ##size_ = *(typeof(data.u ##size_) *)(mem_ + off_); \ fprintf(stdout, "0x%0*llx\n", (int)sizeof(data.u ##size_)*2, \ (unsigned long long)data.u ##size_) switch (get_command_size(info)) { case SIZE8: DO_READ(mmap_addr.mem, mmap_addr.off, 8); break; case SIZE16: DO_READ(mmap_addr.mem, mmap_addr.off, 16); break; case SIZE32: DO_READ(mmap_addr.mem, mmap_addr.off, 32); break; case SIZE64: if (sizeof(void *) != sizeof(uint64_t)) { fprintf(stderr, "warning: 64 bit operations might " "not be atomic on 32 bit builds\n"); } DO_READ(mmap_addr.mem, mmap_addr.off, 64); break; default: fprintf(stderr, "invalid mmio_read parameter\n"); ret = -1; } close_mapping(&mmap_addr); return ret; }
static struct KeywordList * getKeywords(struct EXTRACT_Process * eproc, const char * filename) { struct KeywordList * pos; struct KeywordList * next; struct KeywordList * head; unsigned int count; size_t slen; int status; if (eproc->pid == -1) if (0 != do_fork(eproc)) return NULL; if (eproc->pid == -1) return NULL; fprintf(stderr, "Processing file %s\n", filename); head = NULL; pos = NULL; next = NULL; DO_WRITE(eproc->send_pipe, filename, strlen(filename)+1); DO_READ(eproc->read_pipe, &count, sizeof(unsigned int)); while (count-- > 0) { next = malloc(sizeof(struct KeywordList)); DO_READ(eproc->read_pipe, &next->keywordType, sizeof(enum EXTRACTOR_MetaType)); DO_READ(eproc->read_pipe, &slen, sizeof(size_t)); if (slen == 0) { free(next); next = NULL; continue; } if (slen > MAX_SLEN) goto ERROR; /* too large! something must have gone wrong! */ if (pos == NULL) { pos = next; next = NULL; head = pos; } else { pos->next = next; next = NULL; pos = pos->next; } pos->next = NULL; pos->keyword = malloc(slen + 1); pos->keyword[slen] = '\0'; DO_READ(eproc->read_pipe, pos->keyword, slen); } return head; ERROR: #if DEBUG_IPC fprintf(stderr, "READ ERROR!\n"); #endif if (next != NULL) free(next); freeKeywords(head); if (eproc->send_pipe != -1) close(eproc->send_pipe); eproc->send_pipe = -1; if (eproc->read_pipe != -1) close(eproc->read_pipe); eproc->read_pipe = -1; if (eproc->pid != -1) { kill(eproc->pid, SIGTERM); waitpid(eproc->pid, &status, 0); } eproc->pid = -1; return NULL; }