static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn) { int32_t disp21, disp16, disp12 __attribute__((unused)); uint16_t fn11; uint8_t opc, ra, rb, rc, fpfn, fn7, lit; bool islit, real_islit; TCGv va, vb, vc, tmp, tmp2; TCGv_i32 t32; DisasJumpType ret; /* Decode all instruction fields */ opc = extract32(insn, 26, 6); ra = extract32(insn, 21, 5); rb = extract32(insn, 16, 5); rc = extract32(insn, 0, 5); real_islit = islit = extract32(insn, 12, 1); lit = extract32(insn, 13, 8); disp21 = sextract32(insn, 0, 21); disp16 = sextract32(insn, 0, 16); disp12 = sextract32(insn, 0, 12); fn11 = extract32(insn, 5, 11); fpfn = extract32(insn, 5, 6); fn7 = extract32(insn, 5, 7); if (rb == 31 && !islit) { islit = true; lit = 0; } ret = DISAS_NEXT; switch (opc) { case 0x00: /* CALL_PAL */ ret = gen_call_pal(ctx, insn & 0x03ffffff); break; case 0x01: /* OPC01 */ goto invalid_opc; case 0x02: /* OPC02 */ goto invalid_opc; case 0x03: /* OPC03 */ goto invalid_opc; case 0x04: /* OPC04 */ goto invalid_opc; case 0x05: /* OPC05 */ goto invalid_opc; case 0x06: /* OPC06 */ goto invalid_opc; case 0x07: /* OPC07 */ goto invalid_opc; case 0x09: /* LDAH */ disp16 = (uint32_t)disp16 << 16; /* fall through */ case 0x08: /* LDA */ va = dest_gpr(ctx, ra); /* It's worth special-casing immediate loads. */ if (rb == 31) { tcg_gen_movi_i64(va, disp16); } else { tcg_gen_addi_i64(va, load_gpr(ctx, rb), disp16); } break; case 0x0A: /* LDBU */ REQUIRE_AMASK(BWX); gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0); break; case 0x0B: /* LDQ_U */ gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1); break; case 0x0C: /* LDWU */ REQUIRE_AMASK(BWX); gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0); break; case 0x0D: /* STW */ REQUIRE_AMASK(BWX); gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0); break; case 0x0E: /* STB */ REQUIRE_AMASK(BWX); gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0); break; case 0x0F: /* STQ_U */ gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1); break; case 0x10: vc = dest_gpr(ctx, rc); vb = load_gpr_lit(ctx, rb, lit, islit); if (ra == 31) { if (fn7 == 0x00) { /* Special case ADDL as SEXTL. */ tcg_gen_ext32s_i64(vc, vb); break; } if (fn7 == 0x29) { /* Special case SUBQ as NEGQ. */ tcg_gen_neg_i64(vc, vb); break; } } va = load_gpr(ctx, ra); switch (fn7) { case 0x00: /* ADDL */ tcg_gen_add_i64(vc, va, vb); tcg_gen_ext32s_i64(vc, vc); break; case 0x02: /* S4ADDL */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 2); tcg_gen_add_i64(tmp, tmp, vb); tcg_gen_ext32s_i64(vc, tmp); tcg_temp_free(tmp); break; case 0x09: /* SUBL */ tcg_gen_sub_i64(vc, va, vb); tcg_gen_ext32s_i64(vc, vc); break; case 0x0B: /* S4SUBL */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 2); tcg_gen_sub_i64(tmp, tmp, vb); tcg_gen_ext32s_i64(vc, tmp); tcg_temp_free(tmp); break; case 0x0F: /* CMPBGE */ if (ra == 31) { /* Special case 0 >= X as X == 0. */ gen_helper_cmpbe0(vc, vb); } else { gen_helper_cmpbge(vc, va, vb); } break; case 0x12: /* S8ADDL */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 3); tcg_gen_add_i64(tmp, tmp, vb); tcg_gen_ext32s_i64(vc, tmp); tcg_temp_free(tmp); break; case 0x1B: /* S8SUBL */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 3); tcg_gen_sub_i64(tmp, tmp, vb); tcg_gen_ext32s_i64(vc, tmp); tcg_temp_free(tmp); break; case 0x1D: /* CMPULT */ tcg_gen_setcond_i64(TCG_COND_LTU, vc, va, vb); break; case 0x20: /* ADDQ */ tcg_gen_add_i64(vc, va, vb); break; case 0x22: /* S4ADDQ */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 2); tcg_gen_add_i64(vc, tmp, vb); tcg_temp_free(tmp); break; case 0x29: /* SUBQ */ tcg_gen_sub_i64(vc, va, vb); break; case 0x2B: /* S4SUBQ */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 2); tcg_gen_sub_i64(vc, tmp, vb); tcg_temp_free(tmp); break; case 0x2D: /* CMPEQ */ tcg_gen_setcond_i64(TCG_COND_EQ, vc, va, vb); break; case 0x32: /* S8ADDQ */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 3); tcg_gen_add_i64(vc, tmp, vb); tcg_temp_free(tmp); break; case 0x3B: /* S8SUBQ */ tmp = tcg_temp_new(); tcg_gen_shli_i64(tmp, va, 3); tcg_gen_sub_i64(vc, tmp, vb); tcg_temp_free(tmp); break; case 0x3D: /* CMPULE */ tcg_gen_setcond_i64(TCG_COND_LEU, vc, va, vb); break; case 0x40: /* ADDL/V */ tmp = tcg_temp_new(); tcg_gen_ext32s_i64(tmp, va); tcg_gen_ext32s_i64(vc, vb); tcg_gen_add_i64(tmp, tmp, vc); tcg_gen_ext32s_i64(vc, tmp); gen_helper_check_overflow(cpu_env, vc, tmp); tcg_temp_free(tmp); break; case 0x49: /* SUBL/V */ tmp = tcg_temp_new(); tcg_gen_ext32s_i64(tmp, va); tcg_gen_ext32s_i64(vc, vb); tcg_gen_sub_i64(tmp, tmp, vc); tcg_gen_ext32s_i64(vc, tmp); gen_helper_check_overflow(cpu_env, vc, tmp); tcg_temp_free(tmp); break; case 0x4D: /* CMPLT */ tcg_gen_setcond_i64(TCG_COND_LT, vc, va, vb); break; case 0x60: /* ADDQ/V */ tmp = tcg_temp_new(); tmp2 = tcg_temp_new(); tcg_gen_eqv_i64(tmp, va, vb); tcg_gen_mov_i64(tmp2, va); tcg_gen_add_i64(vc, va, vb); tcg_gen_xor_i64(tmp2, tmp2, vc); tcg_gen_and_i64(tmp, tmp, tmp2); tcg_gen_shri_i64(tmp, tmp, 63); tcg_gen_movi_i64(tmp2, 0); gen_helper_check_overflow(cpu_env, tmp, tmp2); tcg_temp_free(tmp); tcg_temp_free(tmp2); break; case 0x69: /* SUBQ/V */ tmp = tcg_temp_new(); tmp2 = tcg_temp_new(); tcg_gen_xor_i64(tmp, va, vb); tcg_gen_mov_i64(tmp2, va); tcg_gen_sub_i64(vc, va, vb); tcg_gen_xor_i64(tmp2, tmp2, vc); tcg_gen_and_i64(tmp, tmp, tmp2); tcg_gen_shri_i64(tmp, tmp, 63); tcg_gen_movi_i64(tmp2, 0); gen_helper_check_overflow(cpu_env, tmp, tmp2); tcg_temp_free(tmp); tcg_temp_free(tmp2); break; case 0x6D: /* CMPLE */ tcg_gen_setcond_i64(TCG_COND_LE, vc, va, vb); break; default: goto invalid_opc; } break; case 0x11: if (fn7 == 0x20) { if (rc == 31) { /* Special case BIS as NOP. */ break; } if (ra == 31) { /* Special case BIS as MOV. */ vc = dest_gpr(ctx, rc); if (islit) { tcg_gen_movi_i64(vc, lit); } else { tcg_gen_mov_i64(vc, load_gpr(ctx, rb)); } break; } } vc = dest_gpr(ctx, rc); vb = load_gpr_lit(ctx, rb, lit, islit); if (fn7 == 0x28 && ra == 31) { /* Special case ORNOT as NOT. */ tcg_gen_not_i64(vc, vb); break; } va = load_gpr(ctx, ra); switch (fn7) { case 0x00: /* AND */ tcg_gen_and_i64(vc, va, vb); break; case 0x08: /* BIC */ tcg_gen_andc_i64(vc, va, vb); break; case 0x14: /* CMOVLBS */ tmp = tcg_temp_new(); tcg_gen_andi_i64(tmp, va, 1); tcg_gen_movcond_i64(TCG_COND_NE, vc, tmp, load_zero(ctx), vb, load_gpr(ctx, rc)); tcg_temp_free(tmp); break; case 0x16: /* CMOVLBC */ tmp = tcg_temp_new(); tcg_gen_andi_i64(tmp, va, 1); tcg_gen_movcond_i64(TCG_COND_EQ, vc, tmp, load_zero(ctx), vb, load_gpr(ctx, rc)); tcg_temp_free(tmp); break; case 0x20: /* BIS */ tcg_gen_or_i64(vc, va, vb); break; case 0x24: /* CMOVEQ */ tcg_gen_movcond_i64(TCG_COND_EQ, vc, va, load_zero(ctx), vb, load_gpr(ctx, rc)); break; case 0x26: /* CMOVNE */ tcg_gen_movcond_i64(TCG_COND_NE, vc, va, load_zero(ctx), vb, load_gpr(ctx, rc)); break; case 0x28: /* ORNOT */ tcg_gen_orc_i64(vc, va, vb); break; case 0x40: /* XOR */ tcg_gen_xor_i64(vc, va, vb); break; case 0x44: /* CMOVLT */ tcg_gen_movcond_i64(TCG_COND_LT, vc, va, load_zero(ctx), vb, load_gpr(ctx, rc)); break; case 0x46: /* CMOVGE */ tcg_gen_movcond_i64(TCG_COND_GE, vc, va, load_zero(ctx), vb, load_gpr(ctx, rc)); break; case 0x48: /* EQV */ tcg_gen_eqv_i64(vc, va, vb); break; case 0x61: /* AMASK */ REQUIRE_REG_31(ra); tcg_gen_andi_i64(vc, vb, ~ctx->amask); break; case 0x64: /* CMOVLE */ tcg_gen_movcond_i64(TCG_COND_LE, vc, va, load_zero(ctx), vb, load_gpr(ctx, rc)); break; case 0x66: /* CMOVGT */ tcg_gen_movcond_i64(TCG_COND_GT, vc, va, load_zero(ctx), vb, load_gpr(ctx, rc)); break; case 0x6C: /* IMPLVER */ REQUIRE_REG_31(ra); tcg_gen_movi_i64(vc, ctx->implver); break; default: goto invalid_opc; } break; case 0x12: vc = dest_gpr(ctx, rc); va = load_gpr(ctx, ra); switch (fn7) { case 0x02: /* MSKBL */ gen_msk_l(ctx, vc, va, rb, islit, lit, 0x01); break; case 0x06: /* EXTBL */ gen_ext_l(ctx, vc, va, rb, islit, lit, 0x01); break; case 0x0B: /* INSBL */ gen_ins_l(ctx, vc, va, rb, islit, lit, 0x01); break; case 0x12: /* MSKWL */ gen_msk_l(ctx, vc, va, rb, islit, lit, 0x03); break; case 0x16: /* EXTWL */ gen_ext_l(ctx, vc, va, rb, islit, lit, 0x03); break; case 0x1B: /* INSWL */ gen_ins_l(ctx, vc, va, rb, islit, lit, 0x03); break; case 0x22: /* MSKLL */ gen_msk_l(ctx, vc, va, rb, islit, lit, 0x0f); break; case 0x26: /* EXTLL */ gen_ext_l(ctx, vc, va, rb, islit, lit, 0x0f); break; case 0x2B: /* INSLL */ gen_ins_l(ctx, vc, va, rb, islit, lit, 0x0f); break; case 0x30: /* ZAP */ if (islit) { gen_zapnoti(vc, va, ~lit); } else { gen_helper_zap(vc, va, load_gpr(ctx, rb)); } break; case 0x31: /* ZAPNOT */ if (islit) { gen_zapnoti(vc, va, lit); } else { gen_helper_zapnot(vc, va, load_gpr(ctx, rb)); } break; case 0x32: /* MSKQL */ gen_msk_l(ctx, vc, va, rb, islit, lit, 0xff); break; case 0x34: /* SRL */ if (islit) { tcg_gen_shri_i64(vc, va, lit & 0x3f); } else { tmp = tcg_temp_new(); vb = load_gpr(ctx, rb); tcg_gen_andi_i64(tmp, vb, 0x3f); tcg_gen_shr_i64(vc, va, tmp); tcg_temp_free(tmp); } break; case 0x36: /* EXTQL */ gen_ext_l(ctx, vc, va, rb, islit, lit, 0xff); break; case 0x39: /* SLL */ if (islit) { tcg_gen_shli_i64(vc, va, lit & 0x3f); } else { tmp = tcg_temp_new(); vb = load_gpr(ctx, rb); tcg_gen_andi_i64(tmp, vb, 0x3f); tcg_gen_shl_i64(vc, va, tmp); tcg_temp_free(tmp); } break; case 0x3B: /* INSQL */ gen_ins_l(ctx, vc, va, rb, islit, lit, 0xff); break; case 0x3C: /* SRA */ if (islit) { tcg_gen_sari_i64(vc, va, lit & 0x3f); } else { tmp = tcg_temp_new(); vb = load_gpr(ctx, rb); tcg_gen_andi_i64(tmp, vb, 0x3f); tcg_gen_sar_i64(vc, va, tmp); tcg_temp_free(tmp); } break; case 0x52: /* MSKWH */ gen_msk_h(ctx, vc, va, rb, islit, lit, 0x03); break; case 0x57: /* INSWH */ gen_ins_h(ctx, vc, va, rb, islit, lit, 0x03); break; case 0x5A: /* EXTWH */ gen_ext_h(ctx, vc, va, rb, islit, lit, 0x03); break; case 0x62: /* MSKLH */ gen_msk_h(ctx, vc, va, rb, islit, lit, 0x0f); break; case 0x67: /* INSLH */ gen_ins_h(ctx, vc, va, rb, islit, lit, 0x0f); break; case 0x6A: /* EXTLH */ gen_ext_h(ctx, vc, va, rb, islit, lit, 0x0f); break; case 0x72: /* MSKQH */ gen_msk_h(ctx, vc, va, rb, islit, lit, 0xff); break; case 0x77: /* INSQH */ gen_ins_h(ctx, vc, va, rb, islit, lit, 0xff); break; case 0x7A: /* EXTQH */ gen_ext_h(ctx, vc, va, rb, islit, lit, 0xff); break; default: goto invalid_opc; } break; case 0x13: vc = dest_gpr(ctx, rc); vb = load_gpr_lit(ctx, rb, lit, islit); va = load_gpr(ctx, ra); switch (fn7) { case 0x00: /* MULL */ tcg_gen_mul_i64(vc, va, vb); tcg_gen_ext32s_i64(vc, vc); break; case 0x20: /* MULQ */ tcg_gen_mul_i64(vc, va, vb); break; case 0x30: /* UMULH */ tmp = tcg_temp_new(); tcg_gen_mulu2_i64(tmp, vc, va, vb); tcg_temp_free(tmp); break; case 0x40: /* MULL/V */ tmp = tcg_temp_new(); tcg_gen_ext32s_i64(tmp, va); tcg_gen_ext32s_i64(vc, vb); tcg_gen_mul_i64(tmp, tmp, vc); tcg_gen_ext32s_i64(vc, tmp); gen_helper_check_overflow(cpu_env, vc, tmp); tcg_temp_free(tmp); break; case 0x60: /* MULQ/V */ tmp = tcg_temp_new(); tmp2 = tcg_temp_new(); tcg_gen_muls2_i64(vc, tmp, va, vb); tcg_gen_sari_i64(tmp2, vc, 63); gen_helper_check_overflow(cpu_env, tmp, tmp2); tcg_temp_free(tmp); tcg_temp_free(tmp2); break; default: goto invalid_opc; } break; case 0x14: REQUIRE_AMASK(FIX); vc = dest_fpr(ctx, rc); switch (fpfn) { /* fn11 & 0x3F */ case 0x04: /* ITOFS */ REQUIRE_REG_31(rb); t32 = tcg_temp_new_i32(); va = load_gpr(ctx, ra); tcg_gen_extrl_i64_i32(t32, va); gen_helper_memory_to_s(vc, t32); tcg_temp_free_i32(t32); break; case 0x0A: /* SQRTF */ REQUIRE_REG_31(ra); vb = load_fpr(ctx, rb); gen_helper_sqrtf(vc, cpu_env, vb); break; case 0x0B: /* SQRTS */ REQUIRE_REG_31(ra); gen_sqrts(ctx, rb, rc, fn11); break; case 0x14: /* ITOFF */ REQUIRE_REG_31(rb); t32 = tcg_temp_new_i32(); va = load_gpr(ctx, ra); tcg_gen_extrl_i64_i32(t32, va); gen_helper_memory_to_f(vc, t32); tcg_temp_free_i32(t32); break; case 0x24: /* ITOFT */ REQUIRE_REG_31(rb); va = load_gpr(ctx, ra); tcg_gen_mov_i64(vc, va); break; case 0x2A: /* SQRTG */ REQUIRE_REG_31(ra); vb = load_fpr(ctx, rb); gen_helper_sqrtg(vc, cpu_env, vb); break; case 0x02B: /* SQRTT */ REQUIRE_REG_31(ra); gen_sqrtt(ctx, rb, rc, fn11); break; default: goto invalid_opc; } break; case 0x15: /* VAX floating point */ /* XXX: rounding mode and trap are ignored (!) */ vc = dest_fpr(ctx, rc); vb = load_fpr(ctx, rb); va = load_fpr(ctx, ra); switch (fpfn) { /* fn11 & 0x3F */ case 0x00: /* ADDF */ gen_helper_addf(vc, cpu_env, va, vb); break; case 0x01: /* SUBF */ gen_helper_subf(vc, cpu_env, va, vb); break; case 0x02: /* MULF */ gen_helper_mulf(vc, cpu_env, va, vb); break; case 0x03: /* DIVF */ gen_helper_divf(vc, cpu_env, va, vb); break; case 0x1E: /* CVTDG -- TODO */ REQUIRE_REG_31(ra); goto invalid_opc; case 0x20: /* ADDG */ gen_helper_addg(vc, cpu_env, va, vb); break; case 0x21: /* SUBG */ gen_helper_subg(vc, cpu_env, va, vb); break; case 0x22: /* MULG */ gen_helper_mulg(vc, cpu_env, va, vb); break; case 0x23: /* DIVG */ gen_helper_divg(vc, cpu_env, va, vb); break; case 0x25: /* CMPGEQ */ gen_helper_cmpgeq(vc, cpu_env, va, vb); break; case 0x26: /* CMPGLT */ gen_helper_cmpglt(vc, cpu_env, va, vb); break; case 0x27: /* CMPGLE */ gen_helper_cmpgle(vc, cpu_env, va, vb); break; case 0x2C: /* CVTGF */ REQUIRE_REG_31(ra); gen_helper_cvtgf(vc, cpu_env, vb); break; case 0x2D: /* CVTGD -- TODO */ REQUIRE_REG_31(ra); goto invalid_opc; case 0x2F: /* CVTGQ */ REQUIRE_REG_31(ra); gen_helper_cvtgq(vc, cpu_env, vb); break; case 0x3C: /* CVTQF */ REQUIRE_REG_31(ra); gen_helper_cvtqf(vc, cpu_env, vb); break; case 0x3E: /* CVTQG */ REQUIRE_REG_31(ra); gen_helper_cvtqg(vc, cpu_env, vb); break; default: goto invalid_opc; } break; case 0x16: /* IEEE floating-point */ switch (fpfn) { /* fn11 & 0x3F */ case 0x00: /* ADDS */ gen_adds(ctx, ra, rb, rc, fn11); break; case 0x01: /* SUBS */ gen_subs(ctx, ra, rb, rc, fn11); break; case 0x02: /* MULS */ gen_muls(ctx, ra, rb, rc, fn11); break; case 0x03: /* DIVS */ gen_divs(ctx, ra, rb, rc, fn11); break; case 0x20: /* ADDT */ gen_addt(ctx, ra, rb, rc, fn11); break; case 0x21: /* SUBT */ gen_subt(ctx, ra, rb, rc, fn11); break; case 0x22: /* MULT */ gen_mult(ctx, ra, rb, rc, fn11); break; case 0x23: /* DIVT */ gen_divt(ctx, ra, rb, rc, fn11); break; case 0x24: /* CMPTUN */ gen_cmptun(ctx, ra, rb, rc, fn11); break; case 0x25: /* CMPTEQ */ gen_cmpteq(ctx, ra, rb, rc, fn11); break; case 0x26: /* CMPTLT */ gen_cmptlt(ctx, ra, rb, rc, fn11); break; case 0x27: /* CMPTLE */ gen_cmptle(ctx, ra, rb, rc, fn11); break; case 0x2C: REQUIRE_REG_31(ra); if (fn11 == 0x2AC || fn11 == 0x6AC) { /* CVTST */ gen_cvtst(ctx, rb, rc, fn11); } else { /* CVTTS */ gen_cvtts(ctx, rb, rc, fn11); } break; case 0x2F: /* CVTTQ */ REQUIRE_REG_31(ra); gen_cvttq(ctx, rb, rc, fn11); break; case 0x3C: /* CVTQS */ REQUIRE_REG_31(ra); gen_cvtqs(ctx, rb, rc, fn11); break; case 0x3E: /* CVTQT */ REQUIRE_REG_31(ra); gen_cvtqt(ctx, rb, rc, fn11); break; default: goto invalid_opc; } break; case 0x17: switch (fn11) { case 0x010: /* CVTLQ */ REQUIRE_REG_31(ra); vc = dest_fpr(ctx, rc); vb = load_fpr(ctx, rb); gen_cvtlq(vc, vb); break; case 0x020: /* CPYS */ if (rc == 31) { /* Special case CPYS as FNOP. */ } else { vc = dest_fpr(ctx, rc); va = load_fpr(ctx, ra); if (ra == rb) { /* Special case CPYS as FMOV. */ tcg_gen_mov_i64(vc, va); } else { vb = load_fpr(ctx, rb); gen_cpy_mask(vc, va, vb, 0, 0x8000000000000000ULL); } } break; case 0x021: /* CPYSN */ vc = dest_fpr(ctx, rc); vb = load_fpr(ctx, rb); va = load_fpr(ctx, ra); gen_cpy_mask(vc, va, vb, 1, 0x8000000000000000ULL); break; case 0x022: /* CPYSE */ vc = dest_fpr(ctx, rc); vb = load_fpr(ctx, rb); va = load_fpr(ctx, ra); gen_cpy_mask(vc, va, vb, 0, 0xFFF0000000000000ULL); break; case 0x024: /* MT_FPCR */ va = load_fpr(ctx, ra); gen_helper_store_fpcr(cpu_env, va); if (ctx->tb_rm == QUAL_RM_D) { /* Re-do the copy of the rounding mode to fp_status the next time we use dynamic rounding. */ ctx->tb_rm = -1; } break; case 0x025: /* MF_FPCR */ va = dest_fpr(ctx, ra); gen_helper_load_fpcr(va, cpu_env); break; case 0x02A: /* FCMOVEQ */ gen_fcmov(ctx, TCG_COND_EQ, ra, rb, rc); break; case 0x02B: /* FCMOVNE */ gen_fcmov(ctx, TCG_COND_NE, ra, rb, rc); break; case 0x02C: /* FCMOVLT */ gen_fcmov(ctx, TCG_COND_LT, ra, rb, rc); break; case 0x02D: /* FCMOVGE */ gen_fcmov(ctx, TCG_COND_GE, ra, rb, rc); break; case 0x02E: /* FCMOVLE */ gen_fcmov(ctx, TCG_COND_LE, ra, rb, rc); break; case 0x02F: /* FCMOVGT */ gen_fcmov(ctx, TCG_COND_GT, ra, rb, rc); break; case 0x030: /* CVTQL */ case 0x130: /* CVTQL/V */ case 0x530: /* CVTQL/SV */ REQUIRE_REG_31(ra); vc = dest_fpr(ctx, rc); vb = load_fpr(ctx, rb); gen_helper_cvtql(vc, cpu_env, vb); gen_fp_exc_raise(rc, fn11); break; default: goto invalid_opc; } break; case 0x18: switch ((uint16_t)disp16) { case 0x0000: /* TRAPB */ /* No-op. */ break; case 0x0400: /* EXCB */ /* No-op. */ break; case 0x4000: /* MB */ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC); break; case 0x4400: /* WMB */ tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC); break; case 0x8000: /* FETCH */ /* No-op */ break; case 0xA000: /* FETCH_M */ /* No-op */ break; case 0xC000: /* RPCC */ va = dest_gpr(ctx, ra); if (ctx->base.tb->cflags & CF_USE_ICOUNT) { gen_io_start(); gen_helper_load_pcc(va, cpu_env); gen_io_end(); ret = DISAS_PC_STALE; } else { gen_helper_load_pcc(va, cpu_env); } break; case 0xE000: /* RC */ gen_rx(ctx, ra, 0); break; case 0xE800: /* ECB */ break; case 0xF000: /* RS */ gen_rx(ctx, ra, 1); break; case 0xF800: /* WH64 */ /* No-op */ break; case 0xFC00: /* WH64EN */ /* No-op */ break; default: goto invalid_opc; } break; case 0x19: /* HW_MFPR (PALcode) */ #ifndef CONFIG_USER_ONLY REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE); va = dest_gpr(ctx, ra); ret = gen_mfpr(ctx, va, insn & 0xffff); break; #else goto invalid_opc; #endif case 0x1A: /* JMP, JSR, RET, JSR_COROUTINE. These only differ by the branch prediction stack action, which of course we don't implement. */ vb = load_gpr(ctx, rb); tcg_gen_andi_i64(cpu_pc, vb, ~3); if (ra != 31) { tcg_gen_movi_i64(ctx->ir[ra], ctx->base.pc_next); } ret = DISAS_PC_UPDATED; break; case 0x1B: /* HW_LD (PALcode) */ #ifndef CONFIG_USER_ONLY REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE); { TCGv addr = tcg_temp_new(); vb = load_gpr(ctx, rb); va = dest_gpr(ctx, ra); tcg_gen_addi_i64(addr, vb, disp12); switch ((insn >> 12) & 0xF) { case 0x0: /* Longword physical access (hw_ldl/p) */ tcg_gen_qemu_ld_i64(va, addr, MMU_PHYS_IDX, MO_LESL); break; case 0x1: /* Quadword physical access (hw_ldq/p) */ tcg_gen_qemu_ld_i64(va, addr, MMU_PHYS_IDX, MO_LEQ); break; case 0x2: /* Longword physical access with lock (hw_ldl_l/p) */ gen_qemu_ldl_l(va, addr, MMU_PHYS_IDX); break; case 0x3: /* Quadword physical access with lock (hw_ldq_l/p) */ gen_qemu_ldq_l(va, addr, MMU_PHYS_IDX); break; case 0x4: /* Longword virtual PTE fetch (hw_ldl/v) */ goto invalid_opc; case 0x5: /* Quadword virtual PTE fetch (hw_ldq/v) */ goto invalid_opc; break; case 0x6: /* Invalid */ goto invalid_opc; case 0x7: /* Invaliid */ goto invalid_opc; case 0x8: /* Longword virtual access (hw_ldl) */ goto invalid_opc; case 0x9: /* Quadword virtual access (hw_ldq) */ goto invalid_opc; case 0xA: /* Longword virtual access with protection check (hw_ldl/w) */ tcg_gen_qemu_ld_i64(va, addr, MMU_KERNEL_IDX, MO_LESL); break; case 0xB: /* Quadword virtual access with protection check (hw_ldq/w) */ tcg_gen_qemu_ld_i64(va, addr, MMU_KERNEL_IDX, MO_LEQ); break; case 0xC: /* Longword virtual access with alt access mode (hw_ldl/a)*/ goto invalid_opc; case 0xD: /* Quadword virtual access with alt access mode (hw_ldq/a) */ goto invalid_opc; case 0xE: /* Longword virtual access with alternate access mode and protection checks (hw_ldl/wa) */ tcg_gen_qemu_ld_i64(va, addr, MMU_USER_IDX, MO_LESL); break; case 0xF: /* Quadword virtual access with alternate access mode and protection checks (hw_ldq/wa) */ tcg_gen_qemu_ld_i64(va, addr, MMU_USER_IDX, MO_LEQ); break; } tcg_temp_free(addr); break; } #else goto invalid_opc; #endif case 0x1C: vc = dest_gpr(ctx, rc); if (fn7 == 0x70) { /* FTOIT */ REQUIRE_AMASK(FIX); REQUIRE_REG_31(rb); va = load_fpr(ctx, ra); tcg_gen_mov_i64(vc, va); break; } else if (fn7 == 0x78) { /* FTOIS */ REQUIRE_AMASK(FIX); REQUIRE_REG_31(rb); t32 = tcg_temp_new_i32(); va = load_fpr(ctx, ra); gen_helper_s_to_memory(t32, va); tcg_gen_ext_i32_i64(vc, t32); tcg_temp_free_i32(t32); break; } vb = load_gpr_lit(ctx, rb, lit, islit); switch (fn7) { case 0x00: /* SEXTB */ REQUIRE_AMASK(BWX); REQUIRE_REG_31(ra); tcg_gen_ext8s_i64(vc, vb); break; case 0x01: /* SEXTW */ REQUIRE_AMASK(BWX); REQUIRE_REG_31(ra); tcg_gen_ext16s_i64(vc, vb); break; case 0x30: /* CTPOP */ REQUIRE_AMASK(CIX); REQUIRE_REG_31(ra); REQUIRE_NO_LIT; tcg_gen_ctpop_i64(vc, vb); break; case 0x31: /* PERR */ REQUIRE_AMASK(MVI); REQUIRE_NO_LIT; va = load_gpr(ctx, ra); gen_helper_perr(vc, va, vb); break; case 0x32: /* CTLZ */ REQUIRE_AMASK(CIX); REQUIRE_REG_31(ra); REQUIRE_NO_LIT; tcg_gen_clzi_i64(vc, vb, 64); break; case 0x33: /* CTTZ */ REQUIRE_AMASK(CIX); REQUIRE_REG_31(ra); REQUIRE_NO_LIT; tcg_gen_ctzi_i64(vc, vb, 64); break; case 0x34: /* UNPKBW */ REQUIRE_AMASK(MVI); REQUIRE_REG_31(ra); REQUIRE_NO_LIT; gen_helper_unpkbw(vc, vb); break; case 0x35: /* UNPKBL */ REQUIRE_AMASK(MVI); REQUIRE_REG_31(ra); REQUIRE_NO_LIT; gen_helper_unpkbl(vc, vb); break; case 0x36: /* PKWB */ REQUIRE_AMASK(MVI); REQUIRE_REG_31(ra); REQUIRE_NO_LIT; gen_helper_pkwb(vc, vb); break; case 0x37: /* PKLB */ REQUIRE_AMASK(MVI); REQUIRE_REG_31(ra); REQUIRE_NO_LIT; gen_helper_pklb(vc, vb); break; case 0x38: /* MINSB8 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_minsb8(vc, va, vb); break; case 0x39: /* MINSW4 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_minsw4(vc, va, vb); break; case 0x3A: /* MINUB8 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_minub8(vc, va, vb); break; case 0x3B: /* MINUW4 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_minuw4(vc, va, vb); break; case 0x3C: /* MAXUB8 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_maxub8(vc, va, vb); break; case 0x3D: /* MAXUW4 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_maxuw4(vc, va, vb); break; case 0x3E: /* MAXSB8 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_maxsb8(vc, va, vb); break; case 0x3F: /* MAXSW4 */ REQUIRE_AMASK(MVI); va = load_gpr(ctx, ra); gen_helper_maxsw4(vc, va, vb); break; default: goto invalid_opc; } break; case 0x1D: /* HW_MTPR (PALcode) */ #ifndef CONFIG_USER_ONLY REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE); vb = load_gpr(ctx, rb); ret = gen_mtpr(ctx, vb, insn & 0xffff); break; #else goto invalid_opc; #endif case 0x1E: /* HW_RET (PALcode) */ #ifndef CONFIG_USER_ONLY REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE); if (rb == 31) { /* Pre-EV6 CPUs interpreted this as HW_REI, loading the return address from EXC_ADDR. This turns out to be useful for our emulation PALcode, so continue to accept it. */ ctx->lit = vb = tcg_temp_new(); tcg_gen_ld_i64(vb, cpu_env, offsetof(CPUAlphaState, exc_addr)); } else { vb = load_gpr(ctx, rb); } tcg_gen_movi_i64(cpu_lock_addr, -1); tmp = tcg_temp_new(); tcg_gen_movi_i64(tmp, 0); st_flag_byte(tmp, ENV_FLAG_RX_SHIFT); tcg_gen_andi_i64(tmp, vb, 1); st_flag_byte(tmp, ENV_FLAG_PAL_SHIFT); tcg_temp_free(tmp); tcg_gen_andi_i64(cpu_pc, vb, ~3); /* Allow interrupts to be recognized right away. */ ret = DISAS_PC_UPDATED_NOCHAIN; break; #else goto invalid_opc; #endif case 0x1F: /* HW_ST (PALcode) */ #ifndef CONFIG_USER_ONLY REQUIRE_TB_FLAG(ENV_FLAG_PAL_MODE); { switch ((insn >> 12) & 0xF) { case 0x0: /* Longword physical access */ va = load_gpr(ctx, ra); vb = load_gpr(ctx, rb); tmp = tcg_temp_new(); tcg_gen_addi_i64(tmp, vb, disp12); tcg_gen_qemu_st_i64(va, tmp, MMU_PHYS_IDX, MO_LESL); tcg_temp_free(tmp); break; case 0x1: /* Quadword physical access */ va = load_gpr(ctx, ra); vb = load_gpr(ctx, rb); tmp = tcg_temp_new(); tcg_gen_addi_i64(tmp, vb, disp12); tcg_gen_qemu_st_i64(va, tmp, MMU_PHYS_IDX, MO_LEQ); tcg_temp_free(tmp); break; case 0x2: /* Longword physical access with lock */ ret = gen_store_conditional(ctx, ra, rb, disp12, MMU_PHYS_IDX, MO_LESL); break; case 0x3: /* Quadword physical access with lock */ ret = gen_store_conditional(ctx, ra, rb, disp12, MMU_PHYS_IDX, MO_LEQ); break; case 0x4: /* Longword virtual access */ goto invalid_opc; case 0x5: /* Quadword virtual access */ goto invalid_opc; case 0x6: /* Invalid */ goto invalid_opc; case 0x7: /* Invalid */ goto invalid_opc; case 0x8: /* Invalid */ goto invalid_opc; case 0x9: /* Invalid */ goto invalid_opc; case 0xA: /* Invalid */ goto invalid_opc; case 0xB: /* Invalid */ goto invalid_opc; case 0xC: /* Longword virtual access with alternate access mode */ goto invalid_opc; case 0xD: /* Quadword virtual access with alternate access mode */ goto invalid_opc; case 0xE: /* Invalid */ goto invalid_opc; case 0xF: /* Invalid */ goto invalid_opc; } break; } #else goto invalid_opc; #endif case 0x20: /* LDF */ gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0); break; case 0x21: /* LDG */ gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0); break; case 0x22: /* LDS */ gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0); break; case 0x23: /* LDT */ gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0); break; case 0x24: /* STF */ gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0); break; case 0x25: /* STG */ gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0); break; case 0x26: /* STS */ gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0); break; case 0x27: /* STT */ gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0); break; case 0x28: /* LDL */ gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0); break; case 0x29: /* LDQ */ gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0); break; case 0x2A: /* LDL_L */ gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0); break; case 0x2B: /* LDQ_L */ gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0); break; case 0x2C: /* STL */ gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0); break; case 0x2D: /* STQ */ gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0); break; case 0x2E: /* STL_C */ ret = gen_store_conditional(ctx, ra, rb, disp16, ctx->mem_idx, MO_LESL); break; case 0x2F: /* STQ_C */ ret = gen_store_conditional(ctx, ra, rb, disp16, ctx->mem_idx, MO_LEQ); break; case 0x30: /* BR */ ret = gen_bdirect(ctx, ra, disp21); break; case 0x31: /* FBEQ */ ret = gen_fbcond(ctx, TCG_COND_EQ, ra, disp21); break; case 0x32: /* FBLT */ ret = gen_fbcond(ctx, TCG_COND_LT, ra, disp21); break; case 0x33: /* FBLE */ ret = gen_fbcond(ctx, TCG_COND_LE, ra, disp21); break; case 0x34: /* BSR */ ret = gen_bdirect(ctx, ra, disp21); break; case 0x35: /* FBNE */ ret = gen_fbcond(ctx, TCG_COND_NE, ra, disp21); break; case 0x36: /* FBGE */ ret = gen_fbcond(ctx, TCG_COND_GE, ra, disp21); break; case 0x37: /* FBGT */ ret = gen_fbcond(ctx, TCG_COND_GT, ra, disp21); break; case 0x38: /* BLBC */ ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 1); break; case 0x39: /* BEQ */ ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 0); break; case 0x3A: /* BLT */ ret = gen_bcond(ctx, TCG_COND_LT, ra, disp21, 0); break; case 0x3B: /* BLE */ ret = gen_bcond(ctx, TCG_COND_LE, ra, disp21, 0); break; case 0x3C: /* BLBS */ ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 1); break; case 0x3D: /* BNE */ ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 0); break; case 0x3E: /* BGE */ ret = gen_bcond(ctx, TCG_COND_GE, ra, disp21, 0); break; case 0x3F: /* BGT */ ret = gen_bcond(ctx, TCG_COND_GT, ra, disp21, 0); break; invalid_opc: ret = gen_invalid(ctx); break; } return ret; }


void isis_notif_area_mismatch(const struct isis_circuit *circuit,
			      const char *raw_pdu, size_t raw_pdu_len)
{
	const char *xpath = "/frr-isisd:area-mismatch";
	struct list *arguments = yang_data_list_new();
	char xpath_arg[XPATH_MAXLEN];
	struct yang_data *data;
	struct isis_area *area = circuit->area;

	notif_prep_instance_hdr(xpath, area, "default", arguments);
	notif_prepr_iface_hdr(xpath, circuit, arguments);
	snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath);
	data = yang_data_new(xpath_arg, raw_pdu);
	listnode_add(arguments, data);

	hook_call(isis_hook_area_mismatch, circuit, raw_pdu, raw_pdu_len);

	nb_notification_send(xpath, arguments);
}


int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { AVFrame *extended_frame = NULL; AVFrame *padded_frame = NULL; int ret; AVPacket user_pkt = *avpkt; int needs_realloc = !user_pkt.data; *got_packet_ptr = 0; if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) { av_free_packet(avpkt); av_init_packet(avpkt); return 0; } /* ensure that extended_data is properly set */ if (frame && !frame->extended_data) { if (av_sample_fmt_is_planar(avctx->sample_fmt) && avctx->channels > AV_NUM_DATA_POINTERS) { av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, " "with more than %d channels, but extended_data is not set.\n", AV_NUM_DATA_POINTERS); return AVERROR(EINVAL); } av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n"); extended_frame = av_frame_alloc(); if (!extended_frame) return AVERROR(ENOMEM); memcpy(extended_frame, frame, sizeof(AVFrame)); extended_frame->extended_data = extended_frame->data; frame = extended_frame; } /* extract audio service type metadata */ if (frame) { AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_AUDIO_SERVICE_TYPE); if (sd && sd->size >= sizeof(enum AVAudioServiceType)) avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data; } /* check for valid frame size */ if (frame) { if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) { if (frame->nb_samples > avctx->frame_size) { av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n"); ret = AVERROR(EINVAL); goto end; } } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) { if (frame->nb_samples < avctx->frame_size && !avctx->internal->last_audio_frame) { ret = pad_last_frame(avctx, &padded_frame, frame); if (ret < 0) goto end; frame = padded_frame; avctx->internal->last_audio_frame = 1; } if (frame->nb_samples != avctx->frame_size) { av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size); ret = AVERROR(EINVAL); goto end; } } } ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); if (!ret) { if (*got_packet_ptr) { if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) { if (avpkt->pts == AV_NOPTS_VALUE) avpkt->pts = frame->pts; if (!avpkt->duration) avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); } avpkt->dts = avpkt->pts; } else { avpkt->size = 0; } } if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) { needs_realloc = 0; if (user_pkt.data) { if (user_pkt.size >= avpkt->size) { memcpy(user_pkt.data, avpkt->data, avpkt->size); } else { av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size); avpkt->size = user_pkt.size; ret = -1; } avpkt->buf = user_pkt.buf; avpkt->data = user_pkt.data; #if FF_API_DESTRUCT_PACKET FF_DISABLE_DEPRECATION_WARNINGS avpkt->destruct = user_pkt.destruct; FF_ENABLE_DEPRECATION_WARNINGS #endif } else { if (av_dup_packet(avpkt) < 0) { ret = AVERROR(ENOMEM); } } } if (!ret) { if (needs_realloc && avpkt->data) { ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE); if (ret >= 0) avpkt->data = avpkt->buf->data; } avctx->frame_number++; } if (ret < 0 || !*got_packet_ptr) { av_free_packet(avpkt); av_init_packet(avpkt); goto end; } /* NOTE: if we add any audio encoders which output non-keyframe packets, * this needs to be moved to the encoders, but for now we can do it * here to simplify things */ avpkt->flags |= AV_PKT_FLAG_KEY; end: av_frame_free(&padded_frame); av_free(extended_frame); #if FF_API_AUDIOENC_DELAY avctx->delay = avctx->initial_padding; #endif return ret; }


static char *parse_note(char *p,
			int flags)
{
	struct SYMBOL *s;
	char *q;
	int pit = 0, len, acc, nostem, chord, j, m, n;

	if (flags & ABC_F_GRACE) {	/* in a grace note sequence */
		s = abc_new(ABC_T_NOTE, NULL);
	} else {
		s = abc_new(ABC_T_NOTE, gchord);
		if (gchord)
			gchord = NULL;
	}
	s->flags |= flags;
	s->u.note.notes[0].color = -1;

	if (!lyric_started) {
		lyric_started = 1;
		s->flags |= ABC_F_LYRIC_START;
	}
	if (*p != 'X' && *p != 'Z'
	 && !(flags & ABC_F_GRACE)) {
		if (!deco_start)
			deco_start = s;
	}
	chord = 0;

	/* rest */
	switch (*p) {
	case 'X':
		s->flags |= ABC_F_INVIS;
	case 'Z':			/* multi-rest */
		s->abc_type = ABC_T_MREST;
		p++;
		len = 1;
		if (isdigit((unsigned char) *p)) {
			len = strtol(p, &q, 10);
			if (len == 0 || len > 100) {
				syntax("Bad number of measures", p);
				len = 1;
			}
			p = q;
		}
		s->u.bar.type = 0;
		s->u.bar.len = len;
		goto add_deco;
	case 'y':			/* space (BarFly) */
		s->abc_type = ABC_T_REST;
		s->flags |= ABC_F_INVIS;
		p++;
		if (isdigit((unsigned char) *p)		/* number of points */
		 || *p == '-') {			/* accept negative offset... */
			s->u.note.notes[0].shhd = strtol(p, &q, 10);
			p = q;
		} else {
			s->u.note.notes[0].shhd = 10;	// default
		}
		goto add_deco;
	case 'x':			/* invisible rest */
		s->flags |= ABC_F_INVIS;
		/* fall thru */
	case 'z':
		s->abc_type = ABC_T_REST;
		p = parse_len(p + 1, ulen, &len);
		s->u.note.notes[0].len = len;
		goto do_brhythm;
	case '[':			/* '[..]' = chord */
		chord = 1;
		p++;
		break;
	}

	q = p;

	/* get pitch, length and possible accidental */
	m = 0;
	nostem = 0;
	for (;;) {
		if (chord) {
			if (m >= MAXHD) {
				syntax("Too many notes in chord", p);
				m--;
			}
			n = 0;
			if (*p == '.') {
				n = SL_DOTTED;
				p++;
			}
			if (*p == '(') {
				p++;
				switch (*p) {
				case '\'':
					n += SL_ABOVE;
					p++;
					break;
				case ',':
					n += SL_BELOW;
					p++;
					break;
				default:
					n += SL_AUTO;
					break;
				}
				s->u.note.notes[m].sl1 = (s->u.note.notes[m].sl1 << 3)
							+ n;
			}
		}
		p = parse_deco(p, &dc, m);	/* note head decorations */
		p = parse_acc_pit(p, &pit, &acc);
		if (*p == '0') {
			nostem = 1;
			p++;
		}
		p = parse_len(p, (flags & ABC_F_GRACE) ?
					BASE_LEN / 8 :	// for grace note alone
					ulen,
				&len);
		s->u.note.notes[m].pit = pit;
		s->pits[m] = pit;
		s->u.note.notes[m].len = len;
		s->u.note.notes[m].acc = acc;
		s->u.note.notes[m].color = -1;

		if (chord) {
			for (;;) {
				if (*p == '.') {
					if (p[1] != '-')
						break;
					p++;
				}
				if (*p == '-') {
					switch (p[1]) {
					case '\'':
						s->u.note.notes[m].ti1 = SL_ABOVE;
						p++;
						break;
					case ',':
						s->u.note.notes[m].ti1 = SL_BELOW;
						p++;
						break;
					default:
						s->u.note.notes[m].ti1 = SL_AUTO;
						break;
					}
				} else if (*p == ')') {
					s->u.note.notes[m].sl2++;
				} else {
					break;
				}
				p++;
			}
		}
		if (acc >= 0)			/* if no error */
			m++;			/* normal case */

		if (!chord)
			break;
		if (*p == ']') {
			p++;
			if (*p == '0') {
				nostem = 1;
				p++;
			}
			if (*p == '/' || isdigit((unsigned char) *p)) {
				p = parse_len(p, ulen, &len);
				for (j = 0; j < m; j++) {
					s->u.note.notes[j].len =
						len * s->u.note.notes[j].len / ulen;
				}
			}
			break;
		}
		if (*p == '\0') {
			syntax("Chord not closed", q);
			break;
		}
	}
	if (nostem)
		s->flags |= ABC_F_STEMLESS;

	if (m == 0)			/* if no note (or error) */
		goto err;

	s->u.note.microscale = microscale;
	s->nhd = m - 1;

do_brhythm:
	if (curvoice->last_note
	 && curvoice->last_note->u.note.brhythm != 0)
		broken_rhythm(s, -curvoice->last_note->u.note.brhythm);
add_deco:
	if (dc.n > 0) {
		memcpy(s->abc_type != ABC_T_MREST ? &s->u.note.dc
				: &s->u.bar.dc,
			&dc, sizeof dc);
		dc.n = 0;
	}

	/* forbid rests in grace note sequences */
	if (s->abc_type != ABC_T_NOTE && (flags & ABC_F_GRACE)) {
		syntax("Not a note in grace note sequence", p);
		goto err;
	}
	return p;

err:
	if ((parse.last_sym = s->abc_prev) == NULL) {
		parse.first_sym = NULL;
	} else {
		s->abc_prev->abc_next = NULL;
		s->abc_prev->flags |= (s->flags & ABC_F_ERROR);
	}
	return p;
}


static int selinux_socket_recvmsg ( struct socket * sock , struct msghdr * msg , int size , int flags ) {
 return sock_has_perm ( current , sock -> sk , SOCKET__READ ) ;
 }


int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
				u8 event, struct sk_buff *skb)
{
	int r = 0;
	struct device *dev = &hdev->ndev->dev;
	struct nfc_evt_transaction *transaction;

	pr_debug("connectivity gate event: %x\n", event);

	switch (event) {
	case ST21NFCA_EVT_CONNECTIVITY:
		r = nfc_se_connectivity(hdev->ndev, host);
	break;
	case ST21NFCA_EVT_TRANSACTION:
		/*
		 * According to specification etsi 102 622
		 * 11.2.2.4 EVT_TRANSACTION Table 52
		 * Description	Tag	Length
		 * AID		81	5 to 16
		 * PARAMETERS	82	0 to 255
		 */
		if (skb->len < NFC_MIN_AID_LENGTH + 2 &&
		    skb->data[0] != NFC_EVT_TRANSACTION_AID_TAG)
			return -EPROTO;

		transaction = devm_kzalloc(dev, skb->len - 2, GFP_KERNEL);
		if (!transaction)
			return -ENOMEM;

		transaction->aid_len = skb->data[1];
		memcpy(transaction->aid, &skb->data[2],
		       transaction->aid_len);

		/* Check next byte is PARAMETERS tag (82) */
		if (skb->data[transaction->aid_len + 2] !=
		    NFC_EVT_TRANSACTION_PARAMS_TAG)
			return -EPROTO;

		transaction->params_len = skb->data[transaction->aid_len + 3];
		memcpy(transaction->params, skb->data +
		       transaction->aid_len + 4, transaction->params_len);

		r = nfc_se_transaction(hdev->ndev, host, transaction);
	break;
	default:
		nfc_err(&hdev->ndev->dev, "Unexpected event on connectivity gate\n");
		return 1;
	}
	kfree_skb(skb);
	return r;
}


static void xudc_getstatus(struct xusb_udc *udc)
{
	struct xusb_ep *ep0	= &udc->ep[0];
	struct xusb_req *req	= udc->req;
	struct xusb_ep *target_ep;
	u16 status = 0;
	u32 epcfgreg;
	int epnum;
	u32 halt;
	int ret;

	switch (udc->setup.bRequestType & USB_RECIP_MASK) {
	case USB_RECIP_DEVICE:
		/* Get device status */
		status = 1 << USB_DEVICE_SELF_POWERED;
		if (udc->remote_wkp)
			status |= (1 << USB_DEVICE_REMOTE_WAKEUP);
		break;
	case USB_RECIP_INTERFACE:
		break;
	case USB_RECIP_ENDPOINT:
		epnum = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK;
		target_ep = &udc->ep[epnum];
		epcfgreg = udc->read_fn(udc->addr + target_ep->offset);
		halt = epcfgreg & XUSB_EP_CFG_STALL_MASK;
		if (udc->setup.wIndex & USB_DIR_IN) {
			if (!target_ep->is_in)
				goto stall;
		} else {
			if (target_ep->is_in)
				goto stall;
		}
		if (halt)
			status = 1 << USB_ENDPOINT_HALT;
		break;
	default:
		goto stall;
	}

	req->usb_req.length = 2;
	*(u16 *)req->usb_req.buf = cpu_to_le16(status);
	ret = __xudc_ep0_queue(ep0, req);
	if (ret == 0)
		return;
stall:
	dev_err(udc->dev, "Can't respond to getstatus request\n");
	xudc_ep0_stall(udc);
}


static void destroy_surface(struct swaylock_surface *surface) {
	wl_list_remove(&surface->link);
	if (surface->layer_surface != NULL) {
		zwlr_layer_surface_v1_destroy(surface->layer_surface);
	}
	if (surface->surface != NULL) {
		wl_surface_destroy(surface->surface);
	}
	destroy_buffer(&surface->buffers[0]);
	destroy_buffer(&surface->buffers[1]);
	destroy_buffer(&surface->indicator_buffers[0]);
	destroy_buffer(&surface->indicator_buffers[1]);
	wl_output_destroy(surface->output);
	free(surface);
}


void rereadkeys ( void ) {
 if ( NULL != key_file_name ) authreadkeys ( key_file_name ) ;
 }


int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu) { if (cap_has_mp_state) { struct kvm_mp_state mp_state = { .mp_state = cpu->powered_off ? KVM_MP_STATE_STOPPED : KVM_MP_STATE_RUNNABLE }; int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MP_STATE, &mp_state); if (ret) { fprintf(stderr, "%s: failed to set MP_STATE %d/%s\n", __func__, ret, strerror(-ret)); return -1; } } return 0; }


static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_num) { MpegEncContext *s = &v->s; int mb_cbp = v->cbp[s->mb_x - s->mb_stride], block_cbp = mb_cbp >> (block_num * 4), bottom_cbp, mb_is_intra = v->is_intra[s->mb_x - s->mb_stride], block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra; int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk; uint8_t *dst; if (block_num > 3) { dst = s->dest[block_num - 3]; } else { dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize; } if (s->mb_y != s->end_mb_y || block_num < 2) { int16_t (*mv)[2]; int mv_stride; if (block_num > 3) { bottom_cbp = v->cbp[s->mb_x] >> (block_num * 4); bottom_is_intra = v->is_intra[s->mb_x] >> (block_num * 4); mv = &v->luma_mv[s->mb_x - s->mb_stride]; mv_stride = s->mb_stride; } else { bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4)) : (v->cbp[s->mb_x] >> ((block_num - 2) * 4)); bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4)) : (v->is_intra[s->mb_x] >> ((block_num - 2) * 4)); mv_stride = s->b8_stride; mv = &s->current_picture.motion_val[0][s->block_index[block_num] - 2 * mv_stride]; } if (bottom_is_intra & 1 || block_is_intra & 1 || mv[0][0] != mv[mv_stride][0] || mv[0][1] != mv[mv_stride][1]) { v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq); } else { idx = ((bottom_cbp >> 2) | block_cbp) & 3; if (idx == 3) { v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq); } else if (idx) { if (idx == 1) v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq); else v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq); } } } dst -= 4 * linesize; ttblk = (v->ttblk[s->mb_x - s->mb_stride] >> (block_num * 4)) & 0xF; if (ttblk == TT_4X4 || ttblk == TT_8X4) { idx = (block_cbp | (block_cbp >> 2)) & 3; if (idx == 3) { v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq); } else if (idx) { if (idx == 1) v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq); else v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq); } } }


void proto_register_zbee_zcl_appl_ctrl ( void ) {
 guint i , j ;
 static hf_register_info hf [ ] = {
 {
 & hf_zbee_zcl_appl_ctrl_attr_id , {
 "Attribute" , "zbee_zcl_general.applctrl.attr_id" , FT_UINT16 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_attr_names ) , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_time , {
 "Data" , "zbee_zcl_general.applctrl.time" , FT_UINT16 , BASE_HEX , NULL , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_time_mm , {
 "Minutes" , "zbee_zcl_general.applctrl.time.mm" , FT_UINT16 , BASE_DEC , NULL , ZBEE_ZCL_APPL_CTRL_TIME_MM , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_time_encoding_type , {
 "Encoding Type" , "zbee_zcl_general.applctrl.time.encoding_type" , FT_UINT16 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_time_encoding_type_names ) , ZBEE_ZCL_APPL_CTRL_TIME_ENCOD_TYPE , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_time_hh , {
 "Hours" , "zbee_zcl_general.applctrl.time.hh" , FT_UINT16 , BASE_DEC , NULL , ZBEE_ZCL_APPL_CTRL_TIME_HH , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_srv_tx_cmd_id , {
 "Command" , "zbee_zcl_general.applctrl.cmd.srv_tx.id" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_srv_tx_cmd_names ) , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_srv_rx_cmd_id , {
 "Command" , "zbee_zcl_general.applctrl.cmd.srv_rx.id" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_srv_rx_cmd_names ) , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_appl_status , {
 "Appliance Status" , "zbee_zcl_general.applctrl.status" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_appl_status_names ) , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_rem_en_flags_raw , {
 "Remote Enable Flags" , "zbee_zcl_general.applctrl.remote_enable_flags" , FT_UINT8 , BASE_HEX , NULL , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_rem_en_flags , {
 "Remote Enable Flags" , "zbee_zcl_general.applctrl.remenflags" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_rem_flags_names ) , ZBEE_ZCL_APPL_CTRL_REM_EN_FLAGS_FLAGS , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_status2 , {
 "Appliance Status 2" , "zbee_zcl_general.applctrl.status2" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_status2_names ) , ZBEE_ZCL_APPL_CTRL_REM_EN_FLAGS_STATUS2 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_status2_array , {
 "Appliance Status 2" , "zbee_zcl_general.applctrl.status2.array" , FT_UINT24 , BASE_HEX , NULL , 0x00 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_exec_cmd_id , {
 "Command" , "zbee_zcl_general.applctrl.execcmd.id" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_exec_cmd_names ) , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_attr_func_id , {
 "ID" , "zbee_zcl_general.applctrl.attr_func.id" , FT_UINT16 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_attr_names ) , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_attr_func_data_type , {
 "Data Type" , "zbee_zcl_general.applctrl.attr_func.datatype" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_short_data_type_names ) , 0x0 , NULL , HFILL }
 }
 , {
 & hf_zbee_zcl_appl_ctrl_warning_id , {
 "Warning" , "zbee_zcl_general.applctrl.ovrlwarning.id" , FT_UINT8 , BASE_HEX , VALS ( zbee_zcl_appl_ctrl_ovrl_warning_names ) , 0x0 , NULL , HFILL }
 }
 }
 ;
 gint * ett [ ZBEE_ZCL_APPL_CTRL_NUM_ETT ] ;
 ett [ 0 ] = & ett_zbee_zcl_appl_ctrl ;
 ett [ 1 ] = & ett_zbee_zcl_appl_ctrl_flags ;
 ett [ 2 ] = & ett_zbee_zcl_appl_ctrl_time ;
 for ( i = 0 , j = ZBEE_ZCL_APPL_CTRL_NUM_GENERIC_ETT ;
 i < ZBEE_ZCL_APPL_CTRL_NUM_FUNC_ETT ;
 i ++ , j ++ ) {
 ett_zbee_zcl_appl_ctrl_func [ i ] = - 1 ;
 ett [ j ] = & ett_zbee_zcl_appl_ctrl_func [ i ] ;
 }
 proto_zbee_zcl_appl_ctrl = proto_register_protocol ( "ZigBee ZCL Appliance Control" , "ZCL Appliance Control" , ZBEE_PROTOABBREV_ZCL_APPLCTRL ) ;
 proto_register_field_array ( proto_zbee_zcl_appl_ctrl , hf , array_length ( hf ) ) ;
 proto_register_subtree_array ( ett , array_length ( ett ) ) ;
 register_dissector ( ZBEE_PROTOABBREV_ZCL_APPLCTRL , dissect_zbee_zcl_appl_ctrl , proto_zbee_zcl_appl_ctrl ) ;
 }


void pcie_host_mmcfg_init(PCIExpressHost *e, uint32_t size) { assert(!(size & (size - 1))); /* power of 2 */ assert(size >= PCIE_MMCFG_SIZE_MIN); assert(size <= PCIE_MMCFG_SIZE_MAX); e->size = size; memory_region_init_io(&e->mmio, OBJECT(e), &pcie_mmcfg_ops, e, "pcie-mmcfg", e->size); }


static bool reconstruct_chained_fixup(struct MACH0_(obj_t) *bin) {
	if (!bin->dyld_info) {
		return false;
	}
	if (!bin->nsegs) {
		return false;
	}
	bin->chained_starts = R_NEWS0 (struct r_dyld_chained_starts_in_segment *, bin->nsegs);
	if (!bin->chained_starts) {
		return false;
	}
	size_t wordsize = get_word_size (bin);
	ut8 *p = NULL;
	size_t j, count, skip, bind_size;
	int seg_idx = 0;
	ut64 seg_off = 0;
	bind_size = bin->dyld_info->bind_size;
	if (!bind_size || bind_size < 1) {
		return false;
	}
	if (bin->dyld_info->bind_off > bin->size) {
		return false;
	}
	if (bin->dyld_info->bind_off + bind_size > bin->size) {
		return false;
	}
	ut8 *opcodes = calloc (1, bind_size + 1);
	if (!opcodes) {
		return false;
	}
	if (r_buf_read_at (bin->b, bin->dyld_info->bind_off, opcodes, bind_size) != bind_size) {
		bprintf ("Error: read (dyld_info bind) at 0x%08"PFMT64x"\n", (ut64)(size_t)bin->dyld_info->bind_off);
		R_FREE (opcodes);
		return false;
	}
	struct r_dyld_chained_starts_in_segment *cur_seg = NULL;
	size_t cur_seg_idx = 0;
	ut8 *end;
	bool done = false;
	for (p = opcodes, end = opcodes + bind_size; !done && p < end;) {
		ut8 imm = *p & BIND_IMMEDIATE_MASK, op = *p & BIND_OPCODE_MASK;
		p++;
		switch (op) {
		case BIND_OPCODE_DONE:
			done = true;
			break;
		case BIND_OPCODE_THREADED: {
			switch (imm) {
			case BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB: {
				read_uleb128 (&p, end);
				break;
			}
			case BIND_SUBOPCODE_THREADED_APPLY: {
				const size_t ps = 0x1000;
				if (!cur_seg || cur_seg_idx != seg_idx) {
					cur_seg_idx = seg_idx;
					cur_seg = bin->chained_starts[seg_idx];
					if (!cur_seg) {
						cur_seg = R_NEW0 (struct r_dyld_chained_starts_in_segment);
						if (!cur_seg) {
							break;
						}
						bin->chained_starts[seg_idx] = cur_seg;
						cur_seg->pointer_format = DYLD_CHAINED_PTR_ARM64E;
						cur_seg->page_size = ps;
						cur_seg->page_count = ((bin->segs[seg_idx].vmsize + (ps - 1)) & ~(ps - 1)) / ps;
						if (cur_seg->page_count > 0) {
							cur_seg->page_start = malloc (sizeof (ut16) * cur_seg->page_count);
							if (!cur_seg->page_start) {
								break;
							}
							memset (cur_seg->page_start, 0xff, sizeof (ut16) * cur_seg->page_count);
						}
					}
				}
				if (cur_seg) {
					ut32 page_index = (ut32)(seg_off / ps);
					size_t maxsize = cur_seg->page_count * sizeof (ut16);
					if (page_index < maxsize && cur_seg->page_start) {
						cur_seg->page_start[page_index] = seg_off & 0xfff;
					}
				}
				break;
			}
			default:
				bprintf ("Error: Unexpected BIND_OPCODE_THREADED sub-opcode: 0x%x\n", imm);
			}
			break;
		}
		case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM:
		case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM:
		case BIND_OPCODE_SET_TYPE_IMM:
			break;
		case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB:
			read_uleb128 (&p, end);
			break;
		case BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM:
			while (*p++ && p < end) {
				/* empty loop */
			}
			break;
		case BIND_OPCODE_SET_ADDEND_SLEB:
			r_sleb128 ((const ut8 **)&p, end);
			break;
		case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
			seg_idx = imm;
			if (seg_idx >= bin->nsegs) {
				bprintf ("Error: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB"
					" has unexistent segment %d\n", seg_idx);
				R_FREE (opcodes);
				return false;
			} else {
				seg_off = read_uleb128 (&p, end);
			}
			break;
		case BIND_OPCODE_ADD_ADDR_ULEB:
			seg_off += read_uleb128 (&p, end);
			break;
		case BIND_OPCODE_DO_BIND:
			break;
		case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:
			seg_off += read_uleb128 (&p, end) + wordsize;
			break;
		case BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED:
			seg_off += (ut64)imm * (ut64)wordsize + wordsize;
			break;
		case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:
			count = read_uleb128 (&p, end);
			skip = read_uleb128 (&p, end);
			for (j = 0; j < count; j++) {
				seg_off += skip + wordsize;
			}
			break;
		default:
			bprintf ("Error: unknown bind opcode 0x%02x in dyld_info\n", *p);
			R_FREE (opcodes);
			return false;
		}
	}
	R_FREE (opcodes);

	return true;
}


static int dissect_btgatt_microbit_microbit_event ( tvbuff_t * tvb , packet_info * pinfo _U_ , proto_tree * tree , void * data ) {
 btatt_data_t * att_data = ( btatt_data_t * ) data ;
 if ( bluetooth_gatt_has_no_parameter ( att_data -> opcode ) ) return - 1 ;
 proto_tree_add_item ( tree , hf_gatt_microbit_microbit_event , tvb , 0 , tvb_captured_length ( tvb ) , ENC_NA ) ;
 return tvb_captured_length ( tvb ) ;
 }


static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
	struct elo_priv *priv;
	int ret;
	struct usb_device *udev;

	if (!hid_is_usb(hdev))
		return -EINVAL;

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	INIT_DELAYED_WORK(&priv->work, elo_work);
	udev = interface_to_usbdev(to_usb_interface(hdev->dev.parent));
	priv->usbdev = usb_get_dev(udev);

	hid_set_drvdata(hdev, priv);

	ret = hid_parse(hdev);
	if (ret) {
		hid_err(hdev, "parse failed\n");
		goto err_free;
	}

	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
	if (ret) {
		hid_err(hdev, "hw start failed\n");
		goto err_free;
	}

	if (elo_broken_firmware(priv->usbdev)) {
		hid_info(hdev, "broken firmware found, installing workaround\n");
		queue_delayed_work(wq, &priv->work, ELO_PERIODIC_READ_INTERVAL);
	}

	return 0;
err_free:
	kfree(priv);
	return ret;
}


int ff_mjpeg_encode_stuffing(MpegEncContext *s) { int i; PutBitContext *pbc = &s->pb; int mb_y = s->mb_y - !s->mb_x; int ret; MJpegContext *m; m = s->mjpeg_ctx; if (s->huffman == HUFFMAN_TABLE_OPTIMAL) { ff_mjpeg_build_optimal_huffman(m); // Replace the VLCs with the optimal ones. // The default ones may be used for trellis during quantization. ff_init_uni_ac_vlc(m->huff_size_ac_luminance, m->uni_ac_vlc_len); ff_init_uni_ac_vlc(m->huff_size_ac_chrominance, m->uni_chroma_ac_vlc_len); s->intra_ac_vlc_length = s->intra_ac_vlc_last_length = m->uni_ac_vlc_len; s->intra_chroma_ac_vlc_length = s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len; } ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable, s->pred, s->intra_matrix, s->chroma_intra_matrix); ff_mjpeg_encode_picture_frame(s); ret = ff_mpv_reallocate_putbitbuffer(s, put_bits_count(&s->pb) / 8 + 100, put_bits_count(&s->pb) / 4 + 1000); if (ret < 0) { av_log(s->avctx, AV_LOG_ERROR, "Buffer reallocation failed\n"); goto fail; } ff_mjpeg_escape_FF(pbc, s->esc_pos); if((s->avctx->active_thread_type & FF_THREAD_SLICE) && mb_y < s->mb_height) put_marker(pbc, RST0 + (mb_y&7)); s->esc_pos = put_bits_count(pbc) >> 3; fail: for(i=0; i<3; i++) s->last_dc[i] = 128 << s->intra_dc_precision; return ret; }


static int dissect_h245_V76HDLCParameters ( tvbuff_t * tvb _U_ , int offset _U_ , asn1_ctx_t * actx _U_ , proto_tree * tree _U_ , int hf_index _U_ ) {
 offset = dissect_per_sequence ( tvb , offset , actx , tree , hf_index , ett_h245_V76HDLCParameters , V76HDLCParameters_sequence ) ;
 return offset ;
 }


static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
			 u32 msr, u64 data, bool host)
{
	struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic);
	int ret;

	if (!synic->active && !host)
		return 1;

	trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host);

	ret = 0;
	switch (msr) {
	case HV_X64_MSR_SCONTROL:
		synic->control = data;
		if (!host)
			synic_exit(synic, msr);
		break;
	case HV_X64_MSR_SVERSION:
		if (!host) {
			ret = 1;
			break;
		}
		synic->version = data;
		break;
	case HV_X64_MSR_SIEFP:
		if ((data & HV_SYNIC_SIEFP_ENABLE) && !host &&
		    !synic->dont_zero_synic_pages)
			if (kvm_clear_guest(vcpu->kvm,
					    data & PAGE_MASK, PAGE_SIZE)) {
				ret = 1;
				break;
			}
		synic->evt_page = data;
		if (!host)
			synic_exit(synic, msr);
		break;
	case HV_X64_MSR_SIMP:
		if ((data & HV_SYNIC_SIMP_ENABLE) && !host &&
		    !synic->dont_zero_synic_pages)
			if (kvm_clear_guest(vcpu->kvm,
					    data & PAGE_MASK, PAGE_SIZE)) {
				ret = 1;
				break;
			}
		synic->msg_page = data;
		if (!host)
			synic_exit(synic, msr);
		break;
	case HV_X64_MSR_EOM: {
		int i;

		for (i = 0; i < ARRAY_SIZE(synic->sint); i++)
			kvm_hv_notify_acked_sint(vcpu, i);
		break;
	}
	case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:
		ret = synic_set_sint(synic, msr - HV_X64_MSR_SINT0, data, host);
		break;
	default:
		ret = 1;
		break;
	}
	return ret;
}


inline bool is_delimiter_command ( char * name , ulong len ) {
 return ( len >= DELIMITER_NAME_LEN && ! my_strnncoll ( charset_info , ( uchar * ) name , DELIMITER_NAME_LEN , ( uchar * ) DELIMITER_NAME , DELIMITER_NAME_LEN ) ) ;
 }


static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
			    bool host)
{
	struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
	struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu);

	if (!synic->active && !host)
		return 1;

	trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id,
				      stimer->index, count, host);

	stimer_cleanup(stimer);
	stimer->count = count;
	if (stimer->count == 0)
		stimer->config.enable = 0;
	else if (stimer->config.auto_enable)
		stimer->config.enable = 1;

	if (stimer->config.enable)
		stimer_mark_pending(stimer, false);

	return 0;
}


static void evhttp_write_connectioncb ( struct evhttp_connection * evcon , void * arg ) {
 struct evhttp_request * req = TAILQ_FIRST ( & evcon -> requests ) ;
 assert ( req != NULL ) ;
 assert ( evcon -> state == EVCON_WRITING ) ;
 req -> kind = EVHTTP_RESPONSE ;
 evhttp_start_read ( evcon ) ;
 }


static inline void tlb_set_dirty(CPUState *env, target_ulong vaddr) { int i; vaddr &= TARGET_PAGE_MASK; i = (vaddr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); tlb_set_dirty1(&env->tlb_table[0][i], vaddr); tlb_set_dirty1(&env->tlb_table[1][i], vaddr); #if (NB_MMU_MODES >= 3) tlb_set_dirty1(&env->tlb_table[2][i], vaddr); #endif #if (NB_MMU_MODES >= 4) tlb_set_dirty1(&env->tlb_table[3][i], vaddr); #endif #if (NB_MMU_MODES >= 5) tlb_set_dirty1(&env->tlb_table[4][i], vaddr); #endif }


void ax25_dev_device_up(struct net_device *dev)
{
	ax25_dev *ax25_dev;

	if ((ax25_dev = kzalloc(sizeof(*ax25_dev), GFP_ATOMIC)) == NULL) {
		printk(KERN_ERR "AX.25: ax25_dev_device_up - out of memory\n");
		return;
	}

	dev->ax25_ptr     = ax25_dev;
	ax25_dev->dev     = dev;
	dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_ATOMIC);
	ax25_dev->forward = NULL;

	ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE;
	ax25_dev->values[AX25_VALUES_AXDEFMODE] = AX25_DEF_AXDEFMODE;
	ax25_dev->values[AX25_VALUES_BACKOFF]   = AX25_DEF_BACKOFF;
	ax25_dev->values[AX25_VALUES_CONMODE]   = AX25_DEF_CONMODE;
	ax25_dev->values[AX25_VALUES_WINDOW]    = AX25_DEF_WINDOW;
	ax25_dev->values[AX25_VALUES_EWINDOW]   = AX25_DEF_EWINDOW;
	ax25_dev->values[AX25_VALUES_T1]        = AX25_DEF_T1;
	ax25_dev->values[AX25_VALUES_T2]        = AX25_DEF_T2;
	ax25_dev->values[AX25_VALUES_T3]        = AX25_DEF_T3;
	ax25_dev->values[AX25_VALUES_IDLE]	= AX25_DEF_IDLE;
	ax25_dev->values[AX25_VALUES_N2]        = AX25_DEF_N2;
	ax25_dev->values[AX25_VALUES_PACLEN]	= AX25_DEF_PACLEN;
	ax25_dev->values[AX25_VALUES_PROTOCOL]  = AX25_DEF_PROTOCOL;
	ax25_dev->values[AX25_VALUES_DS_TIMEOUT]= AX25_DEF_DS_TIMEOUT;

#if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER)
	ax25_ds_setup_timer(ax25_dev);
#endif

	spin_lock_bh(&ax25_dev_lock);
	ax25_dev->next = ax25_dev_list;
	ax25_dev_list  = ax25_dev;
	spin_unlock_bh(&ax25_dev_lock);

	ax25_register_dev_sysctl(ax25_dev);
}


static av_cold int nvenc_setup_surfaces(AVCodecContext *avctx) { NvencContext *ctx = avctx->priv_data; int i, res; ctx->surfaces = av_mallocz_array(ctx->nb_surfaces, sizeof(*ctx->surfaces)); if (!ctx->surfaces) return AVERROR(ENOMEM); ctx->timestamp_list = av_fifo_alloc(ctx->nb_surfaces * sizeof(int64_t)); if (!ctx->timestamp_list) return AVERROR(ENOMEM); ctx->unused_surface_queue = av_fifo_alloc(ctx->nb_surfaces * sizeof(NvencSurface*)); if (!ctx->unused_surface_queue) return AVERROR(ENOMEM); ctx->output_surface_queue = av_fifo_alloc(ctx->nb_surfaces * sizeof(NvencSurface*)); if (!ctx->output_surface_queue) return AVERROR(ENOMEM); ctx->output_surface_ready_queue = av_fifo_alloc(ctx->nb_surfaces * sizeof(NvencSurface*)); if (!ctx->output_surface_ready_queue) return AVERROR(ENOMEM); res = nvenc_push_context(avctx); if (res < 0) return res; for (i = 0; i < ctx->nb_surfaces; i++) { if ((res = nvenc_alloc_surface(avctx, i)) < 0) { nvenc_pop_context(avctx); return res; } } res = nvenc_pop_context(avctx); if (res < 0) return res; return 0; }


static ram_addr_t s390_virtio_next_ring ( VirtIOS390Bus * bus ) {
 ram_addr_t r = bus -> next_ring ;
 bus -> next_ring += VIRTIO_RING_LEN ;
 return r ;
 }


static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; if(bit == ((*state)&1)){ c->range -= RangeLPS; *state= ff_h264_mps_state[*state]; }else{ c->low += c->range - RangeLPS; c->range = RangeLPS; *state= ff_h264_lps_state[*state]; } renorm_cabac_encoder(c); }


static int ax25_rt_del(struct ax25_routes_struct *route)
{
	ax25_route *s, *t, *ax25_rt;
	ax25_dev *ax25_dev;

	if ((ax25_dev = ax25_addr_ax25dev(&route->port_addr)) == NULL)
		return -EINVAL;

	write_lock_bh(&ax25_route_lock);

	ax25_rt = ax25_route_list;
	while (ax25_rt != NULL) {
		s       = ax25_rt;
		ax25_rt = ax25_rt->next;
		if (s->dev == ax25_dev->dev &&
		    ax25cmp(&route->dest_addr, &s->callsign) == 0) {
			if (ax25_route_list == s) {
				ax25_route_list = s->next;
				ax25_put_route(s);
			} else {
				for (t = ax25_route_list; t != NULL; t = t->next) {
					if (t->next == s) {
						t->next = s->next;
						ax25_put_route(s);
						break;
					}
				}
			}
		}
	}
	ax25_dev_put(ax25_dev);
	write_unlock_bh(&ax25_route_lock);

	return 0;
}


bool check_grant_all_columns ( THD * thd , ulong want_access_arg , Field_iterator_table_ref * fields ) {
 Security_context * sctx = thd -> security_ctx ;
 ulong want_access = want_access_arg ;
 const char * table_name = NULL ;
 const char * db_name ;
 GRANT_INFO * grant ;
 GRANT_TABLE * grant_table = NULL ;
 bool using_column_privileges = FALSE ;
 rw_rdlock ( & LOCK_grant ) ;
 for ( ;
 ! fields -> end_of_fields ( ) ;
 fields -> next ( ) ) {
 const char * field_name = fields -> name ( ) ;
 if ( table_name != fields -> get_table_name ( ) ) {
 table_name = fields -> get_table_name ( ) ;
 db_name = fields -> get_db_name ( ) ;
 grant = fields -> grant ( ) ;
 want_access = want_access_arg & ~ grant -> privilege ;
 if ( want_access ) {
 if ( grant -> version != grant_version ) {
 grant -> grant_table = table_hash_search ( sctx -> host , sctx -> ip , db_name , sctx -> priv_user , table_name , 0 ) ;
 grant -> version = grant_version ;
 }
 grant_table = grant -> grant_table ;
 DBUG_ASSERT ( grant_table ) ;
 }
 }
 if ( want_access ) {
 GRANT_COLUMN * grant_column = column_hash_search ( grant_table , field_name , ( uint ) strlen ( field_name ) ) ;
 if ( grant_column ) using_column_privileges = TRUE ;
 if ( ! grant_column || ( ~ grant_column -> rights & want_access ) ) goto err ;
 }
 }
 rw_unlock ( & LOCK_grant ) ;
 return 0 ;
 err : rw_unlock ( & LOCK_grant ) ;
 char command [ 128 ] ;
 get_privilege_desc ( command , sizeof ( command ) , want_access ) ;
 if ( using_column_privileges ) my_error ( ER_TABLEACCESS_DENIED_ERROR , MYF ( 0 ) , command , sctx -> priv_user , sctx -> host_or_ip , table_name ) ;
 else my_error ( ER_COLUMNACCESS_DENIED_ERROR , MYF ( 0 ) , command , sctx -> priv_user , sctx -> host_or_ip , fields -> name ( ) , table_name ) ;
 return 1 ;
 }


static int decode_frame ( AVCodecContext * avctx , void * data , int * got_frame , AVPacket * avpkt ) {
 SgiState * s = avctx -> priv_data ;
 AVFrame * picture = data ;
 AVFrame * p = & s -> picture ;
 unsigned int dimension , rle ;
 int ret = 0 ;
 uint8_t * out_buf , * out_end ;
 bytestream2_init ( & s -> g , avpkt -> data , avpkt -> size ) ;
 if ( bytestream2_get_bytes_left ( & s -> g ) < SGI_HEADER_SIZE ) {
 av_log ( avctx , AV_LOG_ERROR , "buf_size too small (%d)\n" , avpkt -> size ) ;
 return AVERROR_INVALIDDATA ;
 }
 if ( bytestream2_get_be16 ( & s -> g ) != SGI_MAGIC ) {
 av_log ( avctx , AV_LOG_ERROR , "bad magic number\n" ) ;
 return AVERROR_INVALIDDATA ;
 }
 rle = bytestream2_get_byte ( & s -> g ) ;
 s -> bytes_per_channel = bytestream2_get_byte ( & s -> g ) ;
 dimension = bytestream2_get_be16 ( & s -> g ) ;
 s -> width = bytestream2_get_be16 ( & s -> g ) ;
 s -> height = bytestream2_get_be16 ( & s -> g ) ;
 s -> depth = bytestream2_get_be16 ( & s -> g ) ;
 if ( s -> bytes_per_channel != 1 && ( s -> bytes_per_channel != 2 || rle ) ) {
 av_log ( avctx , AV_LOG_ERROR , "wrong channel number\n" ) ;
 return - 1 ;
 }
 if ( dimension != 2 && dimension != 3 ) {
 av_log ( avctx , AV_LOG_ERROR , "wrong dimension number\n" ) ;
 return - 1 ;
 }
 if ( s -> depth == SGI_GRAYSCALE ) {
 avctx -> pix_fmt = s -> bytes_per_channel == 2 ? AV_PIX_FMT_GRAY16BE : AV_PIX_FMT_GRAY8 ;
 }
 else if ( s -> depth == SGI_RGB ) {
 avctx -> pix_fmt = s -> bytes_per_channel == 2 ? AV_PIX_FMT_RGB48BE : AV_PIX_FMT_RGB24 ;
 }
 else if ( s -> depth == SGI_RGBA && s -> bytes_per_channel == 1 ) {
 avctx -> pix_fmt = AV_PIX_FMT_RGBA ;
 }
 else {
 av_log ( avctx , AV_LOG_ERROR , "wrong picture format\n" ) ;
 return - 1 ;
 }
 if ( av_image_check_size ( s -> width , s -> height , 0 , avctx ) ) return - 1 ;
 avcodec_set_dimensions ( avctx , s -> width , s -> height ) ;
 if ( p -> data [ 0 ] ) avctx -> release_buffer ( avctx , p ) ;
 p -> reference = 0 ;
 if ( ff_get_buffer ( avctx , p ) < 0 ) {
 av_log ( avctx , AV_LOG_ERROR , "get_buffer() failed.\n" ) ;
 return - 1 ;
 }
 p -> pict_type = AV_PICTURE_TYPE_I ;
 p -> key_frame = 1 ;
 out_buf = p -> data [ 0 ] ;
 out_end = out_buf + p -> linesize [ 0 ] * s -> height ;
 s -> linesize = p -> linesize [ 0 ] ;
 bytestream2_seek ( & s -> g , SGI_HEADER_SIZE , SEEK_SET ) ;
 if ( rle ) {
 ret = read_rle_sgi ( out_end , s ) ;
 }
 else {
 ret = read_uncompressed_sgi ( out_buf , out_end , s ) ;
 }
 if ( ret == 0 ) {
 * picture = s -> picture ;
 * got_frame = 1 ;
 return avpkt -> size ;
 }
 else {
 return ret ;
 }
 }


static int rv34_decode_cbp ( GetBitContext * gb , RV34VLC * vlc , int table ) {
 int pattern , code , cbp = 0 ;
 int ones ;
 static const int cbp_masks [ 3 ] = {
 0x100000 , 0x010000 , 0x110000 }
 ;
 static const int shifts [ 4 ] = {
 0 , 2 , 8 , 10 }
 ;
 const int * curshift = shifts ;
 int i , t , mask ;
 code = get_vlc2 ( gb , vlc -> cbppattern [ table ] . table , 9 , 2 ) ;
 pattern = code & 0xF ;
 code >>= 4 ;
 ones = rv34_count_ones [ pattern ] ;
 for ( mask = 8 ;
 mask ;
 mask >>= 1 , curshift ++ ) {
 if ( pattern & mask ) cbp |= get_vlc2 ( gb , vlc -> cbp [ table ] [ ones ] . table , vlc -> cbp [ table ] [ ones ] . bits , 1 ) << curshift [ 0 ] ;
 }
 for ( i = 0 ;
 i < 4 ;
 i ++ ) {
 t = ( modulo_three_table [ code ] >> ( 6 - 2 * i ) ) & 3 ;
 if ( t == 1 ) cbp |= cbp_masks [ get_bits1 ( gb ) ] << i ;
 if ( t == 2 ) cbp |= cbp_masks [ 2 ] << i ;
 }
 return cbp ;
 }


static void DecoderPlayVideo ( decoder_t * p_dec , picture_t * p_picture , int * pi_played_sum , int * pi_lost_sum ) {
 decoder_owner_sys_t * p_owner = p_dec -> p_owner ;
 vout_thread_t * p_vout = p_owner -> p_vout ;
 if ( p_picture -> date <= VLC_TS_INVALID ) {
 msg_Warn ( p_dec , "non-dated video buffer received" ) ;
 * pi_lost_sum += 1 ;
 vout_ReleasePicture ( p_vout , p_picture ) ;
 return ;
 }
 vlc_mutex_lock ( & p_owner -> lock ) ;
 if ( p_owner -> b_waiting && ! p_owner -> b_first ) {
 p_owner -> b_has_data = true ;
 vlc_cond_signal ( & p_owner -> wait_acknowledge ) ;
 }
 bool b_first_after_wait = p_owner -> b_waiting && p_owner -> b_has_data ;
 bool b_reject = DecoderWaitUnblock ( p_dec ) ;
 if ( p_owner -> b_waiting ) {
 assert ( p_owner -> b_first ) ;
 msg_Dbg ( p_dec , "Received first picture" ) ;
 p_owner -> b_first = false ;
 p_picture -> b_force = true ;
 }
 const bool b_dated = p_picture -> date > VLC_TS_INVALID ;
 int i_rate = INPUT_RATE_DEFAULT ;
 DecoderFixTs ( p_dec , & p_picture -> date , NULL , NULL , & i_rate , DECODER_BOGUS_VIDEO_DELAY ) ;
 vlc_mutex_unlock ( & p_owner -> lock ) ;
 if ( ! p_picture -> b_force && p_picture -> date <= VLC_TS_INVALID ) b_reject = true ;
 if ( ! b_reject ) {
 if ( i_rate != p_owner -> i_last_rate || b_first_after_wait ) {
 vout_Flush ( p_vout , p_picture -> date ) ;
 p_owner -> i_last_rate = i_rate ;
 }
 vout_PutPicture ( p_vout , p_picture ) ;
 }
 else {
 if ( b_dated ) msg_Warn ( p_dec , "early picture skipped" ) ;
 else msg_Warn ( p_dec , "non-dated video buffer received" ) ;
 * pi_lost_sum += 1 ;
 vout_ReleasePicture ( p_vout , p_picture ) ;
 }
 int i_tmp_display ;
 int i_tmp_lost ;
 vout_GetResetStatistic ( p_vout , & i_tmp_display , & i_tmp_lost ) ;
 * pi_played_sum += i_tmp_display ;
 * pi_lost_sum += i_tmp_lost ;
 }


RList *r_bin_ne_get_entrypoints(r_bin_ne_obj_t *bin) {
	RList *entries = r_list_newf (free);
	if (!entries) {
		return NULL;
	}
	RList *segments = r_bin_ne_get_segments (bin);
	if (!segments) {
		r_list_free (entries);
		return NULL;
	}
	if (bin->ne_header->csEntryPoint) {
		RBinAddr *entry = R_NEW0 (RBinAddr);
		if (!entry) {
			r_list_free (entries);
			return NULL;
		}
		entry->bits = 16;
		ut32 entry_cs = bin->ne_header->csEntryPoint;
		RBinSection *s = r_list_get_n (segments, entry_cs - 1);
		entry->paddr = bin->ne_header->ipEntryPoint + (s? s->paddr: 0);

		r_list_append (entries, entry);
	}
	int off = 0;
	size_t tableat = bin->header_offset + bin->ne_header->EntryTableOffset;
	while (off < bin->ne_header->EntryTableLength) {
		if (tableat + off >= r_buf_size (bin->buf)) {
			break;
		}
		ut8 bundle_length = *(ut8 *)(bin->entry_table + off);
		if (!bundle_length) {
			break;
		}
		off++;
		ut8 bundle_type = *(ut8 *)(bin->entry_table + off);
		off++;
		int i;
		for (i = 0; i < bundle_length; i++) {
			if (tableat + off + 4 >= r_buf_size (bin->buf)) {
				break;
			}
			RBinAddr *entry = R_NEW0 (RBinAddr);
			if (!entry) {
				r_list_free (entries);
				return NULL;
			}
			off++;
			if (!bundle_type) { // Skip
				off--;
				free (entry);
				break;
			} else if (bundle_type == 0xff) { // moveable
				off += 2;
				ut8 segnum = *(bin->entry_table + off);
				off++;
				ut16 segoff = *(ut16 *)(bin->entry_table + off);
				if (segnum > 0) {
					entry->paddr = (ut64)bin->segment_entries[segnum - 1].offset * bin->alignment + segoff;
				}
			} else { // Fixed
				if (bundle_type < bin->ne_header->SegCount) {
					entry->paddr = (ut64)bin->segment_entries[bundle_type - 1].offset
						* bin->alignment + *(ut16 *)(bin->entry_table + off);
				}
			}
			off += 2;
			r_list_append (entries, entry);
		}
	}
	r_list_free (segments);
	bin->entries = entries;
	return entries;
}


static void chomp3 ( ChannelData * chd , int16_t * output , uint8_t val , int tab_idx ) {
 int16_t current = read_table ( chd , val , tab_idx ) ;
 current = mace_broken_clip_int16 ( current + chd -> level ) ;
 chd -> level = current - ( current >> 3 ) ;
 * output = QT_8S_2_16S ( current ) ;
 }


static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; if((uint64_t)atom.size > (1<<30)) return -1; if (st->codec->codec_id == CODEC_ID_QDM2) { // pass all frma atom to codec, needed at least for QDM2 av_free(st->codec->extradata); st->codec->extradata_size = atom.size; st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (st->codec->extradata) { get_buffer(pb, st->codec->extradata, atom.size); } else url_fskip(pb, atom.size); } else if (atom.size > 8) { /* to read frma, esds atoms */ mov_read_default(c, pb, atom); } else url_fskip(pb, atom.size); return 0; }


int EVP_CipherInit ( EVP_CIPHER_CTX * ctx , const EVP_CIPHER * cipher , const unsigned char * key , const unsigned char * iv , int enc ) {
 EVP_CIPHER_CTX_reset ( ctx ) ;
 return EVP_CipherInit_ex ( ctx , cipher , NULL , key , iv , enc ) ;
 }


static av_cold void set_bandwidth(AC3EncodeContext *s) { int blk, ch, cpl_start; if (s->cutoff) { /* calculate bandwidth based on user-specified cutoff frequency */ int fbw_coeffs; fbw_coeffs = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate; s->bandwidth_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); } else { /* use default bandwidth setting */ s->bandwidth_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2]; } /* set number of coefficients for each channel */ for (ch = 1; ch <= s->fbw_channels; ch++) { s->start_freq[ch] = 0; for (blk = 0; blk < s->num_blocks; blk++) s->blocks[blk].end_freq[ch] = s->bandwidth_code * 3 + 73; } /* LFE channel always has 7 coefs */ if (s->lfe_on) { s->start_freq[s->lfe_channel] = 0; for (blk = 0; blk < s->num_blocks; blk++) s->blocks[blk].end_freq[ch] = 7; } /* initialize coupling strategy */ if (s->cpl_enabled) { if (s->options.cpl_start != AC3ENC_OPT_AUTO) { cpl_start = s->options.cpl_start; } else { cpl_start = ac3_coupling_start_tab[s->channel_mode-2][s->bit_alloc.sr_code][s->frame_size_code/2]; if (cpl_start < 0) { if (s->options.channel_coupling == AC3ENC_OPT_AUTO) s->cpl_enabled = 0; else cpl_start = 15; } } } if (s->cpl_enabled) { int i, cpl_start_band, cpl_end_band; uint8_t *cpl_band_sizes = s->cpl_band_sizes; cpl_end_band = s->bandwidth_code / 4 + 3; cpl_start_band = av_clip(cpl_start, 0, FFMIN(cpl_end_band-1, 15)); s->num_cpl_subbands = cpl_end_band - cpl_start_band; s->num_cpl_bands = 1; *cpl_band_sizes = 12; for (i = cpl_start_band + 1; i < cpl_end_band; i++) { if (ff_eac3_default_cpl_band_struct[i]) { *cpl_band_sizes += 12; } else { s->num_cpl_bands++; cpl_band_sizes++; *cpl_band_sizes = 12; } } s->start_freq[CPL_CH] = cpl_start_band * 12 + 37; s->cpl_end_freq = cpl_end_band * 12 + 37; for (blk = 0; blk < s->num_blocks; blk++) s->blocks[blk].end_freq[CPL_CH] = s->cpl_end_freq; } }


static void test_tco_defaults(void) { TestData d; d.args = NULL; d.noreboot = true; test_init(&d); g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_RLD), ==, TCO_RLD_DEFAULT); /* TCO_DAT_IN & TCO_DAT_OUT */ g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_DAT_IN), ==, (TCO_DAT_OUT_DEFAULT << 8) | TCO_DAT_IN_DEFAULT); /* TCO1_STS & TCO2_STS */ g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_bar, TCO1_STS), ==, (TCO2_STS_DEFAULT << 16) | TCO1_STS_DEFAULT); /* TCO1_CNT & TCO2_CNT */ g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_bar, TCO1_CNT), ==, (TCO2_CNT_DEFAULT << 16) | TCO1_CNT_DEFAULT); /* TCO_MESSAGE1 & TCO_MESSAGE2 */ g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_MESSAGE1), ==, (TCO_MESSAGE2_DEFAULT << 8) | TCO_MESSAGE1_DEFAULT); g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_bar, TCO_WDCNT), ==, TCO_WDCNT_DEFAULT); g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_bar, SW_IRQ_GEN), ==, SW_IRQ_GEN_DEFAULT); g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_bar, TCO_TMR), ==, TCO_TMR_DEFAULT); qtest_end(); }


evdev_device_destroy(struct evdev_device *device)
{
	struct evdev_dispatch *dispatch;

	dispatch = device->dispatch;
	if (dispatch)
		dispatch->interface->destroy(dispatch);

	if (device->base.group)
		libinput_device_group_unref(device->base.group);

	free(device->output_name);
	filter_destroy(device->pointer.filter);
	libinput_timer_destroy(&device->scroll.timer);
	libinput_timer_destroy(&device->middlebutton.timer);
	libinput_seat_unref(device->base.seat);
	libevdev_free(device->evdev);
	udev_device_unref(device->udev_device);
	free(device);
}


litest_utils_suite(void)
{
	TCase *tc;
	Suite *s;

	s = suite_create("litest:utils");
	tc = tcase_create("utils");

	tcase_add_test(tc, bitfield_helpers);
	tcase_add_test(tc, matrix_helpers);
	tcase_add_test(tc, ratelimit_helpers);
	tcase_add_test(tc, dpi_parser);
	tcase_add_test(tc, wheel_click_parser);
	tcase_add_test(tc, wheel_click_count_parser);
	tcase_add_test(tc, dimension_prop_parser);
	tcase_add_test(tc, reliability_prop_parser);
	tcase_add_test(tc, calibration_prop_parser);
	tcase_add_test(tc, range_prop_parser);
	tcase_add_test(tc, evcode_prop_parser);
	tcase_add_test(tc, input_prop_parser);
	tcase_add_test(tc, evdev_abs_parser);
	tcase_add_test(tc, safe_atoi_test);
	tcase_add_test(tc, safe_atoi_base_16_test);
	tcase_add_test(tc, safe_atoi_base_8_test);
	tcase_add_test(tc, safe_atou_test);
	tcase_add_test(tc, safe_atou_base_16_test);
	tcase_add_test(tc, safe_atou_base_8_test);
	tcase_add_test(tc, safe_atod_test);
	tcase_add_test(tc, strsplit_test);
	tcase_add_test(tc, strargv_test);
	tcase_add_test(tc, kvsplit_double_test);
	tcase_add_test(tc, strjoin_test);
	tcase_add_test(tc, strstrip_test);
	tcase_add_test(tc, strendswith_test);
	tcase_add_test(tc, strstartswith_test);
	tcase_add_test(tc, time_conversion);
	tcase_add_test(tc, human_time);

	tcase_add_test(tc, list_test_insert);
	tcase_add_test(tc, list_test_append);
	tcase_add_test(tc, strverscmp_test);
	tcase_add_test(tc, streq_test);
	tcase_add_test(tc, strneq_test);
	tcase_add_test(tc, trunkname_test);
	tcase_add_test(tc, basename_test);

	suite_add_tcase(s, tc);

	return s;
}


static void gic_set_irq(void *opaque, int irq, int level) { gic_state *s = (gic_state *)opaque; /* The first external input line is internal interrupt 32. */ irq += GIC_INTERNAL; if (level == GIC_TEST_LEVEL(irq, ALL_CPU_MASK)) return; if (level) { GIC_SET_LEVEL(irq, ALL_CPU_MASK); if (GIC_TEST_TRIGGER(irq) || GIC_TEST_ENABLED(irq, ALL_CPU_MASK)) { DPRINTF("Set %d pending mask %x\n", irq, GIC_TARGET(irq)); GIC_SET_PENDING(irq, GIC_TARGET(irq)); } } else { GIC_CLEAR_LEVEL(irq, ALL_CPU_MASK); } gic_update(s); }


litest_utils_suite(void)
{
	TCase *tc;
	Suite *s;

	s = suite_create("litest:utils");
	tc = tcase_create("utils");

	tcase_add_test(tc, bitfield_helpers);
	tcase_add_test(tc, matrix_helpers);
	tcase_add_test(tc, ratelimit_helpers);
	tcase_add_test(tc, dpi_parser);
	tcase_add_test(tc, wheel_click_parser);
	tcase_add_test(tc, wheel_click_count_parser);
	tcase_add_test(tc, dimension_prop_parser);
	tcase_add_test(tc, reliability_prop_parser);
	tcase_add_test(tc, calibration_prop_parser);
	tcase_add_test(tc, range_prop_parser);
	tcase_add_test(tc, boolean_prop_parser);
	tcase_add_test(tc, evcode_prop_parser);
	tcase_add_test(tc, input_prop_parser);
	tcase_add_test(tc, evdev_abs_parser);
	tcase_add_test(tc, safe_atoi_test);
	tcase_add_test(tc, safe_atoi_base_16_test);
	tcase_add_test(tc, safe_atoi_base_8_test);
	tcase_add_test(tc, safe_atou_test);
	tcase_add_test(tc, safe_atou_base_16_test);
	tcase_add_test(tc, safe_atou_base_8_test);
	tcase_add_test(tc, safe_atod_test);
	tcase_add_test(tc, strsplit_test);
	tcase_add_test(tc, strargv_test);
	tcase_add_test(tc, kvsplit_double_test);
	tcase_add_test(tc, strjoin_test);
	tcase_add_test(tc, strstrip_test);
	tcase_add_test(tc, strendswith_test);
	tcase_add_test(tc, strstartswith_test);
	tcase_add_test(tc, time_conversion);
	tcase_add_test(tc, human_time);

	tcase_add_test(tc, list_test_insert);
	tcase_add_test(tc, list_test_append);
	tcase_add_test(tc, list_test_foreach);
	tcase_add_test(tc, strverscmp_test);
	tcase_add_test(tc, streq_test);
	tcase_add_test(tc, strneq_test);
	tcase_add_test(tc, trunkname_test);
	tcase_add_test(tc, basename_test);

	suite_add_tcase(s, tc);

	return s;
}


static void rtrs_clt_dev_release(struct device *dev)
{
	struct rtrs_clt_sess *clt = container_of(dev, struct rtrs_clt_sess,
						 dev);

	kfree(clt);
}


static int32_t scsi_unit_attention(SCSIRequest *req, uint8_t *buf) { if (req->dev && req->dev->unit_attention.key == UNIT_ATTENTION) { scsi_req_build_sense(req, req->dev->unit_attention); } else if (req->bus->unit_attention.key == UNIT_ATTENTION) { scsi_req_build_sense(req, req->bus->unit_attention); } scsi_req_complete(req, CHECK_CONDITION); return 0; }


static int ssl_method_error ( const SSL * s , const SSL_METHOD * method ) {
 int version = method -> version ;
 if ( ( s -> min_proto_version != 0 && version_cmp ( s , version , s -> min_proto_version ) < 0 ) || ssl_security ( s , SSL_SECOP_VERSION , 0 , version , NULL ) == 0 ) return SSL_R_VERSION_TOO_LOW ;
 if ( s -> max_proto_version != 0 && version_cmp ( s , version , s -> max_proto_version ) > 0 ) return SSL_R_VERSION_TOO_HIGH ;
 if ( ( s -> options & method -> mask ) != 0 ) return SSL_R_UNSUPPORTED_PROTOCOL ;
 if ( ( method -> flags & SSL_METHOD_NO_SUITEB ) != 0 && tls1_suiteb ( s ) ) return SSL_R_AT_LEAST_TLS_1_2_NEEDED_IN_SUITEB_MODE ;
 else if ( ( method -> flags & SSL_METHOD_NO_FIPS ) != 0 && FIPS_mode ( ) ) return SSL_R_AT_LEAST_TLS_1_0_NEEDED_IN_FIPS_MODE ;
 return 0 ;
 }


static int io_write(struct io_kiocb *req, unsigned int issue_flags)
{
	struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
	struct kiocb *kiocb = &req->rw.kiocb;
	struct iov_iter __iter, *iter = &__iter;
	struct io_async_rw *rw = req->async_data;
	ssize_t ret, ret2, io_size;
	bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;

	if (rw) {
		iter = &rw->iter;
		iovec = NULL;
	} else {
		ret = io_import_iovec(WRITE, req, &iovec, iter, !force_nonblock);
		if (ret < 0)
			return ret;
	}
	io_size = iov_iter_count(iter);
	req->result = io_size;

	/* Ensure we clear previously set non-block flag */
	if (!force_nonblock)
		kiocb->ki_flags &= ~IOCB_NOWAIT;
	else
		kiocb->ki_flags |= IOCB_NOWAIT;

	/* If the file doesn't support async, just async punt */
	if (force_nonblock && !io_file_supports_async(req, WRITE))
		goto copy_iov;

	/* file path doesn't support NOWAIT for non-direct_IO */
	if (force_nonblock && !(kiocb->ki_flags & IOCB_DIRECT) &&
	    (req->flags & REQ_F_ISREG))
		goto copy_iov;

	ret = rw_verify_area(WRITE, req->file, io_kiocb_ppos(kiocb), io_size);
	if (unlikely(ret))
		goto out_free;

	/*
	 * Open-code file_start_write here to grab freeze protection,
	 * which will be released by another thread in
	 * io_complete_rw().  Fool lockdep by telling it the lock got
	 * released so that it doesn't complain about the held lock when
	 * we return to userspace.
	 */
	if (req->flags & REQ_F_ISREG) {
		sb_start_write(file_inode(req->file)->i_sb);
		__sb_writers_release(file_inode(req->file)->i_sb,
					SB_FREEZE_WRITE);
	}
	kiocb->ki_flags |= IOCB_WRITE;

	if (req->file->f_op->write_iter)
		ret2 = call_write_iter(req->file, kiocb, iter);
	else if (req->file->f_op->write)
		ret2 = loop_rw_iter(WRITE, req, iter);
	else
		ret2 = -EINVAL;

	if (req->flags & REQ_F_REISSUE) {
		req->flags &= ~REQ_F_REISSUE;
		ret2 = -EAGAIN;
	}

	/*
	 * Raw bdev writes will return -EOPNOTSUPP for IOCB_NOWAIT. Just
	 * retry them without IOCB_NOWAIT.
	 */
	if (ret2 == -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT))
		ret2 = -EAGAIN;
	/* no retry on NONBLOCK nor RWF_NOWAIT */
	if (ret2 == -EAGAIN && (req->flags & REQ_F_NOWAIT))
		goto done;
	if (!force_nonblock || ret2 != -EAGAIN) {
		/* IOPOLL retry should happen for io-wq threads */
		if ((req->ctx->flags & IORING_SETUP_IOPOLL) && ret2 == -EAGAIN)
			goto copy_iov;
done:
		kiocb_done(kiocb, ret2, issue_flags);
	} else {
copy_iov:
		/* some cases will consume bytes even on error returns */
		iov_iter_revert(iter, io_size - iov_iter_count(iter));
		ret = io_setup_async_rw(req, iovec, inline_vecs, iter, false);
		return ret ?: -EAGAIN;
	}
out_free:
	/* it's reportedly faster than delegating the null check to kfree() */
	if (iovec)
		kfree(iovec);
	return ret;
}


static int kex_string_pair ( unsigned char * * sp , unsigned char * data , size_t data_len , size_t * lenp , unsigned char * * strp ) {
 unsigned char * s = * sp ;
 * lenp = _libssh2_ntohu32 ( s ) ;
 if ( * lenp > ( data_len - ( s - data ) - 4 ) ) return 1 ;
 * strp = s + 4 ;
 s += 4 + * lenp ;
 * sp = s ;
 return 0 ;
 }


static void _reset ( UConverter * converter , UConverterResetChoice choice , UBool callCallback ) {
 if ( converter == NULL ) {
 return ;
 }
 if ( callCallback ) {
 UErrorCode errorCode ;
 if ( choice <= UCNV_RESET_TO_UNICODE && converter -> fromCharErrorBehaviour != UCNV_TO_U_DEFAULT_CALLBACK ) {
 UConverterToUnicodeArgs toUArgs = {
 sizeof ( UConverterToUnicodeArgs ) , TRUE , NULL , NULL , NULL , NULL , NULL , NULL }
 ;
 toUArgs . converter = converter ;
 errorCode = U_ZERO_ERROR ;
 converter -> fromCharErrorBehaviour ( converter -> toUContext , & toUArgs , NULL , 0 , UCNV_RESET , & errorCode ) ;
 }
 if ( choice != UCNV_RESET_TO_UNICODE && converter -> fromUCharErrorBehaviour != UCNV_FROM_U_DEFAULT_CALLBACK ) {
 UConverterFromUnicodeArgs fromUArgs = {
 sizeof ( UConverterFromUnicodeArgs ) , TRUE , NULL , NULL , NULL , NULL , NULL , NULL }
 ;
 fromUArgs . converter = converter ;
 errorCode = U_ZERO_ERROR ;
 converter -> fromUCharErrorBehaviour ( converter -> fromUContext , & fromUArgs , NULL , 0 , 0 , UCNV_RESET , & errorCode ) ;
 }
 }
 if ( choice <= UCNV_RESET_TO_UNICODE ) {
 converter -> toUnicodeStatus = converter -> sharedData -> toUnicodeStatus ;
 converter -> mode = 0 ;
 converter -> toULength = 0 ;
 converter -> invalidCharLength = converter -> UCharErrorBufferLength = 0 ;
 converter -> preToULength = 0 ;
 }
 if ( choice != UCNV_RESET_TO_UNICODE ) {
 converter -> fromUnicodeStatus = 0 ;
 converter -> fromUChar32 = 0 ;
 converter -> invalidUCharLength = converter -> charErrorBufferLength = 0 ;
 converter -> preFromUFirstCP = U_SENTINEL ;
 converter -> preFromULength = 0 ;
 }
 if ( converter -> sharedData -> impl -> reset != NULL ) {
 converter -> sharedData -> impl -> reset ( converter , choice ) ;
 }
 }


static int pfkey_dump ( struct sock * sk , struct sk_buff * skb , const struct sadb_msg * hdr , void * const * ext_hdrs ) {
 u8 proto ;
 struct pfkey_sock * pfk = pfkey_sk ( sk ) ;
 if ( pfk -> dump . dump != NULL ) return - EBUSY ;
 proto = pfkey_satype2proto ( hdr -> sadb_msg_satype ) ;
 if ( proto == 0 ) return - EINVAL ;
 pfk -> dump . msg_version = hdr -> sadb_msg_version ;
 pfk -> dump . msg_portid = hdr -> sadb_msg_pid ;
 pfk -> dump . dump = pfkey_dump_sa ;
 pfk -> dump . done = pfkey_dump_sa_done ;
 xfrm_state_walk_init ( & pfk -> dump . u . state , proto ) ;
 return pfkey_do_dump ( pfk ) ;
 }


static int decode_cabac_mb_type( H264Context *h ) { MpegEncContext * const s = &h->s; if( h->slice_type == I_TYPE ) { return decode_cabac_intra_mb_type(h, 3, 1); } else if( h->slice_type == P_TYPE ) { if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) { /* P-type */ if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) { /* P_L0_D16x16, P_8x8 */ return 3 * get_cabac( &h->cabac, &h->cabac_state[16] ); } else { /* P_L0_D8x16, P_L0_D16x8 */ return 2 - get_cabac( &h->cabac, &h->cabac_state[17] ); } } else { return decode_cabac_intra_mb_type(h, 17, 0) + 5; } } else if( h->slice_type == B_TYPE ) { const int mba_xy = h->left_mb_xy[0]; const int mbb_xy = h->top_mb_xy; int ctx = 0; int bits; if( h->slice_table[mba_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mba_xy] ) ) ctx++; if( h->slice_table[mbb_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mbb_xy] ) ) ctx++; if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) ) return 0; /* B_Direct_16x16 */ if( !get_cabac( &h->cabac, &h->cabac_state[27+3] ) ) { return 1 + get_cabac( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */ } bits = get_cabac( &h->cabac, &h->cabac_state[27+4] ) << 3; bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 2; bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 1; bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ); if( bits < 8 ) return bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */ else if( bits == 13 ) { return decode_cabac_intra_mb_type(h, 32, 0) + 23; } else if( bits == 14 ) return 11; /* B_L1_L0_8x16 */ else if( bits == 15 ) return 22; /* B_8x8 */ bits= ( bits<<1 ) | get_cabac( &h->cabac, &h->cabac_state[27+5] ); return bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */ } else { /* TODO SI/SP frames? */ return -1; } }


MOBI_RET mobi_reconstruct_infl(char *outstring, const MOBIIndx *infl, const MOBIIndexEntry *orth_entry) {
    const char *label = orth_entry->label;
    uint32_t *infl_groups = NULL;
    size_t infl_count = mobi_get_indxentry_tagarray(&infl_groups, orth_entry, INDX_TAGARR_ORTH_INFL);

    if (infl_count == 0 || !infl_groups) {
        return MOBI_SUCCESS;
    }
    const char *start_tag = "<idx:infl>";
    const char *end_tag = "</idx:infl>";
    const char *iform_tag = "<idx:iform%s value=\"%s\"/>";
    char name_attr[INDX_INFLBUF_SIZEMAX + 1];
    char infl_tag[INDX_INFLBUF_SIZEMAX + 1];
    strcpy(outstring, start_tag);
    size_t initlen = strlen(start_tag) + strlen(end_tag);
    size_t outlen = initlen;
    size_t label_length = strlen(label);
    if (label_length > INDX_INFLBUF_SIZEMAX) {
        debug_print("Entry label too long (%s)\n", label);
        return MOBI_DATA_CORRUPT;
    }
    if (infl->cncx_record == NULL) {
        debug_print("%s\n", "Missing cncx record");
        return MOBI_DATA_CORRUPT;
    }
    for (size_t i = 0; i < infl_count; i++) {
        size_t offset = infl_groups[i];
        if (offset >= infl->entries_count) {
            debug_print("%s\n", "Invalid entry offset");
            return MOBI_DATA_CORRUPT;
        }
        uint32_t *groups;
        size_t group_cnt = mobi_get_indxentry_tagarray(&groups, &infl->entries[offset], INDX_TAGARR_INFL_GROUPS);
        uint32_t *parts;
        size_t part_cnt = mobi_get_indxentry_tagarray(&parts, &infl->entries[offset], INDX_TAGARR_INFL_PARTS_V2);
        if (group_cnt != part_cnt) {
            return MOBI_DATA_CORRUPT;
        }
        for (size_t j = 0; j < part_cnt; j++) {
            name_attr[0] = '\0';
            char *group_name = mobi_get_cncx_string(infl->cncx_record, groups[j]);
            if (group_name == NULL) {
                debug_print("%s\n", "Memory allocation failed");
                return MOBI_MALLOC_FAILED;
            }
            if (strlen(group_name)) {
                snprintf(name_attr, INDX_INFLBUF_SIZEMAX, " name=\"%s\"", group_name);
            }
            free(group_name);

            unsigned char decoded[INDX_INFLBUF_SIZEMAX + 1];
            memset(decoded, 0, INDX_INFLBUF_SIZEMAX + 1);
            unsigned char *rule = (unsigned char *) infl->entries[parts[j]].label;
            memcpy(decoded, label, label_length);
            int decoded_length = (int) label_length;
            MOBI_RET ret = mobi_decode_infl(decoded, &decoded_length, rule);
            if (ret != MOBI_SUCCESS) {
                return ret;
            }
            if (decoded_length == 0) {
                continue;
            }
            int n = snprintf(infl_tag, INDX_INFLBUF_SIZEMAX, iform_tag, name_attr, decoded);
            if (n > INDX_INFLBUF_SIZEMAX) {
                debug_print("Skipping truncated tag: %s\n", infl_tag);
                continue;
            }
            outlen += strlen(infl_tag);
            if (outlen > INDX_INFLTAG_SIZEMAX) {
                debug_print("Inflections text in %s too long (%zu)\n", label, outlen);
                return MOBI_ERROR;
            }
            strcat(outstring, infl_tag);
        }
    }
    if (outlen == initlen) {
        outstring[0] = '\0';
    } else {
        strcat(outstring, end_tag);
    }
    return MOBI_SUCCESS;
}


int do_save_master_pos ( ) {
 MYSQL_RES * res ;
 MYSQL_ROW row ;
 MYSQL * mysql = cur_con -> mysql ;
 const char * query ;
 DBUG_ENTER ( "do_save_master_pos" ) ;
 # ifdef HAVE_NDB_BINLOG {
 ulong have_ndbcluster ;
 if ( mysql_query ( mysql , query = "show variables like 'have_ndbcluster'" ) ) die ( "'%s' failed: %d %s" , query , mysql_errno ( mysql ) , mysql_error ( mysql ) ) ;
 if ( ! ( res = mysql_store_result ( mysql ) ) ) die ( "mysql_store_result() returned NULL for '%s'" , query ) ;
 if ( ! ( row = mysql_fetch_row ( res ) ) ) die ( "Query '%s' returned empty result" , query ) ;
 have_ndbcluster = strcmp ( "YES" , row [ 1 ] ) == 0 ;
 mysql_free_result ( res ) ;
 if ( have_ndbcluster ) {
 ulonglong start_epoch = 0 , handled_epoch = 0 , latest_epoch = 0 , latest_trans_epoch = 0 , latest_handled_binlog_epoch = 0 , latest_received_binlog_epoch = 0 , latest_applied_binlog_epoch = 0 ;
 int count = 0 ;
 int do_continue = 1 ;
 while ( do_continue ) {
 const char binlog [ ] = "binlog" ;
 const char latest_epoch_str [ ] = "latest_epoch=" ;
 const char latest_trans_epoch_str [ ] = "latest_trans_epoch=" ;
 const char latest_received_binlog_epoch_str [ ] = "latest_received_binlog_epoch" ;
 const char latest_handled_binlog_epoch_str [ ] = "latest_handled_binlog_epoch=" ;
 const char latest_applied_binlog_epoch_str [ ] = "latest_applied_binlog_epoch=" ;
 if ( count ) my_sleep ( 100 * 1000 ) ;
 if ( mysql_query ( mysql , query = "show engine ndb status" ) ) die ( "failed in '%s': %d %s" , query , mysql_errno ( mysql ) , mysql_error ( mysql ) ) ;
 if ( ! ( res = mysql_store_result ( mysql ) ) ) die ( "mysql_store_result() returned NULL for '%s'" , query ) ;
 while ( ( row = mysql_fetch_row ( res ) ) ) {
 if ( strcmp ( row [ 1 ] , binlog ) == 0 ) {
 const char * status = row [ 2 ] ;
 while ( * status && strncmp ( status , latest_epoch_str , sizeof ( latest_epoch_str ) - 1 ) ) status ++ ;
 if ( * status ) {
 status += sizeof ( latest_epoch_str ) - 1 ;
 latest_epoch = strtoull ( status , ( char * * ) 0 , 10 ) ;
 }
 else die ( "result does not contain '%s' in '%s'" , latest_epoch_str , query ) ;
 while ( * status && strncmp ( status , latest_trans_epoch_str , sizeof ( latest_trans_epoch_str ) - 1 ) ) status ++ ;
 if ( * status ) {
 status += sizeof ( latest_trans_epoch_str ) - 1 ;
 latest_trans_epoch = strtoull ( status , ( char * * ) 0 , 10 ) ;
 }
 else die ( "result does not contain '%s' in '%s'" , latest_trans_epoch_str , query ) ;
 while ( * status && strncmp ( status , latest_received_binlog_epoch_str , sizeof ( latest_received_binlog_epoch_str ) - 1 ) ) status ++ ;
 if ( * status ) {
 status += sizeof ( latest_received_binlog_epoch_str ) - 1 ;
 latest_received_binlog_epoch = strtoull ( status , ( char * * ) 0 , 10 ) ;
 }
 else die ( "result does not contain '%s' in '%s'" , latest_received_binlog_epoch_str , query ) ;
 while ( * status && strncmp ( status , latest_handled_binlog_epoch_str , sizeof ( latest_handled_binlog_epoch_str ) - 1 ) ) status ++ ;
 if ( * status ) {
 status += sizeof ( latest_handled_binlog_epoch_str ) - 1 ;
 latest_handled_binlog_epoch = strtoull ( status , ( char * * ) 0 , 10 ) ;
 }
 else die ( "result does not contain '%s' in '%s'" , latest_handled_binlog_epoch_str , query ) ;
 while ( * status && strncmp ( status , latest_applied_binlog_epoch_str , sizeof ( latest_applied_binlog_epoch_str ) - 1 ) ) status ++ ;
 if ( * status ) {
 status += sizeof ( latest_applied_binlog_epoch_str ) - 1 ;
 latest_applied_binlog_epoch = strtoull ( status , ( char * * ) 0 , 10 ) ;
 }
 else die ( "result does not contain '%s' in '%s'" , latest_applied_binlog_epoch_str , query ) ;
 if ( count == 0 ) start_epoch = latest_trans_epoch ;
 break ;
 }
 }
 if ( ! row ) die ( "result does not contain '%s' in '%s'" , binlog , query ) ;
 if ( latest_handled_binlog_epoch > handled_epoch ) count = 0 ;
 handled_epoch = latest_handled_binlog_epoch ;
 count ++ ;
 if ( latest_handled_binlog_epoch >= start_epoch ) do_continue = 0 ;
 else if ( count > 300 ) {
 break ;
 }
 mysql_free_result ( res ) ;
 }
 }
 }
 # endif if ( mysql_query ( mysql , query = "show master status" ) ) die ( "failed in 'show master status': %d %s" , mysql_errno ( mysql ) , mysql_error ( mysql ) ) ;
 if ( ! ( res = mysql_store_result ( mysql ) ) ) die ( "mysql_store_result() retuned NULL for '%s'" , query ) ;
 if ( ! ( row = mysql_fetch_row ( res ) ) ) die ( "empty result in show master status" ) ;
 strnmov ( master_pos . file , row [ 0 ] , sizeof ( master_pos . file ) - 1 ) ;
 master_pos . pos = strtoul ( row [ 1 ] , ( char * * ) 0 , 10 ) ;
 mysql_free_result ( res ) ;
 DBUG_RETURN ( 0 ) ;
 }


static int arm946_prbs_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { if (ri->crm >= 8) { return EXCP_UDEF; } env->cp15.c6_region[ri->crm] = value; return 0; }


void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) { QEMUTimerList *timer_list = ts->timer_list; bool rearm; qemu_mutex_lock(&timer_list->active_timers_lock); timer_del_locked(timer_list, ts); rearm = timer_mod_ns_locked(timer_list, ts, expire_time); qemu_mutex_unlock(&timer_list->active_timers_lock); if (rearm) { timerlist_rearm(timer_list); } }


static void virLogSourceUpdate ( virLogSourcePtr source ) {
 virLogLock ( ) ;
 if ( source -> serial < virLogFiltersSerial ) {
 unsigned int priority = virLogDefaultPriority ;
 unsigned int flags = 0 ;
 size_t i ;
 for ( i = 0 ;
 i < virLogNbFilters ;
 i ++ ) {
 if ( strstr ( source -> name , virLogFilters [ i ] -> match ) ) {
 priority = virLogFilters [ i ] -> priority ;
 flags = virLogFilters [ i ] -> flags ;
 break ;
 }
 }
 source -> priority = priority ;
 source -> flags = flags ;
 source -> serial = virLogFiltersSerial ;
 }
 virLogUnlock ( ) ;
 }


void dump_layeringinfo ( jpc_enc_t * enc ) {
 jpc_enc_tcmpt_t * tcmpt ;
 int tcmptno ;
 jpc_enc_rlvl_t * rlvl ;
 int rlvlno ;
 jpc_enc_band_t * band ;
 int bandno ;
 jpc_enc_prc_t * prc ;
 int prcno ;
 jpc_enc_cblk_t * cblk ;
 int cblkno ;
 jpc_enc_pass_t * pass ;
 int passno ;
 int lyrno ;
 jpc_enc_tile_t * tile ;
 tile = enc -> curtile ;
 for ( lyrno = 0 ;
 lyrno < tile -> numlyrs ;
 ++ lyrno ) {
 jas_eprintf ( "lyrno = %02d\n" , lyrno ) ;
 for ( tcmptno = 0 , tcmpt = tile -> tcmpts ;
 tcmptno < tile -> numtcmpts ;
 ++ tcmptno , ++ tcmpt ) {
 for ( rlvlno = 0 , rlvl = tcmpt -> rlvls ;
 rlvlno < tcmpt -> numrlvls ;
 ++ rlvlno , ++ rlvl ) {
 if ( ! rlvl -> bands ) {
 continue ;
 }
 for ( bandno = 0 , band = rlvl -> bands ;
 bandno < rlvl -> numbands ;
 ++ bandno , ++ band ) {
 if ( ! band -> data ) {
 continue ;
 }
 for ( prcno = 0 , prc = band -> prcs ;
 prcno < rlvl -> numprcs ;
 ++ prcno , ++ prc ) {
 if ( ! prc -> cblks ) {
 continue ;
 }
 for ( cblkno = 0 , cblk = prc -> cblks ;
 cblkno < prc -> numcblks ;
 ++ cblkno , ++ cblk ) {
 for ( passno = 0 , pass = cblk -> passes ;
 passno < cblk -> numpasses && pass -> lyrno == lyrno ;
 ++ passno , ++ pass ) {
 jas_eprintf ( "lyrno=%02d cmptno=%02d rlvlno=%02d bandno=%02d prcno=%02d cblkno=%03d passno=%03d\n" , lyrno , tcmptno , rlvlno , bandno , prcno , cblkno , passno ) ;
 }
 }
 }
 }
 }
 }
 }
 }


static void validate_bootdevices(char *devices) { /* We just do some generic consistency checks */ const char *p; int bitmap = 0; for (p = devices; *p != '\0'; p++) { /* Allowed boot devices are: * a-b: floppy disk drives * c-f: IDE disk drives * g-m: machine implementation dependent drives * n-p: network devices * It's up to each machine implementation to check if the given boot * devices match the actual hardware implementation and firmware * features. */ if (*p < 'a' || *p > 'p') { fprintf(stderr, "Invalid boot device '%c'\n", *p); exit(1); } if (bitmap & (1 << (*p - 'a'))) { fprintf(stderr, "Boot device '%c' was given twice\n", *p); exit(1); } bitmap |= 1 << (*p - 'a'); } }


void s390_add_running_cpu(S390CPU *cpu) { CPUState *cs = CPU(cpu); if (cs->halted) { s390_running_cpus++; cs->halted = 0; cs->exception_index = -1; } }


xmlBufGrowInternal(xmlBufPtr buf, size_t len) {
    size_t size;
    xmlChar *newbuf;

    if ((buf == NULL) || (buf->error != 0)) return(0);
    CHECK_COMPAT(buf)

    if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0);
    if (buf->use + len < buf->size)
        return(buf->size - buf->use);

    /*
     * Windows has a BIG problem on realloc timing, so we try to double
     * the buffer size (if that's enough) (bug 146697)
     * Apparently BSD too, and it's probably best for linux too
     * On an embedded system this may be something to change
     */
#if 1
    if (buf->size > (size_t) len)
        size = buf->size * 2;
    else
        size = buf->use + len + 100;
#else
    size = buf->use + len + 100;
#endif

    if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {
        /*
	 * Used to provide parsing limits
	 */
        if ((buf->use + len >= XML_MAX_TEXT_LENGTH) ||
	    (buf->size >= XML_MAX_TEXT_LENGTH)) {
	    xmlBufMemoryError(buf, "buffer error: text too long\n");
	    return(0);
	}
	if (size >= XML_MAX_TEXT_LENGTH)
	    size = XML_MAX_TEXT_LENGTH;
    }
    if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {
        size_t start_buf = buf->content - buf->contentIO;

	newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size);
	if (newbuf == NULL) {
	    xmlBufMemoryError(buf, "growing buffer");
	    return(0);
	}
	buf->contentIO = newbuf;
	buf->content = newbuf + start_buf;
    } else {
	newbuf = (xmlChar *) xmlRealloc(buf->content, size);
	if (newbuf == NULL) {
	    xmlBufMemoryError(buf, "growing buffer");
	    return(0);
	}
	buf->content = newbuf;
    }
    buf->size = size;
    UPDATE_COMPAT(buf)
    return(buf->size - buf->use);
}


xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) {
    unsigned int needSize;

    if ((str == NULL) || (buf == NULL)) {
	return -1;
    }
    if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
    if (len < -1) {
#ifdef DEBUG_BUFFER
        xmlGenericError(xmlGenericErrorContext,
		"xmlBufferAdd: len < 0\n");
#endif
	return -1;
    }
    if (len == 0) return 0;

    if (len < 0)
        len = xmlStrlen(str);

    if (len < 0) return -1;
    if (len == 0) return 0;

    needSize = buf->use + len + 2;
    if (needSize > buf->size){
        if (!xmlBufferResize(buf, needSize)){
	    xmlTreeErrMemory("growing buffer");
            return XML_ERR_NO_MEMORY;
        }
    }

    memmove(&buf->content[buf->use], str, len*sizeof(xmlChar));
    buf->use += len;
    buf->content[buf->use] = 0;
    return 0;
}


IN_PROC_BROWSER_TEST_F ( MimeHandlerViewTest , SingleRequest ) {
 GURL url ( embedded_test_server ( ) -> GetURL ( "/testBasic.csv" ) ) ;
 URLRequestCounter request_counter ( url ) ;
 RunTest ( "testBasic.csv" ) ;
 EXPECT_EQ ( 1 , request_counter . GetCount ( ) ) ;
 }