static void xenstore_update_be(char *watch, char *type, int dom, struct XenDevOps *ops) { struct XenDevice *xendev; char path[XEN_BUFSIZE], *dom0, *bepath; unsigned int len, dev; dom0 = xs_get_domain_path(xenstore, 0); len = snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom); free(dom0); if (strncmp(path, watch, len) != 0) { return; } if (sscanf(watch+len, "/%u/%255s", &dev, path) != 2) { strcpy(path, ""); if (sscanf(watch+len, "/%u", &dev) != 1) { dev = -1; } } if (dev == -1) { return; } xendev = xen_be_get_xendev(type, dom, dev, ops); if (xendev != NULL) { bepath = xs_read(xenstore, 0, xendev->be, &len); if (bepath == NULL) { xen_be_del_xendev(dom, dev); } else { free(bepath); xen_be_backend_changed(xendev, path); xen_be_check_state(xendev); } } }


static inline int sub_left_prediction ( HYuvContext * s , uint8_t * dst , const uint8_t * src , int w , int left ) {
 int i ;
 if ( w < 32 ) {
 for ( i = 0 ;
 i < w ;
 i ++ ) {
 const int temp = src [ i ] ;
 dst [ i ] = temp - left ;
 left = temp ;
 }
 return left ;
 }
 else {
 for ( i = 0 ;
 i < 16 ;
 i ++ ) {
 const int temp = src [ i ] ;
 dst [ i ] = temp - left ;
 left = temp ;
 }
 s -> dsp . diff_bytes ( dst + 16 , src + 16 , src + 15 , w - 16 ) ;
 return src [ w - 1 ] ;
 }
 }


static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, TCGReg arg1, intptr_t arg2) { int opi, opx; assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32); if (type == TCG_TYPE_I32) { opi = STW, opx = STWX; } else { opi = STD, opx = STDX; } tcg_out_mem_long(s, opi, opx, arg, arg1, arg2); }


static void IRQ_local_pipe(OpenPICState *opp, int n_CPU, int n_IRQ) { IRQDest *dst; IRQSource *src; int priority; dst = &opp->dst[n_CPU]; src = &opp->src[n_IRQ]; if (src->output != OPENPIC_OUTPUT_INT) { /* On Freescale MPIC, critical interrupts ignore priority, * IACK, EOI, etc. Before MPIC v4.1 they also ignore * masking. */ src->ivpr |= IVPR_ACTIVITY_MASK; DPRINTF("%s: Raise OpenPIC output %d cpu %d irq %d\n", __func__, src->output, n_CPU, n_IRQ); qemu_irq_raise(opp->dst[n_CPU].irqs[src->output]); return; } priority = IVPR_PRIORITY(src->ivpr); if (priority <= dst->ctpr) { /* Too low priority */ DPRINTF("%s: IRQ %d has too low priority on CPU %d\n", __func__, n_IRQ, n_CPU); return; } if (IRQ_testbit(&dst->raised, n_IRQ)) { /* Interrupt miss */ DPRINTF("%s: IRQ %d was missed on CPU %d\n", __func__, n_IRQ, n_CPU); return; } src->ivpr |= IVPR_ACTIVITY_MASK; IRQ_setbit(&dst->raised, n_IRQ); if (priority < dst->raised.priority) { /* An higher priority IRQ is already raised */ DPRINTF("%s: IRQ %d is hidden by raised IRQ %d on CPU %d\n", __func__, n_IRQ, dst->raised.next, n_CPU); return; } IRQ_check(opp, &dst->raised); if (IRQ_get_next(opp, &dst->servicing) != -1 && priority <= dst->servicing.priority) { DPRINTF("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\n", __func__, n_IRQ, dst->servicing.next, n_CPU); /* Already servicing a higher priority IRQ */ return; } DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n", n_CPU, n_IRQ); qemu_irq_raise(opp->dst[n_CPU].irqs[OPENPIC_OUTPUT_INT]); }


int kvm_device_intx_assign ( KVMState * s , uint32_t dev_id , bool use_host_msi , uint32_t guest_irq ) {
 uint32_t irq_type = KVM_DEV_IRQ_GUEST_INTX | ( use_host_msi ? KVM_DEV_IRQ_HOST_MSI : KVM_DEV_IRQ_HOST_INTX ) ;
 return kvm_assign_irq_internal ( s , dev_id , irq_type , guest_irq ) ;
 }


static void omap_mcbsp_source_tick(void *opaque) { struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; static const int bps[8] = { 0, 1, 1, 2, 2, 2, -255, -255 }; if (!s->rx_rate) return; if (s->rx_req) printf("%s: Rx FIFO overrun\n", __FUNCTION__); s->rx_req = s->rx_rate << bps[(s->rcr[0] >> 5) & 7]; omap_mcbsp_rx_newdata(s); timer_mod(s->source_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND); }


MagickExport void RegisterStaticModules(void)
{
  size_t
    extent;

  ssize_t
    i;

  extent=sizeof(MagickModules)/sizeof(MagickModules[0]);
  for (i=0; i < (ssize_t) extent; i++)
  {
    if (MagickModules[i].registered == MagickFalse)
      {
        if (IsRightsAuthorized(ModulePolicyDomain,AllPolicyRights,
              MagickModules[i].module) == MagickFalse)
          continue;
        (void) (MagickModules[i].register_module)();
        MagickModules[i].registered=MagickTrue;
      }
  }
}


static void update_buflen ( const BIGNUM * b , size_t * pbuflen ) {
 size_t i ;
 if ( ! b ) return ;
 if ( * pbuflen < ( i = ( size_t ) BN_num_bytes ( b ) ) ) * pbuflen = i ;
 }


static inline int tcg_target_const_match(tcg_target_long val, const TCGArgConstraint *arg_ct) { int ct; ct = arg_ct->ct; if (ct & TCG_CT_CONST) return 1; else if ((ct & TCG_CT_CONST_S11) && ABS(val) == (ABS(val) & 0x3ff)) return 1; else if ((ct & TCG_CT_CONST_S13) && ABS(val) == (ABS(val) & 0xfff)) return 1; else return 0; }


TEST_F ( SyncBookmarkDataTypeControllerTest , StartBookmarkModelNotReady ) {
 CreateBookmarkModel ( DONT_LOAD_MODEL ) ;
 SetStartExpectations ( ) ;
 SetAssociateExpectations ( ) ;
 EXPECT_CALL ( start_callback_ , Run ( DataTypeController : : OK , _ , _ ) ) ;
 bookmark_dtc_ -> LoadModels ( base : : Bind ( & ModelLoadCallbackMock : : Run , base : : Unretained ( & model_load_callback_ ) ) ) ;
 EXPECT_EQ ( DataTypeController : : MODEL_STARTING , bookmark_dtc_ -> state ( ) ) ;
 TestingPrefServiceSimple prefs ;
 bookmark_model_ -> Load ( & prefs , std : : string ( ) , base : : FilePath ( ) , base : : ThreadTaskRunnerHandle : : Get ( ) , base : : ThreadTaskRunnerHandle : : Get ( ) ) ;
 bookmarks : : test : : WaitForBookmarkModelToLoad ( bookmark_model_ . get ( ) ) ;
 EXPECT_EQ ( DataTypeController : : MODEL_LOADED , bookmark_dtc_ -> state ( ) ) ;
 bookmark_dtc_ -> StartAssociating ( base : : Bind ( & StartCallbackMock : : Run , base : : Unretained ( & start_callback_ ) ) ) ;
 base : : MessageLoop : : current ( ) -> RunUntilIdle ( ) ;
 EXPECT_EQ ( DataTypeController : : RUNNING , bookmark_dtc_ -> state ( ) ) ;
 }


int my_getc ( FILE * file ) {
 if ( line_buffer_pos == line_buffer ) return fgetc ( file ) ;
 return * -- line_buffer_pos ;
 }


void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn, qemu_irq irq) { OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState)); usb_ohci_init(ohci, num_ports, devfn, irq, OHCI_TYPE_PXA, "OHCI USB"); ohci->mem_base = base; cpu_register_physical_memory(ohci->mem_base, 0xfff, ohci->mem); }


static void add_wav(int16_t *dest, int n, int skip_first, int *m, const int16_t *s1, const int8_t *s2, const int8_t *s3) { int i; int v[3]; v[0] = 0; for (i=!skip_first; i<3; i++) v[i] = (gain_val_tab[n][i] * m[i]) >> gain_exp_tab[n]; dest[i] = (s1[i]*v[0] + s2[i]*v[1] + s3[i]*v[2]) >> 12;


static always_inline void gen_op_subfo_64 (void) { gen_op_move_T2_T0(); gen_op_subf(); gen_op_check_subfo_64(); }


int main(int argc, char **argv, char **envp) { struct target_pt_regs regs1, *regs = &regs1; struct image_info info1, *info = &info1; struct linux_binprm bprm; TaskState *ts; CPUArchState *env; CPUState *cpu; int optind; char **target_environ, **wrk; char **target_argv; int target_argc; int i; int ret; int execfd; module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); if ((envlist = envlist_create()) == NULL) { (void) fprintf(stderr, "Unable to allocate envlist\n"); exit(EXIT_FAILURE); } /* add current environment into the list */ for (wrk = environ; *wrk != NULL; wrk++) { (void) envlist_setenv(envlist, *wrk); } /* Read the stack limit from the kernel. If it's "unlimited", then we can do little else besides use the default. */ { struct rlimit lim; if (getrlimit(RLIMIT_STACK, &lim) == 0 && lim.rlim_cur != RLIM_INFINITY && lim.rlim_cur == (target_long)lim.rlim_cur) { guest_stack_size = lim.rlim_cur; } } cpu_model = NULL; srand(time(NULL)); qemu_add_opts(&qemu_trace_opts); optind = parse_args(argc, argv); if (!trace_init_backends()) { exit(1); } trace_init_file(trace_file); /* Zero out regs */ memset(regs, 0, sizeof(struct target_pt_regs)); /* Zero out image_info */ memset(info, 0, sizeof(struct image_info)); memset(&bprm, 0, sizeof (bprm)); /* Scan interp_prefix dir for replacement files. */ init_paths(interp_prefix); init_qemu_uname_release(); if (cpu_model == NULL) { #if defined(TARGET_I386) #ifdef TARGET_X86_64 cpu_model = "qemu64"; #else cpu_model = "qemu32"; #endif #elif defined(TARGET_ARM) cpu_model = "any"; #elif defined(TARGET_UNICORE32) cpu_model = "any"; #elif defined(TARGET_M68K) cpu_model = "any"; #elif defined(TARGET_SPARC) #ifdef TARGET_SPARC64 cpu_model = "TI UltraSparc II"; #else cpu_model = "Fujitsu MB86904"; #endif #elif defined(TARGET_MIPS) #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64) cpu_model = "5KEf"; #else cpu_model = "24Kf"; #endif #elif defined TARGET_OPENRISC cpu_model = "or1200"; #elif defined(TARGET_PPC) # ifdef TARGET_PPC64 cpu_model = "POWER8"; # else cpu_model = "750"; # endif #elif defined TARGET_SH4 cpu_model = TYPE_SH7785_CPU; #elif defined TARGET_S390X cpu_model = "qemu"; #else cpu_model = "any"; #endif } tcg_exec_init(0); /* NOTE: we need to init the CPU at this stage to get qemu_host_page_size */ cpu = cpu_init(cpu_model); if (!cpu) { fprintf(stderr, "Unable to find CPU definition\n"); exit(EXIT_FAILURE); } env = cpu->env_ptr; cpu_reset(cpu); thread_cpu = cpu; if (getenv("QEMU_STRACE")) { do_strace = 1; } if (getenv("QEMU_RAND_SEED")) { handle_arg_randseed(getenv("QEMU_RAND_SEED")); } target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist); /* * Now that page sizes are configured in cpu_init() we can do * proper page alignment for guest_base. */ guest_base = HOST_PAGE_ALIGN(guest_base); if (reserved_va || have_guest_base) { guest_base = init_guest_space(guest_base, reserved_va, 0, have_guest_base); if (guest_base == (unsigned long)-1) { fprintf(stderr, "Unable to reserve 0x%lx bytes of virtual address " "space for use as guest address space (check your virtual " "memory ulimit setting or reserve less using -R option)\n", reserved_va); exit(EXIT_FAILURE); } if (reserved_va) { mmap_next_start = reserved_va; } } /* * Read in mmap_min_addr kernel parameter. This value is used * When loading the ELF image to determine whether guest_base * is needed. It is also used in mmap_find_vma. */ { FILE *fp; if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) { unsigned long tmp; if (fscanf(fp, "%lu", &tmp) == 1) { mmap_min_addr = tmp; qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=0x%lx\n", mmap_min_addr); } fclose(fp); } } /* * Prepare copy of argv vector for target. */ target_argc = argc - optind; target_argv = calloc(target_argc + 1, sizeof (char *)); if (target_argv == NULL) { (void) fprintf(stderr, "Unable to allocate memory for target_argv\n"); exit(EXIT_FAILURE); } /* * If argv0 is specified (using '-0' switch) we replace * argv[0] pointer with the given one. */ i = 0; if (argv0 != NULL) { target_argv[i++] = strdup(argv0); } for (; i < target_argc; i++) { target_argv[i] = strdup(argv[optind + i]); } target_argv[target_argc] = NULL; ts = g_new0(TaskState, 1); init_task_state(ts); /* build Task State */ ts->info = info; ts->bprm = &bprm; cpu->opaque = ts; task_settid(ts); execfd = qemu_getauxval(AT_EXECFD); if (execfd == 0) { execfd = open(filename, O_RDONLY); if (execfd < 0) { printf("Error while loading %s: %s\n", filename, strerror(errno)); _exit(EXIT_FAILURE); } } ret = loader_exec(execfd, filename, target_argv, target_environ, regs, info, &bprm); if (ret != 0) { printf("Error while loading %s: %s\n", filename, strerror(-ret)); _exit(EXIT_FAILURE); } for (wrk = target_environ; *wrk; wrk++) { free(*wrk); } free(target_environ); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { qemu_log("guest_base 0x%lx\n", guest_base); log_page_dump(); qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); qemu_log("start_code 0x" TARGET_ABI_FMT_lx "\n", info->start_code); qemu_log("start_data 0x" TARGET_ABI_FMT_lx "\n", info->start_data); qemu_log("end_data 0x" TARGET_ABI_FMT_lx "\n", info->end_data); qemu_log("start_stack 0x" TARGET_ABI_FMT_lx "\n", info->start_stack); qemu_log("brk 0x" TARGET_ABI_FMT_lx "\n", info->brk); qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry); qemu_log("argv_start 0x" TARGET_ABI_FMT_lx "\n", info->arg_start); qemu_log("env_start 0x" TARGET_ABI_FMT_lx "\n", info->arg_end + (abi_ulong)sizeof(abi_ulong)); qemu_log("auxv_start 0x" TARGET_ABI_FMT_lx "\n", info->saved_auxv); } target_set_brk(info->brk); syscall_init(); signal_init(); /* Now that we've loaded the binary, GUEST_BASE is fixed. Delay generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init(&tcg_ctx); #if defined(TARGET_I386) env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; env->hflags |= HF_PE_MASK | HF_CPL_MASK; if (env->features[FEAT_1_EDX] & CPUID_SSE) { env->cr[4] |= CR4_OSFXSR_MASK; env->hflags |= HF_OSFXSR_MASK; } #ifndef TARGET_ABI32 /* enable 64 bit mode if possible */ if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n"); exit(EXIT_FAILURE); } env->cr[4] |= CR4_PAE_MASK; env->efer |= MSR_EFER_LMA | MSR_EFER_LME; env->hflags |= HF_LMA_MASK; #endif /* flags setup : we activate the IRQs by default as in user mode */ env->eflags |= IF_MASK; /* linux register setup */ #ifndef TARGET_ABI32 env->regs[R_EAX] = regs->rax; env->regs[R_EBX] = regs->rbx; env->regs[R_ECX] = regs->rcx; env->regs[R_EDX] = regs->rdx; env->regs[R_ESI] = regs->rsi; env->regs[R_EDI] = regs->rdi; env->regs[R_EBP] = regs->rbp; env->regs[R_ESP] = regs->rsp; env->eip = regs->rip; #else env->regs[R_EAX] = regs->eax; env->regs[R_EBX] = regs->ebx; env->regs[R_ECX] = regs->ecx; env->regs[R_EDX] = regs->edx; env->regs[R_ESI] = regs->esi; env->regs[R_EDI] = regs->edi; env->regs[R_EBP] = regs->ebp; env->regs[R_ESP] = regs->esp; env->eip = regs->eip; #endif /* linux interrupt setup */ #ifndef TARGET_ABI32 env->idt.limit = 511; #else env->idt.limit = 255; #endif env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); idt_table = g2h(env->idt.base); set_idt(0, 0); set_idt(1, 0); set_idt(2, 0); set_idt(3, 3); set_idt(4, 3); set_idt(5, 0); set_idt(6, 0); set_idt(7, 0); set_idt(8, 0); set_idt(9, 0); set_idt(10, 0); set_idt(11, 0); set_idt(12, 0); set_idt(13, 0); set_idt(14, 0); set_idt(15, 0); set_idt(16, 0); set_idt(17, 0); set_idt(18, 0); set_idt(19, 0); set_idt(0x80, 3); /* linux segment setup */ { uint64_t *gdt_table; env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; gdt_table = g2h(env->gdt.base); #ifdef TARGET_ABI32 write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); #else /* 64 bit code segment */ write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | DESC_L_MASK | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); #endif write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); } cpu_x86_load_seg(env, R_CS, __USER_CS); cpu_x86_load_seg(env, R_SS, __USER_DS); #ifdef TARGET_ABI32 cpu_x86_load_seg(env, R_DS, __USER_DS); cpu_x86_load_seg(env, R_ES, __USER_DS); cpu_x86_load_seg(env, R_FS, __USER_DS); cpu_x86_load_seg(env, R_GS, __USER_DS); /* This hack makes Wine work... */ env->segs[R_FS].selector = 0; #else cpu_x86_load_seg(env, R_DS, 0); cpu_x86_load_seg(env, R_ES, 0); cpu_x86_load_seg(env, R_FS, 0); cpu_x86_load_seg(env, R_GS, 0); #endif #elif defined(TARGET_AARCH64) { int i; if (!(arm_feature(env, ARM_FEATURE_AARCH64))) { fprintf(stderr, "The selected ARM CPU does not support 64 bit mode\n"); exit(EXIT_FAILURE); } for (i = 0; i < 31; i++) { env->xregs[i] = regs->regs[i]; } env->pc = regs->pc; env->xregs[31] = regs->sp; } #elif defined(TARGET_ARM) { int i; cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC, CPSRWriteByInstr); for(i = 0; i < 16; i++) { env->regs[i] = regs->uregs[i]; } #ifdef TARGET_WORDS_BIGENDIAN /* Enable BE8. */ if (EF_ARM_EABI_VERSION(info->elf_flags) >= EF_ARM_EABI_VER4 && (info->elf_flags & EF_ARM_BE8)) { env->uncached_cpsr |= CPSR_E; env->cp15.sctlr_el[1] |= SCTLR_E0E; } else { env->cp15.sctlr_el[1] |= SCTLR_B; } #endif } #elif defined(TARGET_UNICORE32) { int i; cpu_asr_write(env, regs->uregs[32], 0xffffffff); for (i = 0; i < 32; i++) { env->regs[i] = regs->uregs[i]; } } #elif defined(TARGET_SPARC) { int i; env->pc = regs->pc; env->npc = regs->npc; env->y = regs->y; for(i = 0; i < 8; i++) env->gregs[i] = regs->u_regs[i]; for(i = 0; i < 8; i++) env->regwptr[i] = regs->u_regs[i + 8]; } #elif defined(TARGET_PPC) { int i; #if defined(TARGET_PPC64) int flag = (env->insns_flags2 & PPC2_BOOKE206) ? MSR_CM : MSR_SF; #if defined(TARGET_ABI32) env->msr &= ~((target_ulong)1 << flag); #else env->msr |= (target_ulong)1 << flag; #endif #endif env->nip = regs->nip; for(i = 0; i < 32; i++) { env->gpr[i] = regs->gpr[i]; } } #elif defined(TARGET_M68K) { env->pc = regs->pc; env->dregs[0] = regs->d0; env->dregs[1] = regs->d1; env->dregs[2] = regs->d2; env->dregs[3] = regs->d3; env->dregs[4] = regs->d4; env->dregs[5] = regs->d5; env->dregs[6] = regs->d6; env->dregs[7] = regs->d7; env->aregs[0] = regs->a0; env->aregs[1] = regs->a1; env->aregs[2] = regs->a2; env->aregs[3] = regs->a3; env->aregs[4] = regs->a4; env->aregs[5] = regs->a5; env->aregs[6] = regs->a6; env->aregs[7] = regs->usp; env->sr = regs->sr; ts->sim_syscalls = 1; } #elif defined(TARGET_MICROBLAZE) { env->regs[0] = regs->r0; env->regs[1] = regs->r1; env->regs[2] = regs->r2; env->regs[3] = regs->r3; env->regs[4] = regs->r4; env->regs[5] = regs->r5; env->regs[6] = regs->r6; env->regs[7] = regs->r7; env->regs[8] = regs->r8; env->regs[9] = regs->r9; env->regs[10] = regs->r10; env->regs[11] = regs->r11; env->regs[12] = regs->r12; env->regs[13] = regs->r13; env->regs[14] = regs->r14; env->regs[15] = regs->r15; env->regs[16] = regs->r16; env->regs[17] = regs->r17; env->regs[18] = regs->r18; env->regs[19] = regs->r19; env->regs[20] = regs->r20; env->regs[21] = regs->r21; env->regs[22] = regs->r22; env->regs[23] = regs->r23; env->regs[24] = regs->r24; env->regs[25] = regs->r25; env->regs[26] = regs->r26; env->regs[27] = regs->r27; env->regs[28] = regs->r28; env->regs[29] = regs->r29; env->regs[30] = regs->r30; env->regs[31] = regs->r31; env->sregs[SR_PC] = regs->pc; } #elif defined(TARGET_MIPS) { int i; for(i = 0; i < 32; i++) { env->active_tc.gpr[i] = regs->regs[i]; } env->active_tc.PC = regs->cp0_epc & ~(target_ulong)1; if (regs->cp0_epc & 1) { env->hflags |= MIPS_HFLAG_M16; } if (((info->elf_flags & EF_MIPS_NAN2008) != 0) != ((env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) != 0)) { if ((env->active_fpu.fcr31_rw_bitmask & (1 << FCR31_NAN2008)) == 0) { fprintf(stderr, "ELF binary's NaN mode not supported by CPU\n"); exit(1); } if ((info->elf_flags & EF_MIPS_NAN2008) != 0) { env->active_fpu.fcr31 |= (1 << FCR31_NAN2008); } else { env->active_fpu.fcr31 &= ~(1 << FCR31_NAN2008); } restore_snan_bit_mode(env); } } #elif defined(TARGET_NIOS2) { env->regs[0] = 0; env->regs[1] = regs->r1; env->regs[2] = regs->r2; env->regs[3] = regs->r3; env->regs[4] = regs->r4; env->regs[5] = regs->r5; env->regs[6] = regs->r6; env->regs[7] = regs->r7; env->regs[8] = regs->r8; env->regs[9] = regs->r9; env->regs[10] = regs->r10; env->regs[11] = regs->r11; env->regs[12] = regs->r12; env->regs[13] = regs->r13; env->regs[14] = regs->r14; env->regs[15] = regs->r15; /* TODO: unsigned long orig_r2; */ env->regs[R_RA] = regs->ra; env->regs[R_FP] = regs->fp; env->regs[R_SP] = regs->sp; env->regs[R_GP] = regs->gp; env->regs[CR_ESTATUS] = regs->estatus; env->regs[R_EA] = regs->ea; /* TODO: unsigned long orig_r7; */ /* Emulate eret when starting thread. */ env->regs[R_PC] = regs->ea; } #elif defined(TARGET_OPENRISC) { int i; for (i = 0; i < 32; i++) { env->gpr[i] = regs->gpr[i]; } env->pc = regs->pc; cpu_set_sr(env, regs->sr); } #elif defined(TARGET_SH4) { int i; for(i = 0; i < 16; i++) { env->gregs[i] = regs->regs[i]; } env->pc = regs->pc; } #elif defined(TARGET_ALPHA) { int i; for(i = 0; i < 28; i++) { env->ir[i] = ((abi_ulong *)regs)[i]; } env->ir[IR_SP] = regs->usp; env->pc = regs->pc; } #elif defined(TARGET_CRIS) { env->regs[0] = regs->r0; env->regs[1] = regs->r1; env->regs[2] = regs->r2; env->regs[3] = regs->r3; env->regs[4] = regs->r4; env->regs[5] = regs->r5; env->regs[6] = regs->r6; env->regs[7] = regs->r7; env->regs[8] = regs->r8; env->regs[9] = regs->r9; env->regs[10] = regs->r10; env->regs[11] = regs->r11; env->regs[12] = regs->r12; env->regs[13] = regs->r13; env->regs[14] = info->start_stack; env->regs[15] = regs->acr; env->pc = regs->erp; } #elif defined(TARGET_S390X) { int i; for (i = 0; i < 16; i++) { env->regs[i] = regs->gprs[i]; } env->psw.mask = regs->psw.mask; env->psw.addr = regs->psw.addr; } #elif defined(TARGET_TILEGX) { int i; for (i = 0; i < TILEGX_R_COUNT; i++) { env->regs[i] = regs->regs[i]; } for (i = 0; i < TILEGX_SPR_COUNT; i++) { env->spregs[i] = 0; } env->pc = regs->pc; } #elif defined(TARGET_HPPA) { int i; for (i = 1; i < 32; i++) { env->gr[i] = regs->gr[i]; } env->iaoq_f = regs->iaoq[0]; env->iaoq_b = regs->iaoq[1]; } #else #error unsupported target CPU #endif #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) ts->stack_base = info->start_stack; ts->heap_base = info->brk; /* This will be filled in on the first SYS_HEAPINFO call. */ ts->heap_limit = 0; #endif if (gdbstub_port) { if (gdbserver_start(gdbstub_port) < 0) { fprintf(stderr, "qemu: could not open gdbserver on port %d\n", gdbstub_port); exit(EXIT_FAILURE); } gdb_handlesig(cpu, 0); } cpu_loop(env); /* never exits */ return 0; }


static av_cold int X264_init(AVCodecContext *avctx) { X264Context *x4 = avctx->priv_data; int sw,sh; if (avctx->global_quality > 0) av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n"); x264_param_default(&x4->params); x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER; if (x4->preset || x4->tune) if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) { int i; av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune); av_log(avctx, AV_LOG_INFO, "Possible presets:"); for (i = 0; x264_preset_names[i]; i++) av_log(avctx, AV_LOG_INFO, " %s", x264_preset_names[i]); av_log(avctx, AV_LOG_INFO, "\n"); av_log(avctx, AV_LOG_INFO, "Possible tunes:"); for (i = 0; x264_tune_names[i]; i++) av_log(avctx, AV_LOG_INFO, " %s", x264_tune_names[i]); av_log(avctx, AV_LOG_INFO, "\n"); return AVERROR(EINVAL); } if (avctx->level > 0) x4->params.i_level_idc = avctx->level; x4->params.pf_log = X264_log; x4->params.p_log_private = avctx; x4->params.i_log_level = X264_LOG_DEBUG; x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt); OPT_STR("weightp", x4->wpredp); if (avctx->bit_rate) { x4->params.rc.i_bitrate = avctx->bit_rate / 1000; x4->params.rc.i_rc_method = X264_RC_ABR; } x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1; if (avctx->flags & CODEC_FLAG_PASS2) { x4->params.rc.b_stat_read = 1; } else { if (x4->crf >= 0) { x4->params.rc.i_rc_method = X264_RC_CRF; x4->params.rc.f_rf_constant = x4->crf; } else if (x4->cqp >= 0) { x4->params.rc.i_rc_method = X264_RC_CQP; x4->params.rc.i_qp_constant = x4->cqp; } if (x4->crf_max >= 0) x4->params.rc.f_rf_constant_max = x4->crf_max; } if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy > 0 && (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) { x4->params.rc.f_vbv_buffer_init = (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size; } OPT_STR("level", x4->level); if (avctx->i_quant_factor > 0) x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); if (avctx->b_quant_factor > 0) x4->params.rc.f_pb_factor = avctx->b_quant_factor; if (avctx->chromaoffset) x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; if (avctx->me_method == ME_EPZS) x4->params.analyse.i_me_method = X264_ME_DIA; else if (avctx->me_method == ME_HEX) x4->params.analyse.i_me_method = X264_ME_HEX; else if (avctx->me_method == ME_UMH) x4->params.analyse.i_me_method = X264_ME_UMH; else if (avctx->me_method == ME_FULL) x4->params.analyse.i_me_method = X264_ME_ESA; else if (avctx->me_method == ME_TESA) x4->params.analyse.i_me_method = X264_ME_TESA; if (avctx->gop_size >= 0) x4->params.i_keyint_max = avctx->gop_size; if (avctx->max_b_frames >= 0) x4->params.i_bframe = avctx->max_b_frames; if (avctx->scenechange_threshold >= 0) x4->params.i_scenecut_threshold = avctx->scenechange_threshold; if (avctx->qmin >= 0) x4->params.rc.i_qp_min = avctx->qmin; if (avctx->qmax >= 0) x4->params.rc.i_qp_max = avctx->qmax; if (avctx->max_qdiff >= 0) x4->params.rc.i_qp_step = avctx->max_qdiff; if (avctx->qblur >= 0) x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ if (avctx->qcompress >= 0) x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ if (avctx->refs >= 0) x4->params.i_frame_reference = avctx->refs; else if (x4->level) { int i; int mbn = FF_CEIL_RSHIFT(avctx->width, 4) * FF_CEIL_RSHIFT(avctx->height, 4); int level_id = -1; char *tail; int scale = X264_BUILD < 129 ? 384 : 1; if (!strcmp(x4->level, "1b")) { level_id = 9; } else if (strlen(x4->level) <= 3){ level_id = av_strtod(x4->level, &tail) * 10 + 0.5; if (*tail) level_id = -1; } if (level_id <= 0) av_log(avctx, AV_LOG_WARNING, "Failed to parse level\n"); for (i = 0; i<x264_levels[i].level_idc; i++) if (x264_levels[i].level_idc == level_id) x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn / scale, 1, x4->params.i_frame_reference); } if (avctx->trellis >= 0) x4->params.analyse.i_trellis = avctx->trellis; if (avctx->me_range >= 0) x4->params.analyse.i_me_range = avctx->me_range; if (avctx->noise_reduction >= 0) x4->params.analyse.i_noise_reduction = avctx->noise_reduction; if (avctx->me_subpel_quality >= 0) x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; if (avctx->b_frame_strategy >= 0) x4->params.i_bframe_adaptive = avctx->b_frame_strategy; if (avctx->keyint_min >= 0) x4->params.i_keyint_min = avctx->keyint_min; if (avctx->coder_type >= 0) x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC; if (avctx->me_cmp >= 0) x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA; if (x4->aq_mode >= 0) x4->params.rc.i_aq_mode = x4->aq_mode; if (x4->aq_strength >= 0) x4->params.rc.f_aq_strength = x4->aq_strength; PARSE_X264_OPT("psy-rd", psy_rd); PARSE_X264_OPT("deblock", deblock); PARSE_X264_OPT("partitions", partitions); PARSE_X264_OPT("stats", stats); if (x4->psy >= 0) x4->params.analyse.b_psy = x4->psy; if (x4->rc_lookahead >= 0) x4->params.rc.i_lookahead = x4->rc_lookahead; if (x4->weightp >= 0) x4->params.analyse.i_weighted_pred = x4->weightp; if (x4->weightb >= 0) x4->params.analyse.b_weighted_bipred = x4->weightb; if (x4->cplxblur >= 0) x4->params.rc.f_complexity_blur = x4->cplxblur; if (x4->ssim >= 0) x4->params.analyse.b_ssim = x4->ssim; if (x4->intra_refresh >= 0) x4->params.b_intra_refresh = x4->intra_refresh; if (x4->bluray_compat >= 0) { x4->params.b_bluray_compat = x4->bluray_compat; x4->params.b_vfr_input = 0; } if (x4->avcintra_class >= 0) #if X264_BUILD >= 142 x4->params.i_avcintra_class = x4->avcintra_class; #else av_log(avctx, AV_LOG_ERROR, "x264 too old for AVC Intra, at least version 142 needed\n"); #endif if (x4->b_bias != INT_MIN) x4->params.i_bframe_bias = x4->b_bias; if (x4->b_pyramid >= 0) x4->params.i_bframe_pyramid = x4->b_pyramid; if (x4->mixed_refs >= 0) x4->params.analyse.b_mixed_references = x4->mixed_refs; if (x4->dct8x8 >= 0) x4->params.analyse.b_transform_8x8 = x4->dct8x8; if (x4->fast_pskip >= 0) x4->params.analyse.b_fast_pskip = x4->fast_pskip; if (x4->aud >= 0) x4->params.b_aud = x4->aud; if (x4->mbtree >= 0) x4->params.rc.b_mb_tree = x4->mbtree; if (x4->direct_pred >= 0) x4->params.analyse.i_direct_mv_pred = x4->direct_pred; if (x4->slice_max_size >= 0) x4->params.i_slice_max_size = x4->slice_max_size; else { /* * Allow x264 to be instructed through AVCodecContext about the maximum * size of the RTP payload. For example, this enables the production of * payload suitable for the H.264 RTP packetization-mode 0 i.e. single * NAL unit per RTP packet. */ if (avctx->rtp_payload_size) x4->params.i_slice_max_size = avctx->rtp_payload_size; } if (x4->fastfirstpass) x264_param_apply_fastfirstpass(&x4->params); /* Allow specifying the x264 profile through AVCodecContext. */ if (!x4->profile) switch (avctx->profile) { case FF_PROFILE_H264_BASELINE: x4->profile = av_strdup("baseline"); break; case FF_PROFILE_H264_HIGH: x4->profile = av_strdup("high"); break; case FF_PROFILE_H264_HIGH_10: x4->profile = av_strdup("high10"); break; case FF_PROFILE_H264_HIGH_422: x4->profile = av_strdup("high422"); break; case FF_PROFILE_H264_HIGH_444: x4->profile = av_strdup("high444"); break; case FF_PROFILE_H264_MAIN: x4->profile = av_strdup("main"); break; default: break; } if (x4->nal_hrd >= 0) x4->params.i_nal_hrd = x4->nal_hrd; if (x4->profile) if (x264_param_apply_profile(&x4->params, x4->profile) < 0) { int i; av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile); av_log(avctx, AV_LOG_INFO, "Possible profiles:"); for (i = 0; x264_profile_names[i]; i++) av_log(avctx, AV_LOG_INFO, " %s", x264_profile_names[i]); av_log(avctx, AV_LOG_INFO, "\n"); return AVERROR(EINVAL); } x4->params.i_width = avctx->width; x4->params.i_height = avctx->height; av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096); x4->params.vui.i_sar_width = sw; x4->params.vui.i_sar_height = sh; x4->params.i_timebase_den = avctx->time_base.den; x4->params.i_timebase_num = avctx->time_base.num; x4->params.i_fps_num = avctx->time_base.den; x4->params.i_fps_den = avctx->time_base.num * avctx->ticks_per_frame; x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR; x4->params.i_threads = avctx->thread_count; if (avctx->thread_type) x4->params.b_sliced_threads = avctx->thread_type == FF_THREAD_SLICE; x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT; x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP); x4->params.i_slice_count = avctx->slices; x4->params.vui.b_fullrange = avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || avctx->color_range == AVCOL_RANGE_JPEG; if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED) x4->params.vui.i_colmatrix = avctx->colorspace; if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) x4->params.vui.i_colorprim = avctx->color_primaries; if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED) x4->params.vui.i_transfer = avctx->color_trc; if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) x4->params.b_repeat_headers = 0; if(x4->x264opts){ const char *p= x4->x264opts; while(p){ char param[256]={0}, val[256]={0}; if(sscanf(p, "%255[^:=]=%255[^:]", param, val) == 1){ OPT_STR(param, "1"); }else OPT_STR(param, val); p= strchr(p, ':'); p+=!!p; } } if (x4->x264_params) { AVDictionary *dict = NULL; AVDictionaryEntry *en = NULL; if (!av_dict_parse_string(&dict, x4->x264_params, "=", ":", 0)) { while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) { if (x264_param_parse(&x4->params, en->key, en->value) < 0) av_log(avctx, AV_LOG_WARNING, "Error parsing option '%s = %s'.\n", en->key, en->value); } av_dict_free(&dict); } } // update AVCodecContext with x264 parameters avctx->has_b_frames = x4->params.i_bframe ? x4->params.i_bframe_pyramid ? 2 : 1 : 0; if (avctx->max_b_frames < 0) avctx->max_b_frames = 0; avctx->bit_rate = x4->params.rc.i_bitrate*1000; x4->enc = x264_encoder_open(&x4->params); if (!x4->enc) return -1; avctx->coded_frame = av_frame_alloc(); if (!avctx->coded_frame) return AVERROR(ENOMEM); if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) { x264_nal_t *nal; uint8_t *p; int nnal, s, i; s = x264_encoder_headers(x4->enc, &nal, &nnal); avctx->extradata = p = av_malloc(s); for (i = 0; i < nnal; i++) { /* Don't put the SEI in extradata. */ if (nal[i].i_type == NAL_SEI) { av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25); x4->sei_size = nal[i].i_payload; x4->sei = av_malloc(x4->sei_size); if (!x4->sei) memcpy(x4->sei, nal[i].p_payload, nal[i].i_payload); continue; } memcpy(p, nal[i].p_payload, nal[i].i_payload); p += nal[i].i_payload; } avctx->extradata_size = p - avctx->extradata; } return 0; nomem: X264_close(avctx); return AVERROR(ENOMEM); }


static void isf_add_mean_and_past ( float * isf_q , float * isf_past ) {
 int i ;
 float tmp ;
 for ( i = 0 ;
 i < LP_ORDER ;
 i ++ ) {
 tmp = isf_q [ i ] ;
 isf_q [ i ] += isf_mean [ i ] * ( 1.0f / ( 1 << 15 ) ) ;
 isf_q [ i ] += PRED_FACTOR * isf_past [ i ] ;
 isf_past [ i ] = tmp ;
 }
 }


static int lag_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; LagarithContext *l = avctx->priv_data; AVFrame *const p = &l->picture; uint8_t frametype = 0; uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9; uint32_t offs[4]; uint8_t *srcs[4], *dst; int i, j, planes = 3; AVFrame *picture = data; if (p->data[0]) avctx->release_buffer(avctx, p); p->reference = 0; p->key_frame = 1; frametype = buf[0]; offset_gu = AV_RL32(buf + 1); offset_bv = AV_RL32(buf + 5); switch (frametype) { case FRAME_SOLID_RGBA: avctx->pix_fmt = PIX_FMT_RGB32; if (avctx->get_buffer(avctx, p) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } dst = p->data[0]; for (j = 0; j < avctx->height; j++) { for (i = 0; i < avctx->width; i++) AV_WN32(dst + i * 4, offset_gu); dst += p->linesize[0]; } break; case FRAME_ARITH_RGBA: avctx->pix_fmt = PIX_FMT_RGB32; planes = 4; offset_ry += 4; offs[3] = AV_RL32(buf + 9); case FRAME_ARITH_RGB24: case FRAME_U_RGB24: if (frametype == FRAME_ARITH_RGB24 || frametype == FRAME_U_RGB24) avctx->pix_fmt = PIX_FMT_RGB24; if (avctx->get_buffer(avctx, p) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } offs[0] = offset_bv; offs[1] = offset_gu; offs[2] = offset_ry; if (!l->rgb_planes) { l->rgb_stride = FFALIGN(avctx->width, 16); l->rgb_planes = av_malloc(l->rgb_stride * avctx->height * planes); if (!l->rgb_planes) { av_log(avctx, AV_LOG_ERROR, "cannot allocate temporary buffer\n"); return AVERROR(ENOMEM); } } for (i = 0; i < planes; i++) srcs[i] = l->rgb_planes + (i + 1) * l->rgb_stride * avctx->height - l->rgb_stride; if (offset_ry >= buf_size || offset_gu >= buf_size || offset_bv >= buf_size || (planes == 4 && offs[3] >= buf_size)) { av_log(avctx, AV_LOG_ERROR, "Invalid frame offsets\n"); return AVERROR_INVALIDDATA; } for (i = 0; i < planes; i++) lag_decode_arith_plane(l, srcs[i], avctx->width, avctx->height, -l->rgb_stride, buf + offs[i], buf_size - offs[i]); dst = p->data[0]; for (i = 0; i < planes; i++) srcs[i] = l->rgb_planes + i * l->rgb_stride * avctx->height; for (j = 0; j < avctx->height; j++) { for (i = 0; i < avctx->width; i++) { uint8_t r, g, b, a; r = srcs[0][i]; g = srcs[1][i]; b = srcs[2][i]; r += g; b += g; if (frametype == FRAME_ARITH_RGBA) { a = srcs[3][i]; AV_WN32(dst + i * 4, MKBETAG(a, r, g, b)); } else { dst[i * 3 + 0] = r; dst[i * 3 + 1] = g; dst[i * 3 + 2] = b; } } dst += p->linesize[0]; for (i = 0; i < planes; i++) srcs[i] += l->rgb_stride; } break; case FRAME_ARITH_YUY2: avctx->pix_fmt = PIX_FMT_YUV422P; if (avctx->get_buffer(avctx, p) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } if (offset_ry >= buf_size || offset_gu >= buf_size || offset_bv >= buf_size) { av_log(avctx, AV_LOG_ERROR, "Invalid frame offsets\n"); return AVERROR_INVALIDDATA; } lag_decode_arith_plane(l, p->data[0], avctx->width, avctx->height, p->linesize[0], buf + offset_ry, buf_size - offset_ry); lag_decode_arith_plane(l, p->data[2], avctx->width / 2, avctx->height, p->linesize[2], buf + offset_gu, buf_size - offset_gu); lag_decode_arith_plane(l, p->data[1], avctx->width / 2, avctx->height, p->linesize[1], buf + offset_bv, buf_size - offset_bv); break; case FRAME_ARITH_YV12: avctx->pix_fmt = PIX_FMT_YUV420P; if (avctx->get_buffer(avctx, p) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } if (offset_ry >= buf_size || offset_gu >= buf_size || offset_bv >= buf_size) { av_log(avctx, AV_LOG_ERROR, "Invalid frame offsets\n"); return AVERROR_INVALIDDATA; } lag_decode_arith_plane(l, p->data[0], avctx->width, avctx->height, p->linesize[0], buf + offset_ry, buf_size - offset_ry); lag_decode_arith_plane(l, p->data[2], avctx->width / 2, avctx->height / 2, p->linesize[2], buf + offset_gu, buf_size - offset_gu); lag_decode_arith_plane(l, p->data[1], avctx->width / 2, avctx->height / 2, p->linesize[1], buf + offset_bv, buf_size - offset_bv); break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported Lagarith frame type: %#x\n", frametype); return -1; } *picture = *p; *data_size = sizeof(AVFrame); return buf_size; }


static const char * map_token ( const value_valuestring * token_map , guint8 codepage , guint8 token ) {
 const value_string * vs ;
 const char * s ;
 if ( token_map ) {
 if ( ( vs = val_to_valstr ( codepage , token_map ) ) ) {
 s = try_val_to_str ( token , vs ) ;
 if ( s ) {
 DebugLog ( ( "map_token(codepage = %u, token = %u: [%s]\n" , codepage , token , s ) ) ;
 return s ;
 }
 DebugLog ( ( "map_token(codepage = %u, token = %u: " wbxml_UNDEFINED_TOKEN "\n" , codepage , token ) ) ;
 return wbxml_UNDEFINED_TOKEN ;
 }
 DebugLog ( ( "map_token(codepage = %u, token = %u: " wbxml_UNDEFINED_TOKEN_CODE_PAGE "\n" , codepage , token ) ) ;
 return wbxml_UNDEFINED_TOKEN_CODE_PAGE ;
 }
 DebugLog ( ( "map_token(codepage = %u, token = %u: " wbxml_UNDEFINED_TOKEN_MAP "\n" , codepage , token ) ) ;
 return wbxml_UNDEFINED_TOKEN_MAP ;
 }


static void choose_largest_tx_size ( VP9_COMP * cpi , MACROBLOCK * x , int * rate , int64_t * distortion , int * skip , int64_t * sse , int64_t ref_best_rd , BLOCK_SIZE bs ) {
 const TX_SIZE max_tx_size = max_txsize_lookup [ bs ] ;
 VP9_COMMON * const cm = & cpi -> common ;
 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size [ cm -> tx_mode ] ;
 MACROBLOCKD * const xd = & x -> e_mbd ;
 MB_MODE_INFO * const mbmi = & xd -> mi [ 0 ] . src_mi -> mbmi ;
 mbmi -> tx_size = MIN ( max_tx_size , largest_tx_size ) ;
 txfm_rd_in_plane ( x , rate , distortion , skip , sse , ref_best_rd , 0 , bs , mbmi -> tx_size , cpi -> sf . use_fast_coef_costing ) ;
 }


static gs_memory_t * gs_heap_stable ( gs_memory_t * mem ) {
 return mem ;
 }


SPL_METHOD ( SplFileObject , getChildren ) {
 if ( zend_parse_parameters_none ( ) == FAILURE ) {
 return ;
 }
 }


static int dvvideo_encode_close(AVCodecContext *avctx) { av_frame_free(&avctx->coded_frame); return 0; }


  v8::Local<v8::Promise> Invoke(v8::Isolate* isolate,
                                gin_helper::ErrorThrower thrower,
                                bool internal,
                                const std::string& channel,
                                v8::Local<v8::Value> arguments) {
    if (!electron_browser_remote_) {
      thrower.ThrowError(kIPCMethodCalledAfterContextReleasedError);
      return v8::Local<v8::Promise>();
    }
    blink::CloneableMessage message;
    if (!electron::SerializeV8Value(isolate, arguments, &message)) {
      return v8::Local<v8::Promise>();
    }
    gin_helper::Promise<blink::CloneableMessage> p(isolate);
    auto handle = p.GetHandle();

    electron_browser_remote_->Invoke(
        internal, channel, std::move(message),
        base::BindOnce(
            [](gin_helper::Promise<blink::CloneableMessage> p,
               blink::CloneableMessage result) { p.Resolve(result); },
            std::move(p)));

    return handle;
  }


static void extract_job_on_completed ( AutoarExtractor * extractor , gpointer user_data ) {
 ExtractJob * extract_job = user_data ;
 GFile * output_file ;
 output_file = G_FILE ( extract_job -> output_files -> data ) ;
 nautilus_file_changes_queue_file_added ( output_file ) ;
 }


void ElectronBrowserHandlerImpl::SetTemporaryZoomLevel(double level) {
  api::WebContents* api_web_contents = api::WebContents::From(web_contents());
  if (api_web_contents) {
    api_web_contents->SetTemporaryZoomLevel(level);
  }
}


void OnDestruct() override { electron_browser_remote_.reset(); }


static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track) { int64_t maxTrackLenTemp; put_be32(pb, 0x5c); /* size (always 0x5c) */ put_tag(pb, "tkhd"); put_be32(pb, 0xf); /* version & flags (track enabled) */ put_be32(pb, track->time); /* creation time */ put_be32(pb, track->time); /* modification time */ put_be32(pb, track->trackID); /* track-id */ put_be32(pb, 0); /* reserved */ maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)track->trackDuration)/(int64_t)track->timescale; put_be32(pb, (long)maxTrackLenTemp); /* duration */ put_be32(pb, 0); /* reserved */ put_be32(pb, 0); /* reserved */ put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */ /* Volume, only for audio */ if(track->enc->codec_type == CODEC_TYPE_AUDIO) put_be16(pb, 0x0100); else put_be16(pb, 0); put_be16(pb, 0); /* reserved */ /* Matrix structure */ put_be32(pb, 0x00010000); /* reserved */ put_be32(pb, 0x0); /* reserved */ put_be32(pb, 0x0); /* reserved */ put_be32(pb, 0x0); /* reserved */ put_be32(pb, 0x00010000); /* reserved */ put_be32(pb, 0x0); /* reserved */ put_be32(pb, 0x0); /* reserved */ put_be32(pb, 0x0); /* reserved */ put_be32(pb, 0x40000000); /* reserved */ /* Track width and height, for visual only */ if(track->enc->codec_type == CODEC_TYPE_VIDEO) { put_be32(pb, track->enc->width*0x10000); put_be32(pb, track->enc->height*0x10000); } else { put_be32(pb, 0); put_be32(pb, 0); } return 0x5c; }


static void quantize_and_encode_band_cost_NONE_mips(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, const float ROUNDING) { av_assert0(0); }


void ElectronRenderFrameObserver::DraggableRegionsChanged() {
  blink::WebVector<blink::WebDraggableRegion> webregions =
      render_frame_->GetWebFrame()->GetDocument().DraggableRegions();
  std::vector<mojom::DraggableRegionPtr> regions;
  for (auto& webregion : webregions) {
    auto region = mojom::DraggableRegion::New();
    render_frame_->ConvertViewportToWindow(&webregion.bounds);
    region->bounds = webregion.bounds;
    region->draggable = webregion.draggable;
    regions.push_back(std::move(region));
  }

  mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
  render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(&browser_remote);
  browser_remote->UpdateDraggableRegions(std::move(regions));
}


static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *int_mask, bool queuing) { UHCIAsync *async; int len = 0, max_len; uint8_t pid; USBDevice *dev; USBEndpoint *ep; /* Is active ? */ if (!(td->ctrl & TD_CTRL_ACTIVE)) return TD_RESULT_NEXT_QH; async = uhci_async_find_td(s, addr, td); if (async) { /* Already submitted */ async->queue->valid = 32; if (!async->done) return TD_RESULT_ASYNC_CONT; if (queuing) { /* we are busy filling the queue, we are not prepared to consume completed packages then, just leave them in async state */ return TD_RESULT_ASYNC_CONT; } uhci_async_unlink(async); goto done; } /* Allocate new packet */ async = uhci_async_alloc(uhci_queue_get(s, td), addr); /* valid needs to be large enough to handle 10 frame delay * for initial isochronous requests */ async->queue->valid = 32; async->isoc = td->ctrl & TD_CTRL_IOS; max_len = ((td->token >> 21) + 1) & 0x7ff; pid = td->token & 0xff; dev = uhci_find_device(s, (td->token >> 8) & 0x7f); ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf); usb_packet_setup(&async->packet, pid, ep); qemu_sglist_add(&async->sgl, td->buffer, max_len); usb_packet_map(&async->packet, &async->sgl); switch(pid) { case USB_TOKEN_OUT: case USB_TOKEN_SETUP: len = usb_handle_packet(dev, &async->packet); if (len >= 0) len = max_len; break; case USB_TOKEN_IN: len = usb_handle_packet(dev, &async->packet); break; default: /* invalid pid : frame interrupted */ uhci_async_free(async); s->status |= UHCI_STS_HCPERR; uhci_update_irq(s); return TD_RESULT_STOP_FRAME; } if (len == USB_RET_ASYNC) { uhci_async_link(async); return TD_RESULT_ASYNC_START; } async->packet.result = len; done: len = uhci_complete_td(s, td, async, int_mask); usb_packet_unmap(&async->packet); uhci_async_free(async); return len; }


void WebContents::Message(bool internal,
                          const std::string& channel,
                          blink::CloneableMessage arguments,
                          content::RenderFrameHost* render_frame_host) {
  TRACE_EVENT1("electron", "WebContents::Message", "channel", channel);
  // webContents.emit('-ipc-message', new Event(), internal, channel,
  // arguments);
  EmitWithSender("-ipc-message", render_frame_host,
                 electron::mojom::ElectronBrowser::InvokeCallback(), internal,
                 channel, std::move(arguments));
}


static void cancel_mount_for_file ( NautilusDirectory * directory , NautilusFile * file ) {
 if ( directory -> details -> mount_state != NULL && directory -> details -> mount_state -> file == file ) {
 mount_cancel ( directory ) ;
 }
 }


void spl_filesystem_info_set_filename ( spl_filesystem_object * intern , char * path , int len , int use_copy TSRMLS_DC ) {
 char * p1 , * p2 ;
 if ( intern -> file_name ) {
 efree ( intern -> file_name ) ;
 }
 intern -> file_name = use_copy ? estrndup ( path , len ) : path ;
 intern -> file_name_len = len ;
 while ( IS_SLASH_AT ( intern -> file_name , intern -> file_name_len - 1 ) && intern -> file_name_len > 1 ) {
 intern -> file_name [ intern -> file_name_len - 1 ] = 0 ;
 intern -> file_name_len -- ;
 }
 p1 = strrchr ( intern -> file_name , '/' ) ;
 # if defined ( PHP_WIN32 ) || defined ( NETWARE ) p2 = strrchr ( intern -> file_name , '\\' ) ;
 # else p2 = 0 ;
 # endif if ( p1 || p2 ) {
 intern -> _path_len = ( p1 > p2 ? p1 : p2 ) - intern -> file_name ;
 }
 else {
 intern -> _path_len = 0 ;
 }
 if ( intern -> _path ) {
 efree ( intern -> _path ) ;
 }
 intern -> _path = estrndup ( path , intern -> _path_len ) ;
 }


Status PyArrayDescr_to_TF_DataType(PyArray_Descr* descr,
                                   TF_DataType* out_tf_datatype) {
  PyObject* key;
  PyObject* value;
  Py_ssize_t pos = 0;
  if (PyDict_Next(descr->fields, &pos, &key, &value)) {
    // In Python 3, the keys of numpy custom struct types are unicode, unlike
    // Python 2, where the keys are bytes.
    const char* key_string =
        PyBytes_Check(key) ? PyBytes_AsString(key)
                           : PyBytes_AsString(PyUnicode_AsASCIIString(key));
    if (!key_string) {
      return errors::Internal("Corrupt numpy type descriptor");
    }
    tensorflow::string key = key_string;
    // The typenames here should match the field names in the custom struct
    // types constructed in test_util.py.
    // TODO(mrry,keveman): Investigate Numpy type registration to replace this
    // hard-coding of names.
    if (key == "quint8") {
      *out_tf_datatype = TF_QUINT8;
    } else if (key == "qint8") {
      *out_tf_datatype = TF_QINT8;
    } else if (key == "qint16") {
      *out_tf_datatype = TF_QINT16;
    } else if (key == "quint16") {
      *out_tf_datatype = TF_QUINT16;
    } else if (key == "qint32") {
      *out_tf_datatype = TF_QINT32;
    } else if (key == "resource") {
      *out_tf_datatype = TF_RESOURCE;
    } else {
      return errors::Internal("Unsupported numpy data type");
    }
    return Status::OK();
  }
  return errors::Internal("Unsupported numpy data type");
}


static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t length, uint16_t myflags, bool no_zeroes, Error **errp) { char name[NBD_MAX_NAME_SIZE + 1]; char buf[8 + 4 + 124] = ""; size_t len; int ret; /* Client sends: [20 .. xx] export name (length bytes) */ trace_nbd_negotiate_handle_export_name(); if (length >= sizeof(name)) { error_setg(errp, "Bad length received"); return -EINVAL; } if (nbd_read(client->ioc, name, length, errp) < 0) { error_prepend(errp, "read failed: "); return -EINVAL; } name[length] = '\0'; trace_nbd_negotiate_handle_export_name_request(name); client->exp = nbd_export_find(name); if (!client->exp) { error_setg(errp, "export not found"); return -EINVAL; } trace_nbd_negotiate_new_style_size_flags(client->exp->size, client->exp->nbdflags | myflags); stq_be_p(buf, client->exp->size); stw_be_p(buf + 8, client->exp->nbdflags | myflags); len = no_zeroes ? 10 : sizeof(buf); ret = nbd_write(client->ioc, buf, len, errp); if (ret < 0) { error_prepend(errp, "write failed: "); return ret; } QTAILQ_INSERT_TAIL(&client->exp->clients, client, next); nbd_export_get(client->exp); return 0; }


static void U_CALLCONV uprv_writeSwapUInt16 ( uint16_t * p , uint16_t x ) {
 * p = ( uint16_t ) ( ( x << 8 ) | ( x >> 8 ) ) ;
 }


static void idreg_class_init ( ObjectClass * klass , void * data ) {
 SysBusDeviceClass * k = SYS_BUS_DEVICE_CLASS ( klass ) ;
 k -> init = idreg_init1 ;
 }


static void pci_bridge_write_config(PCIDevice *d, uint32_t address, uint32_t val, int len) { PCIBridge *s = (PCIBridge *)d; if (address == 0x19 || (address == 0x18 && len > 1)) { if (address == 0x19) s->bus->bus_num = val & 0xff; else s->bus->bus_num = (val >> 8) & 0xff; #if defined(DEBUG_PCI) printf ("pci-bridge: %s: Assigned bus %d\n", d->name, s->bus->bus_num); #endif } pci_default_write_config(d, address, val, len); }


static krb5_boolean policy_exists ( const char * name ) {
 kadm5_policy_ent_rec pol ;
 if ( kadm5_get_policy ( handle , ( char * ) name , & pol ) != 0 ) return FALSE ;
 kadm5_free_policy_ent ( handle , & pol ) ;
 return TRUE ;
 }


void TSMatcherLineDestroy ( TSMatcherLine ml ) {
 sdk_assert ( sdk_sanity_check_null_ptr ( ( void * ) ml ) == TS_SUCCESS ) ;
 ats_free ( ml ) ;
 }


static int xio3130_upstream_initfn(PCIDevice *d) { PCIBridge* br = DO_UPCAST(PCIBridge, dev, d); PCIEPort *p = DO_UPCAST(PCIEPort, br, br); int rc; int tmp; rc = pci_bridge_initfn(d); if (rc < 0) { return rc; } pcie_port_init_reg(d); pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_TI); pci_config_set_device_id(d->config, PCI_DEVICE_ID_TI_XIO3130U); d->config[PCI_REVISION_ID] = XIO3130_REVISION; rc = msi_init(d, XIO3130_MSI_OFFSET, XIO3130_MSI_NR_VECTOR, XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT, XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT); if (rc < 0) { goto err_bridge; } rc = pci_bridge_ssvid_init(d, XIO3130_SSVID_OFFSET, XIO3130_SSVID_SVID, XIO3130_SSVID_SSID); if (rc < 0) { goto err_bridge; } rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_UPSTREAM, p->port); if (rc < 0) { goto err_msi; } pcie_cap_flr_init(d); pcie_cap_deverr_init(d); rc = pcie_aer_init(d, XIO3130_AER_OFFSET); if (rc < 0) { goto err; } return 0; err: pcie_cap_exit(d); err_msi: msi_uninit(d); err_bridge: tmp = pci_bridge_exitfn(d); assert(!tmp); return rc; }


TEST_F ( TemplateURLTest , ExtractSearchTermsFromNonUTF8URL ) {
 TemplateURLData data ;
 data . SetURL ( "http://windows-1251.ru/?q={
searchTerms}
" ) ;
 data . alternate_urls . push_back ( "http://windows-1251.ru/#q={
searchTerms}
" ) ;
 data . alternate_urls . push_back ( "http://windows-1251.ru/path/{
searchTerms}
" ) ;
 data . input_encodings . push_back ( "windows-1251" ) ;
 TemplateURL url ( data ) ;
 base : : string16 result ;
 EXPECT_TRUE ( url . ExtractSearchTermsFromURL ( GURL ( "http://windows-1251.ru/?q=%C7%E4%F0%E0%E2%F1%F2%E2%F3%E9%2C+" "%EC%E8%F0!" ) , search_terms_data_ , & result ) ) ;
 EXPECT_EQ ( base : : WideToUTF16 ( L"\x0417\x0434\x0440\x0430\x0432\x0441\x0442\x0432\x0443\x0439, " L"\x043C\x0438\x0440!" ) , result ) ;
 EXPECT_TRUE ( url . ExtractSearchTermsFromURL ( GURL ( "http://windows-1251.ru/#q=%E4%E2%E0+%F1%EB%EE%E2%E0" ) , search_terms_data_ , & result ) ) ;
 EXPECT_EQ ( base : : WideToUTF16 ( L"\x0434\x0432\x0430 \x0441\x043B\x043E\x0432\x0430" ) , result ) ;
 EXPECT_TRUE ( url . ExtractSearchTermsFromURL ( GURL ( "http://windows-1251.ru/path/%E1%F3%EA%E2%FB%20%C0%20%E8%20A" ) , search_terms_data_ , & result ) ) ;
 EXPECT_EQ ( base : : WideToUTF16 ( L"\x0431\x0443\x043A\x0432\x044B \x0410 \x0438 A" ) , result ) ;
 }


static int get_default_root(pool *p, int allow_symlinks, const char **root) {
  config_rec *c = NULL;
  const char *dir = NULL;
  int res;

  c = find_config(main_server->conf, CONF_PARAM, "DefaultRoot", FALSE);
  while (c != NULL) {
    pr_signals_handle();

    /* Check the groups acl */
    if (c->argc < 2) {
      dir = c->argv[0];
      break;
    }

    res = pr_expr_eval_group_and(((char **) c->argv)+1);
    if (res) {
      dir = c->argv[0];
      break;
    }

    c = find_config_next(c, c->next, CONF_PARAM, "DefaultRoot", FALSE);
  }

  if (dir != NULL) {
    const char *new_dir;

    /* Check for any expandable variables. */
    new_dir = path_subst_uservar(p, &dir);
    if (new_dir != NULL) {
      dir = new_dir;
    }

    if (strncmp(dir, "/", 2) == 0) {
      dir = NULL;

    } else {
      char *realdir;
      int xerrno = 0;

      if (allow_symlinks == FALSE) {
        char *path, target_path[PR_TUNABLE_PATH_MAX + 1];
        struct stat st;
        size_t pathlen;

        /* First, deal with any possible interpolation.  dir_realpath() will
         * do this for us, but dir_realpath() ALSO automatically follows
         * symlinks, which is what we do NOT want to do here.
         */

        path = pstrdup(p, dir);
        if (*path != '/') {
          if (*path == '~') {
            if (pr_fs_interpolate(dir, target_path,
                sizeof(target_path)-1) < 0) {
              return -1;
            }

            path = target_path;
          }
        }

        /* Note: lstat(2) is sensitive to the presence of a trailing slash on
         * the path, particularly in the case of a symlink to a directory.
         * Thus to get the correct test, we need to remove any trailing slash
         * that might be present.  Subtle.
         */
        pathlen = strlen(path);
        if (pathlen > 1 &&
            path[pathlen-1] == '/') {
          path[pathlen-1] = '\0';
        }

        pr_fs_clear_cache2(path);
        res = pr_fsio_lstat(path, &st);
        if (res < 0) {
          xerrno = errno;

          pr_log_pri(PR_LOG_WARNING, "error: unable to check %s: %s", path,
            strerror(xerrno));

          errno = xerrno;
          return -1;
        }

        if (S_ISLNK(st.st_mode)) {
          pr_log_pri(PR_LOG_WARNING,
            "error: DefaultRoot %s is a symlink (denied by AllowChrootSymlinks "
            "config)", path);
          errno = EPERM;
          return -1;
        }
      }

      /* We need to be the final user here so that if the user has their home
       * directory with a mode the user proftpd is running (i.e. the User
       * directive) as can not traverse down, we can still have the default
       * root.
       */

      pr_fs_clear_cache2(dir);

      PRIVS_USER
      realdir = dir_realpath(p, dir);
      xerrno = errno;
      PRIVS_RELINQUISH

      if (realdir) {
        dir = realdir;

      } else {
        /* Try to provide a more informative message. */
        char interp_dir[PR_TUNABLE_PATH_MAX + 1];

        memset(interp_dir, '\0', sizeof(interp_dir));
        (void) pr_fs_interpolate(dir, interp_dir, sizeof(interp_dir)-1);

        pr_log_pri(PR_LOG_NOTICE,
          "notice: unable to use DefaultRoot '%s' [resolved to '%s']: %s",
          dir, interp_dir, strerror(xerrno));

        errno = xerrno;
      }
    }
  }

  *root = dir;
  return 0;
}


static void mv88w8618_audio_write(void *opaque, target_phys_addr_t offset, uint64_t value, unsigned size) { mv88w8618_audio_state *s = opaque; switch (offset) { case MP_AUDIO_PLAYBACK_MODE: if (value & MP_AUDIO_PLAYBACK_EN && !(s->playback_mode & MP_AUDIO_PLAYBACK_EN)) { s->status = 0; s->last_free = 0; s->play_pos = 0; } s->playback_mode = value; mv88w8618_audio_clock_update(s); break; case MP_AUDIO_CLOCK_DIV: s->clock_div = value; s->last_free = 0; s->play_pos = 0; mv88w8618_audio_clock_update(s); break; case MP_AUDIO_IRQ_STATUS: s->status &= ~value; break; case MP_AUDIO_IRQ_ENABLE: s->irq_enable = value; if (s->status & s->irq_enable) { qemu_irq_raise(s->irq); } break; case MP_AUDIO_TX_START_LO: s->phys_buf = (s->phys_buf & 0xFFFF0000) | (value & 0xFFFF); s->target_buffer = s->phys_buf; s->play_pos = 0; s->last_free = 0; break; case MP_AUDIO_TX_THRESHOLD: s->threshold = (value + 1) * 4; break; case MP_AUDIO_TX_START_HI: s->phys_buf = (s->phys_buf & 0xFFFF) | (value << 16); s->target_buffer = s->phys_buf; s->play_pos = 0; s->last_free = 0; break; } }


static void ImportRGBOQuantum ( const Image * image , QuantumInfo * quantum_info , const MagickSizeType number_pixels , const unsigned char * magick_restrict p , Quantum * magick_restrict q , ExceptionInfo * exception ) {
 QuantumAny range ;
 register ssize_t x ;
 unsigned int pixel ;
 assert ( image != ( Image * ) NULL ) ;
 assert ( image -> signature == MagickCoreSignature ) ;
 switch ( quantum_info -> depth ) {
 case 8 : {
 unsigned char pixel ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushCharPixel ( p , & pixel ) ;
 SetPixelRed ( image , ScaleCharToQuantum ( pixel ) , q ) ;
 p = PushCharPixel ( p , & pixel ) ;
 SetPixelGreen ( image , ScaleCharToQuantum ( pixel ) , q ) ;
 p = PushCharPixel ( p , & pixel ) ;
 SetPixelBlue ( image , ScaleCharToQuantum ( pixel ) , q ) ;
 p = PushCharPixel ( p , & pixel ) ;
 SetPixelOpacity ( image , ScaleCharToQuantum ( pixel ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 10 : {
 pixel = 0 ;
 if ( quantum_info -> pack == MagickFalse ) {
 register ssize_t i ;
 size_t quantum ;
 ssize_t n ;
 n = 0 ;
 quantum = 0 ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 for ( i = 0 ;
 i < 4 ;
 i ++ ) {
 switch ( n % 3 ) {
 case 0 : {
 p = PushLongPixel ( quantum_info -> endian , p , & pixel ) ;
 quantum = ( size_t ) ( ScaleShortToQuantum ( ( unsigned short ) ( ( ( pixel >> 22 ) & 0x3ff ) << 6 ) ) ) ;
 break ;
 }
 case 1 : {
 quantum = ( size_t ) ( ScaleShortToQuantum ( ( unsigned short ) ( ( ( pixel >> 12 ) & 0x3ff ) << 6 ) ) ) ;
 break ;
 }
 case 2 : {
 quantum = ( size_t ) ( ScaleShortToQuantum ( ( unsigned short ) ( ( ( pixel >> 2 ) & 0x3ff ) << 6 ) ) ) ;
 break ;
 }
 }
 switch ( i ) {
 case 0 : SetPixelRed ( image , ( Quantum ) quantum , q ) ;
 break ;
 case 1 : SetPixelGreen ( image , ( Quantum ) quantum , q ) ;
 break ;
 case 2 : SetPixelBlue ( image , ( Quantum ) quantum , q ) ;
 break ;
 case 3 : SetPixelOpacity ( image , ( Quantum ) quantum , q ) ;
 break ;
 }
 n ++ ;
 }
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelRed ( image , ScaleShortToQuantum ( ( unsigned short ) ( pixel << 6 ) ) , q ) ;
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelGreen ( image , ScaleShortToQuantum ( ( unsigned short ) ( pixel << 6 ) ) , q ) ;
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelBlue ( image , ScaleShortToQuantum ( ( unsigned short ) ( pixel << 6 ) ) , q ) ;
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelOpacity ( image , ScaleShortToQuantum ( ( unsigned short ) ( pixel << 6 ) ) , q ) ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 16 : {
 unsigned short pixel ;
 if ( quantum_info -> format == FloatingPointQuantumFormat ) {
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelRed ( image , ClampToQuantum ( QuantumRange * HalfToSinglePrecision ( pixel ) ) , q ) ;
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelGreen ( image , ClampToQuantum ( QuantumRange * HalfToSinglePrecision ( pixel ) ) , q ) ;
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelBlue ( image , ClampToQuantum ( QuantumRange * HalfToSinglePrecision ( pixel ) ) , q ) ;
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelOpacity ( image , ClampToQuantum ( QuantumRange * HalfToSinglePrecision ( pixel ) ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelRed ( image , ScaleShortToQuantum ( pixel ) , q ) ;
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelGreen ( image , ScaleShortToQuantum ( pixel ) , q ) ;
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelBlue ( image , ScaleShortToQuantum ( pixel ) , q ) ;
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelOpacity ( image , ScaleShortToQuantum ( pixel ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 32 : {
 unsigned int pixel ;
 if ( quantum_info -> format == FloatingPointQuantumFormat ) {
 float pixel ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushFloatPixel ( quantum_info , p , & pixel ) ;
 SetPixelRed ( image , ClampToQuantum ( pixel ) , q ) ;
 p = PushFloatPixel ( quantum_info , p , & pixel ) ;
 SetPixelGreen ( image , ClampToQuantum ( pixel ) , q ) ;
 p = PushFloatPixel ( quantum_info , p , & pixel ) ;
 SetPixelBlue ( image , ClampToQuantum ( pixel ) , q ) ;
 p = PushFloatPixel ( quantum_info , p , & pixel ) ;
 SetPixelOpacity ( image , ClampToQuantum ( pixel ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushLongPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelRed ( image , ScaleLongToQuantum ( pixel ) , q ) ;
 p = PushLongPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelGreen ( image , ScaleLongToQuantum ( pixel ) , q ) ;
 p = PushLongPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelBlue ( image , ScaleLongToQuantum ( pixel ) , q ) ;
 p = PushLongPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelOpacity ( image , ScaleLongToQuantum ( pixel ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 64 : {
 if ( quantum_info -> format == FloatingPointQuantumFormat ) {
 double pixel ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushDoublePixel ( quantum_info , p , & pixel ) ;
 SetPixelRed ( image , ClampToQuantum ( pixel ) , q ) ;
 p = PushDoublePixel ( quantum_info , p , & pixel ) ;
 SetPixelGreen ( image , ClampToQuantum ( pixel ) , q ) ;
 p = PushDoublePixel ( quantum_info , p , & pixel ) ;
 SetPixelBlue ( image , ClampToQuantum ( pixel ) , q ) ;
 p = PushDoublePixel ( quantum_info , p , & pixel ) ;
 SetPixelOpacity ( image , ClampToQuantum ( pixel ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 }
 default : {
 range = GetQuantumRange ( quantum_info -> depth ) ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelRed ( image , ScaleAnyToQuantum ( pixel , range ) , q ) ;
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelGreen ( image , ScaleAnyToQuantum ( pixel , range ) , q ) ;
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelBlue ( image , ScaleAnyToQuantum ( pixel , range ) , q ) ;
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelOpacity ( image , ScaleAnyToQuantum ( pixel , range ) , q ) ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 }
 }


int test_sqr ( BIO * bp , BN_CTX * ctx ) {
 BIGNUM * a , * c , * d , * e ;
 int i , ret = 0 ;
 a = BN_new ( ) ;
 c = BN_new ( ) ;
 d = BN_new ( ) ;
 e = BN_new ( ) ;
 if ( a == NULL || c == NULL || d == NULL || e == NULL ) {
 goto err ;
 }
 for ( i = 0 ;
 i < num0 ;
 i ++ ) {
 BN_bntest_rand ( a , 40 + i * 10 , 0 , 0 ) ;
 a -> neg = rand_neg ( ) ;
 BN_sqr ( c , a , ctx ) ;
 if ( bp != NULL ) {
 if ( ! results ) {
 BN_print ( bp , a ) ;
 BIO_puts ( bp , " * " ) ;
 BN_print ( bp , a ) ;
 BIO_puts ( bp , " - " ) ;
 }
 BN_print ( bp , c ) ;
 BIO_puts ( bp , "\n" ) ;
 }
 BN_div ( d , e , c , a , ctx ) ;
 BN_sub ( d , d , a ) ;
 if ( ! BN_is_zero ( d ) || ! BN_is_zero ( e ) ) {
 fprintf ( stderr , "Square test failed!\n" ) ;
 goto err ;
 }
 }
 BN_hex2bn ( & a , "80000000000000008000000000000001FFFFFFFFFFFFFFFE0000000000000000" ) ;
 BN_sqr ( c , a , ctx ) ;
 if ( bp != NULL ) {
 if ( ! results ) {
 BN_print ( bp , a ) ;
 BIO_puts ( bp , " * " ) ;
 BN_print ( bp , a ) ;
 BIO_puts ( bp , " - " ) ;
 }
 BN_print ( bp , c ) ;
 BIO_puts ( bp , "\n" ) ;
 }
 BN_mul ( d , a , a , ctx ) ;
 if ( BN_cmp ( c , d ) ) {
 fprintf ( stderr , "Square test failed: BN_sqr and BN_mul produce " "different results!\n" ) ;
 goto err ;
 }
 BN_hex2bn ( & a , "80000000000000000000000080000001FFFFFFFE000000000000000000000000" ) ;
 BN_sqr ( c , a , ctx ) ;
 if ( bp != NULL ) {
 if ( ! results ) {
 BN_print ( bp , a ) ;
 BIO_puts ( bp , " * " ) ;
 BN_print ( bp , a ) ;
 BIO_puts ( bp , " - " ) ;
 }
 BN_print ( bp , c ) ;
 BIO_puts ( bp , "\n" ) ;
 }
 BN_mul ( d , a , a , ctx ) ;
 if ( BN_cmp ( c , d ) ) {
 fprintf ( stderr , "Square test failed: BN_sqr and BN_mul produce " "different results!\n" ) ;
 goto err ;
 }
 ret = 1 ;
 err : if ( a != NULL ) BN_free ( a ) ;
 if ( c != NULL ) BN_free ( c ) ;
 if ( d != NULL ) BN_free ( d ) ;
 if ( e != NULL ) BN_free ( e ) ;
 return ret ;
 }


void ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { ff_start_frame(link->dst->outputs[0], picref); }


static int match_principals_file ( struct ssh * ssh , struct passwd * pw , char * file , struct sshkey_cert * cert , struct sshauthopt * * authoptsp ) {
 FILE * f ;
 int success ;
 if ( authoptsp != NULL ) * authoptsp = NULL ;
 temporarily_use_uid ( pw ) ;
 debug ( "trying authorized principals file %s" , file ) ;
 if ( ( f = auth_openprincipals ( file , pw , options . strict_modes ) ) == NULL ) {
 restore_uid ( ) ;
 return 0 ;
 }
 success = process_principals ( ssh , f , file , cert , authoptsp ) ;
 fclose ( f ) ;
 restore_uid ( ) ;
 return success ;
 }


static inline bool is_ra ( hb_codepoint_t u ) {
 for ( unsigned int i = 0 ;
 i < ARRAY_LENGTH ( ra_chars ) ;
 i ++ ) if ( u == ra_chars [ i ] ) return true ;
 return false ;
 }


static void dissect_rsvp_unknown ( proto_tree * ti _U_ , proto_tree * rsvp_object_tree , tvbuff_t * tvb , int offset , int obj_length , int rsvp_class _U_ , int type ) {
 proto_tree_add_uint ( rsvp_object_tree , hf_rsvp_ctype , tvb , offset + 3 , 1 , type ) ;
 if ( obj_length > 4 ) {
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_unknown_data , tvb , offset + 4 , obj_length - 4 , ENC_NA ) ;
 }
 }


static struct message_data * find_matching_request_by_fid ( struct mswsp_ct * ct , packet_info * pinfo , guint32 msg , gboolean in , void * private_data ) {
 guint32 fid = 0 ;
 guint frame = 0 ;
 GSList * iter ;
 int * p_smb_level = ( int * ) p_get_proto_data ( wmem_file_scope ( ) , pinfo , proto_mswsp , 0 ) ;
 struct message_data * result = NULL ;
 get_fid_and_frame ( pinfo , & fid , & frame , private_data ) ;
 for ( iter = ct -> GSL_message_data ;
 iter ;
 iter = iter -> next ) {
 struct message_data * data = ( struct message_data * ) iter -> data ;
 if ( data -> frame < frame && data -> fid == fid && data -> is_request == in && data -> msg_id == msg && data -> smb_level == * p_smb_level ) {
 result = data ;
 break ;
 }
 }
 return result ;
 }


static void auth_delay ( struct parse * pcmd , FILE * fp ) {
 int isneg ;
 u_long val ;
 if ( pcmd -> nargs == 0 ) {
 val = delay_time . l_ui * 1000 + delay_time . l_uf / 4294967 ;
 ( void ) fprintf ( fp , "delay %lu ms\n" , val ) ;
 }
 else {
 if ( pcmd -> argval [ 0 ] . ival < 0 ) {
 isneg = 1 ;
 val = ( u_long ) ( - pcmd -> argval [ 0 ] . ival ) ;
 }
 else {
 isneg = 0 ;
 val = ( u_long ) pcmd -> argval [ 0 ] . ival ;
 }
 delay_time . l_ui = val / 1000 ;
 val %= 1000 ;
 delay_time . l_uf = val * 4294967 ;
 if ( isneg ) L_NEG ( & delay_time ) ;
 }
 }


static int aacPlus_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) { aacPlusAudioContext *s = avctx->priv_data; int32_t *input_buffer = (int32_t *)frame->data[0]; int ret; if ((ret = ff_alloc_packet2(avctx, pkt, s->max_output_bytes))) return ret; pkt->size = aacplusEncEncode(s->aacplus_handle, input_buffer, s->samples_input, pkt->data, pkt->size); *got_packet = 1; pkt->pts = frame->pts; return 0; }


static uint32_t pci_apb_ioreadb (void *opaque, target_phys_addr_t addr) { uint32_t val; val = cpu_inb(addr & IOPORTS_MASK); return val; }


TSReturnCode TSMgmtStringCreate ( TSRecordType rec_type , const char * name , const TSMgmtString data_default , TSRecordUpdateType update_type , TSRecordCheckType check_type , const char * check_regex , TSRecordAccessType access_type ) {
 if ( check_regex == nullptr && check_type != TS_RECORDCHECK_NULL ) {
 return TS_ERROR ;
 }
 if ( REC_ERR_OKAY != RecRegisterConfigString ( ( enum RecT ) rec_type , name , data_default , ( enum RecUpdateT ) update_type , ( enum RecCheckT ) check_type , check_regex , REC_SOURCE_PLUGIN , ( enum RecAccessT ) access_type ) ) {
 return TS_ERROR ;
 }
 return TS_SUCCESS ;
 }


void TSMimeParserClear ( TSMimeParser parser ) {
 sdk_assert ( sdk_sanity_check_mime_parser ( parser ) == TS_SUCCESS ) ;
 mime_parser_clear ( ( MIMEParser * ) parser ) ;
 }


static void v7m_push_stack(ARMCPU *cpu) { /* Do the "set up stack frame" part of exception entry, * similar to pseudocode PushStack(). */ CPUARMState *env = &cpu->env; uint32_t xpsr = xpsr_read(env); /* Align stack pointer if the guest wants that */ if ((env->regs[13] & 4) && (env->v7m.ccr & R_V7M_CCR_STKALIGN_MASK)) { env->regs[13] -= 4; xpsr |= XPSR_SPREALIGN; } /* Switch to the handler mode. */ v7m_push(env, xpsr); v7m_push(env, env->regs[15]); v7m_push(env, env->regs[14]); v7m_push(env, env->regs[12]); v7m_push(env, env->regs[3]); v7m_push(env, env->regs[2]); v7m_push(env, env->regs[1]); v7m_push(env, env->regs[0]); }


static void piix4_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { PIIX4PMState *s = PIIX4_PM(hotplug_dev); if (s->acpi_memory_hotplug.is_enabled && object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) { nvdimm_acpi_plug_cb(hotplug_dev, dev); } else { acpi_memory_plug_cb(hotplug_dev, &s->acpi_memory_hotplug, dev, errp); } } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { if (!xen_enabled()) { acpi_pcihp_device_plug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev, errp); } } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { if (s->cpu_hotplug_legacy) { legacy_acpi_cpu_plug_cb(hotplug_dev, &s->gpe_cpu, dev, errp); } else { acpi_cpu_plug_cb(hotplug_dev, &s->cpuhp_state, dev, errp); } } else { error_setg(errp, "acpi: device plug request for not supported device" " type: %s", object_get_typename(OBJECT(dev))); } }


void rgb15tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size) { const uint16_t *end; uint8_t *d = (uint8_t *)dst; const uint16_t *s = (uint16_t *)src; end = s + src_size/2; while(s < end) { register uint16_t bgr; bgr = *s++; *d++ = (bgr&0x7C00)>>7; *d++ = (bgr&0x3E0)>>2; *d++ = (bgr&0x1F)<<3; } }


static void acl_insert_user ( const char * user , const char * host , const char * password , uint password_len , enum SSL_type ssl_type , const char * ssl_cipher , const char * x509_issuer , const char * x509_subject , USER_RESOURCES * mqh , ulong privileges ) {
 ACL_USER acl_user ;
 safe_mutex_assert_owner ( & acl_cache -> lock ) ;
 acl_user . user = * user ? strdup_root ( & mem , user ) : 0 ;
 update_hostname ( & acl_user . host , * host ? strdup_root ( & mem , host ) : 0 ) ;
 acl_user . access = privileges ;
 acl_user . user_resource = * mqh ;
 acl_user . sort = get_sort ( 2 , acl_user . host . hostname , acl_user . user ) ;
 acl_user . hostname_length = ( uint ) strlen ( host ) ;
 acl_user . ssl_type = ( ssl_type != SSL_TYPE_NOT_SPECIFIED ? ssl_type : SSL_TYPE_NONE ) ;
 acl_user . ssl_cipher = ssl_cipher ? strdup_root ( & mem , ssl_cipher ) : 0 ;
 acl_user . x509_issuer = x509_issuer ? strdup_root ( & mem , x509_issuer ) : 0 ;
 acl_user . x509_subject = x509_subject ? strdup_root ( & mem , x509_subject ) : 0 ;
 set_user_salt ( & acl_user , password , password_len ) ;
 VOID ( push_dynamic ( & acl_users , ( uchar * ) & acl_user ) ) ;
 if ( ! acl_user . host . hostname || ( acl_user . host . hostname [ 0 ] == wild_many && ! acl_user . host . hostname [ 1 ] ) ) allow_all_hosts = 1 ;
 my_qsort ( ( uchar * ) dynamic_element ( & acl_users , 0 , ACL_USER * ) , acl_users . elements , sizeof ( ACL_USER ) , ( qsort_cmp ) acl_compare ) ;
 rebuild_check_host ( ) ;
 }


static int nbd_send_negotiate(NBDClient *client) { int csock = client->sock; char buf[8 + 8 + 8 + 128]; int rc; const int myflags = (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA); /* Negotiation header without options: [ 0 .. 7] passwd ("NBDMAGIC") [ 8 .. 15] magic (NBD_CLIENT_MAGIC) [16 .. 23] size [24 .. 25] server flags (0) [24 .. 27] export flags [28 .. 151] reserved (0) Negotiation header with options, part 1: [ 0 .. 7] passwd ("NBDMAGIC") [ 8 .. 15] magic (NBD_OPTS_MAGIC) [16 .. 17] server flags (0) part 2 (after options are sent): [18 .. 25] size [26 .. 27] export flags [28 .. 151] reserved (0) */ socket_set_block(csock); rc = -EINVAL; TRACE("Beginning negotiation."); memcpy(buf, "NBDMAGIC", 8); if (client->exp) { assert ((client->exp->nbdflags & ~65535) == 0); cpu_to_be64w((uint64_t*)(buf + 8), NBD_CLIENT_MAGIC); cpu_to_be64w((uint64_t*)(buf + 16), client->exp->size); cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags); } else { cpu_to_be64w((uint64_t*)(buf + 8), NBD_OPTS_MAGIC); } memset(buf + 28, 0, 124); if (client->exp) { if (write_sync(csock, buf, sizeof(buf)) != sizeof(buf)) { LOG("write failed"); goto fail; } } else { if (write_sync(csock, buf, 18) != 18) { LOG("write failed"); goto fail; } rc = nbd_receive_options(client); if (rc < 0) { LOG("option negotiation failed"); goto fail; } assert ((client->exp->nbdflags & ~65535) == 0); cpu_to_be64w((uint64_t*)(buf + 18), client->exp->size); cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags); if (write_sync(csock, buf + 18, sizeof(buf) - 18) != sizeof(buf) - 18) { LOG("write failed"); goto fail; } } TRACE("Negotiation succeeded."); rc = 0; fail: socket_set_nonblock(csock); return rc; }


static int get_rx_bufs(struct vhost_virtqueue *vq,
		       struct vring_used_elem *heads,
		       int datalen,
		       unsigned *iovcount,
		       struct vhost_log *log,
		       unsigned *log_num,
		       unsigned int quota)
{
	unsigned int out, in;
	int seg = 0;
	int headcount = 0;
	unsigned d;
	int r, nlogs = 0;

	while (datalen > 0 && headcount < quota) {
		if (unlikely(seg >= UIO_MAXIOV)) {
			r = -ENOBUFS;
			goto err;
		}
		d = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg,
				      ARRAY_SIZE(vq->iov) - seg, &out,
				      &in, log, log_num);
		if (d == vq->num) {
			r = 0;
			goto err;
		}
		if (unlikely(out || in <= 0)) {
			vq_err(vq, "unexpected descriptor format for RX: "
				"out %d, in %d\n", out, in);
			r = -EINVAL;
			goto err;
		}
		if (unlikely(log)) {
			nlogs += *log_num;
			log += *log_num;
		}
		heads[headcount].id = d;
		heads[headcount].len = iov_length(vq->iov + seg, in);
		datalen -= heads[headcount].len;
		++headcount;
		seg += in;
	}
	heads[headcount - 1].len += datalen;
	*iovcount = seg;
	if (unlikely(log))
		*log_num = nlogs;
	return headcount;
err:
	vhost_discard_vq_desc(vq, headcount);
	return r;
}


static int archive_read_format_cpio_skip ( struct archive_read * a ) {
 struct cpio * cpio = ( struct cpio * ) ( a -> format -> data ) ;
 int64_t to_skip = cpio -> entry_bytes_remaining + cpio -> entry_padding + cpio -> entry_bytes_unconsumed ;
 if ( to_skip != __archive_read_consume ( a , to_skip ) ) {
 return ( ARCHIVE_FATAL ) ;
 }
 cpio -> entry_bytes_remaining = 0 ;
 cpio -> entry_padding = 0 ;
 cpio -> entry_bytes_unconsumed = 0 ;
 return ( ARCHIVE_OK ) ;
 }


static void ImportIndexQuantum ( const Image * image , QuantumInfo * quantum_info , const MagickSizeType number_pixels , const unsigned char * magick_restrict p , Quantum * magick_restrict q , ExceptionInfo * exception ) {
 MagickBooleanType range_exception ;
 register ssize_t x ;
 ssize_t bit ;
 unsigned int pixel ;
 if ( image -> storage_class != PseudoClass ) {
 ( void ) ThrowMagickException ( exception , GetMagickModule ( ) , ImageError , "ColormappedImageRequired" , "`%s'" , image -> filename ) ;
 return ;
 }
 range_exception = MagickFalse ;
 switch ( quantum_info -> depth ) {
 case 1 : {
 register unsigned char pixel ;
 for ( x = 0 ;
 x < ( ( ssize_t ) number_pixels - 7 ) ;
 x += 8 ) {
 for ( bit = 0 ;
 bit < 8 ;
 bit ++ ) {
 if ( quantum_info -> min_is_white == MagickFalse ) pixel = ( unsigned char ) ( ( ( * p ) & ( 1 << ( 7 - bit ) ) ) == 0 ? 0x00 : 0x01 ) ;
 else pixel = ( unsigned char ) ( ( ( * p ) & ( 1 << ( 7 - bit ) ) ) != 0 ? 0x00 : 0x01 ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 q += GetPixelChannels ( image ) ;
 }
 p ++ ;
 }
 for ( bit = 0 ;
 bit < ( ssize_t ) ( number_pixels % 8 ) ;
 bit ++ ) {
 if ( quantum_info -> min_is_white == MagickFalse ) pixel = ( unsigned char ) ( ( ( * p ) & ( 1 << ( 7 - bit ) ) ) == 0 ? 0x00 : 0x01 ) ;
 else pixel = ( unsigned char ) ( ( ( * p ) & ( 1 << ( 7 - bit ) ) ) != 0 ? 0x00 : 0x01 ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 4 : {
 register unsigned char pixel ;
 for ( x = 0 ;
 x < ( ( ssize_t ) number_pixels - 1 ) ;
 x += 2 ) {
 pixel = ( unsigned char ) ( ( * p >> 4 ) & 0xf ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 q += GetPixelChannels ( image ) ;
 pixel = ( unsigned char ) ( ( * p ) & 0xf ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p ++ ;
 q += GetPixelChannels ( image ) ;
 }
 for ( bit = 0 ;
 bit < ( ssize_t ) ( number_pixels % 2 ) ;
 bit ++ ) {
 pixel = ( unsigned char ) ( ( * p ++ >> 4 ) & 0xf ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 8 : {
 unsigned char pixel ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushCharPixel ( p , & pixel ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 16 : {
 unsigned short pixel ;
 if ( quantum_info -> format == FloatingPointQuantumFormat ) {
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , ClampToQuantum ( ( double ) QuantumRange * HalfToSinglePrecision ( pixel ) ) , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushShortPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 32 : {
 unsigned int pixel ;
 if ( quantum_info -> format == FloatingPointQuantumFormat ) {
 float pixel ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushFloatPixel ( quantum_info , p , & pixel ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , ClampToQuantum ( pixel ) , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushLongPixel ( quantum_info -> endian , p , & pixel ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 case 64 : {
 if ( quantum_info -> format == FloatingPointQuantumFormat ) {
 double pixel ;
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushDoublePixel ( quantum_info , p , & pixel ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , ClampToQuantum ( pixel ) , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 }
 default : {
 for ( x = 0 ;
 x < ( ssize_t ) number_pixels ;
 x ++ ) {
 p = PushQuantumPixel ( quantum_info , p , & pixel ) ;
 SetPixelIndex ( image , PushColormapIndex ( image , pixel , & range_exception ) , q ) ;
 SetPixelViaPixelInfo ( image , image -> colormap + ( ssize_t ) GetPixelIndex ( image , q ) , q ) ;
 p += quantum_info -> pad ;
 q += GetPixelChannels ( image ) ;
 }
 break ;
 }
 }
 if ( range_exception != MagickFalse ) ( void ) ThrowMagickException ( exception , GetMagickModule ( ) , CorruptImageError , "InvalidColormapIndex" , "`%s'" , image -> filename ) ;
 }


static void visit_type_int32(Visitor *v, int *value, const char *name, Error **errp) { int64_t val = *value; visit_type_int(v, &val, name, errp); }


kadm5_ret_t kadm5_delete_policy ( void * server_handle , kadm5_policy_t name ) {
 kadm5_server_handle_t handle = server_handle ;
 osa_policy_ent_t entry ;
 int ret ;
 CHECK_HANDLE ( server_handle ) ;
 krb5_clear_error_message ( handle -> context ) ;
 if ( name == ( kadm5_policy_t ) NULL ) return EINVAL ;
 if ( strlen ( name ) == 0 ) return KADM5_BAD_POLICY ;
 ret = krb5_db_get_policy ( handle -> context , name , & entry ) ;
 if ( ret == KRB5_KDB_NOENTRY ) return KADM5_UNK_POLICY ;
 else if ( ret ) return ret ;
 krb5_db_free_policy ( handle -> context , entry ) ;
 ret = krb5_db_delete_policy ( handle -> context , name ) ;
 if ( ret == KRB5_KDB_POLICY_REF ) ret = KADM5_POLICY_REF ;
 return ( ret == 0 ) ? KADM5_OK : ret ;
 }


MigrationIncomingState *migration_incoming_state_new(QEMUFile* f) { mis_current = g_malloc0(sizeof(MigrationIncomingState)); mis_current->file = f; QLIST_INIT(&mis_current->loadvm_handlers); return mis_current; }


static int32_t u_scanf_octal_handler ( UFILE * input , u_scanf_spec_info * info , ufmt_args * args , const UChar * fmt , int32_t * fmtConsumed , int32_t * argConverted ) {
 ( void ) fmt ;
 ( void ) fmtConsumed ;
 int32_t len ;
 int32_t skipped ;
 void * num = ( void * ) ( args [ 0 ] . ptrValue ) ;
 int64_t result ;
 skipped = u_scanf_skip_leading_ws ( input , info -> fPadChar ) ;
 ufile_fill_uchar_buffer ( input ) ;
 len = ( int32_t ) ( input -> str . fLimit - input -> str . fPos ) ;
 if ( info -> fWidth != - 1 ) len = ufmt_min ( len , info -> fWidth ) ;
 result = ufmt_uto64 ( input -> str . fPos , & len , 8 ) ;
 input -> str . fPos += len ;
 if ( ! info -> fSkipArg ) {
 if ( info -> fIsShort ) * ( int16_t * ) num = ( int16_t ) ( UINT16_MAX & result ) ;
 else if ( info -> fIsLongLong ) * ( int64_t * ) num = result ;
 else * ( int32_t * ) num = ( int32_t ) ( UINT32_MAX & result ) ;
 }
 * argConverted = ! info -> fSkipArg ;
 return len + skipped ;
 }


static void free_pred_buffer ( PRED_BUFFER * p ) {
 if ( p != NULL ) p -> in_use = 0 ;
 }


static int calculate_geometry(int64_t total_sectors, uint16_t* cyls, uint8_t* heads, uint8_t* secs_per_cyl) { uint32_t cyls_times_heads; if (total_sectors > 65535 * 16 * 255) return -EFBIG; if (total_sectors > 65535 * 16 * 63) { *secs_per_cyl = 255; *heads = 16; cyls_times_heads = total_sectors / *secs_per_cyl; } else { *secs_per_cyl = 17; cyls_times_heads = total_sectors / *secs_per_cyl; *heads = (cyls_times_heads + 1023) / 1024; if (*heads < 4) *heads = 4; if (cyls_times_heads >= (*heads * 1024) || *heads > 16) { *secs_per_cyl = 31; *heads = 16; cyls_times_heads = total_sectors / *secs_per_cyl; } if (cyls_times_heads >= (*heads * 1024)) { *secs_per_cyl = 63; *heads = 16; cyls_times_heads = total_sectors / *secs_per_cyl; } } *cyls = cyls_times_heads / *heads; return 0; }


TEST_CASE("Semantic values test", "[general]")
{
    parser parser(R"(
        term <- ( a b c x )? a b c
        a <- 'a'
        b <- 'b'
        c <- 'c'
        x <- 'x'
    )");

	for (const auto& rule: parser.get_rule_names()){
		parser[rule.c_str()] = [rule](const SemanticValues& sv, any&) {
            if (rule == "term") {
                REQUIRE(any_cast<std::string>(sv[0]) == "a at 0");
                REQUIRE(any_cast<std::string>(sv[1]) == "b at 1");
                REQUIRE(any_cast<std::string>(sv[2]) == "c at 2");
                return std::string();
            } else {
                return rule + " at " + std::to_string(sv.c_str() - sv.ss);
            }
		};
	}

	REQUIRE(parser.parse("abc"));
}


static inline void t_gen_swapb(TCGv d, TCGv s) { TCGv t, org_s; t = tcg_temp_new(TCG_TYPE_TL); org_s = tcg_temp_new(TCG_TYPE_TL); /* d and s may refer to the same object. */ tcg_gen_mov_tl(org_s, s); tcg_gen_shli_tl(t, org_s, 8); tcg_gen_andi_tl(d, t, 0xff00ff00); tcg_gen_shri_tl(t, org_s, 8); tcg_gen_andi_tl(t, t, 0x00ff00ff); tcg_gen_or_tl(d, d, t); tcg_temp_free(t); tcg_temp_free(org_s); }


TEST_CASE("Lambda action test", "[general]")
{
    parser parser(R"(
       START <- (CHAR)*
       CHAR  <- .
    )");

    std::string ss;
    parser["CHAR"] = [&](const SemanticValues& sv) {
        ss += *sv.c_str();
    };

    bool ret = parser.parse("hello");
    REQUIRE(ret == true);
    REQUIRE(ss == "hello");
}


static int asink_query_formats(AVFilterContext *ctx) { BufferSinkContext *buf = ctx->priv; AVFilterFormats *formats = NULL; AVFilterChannelLayouts *layouts = NULL; unsigned i; int ret; CHECK_LIST_SIZE(sample_fmts) CHECK_LIST_SIZE(sample_rates) CHECK_LIST_SIZE(channel_layouts) CHECK_LIST_SIZE(channel_counts) if (buf->sample_fmts_size) { for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++) if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0) return ret; ff_set_common_formats(ctx, formats); } if (buf->channel_layouts_size || buf->channel_counts_size || buf->all_channel_counts) { for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++) if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) return ret; for (i = 0; i < NB_ITEMS(buf->channel_counts); i++) if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0) return ret; if (buf->all_channel_counts) { if (layouts) av_log(ctx, AV_LOG_WARNING, "Conflicting all_channel_counts and list in options\n"); else if (!(layouts = ff_all_channel_counts())) return AVERROR(ENOMEM); } ff_set_common_channel_layouts(ctx, layouts); } if (buf->sample_rates_size) { formats = NULL; for (i = 0; i < NB_ITEMS(buf->sample_rates); i++) if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0) return ret; ff_set_common_samplerates(ctx, formats); } return 0; }


TEST_CASE("Simple syntax test (with unicode)", "[general]")
{
    parser parser(
        u8" ROOT ← _ "
        " _ <- ' ' "
    );

    bool ret = parser;
    REQUIRE(ret == true);
}


static void set_partial_b64x64_partition ( MODE_INFO * mi , int mis , int bh_in , int bw_in , int row8x8_remaining , int col8x8_remaining , BLOCK_SIZE bsize , MODE_INFO * mi_8x8 ) {
 int bh = bh_in ;
 int r , c ;
 for ( r = 0 ;
 r < MI_BLOCK_SIZE ;
 r += bh ) {
 int bw = bw_in ;
 for ( c = 0 ;
 c < MI_BLOCK_SIZE ;
 c += bw ) {
 const int index = r * mis + c ;
 mi_8x8 [ index ] . src_mi = mi + index ;
 mi_8x8 [ index ] . src_mi -> mbmi . sb_type = find_partition_size ( bsize , row8x8_remaining - r , col8x8_remaining - c , & bh , & bw ) ;
 }
 }
 }


static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
{
	struct bnep_connlist_req cl;
	struct bnep_connadd_req  ca;
	struct bnep_conndel_req  cd;
	struct bnep_conninfo ci;
	struct socket *nsock;
	void __user *argp = (void __user *)arg;
	int err;

	BT_DBG("cmd %x arg %lx", cmd, arg);

	switch (cmd) {
	case BNEPCONNADD:
		if (!capable(CAP_NET_ADMIN))
			return -EACCES;

		if (copy_from_user(&ca, argp, sizeof(ca)))
			return -EFAULT;

		nsock = sockfd_lookup(ca.sock, &err);
		if (!nsock)
			return err;

		if (nsock->sk->sk_state != BT_CONNECTED) {
			sockfd_put(nsock);
			return -EBADFD;
		}

		err = bnep_add_connection(&ca, nsock);
		if (!err) {
			if (copy_to_user(argp, &ca, sizeof(ca)))
				err = -EFAULT;
		} else
			sockfd_put(nsock);

		return err;

	case BNEPCONNDEL:
		if (!capable(CAP_NET_ADMIN))
			return -EACCES;

		if (copy_from_user(&cd, argp, sizeof(cd)))
			return -EFAULT;

		return bnep_del_connection(&cd);

	case BNEPGETCONNLIST:
		if (copy_from_user(&cl, argp, sizeof(cl)))
			return -EFAULT;

		if (cl.cnum <= 0)
			return -EINVAL;

		err = bnep_get_connlist(&cl);
		if (!err && copy_to_user(argp, &cl, sizeof(cl)))
			return -EFAULT;

		return err;

	case BNEPGETCONNINFO:
		if (copy_from_user(&ci, argp, sizeof(ci)))
			return -EFAULT;

		err = bnep_get_conninfo(&ci);
		if (!err && copy_to_user(argp, &ci, sizeof(ci)))
			return -EFAULT;

		return err;

	default:
		return -EINVAL;
	}

	return 0;
}


name_len(netdissect_options *ndo,
         const unsigned char *s, const unsigned char *maxbuf)
{
    const unsigned char *s0 = s;
    unsigned char c;

    if (s >= maxbuf)
	return(-1);	/* name goes past the end of the buffer */
    ND_TCHECK2(*s, 1);
    c = *s;
    if ((c & 0xC0) == 0xC0)
	return(2);
    while (*s) {
	if (s >= maxbuf)
	    return(-1);	/* name goes past the end of the buffer */
	ND_TCHECK2(*s, 1);
	s += (*s) + 1;
    }
    return(PTR_DIFF(s, s0) + 1);

trunc:
    return(-1);	/* name goes past the end of the buffer */
}


static void xen_platform_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, unsigned int size) { PCIXenPlatformState *s = opaque; PCIDevice *pci_dev = PCI_DEVICE(s); switch (addr) { case 0: /* Platform flags */ platform_fixed_ioport_writeb(opaque, 0, (uint32_t)val); break; case 4: if (val == 1) { /* * SUSE unplug for Xenlinux * xen-kmp used this since xen-3.0.4, instead the official protocol * from xen-3.3+ It did an unconditional "outl(1, (ioaddr + 4));" * Pre VMDP 1.7 used 4 and 8 depending on how VMDP was configured. * If VMDP was to control both disk and LAN it would use 4. * If it controlled just disk or just LAN, it would use 8 below. */ pci_unplug_disks(pci_dev->bus); pci_unplug_nics(pci_dev->bus); } break; case 8: switch (val) { case 1: pci_unplug_disks(pci_dev->bus); break; case 2: pci_unplug_nics(pci_dev->bus); break; default: log_writeb(s, (uint32_t)val); break; } break; default: break; } }


static uint dump_events_for_db ( char * db ) {
 char query_buff [ QUERY_LENGTH ] ;
 char db_name_buff [ NAME_LEN * 2 + 3 ] , name_buff [ NAME_LEN * 2 + 3 ] ;
 char * event_name ;
 char delimiter [ QUERY_LENGTH ] ;
 FILE * sql_file = md_result_file ;
 MYSQL_RES * event_res , * event_list_res ;
 MYSQL_ROW row , event_list_row ;
 char db_cl_name [ MY_CS_NAME_SIZE ] ;
 int db_cl_altered = FALSE ;
 DBUG_ENTER ( "dump_events_for_db" ) ;
 DBUG_PRINT ( "enter" , ( "db: '%s'" , db ) ) ;
 mysql_real_escape_string ( mysql , db_name_buff , db , ( ulong ) strlen ( db ) ) ;
 print_comment ( sql_file , 0 , "\n--\n-- Dumping events for database '%s'\n--\n" , fix_for_comment ( db ) ) ;
 if ( lock_tables ) mysql_query ( mysql , "LOCK TABLES mysql.event READ" ) ;
 if ( mysql_query_with_error_report ( mysql , & event_list_res , "show events" ) ) DBUG_RETURN ( 0 ) ;
 strcpy ( delimiter , ";
" ) ;
 if ( mysql_num_rows ( event_list_res ) > 0 ) {
 if ( opt_xml ) fputs ( "\t<events>\n" , sql_file ) ;
 else {
 fprintf ( sql_file , "/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;
\n" ) ;
 if ( fetch_db_collation ( db_name_buff , db_cl_name , sizeof ( db_cl_name ) ) ) DBUG_RETURN ( 1 ) ;
 }
 if ( switch_character_set_results ( mysql , "binary" ) ) DBUG_RETURN ( 1 ) ;
 while ( ( event_list_row = mysql_fetch_row ( event_list_res ) ) != NULL ) {
 event_name = quote_name ( event_list_row [ 1 ] , name_buff , 0 ) ;
 DBUG_PRINT ( "info" , ( "retrieving CREATE EVENT for %s" , name_buff ) ) ;
 my_snprintf ( query_buff , sizeof ( query_buff ) , "SHOW CREATE EVENT %s" , event_name ) ;
 if ( mysql_query_with_error_report ( mysql , & event_res , query_buff ) ) DBUG_RETURN ( 1 ) ;
 while ( ( row = mysql_fetch_row ( event_res ) ) != NULL ) {
 if ( opt_xml ) {
 print_xml_row ( sql_file , "event" , event_res , & row , "Create Event" ) ;
 continue ;
 }
 if ( strlen ( row [ 3 ] ) != 0 ) {
 char * query_str ;
 if ( opt_drop ) fprintf ( sql_file , "/*!50106 DROP EVENT IF EXISTS %s */%s\n" , event_name , delimiter ) ;
 if ( create_delimiter ( row [ 3 ] , delimiter , sizeof ( delimiter ) ) == NULL ) {
 fprintf ( stderr , "%s: Warning: Can't create delimiter for event '%s'\n" , my_progname_short , event_name ) ;
 DBUG_RETURN ( 1 ) ;
 }
 fprintf ( sql_file , "DELIMITER %s\n" , delimiter ) ;
 if ( mysql_num_fields ( event_res ) >= 7 ) {
 if ( switch_db_collation ( sql_file , db_name_buff , delimiter , db_cl_name , row [ 6 ] , & db_cl_altered ) ) {
 DBUG_RETURN ( 1 ) ;
 }
 switch_cs_variables ( sql_file , delimiter , row [ 4 ] , row [ 4 ] , row [ 5 ] ) ;
 }
 else {
 fprintf ( sql_file , "--\n" "-- WARNING: old server version. " "The following dump may be incomplete.\n" "--\n" ) ;
 }
 switch_sql_mode ( sql_file , delimiter , row [ 1 ] ) ;
 switch_time_zone ( sql_file , delimiter , row [ 2 ] ) ;
 query_str = cover_definer_clause ( row [ 3 ] , strlen ( row [ 3 ] ) , C_STRING_WITH_LEN ( "50117" ) , C_STRING_WITH_LEN ( "50106" ) , C_STRING_WITH_LEN ( " EVENT" ) ) ;
 fprintf ( sql_file , "/*!50106 %s */ %s\n" , ( const char * ) ( query_str != NULL ? query_str : row [ 3 ] ) , ( const char * ) delimiter ) ;
 my_free ( query_str ) ;
 restore_time_zone ( sql_file , delimiter ) ;
 restore_sql_mode ( sql_file , delimiter ) ;
 if ( mysql_num_fields ( event_res ) >= 7 ) {
 restore_cs_variables ( sql_file , delimiter ) ;
 if ( db_cl_altered ) {
 if ( restore_db_collation ( sql_file , db_name_buff , delimiter , db_cl_name ) ) DBUG_RETURN ( 1 ) ;
 }
 }
 }
 }
 mysql_free_result ( event_res ) ;
 }
 if ( opt_xml ) {
 fputs ( "\t</events>\n" , sql_file ) ;
 check_io ( sql_file ) ;
 }
 else {
 fprintf ( sql_file , "DELIMITER ;
\n" ) ;
 fprintf ( sql_file , "/*!50106 SET TIME_ZONE= @save_time_zone */ ;
\n" ) ;
 }
 if ( switch_character_set_results ( mysql , default_charset ) ) DBUG_RETURN ( 1 ) ;
 }
 mysql_free_result ( event_list_res ) ;
 if ( lock_tables ) ( void ) mysql_query_with_error_report ( mysql , 0 , "UNLOCK TABLES" ) ;
 DBUG_RETURN ( 0 ) ;
 }


QEMUFile *qemu_popen_cmd(const char *command, const char *mode) { FILE *stdio_file; QEMUFileStdio *s; stdio_file = popen(command, mode); if (stdio_file == NULL) { return NULL; } if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 0) { fprintf(stderr, "qemu_popen: Argument validity check failed\n"); return NULL; } s = g_malloc0(sizeof(QEMUFileStdio)); s->stdio_file = stdio_file; if(mode[0] == 'r') { s->file = qemu_fopen_ops(s, &stdio_pipe_read_ops); } else { s->file = qemu_fopen_ops(s, &stdio_pipe_write_ops); } return s->file; }