static void choose_sample_fmt(AVStream *st, AVCodec *codec) { if (codec && codec->sample_fmts) { const enum AVSampleFormat *p = codec->sample_fmts; for (; *p != -1; p++) { if (*p == st->codec->sample_fmt) break; } if (*p == -1) { av_log(NULL, AV_LOG_WARNING, "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n", av_get_sample_fmt_name(st->codec->sample_fmt), codec->name, av_get_sample_fmt_name(codec->sample_fmts[0])); st->codec->sample_fmt = codec->sample_fmts[0]; } } }


static void unin_data_write(void *opaque, hwaddr addr, uint64_t val, unsigned len) { UNINState *s = opaque; PCIHostState *phb = PCI_HOST_BRIDGE(s); UNIN_DPRINTF("write addr %" TARGET_FMT_plx " len %d val %"PRIx64"\n", addr, len, val); pci_data_write(phb->bus, unin_get_config_reg(phb->config_reg, addr), val, len); }


static bool vhost_section(MemoryRegionSection *section) { return memory_region_is_ram(section->mr); }


static void test_visitor_out_native_list_int(TestOutputVisitorData *data, const void *unused) { test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER); }


QList *qlist_new(void) { QList *qlist; qlist = g_malloc(sizeof(*qlist)); QTAILQ_INIT(&qlist->head); QOBJECT_INIT(qlist, &qlist_type); return qlist; }


static int decode_wdlt(GetByteContext *gb, uint8_t *frame, int width, int height) { const uint8_t *frame_end = frame + width * height; uint8_t *line_ptr; int count, i, v, lines, segments; lines = bytestream2_get_le16(gb); if (lines > height) return -1; while (lines--) { if (bytestream2_get_bytes_left(gb) < 2) return -1; segments = bytestream2_get_le16u(gb); while ((segments & 0xC000) == 0xC000) { unsigned delta = -((int16_t)segments * width); if (frame_end - frame <= delta) return -1; frame += delta; segments = bytestream2_get_le16(gb); } if (segments & 0x8000) { frame[width - 1] = segments & 0xFF; segments = bytestream2_get_le16(gb); } line_ptr = frame; frame += width; while (segments--) { if (frame - line_ptr <= bytestream2_peek_byte(gb)) return -1; line_ptr += bytestream2_get_byte(gb); count = (int8_t)bytestream2_get_byte(gb); if (count >= 0) { if (frame - line_ptr < count * 2) return -1; if (bytestream2_get_buffer(gb, line_ptr, count * 2) != count * 2) return -1; line_ptr += count * 2; } else { count = -count; if (frame - line_ptr < count * 2) return -1; v = bytestream2_get_le16(gb); for (i = 0; i < count; i++) bytestream_put_le16(&line_ptr, v); } } } return 0; }


static void fw_cfg_comb_write(void *opaque, target_phys_addr_t addr, uint64_t value, unsigned size) { switch (size) { case 1: fw_cfg_write(opaque, (uint8_t)value); break; case 2: fw_cfg_select(opaque, (uint16_t)value); break; } }


void virtio_queue_notify(VirtIODevice *vdev, int n) { if (n < VIRTIO_PCI_QUEUE_MAX && vdev->vq[n].vring.desc) { trace_virtio_queue_notify(vdev, n, &vdev->vq[n]); vdev->vq[n].handle_output(vdev, &vdev->vq[n]); } }


void ioinst_handle_stcrw(S390CPU *cpu, uint32_t ipb) { CRW *crw; uint64_t addr; int cc; hwaddr len = sizeof(*crw); CPUS390XState *env = &cpu->env; addr = decode_basedisp_s(env, ipb); if (addr & 3) { program_interrupt(env, PGM_SPECIFICATION, 2); return; } crw = s390_cpu_physical_memory_map(env, addr, &len, 1); if (!crw || len != sizeof(*crw)) { program_interrupt(env, PGM_ADDRESSING, 2); goto out; } cc = css_do_stcrw(crw); /* 0 - crw stored, 1 - zeroes stored */ setcc(cpu, cc); out: s390_cpu_physical_memory_unmap(env, crw, len, 1); }


void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr, unsigned priority) { sysbus_mmio_map_common(dev, n, addr, true, priority); }


static int tpm_passthrough_test_tpmdev(int fd) { struct tpm_req_hdr req = { .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), .len = cpu_to_be32(sizeof(req)), .ordinal = cpu_to_be32(TPM_ORD_GetTicks), }; struct tpm_resp_hdr *resp; fd_set readfds; int n; struct timeval tv = { .tv_sec = 1, .tv_usec = 0, }; unsigned char buf[1024]; n = write(fd, &req, sizeof(req)); if (n < 0) { return errno; } if (n != sizeof(req)) { return EFAULT; } FD_ZERO(&readfds); FD_SET(fd, &readfds); /* wait for a second */ n = select(fd + 1, &readfds, NULL, NULL, &tv); if (n != 1) { return errno; } n = read(fd, &buf, sizeof(buf)); if (n < sizeof(struct tpm_resp_hdr)) { return EFAULT; } resp = (struct tpm_resp_hdr *)buf; /* check the header */ if (be16_to_cpu(resp->tag) != TPM_TAG_RSP_COMMAND || be32_to_cpu(resp->len) != n) { return EBADMSG; } return 0; }


static int tight_palette_insert(QDict *palette, uint32_t rgb, int bpp, int max) { uint8_t key[6]; int idx = qdict_size(palette); bool present; tight_palette_rgb2buf(rgb, bpp, key); present = qdict_haskey(palette, (char *)key); if (idx >= max && !present) { return 0; } if (!present) { qdict_put(palette, (char *)key, qint_from_int(idx)); } return qdict_size(palette); }


static void vnc_connect(VncDisplay *vd, int csock, bool skipauth, bool websocket) { VncState *vs = g_malloc0(sizeof(VncState)); int i; vs->csock = csock; vs->vd = vd; if (skipauth) { vs->auth = VNC_AUTH_NONE; vs->subauth = VNC_AUTH_INVALID; } else { if (websocket) { vs->auth = vd->ws_auth; vs->subauth = VNC_AUTH_INVALID; } else { vs->auth = vd->auth; vs->subauth = vd->subauth; } } VNC_DEBUG("Client sock=%d ws=%d auth=%d subauth=%d\n", csock, websocket, vs->auth, vs->subauth); vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect)); for (i = 0; i < VNC_STAT_ROWS; ++i) { vs->lossy_rect[i] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t)); } VNC_DEBUG("New client on socket %d\n", csock); update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE); qemu_set_nonblock(vs->csock); #ifdef CONFIG_VNC_WS if (websocket) { vs->websocket = 1; #ifdef CONFIG_VNC_TLS if (vd->ws_tls) { qemu_set_fd_handler(vs->csock, vncws_tls_handshake_io, NULL, vs); } else #endif /* CONFIG_VNC_TLS */ { qemu_set_fd_handler(vs->csock, vncws_handshake_read, NULL, vs); } } else #endif /* CONFIG_VNC_WS */ { qemu_set_fd_handler(vs->csock, vnc_client_read, NULL, vs); } vnc_client_cache_addr(vs); vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED); vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING); #ifdef CONFIG_VNC_WS if (!vs->websocket) #endif { vnc_init_state(vs); } if (vd->num_connecting > vd->connections_limit) { QTAILQ_FOREACH(vs, &vd->clients, next) { if (vs->share_mode == VNC_SHARE_MODE_CONNECTING) { vnc_disconnect_start(vs); return; } } } }


static void lsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid) { LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent); int out; out = (s->sstat1 & PHASE_MASK) == PHASE_DO; DPRINTF("Command complete status=%d\n", (int)status); s->status = status; s->command_complete = 2; if (s->waiting && s->dbc != 0) { /* Raise phase mismatch for short transfers. */ lsi_bad_phase(s, out, PHASE_ST); } else { lsi_set_phase(s, PHASE_ST); } if (s->current && req == s->current->req) { req->hba_private = NULL; lsi_request_free(s, s->current); scsi_req_unref(req); } lsi_resume_script(s); }


static ssize_t test_block_init_func(QCryptoBlock *block, void *opaque, size_t headerlen, Error **errp) { Buffer *header = opaque; g_assert_cmpint(header->capacity, ==, 0); buffer_reserve(header, headerlen); return headerlen; }


static inline void decode_hrd_parameters(H264Context *h, SPS *sps){ MpegEncContext * const s = &h->s; int cpb_count, i; cpb_count = get_ue_golomb(&s->gb) + 1; get_bits(&s->gb, 4); /* bit_rate_scale */ get_bits(&s->gb, 4); /* cpb_size_scale */ for(i=0; i<cpb_count; i++){ get_ue_golomb(&s->gb); /* bit_rate_value_minus1 */ get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */ get_bits1(&s->gb); /* cbr_flag */ } get_bits(&s->gb, 5); /* initial_cpb_removal_delay_length_minus1 */ sps->cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; sps->dpb_output_delay_length = get_bits(&s->gb, 5) + 1; sps->time_offset_length = get_bits(&s->gb, 5); }


void OPPROTO op_addw_ESI_T0(void) { ESI = (ESI & ~0xffff) | ((ESI + T0) & 0xffff); }


uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uint8_t lock) { MapCacheEntry *entry, *pentry = NULL; target_phys_addr_t address_index = phys_addr >> MCACHE_BUCKET_SHIFT; target_phys_addr_t address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1); target_phys_addr_t __size = size; trace_xen_map_cache(phys_addr); if (address_index == mapcache->last_address_index && !lock && !__size) { trace_xen_map_cache_return(mapcache->last_address_vaddr + address_offset); return mapcache->last_address_vaddr + address_offset; } /* size is always a multiple of MCACHE_BUCKET_SIZE */ if ((address_offset + (__size % MCACHE_BUCKET_SIZE)) > MCACHE_BUCKET_SIZE) __size += MCACHE_BUCKET_SIZE; if (__size % MCACHE_BUCKET_SIZE) __size += MCACHE_BUCKET_SIZE - (__size % MCACHE_BUCKET_SIZE); if (!__size) __size = MCACHE_BUCKET_SIZE; entry = &mapcache->entry[address_index % mapcache->nr_buckets]; while (entry && entry->lock && entry->vaddr_base && (entry->paddr_index != address_index || entry->size != __size || !test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT, entry->valid_mapping))) { pentry = entry; entry = entry->next; } if (!entry) { entry = g_malloc0(sizeof (MapCacheEntry)); pentry->next = entry; xen_remap_bucket(entry, __size, address_index); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index != address_index || entry->size != __size || !test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT, entry->valid_mapping)) { xen_remap_bucket(entry, __size, address_index); } } if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT, entry->valid_mapping)) { mapcache->last_address_index = -1; trace_xen_map_cache_return(NULL); return NULL; } mapcache->last_address_index = address_index; mapcache->last_address_vaddr = entry->vaddr_base; if (lock) { MapCacheRev *reventry = g_malloc0(sizeof(MapCacheRev)); entry->lock++; reventry->vaddr_req = mapcache->last_address_vaddr + address_offset; reventry->paddr_index = mapcache->last_address_index; reventry->size = entry->size; QTAILQ_INSERT_HEAD(&mapcache->locked_entries, reventry, next); } trace_xen_map_cache_return(mapcache->last_address_vaddr + address_offset); return mapcache->last_address_vaddr + address_offset; }


static unsigned int dec_move_pm(DisasContext *dc) { TCGv t0; int memsize; memsize = preg_sizes[dc->op2]; DIS(fprintf (logfile, "move.%c $p%u, [$r%u%s\n", memsize_char(memsize), dc->op2, dc->op1, dc->postinc ? "+]" : "]")); /* prepare store. Address in T0, value in T1. */ if (dc->op2 == PR_CCS) cris_evaluate_flags(dc); t0 = tcg_temp_new(TCG_TYPE_TL); t_gen_mov_TN_preg(t0, dc->op2); cris_flush_cc_state(dc); gen_store(dc, cpu_R[dc->op1], t0, memsize); tcg_temp_free(t0); cris_cc_mask(dc, 0); if (dc->postinc) tcg_gen_addi_tl(cpu_R[dc->op1], cpu_R[dc->op1], memsize); return 2; }


static void test_event_d(TestEventData *data, const void *unused) { UserDefOne struct1; EventStructOne a; UserDefZero z; QDict *d, *d_data, *d_a, *d_struct1; z.integer = 2; struct1.base = &z; struct1.string = g_strdup("test1"); struct1.has_enum1 = true; struct1.enum1 = ENUM_ONE_VALUE1; a.struct1 = &struct1; a.string = g_strdup("test2"); a.has_enum2 = true; a.enum2 = ENUM_ONE_VALUE2; d_struct1 = qdict_new(); qdict_put(d_struct1, "integer", qint_from_int(2)); qdict_put(d_struct1, "string", qstring_from_str("test1")); qdict_put(d_struct1, "enum1", qstring_from_str("value1")); d_a = qdict_new(); qdict_put(d_a, "struct1", d_struct1); qdict_put(d_a, "string", qstring_from_str("test2")); qdict_put(d_a, "enum2", qstring_from_str("value2")); d_data = qdict_new(); qdict_put(d_data, "a", d_a); qdict_put(d_data, "b", qstring_from_str("test3")); qdict_put(d_data, "enum3", qstring_from_str("value3")); d = data->expect; qdict_put(d, "event", qstring_from_str("EVENT_D")); qdict_put(d, "data", d_data); qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE3, &error_abort); g_free(struct1.string); g_free(a.string); }


void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1, qemu_irq irq) { IDEState *s; static int drive_serial = 1; int i, cylinders, heads, secs; uint64_t nb_sectors; for(i = 0; i < 2; i++) { s = bus->ifs + i; s->bus = bus; s->unit = i; if (i == 0 && hd0) s->bs = hd0->bdrv; if (i == 1 && hd1) s->bs = hd1->bdrv; s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4); if (s->bs) { bdrv_get_geometry(s->bs, &nb_sectors); bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); s->cylinders = cylinders; s->heads = heads; s->sectors = secs; s->nb_sectors = nb_sectors; /* The SMART values should be preserved across power cycles but they aren't. */ s->smart_enabled = 1; s->smart_autosave = 1; s->smart_errors = 0; s->smart_selftest_count = 0; s->smart_selftest_data = qemu_blockalign(s->bs, 512); if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) { s->is_cdrom = 1; bdrv_set_change_cb(s->bs, cdrom_change_cb, s); } } s->drive_serial = drive_serial++; strncpy(s->drive_serial_str, drive_get_serial(s->bs), sizeof(s->drive_serial_str)); if (strlen(s->drive_serial_str) == 0) snprintf(s->drive_serial_str, sizeof(s->drive_serial_str), "QM%05d", s->drive_serial); s->sector_write_timer = qemu_new_timer(vm_clock, ide_sector_write_timer_cb, s); ide_reset(s); } bus->irq = irq; }


BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, const BdrvChildRole *child_role, uint64_t perm, uint64_t shared_perm, void *opaque, Error **errp) { BdrvChild *child; int ret; ret = bdrv_check_update_perm(child_bs, perm, shared_perm, NULL, errp); if (ret < 0) { return NULL; } child = g_new(BdrvChild, 1); *child = (BdrvChild) { .bs = NULL, .name = g_strdup(child_name), .role = child_role, .perm = perm, .shared_perm = shared_perm, .opaque = opaque, }; bdrv_replace_child(child, child_bs); return child; }


static void do_eject(int argc, const char **argv) { BlockDriverState *bs; const char **parg; int force; parg = argv + 1; if (!*parg) { fail: help_cmd(argv[0]); return; } force = 0; if (!strcmp(*parg, "-f")) { force = 1; parg++; } if (!*parg) goto fail; bs = bdrv_find(*parg); if (!bs) { term_printf("device not found\n"); return; } eject_device(bs, force); }


long do_sigreturn(CPUSH4State *regs) { struct target_sigframe *frame; abi_ulong frame_addr; sigset_t blocked; target_sigset_t target_set; target_ulong r0; int i; int err = 0; #if defined(DEBUG_SIGNAL) fprintf(stderr, "do_sigreturn\n"); #endif frame_addr = regs->gregs[15]; if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; err |= __get_user(target_set.sig[0], &frame->sc.oldmask); for(i = 1; i < TARGET_NSIG_WORDS; i++) { err |= (__get_user(target_set.sig[i], &frame->extramask[i - 1])); } if (err) goto badframe; target_to_host_sigset_internal(&blocked, &target_set); sigprocmask(SIG_SETMASK, &blocked, NULL); if (restore_sigcontext(regs, &frame->sc, &r0)) goto badframe; unlock_user_struct(frame, frame_addr, 0); return r0; badframe: unlock_user_struct(frame, frame_addr, 0); force_sig(TARGET_SIGSEGV); return 0; }


static uint64_t pcnet_ioport_read(void *opaque, target_phys_addr_t addr, unsigned size) { PCNetState *d = opaque; if (addr < 16 && size == 1) { return pcnet_aprom_readb(d, addr); } else if (addr >= 0x10 && addr < 0x20 && size == 2) { return pcnet_ioport_readw(d, addr); } else if (addr >= 0x10 && addr < 0x20 && size == 4) { return pcnet_ioport_readl(d, addr); } return ((uint64_t)1 << (size * 8)) - 1; }


int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size, int *gen_code_size_ptr, uint8_t *pc_start, uint8_t *cs_base, int flags) { DisasContext dc1, *dc = &dc1; uint8_t *pc_ptr; uint16_t *gen_opc_end; int gen_code_size; long ret; #ifdef DEBUG_DISAS struct disassemble_info disasm_info; #endif /* generate intermediate code */ dc->code32 = (flags >> GEN_FLAG_CODE32_SHIFT) & 1; dc->ss32 = (flags >> GEN_FLAG_SS32_SHIFT) & 1; dc->addseg = (flags >> GEN_FLAG_ADDSEG_SHIFT) & 1; dc->f_st = (flags >> GEN_FLAG_ST_SHIFT) & 7; dc->cc_op = CC_OP_DYNAMIC; dc->cs_base = cs_base; gen_opc_ptr = gen_opc_buf; gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; gen_opparam_ptr = gen_opparam_buf; dc->is_jmp = 0; pc_ptr = pc_start; do { ret = disas_insn(dc, pc_ptr); if (ret == -1) { /* we trigger an illegal instruction operation only if it is the first instruction. Otherwise, we simply stop generating the code just before it */ if (pc_ptr == pc_start) return -1; else break; } pc_ptr = (void *)ret; } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end); /* we must store the eflags state if it is not already done */ if (dc->cc_op != CC_OP_DYNAMIC) gen_op_set_cc_op(dc->cc_op); if (dc->is_jmp != 1) { /* we add an additionnal jmp to update the simulated PC */ gen_op_jmp_im(ret - (unsigned long)dc->cs_base); } *gen_opc_ptr = INDEX_op_end; /* optimize flag computations */ #ifdef DEBUG_DISAS if (loglevel) { uint8_t *pc; int count; INIT_DISASSEMBLE_INFO(disasm_info, logfile, fprintf); #if 0 disasm_info.flavour = bfd_get_flavour (abfd); disasm_info.arch = bfd_get_arch (abfd); disasm_info.mach = bfd_get_mach (abfd); #endif disasm_info.endian = BFD_ENDIAN_LITTLE; if (dc->code32) disasm_info.mach = bfd_mach_i386_i386; else disasm_info.mach = bfd_mach_i386_i8086; fprintf(logfile, "----------------\n"); fprintf(logfile, "IN:\n"); disasm_info.buffer = pc_start; disasm_info.buffer_vma = (unsigned long)pc_start; disasm_info.buffer_length = pc_ptr - pc_start; pc = pc_start; while (pc < pc_ptr) { fprintf(logfile, "0x%08lx: ", (long)pc); count = print_insn_i386((unsigned long)pc, &disasm_info); fprintf(logfile, "\n"); pc += count; } fprintf(logfile, "\n"); fprintf(logfile, "OP:\n"); dump_ops(gen_opc_buf); fprintf(logfile, "\n"); } #endif /* optimize flag computations */ optimize_flags(gen_opc_buf, gen_opc_ptr - gen_opc_buf); #ifdef DEBUG_DISAS if (loglevel) { fprintf(logfile, "AFTER FLAGS OPT:\n"); dump_ops(gen_opc_buf); fprintf(logfile, "\n"); } #endif /* generate machine code */ gen_code_size = dyngen_code(gen_code_buf, gen_opc_buf, gen_opparam_buf); flush_icache_range((unsigned long)gen_code_buf, (unsigned long)(gen_code_buf + gen_code_size)); *gen_code_size_ptr = gen_code_size; #ifdef DEBUG_DISAS if (loglevel) { uint8_t *pc; int count; INIT_DISASSEMBLE_INFO(disasm_info, logfile, fprintf); #if 0 disasm_info.flavour = bfd_get_flavour (abfd); disasm_info.arch = bfd_get_arch (abfd); disasm_info.mach = bfd_get_mach (abfd); #endif #ifdef WORDS_BIGENDIAN disasm_info.endian = BFD_ENDIAN_BIG; #else disasm_info.endian = BFD_ENDIAN_LITTLE; #endif disasm_info.mach = bfd_mach_i386_i386; pc = gen_code_buf; disasm_info.buffer = pc; disasm_info.buffer_vma = (unsigned long)pc; disasm_info.buffer_length = *gen_code_size_ptr; fprintf(logfile, "OUT: [size=%d]\n", *gen_code_size_ptr); while (pc < gen_code_buf + *gen_code_size_ptr) { fprintf(logfile, "0x%08lx: ", (long)pc); count = print_insn_i386((unsigned long)pc, &disasm_info); fprintf(logfile, "\n"); pc += count; } fprintf(logfile, "\n"); fflush(logfile); } #endif return 0; }


static void parse_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { StringInputVisitor *siv = to_siv(v); if (!siv->string) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "integer"); return; } if (parse_str(siv, name, errp) < 0) { return; } if (!siv->ranges) { goto error; } if (!siv->cur_range) { Range *r; siv->cur_range = g_list_first(siv->ranges); if (!siv->cur_range) { goto error; } r = siv->cur_range->data; if (!r) { goto error; } siv->cur = r->begin; } *obj = siv->cur; siv->cur++; return; error: error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "an int64 value or range"); }


static void reanalyze(MpegTSContext *ts) { AVIOContext *pb = ts->stream->pb; int64_t pos = avio_tell(pb); if(pos < 0) return; pos += ts->raw_packet_size - ts->pos47_full; if (pos == TS_PACKET_SIZE) { ts->size_stat[0] ++; } else if (pos == TS_DVHS_PACKET_SIZE) { ts->size_stat[1] ++; } else if (pos == TS_FEC_PACKET_SIZE) { ts->size_stat[2] ++; } ts->size_stat_count ++; if(ts->size_stat_count > SIZE_STAT_THRESHOLD) { int newsize = 0; if (ts->size_stat[0] > SIZE_STAT_THRESHOLD) { newsize = TS_PACKET_SIZE; } else if (ts->size_stat[1] > SIZE_STAT_THRESHOLD) { newsize = TS_DVHS_PACKET_SIZE; } else if (ts->size_stat[2] > SIZE_STAT_THRESHOLD) { newsize = TS_FEC_PACKET_SIZE; } if (newsize) { av_log(ts->stream, AV_LOG_WARNING, "changing packet size to %d\n", newsize); ts->raw_packet_size = newsize; } ts->size_stat_count = 0; memset(ts->size_stat, 0, sizeof(ts->size_stat)); } }


static void spapr_create_nvram(sPAPREnvironment *spapr) { DeviceState *dev = qdev_create(&spapr->vio_bus->bus, "spapr-nvram"); DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0); if (dinfo) { qdev_prop_set_drive_nofail(dev, "drive", blk_bs(blk_by_legacy_dinfo(dinfo))); } qdev_init_nofail(dev); spapr->nvram = (struct sPAPRNVRAM *)dev; }


void qmp_block_dirty_bitmap_remove(const char *node, const char *name, Error **errp) { AioContext *aio_context; BlockDriverState *bs; BdrvDirtyBitmap *bitmap; bitmap = block_dirty_bitmap_lookup(node, name, &bs, &aio_context, errp); if (!bitmap || !bs) { return; } if (bdrv_dirty_bitmap_frozen(bitmap)) { error_setg(errp, "Bitmap '%s' is currently frozen and cannot be removed", name); goto out; } bdrv_dirty_bitmap_make_anon(bitmap); bdrv_release_dirty_bitmap(bs, bitmap); out: aio_context_release(aio_context); }


int tcg_gen_code(TCGContext *s, TranslationBlock *tb) { int i, oi, oi_next, num_insns; #ifdef CONFIG_PROFILER { int n; n = s->gen_last_op_idx + 1; s->op_count += n; if (n > s->op_count_max) { s->op_count_max = n; } n = s->nb_temps; s->temp_count += n; if (n > s->temp_count_max) { s->temp_count_max = n; } } #endif #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP) && qemu_log_in_addr_range(tb->pc))) { qemu_log("OP:\n"); tcg_dump_ops(s); qemu_log("\n"); } #endif #ifdef CONFIG_PROFILER s->opt_time -= profile_getclock(); #endif #ifdef USE_TCG_OPTIMIZATIONS tcg_optimize(s); #endif #ifdef CONFIG_PROFILER s->opt_time += profile_getclock(); s->la_time -= profile_getclock(); #endif tcg_liveness_analysis(s); #ifdef CONFIG_PROFILER s->la_time += profile_getclock(); #endif #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT) && qemu_log_in_addr_range(tb->pc))) { qemu_log("OP after optimization and liveness analysis:\n"); tcg_dump_ops(s); qemu_log("\n"); } #endif tcg_reg_alloc_start(s); s->code_buf = tb->tc_ptr; s->code_ptr = tb->tc_ptr; tcg_out_tb_init(s); num_insns = -1; for (oi = s->gen_first_op_idx; oi >= 0; oi = oi_next) { TCGOp * const op = &s->gen_op_buf[oi]; TCGArg * const args = &s->gen_opparam_buf[op->args]; TCGOpcode opc = op->opc; const TCGOpDef *def = &tcg_op_defs[opc]; uint16_t dead_args = s->op_dead_args[oi]; uint8_t sync_args = s->op_sync_args[oi]; oi_next = op->next; #ifdef CONFIG_PROFILER tcg_table_op_count[opc]++; #endif switch (opc) { case INDEX_op_mov_i32: case INDEX_op_mov_i64: tcg_reg_alloc_mov(s, def, args, dead_args, sync_args); break; case INDEX_op_movi_i32: case INDEX_op_movi_i64: tcg_reg_alloc_movi(s, args, dead_args, sync_args); break; case INDEX_op_insn_start: if (num_insns >= 0) { s->gen_insn_end_off[num_insns] = tcg_current_code_size(s); } num_insns++; for (i = 0; i < TARGET_INSN_START_WORDS; ++i) { target_ulong a; #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS a = ((target_ulong)args[i * 2 + 1] << 32) | args[i * 2]; #else a = args[i]; #endif s->gen_insn_data[num_insns][i] = a; } break; case INDEX_op_discard: temp_dead(s, &s->temps[args[0]]); break; case INDEX_op_set_label: tcg_reg_alloc_bb_end(s, s->reserved_regs); tcg_out_label(s, arg_label(args[0]), s->code_ptr); break; case INDEX_op_call: tcg_reg_alloc_call(s, op->callo, op->calli, args, dead_args, sync_args); break; default: /* Sanity check that we've not introduced any unhandled opcodes. */ if (def->flags & TCG_OPF_NOT_PRESENT) { tcg_abort(); } /* Note: in order to speed up the code, it would be much faster to have specialized register allocator functions for some common argument patterns */ tcg_reg_alloc_op(s, def, opc, args, dead_args, sync_args); break; } #ifndef NDEBUG check_regs(s); #endif /* Test for (pending) buffer overflow. The assumption is that any one operation beginning below the high water mark cannot overrun the buffer completely. Thus we can test for overflow after generating code without having to check during generation. */ if (unlikely((void *)s->code_ptr > s->code_gen_highwater)) { return -1; } } tcg_debug_assert(num_insns >= 0); s->gen_insn_end_off[num_insns] = tcg_current_code_size(s); /* Generate TB finalization at the end of block */ if (!tcg_out_tb_finalize(s)) { return -1; } /* flush instruction cache */ flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr); return tcg_current_code_size(s); }


static void curl_multi_read(void *arg) { CURLState *s = (CURLState *)arg; aio_context_acquire(s->s->aio_context); curl_multi_do_locked(s); curl_multi_check_completion(s->s); aio_context_release(s->s->aio_context); }


static int sh_pci_host_init(PCIDevice *d) { pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_HITACHI); pci_config_set_device_id(d->config, PCI_DEVICE_ID_HITACHI_SH7751R); pci_set_word(d->config + PCI_COMMAND, PCI_COMMAND_WAIT); pci_set_word(d->config + PCI_STATUS, PCI_STATUS_CAP_LIST | PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM); return 0; }


static int do_sigframe_return_v2(CPUARMState *env, target_ulong frame_addr, struct target_ucontext_v2 *uc) { sigset_t host_set; abi_ulong *regspace; target_to_host_sigset(&host_set, &uc->tuc_sigmask); sigprocmask(SIG_SETMASK, &host_set, NULL); if (restore_sigcontext(env, &uc->tuc_mcontext)) return 1; /* Restore coprocessor signal frame */ regspace = uc->tuc_regspace; if (arm_feature(env, ARM_FEATURE_VFP)) { regspace = restore_sigframe_v2_vfp(env, regspace); if (!regspace) { return 1; } } if (arm_feature(env, ARM_FEATURE_IWMMXT)) { regspace = restore_sigframe_v2_iwmmxt(env, regspace); if (!regspace) { return 1; } } if (do_sigaltstack(frame_addr + offsetof(struct target_ucontext_v2, tuc_stack), 0, get_sp_from_cpustate(env)) == -EFAULT) return 1; #if 0 /* Send SIGTRAP if we're single-stepping */ if (ptrace_cancel_bpt(current)) send_sig(SIGTRAP, current, 1); #endif return 0; }


static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { return -EIO; } return bdrv_check_byte_request(bs, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); }


static int kvm_arch_sync_sregs(CPUState *cenv) { struct kvm_sregs sregs; int ret; if (cenv->excp_model == POWERPC_EXCP_BOOKE) { return 0; } else { if (!cap_segstate) { return 0; } } ret = kvm_vcpu_ioctl(cenv, KVM_GET_SREGS, &sregs); if (ret) { return ret; } sregs.pvr = cenv->spr[SPR_PVR]; return kvm_vcpu_ioctl(cenv, KVM_SET_SREGS, &sregs); }


static int net_client_init1(const void *object, int is_netdev, Error **errp) { union { const Netdev *netdev; const NetLegacy *net; } u; const NetClientOptions *opts; const char *name; if (is_netdev) { u.netdev = object; opts = u.netdev->opts; name = u.netdev->id; if (opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP || opts->kind == NET_CLIENT_OPTIONS_KIND_NIC || !net_client_init_fun[opts->kind]) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", "a netdev backend type"); return -1; } } else { u.net = object; opts = u.net->opts; if (opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", "a net type"); return -1; } /* missing optional values have been initialized to "all bits zero" */ name = u.net->has_id ? u.net->id : u.net->name; if (opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) { return 0; /* nothing to do */ } if (!net_client_init_fun[opts->kind]) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", "a net backend type (maybe it is not compiled " "into this binary)"); return -1; } } if (net_client_init_fun[opts->kind]) { NetClientState *peer = NULL; /* Do not add to a vlan if it's a -netdev or a nic with a netdev= * parameter. */ if (!is_netdev && (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC || !opts->nic->has_netdev)) { peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL); } if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) { /* FIXME drop when all init functions store an Error */ if (errp && !*errp) { error_setg(errp, QERR_DEVICE_INIT_FAILED, NetClientOptionsKind_lookup[opts->kind]); } return -1; } } return 0; }


static inline void gen_evsel (DisasContext *ctx) { if (unlikely(!ctx->spe_enabled)) { RET_EXCP(ctx, EXCP_NO_SPE, 0); return; } gen_op_load_crf_T0(ctx->opcode & 0x7); gen_op_load_gpr64_T0(rA(ctx->opcode)); gen_op_load_gpr64_T1(rB(ctx->opcode)); gen_op_evsel(); gen_op_store_T0_gpr64(rD(ctx->opcode)); }


int pci_device_load(PCIDevice *s, QEMUFile *f) { uint32_t version_id; int i; version_id = qemu_get_be32(f); if (version_id > 2) return -EINVAL; qemu_get_buffer(f, s->config, 256); pci_update_mappings(s); if (version_id >= 2) for (i = 0; i < 4; i ++) s->irq_state[i] = qemu_get_be32(f); return 0; }


int ff_hevc_decode_nal_vps(HEVCContext *s) { int i,j; GetBitContext *gb = &s->HEVClc.gb; int vps_id = 0; HEVCVPS *vps; AVBufferRef *vps_buf = av_buffer_allocz(sizeof(*vps)); if (!vps_buf) return AVERROR(ENOMEM); vps = (HEVCVPS*)vps_buf->data; av_log(s->avctx, AV_LOG_DEBUG, "Decoding VPS\n"); vps_id = get_bits(gb, 4); if (vps_id >= MAX_VPS_COUNT) { av_log(s->avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id); goto err; } if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n"); goto err; } vps->vps_max_layers = get_bits(gb, 6) + 1; vps->vps_max_sub_layers = get_bits(gb, 3) + 1; vps->vps_temporal_id_nesting_flag = get_bits1(gb); if (get_bits(gb, 16) != 0xffff) { // vps_reserved_ffff_16bits av_log(s->avctx, AV_LOG_ERROR, "vps_reserved_ffff_16bits is not 0xffff\n"); goto err; } if (vps->vps_max_sub_layers > MAX_SUB_LAYERS) { av_log(s->avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n", vps->vps_max_sub_layers); goto err; } if (decode_profile_tier_level(&s->HEVClc, &vps->ptl, vps->vps_max_sub_layers) < 0) { av_log(s->avctx, AV_LOG_ERROR, "Error decoding profile tier level.\n"); goto err; } vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb); i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_sub_layers - 1; for (; i < vps->vps_max_sub_layers; i++) { vps->vps_max_dec_pic_buffering[i] = get_ue_golomb_long(gb) + 1; vps->vps_num_reorder_pics[i] = get_ue_golomb_long(gb); vps->vps_max_latency_increase[i] = get_ue_golomb_long(gb) - 1; if (vps->vps_max_dec_pic_buffering[i] > MAX_DPB_SIZE) { av_log(s->avctx, AV_LOG_ERROR, "vps_max_dec_pic_buffering_minus1 out of range: %d\n", vps->vps_max_dec_pic_buffering[i] - 1); goto err; } if (vps->vps_num_reorder_pics[i] > vps->vps_max_dec_pic_buffering[i] - 1) { av_log(s->avctx, AV_LOG_ERROR, "vps_max_num_reorder_pics out of range: %d\n", vps->vps_num_reorder_pics[i]); goto err; } } vps->vps_max_layer_id = get_bits(gb, 6); vps->vps_num_layer_sets = get_ue_golomb_long(gb) + 1; for (i = 1; i < vps->vps_num_layer_sets; i++) for (j = 0; j <= vps->vps_max_layer_id; j++) skip_bits(gb, 1); // layer_id_included_flag[i][j] vps->vps_timing_info_present_flag = get_bits1(gb); if (vps->vps_timing_info_present_flag) { vps->vps_num_units_in_tick = get_bits_long(gb, 32); vps->vps_time_scale = get_bits_long(gb, 32); vps->vps_poc_proportional_to_timing_flag = get_bits1(gb); if (vps->vps_poc_proportional_to_timing_flag) vps->vps_num_ticks_poc_diff_one = get_ue_golomb_long(gb) + 1; vps->vps_num_hrd_parameters = get_ue_golomb_long(gb); for (i = 0; i < vps->vps_num_hrd_parameters; i++) { int common_inf_present = 1; get_ue_golomb_long(gb); // hrd_layer_set_idx if (i) common_inf_present = get_bits1(gb); decode_hrd(s, common_inf_present, vps->vps_max_sub_layers); } } get_bits1(gb); /* vps_extension_flag */ av_buffer_unref(&s->vps_list[vps_id]); s->vps_list[vps_id] = vps_buf; return 0; err: av_buffer_unref(&vps_buf); return AVERROR_INVALIDDATA; }


static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; KmvcContext *const ctx = avctx->priv_data; uint8_t *out, *src; int i; int header; int blocksize; const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (ctx->pic.data[0]) avctx->release_buffer(avctx, &ctx->pic); ctx->pic.reference = 1; ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID; if (avctx->get_buffer(avctx, &ctx->pic) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } header = *buf++; /* blocksize 127 is really palette change event */ if (buf[0] == 127) { buf += 3; for (i = 0; i < 127; i++) { ctx->pal[i + (header & 0x81)] = AV_RB24(buf); buf += 4; } buf -= 127 * 4 + 3; } if (header & KMVC_KEYFRAME) { ctx->pic.key_frame = 1; ctx->pic.pict_type = AV_PICTURE_TYPE_I; } else { ctx->pic.key_frame = 0; ctx->pic.pict_type = AV_PICTURE_TYPE_P; } if (header & KMVC_PALETTE) { ctx->pic.palette_has_changed = 1; // palette starts from index 1 and has 127 entries for (i = 1; i <= ctx->palsize; i++) { ctx->pal[i] = bytestream_get_be24(&buf); } } if (pal) { ctx->pic.palette_has_changed = 1; memcpy(ctx->pal, pal, AVPALETTE_SIZE); } if (ctx->setpal) { ctx->setpal = 0; ctx->pic.palette_has_changed = 1; } /* make the palette available on the way out */ memcpy(ctx->pic.data[1], ctx->pal, 1024); blocksize = *buf++; if (blocksize != 8 && blocksize != 127) { av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize); return -1; } memset(ctx->cur, 0, 320 * 200); switch (header & KMVC_METHOD) { case 0: case 1: // used in palette changed event memcpy(ctx->cur, ctx->prev, 320 * 200); break; case 3: kmvc_decode_intra_8x8(ctx, buf, buf_size, avctx->width, avctx->height); break; case 4: kmvc_decode_inter_8x8(ctx, buf, buf_size, avctx->width, avctx->height); break; default: av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD); return -1; } out = ctx->pic.data[0]; src = ctx->cur; for (i = 0; i < avctx->height; i++) { memcpy(out, src, avctx->width); src += 320; out += ctx->pic.linesize[0]; } /* flip buffers */ if (ctx->cur == ctx->frm0) { ctx->cur = ctx->frm1; ctx->prev = ctx->frm0; } else { ctx->cur = ctx->frm0; ctx->prev = ctx->frm1; } *data_size = sizeof(AVFrame); *(AVFrame *) data = ctx->pic; /* always report that the buffer was completely consumed */ return buf_size; }


static int read_header(FFV1Context *f) { uint8_t state[CONTEXT_SIZE]; int i, j, context_count = -1; //-1 to avoid warning RangeCoder *const c = &f->slice_context[0]->c; memset(state, 128, sizeof(state)); if (f->version < 2) { int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample; unsigned v= get_symbol(c, state, 0); if (v >= 2) { av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v); return AVERROR_INVALIDDATA; } f->version = v; f->ac = f->avctx->coder_type = get_symbol(c, state, 0); if (f->ac > 1) { for (i = 1; i < 256; i++) f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i]; } colorspace = get_symbol(c, state, 0); //YUV cs type bits_per_raw_sample = f->version > 0 ? get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample; chroma_planes = get_rac(c, state); chroma_h_shift = get_symbol(c, state, 0); chroma_v_shift = get_symbol(c, state, 0); transparency = get_rac(c, state); if (f->plane_count) { if ( colorspace != f->colorspace || bits_per_raw_sample != f->avctx->bits_per_raw_sample || chroma_planes != f->chroma_planes || chroma_h_shift!= f->chroma_h_shift || chroma_v_shift!= f->chroma_v_shift || transparency != f->transparency) { av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n"); return AVERROR_INVALIDDATA; } } f->colorspace = colorspace; f->avctx->bits_per_raw_sample = bits_per_raw_sample; f->chroma_planes = chroma_planes; f->chroma_h_shift = chroma_h_shift; f->chroma_v_shift = chroma_v_shift; f->transparency = transparency; f->plane_count = 2 + f->transparency; } if (f->colorspace == 0) { if (!f->transparency && !f->chroma_planes) { if (f->avctx->bits_per_raw_sample <= 8) f->avctx->pix_fmt = AV_PIX_FMT_GRAY8; else f->avctx->pix_fmt = AV_PIX_FMT_GRAY16; } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) { switch(16 * f->chroma_h_shift + f->chroma_v_shift) { case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P; break; case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P; break; case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P; break; case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P; break; case 0x20: f->avctx->pix_fmt = AV_PIX_FMT_YUV411P; break; case 0x22: f->avctx->pix_fmt = AV_PIX_FMT_YUV410P; break; default: av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); return AVERROR(ENOSYS); } } else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) { switch(16*f->chroma_h_shift + f->chroma_v_shift) { case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P; break; case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P; break; case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P; break; default: av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); return AVERROR(ENOSYS); } } else if (f->avctx->bits_per_raw_sample == 9) { f->packed_at_lsb = 1; switch(16 * f->chroma_h_shift + f->chroma_v_shift) { case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P9; break; case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P9; break; case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P9; break; default: av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); return AVERROR(ENOSYS); } } else if (f->avctx->bits_per_raw_sample == 10) { f->packed_at_lsb = 1; switch(16 * f->chroma_h_shift + f->chroma_v_shift) { case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P10; break; case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; break; case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P10; break; default: av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); return AVERROR(ENOSYS); } } else { switch(16 * f->chroma_h_shift + f->chroma_v_shift) { case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P16; break; case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P16; break; case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P16; break; default: av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); return AVERROR(ENOSYS); } } } else if (f->colorspace == 1) { if (f->chroma_h_shift || f->chroma_v_shift) { av_log(f->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n"); return AVERROR(ENOSYS); } if ( f->avctx->bits_per_raw_sample == 9) f->avctx->pix_fmt = AV_PIX_FMT_GBRP9; else if (f->avctx->bits_per_raw_sample == 10) f->avctx->pix_fmt = AV_PIX_FMT_GBRP10; else if (f->avctx->bits_per_raw_sample == 12) f->avctx->pix_fmt = AV_PIX_FMT_GBRP12; else if (f->avctx->bits_per_raw_sample == 14) f->avctx->pix_fmt = AV_PIX_FMT_GBRP14; else if (f->transparency) f->avctx->pix_fmt = AV_PIX_FMT_RGB32; else f->avctx->pix_fmt = AV_PIX_FMT_0RGB32; } else { av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n"); return AVERROR(ENOSYS); } av_dlog(f->avctx, "%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift, f->avctx->pix_fmt); if (f->version < 2) { context_count = read_quant_tables(c, f->quant_table); if (context_count < 0) { av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); return AVERROR_INVALIDDATA; } } else if (f->version < 3) { f->slice_count = get_symbol(c, state, 0); } else { const uint8_t *p = c->bytestream_end; for (f->slice_count = 0; f->slice_count < MAX_SLICES && 3 < p - c->bytestream_start; f->slice_count++) { int trailer = 3 + 5*!!f->ec; int size = AV_RB24(p-trailer); if (size + trailer > p - c->bytestream_start) break; p -= size + trailer; } } if (f->slice_count > (unsigned)MAX_SLICES || f->slice_count <= 0) { av_log(f->avctx, AV_LOG_ERROR, "slice count %d is invalid\n", f->slice_count); return AVERROR_INVALIDDATA; } for (j = 0; j < f->slice_count; j++) { FFV1Context *fs = f->slice_context[j]; fs->ac = f->ac; fs->packed_at_lsb = f->packed_at_lsb; fs->slice_damaged = 0; if (f->version == 2) { fs->slice_x = get_symbol(c, state, 0) * f->width ; fs->slice_y = get_symbol(c, state, 0) * f->height; fs->slice_width = (get_symbol(c, state, 0) + 1) * f->width + fs->slice_x; fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y; fs->slice_x /= f->num_h_slices; fs->slice_y /= f->num_v_slices; fs->slice_width = fs->slice_width / f->num_h_slices - fs->slice_x; fs->slice_height = fs->slice_height / f->num_v_slices - fs->slice_y; if ((unsigned)fs->slice_width > f->width || (unsigned)fs->slice_height > f->height) return AVERROR_INVALIDDATA; if ( (unsigned)fs->slice_x + (uint64_t)fs->slice_width > f->width || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height) return AVERROR_INVALIDDATA; } for (i = 0; i < f->plane_count; i++) { PlaneContext *const p = &fs->plane[i]; if (f->version == 2) { int idx = get_symbol(c, state, 0); if (idx > (unsigned)f->quant_table_count) { av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n"); return AVERROR_INVALIDDATA; } p->quant_table_index = idx; memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table)); context_count = f->context_count[idx]; } else { memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table)); } if (f->version <= 2) { av_assert0(context_count >= 0); if (p->context_count < context_count) { av_freep(&p->state); av_freep(&p->vlc_state); } p->context_count = context_count; } } } return 0; }


static int config_props(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = outlink->src->inputs[0]; ScaleContext *scale = ctx->priv; int64_t w, h; double var_values[VARS_NB], res; char *expr; int ret; var_values[VAR_PI] = M_PI; var_values[VAR_PHI] = M_PHI; var_values[VAR_E] = M_E; var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; var_values[VAR_DAR] = var_values[VAR_A] = (float) inlink->w / inlink->h; var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? (float) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1; var_values[VAR_HSUB] = 1<<av_pix_fmt_descriptors[inlink->format].log2_chroma_w; var_values[VAR_VSUB] = 1<<av_pix_fmt_descriptors[inlink->format].log2_chroma_h; /* evaluate width and height */ av_expr_parse_and_eval(&res, (expr = scale->w_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx); scale->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = scale->h_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail; scale->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; /* evaluate again the width, as it may depend on the output height */ if ((ret = av_expr_parse_and_eval(&res, (expr = scale->w_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail; scale->w = res; w = scale->w; h = scale->h; /* sanity check params */ if (w < -1 || h < -1) { av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); return AVERROR(EINVAL); } if (w == -1 && h == -1) scale->w = scale->h = 0; if (!(w = scale->w)) w = inlink->w; if (!(h = scale->h)) h = inlink->h; if (w == -1) w = av_rescale(h, inlink->w, inlink->h); if (h == -1) h = av_rescale(w, inlink->h, inlink->w); if (w > INT_MAX || h > INT_MAX || (h * inlink->w) > INT_MAX || (w * inlink->h) > INT_MAX) av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n"); outlink->w = w; outlink->h = h; /* TODO: make algorithm configurable */ av_log(ctx, AV_LOG_INFO, "w:%d h:%d fmt:%s -> w:%d h:%d fmt:%s flags:0x%0x\n", inlink ->w, inlink ->h, av_pix_fmt_descriptors[ inlink->format].name, outlink->w, outlink->h, av_pix_fmt_descriptors[outlink->format].name, scale->flags); scale->input_is_pal = av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL; if (scale->sws) sws_freeContext(scale->sws); scale->sws = sws_getContext(inlink ->w, inlink ->h, inlink ->format, outlink->w, outlink->h, outlink->format, scale->flags, NULL, NULL, NULL); if (!scale->sws) return AVERROR(EINVAL); if (inlink->sample_aspect_ratio.num) outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w, outlink->w*inlink->h}, inlink->sample_aspect_ratio); else outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; return 0; fail: av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr); return ret; }


static int set_sps(HEVCContext *s, const HEVCSPS *sps) { #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + CONFIG_HEVC_D3D11VA_HWACCEL) enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; int ret; export_stream_params(s->avctx, &s->ps, sps); pic_arrays_free(s); ret = pic_arrays_init(s, sps); if (ret < 0) goto fail; if (sps->pix_fmt == AV_PIX_FMT_YUV420P || sps->pix_fmt == AV_PIX_FMT_YUVJ420P) { #if CONFIG_HEVC_DXVA2_HWACCEL *fmt++ = AV_PIX_FMT_DXVA2_VLD; #endif #if CONFIG_HEVC_D3D11VA_HWACCEL *fmt++ = AV_PIX_FMT_D3D11VA_VLD; #endif } *fmt++ = sps->pix_fmt; *fmt = AV_PIX_FMT_NONE; ret = ff_get_format(s->avctx, pix_fmts); if (ret < 0) goto fail; s->avctx->pix_fmt = ret; ff_hevc_pred_init(&s->hpc, sps->bit_depth); ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); ff_videodsp_init (&s->vdsp, sps->bit_depth); if (sps->sao_enabled && !s->avctx->hwaccel) { av_frame_unref(s->tmp_frame); ret = ff_get_buffer(s->avctx, s->tmp_frame, AV_GET_BUFFER_FLAG_REF); if (ret < 0) goto fail; s->frame = s->tmp_frame; } s->ps.sps = sps; s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data; return 0; fail: pic_arrays_free(s); s->ps.sps = NULL; return ret; }


static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { SVQ1Context * const s = avctx->priv_data; AVFrame *pict = data; AVFrame * const p= (AVFrame*)&s->picture; AVFrame temp; int i; if(avctx->pix_fmt != PIX_FMT_YUV410P){ av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); return -1; } if(!s->current_picture.data[0]){ avctx->get_buffer(avctx, &s->current_picture); avctx->get_buffer(avctx, &s->last_picture); } temp= s->current_picture; s->current_picture= s->last_picture; s->last_picture= temp; init_put_bits(&s->pb, buf, buf_size); *p = *pict; p->pict_type = avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE; p->key_frame = p->pict_type == I_TYPE; svq1_write_header(s, p->pict_type); for(i=0; i<3; i++){ svq1_encode_plane(s, i, s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i], s->frame_width / (i?4:1), s->frame_height / (i?4:1), s->picture.linesize[i], s->current_picture.linesize[i]); } // align_put_bits(&s->pb); while(put_bits_count(&s->pb) & 31) put_bits(&s->pb, 1, 0); flush_put_bits(&s->pb); return (put_bits_count(&s->pb) / 8); }


static void scsi_dma_restart_bh(void *opaque) { SCSIDiskState *s = opaque; SCSIRequest *req; SCSIDiskReq *r; qemu_bh_delete(s->bh); s->bh = NULL; QTAILQ_FOREACH(req, &s->qdev.requests, next) { r = DO_UPCAST(SCSIDiskReq, req, req); if (r->status & SCSI_REQ_STATUS_RETRY) { int status = r->status; int ret; r->status &= ~(SCSI_REQ_STATUS_RETRY | SCSI_REQ_STATUS_RETRY_TYPE_MASK); switch (status & SCSI_REQ_STATUS_RETRY_TYPE_MASK) { case SCSI_REQ_STATUS_RETRY_READ: scsi_read_data(&r->req); break; case SCSI_REQ_STATUS_RETRY_WRITE: scsi_write_data(&r->req); break; case SCSI_REQ_STATUS_RETRY_FLUSH: ret = scsi_disk_emulate_command(r, r->iov.iov_base); if (ret == 0) { scsi_command_complete(r, GOOD, NO_SENSE); } } } } }


static bool is_sector_request_lun_aligned(int64_t sector_num, int nb_sectors, IscsiLun *iscsilun) { assert(nb_sectors < BDRV_REQUEST_MAX_SECTORS); return is_byte_request_lun_aligned(sector_num << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, iscsilun); }


void ff_put_h264_qpel16_mc11_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_hv_qrt_16w_msa(src - 2, src - (stride * 2), stride, dst, stride, 16); }


static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; MpegTSSectionFilter *tssf = &filter->u.section_filter; SectionHeader h1, *h = &h1; PESContext *pes; AVStream *st; const uint8_t *p, *p_end, *desc_list_end; int program_info_length, pcr_pid, pid, stream_type; int desc_list_len; uint32_t prog_reg_desc = 0; /* registration descriptor */ int mp4_descr_count = 0; Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } }; int i; av_log(ts->stream, AV_LOG_TRACE, "PMT: len %i\n", section_len); hex_dump_debug(ts->stream, section, section_len); p_end = section + section_len - 4; p = section; if (parse_section_header(h, &p, p_end) < 0) return; if (h->version == tssf->last_ver) return; tssf->last_ver = h->version; av_log(ts->stream, AV_LOG_TRACE, "sid=0x%x sec_num=%d/%d version=%d\n", h->id, h->sec_num, h->last_sec_num, h->version); if (h->tid != PMT_TID) return; if (!ts->scan_all_pmts && ts->skip_changes) return; if (!ts->skip_clear) clear_program(ts, h->id); pcr_pid = get16(&p, p_end); if (pcr_pid < 0) return; pcr_pid &= 0x1fff; add_pid_to_pmt(ts, h->id, pcr_pid); set_pcr_pid(ts->stream, h->id, pcr_pid); av_log(ts->stream, AV_LOG_TRACE, "pcr_pid=0x%x\n", pcr_pid); program_info_length = get16(&p, p_end); if (program_info_length < 0) return; program_info_length &= 0xfff; while (program_info_length >= 2) { uint8_t tag, len; tag = get8(&p, p_end); len = get8(&p, p_end); av_log(ts->stream, AV_LOG_TRACE, "program tag: 0x%02x len=%d\n", tag, len); if (len > program_info_length - 2) // something else is broken, exit the program_descriptors_loop break; program_info_length -= len + 2; if (tag == 0x1d) { // IOD descriptor get8(&p, p_end); // scope get8(&p, p_end); // label len -= 2; mp4_read_iods(ts->stream, p, len, mp4_descr + mp4_descr_count, &mp4_descr_count, MAX_MP4_DESCR_COUNT); } else if (tag == 0x05 && len >= 4) { // registration descriptor prog_reg_desc = bytestream_get_le32(&p); len -= 4; } p += len; } p += program_info_length; if (p >= p_end) goto out; // stop parsing after pmt, we found header if (!ts->stream->nb_streams) ts->stop_parse = 2; set_pmt_found(ts, h->id); for (;;) { st = 0; pes = NULL; stream_type = get8(&p, p_end); if (stream_type < 0) break; pid = get16(&p, p_end); if (pid < 0) goto out; pid &= 0x1fff; if (pid == ts->current_pid) goto out; /* now create stream */ if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) { pes = ts->pids[pid]->u.pes_filter.opaque; if (!pes->st) { pes->st = avformat_new_stream(pes->stream, NULL); if (!pes->st) goto out; pes->st->id = pes->pid; } st = pes->st; } else if (stream_type != 0x13) { if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); // wrongly added sdt filter probably pes = add_pes_stream(ts, pid, pcr_pid); if (pes) { st = avformat_new_stream(pes->stream, NULL); if (!st) goto out; st->id = pes->pid; } } else { int idx = ff_find_stream_index(ts->stream, pid); if (idx >= 0) { st = ts->stream->streams[idx]; } else { st = avformat_new_stream(ts->stream, NULL); if (!st) goto out; st->id = pid; st->codec->codec_type = AVMEDIA_TYPE_DATA; } } if (!st) goto out; if (pes && !pes->stream_type) mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); add_pid_to_pmt(ts, h->id, pid); ff_program_add_stream_index(ts->stream, h->id, st->index); desc_list_len = get16(&p, p_end); if (desc_list_len < 0) goto out; desc_list_len &= 0xfff; desc_list_end = p + desc_list_len; if (desc_list_end > p_end) goto out; for (;;) { if (ff_parse_mpeg2_descriptor(ts->stream, st, stream_type, &p, desc_list_end, mp4_descr, mp4_descr_count, pid, ts) < 0) break; if (pes && prog_reg_desc == AV_RL32("HDMV") && stream_type == 0x83 && pes->sub_st) { ff_program_add_stream_index(ts->stream, h->id, pes->sub_st->index); pes->sub_st->codec->codec_tag = st->codec->codec_tag; } } p = desc_list_end; } if (!ts->pids[pcr_pid]) mpegts_open_pcr_filter(ts, pcr_pid); out: for (i = 0; i < mp4_descr_count; i++) av_free(mp4_descr[i].dec_config_descr); }


static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) { RMDemuxContext *rm = s->priv_data; AVStream *st; int i, len, res, seq = 1; int64_t timestamp, pos; int flags; for (;;) { if (rm->audio_pkt_cnt) { // If there are queued audio packet return them first st = s->streams[rm->audio_stream_num]; ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt); flags = 0; } else { if (rm->old_format) { RMStream *ast; st = s->streams[0]; ast = st->priv_data; timestamp = AV_NOPTS_VALUE; len = !ast->audio_framesize ? RAW_PACKET_SIZE : ast->coded_framesize * ast->sub_packet_h / 2; flags = (seq++ == 1) ? 2 : 0; pos = avio_tell(s->pb); } else { len=sync(s, &timestamp, &flags, &i, &pos); if (len > 0) st = s->streams[i]; } if(len<0 || s->pb->eof_reached) return AVERROR(EIO); res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt, &seq, flags, timestamp); if((flags&2) && (seq&0x7F) == 1) av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME); if (res) continue; } if( (st->discard >= AVDISCARD_NONKEY && !(flags&2)) || st->discard >= AVDISCARD_ALL){ av_free_packet(pkt); } else break; } return 0; }


static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb, int width, int *runs, const int *runend, const int *ref) { int mode = 0, offs = 0, run = 0, saved_run = 0, t; int run_off = *ref++; int *run_start = runs; runend--; // for the last written 0 while(offs < width){ int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1); if(cmode == -1){ av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n"); return -1; } //sync line pointers if(runs != run_start)while(run_off <= offs){ run_off += *ref++; run_off += *ref++; } if(!cmode){//pass mode run_off += *ref++; run = run_off - offs; run_off += *ref++; offs += run; if(offs > width){ av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); return -1; } saved_run += run; }else if(cmode == 1){//horizontal mode int k; for(k = 0; k < 2; k++){ run = 0; for(;;){ t = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2); if(t == -1){ av_log(avctx, AV_LOG_ERROR, "Incorrect code\n"); return -1; } run += t; if(t < 64) break; } *runs++ = run + saved_run; if(runs >= runend){ av_log(avctx, AV_LOG_ERROR, "Run overrun\n"); return -1; } saved_run = 0; offs += run; if(offs > width){ av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); return -1; } mode = !mode; } }else if(cmode == 9 || cmode == 10){ av_log(avctx, AV_LOG_ERROR, "Special modes are not supported (yet)\n"); return -1; }else{//vertical mode run = run_off - offs + (cmode - 5); if(cmode >= 5) run_off += *ref++; else run_off -= *--ref; offs += run; if(offs > width){ av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); return -1; } *runs++ = run + saved_run; if(runs >= runend){ av_log(avctx, AV_LOG_ERROR, "Run overrun\n"); return -1; } saved_run = 0; mode = !mode; } } *runs++ = saved_run; *runs++ = 0; return 0; }


static int analyze(const uint8_t *buf, int size, int packet_size, int *index, int probe) { int stat[TS_MAX_PACKET_SIZE]; int stat_all = 0; int i; int best_score = 0; memset(stat, 0, packet_size * sizeof(*stat)); for (i = 0; i < size - 3; i++) { if (buf[i] == 0x47 && (!probe || (!(buf[i + 1] & 0x80) && buf[i + 3] != 0x47))) { int x = i % packet_size; stat[x]++; stat_all++; if (stat[x] > best_score) { best_score = stat[x]; if (index) *index = x; } } } return best_score - FFMAX(stat_all - 10*best_score, 0)/10; }


static void ff_h264_idct_dc_add8_mmx2(uint8_t *dst, int16_t *block, int stride) { __asm__ volatile( "movd %0, %%mm0 \n\t" // 0 0 X D "punpcklwd %1, %%mm0 \n\t" // x X d D "paddsw %2, %%mm0 \n\t" "psraw $6, %%mm0 \n\t" "punpcklwd %%mm0, %%mm0 \n\t" // d d D D "pxor %%mm1, %%mm1 \n\t" // 0 0 0 0 "psubw %%mm0, %%mm1 \n\t" // -d-d-D-D "packuswb %%mm1, %%mm0 \n\t" // -d-d-D-D d d D D "pshufw $0xFA, %%mm0, %%mm1 \n\t" // -d-d-d-d-D-D-D-D "punpcklwd %%mm0, %%mm0 \n\t" // d d d d D D D D ::"m"(block[ 0]), "m"(block[16]), "m"(ff_pw_32) ); __asm__ volatile( "movq %0, %%mm2 \n\t" "movq %1, %%mm3 \n\t" "movq %2, %%mm4 \n\t" "movq %3, %%mm5 \n\t" "paddusb %%mm0, %%mm2 \n\t" "paddusb %%mm0, %%mm3 \n\t" "paddusb %%mm0, %%mm4 \n\t" "paddusb %%mm0, %%mm5 \n\t" "psubusb %%mm1, %%mm2 \n\t" "psubusb %%mm1, %%mm3 \n\t" "psubusb %%mm1, %%mm4 \n\t" "psubusb %%mm1, %%mm5 \n\t" "movq %%mm2, %0 \n\t" "movq %%mm3, %1 \n\t" "movq %%mm4, %2 \n\t" "movq %%mm5, %3 \n\t" :"+m"(*(uint64_t*)(dst+0*stride)), "+m"(*(uint64_t*)(dst+1*stride)), "+m"(*(uint64_t*)(dst+2*stride)), "+m"(*(uint64_t*)(dst+3*stride)) ); }


void uninit_opts(void) { int i; for (i = 0; i < AVMEDIA_TYPE_NB; i++) av_freep(&avcodec_opts[i]); av_freep(&avformat_opts->key); av_freep(&avformat_opts); #if CONFIG_SWSCALE av_freep(&sws_opts); #endif for (i = 0; i < opt_name_count; i++) { //opt_values are only stored for codec-specific options in which case //both the name and value are dup'd if (opt_values[i]) { av_freep(&opt_names[i]); av_freep(&opt_values[i]); } } av_freep(&opt_names); av_freep(&opt_values); }


static int ftp_send_command(FTPContext *s, const char *command, const int response_codes[], char **response) { int err; /* Flush control connection input to get rid of non relevant responses if any */ if ((err = ftp_flush_control_input(s)) < 0) return err; /* send command in blocking mode */ s->conn_control_block_flag = 0; if ((err = ffurl_write(s->conn_control, command, strlen(command))) < 0) return err; if (!err) return -1; /* return status */ if (response_codes) { return ftp_status(s, response, response_codes); } return 0; }


static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { LibvorbisContext *s = avctx->priv_data; ogg_packet op; int ret, duration; /* send samples to libvorbis */ if (frame) { const int samples = frame->nb_samples; float **buffer; int c, channels = s->vi.channels; buffer = vorbis_analysis_buffer(&s->vd, samples); for (c = 0; c < channels; c++) { int co = (channels > 8) ? c : ff_vorbis_encoding_channel_layout_offsets[channels - 1][c]; memcpy(buffer[c], frame->extended_data[co], samples * sizeof(*buffer[c])); } if ((ret = vorbis_analysis_wrote(&s->vd, samples)) < 0) { av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n"); return vorbis_error_to_averror(ret); } if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) return ret; } else { if (!s->eof) if ((ret = vorbis_analysis_wrote(&s->vd, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n"); return vorbis_error_to_averror(ret); } s->eof = 1; } /* retrieve available packets from libvorbis */ while ((ret = vorbis_analysis_blockout(&s->vd, &s->vb)) == 1) { if ((ret = vorbis_analysis(&s->vb, NULL)) < 0) break; if ((ret = vorbis_bitrate_addblock(&s->vb)) < 0) break; /* add any available packets to the output packet buffer */ while ((ret = vorbis_bitrate_flushpacket(&s->vd, &op)) == 1) { if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) { av_log(avctx, AV_LOG_ERROR, "packet buffer is too small"); return AVERROR_BUG; } av_fifo_generic_write(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL); } if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "error getting available packets\n"); break; } } if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "error getting available packets\n"); return vorbis_error_to_averror(ret); } /* check for available packets */ if (av_fifo_size(s->pkt_fifo) < sizeof(ogg_packet)) return 0; av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); if ((ret = ff_alloc_packet(avpkt, op.bytes))) { av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); return ret; } av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL); avpkt->pts = ff_samples_to_time_base(avctx, op.granulepos); duration = avpriv_vorbis_parse_frame(&s->vp, avpkt->data, avpkt->size); if (duration > 0) { /* we do not know encoder delay until we get the first packet from * libvorbis, so we have to update the AudioFrameQueue counts */ if (!avctx->delay) { avctx->delay = duration; s->afq.remaining_delay += duration; s->afq.remaining_samples += duration; } ff_af_queue_remove(&s->afq, duration, &avpkt->pts, &avpkt->duration); } *got_packet_ptr = 1; return 0; }


int bdrv_set_key(BlockDriverState *bs, const char *key) { int ret; if (bs->backing_hd && bs->backing_hd->encrypted) { ret = bdrv_set_key(bs->backing_hd, key); if (ret < 0) return ret; if (!bs->encrypted) return 0; } if (!bs->encrypted) { return -EINVAL; } else if (!bs->drv || !bs->drv->bdrv_set_key) { return -ENOMEDIUM; } ret = bs->drv->bdrv_set_key(bs, key); if (ret < 0) { bs->valid_key = 0; } else if (!bs->valid_key) { bs->valid_key = 1; if (bs->blk) { /* call the change callback now, we skipped it on open */ blk_dev_change_media_cb(bs->blk, true); } } return ret; }


int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) { BlockDriver *drv = bs->drv; if (!drv) return -ENOMEDIUM; if (drv->bdrv_snapshot_delete) return drv->bdrv_snapshot_delete(bs, snapshot_id); if (bs->file) return bdrv_snapshot_delete(bs->file, snapshot_id); return -ENOTSUP; }


static char *idebus_get_fw_dev_path(DeviceState *dev) { char path[30]; snprintf(path, sizeof(path), "%s@%d", qdev_fw_name(dev), ((IDEBus*)dev->parent_bus)->bus_id); return strdup(path); }


int bdrv_key_required(BlockDriverState *bs) { BlockDriverState *backing_hd = bs->backing_hd; if (backing_hd && backing_hd->encrypted && !backing_hd->valid_key) return 1; return (bs->encrypted && !bs->valid_key); }


static void init_proc_970 (CPUPPCState *env) { gen_spr_ne_601(env); gen_spr_7xx(env); /* Time base */ gen_tbl(env); /* Hardware implementation registers */ /* XXX : not implemented */ spr_register(env, SPR_HID0, "HID0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_clear, 0x60000000); /* XXX : not implemented */ spr_register(env, SPR_HID1, "HID1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_970_HID5, "HID5", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, POWERPC970_HID5_INIT); /* Memory management */ /* XXX: not correct */ gen_low_BATs(env); spr_register(env, SPR_HIOR, "SPR_HIOR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_hior, &spr_write_hior, 0x00000000); #if !defined(CONFIG_USER_ONLY) env->slb_nr = 32; #endif init_excp_970(env); env->dcache_line_size = 128; env->icache_line_size = 128; /* Allocate hardware IRQ controller */ ppc970_irq_init(env); /* Can't find information on what this should be on reset. This * value is the one used by 74xx processors. */ vscr_init(env, 0x00010000); }


void qmp_drive_mirror(DriveMirror *arg, Error **errp) { BlockDriverState *bs; BlockBackend *blk; BlockDriverState *source, *target_bs; AioContext *aio_context; BlockMirrorBackingMode backing_mode; Error *local_err = NULL; QDict *options = NULL; int flags; int64_t size; const char *format = arg->format; blk = blk_by_name(arg->device); if (!blk) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", arg->device); return; } aio_context = blk_get_aio_context(blk); aio_context_acquire(aio_context); if (!blk_is_available(blk)) { error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, arg->device); goto out; } bs = blk_bs(blk); if (!arg->has_mode) { arg->mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; } if (!arg->has_format) { format = (arg->mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name); } flags = bs->open_flags | BDRV_O_RDWR; source = backing_bs(bs); if (!source && arg->sync == MIRROR_SYNC_MODE_TOP) { arg->sync = MIRROR_SYNC_MODE_FULL; } if (arg->sync == MIRROR_SYNC_MODE_NONE) { source = bs; } size = bdrv_getlength(bs); if (size < 0) { error_setg_errno(errp, -size, "bdrv_getlength failed"); goto out; } if (arg->has_replaces) { BlockDriverState *to_replace_bs; AioContext *replace_aio_context; int64_t replace_size; if (!arg->has_node_name) { error_setg(errp, "a node-name must be provided when replacing a" " named node of the graph"); goto out; } to_replace_bs = check_to_replace_node(bs, arg->replaces, &local_err); if (!to_replace_bs) { error_propagate(errp, local_err); goto out; } replace_aio_context = bdrv_get_aio_context(to_replace_bs); aio_context_acquire(replace_aio_context); replace_size = bdrv_getlength(to_replace_bs); aio_context_release(replace_aio_context); if (size != replace_size) { error_setg(errp, "cannot replace image with a mirror image of " "different size"); goto out; } } if (arg->mode == NEW_IMAGE_MODE_ABSOLUTE_PATHS) { backing_mode = MIRROR_SOURCE_BACKING_CHAIN; } else { backing_mode = MIRROR_OPEN_BACKING_CHAIN; } if ((arg->sync == MIRROR_SYNC_MODE_FULL || !source) && arg->mode != NEW_IMAGE_MODE_EXISTING) { /* create new image w/o backing file */ assert(format); bdrv_img_create(arg->target, format, NULL, NULL, NULL, size, flags, &local_err, false); } else { switch (arg->mode) { case NEW_IMAGE_MODE_EXISTING: break; case NEW_IMAGE_MODE_ABSOLUTE_PATHS: /* create new image with backing file */ bdrv_img_create(arg->target, format, source->filename, source->drv->format_name, NULL, size, flags, &local_err, false); break; default: abort(); } } if (local_err) { error_propagate(errp, local_err); goto out; } options = qdict_new(); if (arg->has_node_name) { qdict_put(options, "node-name", qstring_from_str(arg->node_name)); } if (format) { qdict_put(options, "driver", qstring_from_str(format)); } /* Mirroring takes care of copy-on-write using the source's backing * file. */ target_bs = bdrv_open(arg->target, NULL, options, flags | BDRV_O_NO_BACKING, errp); if (!target_bs) { goto out; } bdrv_set_aio_context(target_bs, aio_context); blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs, arg->has_replaces, arg->replaces, arg->sync, backing_mode, arg->has_speed, arg->speed, arg->has_granularity, arg->granularity, arg->has_buf_size, arg->buf_size, arg->has_on_source_error, arg->on_source_error, arg->has_on_target_error, arg->on_target_error, arg->has_unmap, arg->unmap, &local_err); bdrv_unref(target_bs); error_propagate(errp, local_err); out: aio_context_release(aio_context); }


static int get_aac_sample_rates(AVFormatContext *s, AVCodecParameters *par, int *sample_rate, int *output_sample_rate) { MPEG4AudioConfig mp4ac; if (avpriv_mpeg4audio_get_config(&mp4ac, par->extradata, par->extradata_size * 8, 1) < 0) { av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to determine samplerate.\n"); return AVERROR(EINVAL); } *sample_rate = mp4ac.sample_rate; *output_sample_rate = mp4ac.ext_sample_rate; return 0; }


static void pxa2xx_lcdc_dma0_redraw_rot270(PXA2xxLCDState *s, hwaddr addr, int *miny, int *maxy) { DisplaySurface *surface = qemu_console_surface(s->con); int src_width, dest_width; drawfn fn = NULL; if (s->dest_width) { fn = s->line_fn[s->transp][s->bpp]; } if (!fn) { return; } src_width = (s->xres + 3) & ~3; /* Pad to a 4 pixels multiple */ if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp) { src_width *= 3; } else if (s->bpp > pxa_lcdc_16bpp) { src_width *= 4; } else if (s->bpp > pxa_lcdc_8bpp) { src_width *= 2; } dest_width = s->yres * s->dest_width; *miny = 0; framebuffer_update_display(surface, s->sysmem, addr, s->xres, s->yres, src_width, -s->dest_width, dest_width, s->invalidated, fn, s->dma_ch[0].palette, miny, maxy); }


static void tci_out_label(TCGContext *s, TCGLabel *label) { if (label->has_value) { tcg_out_i(s, label->u.value); assert(label->u.value); } else { tcg_out_reloc(s, s->code_ptr, sizeof(tcg_target_ulong), label, 0); s->code_ptr += sizeof(tcg_target_ulong); } }


void tlb_flush(CPUState *env, int flush_global) { int i; #if defined(DEBUG_TLB) printf("tlb_flush:\n"); #endif /* must reset current TB so that interrupts cannot modify the links while we are modifying them */ env->current_tb = NULL; for(i = 0; i < CPU_TLB_SIZE; i++) { env->tlb_table[0][i].addr_read = -1; env->tlb_table[0][i].addr_write = -1; env->tlb_table[0][i].addr_code = -1; env->tlb_table[1][i].addr_read = -1; env->tlb_table[1][i].addr_write = -1; env->tlb_table[1][i].addr_code = -1; #if (NB_MMU_MODES >= 3) env->tlb_table[2][i].addr_read = -1; env->tlb_table[2][i].addr_write = -1; env->tlb_table[2][i].addr_code = -1; #if (NB_MMU_MODES == 4) env->tlb_table[3][i].addr_read = -1; env->tlb_table[3][i].addr_write = -1; env->tlb_table[3][i].addr_code = -1; #endif #endif } memset (env->tb_jmp_cache, 0, TB_JMP_CACHE_SIZE * sizeof (void *)); #ifdef USE_KQEMU if (env->kqemu_enabled) { kqemu_flush(env, flush_global); } #endif tlb_flush_count++; }


static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping, int phdr_index, hwaddr offset) { Elf64_Phdr phdr; int ret; int endian = s->dump_info.d_endian; memset(&phdr, 0, sizeof(Elf64_Phdr)); phdr.p_type = cpu_convert_to_target32(PT_LOAD, endian); phdr.p_offset = cpu_convert_to_target64(offset, endian); phdr.p_paddr = cpu_convert_to_target64(memory_mapping->phys_addr, endian); if (offset == -1) { /* When the memory is not stored into vmcore, offset will be -1 */ phdr.p_filesz = 0; } else { phdr.p_filesz = cpu_convert_to_target64(memory_mapping->length, endian); } phdr.p_memsz = cpu_convert_to_target64(memory_mapping->length, endian); phdr.p_vaddr = cpu_convert_to_target64(memory_mapping->virt_addr, endian); ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s); if (ret < 0) { dump_error(s, "dump: failed to write program header table.\n"); return -1; } return 0; }


static int patch_hypercalls(VAPICROMState *s) { hwaddr rom_paddr = s->rom_state_paddr & ROM_BLOCK_MASK; static const uint8_t vmcall_pattern[] = { /* vmcall */ 0xb8, 0x1, 0, 0, 0, 0xf, 0x1, 0xc1 }; static const uint8_t outl_pattern[] = { /* nop; outl %eax,0x7e */ 0xb8, 0x1, 0, 0, 0, 0x90, 0xe7, 0x7e }; uint8_t alternates[2]; const uint8_t *pattern; const uint8_t *patch; int patches = 0; off_t pos; uint8_t *rom; rom = g_malloc(s->rom_size); cpu_physical_memory_read(rom_paddr, rom, s->rom_size); for (pos = 0; pos < s->rom_size - sizeof(vmcall_pattern); pos++) { if (kvm_irqchip_in_kernel()) { pattern = outl_pattern; alternates[0] = outl_pattern[7]; alternates[1] = outl_pattern[7]; patch = &vmcall_pattern[5]; } else { pattern = vmcall_pattern; alternates[0] = vmcall_pattern[7]; alternates[1] = 0xd9; /* AMD's VMMCALL */ patch = &outl_pattern[5]; } if (memcmp(rom + pos, pattern, 7) == 0 && (rom[pos + 7] == alternates[0] || rom[pos + 7] == alternates[1])) { cpu_physical_memory_write(rom_paddr + pos + 5, patch, 3); /* * Don't flush the tb here. Under ordinary conditions, the patched * calls are miles away from the current IP. Under malicious * conditions, the guest could trick us to crash. */ } } g_free(rom); if (patches != 0 && patches != 2) { return -1; } return 0; }


static void vnc_zlib_start(VncState *vs) { buffer_reset(&vs->zlib); // make the output buffer be the zlib buffer, so we can compress it later vs->zlib_tmp = vs->output; vs->output = vs->zlib; }


target_ulong helper_rdhwr_cpunum(CPUMIPSState *env) { if ((env->hflags & MIPS_HFLAG_CP0) || (env->CP0_HWREna & (1 << 0))) return env->CP0_EBase & 0x3ff; else do_raise_exception(env, EXCP_RI, GETPC()); return 0; }


static int write_l1_entry(BlockDriverState *bs, int l1_index) { BDRVQcowState *s = bs->opaque; uint64_t buf[L1_ENTRIES_PER_SECTOR]; int l1_start_index; int i, ret; l1_start_index = l1_index & ~(L1_ENTRIES_PER_SECTOR - 1); for (i = 0; i < L1_ENTRIES_PER_SECTOR; i++) { buf[i] = cpu_to_be64(s->l1_table[l1_start_index + i]); } ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT & ~QCOW2_OL_ACTIVE_L1, s->l1_table_offset + 8 * l1_start_index, sizeof(buf)); if (ret < 0) { return ret; } BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset + 8 * l1_start_index, buf, sizeof(buf)); if (ret < 0) { return ret; } return 0; }


static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AMRWBContext *s = avctx->priv_data; int mode; int packet_size; static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1}; mode = (buf[0] >> 3) & 0x000F; packet_size = block_size[mode]; if (packet_size > buf_size) { av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size + 1); return AVERROR_INVALIDDATA; } D_IF_decode(s->state, buf, data, _good_frame); *data_size = 320 * 2; return packet_size; }


static void gui_update(void *opaque) { uint64_t interval = GUI_REFRESH_INTERVAL; DisplayState *ds = opaque; DisplayChangeListener *dcl = ds->listeners; qemu_flush_coalesced_mmio_buffer(); dpy_refresh(ds); while (dcl != NULL) { if (dcl->gui_timer_interval && dcl->gui_timer_interval < interval) interval = dcl->gui_timer_interval; dcl = dcl->next; } qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock)); }


static void spapr_phb_vfio_instance_init(Object *obj) { error_report("spapr-pci-vfio-host-bridge is deprecated"); }


static void connex_init(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { struct pxa2xx_state_s *cpu; int index; uint32_t connex_rom = 0x01000000; uint32_t connex_ram = 0x04000000; if (ram_size < (connex_ram + connex_rom + PXA2XX_INTERNAL_SIZE)) { fprintf(stderr, "This platform requires %i bytes of memory\n", connex_ram + connex_rom + PXA2XX_INTERNAL_SIZE); exit(1); } cpu = pxa255_init(connex_ram); index = drive_get_index(IF_PFLASH, 0, 0); if (index == -1) { fprintf(stderr, "A flash image must be given with the " "'pflash' parameter\n"); exit(1); } if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(connex_rom), drives_table[index].bdrv, sector_len, connex_rom / sector_len, 2, 0, 0, 0, 0)) { fprintf(stderr, "qemu: Error registering flash memory.\n"); exit(1); } cpu->env->regs[15] = 0x00000000; /* Interrupt line of NIC is connected to GPIO line 36 */ smc91c111_init(&nd_table[0], 0x04000300, pxa2xx_gpio_in_get(cpu->gpio)[36]); }


static void handle_notify(EventNotifier *e) { VirtIOBlockDataPlane *s = container_of(e, VirtIOBlockDataPlane, host_notifier); VirtIOBlock *vblk = VIRTIO_BLK(s->vdev); event_notifier_test_and_clear(&s->host_notifier); blk_io_plug(s->conf->conf.blk); for (;;) { MultiReqBuffer mrb = {}; int ret; /* Disable guest->host notifies to avoid unnecessary vmexits */ vring_disable_notification(s->vdev, &s->vring); for (;;) { VirtIOBlockReq *req = virtio_blk_alloc_request(vblk); ret = vring_pop(s->vdev, &s->vring, &req->elem); if (ret < 0) { virtio_blk_free_request(req); break; /* no more requests */ } trace_virtio_blk_data_plane_process_request(s, req->elem.out_num, req->elem.in_num, req->elem.index); virtio_blk_handle_request(req, &mrb); } if (mrb.num_reqs) { virtio_blk_submit_multireq(s->conf->conf.blk, &mrb); } if (likely(ret == -EAGAIN)) { /* vring emptied */ /* Re-enable guest->host notifies and stop processing the vring. * But if the guest has snuck in more descriptors, keep processing. */ if (vring_enable_notification(s->vdev, &s->vring)) { break; } } else { /* fatal error */ break; } } blk_io_unplug(s->conf->conf.blk); }


static void mcf5208evb_init(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { CPUState *env; int kernel_size; uint64_t elf_entry; target_ulong entry; qemu_irq *pic; if (!cpu_model) cpu_model = "m5208"; env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find m68k CPU definition\n"); exit(1); } /* Initialize CPU registers. */ env->vbr = 0; /* TODO: Configure BARs. */ /* DRAM at 0x20000000 */ cpu_register_physical_memory(0x40000000, ram_size, qemu_ram_alloc(ram_size) | IO_MEM_RAM); /* Internal SRAM. */ cpu_register_physical_memory(0x80000000, 16384, qemu_ram_alloc(16384) | IO_MEM_RAM); /* Internal peripherals. */ pic = mcf_intc_init(0xfc048000, env); mcf_uart_mm_init(0xfc060000, pic[26], serial_hds[0]); mcf_uart_mm_init(0xfc064000, pic[27], serial_hds[1]); mcf_uart_mm_init(0xfc068000, pic[28], serial_hds[2]); mcf5208_sys_init(pic); if (nb_nics > 1) { fprintf(stderr, "Too many NICs\n"); exit(1); } if (nd_table[0].vlan) { if (nd_table[0].model == NULL || strcmp(nd_table[0].model, "mcf_fec") == 0) { mcf_fec_init(&nd_table[0], 0xfc030000, pic + 36); } else if (strcmp(nd_table[0].model, "?") == 0) { fprintf(stderr, "qemu: Supported NICs: mcf_fec\n"); exit (1); } else { fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model); exit (1); } } /* 0xfc000000 SCM. */ /* 0xfc004000 XBS. */ /* 0xfc008000 FlexBus CS. */ /* 0xfc030000 FEC. */ /* 0xfc040000 SCM + Power management. */ /* 0xfc044000 eDMA. */ /* 0xfc048000 INTC. */ /* 0xfc058000 I2C. */ /* 0xfc05c000 QSPI. */ /* 0xfc060000 UART0. */ /* 0xfc064000 UART0. */ /* 0xfc068000 UART0. */ /* 0xfc070000 DMA timers. */ /* 0xfc080000 PIT0. */ /* 0xfc084000 PIT1. */ /* 0xfc088000 EPORT. */ /* 0xfc08c000 Watchdog. */ /* 0xfc090000 clock module. */ /* 0xfc0a0000 CCM + reset. */ /* 0xfc0a4000 GPIO. */ /* 0xfc0a8000 SDRAM controller. */ /* Load kernel. */ if (!kernel_filename) { fprintf(stderr, "Kernel image must be specified\n"); exit(1); } kernel_size = load_elf(kernel_filename, 0, &elf_entry, NULL, NULL); entry = elf_entry; if (kernel_size < 0) { kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL); } if (kernel_size < 0) { kernel_size = load_image(kernel_filename, phys_ram_base); entry = 0x20000000; } if (kernel_size < 0) { fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } env->pc = entry; }


static int qcow_read_extensions(BlockDriverState *bs, uint64_t start_offset, uint64_t end_offset) { BDRVQcowState *s = bs->opaque; QCowExtension ext; uint64_t offset; #ifdef DEBUG_EXT printf("qcow_read_extensions: start=%ld end=%ld\n", start_offset, end_offset); #endif offset = start_offset; while (offset < end_offset) { #ifdef DEBUG_EXT /* Sanity check */ if (offset > s->cluster_size) printf("qcow_handle_extension: suspicious offset %lu\n", offset); printf("attemting to read extended header in offset %lu\n", offset); #endif if (bdrv_pread(s->hd, offset, &ext, sizeof(ext)) != sizeof(ext)) { fprintf(stderr, "qcow_handle_extension: ERROR: pread fail from offset %llu\n", (unsigned long long)offset); return 1; } be32_to_cpus(&ext.magic); be32_to_cpus(&ext.len); offset += sizeof(ext); #ifdef DEBUG_EXT printf("ext.magic = 0x%x\n", ext.magic); #endif switch (ext.magic) { case QCOW_EXT_MAGIC_END: return 0; case QCOW_EXT_MAGIC_BACKING_FORMAT: if (ext.len >= sizeof(bs->backing_format)) { fprintf(stderr, "ERROR: ext_backing_format: len=%u too large" " (>=%zu)\n", ext.len, sizeof(bs->backing_format)); return 2; } if (bdrv_pread(s->hd, offset , bs->backing_format, ext.len) != ext.len) return 3; bs->backing_format[ext.len] = '\0'; #ifdef DEBUG_EXT printf("Qcow2: Got format extension %s\n", bs->backing_format); #endif offset += ((ext.len + 7) & ~7); break; default: /* unknown magic -- just skip it */ offset += ((ext.len + 7) & ~7); break; } } return 0; }


int armv7m_nvic_acknowledge_irq(void *opaque) { nvic_state *s = (nvic_state *)opaque; uint32_t irq; irq = gic_acknowledge_irq(&s->gic, 0); if (irq == 1023) hw_error("Interrupt but no vector\n"); if (irq >= 32) irq -= 16; return irq; }


static FlatView *address_space_get_flatview(AddressSpace *as) { FlatView *view; qemu_mutex_lock(&flat_view_mutex); view = as->current_map; flatview_ref(view); qemu_mutex_unlock(&flat_view_mutex); return view; }


static int kvm_put_vcpu_events(X86CPU *cpu, int level) { CPUX86State *env = &cpu->env; struct kvm_vcpu_events events; if (!kvm_has_vcpu_events()) { return 0; } events.exception.injected = (env->exception_injected >= 0); events.exception.nr = env->exception_injected; events.exception.has_error_code = env->has_error_code; events.exception.error_code = env->error_code; events.exception.pad = 0; events.interrupt.injected = (env->interrupt_injected >= 0); events.interrupt.nr = env->interrupt_injected; events.interrupt.soft = env->soft_interrupt; events.nmi.injected = env->nmi_injected; events.nmi.pending = env->nmi_pending; events.nmi.masked = !!(env->hflags2 & HF2_NMI_MASK); events.nmi.pad = 0; events.sipi_vector = env->sipi_vector; events.flags = 0; if (level >= KVM_PUT_RESET_STATE) { events.flags |= KVM_VCPUEVENT_VALID_NMI_PENDING | KVM_VCPUEVENT_VALID_SIPI_VECTOR; } return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, &events); }


static int qdm2_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { QDM2Context *s = avctx->priv_data; if((buf == NULL) || (buf_size < s->checksum_size)) return 0; *data_size = s->channels * s->frame_size * sizeof(int16_t); av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\n", buf_size, buf, s->checksum_size, data, *data_size); qdm2_decode(s, buf, data); // reading only when next superblock found if (s->sub_packet == 0) { return s->checksum_size; } return 0; }


static void bdrv_sync_complete(void *opaque, int ret) { /* do nothing. Masters do not directly interact with the backing store, * only the working copy so no mutexing required. */ }


set_phy_ctrl(E1000State *s, int index, uint16_t val) { /* * QEMU 1.3 does not support link auto-negotiation emulation, so if we * migrate during auto negotiation, after migration the link will be * down. */ if (!(s->compat_flags & E1000_FLAG_AUTONEG)) { return; } if ((val & MII_CR_AUTO_NEG_EN) && (val & MII_CR_RESTART_AUTO_NEG)) { e1000_link_down(s); DBGOUT(PHY, "Start link auto negotiation\n"); timer_mod(s->autoneg_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500); } }


static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) { IOMMUTLBEntry entry; hwaddr size; hwaddr start = n->start; hwaddr end = n->end; /* * Note: all the codes in this function has a assumption that IOVA * bits are no more than VTD_MGAW bits (which is restricted by * VT-d spec), otherwise we need to consider overflow of 64 bits. */ if (end > VTD_ADDRESS_SIZE(VTD_HOST_ADDRESS_WIDTH)) { /* * Don't need to unmap regions that is bigger than the whole * VT-d supported address space size */ end = VTD_ADDRESS_SIZE(VTD_HOST_ADDRESS_WIDTH); } assert(start <= end); size = end - start; if (ctpop64(size) != 1) { /* * This size cannot format a correct mask. Let's enlarge it to * suite the minimum available mask. */ int n = 64 - clz64(size); if (n > VTD_MGAW) { /* should not happen, but in case it happens, limit it */ n = VTD_MGAW; } size = 1ULL << n; } entry.target_as = &address_space_memory; /* Adjust iova for the size */ entry.iova = n->start & ~(size - 1); /* This field is meaningless for unmap */ entry.translated_addr = 0; entry.perm = IOMMU_NONE; entry.addr_mask = size - 1; trace_vtd_as_unmap_whole(pci_bus_num(as->bus), VTD_PCI_SLOT(as->devfn), VTD_PCI_FUNC(as->devfn), entry.iova, size); memory_region_notify_one(n, &entry); }


static int megasas_ld_get_info_submit(SCSIDevice *sdev, int lun, MegasasCmd *cmd) { struct mfi_ld_info *info = cmd->iov_buf; size_t dcmd_size = sizeof(struct mfi_ld_info); uint8_t cdb[6]; SCSIRequest *req; ssize_t len, resid; BlockConf *conf = &sdev->conf; uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (lun & 0xFF); uint64_t ld_size; if (!cmd->iov_buf) { cmd->iov_buf = g_malloc(dcmd_size); memset(cmd->iov_buf, 0x0, dcmd_size); info = cmd->iov_buf; megasas_setup_inquiry(cdb, 0x83, sizeof(info->vpd_page83)); req = scsi_req_new(sdev, cmd->index, lun, cdb, cmd); if (!req) { trace_megasas_dcmd_req_alloc_failed(cmd->index, "LD get info vpd inquiry"); g_free(cmd->iov_buf); cmd->iov_buf = NULL; return MFI_STAT_FLASH_ALLOC_FAIL; } trace_megasas_dcmd_internal_submit(cmd->index, "LD get info vpd inquiry", lun); len = scsi_req_enqueue(req); if (len > 0) { cmd->iov_size = len; scsi_req_continue(req); } return MFI_STAT_INVALID_STATUS; } info->ld_config.params.state = MFI_LD_STATE_OPTIMAL; info->ld_config.properties.ld.v.target_id = lun; info->ld_config.params.stripe_size = 3; info->ld_config.params.num_drives = 1; info->ld_config.params.is_consistent = 1; /* Logical device size is in blocks */ bdrv_get_geometry(conf->bs, &ld_size); info->size = cpu_to_le64(ld_size); memset(info->ld_config.span, 0, sizeof(info->ld_config.span)); info->ld_config.span[0].start_block = 0; info->ld_config.span[0].num_blocks = info->size; info->ld_config.span[0].array_ref = cpu_to_le16(sdev_id); resid = dma_buf_read(cmd->iov_buf, dcmd_size, &cmd->qsg); g_free(cmd->iov_buf); cmd->iov_size = dcmd_size - resid; cmd->iov_buf = NULL; return MFI_STAT_OK; }


static void do_interrupt_protected(int intno, int is_int, int error_code, unsigned int next_eip) { SegmentCache *dt; uint8_t *ptr, *ssp; int type, dpl, selector, ss_dpl; int has_error_code, new_stack, shift; uint32_t e1, e2, offset, ss, esp, ss_e1, ss_e2, push_size; uint32_t old_cs, old_ss, old_esp, old_eip; dt = &env->idt; if (intno * 8 + 7 > dt->limit) raise_exception_err(EXCP0D_GPF, intno * 8 + 2); ptr = dt->base + intno * 8; e1 = ldl(ptr); e2 = ldl(ptr + 4); /* check gate type */ type = (e2 >> DESC_TYPE_SHIFT) & 0x1f; switch(type) { case 5: /* task gate */ cpu_abort(env, "task gate not supported"); break; case 6: /* 286 interrupt gate */ case 7: /* 286 trap gate */ case 14: /* 386 interrupt gate */ case 15: /* 386 trap gate */ break; default: raise_exception_err(EXCP0D_GPF, intno * 8 + 2); break; } dpl = (e2 >> DESC_DPL_SHIFT) & 3; /* check privledge if software int */ if (is_int && dpl < env->cpl) raise_exception_err(EXCP0D_GPF, intno * 8 + 2); /* check valid bit */ if (!(e2 & DESC_P_MASK)) raise_exception_err(EXCP0B_NOSEG, intno * 8 + 2); selector = e1 >> 16; offset = (e2 & 0xffff0000) | (e1 & 0x0000ffff); if ((selector & 0xfffc) == 0) raise_exception_err(EXCP0D_GPF, 0); if (load_segment(&e1, &e2, selector) != 0) raise_exception_err(EXCP0D_GPF, selector & 0xfffc); if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK))) raise_exception_err(EXCP0D_GPF, selector & 0xfffc); dpl = (e2 >> DESC_DPL_SHIFT) & 3; if (dpl > env->cpl) raise_exception_err(EXCP0D_GPF, selector & 0xfffc); if (!(e2 & DESC_P_MASK)) raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc); if (!(e2 & DESC_C_MASK) && dpl < env->cpl) { /* to inner priviledge */ get_ss_esp_from_tss(&ss, &esp, dpl); if ((ss & 0xfffc) == 0) raise_exception_err(EXCP0A_TSS, ss & 0xfffc); if ((ss & 3) != dpl) raise_exception_err(EXCP0A_TSS, ss & 0xfffc); if (load_segment(&ss_e1, &ss_e2, ss) != 0) raise_exception_err(EXCP0A_TSS, ss & 0xfffc); ss_dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3; if (ss_dpl != dpl) raise_exception_err(EXCP0A_TSS, ss & 0xfffc); if (!(ss_e2 & DESC_S_MASK) || (ss_e2 & DESC_CS_MASK) || !(ss_e2 & DESC_W_MASK)) raise_exception_err(EXCP0A_TSS, ss & 0xfffc); if (!(ss_e2 & DESC_P_MASK)) raise_exception_err(EXCP0A_TSS, ss & 0xfffc); new_stack = 1; } else if ((e2 & DESC_C_MASK) || dpl == env->cpl) { /* to same priviledge */ new_stack = 0; } else { raise_exception_err(EXCP0D_GPF, selector & 0xfffc); new_stack = 0; /* avoid warning */ } shift = type >> 3; has_error_code = 0; if (!is_int) { switch(intno) { case 8: case 10: case 11: case 12: case 13: case 14: case 17: has_error_code = 1; break; } } push_size = 6 + (new_stack << 2) + (has_error_code << 1); if (env->eflags & VM_MASK) push_size += 8; push_size <<= shift; /* XXX: check that enough room is available */ if (new_stack) { old_esp = env->regs[R_ESP]; old_ss = env->segs[R_SS].selector; load_seg(R_SS, ss, env->eip); } else { old_esp = 0; old_ss = 0; esp = env->regs[R_ESP]; } if (is_int) old_eip = next_eip; else old_eip = env->eip; old_cs = env->segs[R_CS].selector; load_seg(R_CS, selector, env->eip); env->eip = offset; env->regs[R_ESP] = esp - push_size; ssp = env->segs[R_SS].base + esp; if (shift == 1) { int old_eflags; if (env->eflags & VM_MASK) { ssp -= 4; stl(ssp, env->segs[R_GS].selector); ssp -= 4; stl(ssp, env->segs[R_FS].selector); ssp -= 4; stl(ssp, env->segs[R_DS].selector); ssp -= 4; stl(ssp, env->segs[R_ES].selector); } if (new_stack) { ssp -= 4; stl(ssp, old_ss); ssp -= 4; stl(ssp, old_esp); } ssp -= 4; old_eflags = compute_eflags(); stl(ssp, old_eflags); ssp -= 4; stl(ssp, old_cs); ssp -= 4; stl(ssp, old_eip); if (has_error_code) { ssp -= 4; stl(ssp, error_code); } } else { if (new_stack) { ssp -= 2; stw(ssp, old_ss); ssp -= 2; stw(ssp, old_esp); } ssp -= 2; stw(ssp, compute_eflags()); ssp -= 2; stw(ssp, old_cs); ssp -= 2; stw(ssp, old_eip); if (has_error_code) { ssp -= 2; stw(ssp, error_code); } } /* interrupt gate clear IF mask */ if ((type & 1) == 0) { env->eflags &= ~IF_MASK; } env->eflags &= ~(TF_MASK | VM_MASK | RF_MASK | NT_MASK); }


static inline void gen_evmergehilo(DisasContext *ctx) { if (unlikely(!ctx->spe_enabled)) { gen_exception(ctx, POWERPC_EXCP_APU); return; } #if defined(TARGET_PPC64) TCGv t0 = tcg_temp_new(); TCGv t1 = tcg_temp_new(); tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); tcg_temp_free(t0); tcg_temp_free(t1); #else tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); #endif }


void qjson_finish(QJSON *json) { json_end_object(json); }


static void arm_cache_flush(abi_ulong start, abi_ulong last) { abi_ulong addr, last1; if (last < start) return; addr = start; for(;;) { last1 = ((addr + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK) - 1; if (last1 > last) last1 = last; tb_invalidate_page_range(addr, last1 + 1); if (last1 == last) break; addr = last1 + 1; } }


Object *object_dynamic_cast(Object *obj, const char *typename) { GSList *i; /* Check if typename is a direct ancestor */ if (object_is_type(obj, typename)) { return obj; } /* Check if obj has an interface of typename */ for (i = obj->interfaces; i; i = i->next) { Interface *iface = i->data; if (object_is_type(OBJECT(iface), typename)) { return OBJECT(iface); } } /* Check if obj is an interface and its containing object is a direct * ancestor of typename */ if (object_is_type(obj, TYPE_INTERFACE)) { Interface *iface = INTERFACE(obj); if (object_is_type(iface->obj, typename)) { return iface->obj; } } return NULL; }


void ioinst_handle_rchp(S390CPU *cpu, uint64_t reg1) { int cc; uint8_t cssid; uint8_t chpid; int ret; CPUS390XState *env = &cpu->env; if (RCHP_REG1_RES(reg1)) { program_interrupt(env, PGM_OPERAND, 2); return; } cssid = RCHP_REG1_CSSID(reg1); chpid = RCHP_REG1_CHPID(reg1); trace_ioinst_chp_id("rchp", cssid, chpid); ret = css_do_rchp(cssid, chpid); switch (ret) { case -ENODEV: cc = 3; break; case -EBUSY: cc = 2; break; case 0: cc = 0; break; default: /* Invalid channel subsystem. */ program_interrupt(env, PGM_OPERAND, 2); return; } setcc(cpu, cc); }


int s390_cpu_restart(S390CPU *cpu) { if (kvm_enabled()) { return kvm_s390_cpu_restart(cpu); } return -ENOSYS; }


static int parse_packet_header(WMAVoiceContext *s) { GetBitContext *gb = &s->gb; unsigned int res; if (get_bits_left(gb) < 11) return 1; skip_bits(gb, 4); // packet sequence number s->has_residual_lsps = get_bits1(gb); do { res = get_bits(gb, 6); // number of superframes per packet // (minus first one if there is spillover) if (get_bits_left(gb) < 6 * (res == 0x3F) + s->spillover_bitsize) return 1; } while (res == 0x3F); s->spillover_nbits = get_bits(gb, s->spillover_bitsize); return 0; }


int xenstore_domain_init1(const char *kernel, const char *ramdisk, const char *cmdline) { char *dom, uuid_string[42], vm[256], path[256]; int i; snprintf(uuid_string, sizeof(uuid_string), UUID_FMT, qemu_uuid[0], qemu_uuid[1], qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14], qemu_uuid[15]); dom = xs_get_domain_path(xenstore, xen_domid); snprintf(vm, sizeof(vm), "/vm/%s", uuid_string); xenstore_domain_mkdir(dom); xenstore_write_str(vm, "image/ostype", "linux"); if (kernel) xenstore_write_str(vm, "image/kernel", kernel); if (ramdisk) xenstore_write_str(vm, "image/ramdisk", ramdisk); if (cmdline) xenstore_write_str(vm, "image/cmdline", cmdline); /* name + id */ xenstore_write_str(vm, "name", qemu_name ? qemu_name : "no-name"); xenstore_write_str(vm, "uuid", uuid_string); xenstore_write_str(dom, "name", qemu_name ? qemu_name : "no-name"); xenstore_write_int(dom, "domid", xen_domid); xenstore_write_str(dom, "vm", vm); /* memory */ xenstore_write_int(dom, "memory/target", ram_size >> 10); // kB xenstore_write_int(vm, "memory", ram_size >> 20); // MB xenstore_write_int(vm, "maxmem", ram_size >> 20); // MB /* cpus */ for (i = 0; i < smp_cpus; i++) { snprintf(path, sizeof(path), "cpu/%d/availability",i); xenstore_write_str(dom, path, "online"); } xenstore_write_int(vm, "vcpu_avail", smp_cpus); xenstore_write_int(vm, "vcpus", smp_cpus); /* vnc password */ xenstore_write_str(vm, "vncpassword", "" /* FIXME */); free(dom); return 0; }


static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { int idx; int node_id; CPUState *cs; CPUArchId *cpu_slot; X86CPUTopoInfo topo; X86CPU *cpu = X86_CPU(dev); PCMachineState *pcms = PC_MACHINE(hotplug_dev); /* if APIC ID is not set, set it based on socket/core/thread properties */ if (cpu->apic_id == UNASSIGNED_APIC_ID) { int max_socket = (max_cpus - 1) / smp_threads / smp_cores; if (cpu->socket_id < 0) { error_setg(errp, "CPU socket-id is not set"); return; } else if (cpu->socket_id > max_socket) { error_setg(errp, "Invalid CPU socket-id: %u must be in range 0:%u", cpu->socket_id, max_socket); return; } if (cpu->core_id < 0) { error_setg(errp, "CPU core-id is not set"); return; } else if (cpu->core_id > (smp_cores - 1)) { error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%u", cpu->core_id, smp_cores - 1); return; } if (cpu->thread_id < 0) { error_setg(errp, "CPU thread-id is not set"); return; } else if (cpu->thread_id > (smp_threads - 1)) { error_setg(errp, "Invalid CPU thread-id: %u must be in range 0:%u", cpu->thread_id, smp_threads - 1); return; } topo.pkg_id = cpu->socket_id; topo.core_id = cpu->core_id; topo.smt_id = cpu->thread_id; cpu->apic_id = apicid_from_topo_ids(smp_cores, smp_threads, &topo); } cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx); if (!cpu_slot) { MachineState *ms = MACHINE(pcms); x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo); error_setg(errp, "Invalid CPU [socket: %u, core: %u, thread: %u] with" " APIC ID %" PRIu32 ", valid index range 0:%d", topo.pkg_id, topo.core_id, topo.smt_id, cpu->apic_id, ms->possible_cpus->len - 1); return; } if (cpu_slot->cpu) { error_setg(errp, "CPU[%d] with APIC ID %" PRIu32 " exists", idx, cpu->apic_id); return; } /* if 'address' properties socket-id/core-id/thread-id are not set, set them * so that machine_query_hotpluggable_cpus would show correct values */ /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn() * once -smp refactoring is complete and there will be CPU private * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */ x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo); if (cpu->socket_id != -1 && cpu->socket_id != topo.pkg_id) { error_setg(errp, "property socket-id: %u doesn't match set apic-id:" " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, topo.pkg_id); return; } cpu->socket_id = topo.pkg_id; if (cpu->core_id != -1 && cpu->core_id != topo.core_id) { error_setg(errp, "property core-id: %u doesn't match set apic-id:" " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, topo.core_id); return; } cpu->core_id = topo.core_id; if (cpu->thread_id != -1 && cpu->thread_id != topo.smt_id) { error_setg(errp, "property thread-id: %u doesn't match set apic-id:" " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, topo.smt_id); return; } cpu->thread_id = topo.smt_id; cs = CPU(cpu); cs->cpu_index = idx; node_id = cpu_slot->props.node_id; if (!cpu_slot->props.has_node_id) { /* by default CPUState::numa_node was 0 if it's not set via CLI * keep it this way for now but in future we probably should * refuse to start up with incomplete numa mapping */ node_id = 0; } if (cs->numa_node == CPU_UNSET_NUMA_NODE_ID) { cs->numa_node = node_id; } else if (cs->numa_node != node_id) { error_setg(errp, "node-id %d must match numa node specified" "with -numa option for cpu-index %d", cs->numa_node, cs->cpu_index); return; } }


void monitor_readline(const char *prompt, int is_password, char *buf, int buf_size) { int i; if (is_password) { for (i = 0; i < MAX_MON; i++) if (monitor_hd[i] && monitor_hd[i]->focus == 0) qemu_chr_send_event(monitor_hd[i], CHR_EVENT_FOCUS); } readline_start(prompt, is_password, monitor_readline_cb, NULL); monitor_readline_buf = buf; monitor_readline_buf_size = buf_size; monitor_readline_started = 1; while (monitor_readline_started) { main_loop_wait(10); } }


static void decode_422_bitstream(HYuvContext *s, int count) { int i; count /= 2; if (count >= (get_bits_left(&s->gb)) / (31 * 4)) { for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1); READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2); } for (; i < count; i++) s->temp[0][2 * i ] = s->temp[1][i] = s->temp[0][2 * i + 1] = s->temp[2][i] = 128; } else { for (i = 0; i < count; i++) { READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1); READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2); } } }


static int oss_init_out (HWVoiceOut *hw, audsettings_t *as) { OSSVoiceOut *oss = (OSSVoiceOut *) hw; struct oss_params req, obt; int endianness; int err; int fd; audfmt_e effective_fmt; audsettings_t obt_as; oss->fd = -1; req.fmt = aud_to_ossfmt (as->fmt); req.freq = as->freq; req.nchannels = as->nchannels; req.fragsize = conf.fragsize; req.nfrags = conf.nfrags; if (oss_open (0, &req, &obt, &fd)) { return -1; } err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness); if (err) { oss_anal_close (&fd); return -1; } obt_as.freq = obt.freq; obt_as.nchannels = obt.nchannels; obt_as.fmt = effective_fmt; obt_as.endianness = endianness; audio_pcm_init_info (&hw->info, &obt_as); oss->nfrags = obt.nfrags; oss->fragsize = obt.fragsize; if (obt.nfrags * obt.fragsize & hw->info.align) { dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n", obt.nfrags * obt.fragsize, hw->info.align + 1); } hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; oss->mmapped = 0; if (conf.try_mmap) { oss->pcm_buf = mmap ( 0, hw->samples << hw->info.shift, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); if (oss->pcm_buf == MAP_FAILED) { oss_logerr (errno, "Failed to map %d bytes of DAC\n", hw->samples << hw->info.shift); } else { int err; int trig = 0; if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n"); } else { trig = PCM_ENABLE_OUTPUT; if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { oss_logerr ( errno, "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n" ); } else { oss->mmapped = 1; } } if (!oss->mmapped) { err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); if (err) { oss_logerr (errno, "Failed to unmap buffer %p size %d\n", oss->pcm_buf, hw->samples << hw->info.shift); } } } } if (!oss->mmapped) { oss->pcm_buf = audio_calloc ( AUDIO_FUNC, hw->samples, 1 << hw->info.shift ); if (!oss->pcm_buf) { dolog ( "Could not allocate DAC buffer (%d samples, each %d bytes)\n", hw->samples, 1 << hw->info.shift ); oss_anal_close (&fd); return -1; } } oss->fd = fd; return 0; }


void msi_notify(PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; unsigned int nr_vectors = msi_nr_vectors(flags); MSIMessage msg; assert(vector < nr_vectors); if (msi_is_masked(dev, vector)) { assert(flags & PCI_MSI_FLAGS_MASKBIT); pci_long_test_and_set_mask( dev->config + msi_pending_off(dev, msi64bit), 1U << vector); MSI_DEV_PRINTF(dev, "pending vector 0x%x\n", vector); return; } msg = msi_get_message(dev, vector); MSI_DEV_PRINTF(dev, "notify vector 0x%x" " address: 0x%"PRIx64" data: 0x%"PRIx32"\n", vector, msg.address, msg.data); stl_le_phys(&address_space_memory, msg.address, msg.data); }