static void read_header_files(void) { unsigned long long size; char *header_event; char buf[BUFSIZ]; read_or_die(buf, 12); if (memcmp(buf, "header_page", 12) != 0) die("did not read header page"); size = read8(); skip(size); /* * The size field in the page is of type long, * use that instead, since it represents the kernel. */ long_size = header_page_size_size; read_or_die(buf, 13); if (memcmp(buf, "header_event", 13) != 0) die("did not read header event"); size = read8(); header_event = malloc_or_die(size); read_or_die(header_event, size); free(header_event); }
static unsigned int read4(void) { unsigned int data; read_or_die(&data, 4); return __data2host4(data); }
static unsigned long long read8(void) { unsigned long long data; read_or_die(&data, 8); return __data2host8(data); }
size_t wav_to_doom(void **lumpdata, const char *filename) { void *data; size_t size = read_or_die(&data, filename); struct wav_header *header = data; struct doom_sound_header *out; if (size < sizeof(*header) - 1 || memcmp(header->riff, "RIFF", 4) != 0 || memcmp(header->wave, "WAVE", 4) != 0) die("Invalid WAV file: %s\n", filename); size = sizeof(*out) - 1 + LONG(header->datalen); out = xmalloc(size); out->log2bits = 3; out->rate = SHORT(LONG(header->samplerate)); out->length = header->datalen; memmove(out->samples, header->samples, LONG(header->datalen)); free(data); *lumpdata = out; return size; }
Config::Config(const char * config_filename) { QVariant config_root = read_or_die(config_filename); QMap<QString, QVariant> _config_map = config_root.toMap(); _simulation_config = _config_map[QString("simulation")].toMap(); _viewer_config = _config_map[QString("viewer")].toMap(); _window_config = _config_map[QString("window")].toMap(); }
static void read_event_file(char *sys, unsigned long long size) { char *buf; buf = malloc_or_die(size); read_or_die(buf, size); parse_event_file(buf, size, sys); free(buf); }
static void read_ftrace_file(unsigned long long size) { char *buf; buf = malloc_or_die(size); read_or_die(buf, size); parse_ftrace_file(buf, size); free(buf); }
/* If it fails, the next read will report it */ static void skip(int size) { char buf[BUFSIZ]; int r; while (size) { r = size > BUFSIZ ? BUFSIZ : size; read_or_die(buf, r); size -= r; }; }
/* Reads a snapshot record from a qcow2-formatted file. * * The function assumes the file position of 'fd' points to the beginning of a * QcowSnapshotHeader record. When the call returns, the file position of fd is * at the place where the next QcowSnapshotHeader should start, if there is one. * * C.f. QCowSnapshotHeader in block/qcow2-snapshot.c for the complete layout of * the header. */ static void snapshot_info_read( int fd, SnapshotInfo* info ) { uint64_t start_offset = seek_or_die(fd, 0, SEEK_CUR); uint32_t extra_data_size; uint16_t id_str_size, name_size; /* read fixed-length fields */ seek_or_die(fd, 12, SEEK_CUR); /* skip l1 info */ read_or_die(fd, &id_str_size, sizeof(id_str_size)); read_or_die(fd, &name_size, sizeof(name_size)); read_or_die(fd, &info->date_sec, sizeof(info->date_sec)); read_or_die(fd, &info->date_nsec, sizeof(info->date_nsec)); read_or_die(fd, &info->vm_clock_nsec, sizeof(info->vm_clock_nsec)); read_or_die(fd, &info->vm_state_size, sizeof(info->vm_state_size)); read_or_die(fd, &extra_data_size, sizeof(extra_data_size)); /* convert to host endianness */ be16_to_cpus(&id_str_size); be16_to_cpus(&name_size); be32_to_cpus(&info->date_sec); be32_to_cpus(&info->date_nsec); be64_to_cpus(&info->vm_clock_nsec); be32_to_cpus(&info->vm_state_size); be32_to_cpus(&extra_data_size); be32_to_cpus(&extra_data_size); /* read variable-length buffers*/ info->id_str = android_alloc(id_str_size + 1); // +1: manual null-termination info->name = android_alloc(name_size + 1); seek_or_die(fd, extra_data_size, SEEK_CUR); /* skip extra data */ read_or_die(fd, info->id_str, id_str_size); read_or_die(fd, info->name, name_size); info->id_str[id_str_size] = '\0'; info->name[name_size] = '\0'; /* headers are 8 byte aligned, ceil to nearest multiple of 8 */ uint64_t end_offset = seek_or_die(fd, 0, SEEK_CUR); uint32_t total_size = end_offset - start_offset; uint32_t aligned_size = ((total_size - 1) / 8 + 1) * 8; /* skip to start of next record */ seek_or_die(fd, start_offset + aligned_size, SEEK_SET); }
static unsigned int generate_srand_seed(void) { int fd; unsigned int seed; fd = open("/dev/urandom", O_RDONLY); if (fd < 0) return time(0); read_or_die(fd, &seed, sizeof(seed)); close(fd); return seed; }
size_t ppm_to_patch(void **lumpdata, const char *filename, int insert_x, int insert_y) { void *data; size_t size = read_or_die(&data, filename); int i, width, height, *column_colours; unsigned char *pixels, **columns, *patch; size_t *columnsizes, totalcolumnsize, offset; pixels = parseppm(data, size, filename, &width, &height); columns = xmalloc(width * sizeof(*columns)); columnsizes = xmalloc(width * sizeof(*columnsizes)); column_colours = xmalloc(height * sizeof(*column_colours)); for (totalcolumnsize = i = 0; i < width; i++) { pixels_to_colours(column_colours, pixels, width, height, i); columnsizes[i] = createcolumn(&columns[i], column_colours, height); totalcolumnsize += columnsizes[i]; } patch = xmalloc(8+4*width+totalcolumnsize); ((short *)patch)[0] = SHORT(width); ((short *)patch)[1] = SHORT(height); ((short *)patch)[2] = SHORT(insert_x); ((short *)patch)[3] = SHORT(insert_y); for (offset = 8+4*width, i = 0; i < width; i++) { ((int *)(patch+8))[i] = LONG(offset); offset += columnsizes[i]; } for (offset = 8+4*width, i = 0; i < width; i++) { memmove(patch + offset, columns[i], columnsizes[i]); offset += columnsizes[i]; free(columns[i]); } free(column_colours); free(columnsizes); free(columns); free(data); *lumpdata = patch; return 8+4*width+totalcolumnsize; }
void transport_fds(int rfd, int wfd) { payload_size_t _; int n; char *buf; n = read_int32(rfd, &_); assert(0 <= n); buf = (char *)alloca(sizeof(char) * n); read_or_die(rfd, buf, n); write_int32(wfd, n); write_or_die(wfd, buf, n); }
static void read_ftrace_printk(void) { unsigned int size; char *buf; size = read4(); if (!size) return; buf = malloc_or_die(size); read_or_die(buf, size); parse_ftrace_printk(buf, size); free(buf); }
static void read_proc_kallsyms(void) { unsigned int size; char *buf; size = read4(); if (!size) return; buf = malloc_or_die(size + 1); read_or_die(buf, size); buf[size] = '\0'; parse_proc_kallsyms(buf, size); free(buf); }
size_t ppm_to_bitmap(void **lumpdata, const char *filename) { void *data; size_t size = read_or_die(&data, filename); int i, j, width, height; unsigned char *pixels, *bitmap; pixels = parseppm(data, size, filename, &width, &height); bitmap = xmalloc(width * height); for (j = 0; j < height; j++) for (i = 0; i < width; i++) bitmap[width*j+i] = palette_getindex(&pixels[3*(width*j+i)]); free(data); *lumpdata = bitmap; return width * height; }
static void read_ftrace_printk(void) { unsigned int size; #else static void read_ftrace_; #endif char *buf; size = read4(); if (!size) return; buf = malloc_or_die(size); read_or_die(buf, size); #ifdef CONFIG_DEBUG_PRINTK parse_ftrace_printk(buf, size); #else parse_ftrace_; #endif free(buf); }
Config::Config(char * config_filename) { QVariant config_root = read_or_die(config_filename); _config_root = config_root.toMap(); }