static void gen_spr_power8_tce_address_control(CPUPPCState *env) { spr_register(env, SPR_TAR, "TAR", &spr_read_generic, &spr_write_generic, &spr_read_generic, &spr_write_generic, 0x00000000); }


static void print_blob_as_hex ( FILE * output_file , const char * str , ulong len ) {
 const char * ptr = str , * end = ptr + len ;
 for ( ;
 ptr < end ;
 ptr ++ ) fprintf ( output_file , "%02X" , * ( ( uchar * ) ptr ) ) ;
 check_io ( output_file ) ;
 }


int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
{
	pud_t *new = pud_alloc_one(mm, address);
	if (!new)
		return -ENOMEM;

	smp_wmb(); /* See comment in __pte_alloc */

	spin_lock(&mm->page_table_lock);
	if (pgd_present(*pgd))		/* Another has populated it */
		pud_free(mm, new);
	else
		pgd_populate(mm, pgd, new);
	spin_unlock(&mm->page_table_lock);
	return 0;
}


void pud_clear_bad(pud_t *pud)
{
	pud_ERROR(*pud);
	pud_clear(pud);
}


static inline uint8_t motion_arg ( motion_vect mot ) {
 uint8_t ax = 8 - ( ( uint8_t ) mot . d [ 0 ] ) ;
 uint8_t ay = 8 - ( ( uint8_t ) mot . d [ 1 ] ) ;
 return ( ( ax & 15 ) << 4 ) | ( ay & 15 ) ;
 }


static int rm_read_seek ( AVFormatContext * s , int stream_index , int64_t pts , int flags ) {
 RMDemuxContext * rm = s -> priv_data ;
 if ( ff_seek_frame_binary ( s , stream_index , pts , flags ) < 0 ) return - 1 ;
 rm -> audio_pkt_cnt = 0 ;
 return 0 ;
 }


static void list_formats(AVFormatContext *ctx, int type) { const struct video_data *s = ctx->priv_data; struct v4l2_fmtdesc vfd = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE }; while(!v4l2_ioctl(s->fd, VIDIOC_ENUM_FMT, &vfd)) { enum AVCodecID codec_id = avpriv_fmt_v4l2codec(vfd.pixelformat); enum AVPixelFormat pix_fmt = avpriv_fmt_v4l2ff(vfd.pixelformat, codec_id); vfd.index++; if (!(vfd.flags & V4L2_FMT_FLAG_COMPRESSED) && type & V4L_RAWFORMATS) { const char *fmt_name = av_get_pix_fmt_name(pix_fmt); av_log(ctx, AV_LOG_INFO, "Raw : %9s : %20s :", fmt_name ? fmt_name : "Unsupported", vfd.description); } else if (vfd.flags & V4L2_FMT_FLAG_COMPRESSED && type & V4L_COMPFORMATS) { AVCodec *codec = avcodec_find_decoder(codec_id); av_log(ctx, AV_LOG_INFO, "Compressed: %9s : %20s :", codec ? codec->name : "Unsupported", vfd.description); } else { continue; } #ifdef V4L2_FMT_FLAG_EMULATED if (vfd.flags & V4L2_FMT_FLAG_EMULATED) av_log(ctx, AV_LOG_INFO, " Emulated :"); #endif #if HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE list_framesizes(ctx, vfd.pixelformat); #endif av_log(ctx, AV_LOG_INFO, "\n"); } }


void print_vma_addr(char *prefix, unsigned long ip)
{
	struct mm_struct *mm = current->mm;
	struct vm_area_struct *vma;

	/*
	 * Do not print if we are in atomic
	 * contexts (in exception stacks, etc.):
	 */
	if (preempt_count())
		return;

	down_read(&mm->mmap_sem);
	vma = find_vma(mm, ip);
	if (vma && vma->vm_file) {
		struct file *f = vma->vm_file;
		char *buf = (char *)__get_free_page(GFP_KERNEL);
		if (buf) {
			char *p, *s;

			p = d_path(&f->f_path, buf, PAGE_SIZE);
			if (IS_ERR(p))
				p = "?";
			s = strrchr(p, '/');
			if (s)
				p = s+1;
			printk("%s%s[%lx+%lx]", prefix, p,
					vma->vm_start,
					vma->vm_end - vma->vm_start);
			free_page((unsigned long)buf);
		}
	}
	up_read(&current->mm->mmap_sem);
}


static int cinepak_decode_strip (CinepakContext *s, cvid_strip *strip, const uint8_t *data, int size) { const uint8_t *eod = (data + size); int chunk_id, chunk_size; /* coordinate sanity checks */ if (strip->x1 >= s->width || strip->x2 > s->width || strip->y1 >= s->height || strip->y2 > s->height || strip->x1 >= strip->x2 || strip->y1 >= strip->y2) return -1; while ((data + 4) <= eod) { chunk_id = data[0]; chunk_size = AV_RB24 (&data[1]) - 4; if(chunk_size < 0) return -1; data += 4; chunk_size = ((data + chunk_size) > eod) ? (eod - data) : chunk_size; switch (chunk_id) { case 0x20: case 0x21: case 0x24: case 0x25: cinepak_decode_codebook (strip->v4_codebook, chunk_id, chunk_size, data); break; case 0x22: case 0x23: case 0x26: case 0x27: cinepak_decode_codebook (strip->v1_codebook, chunk_id, chunk_size, data); break; case 0x30: case 0x31: case 0x32: return cinepak_decode_vectors (s, strip, chunk_id, chunk_size, data); } data += chunk_size; } return -1; }


int buffer_write_bytes ( buffer_t buffer , const char * data , int size ) {
 if ( buffer_write ( buffer , data , size ) ) {
 PyErr_NoMemory ( ) ;
 return 0 ;
 }
 return 1 ;
 }


static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
{
	if (likely(vma->vm_flags & VM_WRITE))
		pte = pte_mkwrite(pte);
	return pte;
}


int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
		unsigned long address, int write_access)
{
	pgd_t *pgd;
	pud_t *pud;
	pmd_t *pmd;
	pte_t *pte;

	__set_current_state(TASK_RUNNING);

	count_vm_event(PGFAULT);

	if (unlikely(is_vm_hugetlb_page(vma)))
		return hugetlb_fault(mm, vma, address, write_access);

	pgd = pgd_offset(mm, address);
	pud = pud_alloc(mm, pgd, address);
	if (!pud)
		return VM_FAULT_OOM;
	pmd = pmd_alloc(mm, pud, address);
	if (!pmd)
		return VM_FAULT_OOM;
	pte = pte_alloc_map(mm, pmd, address);
	if (!pte)
		return VM_FAULT_OOM;

	return handle_pte_fault(mm, vma, address, pte, pmd, write_access);
}


static int paf_video_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt) { PAFVideoDecContext *c = avctx->priv_data; uint8_t code, *dst, *end; int i, frame, ret; if (pkt->size < 2) return AVERROR_INVALIDDATA; bytestream2_init(&c->gb, pkt->data, pkt->size); code = bytestream2_get_byte(&c->gb); if ((code & 0xF) > 4) { avpriv_request_sample(avctx, "unknown/invalid code"); return AVERROR_INVALIDDATA; } if ((ret = ff_reget_buffer(avctx, c->pic)) < 0) return ret; if (code & 0x20) { // frame is keyframe for (i = 0; i < 4; i++) memset(c->frame[i], 0, c->frame_size); memset(c->pic->data[1], 0, AVPALETTE_SIZE); c->current_frame = 0; c->pic->key_frame = 1; c->pic->pict_type = AV_PICTURE_TYPE_I; } else { c->pic->key_frame = 0; c->pic->pict_type = AV_PICTURE_TYPE_P; } if (code & 0x40) { // palette update uint32_t *out = (uint32_t *)c->pic->data[1]; int index, count; index = bytestream2_get_byte(&c->gb); count = bytestream2_get_byte(&c->gb) + 1; if (index + count > 256) return AVERROR_INVALIDDATA; if (bytestream2_get_bytes_left(&c->gb) < 3 * count) return AVERROR_INVALIDDATA; out += index; for (i = 0; i < count; i++) { unsigned r, g, b; r = bytestream2_get_byteu(&c->gb); r = r << 2 | r >> 4; g = bytestream2_get_byteu(&c->gb); g = g << 2 | g >> 4; b = bytestream2_get_byteu(&c->gb); b = b << 2 | b >> 4; *out++ = (0xFFU << 24) | (r << 16) | (g << 8) | b; } c->pic->palette_has_changed = 1; } switch (code & 0x0F) { case 0: /* Block-based motion compensation using 4x4 blocks with either * horizontal or vertical vectors; might incorporate VQ as well. */ if ((ret = decode_0(c, pkt->data, code)) < 0) return ret; break; case 1: /* Uncompressed data. This mode specifies that (width * height) bytes * should be copied directly from the encoded buffer into the output. */ dst = c->frame[c->current_frame]; // possibly chunk length data bytestream2_skip(&c->gb, 2); if (bytestream2_get_bytes_left(&c->gb) < c->video_size) return AVERROR_INVALIDDATA; bytestream2_get_bufferu(&c->gb, dst, c->video_size); break; case 2: /* Copy reference frame: Consume the next byte in the stream as the * reference frame (which should be 0, 1, 2, or 3, and should not be * the same as the current frame number). */ frame = bytestream2_get_byte(&c->gb); if (frame > 3) return AVERROR_INVALIDDATA; if (frame != c->current_frame) memcpy(c->frame[c->current_frame], c->frame[frame], c->frame_size); break; case 4: /* Run length encoding.*/ dst = c->frame[c->current_frame]; end = dst + c->video_size; bytestream2_skip(&c->gb, 2); while (dst < end) { int8_t code; int count; if (bytestream2_get_bytes_left(&c->gb) < 2) return AVERROR_INVALIDDATA; code = bytestream2_get_byteu(&c->gb); count = FFABS(code) + 1; if (dst + count > end) return AVERROR_INVALIDDATA; if (code < 0) memset(dst, bytestream2_get_byteu(&c->gb), count); else bytestream2_get_buffer(&c->gb, dst, count); dst += count; } break; default: av_assert0(0); } av_image_copy_plane(c->pic->data[0], c->pic->linesize[0], c->frame[c->current_frame], c->width, c->width, c->height); c->current_frame = (c->current_frame + 1) & 3; if ((ret = av_frame_ref(data, c->pic)) < 0) return ret; *got_frame = 1; return pkt->size; }


int in_gate_area_no_task(unsigned long addr)
{
	return 0;
}


int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong address, int rw, int access_type) { ppcemb_tlb_t *tlb; target_phys_addr_t raddr; int i, ret, zsel, zpr, pr; ret = -1; raddr = -1; pr = msr_pr; for (i = 0; i < env->nb_tlb; i++) { tlb = &env->tlb[i].tlbe; if (ppcemb_tlb_check(env, tlb, &raddr, address, env->spr[SPR_40x_PID], 0, i) < 0) continue; zsel = (tlb->attr >> 4) & 0xF; zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3; #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "%s: TLB %d zsel %d zpr %d rw %d attr %08x\n", __func__, i, zsel, zpr, rw, tlb->attr); } #endif /* Check execute enable bit */ switch (zpr) { case 0x2: if (pr != 0) goto check_perms; /* No break here */ case 0x3: /* All accesses granted */ ctx->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; ret = 0; break; case 0x0: if (pr != 0) { ctx->prot = 0; ret = -2; break; } /* No break here */ case 0x1: check_perms: /* Check from TLB entry */ /* XXX: there is a problem here or in the TLB fill code... */ ctx->prot = tlb->prot; ctx->prot |= PAGE_EXEC; ret = check_prot(ctx->prot, rw, access_type); break; } if (ret >= 0) { ctx->raddr = raddr; #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "%s: access granted " ADDRX " => " REGX " %d %d\n", __func__, address, ctx->raddr, ctx->prot, ret); } #endif return 0; } } #if defined (DEBUG_SOFTWARE_TLB) if (loglevel != 0) { fprintf(logfile, "%s: access refused " ADDRX " => " REGX " %d %d\n", __func__, address, raddr, ctx->prot, ret); } #endif return ret; }


static void qemu_kvm_start_vcpu ( CPUState * cpu ) {
 cpu -> thread = g_malloc0 ( sizeof ( QemuThread ) ) ;
 cpu -> halt_cond = g_malloc0 ( sizeof ( QemuCond ) ) ;
 qemu_cond_init ( cpu -> halt_cond ) ;
 qemu_thread_create ( cpu -> thread , qemu_kvm_cpu_thread_fn , cpu , QEMU_THREAD_JOINABLE ) ;
 while ( ! cpu -> created ) {
 qemu_cond_wait ( & qemu_cpu_cond , & qemu_global_mutex ) ;
 }
 }


static inline void add_mm_rss(struct mm_struct *mm, int file_rss, int anon_rss)
{
	if (file_rss)
		add_mm_counter(mm, file_rss, file_rss);
	if (anon_rss)
		add_mm_counter(mm, anon_rss, anon_rss);
}


int bdrv_get_dirty(BlockDriverState *bs, int64_t sector) { int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK; if (bs->dirty_bitmap != NULL && (sector << BDRV_SECTOR_BITS) <= bdrv_getlength(bs)) { return bs->dirty_bitmap[chunk]; } else { return 0; } }


static void stream_component_close(VideoState *is, int stream_index) { AVFormatContext *ic = is->ic; AVCodecContext *avctx; if (stream_index < 0 || stream_index >= ic->nb_streams) return; avctx = ic->streams[stream_index]->codec; switch (avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: packet_queue_abort(&is->audioq); SDL_CloseAudio(); packet_queue_flush(&is->audioq); av_free_packet(&is->audio_pkt); if (is->swr_ctx) swr_free(&is->swr_ctx); av_freep(&is->audio_buf1); is->audio_buf = NULL; av_freep(&is->frame); if (is->rdft) { av_rdft_end(is->rdft); av_freep(&is->rdft_data); is->rdft = NULL; is->rdft_bits = 0; } break; case AVMEDIA_TYPE_VIDEO: packet_queue_abort(&is->videoq); /* note: we also signal this mutex to make sure we deblock the video thread in all cases */ SDL_LockMutex(is->pictq_mutex); SDL_CondSignal(is->pictq_cond); SDL_UnlockMutex(is->pictq_mutex); SDL_WaitThread(is->video_tid, NULL); packet_queue_flush(&is->videoq); break; case AVMEDIA_TYPE_SUBTITLE: packet_queue_abort(&is->subtitleq); /* note: we also signal this mutex to make sure we deblock the video thread in all cases */ SDL_LockMutex(is->subpq_mutex); is->subtitle_stream_changed = 1; SDL_CondSignal(is->subpq_cond); SDL_UnlockMutex(is->subpq_mutex); SDL_WaitThread(is->subtitle_tid, NULL); packet_queue_flush(&is->subtitleq); break; default: break; } ic->streams[stream_index]->discard = AVDISCARD_ALL; avcodec_close(avctx); #if CONFIG_AVFILTER free_buffer_pool(&is->buffer_pool); #endif switch (avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: is->audio_st = NULL; is->audio_stream = -1; break; case AVMEDIA_TYPE_VIDEO: is->video_st = NULL; is->video_stream = -1; break; case AVMEDIA_TYPE_SUBTITLE: is->subtitle_st = NULL; is->subtitle_stream = -1; break; default: break; } }


static void vp8_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *curframe, VP8Frame *prev_frame) { VP8Context *s = avctx->priv_data; int mb_x, mb_y; s->mv_min.y = -MARGIN; s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN; for (mb_y = 0; mb_y < s->mb_height; mb_y++) { VP8Macroblock *mb = s->macroblocks_base + ((s->mb_width + 1) * (mb_y + 1) + 1); int mb_xy = mb_y * s->mb_width; AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED * 0x01010101); s->mv_min.x = -MARGIN; s->mv_max.x = ((s->mb_width - 1) << 6) + MARGIN; for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) { if (mb_y == 0) AV_WN32A((mb - s->mb_width - 1)->intra4x4_pred_mode_top, DC_PRED * 0x01010101); decode_mb_mode(s, mb, mb_x, mb_y, curframe->seg_map->data + mb_xy, prev_frame && prev_frame->seg_map ? prev_frame->seg_map->data + mb_xy : NULL, 1); s->mv_min.x -= 64; s->mv_max.x -= 64; } s->mv_min.y -= 64; s->mv_max.y -= 64; } }


int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
{
	pgtable_t new = pte_alloc_one(mm, address);
	if (!new)
		return -ENOMEM;

	/*
	 * Ensure all pte setup (eg. pte page lock and page clearing) are
	 * visible before the pte is made visible to other CPUs by being
	 * put into page tables.
	 *
	 * The other side of the story is the pointer chasing in the page
	 * table walking code (when walking the page table without locking;
	 * ie. most of the time). Fortunately, these data accesses consist
	 * of a chain of data-dependent loads, meaning most CPUs (alpha
	 * being the notable exception) will already guarantee loads are
	 * seen in-order. See the alpha page table accessors for the
	 * smp_read_barrier_depends() barriers in page table walking code.
	 */
	smp_wmb(); /* Could be smp_wmb__xxx(before|after)_spin_lock */

	spin_lock(&mm->page_table_lock);
	if (!pmd_present(*pmd)) {	/* Has another populated it ? */
		mm->nr_ptes++;
		pmd_populate(mm, pmd, new);
		new = NULL;
	}
	spin_unlock(&mm->page_table_lock);
	if (new)
		pte_free(mm, new);
	return 0;
}


static int __init gate_vma_init(void)
{
	gate_vma.vm_mm = NULL;
	gate_vma.vm_start = FIXADDR_USER_START;
	gate_vma.vm_end = FIXADDR_USER_END;
	gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
	gate_vma.vm_page_prot = __P101;
	/*
	 * Make sure the vDSO gets into every core dump.
	 * Dumping its contents makes post-mortem fully interpretable later
	 * without matching up the same kernel and hardware config to see
	 * what PC values meant.
	 */
	gate_vma.vm_flags |= VM_ALWAYSDUMP;
	return 0;
}


static int dissect_rsl_ie_phy_ctx ( tvbuff_t * tvb , packet_info * pinfo _U_ , proto_tree * tree , int offset , gboolean is_mandatory ) {
 proto_item * ti ;
 proto_tree * ie_tree ;
 guint length ;
 guint8 ie_id ;
 if ( is_mandatory == FALSE ) {
 ie_id = tvb_get_guint8 ( tvb , offset ) ;
 if ( ie_id != RSL_IE_PHY_CTX ) return offset ;
 }
 ie_tree = proto_tree_add_subtree ( tree , tvb , offset , 0 , ett_ie_phy_ctx , & ti , "Physical Context IE " ) ;
 proto_tree_add_item ( ie_tree , hf_rsl_ie_id , tvb , offset , 1 , ENC_BIG_ENDIAN ) ;
 offset ++ ;
 length = tvb_get_guint8 ( tvb , offset ) ;
 proto_item_set_len ( ti , length + 2 ) ;
 proto_tree_add_item ( ie_tree , hf_rsl_ie_length , tvb , offset , 1 , ENC_BIG_ENDIAN ) ;
 offset ++ ;
 proto_tree_add_item ( ie_tree , hf_rsl_phy_ctx , tvb , offset , length , ENC_NA ) ;
 offset = offset + length ;
 return offset ;
 }


int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
			unsigned long pfn)
{
	/*
	 * Technically, architectures with pte_special can avoid all these
	 * restrictions (same for remap_pfn_range).  However we would like
	 * consistency in testing and feature parity among all, so we should
	 * try to keep these invariants in place for everybody.
	 */
	BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)));
	BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) ==
						(VM_PFNMAP|VM_MIXEDMAP));
	BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags));
	BUG_ON((vma->vm_flags & VM_MIXEDMAP) && pfn_valid(pfn));

	if (addr < vma->vm_start || addr >= vma->vm_end)
		return -EFAULT;
	return insert_pfn(vma, addr, pfn, vma->vm_page_prot);
}


TSReturnCode TSHttpTxnHookRegisteredFor ( TSHttpTxn txnp , TSHttpHookID id , TSEventFunc funcp ) {
 HttpSM * sm = ( HttpSM * ) txnp ;
 APIHook * hook = sm -> txn_hook_get ( id ) ;
 while ( hook != nullptr ) {
 if ( hook -> m_cont && hook -> m_cont -> m_event_func == funcp ) {
 return TS_SUCCESS ;
 }
 hook = hook -> m_link . next ;
 }
 return TS_ERROR ;
 }


void jpc_qmfb_join_row ( jpc_fix_t * a , int numcols , int parity ) {
 int bufsize = JPC_CEILDIVPOW2 ( numcols , 1 ) ;
 jpc_fix_t joinbuf [ QMFB_JOINBUFSIZE ] ;
 jpc_fix_t * buf = joinbuf ;
 register jpc_fix_t * srcptr ;
 register jpc_fix_t * dstptr ;
 register int n ;
 int hstartcol ;
 if ( bufsize > QMFB_JOINBUFSIZE ) {
 if ( ! ( buf = jas_alloc2 ( bufsize , sizeof ( jpc_fix_t ) ) ) ) {
 abort ( ) ;
 }
 }
 hstartcol = ( numcols + 1 - parity ) >> 1 ;
 n = hstartcol ;
 srcptr = & a [ 0 ] ;
 dstptr = buf ;
 while ( n -- > 0 ) {
 * dstptr = * srcptr ;
 ++ srcptr ;
 ++ dstptr ;
 }
 srcptr = & a [ hstartcol ] ;
 dstptr = & a [ 1 - parity ] ;
 n = numcols - hstartcol ;
 while ( n -- > 0 ) {
 * dstptr = * srcptr ;
 dstptr += 2 ;
 ++ srcptr ;
 }
 srcptr = buf ;
 dstptr = & a [ parity ] ;
 n = hstartcol ;
 while ( n -- > 0 ) {
 * dstptr = * srcptr ;
 dstptr += 2 ;
 ++ srcptr ;
 }
 if ( buf != joinbuf ) {
 jas_free ( buf ) ;
 }
 }


static void setup_features ( VP8_COMP * cpi ) {
 if ( cpi -> mb . e_mbd . segmentation_enabled ) {
 cpi -> mb . e_mbd . update_mb_segmentation_map = 1 ;
 cpi -> mb . e_mbd . update_mb_segmentation_data = 1 ;
 }
 else {
 cpi -> mb . e_mbd . update_mb_segmentation_map = 0 ;
 cpi -> mb . e_mbd . update_mb_segmentation_data = 0 ;
 }
 cpi -> mb . e_mbd . mode_ref_lf_delta_enabled = 0 ;
 cpi -> mb . e_mbd . mode_ref_lf_delta_update = 0 ;
 vpx_memset ( cpi -> mb . e_mbd . ref_lf_deltas , 0 , sizeof ( cpi -> mb . e_mbd . ref_lf_deltas ) ) ;
 vpx_memset ( cpi -> mb . e_mbd . mode_lf_deltas , 0 , sizeof ( cpi -> mb . e_mbd . mode_lf_deltas ) ) ;
 vpx_memset ( cpi -> mb . e_mbd . last_ref_lf_deltas , 0 , sizeof ( cpi -> mb . e_mbd . ref_lf_deltas ) ) ;
 vpx_memset ( cpi -> mb . e_mbd . last_mode_lf_deltas , 0 , sizeof ( cpi -> mb . e_mbd . mode_lf_deltas ) ) ;
 set_default_lf_deltas ( cpi ) ;
 }


static int float64_is_unordered(int sig, float64 a, float64 b STATUS_PARAM) { if (float64_is_signaling_nan(a) || float64_is_signaling_nan(b) || (sig && (float64_is_nan(a) || float64_is_nan(b)))) { float_raise(float_flag_invalid, status); return 1; } else if (float64_is_nan(a) || float64_is_nan(b)) { return 1; } else { return 0; } }


static void gen_ldarx(DisasContext *ctx) { TCGv t0; gen_set_access_type(ctx, ACCESS_RES); t0 = tcg_temp_local_new(); gen_addr_reg_index(ctx, t0); gen_check_align(ctx, t0, 0x07); gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], t0); tcg_gen_mov_tl(cpu_reserve, t0); tcg_temp_free(t0); }


static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOSCSI *s = (VirtIOSCSI *)vdev; VirtIOSCSIReq *req; while ((req = virtio_scsi_pop_req(s, vq))) { int type; if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0, &type, sizeof(type)) < sizeof(type)) { virtio_scsi_bad_req(); continue; } tswap32s(&req->req.tmf->type); if (req->req.tmf->type == VIRTIO_SCSI_T_TMF) { if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlTMFReq), sizeof(VirtIOSCSICtrlTMFResp)) < 0) { virtio_scsi_bad_req(); } else { virtio_scsi_do_tmf(s, req); } } else if (req->req.tmf->type == VIRTIO_SCSI_T_AN_QUERY || req->req.tmf->type == VIRTIO_SCSI_T_AN_SUBSCRIBE) { if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlANReq), sizeof(VirtIOSCSICtrlANResp)) < 0) { virtio_scsi_bad_req(); } else { req->resp.an->event_actual = 0; req->resp.an->response = VIRTIO_SCSI_S_OK; } } virtio_scsi_complete_req(req); } }


static const char * flat_escape_value_str ( AVBPrint * dst , const char * src ) {
 const char * p ;
 for ( p = src ;
 * p ;
 p ++ ) {
 switch ( * p ) {
 case '\n' : av_bprintf ( dst , "%s" , "\\n" ) ;
 break ;
 case '\r' : av_bprintf ( dst , "%s" , "\\r" ) ;
 break ;
 case '\\' : av_bprintf ( dst , "%s" , "\\\\" ) ;
 break ;
 case '"' : av_bprintf ( dst , "%s" , "\\\"" ) ;
 break ;
 case '`' : av_bprintf ( dst , "%s" , "\\`" ) ;
 break ;
 case '$' : av_bprintf ( dst , "%s" , "\\$" ) ;
 break ;
 default : av_bprint_chars ( dst , * p , 1 ) ;
 break ;
 }
 }
 return dst -> str ;
 }


unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address,
		unsigned long size, struct zap_details *details)
{
	struct mm_struct *mm = vma->vm_mm;
	struct mmu_gather *tlb;
	unsigned long end = address + size;
	unsigned long nr_accounted = 0;

	lru_add_drain();
	tlb = tlb_gather_mmu(mm, 0);
	update_hiwater_rss(mm);
	end = unmap_vmas(&tlb, vma, address, end, &nr_accounted, details);
	if (tlb)
		tlb_finish_mmu(tlb, address, end);
	return end;
}


static void s390_virtio_bus_register_withprop ( VirtIOS390DeviceInfo * info ) {
 info -> qdev . init = s390_virtio_busdev_init ;
 info -> qdev . bus_info = & s390_virtio_bus_info ;
 assert ( info -> qdev . size >= sizeof ( VirtIOS390Device ) ) ;
 qdev_register ( & info -> qdev ) ;
 }


static int execute_command(BlockDriverState *bdrv, SCSIGenericReq *r, int direction, BlockDriverCompletionFunc *complete) { SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, r->req.dev); r->io_header.interface_id = 'S'; r->io_header.dxfer_direction = direction; r->io_header.dxferp = r->buf; r->io_header.dxfer_len = r->buflen; r->io_header.cmdp = r->req.cmd.buf; r->io_header.cmd_len = r->req.cmd.len; r->io_header.mx_sb_len = sizeof(s->sensebuf); r->io_header.sbp = s->sensebuf; r->io_header.timeout = MAX_UINT; r->io_header.usr_ptr = r; r->io_header.flags |= SG_FLAG_DIRECT_IO; r->req.aiocb = bdrv_aio_ioctl(bdrv, SG_IO, &r->io_header, complete, r); if (r->req.aiocb == NULL) { BADF("execute_command: read failed !\n"); return -1; } return 0; }


static int get_int8(QEMUFile *f, void *pv, size_t size) { int8_t *v = pv; qemu_get_s8s(f, v); return 0; }


static void alljoyn_typeid ( gchar * result , guint32 type ) {
 g_snprintf ( result , ITEM_LABEL_LENGTH , "'%c' => " , type ) ;
 }


static void remove_migration_ptes(struct page *old, struct page *new)
{
	if (PageAnon(new))
		remove_anon_migration_ptes(old, new);
	else
		remove_file_migration_ptes(old, new);
}


void cpu_breakpoint_remove_all(CPUState *env, int mask) { #if defined(TARGET_HAS_ICE) CPUBreakpoint *bp, *next; TAILQ_FOREACH_SAFE(bp, &env->breakpoints, entry, next) { if (bp->flags & mask) cpu_breakpoint_remove_by_ref(env, bp); } #endif }


static __init void vdso_setup_trampolines(struct lib32_elfinfo *v32,
					  struct lib64_elfinfo *v64)
{
	/*
	 * Find signal trampolines
	 */

#ifdef CONFIG_PPC64
	vdso64_rt_sigtramp = find_function64(v64, "__kernel_sigtramp_rt64");
#endif
	vdso32_sigtramp	   = find_function32(v32, "__kernel_sigtramp32");
	vdso32_rt_sigtramp = find_function32(v32, "__kernel_sigtramp_rt32");
}


static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
		unsigned long address, pmd_t *pmd,
		pgoff_t pgoff, unsigned int flags, pte_t orig_pte)
{
	pte_t *page_table;
	spinlock_t *ptl;
	struct page *page;
	pte_t entry;
	int anon = 0;
	struct page *dirty_page = NULL;
	struct vm_fault vmf;
	int ret;
	int page_mkwrite = 0;

	vmf.virtual_address = (void __user *)(address & PAGE_MASK);
	vmf.pgoff = pgoff;
	vmf.flags = flags;
	vmf.page = NULL;

	ret = vma->vm_ops->fault(vma, &vmf);
	if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
		return ret;

	/*
	 * For consistency in subsequent calls, make the faulted page always
	 * locked.
	 */
	if (unlikely(!(ret & VM_FAULT_LOCKED)))
		lock_page(vmf.page);
	else
		VM_BUG_ON(!PageLocked(vmf.page));

	/*
	 * Should we do an early C-O-W break?
	 */
	page = vmf.page;
	if (flags & FAULT_FLAG_WRITE) {
		if (!(vma->vm_flags & VM_SHARED)) {
			anon = 1;
			if (unlikely(anon_vma_prepare(vma))) {
				ret = VM_FAULT_OOM;
				goto out;
			}
			page = alloc_page_vma(GFP_HIGHUSER_MOVABLE,
						vma, address);
			if (!page) {
				ret = VM_FAULT_OOM;
				goto out;
			}
			copy_user_highpage(page, vmf.page, address, vma);
			__SetPageUptodate(page);
		} else {
			/*
			 * If the page will be shareable, see if the backing
			 * address space wants to know that the page is about
			 * to become writable
			 */
			if (vma->vm_ops->page_mkwrite) {
				unlock_page(page);
				if (vma->vm_ops->page_mkwrite(vma, page) < 0) {
					ret = VM_FAULT_SIGBUS;
					anon = 1; /* no anon but release vmf.page */
					goto out_unlocked;
				}
				lock_page(page);
				/*
				 * XXX: this is not quite right (racy vs
				 * invalidate) to unlock and relock the page
				 * like this, however a better fix requires
				 * reworking page_mkwrite locking API, which
				 * is better done later.
				 */
				if (!page->mapping) {
					ret = 0;
					anon = 1; /* no anon but release vmf.page */
					goto out;
				}
				page_mkwrite = 1;
			}
		}

	}

	if (mem_cgroup_charge(page, mm, GFP_KERNEL)) {
		ret = VM_FAULT_OOM;
		goto out;
	}

	page_table = pte_offset_map_lock(mm, pmd, address, &ptl);

	/*
	 * This silly early PAGE_DIRTY setting removes a race
	 * due to the bad i386 page protection. But it's valid
	 * for other architectures too.
	 *
	 * Note that if write_access is true, we either now have
	 * an exclusive copy of the page, or this is a shared mapping,
	 * so we can make it writable and dirty to avoid having to
	 * handle that later.
	 */
	/* Only go through if we didn't race with anybody else... */
	if (likely(pte_same(*page_table, orig_pte))) {
		flush_icache_page(vma, page);
		entry = mk_pte(page, vma->vm_page_prot);
		if (flags & FAULT_FLAG_WRITE)
			entry = maybe_mkwrite(pte_mkdirty(entry), vma);
		set_pte_at(mm, address, page_table, entry);
		if (anon) {
                        inc_mm_counter(mm, anon_rss);
                        lru_cache_add_active(page);
                        page_add_new_anon_rmap(page, vma, address);
		} else {
			inc_mm_counter(mm, file_rss);
			page_add_file_rmap(page);
			if (flags & FAULT_FLAG_WRITE) {
				dirty_page = page;
				get_page(dirty_page);
			}
		}

		/* no need to invalidate: a not-present page won't be cached */
		update_mmu_cache(vma, address, entry);
	} else {
		mem_cgroup_uncharge_page(page);
		if (anon)
			page_cache_release(page);
		else
			anon = 1; /* no anon but release faulted_page */
	}

	pte_unmap_unlock(page_table, ptl);

out:
	unlock_page(vmf.page);
out_unlocked:
	if (anon)
		page_cache_release(vmf.page);
	else if (dirty_page) {
		if (vma->vm_file)
			file_update_time(vma->vm_file);

		set_page_dirty_balance(dirty_page, page_mkwrite);
		put_page(dirty_page);
	}

	return ret;
}


static int migrate_page_move_mapping(struct address_space *mapping,
		struct page *newpage, struct page *page)
{
	void **pslot;

	if (!mapping) {
		/* Anonymous page without mapping */
		if (page_count(page) != 1)
			return -EAGAIN;
		return 0;
	}

	write_lock_irq(&mapping->tree_lock);

	pslot = radix_tree_lookup_slot(&mapping->page_tree,
 					page_index(page));

	if (page_count(page) != 2 + !!PagePrivate(page) ||
			(struct page *)radix_tree_deref_slot(pslot) != page) {
		write_unlock_irq(&mapping->tree_lock);
		return -EAGAIN;
	}

	/*
	 * Now we know that no one else is looking at the page.
	 */
	get_page(newpage);	/* add cache reference */
#ifdef CONFIG_SWAP
	if (PageSwapCache(page)) {
		SetPageSwapCache(newpage);
		set_page_private(newpage, page_private(page));
	}
#endif

	radix_tree_replace_slot(pslot, newpage);

	/*
	 * Drop cache reference from old page.
	 * We know this isn't the last reference.
	 */
	__put_page(page);

	/*
	 * If moved to a different zone then also account
	 * the page for that zone. Other VM counters will be
	 * taken care of when we establish references to the
	 * new page and drop references to the old page.
	 *
	 * Note that anonymous pages are accounted for
	 * via NR_FILE_PAGES and NR_ANON_PAGES if they
	 * are mapped to swap space.
	 */
	__dec_zone_page_state(page, NR_FILE_PAGES);
	__inc_zone_page_state(newpage, NR_FILE_PAGES);

	write_unlock_irq(&mapping->tree_lock);

	return 0;
}


void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
			struct vfsmount *child_mnt)
{
	child_mnt->mnt_parent = mntget(mnt);
	child_mnt->mnt_mountpoint = dget(dentry);
	dentry->d_mounted++;
}


static void omap_id_write(void *opaque, target_phys_addr_t addr, uint64_t value, unsigned size) { if (size != 4) { return omap_badwidth_write32(opaque, addr, value); } OMAP_BAD_REG(addr); }


static void omap_tcmi_init(MemoryRegion *memory, target_phys_addr_t base, struct omap_mpu_state_s *mpu) { memory_region_init_io(&mpu->tcmi_iomem, &omap_tcmi_ops, mpu, "omap-tcmi", 0x100); memory_region_add_subregion(memory, base, &mpu->tcmi_iomem); omap_tcmi_reset(mpu); }


struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
					int flag)
{
	struct vfsmount *res, *p, *q, *r, *s;
	struct nameidata nd;

	if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt))
		return NULL;

	res = q = clone_mnt(mnt, dentry, flag);
	if (!q)
		goto Enomem;
	q->mnt_mountpoint = mnt->mnt_mountpoint;

	p = mnt;
	list_for_each_entry(r, &mnt->mnt_mounts, mnt_child) {
		if (!lives_below_in_same_fs(r->mnt_mountpoint, dentry))
			continue;

		for (s = r; s; s = next_mnt(s, r)) {
			if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(s)) {
				s = skip_mnt_tree(s);
				continue;
			}
			while (p != s->mnt_parent) {
				p = p->mnt_parent;
				q = q->mnt_parent;
			}
			p = s;
			nd.mnt = q;
			nd.dentry = p->mnt_mountpoint;
			q = clone_mnt(p, p->mnt_root, flag);
			if (!q)
				goto Enomem;
			spin_lock(&vfsmount_lock);
			list_add_tail(&q->mnt_list, &res->mnt_list);
			attach_mnt(q, &nd);
			spin_unlock(&vfsmount_lock);
		}
	}
	return res;
Enomem:
	if (res) {
		LIST_HEAD(umount_list);
		spin_lock(&vfsmount_lock);
		umount_tree(res, 0, &umount_list);
		spin_unlock(&vfsmount_lock);
		release_mounts(&umount_list);
	}
	return NULL;
}


static void processEncodingEntry ( ArchiveHandle * AH , TocEntry * te ) {
 char * defn = pg_strdup ( te -> defn ) ;
 char * ptr1 ;
 char * ptr2 = NULL ;
 int encoding ;
 ptr1 = strchr ( defn , '\'' ) ;
 if ( ptr1 ) ptr2 = strchr ( ++ ptr1 , '\'' ) ;
 if ( ptr2 ) {
 * ptr2 = '\0' ;
 encoding = pg_char_to_encoding ( ptr1 ) ;
 if ( encoding < 0 ) exit_horribly ( modulename , "unrecognized encoding \"%s\"\n" , ptr1 ) ;
 AH -> public . encoding = encoding ;
 }
 else exit_horribly ( modulename , "invalid ENCODING item: %s\n" , te -> defn ) ;
 free ( defn ) ;
 }


void append_field ( DYNAMIC_STRING * ds , uint col_idx , MYSQL_FIELD * field , char * val , ulonglong len , my_bool is_null ) {
 char null [ ] = "NULL" ;
 if ( col_idx < max_replace_column && replace_column [ col_idx ] ) {
 val = replace_column [ col_idx ] ;
 len = strlen ( val ) ;
 }
 else if ( is_null ) {
 val = null ;
 len = 4 ;
 }
 # ifdef __WIN__ else if ( ( field -> type == MYSQL_TYPE_DOUBLE || field -> type == MYSQL_TYPE_FLOAT ) && field -> decimals >= 31 ) {
 char * start = strchr ( val , 'e' ) ;
 if ( start && strlen ( start ) >= 5 && ( start [ 1 ] == '-' || start [ 1 ] == '+' ) && start [ 2 ] == '0' ) {
 start += 2 ;
 if ( field -> flags & ZEROFILL_FLAG ) {
 memmove ( val + 1 , val , start - val ) ;
 * val = '0' ;
 }
 else {
 memmove ( start , start + 1 , strlen ( start ) ) ;
 len -- ;
 }
 }
 }
 # endif if ( ! display_result_vertically ) {
 if ( col_idx ) dynstr_append_mem ( ds , "\t" , 1 ) ;
 replace_dynstr_append_mem ( ds , val , ( int ) len ) ;
 }
 else {
 dynstr_append ( ds , field -> name ) ;
 dynstr_append_mem ( ds , "\t" , 1 ) ;
 replace_dynstr_append_mem ( ds , val , ( int ) len ) ;
 dynstr_append_mem ( ds , "\n" , 1 ) ;
 }
 }


int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
		 int mnt_flags, struct list_head *fslist)
{
	int err;

	down_write(&namespace_sem);
	/* Something was mounted here while we slept */
	while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
		;
	err = -EINVAL;
	if (!check_mnt(nd->mnt))
		goto unlock;

	/* Refuse the same filesystem on the same mount point */
	err = -EBUSY;
	if (nd->mnt->mnt_sb == newmnt->mnt_sb &&
	    nd->mnt->mnt_root == nd->dentry)
		goto unlock;

	err = -EINVAL;
	if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
		goto unlock;

	newmnt->mnt_flags = mnt_flags;
	if ((err = graft_tree(newmnt, nd)))
		goto unlock;

	if (fslist) {
		/* add to the specified expiration list */
		spin_lock(&vfsmount_lock);
		list_add_tail(&newmnt->mnt_expire, fslist);
		spin_unlock(&vfsmount_lock);
	}
	up_write(&namespace_sem);
	return 0;

unlock:
	up_write(&namespace_sem);
	mntput(newmnt);
	return err;
}


void appendStringLiteralDQ ( PQExpBuffer buf , const char * str , const char * dqprefix ) {
 static const char suffixes [ ] = "_XXXXXXX" ;
 int nextchar = 0 ;
 PQExpBuffer delimBuf = createPQExpBuffer ( ) ;
 appendPQExpBufferChar ( delimBuf , '$' ) ;
 if ( dqprefix ) appendPQExpBufferStr ( delimBuf , dqprefix ) ;
 while ( strstr ( str , delimBuf -> data ) != NULL ) {
 appendPQExpBufferChar ( delimBuf , suffixes [ nextchar ++ ] ) ;
 nextchar %= sizeof ( suffixes ) - 1 ;
 }
 appendPQExpBufferChar ( delimBuf , '$' ) ;
 appendPQExpBufferStr ( buf , delimBuf -> data ) ;
 appendPQExpBufferStr ( buf , str ) ;
 appendPQExpBufferStr ( buf , delimBuf -> data ) ;
 destroyPQExpBuffer ( delimBuf ) ;
 }


static void event_scan(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { uint32_t mask, buf, len, event_len; sPAPREventLogEntry *event; struct rtas_error_log *hdr; if (nargs != 4 || nret != 1) { rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); return; } mask = rtas_ld(args, 0); buf = rtas_ld(args, 2); len = rtas_ld(args, 3); event = rtas_event_log_dequeue(mask, false); if (!event) { goto out_no_events; } hdr = event->data; event_len = be32_to_cpu(hdr->extended_length) + sizeof(*hdr); if (event_len < len) { len = event_len; } cpu_physical_memory_write(buf, event->data, len); rtas_st(rets, 0, RTAS_OUT_SUCCESS); g_free(event->data); g_free(event); return; out_no_events: rtas_st(rets, 0, RTAS_OUT_NO_ERRORS_FOUND); }


void event_loop(void) { SDL_Event event; double incr, pos, frac; for(;;) { SDL_WaitEvent(&event); switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_q: do_exit(); break; case SDLK_f: toggle_full_screen(); break; case SDLK_p: case SDLK_SPACE: toggle_pause(); break; case SDLK_s: //S: Step to next frame step_to_next_frame(); break; case SDLK_a: if (cur_stream) stream_cycle_channel(cur_stream, CODEC_TYPE_AUDIO); break; case SDLK_v: if (cur_stream) stream_cycle_channel(cur_stream, CODEC_TYPE_VIDEO); break; case SDLK_w: toggle_audio_display(); break; case SDLK_LEFT: incr = -10.0; goto do_seek; case SDLK_RIGHT: incr = 10.0; goto do_seek; case SDLK_UP: incr = 60.0; goto do_seek; case SDLK_DOWN: incr = -60.0; do_seek: if (cur_stream) { pos = get_master_clock(cur_stream); printf("%f %f %d %d %d %d\n", (float)pos, (float)incr, cur_stream->av_sync_type == AV_SYNC_VIDEO_MASTER, cur_stream->av_sync_type == AV_SYNC_AUDIO_MASTER, cur_stream->video_st, cur_stream->audio_st); pos += incr; stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE)); } break; default: break; } break; case SDL_MOUSEBUTTONDOWN: if (cur_stream) { int ns, hh, mm, ss; int tns, thh, tmm, tss; tns = cur_stream->ic->duration/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); frac = (double)event.button.x/(double)cur_stream->width; ns = frac*tns; hh = ns/3600; mm = (ns%3600)/60; ss = (ns%60); fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100, hh, mm, ss, thh, tmm, tss); stream_seek(cur_stream, (int64_t)(cur_stream->ic->start_time+frac*cur_stream->ic->duration)); } break; case SDL_VIDEORESIZE: if (cur_stream) { screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); cur_stream->width = event.resize.w; cur_stream->height = event.resize.h; } break; case SDL_QUIT: case FF_QUIT_EVENT: do_exit(); break; case FF_ALLOC_EVENT: alloc_picture(event.user.data1); break; case FF_REFRESH_EVENT: video_refresh_timer(event.user.data1); break; default: break; } } }


static void dumpttf ( FILE * ttf , struct alltabs * at ) {
 int32 checksum ;
 int i , head_index = - 1 ;
 putlong ( ttf , at -> tabdir . version ) ;
 putshort ( ttf , at -> tabdir . numtab ) ;
 putshort ( ttf , at -> tabdir . searchRange ) ;
 putshort ( ttf , at -> tabdir . entrySel ) ;
 putshort ( ttf , at -> tabdir . rangeShift ) ;
 for ( i = 0 ;
 i < at -> tabdir . numtab ;
 ++ i ) {
 if ( at -> tabdir . alpha [ i ] -> tag == CHR ( 'h' , 'e' , 'a' , 'd' ) || at -> tabdir . alpha [ i ] -> tag == CHR ( 'b' , 'h' , 'e' , 'd' ) ) head_index = i ;
 putlong ( ttf , at -> tabdir . alpha [ i ] -> tag ) ;
 putlong ( ttf , at -> tabdir . alpha [ i ] -> checksum ) ;
 putlong ( ttf , at -> tabdir . alpha [ i ] -> offset ) ;
 putlong ( ttf , at -> tabdir . alpha [ i ] -> length ) ;
 }
 for ( i = 0 ;
 i < at -> tabdir . numtab ;
 ++ i ) if ( at -> tabdir . ordered [ i ] -> data != NULL ) {
 if ( ! ttfcopyfile ( ttf , at -> tabdir . ordered [ i ] -> data , at -> tabdir . ordered [ i ] -> offset , Tag2String ( at -> tabdir . ordered [ i ] -> tag ) ) ) at -> error = true ;
 }
 if ( head_index != - 1 ) {
 checksum = filechecksum ( ttf ) ;
 checksum = 0xb1b0afba - checksum ;
 fseek ( ttf , at -> tabdir . alpha [ head_index ] -> offset + 2 * sizeof ( int32 ) , SEEK_SET ) ;
 putlong ( ttf , checksum ) ;
 }
 }


long do_mount(char *dev_name, char *dir_name, char *type_page,
		  unsigned long flags, void *data_page)
{
	struct nameidata nd;
	int retval = 0;
	int mnt_flags = 0;

	/* Discard magic */
	if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
		flags &= ~MS_MGC_MSK;

	/* Basic sanity checks */

	if (!dir_name || !*dir_name || !memchr(dir_name, 0, PAGE_SIZE))
		return -EINVAL;
	if (dev_name && !memchr(dev_name, 0, PAGE_SIZE))
		return -EINVAL;

	if (data_page)
		((char *)data_page)[PAGE_SIZE - 1] = 0;

	/* Separate the per-mountpoint flags */
	if (flags & MS_NOSUID)
		mnt_flags |= MNT_NOSUID;
	if (flags & MS_NODEV)
		mnt_flags |= MNT_NODEV;
	if (flags & MS_NOEXEC)
		mnt_flags |= MNT_NOEXEC;
	if (flags & MS_NOATIME)
		mnt_flags |= MNT_NOATIME;
	if (flags & MS_NODIRATIME)
		mnt_flags |= MNT_NODIRATIME;
	if (flags & MS_RELATIME)
		mnt_flags |= MNT_RELATIME;

	flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
		   MS_NOATIME | MS_NODIRATIME | MS_RELATIME);

	/* ... and get the mountpoint */
	retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
	if (retval)
		return retval;

	retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
	if (retval)
		goto dput_out;

	if (flags & MS_REMOUNT)
		retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
				    data_page);
	else if (flags & MS_BIND)
		retval = do_loopback(&nd, dev_name, flags & MS_REC);
	else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
		retval = do_change_type(&nd, flags);
	else if (flags & MS_MOVE)
		retval = do_move_mount(&nd, dev_name);
	else
		retval = do_new_mount(&nd, type_page, flags, mnt_flags,
				      dev_name, data_page);
dput_out:
	path_release(&nd);
	return retval;
}


static int mov_write_ilst_tag(AVIOContext *pb, MOVMuxContext *mov, AVFormatContext *s) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "ilst"); mov_write_string_metadata(s, pb, "\251nam", "title" , 1); mov_write_string_metadata(s, pb, "\251ART", "artist" , 1); mov_write_string_metadata(s, pb, "aART", "album_artist", 1); mov_write_string_metadata(s, pb, "\251wrt", "composer" , 1); mov_write_string_metadata(s, pb, "\251alb", "album" , 1); mov_write_string_metadata(s, pb, "\251day", "date" , 1); mov_write_string_tag(pb, "\251too", LIBAVFORMAT_IDENT, 0, 1); mov_write_string_metadata(s, pb, "\251cmt", "comment" , 1); mov_write_string_metadata(s, pb, "\251gen", "genre" , 1); mov_write_string_metadata(s, pb, "\251cpy", "copyright", 1); mov_write_string_metadata(s, pb, "\251grp", "grouping" , 1); mov_write_string_metadata(s, pb, "\251lyr", "lyrics" , 1); mov_write_string_metadata(s, pb, "desc", "description",1); mov_write_string_metadata(s, pb, "ldes", "synopsis" , 1); mov_write_string_metadata(s, pb, "tvsh", "show" , 1); mov_write_string_metadata(s, pb, "tven", "episode_id",1); mov_write_string_metadata(s, pb, "tvnn", "network" , 1); mov_write_trkn_tag(pb, mov, s); return update_size(pb, pos); }


void free_vfsmnt(struct vfsmount *mnt)
{
	kfree(mnt->mnt_devname);
	kmem_cache_free(mnt_cache, mnt);
}


void shrink_submounts(struct vfsmount *mountpoint, struct list_head *mounts)
{
	LIST_HEAD(graveyard);
	int found;

	spin_lock(&vfsmount_lock);

	/* extract submounts of 'mountpoint' from the expiration list */
	while ((found = select_submounts(mountpoint, &graveyard)) != 0)
		expire_mount_list(&graveyard, mounts);

	spin_unlock(&vfsmount_lock);
}


static struct vfsmount *skip_mnt_tree(struct vfsmount *p)
{
	struct list_head *prev = p->mnt_mounts.prev;
	while (prev != &p->mnt_mounts) {
		p = list_entry(prev, struct vfsmount, mnt_child);
		prev = p->mnt_mounts.prev;
	}
	return p;
}


long do_sigreturn(CPUAlphaState *env) { struct target_sigcontext *sc; abi_ulong sc_addr = env->ir[IR_A0]; target_sigset_t target_set; sigset_t set; if (!lock_user_struct(VERIFY_READ, sc, sc_addr, 1)) { goto badframe; } target_sigemptyset(&target_set); __get_user(target_set.sig[0], &sc->sc_mask); target_to_host_sigset_internal(&set, &target_set); do_sigprocmask(SIG_SETMASK, &set, NULL); restore_sigcontext(env, sc); unlock_user_struct(sc, sc_addr, 0); return env->ir[IR_V0]; badframe: force_sig(TARGET_SIGSEGV); }


static void filter_mirror_setup(NetFilterState *nf, Error **errp) { MirrorState *s = FILTER_MIRROR(nf); if (!s->outdev) { error_setg(errp, "filter filter mirror needs 'outdev' " "property set"); return; } s->chr_out = qemu_chr_find(s->outdev); if (s->chr_out == NULL) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", s->outdev); return; } if (qemu_chr_fe_claim(s->chr_out) != 0) { error_setg(errp, QERR_DEVICE_IN_USE, s->outdev); return; } }


static int xmlLinkCompare ( const void * data0 , const void * data1 ) {
 if ( data0 < data1 ) return ( - 1 ) ;
 else if ( data0 == data1 ) return ( 0 ) ;
 return ( 1 ) ;
 }


static inline void e1000e_autoneg_pause ( E1000ECore * core ) {
 timer_del ( core -> autoneg_timer ) ;
 }


struct vfsmount *alloc_vfsmnt(const char *name)
{
	struct vfsmount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL);
	if (mnt) {
		atomic_set(&mnt->mnt_count, 1);
		INIT_LIST_HEAD(&mnt->mnt_hash);
		INIT_LIST_HEAD(&mnt->mnt_child);
		INIT_LIST_HEAD(&mnt->mnt_mounts);
		INIT_LIST_HEAD(&mnt->mnt_list);
		INIT_LIST_HEAD(&mnt->mnt_expire);
		INIT_LIST_HEAD(&mnt->mnt_share);
		INIT_LIST_HEAD(&mnt->mnt_slave_list);
		INIT_LIST_HEAD(&mnt->mnt_slave);
		if (name) {
			int size = strlen(name) + 1;
			char *newname = kmalloc(size, GFP_KERNEL);
			if (newname) {
				memcpy(newname, name, size);
				mnt->mnt_devname = newname;
			}
		}
	}
	return mnt;
}


static int write_object(int fd, char *buf, uint64_t oid, int copies, unsigned int datalen, uint64_t offset, bool create, bool cache) { return read_write_object(fd, buf, oid, copies, datalen, offset, true, create, cache); }


static void check_for_jsonb_9_4_usage ( ClusterInfo * cluster ) {
 int dbnum ;
 FILE * script = NULL ;
 bool found = false ;
 char output_path [ MAXPGPATH ] ;
 prep_status ( "Checking for JSONB user data types" ) ;
 snprintf ( output_path , sizeof ( output_path ) , "tables_using_jsonb.txt" ) ;
 for ( dbnum = 0 ;
 dbnum < cluster -> dbarr . ndbs ;
 dbnum ++ ) {
 PGresult * res ;
 bool db_used = false ;
 int ntups ;
 int rowno ;
 int i_nspname , i_relname , i_attname ;
 DbInfo * active_db = & cluster -> dbarr . dbs [ dbnum ] ;
 PGconn * conn = connectToServer ( cluster , active_db -> db_name ) ;
 res = executeQueryOrDie ( conn , "SELECT n.nspname, c.relname, a.attname " "FROM pg_catalog.pg_class c, " " pg_catalog.pg_namespace n, " " pg_catalog.pg_attribute a " "WHERE c.oid = a.attrelid AND " " NOT a.attisdropped AND " " a.atttypid = 'pg_catalog.jsonb'::pg_catalog.regtype AND " " c.relnamespace = n.oid AND " " n.nspname !~ '^pg_temp_' AND " " n.nspname NOT IN ('pg_catalog', 'information_schema')" ) ;
 ntups = PQntuples ( res ) ;
 i_nspname = PQfnumber ( res , "nspname" ) ;
 i_relname = PQfnumber ( res , "relname" ) ;
 i_attname = PQfnumber ( res , "attname" ) ;
 for ( rowno = 0 ;
 rowno < ntups ;
 rowno ++ ) {
 found = true ;
 if ( script == NULL && ( script = fopen_priv ( output_path , "w" ) ) == NULL ) pg_fatal ( "Could not open file \"%s\": %s\n" , output_path , getErrorText ( ) ) ;
 if ( ! db_used ) {
 fprintf ( script , "Database: %s\n" , active_db -> db_name ) ;
 db_used = true ;
 }
 fprintf ( script , " %s.%s.%s\n" , PQgetvalue ( res , rowno , i_nspname ) , PQgetvalue ( res , rowno , i_relname ) , PQgetvalue ( res , rowno , i_attname ) ) ;
 }
 PQclear ( res ) ;
 PQfinish ( conn ) ;
 }
 if ( script ) fclose ( script ) ;
 if ( found ) {
 pg_log ( PG_REPORT , "fatal\n" ) ;
 pg_fatal ( "Your installation contains one of the JSONB data types in user tables.\n" "The internal format of JSONB changed during 9.4 beta so this cluster cannot currently\n" "be upgraded. You can remove the problem tables and restart the upgrade. A list\n" "of the problem columns is in the file:\n" " %s\n\n" , output_path ) ;
 }
 else check_ok ( ) ;
 }


static void git_pack_config ( void ) {
 int indexversion_value ;
 unsigned long packsizelimit_value ;
 if ( ! git_config_get_ulong ( "pack.depth" , & max_depth ) ) {
 if ( max_depth > MAX_DEPTH ) max_depth = MAX_DEPTH ;
 }
 if ( ! git_config_get_int ( "pack.compression" , & pack_compression_level ) ) {
 if ( pack_compression_level == - 1 ) pack_compression_level = Z_DEFAULT_COMPRESSION ;
 else if ( pack_compression_level < 0 || pack_compression_level > Z_BEST_COMPRESSION ) git_die_config ( "pack.compression" , "bad pack compression level %d" , pack_compression_level ) ;
 pack_compression_seen = 1 ;
 }
 if ( ! git_config_get_int ( "pack.indexversion" , & indexversion_value ) ) {
 pack_idx_opts . version = indexversion_value ;
 if ( pack_idx_opts . version > 2 ) git_die_config ( "pack.indexversion" , "bad pack.indexversion=%" PRIu32 , pack_idx_opts . version ) ;
 }
 if ( ! git_config_get_ulong ( "pack.packsizelimit" , & packsizelimit_value ) ) max_packsize = packsizelimit_value ;
 git_config ( git_default_config , NULL ) ;
 }


static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrUSrc, const int16_t *chrVSrc, const int16_t *alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW) { int p= 4; const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW }; uint8_t *dst[4]= { aDest, dest, uDest, vDest }; x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW }; while (p--) { if (dst[p]) { __asm__ volatile( "mov %2, %%"REG_a" \n\t" ".p2align 4 \n\t" /* FIXME Unroll? */ "1: \n\t" "movq (%0, %%"REG_a", 2), %%mm0 \n\t" "movq 8(%0, %%"REG_a", 2), %%mm1 \n\t" "psraw $7, %%mm0 \n\t" "psraw $7, %%mm1 \n\t" "packuswb %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%1, %%REGa)) "add $8, %%"REG_a" \n\t" "jnc 1b \n\t" :: "r" (src[p]), "r" (dst[p] + counter[p]), "g" (-counter[p]) : "%"REG_a ); } } }


static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size) { register const uint8_t* s=src; register uint8_t* d=dst; register const uint8_t *end; const uint8_t *mm_end; end = s + src_size; #if COMPILE_TEMPLATE_MMX __asm__ volatile(PREFETCH" %0"::"m"(*s)); __asm__ volatile("movq %0, %%mm4"::"m"(mask15s)); mm_end = end - 15; while (s<mm_end) { __asm__ volatile( PREFETCH" 32%1 \n\t" "movq %1, %%mm0 \n\t" "movq 8%1, %%mm2 \n\t" "movq %%mm0, %%mm1 \n\t" "movq %%mm2, %%mm3 \n\t" "pand %%mm4, %%mm0 \n\t" "pand %%mm4, %%mm2 \n\t" "paddw %%mm1, %%mm0 \n\t" "paddw %%mm3, %%mm2 \n\t" MOVNTQ" %%mm0, %0 \n\t" MOVNTQ" %%mm2, 8%0" :"=m"(*d) :"m"(*s) ); d+=16; s+=16; } __asm__ volatile(SFENCE:::"memory"); __asm__ volatile(EMMS:::"memory"); #endif mm_end = end - 3; while (s < mm_end) { register unsigned x= *((const uint32_t *)s); *((uint32_t *)d) = (x&0x7FFF7FFF) + (x&0x7FE07FE0); d+=4; s+=4; } if (s < end) { register unsigned short x= *((const uint16_t *)s); *((uint16_t *)d) = (x&0x7FFF) + (x&0x7FE0); } }


static void DupTagList ( struct _cmsContext_struct * ctx , const struct _cmsContext_struct * src ) {
 _cmsTagPluginChunkType newHead = {
 NULL }
 ;
 _cmsTagLinkedList * entry ;
 _cmsTagLinkedList * Anterior = NULL ;
 _cmsTagPluginChunkType * head = ( _cmsTagPluginChunkType * ) src -> chunks [ TagPlugin ] ;
 for ( entry = head -> Tag ;
 entry != NULL ;
 entry = entry -> Next ) {
 _cmsTagLinkedList * newEntry = ( _cmsTagLinkedList * ) _cmsSubAllocDup ( ctx -> MemPool , entry , sizeof ( _cmsTagLinkedList ) ) ;
 if ( newEntry == NULL ) return ;
 newEntry -> Next = NULL ;
 if ( Anterior ) Anterior -> Next = newEntry ;
 Anterior = newEntry ;
 if ( newHead . Tag == NULL ) newHead . Tag = newEntry ;
 }
 ctx -> chunks [ TagPlugin ] = _cmsSubAllocDup ( ctx -> MemPool , & newHead , sizeof ( _cmsTagPluginChunkType ) ) ;
 }


static inline void SetPixelBlackTraits ( Image * image , const PixelTrait traits ) {
 image -> channel_map [ BlackPixelChannel ] . traits = traits ;
 }


void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf, int buf_size, int slice_count) { struct vdpau_render_state *render, *last, *next; int i; render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; assert(render); /* fill VdpPictureInfoMPEG1Or2 struct */ render->info.mpeg.picture_structure = s->picture_structure; render->info.mpeg.picture_coding_type = s->pict_type; render->info.mpeg.intra_dc_precision = s->intra_dc_precision; render->info.mpeg.frame_pred_frame_dct = s->frame_pred_frame_dct; render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors; render->info.mpeg.intra_vlc_format = s->intra_vlc_format; render->info.mpeg.alternate_scan = s->alternate_scan; render->info.mpeg.q_scale_type = s->q_scale_type; render->info.mpeg.top_field_first = s->top_field_first; render->info.mpeg.full_pel_forward_vector = s->full_pel[0]; // MPEG-1 only. Set 0 for MPEG-2 render->info.mpeg.full_pel_backward_vector = s->full_pel[1]; // MPEG-1 only. Set 0 for MPEG-2 render->info.mpeg.f_code[0][0] = s->mpeg_f_code[0][0]; // For MPEG-1 fill both horiz. & vert. render->info.mpeg.f_code[0][1] = s->mpeg_f_code[0][1]; render->info.mpeg.f_code[1][0] = s->mpeg_f_code[1][0]; render->info.mpeg.f_code[1][1] = s->mpeg_f_code[1][1]; for (i = 0; i < 64; ++i) { render->info.mpeg.intra_quantizer_matrix[i] = s->intra_matrix[i]; render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i]; } render->info.mpeg.forward_reference = VDP_INVALID_HANDLE; render->info.mpeg.backward_reference = VDP_INVALID_HANDLE; switch(s->pict_type){ case FF_B_TYPE: next = (struct vdpau_render_state *)s->next_picture.data[0]; assert(next); render->info.mpeg.backward_reference = next->surface; // no return here, going to set forward prediction case FF_P_TYPE: last = (struct vdpau_render_state *)s->last_picture.data[0]; if (!last) // FIXME: Does this test make sense? last = render; // predict second field from the first render->info.mpeg.forward_reference = last->surface; } ff_vdpau_add_data_chunk(s, buf, buf_size); render->info.mpeg.slice_count = slice_count; if (slice_count) ff_draw_horiz_band(s, 0, s->avctx->height); render->bitstream_buffers_used = 0; }


static int close_f(int argc, char **argv) { bdrv_close(bs); bs = NULL; return 0; }


static void pty_chr_state(CharDriverState *chr, int connected) { PtyCharDriver *s = chr->opaque; if (!connected) { if (s->fd_tag) { io_remove_watch_poll(s->fd_tag); s->fd_tag = 0; } s->connected = 0; /* (re-)connect poll interval for idle guests: once per second. * We check more frequently in case the guests sends data to * the virtual device linked to our pty. */ pty_chr_rearm_timer(chr, 1000); } else { if (s->timer_tag) { g_source_remove(s->timer_tag); s->timer_tag = 0; } if (!s->connected) { qemu_chr_be_generic_open(chr); s->connected = 1; s->fd_tag = io_add_watch_poll(s->fd, pty_chr_read_poll, pty_chr_read, chr); } } }


int compat_udp_setsockopt(struct sock *sk, int level, int optname,
			  char __user *optval, int optlen)
{
	if (level == SOL_UDP  ||  level == SOL_UDPLITE)
		return udp_lib_setsockopt(sk, level, optname, optval, optlen,
					  udp_push_pending_frames);
	return compat_ip_setsockopt(sk, level, optname, optval, optlen);
}


static void dumpblankglyph ( struct glyphinfo * gi , SplineFont * sf , int fixedwidth ) {
 int advance = gi -> next_glyph == 1 ? 0 : fixedwidth <= 0 ? ( sf -> ascent + sf -> descent ) / 3 : fixedwidth ;
 gi -> pointcounts [ gi -> next_glyph ] = 0 ;
 gi -> loca [ gi -> next_glyph ++ ] = ftell ( gi -> glyphs ) ;
 putshort ( gi -> hmtx , advance ) ;
 putshort ( gi -> hmtx , 0 ) ;
 if ( sf -> hasvmetrics ) {
 putshort ( gi -> vmtx , gi -> next_glyph == 2 ? 0 : ( sf -> ascent + sf -> descent ) ) ;
 putshort ( gi -> vmtx , 0 ) ;
 }
 }


static void zynq_xadc_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) { ZynqXADCState *s = (ZynqXADCState *)opaque; int reg = offset / 4; int xadc_reg; int xadc_cmd; int xadc_data; if (!zynq_xadc_check_offset(reg, false)) { qemu_log_mask(LOG_GUEST_ERROR, "zynq_xadc: Invalid write access " "to addr %" HWADDR_PRIx "\n", offset); return; } switch (reg) { case CFG: s->regs[CFG] = val; break; case INT_STS: s->regs[INT_STS] &= ~val; break; case INT_MASK: s->regs[INT_MASK] = val & INT_ALL; break; case CMDFIFO: xadc_cmd = extract32(val, 26, 4); xadc_reg = extract32(val, 16, 10); xadc_data = extract32(val, 0, 16); if (s->regs[MCTL] & MCTL_RESET) { qemu_log_mask(LOG_GUEST_ERROR, "zynq_xadc: Sending command " "while comm channel held in reset: %" PRIx32 "\n", (uint32_t) val); break; } if (xadc_reg > ZYNQ_XADC_NUM_ADC_REGS && xadc_cmd != CMD_NOP) { qemu_log_mask(LOG_GUEST_ERROR, "read/write op to invalid xadc " "reg 0x%x\n", xadc_reg); break; } switch (xadc_cmd) { case CMD_READ: xadc_push_dfifo(s, s->xadc_regs[xadc_reg]); break; case CMD_WRITE: s->xadc_regs[xadc_reg] = xadc_data; /* fallthrough */ case CMD_NOP: xadc_push_dfifo(s, 0); break; } break; case MCTL: s->regs[MCTL] = val & 0x00fffeff; break; } zynq_xadc_update_ints(s); }


static inline void gen_set_Rc0 (DisasContext *ctx) { gen_op_cmpi(0); gen_op_set_Rc0(); }


VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf) { VirtIOBlock *s; int cylinders, heads, secs; static int virtio_blk_id; DriveInfo *dinfo; if (!conf->bs) { error_report("virtio-blk-pci: drive property not set"); s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config), sizeof(VirtIOBlock)); s->vdev.get_config = virtio_blk_update_config; s->vdev.get_features = virtio_blk_get_features; s->vdev.reset = virtio_blk_reset; s->bs = conf->bs; s->conf = conf; s->rq = NULL; s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1; bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); /* NB: per existing s/n string convention the string is terminated * by '\0' only when less than sizeof (s->sn) */ dinfo = drive_get_by_blockdev(s->bs); strncpy(s->sn, dinfo->serial, sizeof (s->sn)); s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output); qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s); register_savevm(dev, "virtio-blk", virtio_blk_id++, 2, virtio_blk_save, virtio_blk_load, s); bdrv_set_removable(s->bs, 0); return &s->vdev;


static int write_directory_descriptors ( struct archive_write * a , struct vdd * vdd ) {
 struct isoent * np ;
 int depth , r ;
 depth = 0 ;
 np = vdd -> rootent ;
 do {
 struct extr_rec * extr ;
 r = _write_directory_descriptors ( a , vdd , np , depth ) ;
 if ( r < 0 ) return ( r ) ;
 if ( vdd -> vdd_type != VDD_JOLIET ) {
 for ( extr = np -> extr_rec_list . first ;
 extr != NULL ;
 extr = extr -> next ) {
 unsigned char * wb ;
 wb = wb_buffptr ( a ) ;
 memcpy ( wb , extr -> buf , extr -> offset ) ;
 memset ( wb + extr -> offset , 0 , LOGICAL_BLOCK_SIZE - extr -> offset ) ;
 r = wb_consume ( a , LOGICAL_BLOCK_SIZE ) ;
 if ( r < 0 ) return ( r ) ;
 }
 }
 if ( np -> subdirs . first != NULL && depth + 1 < vdd -> max_depth ) {
 np = np -> subdirs . first ;
 depth ++ ;
 continue ;
 }
 while ( np != np -> parent ) {
 if ( np -> drnext == NULL ) {
 np = np -> parent ;
 depth -- ;
 }
 else {
 np = np -> drnext ;
 break ;
 }
 }
 }
 while ( np != np -> parent ) ;
 return ( ARCHIVE_OK ) ;
 }


static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
{
	struct udp_iter_state *state = seq->private;

	do {
		sk = sk_next(sk);
try_again:
		;
	} while (sk && sk->sk_family != state->family);

	if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
		sk = sk_head(state->hashtable + state->bucket);
		goto try_again;
	}
	return sk;
}


int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl) { unsigned int first_mb_in_slice; unsigned int pps_id; int ret; unsigned int slice_type, tmp, i, j; int last_pic_structure, last_pic_droppable; int must_reinit; int needs_reinit = 0; int field_pic_flag, bottom_field_flag; int first_slice = sl == h->slice_ctx && !h->current_slice; int frame_num, picture_structure, droppable; PPS *pps; h->qpel_put = h->h264qpel.put_h264_qpel_pixels_tab; h->qpel_avg = h->h264qpel.avg_h264_qpel_pixels_tab; first_mb_in_slice = get_ue_golomb_long(&sl->gb); if (first_mb_in_slice == 0) { // FIXME better field boundary detection if (h->current_slice) { if (h->cur_pic_ptr && FIELD_PICTURE(h) && h->first_field) { ff_h264_field_end(h, sl, 1); h->current_slice = 0; } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == NAL_IDR_SLICE) { av_log(h, AV_LOG_WARNING, "Broken frame packetizing\n"); ff_h264_field_end(h, sl, 1); h->current_slice = 0; ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); h->cur_pic_ptr = NULL; } else return AVERROR_INVALIDDATA; } if (!h->first_field) { if (h->cur_pic_ptr && !h->droppable) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, h->picture_structure == PICT_BOTTOM_FIELD); } h->cur_pic_ptr = NULL; } } slice_type = get_ue_golomb_31(&sl->gb); if (slice_type > 9) { av_log(h->avctx, AV_LOG_ERROR, "slice type %d too large at %d\n", slice_type, first_mb_in_slice); return AVERROR_INVALIDDATA; } if (slice_type > 4) { slice_type -= 5; sl->slice_type_fixed = 1; } else sl->slice_type_fixed = 0; slice_type = golomb_to_pict_type[slice_type]; sl->slice_type = slice_type; sl->slice_type_nos = slice_type & 3; if (h->nal_unit_type == NAL_IDR_SLICE && sl->slice_type_nos != AV_PICTURE_TYPE_I) { av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n"); return AVERROR_INVALIDDATA; } if ( (h->avctx->skip_frame >= AVDISCARD_NONREF && !h->nal_ref_idc) || (h->avctx->skip_frame >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || (h->avctx->skip_frame >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != NAL_IDR_SLICE) || h->avctx->skip_frame >= AVDISCARD_ALL) { return SLICE_SKIPED; } // to make a few old functions happy, it's wrong though h->pict_type = sl->slice_type; pps_id = get_ue_golomb(&sl->gb); if (pps_id >= MAX_PPS_COUNT) { av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id); return AVERROR_INVALIDDATA; } if (!h->pps_buffers[pps_id]) { av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps_id); return AVERROR_INVALIDDATA; } if (h->au_pps_id >= 0 && pps_id != h->au_pps_id) { av_log(h->avctx, AV_LOG_ERROR, "PPS change from %d to %d forbidden\n", h->au_pps_id, pps_id); return AVERROR_INVALIDDATA; } pps = h->pps_buffers[pps_id]; if (!h->sps_buffers[pps->sps_id]) { av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h->pps.sps_id); return AVERROR_INVALIDDATA; } if (first_slice) h->pps = *h->pps_buffers[pps_id]; if (pps->sps_id != h->sps.sps_id || pps->sps_id != h->current_sps_id || h->sps_buffers[pps->sps_id]->new) { if (!first_slice) { av_log(h->avctx, AV_LOG_ERROR, "SPS changed in the middle of the frame\n"); return AVERROR_INVALIDDATA; } h->sps = *h->sps_buffers[h->pps.sps_id]; if (h->mb_width != h->sps.mb_width || h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) || h->cur_bit_depth_luma != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc ) needs_reinit = 1; if (h->bit_depth_luma != h->sps.bit_depth_luma || h->chroma_format_idc != h->sps.chroma_format_idc) { h->bit_depth_luma = h->sps.bit_depth_luma; h->chroma_format_idc = h->sps.chroma_format_idc; needs_reinit = 1; } if ((ret = ff_h264_set_parameter_from_sps(h)) < 0) return ret; } h->avctx->profile = ff_h264_get_profile(&h->sps); h->avctx->level = h->sps.level_idc; h->avctx->refs = h->sps.ref_frame_count; must_reinit = (h->context_initialized && ( 16*h->sps.mb_width != h->avctx->coded_width || 16*h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) != h->avctx->coded_height || h->cur_bit_depth_luma != h->sps.bit_depth_luma || h->cur_chroma_format_idc != h->sps.chroma_format_idc || h->mb_width != h->sps.mb_width || h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) )); if (h->avctx->pix_fmt == AV_PIX_FMT_NONE || (non_j_pixfmt(h->avctx->pix_fmt) != non_j_pixfmt(get_pixel_format(h, 0)))) must_reinit = 1; if (first_slice && av_cmp_q(h->sps.sar, h->avctx->sample_aspect_ratio)) must_reinit = 1; h->mb_width = h->sps.mb_width; h->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); h->mb_num = h->mb_width * h->mb_height; h->mb_stride = h->mb_width + 1; h->b_stride = h->mb_width * 4; h->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p h->width = 16 * h->mb_width; h->height = 16 * h->mb_height; ret = init_dimensions(h); if (ret < 0) return ret; if (h->sps.video_signal_type_present_flag) { h->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; if (h->sps.colour_description_present_flag) { if (h->avctx->colorspace != h->sps.colorspace) needs_reinit = 1; h->avctx->color_primaries = h->sps.color_primaries; h->avctx->color_trc = h->sps.color_trc; h->avctx->colorspace = h->sps.colorspace; } } if (h->context_initialized && (must_reinit || needs_reinit)) { if (sl != h->slice_ctx) { av_log(h->avctx, AV_LOG_ERROR, "changing width %d -> %d / height %d -> %d on " "slice %d\n", h->width, h->avctx->coded_width, h->height, h->avctx->coded_height, h->current_slice + 1); return AVERROR_INVALIDDATA; } av_assert1(first_slice); ff_h264_flush_change(h); if ((ret = get_pixel_format(h, 1)) < 0) return ret; h->avctx->pix_fmt = ret; av_log(h->avctx, AV_LOG_INFO, "Reinit context to %dx%d, " "pix_fmt: %s\n", h->width, h->height, av_get_pix_fmt_name(h->avctx->pix_fmt)); if ((ret = h264_slice_header_init(h, 1)) < 0) { av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } } if (!h->context_initialized) { if (sl != h->slice_ctx) { av_log(h->avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n"); return AVERROR_PATCHWELCOME; } if ((ret = get_pixel_format(h, 1)) < 0) return ret; h->avctx->pix_fmt = ret; if ((ret = h264_slice_header_init(h, 0)) < 0) { av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n"); return ret; } } if (first_slice && h->dequant_coeff_pps != pps_id) { h->dequant_coeff_pps = pps_id; ff_h264_init_dequant_tables(h); } frame_num = get_bits(&sl->gb, h->sps.log2_max_frame_num); if (!first_slice) { if (h->frame_num != frame_num) { av_log(h->avctx, AV_LOG_ERROR, "Frame num change from %d to %d\n", h->frame_num, frame_num); return AVERROR_INVALIDDATA; } } sl->mb_mbaff = 0; h->mb_aff_frame = 0; last_pic_structure = h->picture_structure; last_pic_droppable = h->droppable; droppable = h->nal_ref_idc == 0; if (h->sps.frame_mbs_only_flag) { picture_structure = PICT_FRAME; } else { if (!h->sps.direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B) { av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); return -1; } field_pic_flag = get_bits1(&sl->gb); if (field_pic_flag) { bottom_field_flag = get_bits1(&sl->gb); picture_structure = PICT_TOP_FIELD + bottom_field_flag; } else { picture_structure = PICT_FRAME; h->mb_aff_frame = h->sps.mb_aff; } } if (h->current_slice) { if (last_pic_structure != picture_structure || last_pic_droppable != droppable) { av_log(h->avctx, AV_LOG_ERROR, "Changing field mode (%d -> %d) between slices is not allowed\n", last_pic_structure, h->picture_structure); return AVERROR_INVALIDDATA; } else if (!h->cur_pic_ptr) { av_log(h->avctx, AV_LOG_ERROR, "unset cur_pic_ptr on slice %d\n", h->current_slice + 1); return AVERROR_INVALIDDATA; } } h->picture_structure = picture_structure; h->droppable = droppable; h->frame_num = frame_num; sl->mb_field_decoding_flag = picture_structure != PICT_FRAME; if (h->current_slice == 0) { /* Shorten frame num gaps so we don't have to allocate reference * frames just to throw them away */ if (h->frame_num != h->prev_frame_num) { int unwrap_prev_frame_num = h->prev_frame_num; int max_frame_num = 1 << h->sps.log2_max_frame_num; if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num; if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) { unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1; if (unwrap_prev_frame_num < 0) unwrap_prev_frame_num += max_frame_num; h->prev_frame_num = unwrap_prev_frame_num; } } /* See if we have a decoded first field looking for a pair... * Here, we're using that to see if we should mark previously * decode frames as "finished". * We have to do that before the "dummy" in-between frame allocation, * since that can modify h->cur_pic_ptr. */ if (h->first_field) { assert(h->cur_pic_ptr); assert(h->cur_pic_ptr->f.buf[0]); assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); /* Mark old field/frame as completed */ if (h->cur_pic_ptr->tf.owner == h->avctx) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_BOTTOM_FIELD); } /* figure out if we have a complementary field pair */ if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ if (last_pic_structure != PICT_FRAME) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { if (h->cur_pic_ptr->frame_num != h->frame_num) { /* This and previous field were reference, but had * different frame_nums. Consider this field first in * pair. Throw away previous field except for reference * purposes. */ if (last_pic_structure != PICT_FRAME) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_pic_structure == PICT_TOP_FIELD); } } else { /* Second field in complementary pair */ if (!((last_pic_structure == PICT_TOP_FIELD && h->picture_structure == PICT_BOTTOM_FIELD) || (last_pic_structure == PICT_BOTTOM_FIELD && h->picture_structure == PICT_TOP_FIELD))) { av_log(h->avctx, AV_LOG_ERROR, "Invalid field mode combination %d/%d\n", last_pic_structure, h->picture_structure); h->picture_structure = last_pic_structure; h->droppable = last_pic_droppable; return AVERROR_INVALIDDATA; } else if (last_pic_droppable != h->droppable) { avpriv_request_sample(h->avctx, "Found reference and non-reference fields in the same frame, which"); h->picture_structure = last_pic_structure; h->droppable = last_pic_droppable; return AVERROR_PATCHWELCOME; } } } } while (h->frame_num != h->prev_frame_num && !h->first_field && h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) { H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); if (!h->sps.gaps_in_frame_num_allowed_flag) for(i=0; i<FF_ARRAY_ELEMS(h->last_pocs); i++) h->last_pocs[i] = INT_MIN; ret = h264_frame_start(h); if (ret < 0) { h->first_field = 0; return ret; } h->prev_frame_num++; h->prev_frame_num %= 1 << h->sps.log2_max_frame_num; h->cur_pic_ptr->frame_num = h->prev_frame_num; h->cur_pic_ptr->invalid_gap = !h->sps.gaps_in_frame_num_allowed_flag; ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); ret = ff_generate_sliding_window_mmcos(h, 1); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return ret; ret = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return ret; /* Error concealment: If a ref is missing, copy the previous ref * in its place. * FIXME: Avoiding a memcpy would be nice, but ref handling makes * many assumptions about there being no actual duplicates. * FIXME: This does not copy padding for out-of-frame motion * vectors. Given we are concealing a lost frame, this probably * is not noticeable by comparison, but it should be fixed. */ if (h->short_ref_count) { if (prev) { av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize, (const uint8_t **)prev->f.data, prev->f.linesize, h->avctx->pix_fmt, h->mb_width * 16, h->mb_height * 16); h->short_ref[0]->poc = prev->poc + 2; } h->short_ref[0]->frame_num = h->prev_frame_num; } } /* See if we have a decoded first field looking for a pair... * We're using that to see whether to continue decoding in that * frame, or to allocate a new one. */ if (h->first_field) { assert(h->cur_pic_ptr); assert(h->cur_pic_ptr->f.buf[0]); assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); /* figure out if we have a complementary field pair */ if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { /* Previous field is unmatched. Don't display it, but let it * remain for reference if marked as such. */ h->missing_fields ++; h->cur_pic_ptr = NULL; h->first_field = FIELD_PICTURE(h); } else { h->missing_fields = 0; if (h->cur_pic_ptr->frame_num != h->frame_num) { ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, h->picture_structure==PICT_BOTTOM_FIELD); /* This and the previous field had different frame_nums. * Consider this field first in pair. Throw away previous * one except for reference purposes. */ h->first_field = 1; h->cur_pic_ptr = NULL; } else { /* Second field in complementary pair */ h->first_field = 0; } } } else { /* Frame or first field in a potentially complementary pair */ h->first_field = FIELD_PICTURE(h); } if (!FIELD_PICTURE(h) || h->first_field) { if (h264_frame_start(h) < 0) { h->first_field = 0; return AVERROR_INVALIDDATA; } } else { release_unused_pictures(h, 0); } /* Some macroblocks can be accessed before they're available in case * of lost slices, MBAFF or threading. */ if (FIELD_PICTURE(h)) { for(i = (h->picture_structure == PICT_BOTTOM_FIELD); i<h->mb_height; i++) memset(h->slice_table + i*h->mb_stride, -1, (h->mb_stride - (i+1==h->mb_height)) * sizeof(*h->slice_table)); } else { memset(h->slice_table, -1, (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); } h->last_slice_type = -1; } h->cur_pic_ptr->frame_num = h->frame_num; // FIXME frame_num cleanup av_assert1(h->mb_num == h->mb_width * h->mb_height); if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num || first_mb_in_slice >= h->mb_num) { av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return AVERROR_INVALIDDATA; } sl->resync_mb_x = sl->mb_x = first_mb_in_slice % h->mb_width; sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) << FIELD_OR_MBAFF_PICTURE(h); if (h->picture_structure == PICT_BOTTOM_FIELD) sl->resync_mb_y = sl->mb_y = sl->mb_y + 1; av_assert1(sl->mb_y < h->mb_height); if (h->picture_structure == PICT_FRAME) { h->curr_pic_num = h->frame_num; h->max_pic_num = 1 << h->sps.log2_max_frame_num; } else { h->curr_pic_num = 2 * h->frame_num + 1; h->max_pic_num = 1 << (h->sps.log2_max_frame_num + 1); } if (h->nal_unit_type == NAL_IDR_SLICE) get_ue_golomb(&sl->gb); /* idr_pic_id */ if (h->sps.poc_type == 0) { h->poc_lsb = get_bits(&sl->gb, h->sps.log2_max_poc_lsb); if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) h->delta_poc_bottom = get_se_golomb(&sl->gb); } if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) { h->delta_poc[0] = get_se_golomb(&sl->gb); if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) h->delta_poc[1] = get_se_golomb(&sl->gb); } ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc); if (h->pps.redundant_pic_cnt_present) sl->redundant_pic_count = get_ue_golomb(&sl->gb); ret = ff_set_ref_count(h, sl); if (ret < 0) return ret; if (slice_type != AV_PICTURE_TYPE_I && (h->current_slice == 0 || slice_type != h->last_slice_type || memcmp(h->last_ref_count, sl->ref_count, sizeof(sl->ref_count)))) { ff_h264_fill_default_ref_list(h, sl); } if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { ret = ff_h264_decode_ref_pic_list_reordering(h, sl); if (ret < 0) { sl->ref_count[1] = sl->ref_count[0] = 0; return ret; } } if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) || (h->pps.weighted_bipred_idc == 1 && sl->slice_type_nos == AV_PICTURE_TYPE_B)) ff_pred_weight_table(h, sl); else if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, sl, -1); } else { sl->use_weight = 0; for (i = 0; i < 2; i++) { sl->luma_weight_flag[i] = 0; sl->chroma_weight_flag[i] = 0; } } // If frame-mt is enabled, only update mmco tables for the first slice // in a field. Subsequent slices can temporarily clobber h->mmco_index // or h->mmco, which will cause ref list mix-ups and decoding errors // further down the line. This may break decoding if the first slice is // corrupt, thus we only do this if frame-mt is enabled. if (h->nal_ref_idc) { ret = ff_h264_decode_ref_pic_marking(h, &sl->gb, !(h->avctx->active_thread_type & FF_THREAD_FRAME) || h->current_slice == 0); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) return AVERROR_INVALIDDATA; } if (FRAME_MBAFF(h)) { ff_h264_fill_mbaff_ref_list(h, sl); if (h->pps.weighted_bipred_idc == 2 && sl->slice_type_nos == AV_PICTURE_TYPE_B) { implicit_weight_table(h, sl, 0); implicit_weight_table(h, sl, 1); } } if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred) ff_h264_direct_dist_scale_factor(h, sl); ff_h264_direct_ref_list_init(h, sl); if (sl->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) { tmp = get_ue_golomb_31(&sl->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp); return AVERROR_INVALIDDATA; } sl->cabac_init_idc = tmp; } sl->last_qscale_diff = 0; tmp = h->pps.init_qp + get_se_golomb(&sl->gb); if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) { av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); return AVERROR_INVALIDDATA; } sl->qscale = tmp; sl->chroma_qp[0] = get_chroma_qp(h, 0, sl->qscale); sl->chroma_qp[1] = get_chroma_qp(h, 1, sl->qscale); // FIXME qscale / qp ... stuff if (sl->slice_type == AV_PICTURE_TYPE_SP) get_bits1(&sl->gb); /* sp_for_switch_flag */ if (sl->slice_type == AV_PICTURE_TYPE_SP || sl->slice_type == AV_PICTURE_TYPE_SI) get_se_golomb(&sl->gb); /* slice_qs_delta */ sl->deblocking_filter = 1; sl->slice_alpha_c0_offset = 0; sl->slice_beta_offset = 0; if (h->pps.deblocking_filter_parameters_present) { tmp = get_ue_golomb_31(&sl->gb); if (tmp > 2) { av_log(h->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); return AVERROR_INVALIDDATA; } sl->deblocking_filter = tmp; if (sl->deblocking_filter < 2) sl->deblocking_filter ^= 1; // 1<->0 if (sl->deblocking_filter) { sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2; sl->slice_beta_offset = get_se_golomb(&sl->gb) * 2; if (sl->slice_alpha_c0_offset > 12 || sl->slice_alpha_c0_offset < -12 || sl->slice_beta_offset > 12 || sl->slice_beta_offset < -12) { av_log(h->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\n", sl->slice_alpha_c0_offset, sl->slice_beta_offset); return AVERROR_INVALIDDATA; } } } if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->nal_unit_type != NAL_IDR_SLICE) || (h->avctx->skip_loop_filter >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || (h->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) sl->deblocking_filter = 0; if (sl->deblocking_filter == 1 && h->max_contexts > 1) { if (h->avctx->flags2 & CODEC_FLAG2_FAST) { /* Cheat slightly for speed: * Do not bother to deblock across slices. */ sl->deblocking_filter = 2; } else { h->max_contexts = 1; if (!h->single_decode_warning) { av_log(h->avctx, AV_LOG_INFO, "Cannot parallelize slice decoding with deblocking filter type 1, decoding such frames in sequential order\n" "To parallelize slice decoding you need video encoded with disable_deblocking_filter_idc set to 2 (deblock only edges that do not cross slices).\n" "Setting the flags2 libavcodec option to +fast (-flags2 +fast) will disable deblocking across slices and enable parallel slice decoding " "but will generate non-standard-compliant output.\n"); h->single_decode_warning = 1; } if (sl != h->slice_ctx) { av_log(h->avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\n"); return SLICE_SINGLETHREAD; } } } sl->qp_thresh = 15 - FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]) + 6 * (h->sps.bit_depth_luma - 8); h->last_slice_type = slice_type; memcpy(h->last_ref_count, sl->ref_count, sizeof(h->last_ref_count)); sl->slice_num = ++h->current_slice; if (sl->slice_num) h->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= sl->resync_mb_y; if ( h->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= sl->resync_mb_y && h->slice_row[sl->slice_num&(MAX_SLICES-1)] <= sl->resync_mb_y && sl->slice_num >= MAX_SLICES) { //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", sl->slice_num, MAX_SLICES); } for (j = 0; j < 2; j++) { int id_list[16]; int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; for (i = 0; i < 16; i++) { id_list[i] = 60; if (j < sl->list_count && i < sl->ref_count[j] && sl->ref_list[j][i].parent->f.buf[0]) { int k; AVBuffer *buf = sl->ref_list[j][i].parent->f.buf[0]->buffer; for (k = 0; k < h->short_ref_count; k++) if (h->short_ref[k]->f.buf[0]->buffer == buf) { id_list[i] = k; break; } for (k = 0; k < h->long_ref_count; k++) if (h->long_ref[k] && h->long_ref[k]->f.buf[0]->buffer == buf) { id_list[i] = h->short_ref_count + k; break; } } } ref2frm[0] = ref2frm[1] = -1; for (i = 0; i < 16; i++) ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3); ref2frm[18 + 0] = ref2frm[18 + 1] = -1; for (i = 16; i < 48; i++) ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] + (sl->ref_list[j][i].reference & 3); } h->au_pps_id = pps_id; h->sps.new = h->sps_buffers[h->pps.sps_id]->new = 0; h->current_sps_id = h->pps.sps_id; if (h->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(h->avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", sl->slice_num, (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"), first_mb_in_slice, av_get_picture_type_char(sl->slice_type), sl->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "", pps_id, h->frame_num, h->cur_pic_ptr->field_poc[0], h->cur_pic_ptr->field_poc[1], sl->ref_count[0], sl->ref_count[1], sl->qscale, sl->deblocking_filter, sl->slice_alpha_c0_offset, sl->slice_beta_offset, sl->use_weight, sl->use_weight == 1 && sl->use_weight_chroma ? "c" : "", sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""); } return 0; }


static void udp4_hwcsum_outgoing(struct sock *sk, struct sk_buff *skb,
				 __be32 src, __be32 dst, int len      )
{
	unsigned int offset;
	struct udphdr *uh = udp_hdr(skb);
	__wsum csum = 0;

	if (skb_queue_len(&sk->sk_write_queue) == 1) {
		/*
		 * Only one fragment on the socket.
		 */
		skb->csum_start = skb_transport_header(skb) - skb->head;
		skb->csum_offset = offsetof(struct udphdr, check);
		uh->check = ~csum_tcpudp_magic(src, dst, len, IPPROTO_UDP, 0);
	} else {
		/*
		 * HW-checksum won't work as there are two or more
		 * fragments on the socket so that all csums of sk_buffs
		 * should be together
		 */
		offset = skb_transport_offset(skb);
		skb->csum = skb_checksum(skb, offset, skb->len - offset, 0);

		skb->ip_summed = CHECKSUM_NONE;

		skb_queue_walk(&sk->sk_write_queue, skb) {
			csum = csum_add(csum, skb->csum);
		}

		uh->check = csum_tcpudp_magic(src, dst, len, IPPROTO_UDP, csum);
		if (uh->check == 0)
			uh->check = CSUM_MANGLED_0;
	}
}


static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { Vp3DecodeContext *s = avctx->priv_data; GetBitContext gb; static int counter = 0; int i; init_get_bits(&gb, buf, buf_size * 8); if (s->theora && get_bits1(&gb)) { #if 1 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); return -1; #else int ptype = get_bits(&gb, 7); skip_bits(&gb, 6*8); /* "theora" */ switch(ptype) { case 1: theora_decode_comments(avctx, gb); break; case 2: theora_decode_tables(avctx, gb); init_dequantizer(s); break; default: av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype); } return buf_size; #endif } s->keyframe = !get_bits1(&gb); if (!s->theora) skip_bits(&gb, 1); s->last_quality_index = s->quality_index; s->quality_index = get_bits(&gb, 6); if (s->theora >= 0x030200) skip_bits1(&gb); if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n", s->keyframe?"key":"", counter, s->quality_index); counter++; if (s->quality_index != s->last_quality_index) { init_dequantizer(s); init_loop_filter(s); } if (s->keyframe) { if (!s->theora) { skip_bits(&gb, 4); /* width code */ skip_bits(&gb, 4); /* height code */ if (s->version) { s->version = get_bits(&gb, 5); if (counter == 1) av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); } } if (s->version || s->theora) { if (get_bits1(&gb)) av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); skip_bits(&gb, 2); /* reserved? */ } if (s->last_frame.data[0] == s->golden_frame.data[0]) { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */ } else { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); if (s->last_frame.data[0]) avctx->release_buffer(avctx, &s->last_frame); } s->golden_frame.reference = 3; if(avctx->get_buffer(avctx, &s->golden_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } /* golden frame is also the current frame */ memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame)); /* time to figure out pixel addresses? */ if (!s->pixel_addresses_inited) { if (!s->flipped_image) vp3_calculate_pixel_addresses(s); else theora_calculate_pixel_addresses(s); } } else { /* allocate a new current frame */ s->current_frame.reference = 3; if(avctx->get_buffer(avctx, &s->current_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } } s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame s->current_frame.qstride= 0; {START_TIMER init_frame(s, &gb); STOP_TIMER("init_frame")} #if KEYFRAMES_ONLY if (!s->keyframe) { memcpy(s->current_frame.data[0], s->golden_frame.data[0], s->current_frame.linesize[0] * s->height); memcpy(s->current_frame.data[1], s->golden_frame.data[1], s->current_frame.linesize[1] * s->height / 2); memcpy(s->current_frame.data[2], s->golden_frame.data[2], s->current_frame.linesize[2] * s->height / 2); } else { #endif {START_TIMER if (unpack_superblocks(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); return -1; } STOP_TIMER("unpack_superblocks")} {START_TIMER if (unpack_modes(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n"); return -1; } STOP_TIMER("unpack_modes")} {START_TIMER if (unpack_vectors(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n"); return -1; } STOP_TIMER("unpack_vectors")} {START_TIMER if (unpack_dct_coeffs(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); return -1; } STOP_TIMER("unpack_dct_coeffs")} {START_TIMER reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { reverse_dc_prediction(s, s->u_fragment_start, s->fragment_width / 2, s->fragment_height / 2); reverse_dc_prediction(s, s->v_fragment_start, s->fragment_width / 2, s->fragment_height / 2); } STOP_TIMER("reverse_dc_prediction")} {START_TIMER for (i = 0; i < s->macroblock_height; i++) render_slice(s, i); STOP_TIMER("render_fragments")} {START_TIMER apply_loop_filter(s); STOP_TIMER("apply_loop_filter")} #if KEYFRAMES_ONLY } #endif *data_size=sizeof(AVFrame); *(AVFrame*)data= s->current_frame; /* release the last frame, if it is allocated and if it is not the * golden frame */ if ((s->last_frame.data[0]) && (s->last_frame.data[0] != s->golden_frame.data[0])) avctx->release_buffer(avctx, &s->last_frame); /* shuffle frames (last = current) */ memcpy(&s->last_frame, &s->current_frame, sizeof(AVFrame)); s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */ return buf_size; }


int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
		size_t len)
{
	struct inet_sock *inet = inet_sk(sk);
	struct udp_sock *up = udp_sk(sk);
	int ulen = len;
	struct ipcm_cookie ipc;
	struct rtable *rt = NULL;
	int free = 0;
	int connected = 0;
	__be32 daddr, faddr, saddr;
	__be16 dport;
	u8  tos;
	int err, is_udplite = up->pcflag;
	int corkreq = up->corkflag || msg->msg_flags&MSG_MORE;
	int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);

	if (len > 0xFFFF)
		return -EMSGSIZE;

	/*
	 *	Check the flags.
	 */

	if (msg->msg_flags&MSG_OOB)	/* Mirror BSD error message compatibility */
		return -EOPNOTSUPP;

	ipc.opt = NULL;

	if (up->pending) {
		/*
		 * There are pending frames.
		 * The socket lock must be held while it's corked.
		 */
		lock_sock(sk);
		if (likely(up->pending)) {
			if (unlikely(up->pending != AF_INET)) {
				release_sock(sk);
				return -EINVAL;
			}
			goto do_append_data;
		}
		release_sock(sk);
	}
	ulen += sizeof(struct udphdr);

	/*
	 *	Get and verify the address.
	 */
	if (msg->msg_name) {
		struct sockaddr_in * usin = (struct sockaddr_in*)msg->msg_name;
		if (msg->msg_namelen < sizeof(*usin))
			return -EINVAL;
		if (usin->sin_family != AF_INET) {
			if (usin->sin_family != AF_UNSPEC)
				return -EAFNOSUPPORT;
		}

		daddr = usin->sin_addr.s_addr;
		dport = usin->sin_port;
		if (dport == 0)
			return -EINVAL;
	} else {
		if (sk->sk_state != TCP_ESTABLISHED)
			return -EDESTADDRREQ;
		daddr = inet->daddr;
		dport = inet->dport;
		/* Open fast path for connected socket.
		   Route will not be used, if at least one option is set.
		 */
		connected = 1;
	}
	ipc.addr = inet->saddr;

	ipc.oif = sk->sk_bound_dev_if;
	if (msg->msg_controllen) {
		err = ip_cmsg_send(msg, &ipc);
		if (err)
			return err;
		if (ipc.opt)
			free = 1;
		connected = 0;
	}
	if (!ipc.opt)
		ipc.opt = inet->opt;

	saddr = ipc.addr;
	ipc.addr = faddr = daddr;

	if (ipc.opt && ipc.opt->srr) {
		if (!daddr)
			return -EINVAL;
		faddr = ipc.opt->faddr;
		connected = 0;
	}
	tos = RT_TOS(inet->tos);
	if (sock_flag(sk, SOCK_LOCALROUTE) ||
	    (msg->msg_flags & MSG_DONTROUTE) ||
	    (ipc.opt && ipc.opt->is_strictroute)) {
		tos |= RTO_ONLINK;
		connected = 0;
	}

	if (MULTICAST(daddr)) {
		if (!ipc.oif)
			ipc.oif = inet->mc_index;
		if (!saddr)
			saddr = inet->mc_addr;
		connected = 0;
	}

	if (connected)
		rt = (struct rtable*)sk_dst_check(sk, 0);

	if (rt == NULL) {
		struct flowi fl = { .oif = ipc.oif,
				    .nl_u = { .ip4_u =
					      { .daddr = faddr,
						.saddr = saddr,
						.tos = tos } },
				    .proto = sk->sk_protocol,
				    .uli_u = { .ports =
					       { .sport = inet->sport,
						 .dport = dport } } };
		security_sk_classify_flow(sk, &fl);
		err = ip_route_output_flow(&rt, &fl, sk, 1);
		if (err) {
			if (err == -ENETUNREACH)
				IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
			goto out;
		}

		err = -EACCES;
		if ((rt->rt_flags & RTCF_BROADCAST) &&
		    !sock_flag(sk, SOCK_BROADCAST))
			goto out;
		if (connected)
			sk_dst_set(sk, dst_clone(&rt->u.dst));
	}

	if (msg->msg_flags&MSG_CONFIRM)
		goto do_confirm;
back_from_confirm:

	saddr = rt->rt_src;
	if (!ipc.addr)
		daddr = ipc.addr = rt->rt_dst;

	lock_sock(sk);
	if (unlikely(up->pending)) {
		/* The socket is already corked while preparing it. */
		/* ... which is an evident application bug. --ANK */
		release_sock(sk);

		LIMIT_NETDEBUG(KERN_DEBUG "udp cork app bug 2\n");
		err = -EINVAL;
		goto out;
	}
	/*
	 *	Now cork the socket to pend data.
	 */
	inet->cork.fl.fl4_dst = daddr;
	inet->cork.fl.fl_ip_dport = dport;
	inet->cork.fl.fl4_src = saddr;
	inet->cork.fl.fl_ip_sport = inet->sport;
	up->pending = AF_INET;

do_append_data:
	up->len += ulen;
	getfrag  =  is_udplite ?  udplite_getfrag : ip_generic_getfrag;
	err = ip_append_data(sk, getfrag, msg->msg_iov, ulen,
			sizeof(struct udphdr), &ipc, rt,
			corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);
	if (err)
		udp_flush_pending_frames(sk);
	else if (!corkreq)
		err = udp_push_pending_frames(sk);
	else if (unlikely(skb_queue_empty(&sk->sk_write_queue)))
		up->pending = 0;
	release_sock(sk);

out:
	ip_rt_put(rt);
	if (free)
		kfree(ipc.opt);
	if (!err)
		return len;
	/*
	 * ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space.  Reporting
	 * ENOBUFS might not be good (it's not tunable per se), but otherwise
	 * we don't have a good statistic (IpOutDiscards but it can be too many
	 * things).  We could add another new stat but at least for now that
	 * seems like overkill.
	 */
	if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) {
		UDP_INC_STATS_USER(UDP_MIB_SNDBUFERRORS, is_udplite);
	}
	return err;

do_confirm:
	dst_confirm(&rt->u.dst);
	if (!(msg->msg_flags&MSG_PROBE) || len)
		goto back_from_confirm;
	err = 0;
	goto out;
}


static inline void set_trap_gate(unsigned int n, void *addr)
{
	BUG_ON((unsigned)n > 0xFF);
	_set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
}


static inline void pack_gate(gate_desc *gate, unsigned char type,
			     unsigned long base, unsigned dpl, unsigned flags,
			     unsigned short seg)
{
	gate->a = (seg << 16) | (base & 0xffff);
	gate->b = (base & 0xffff0000) |
		  (((0x80 | type | (dpl << 5)) & 0xff) << 8);
}


static inline void set_intr_gate(unsigned int n, void *addr)
{
	BUG_ON((unsigned)n > 0xFF);
	_set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
}


static int dissect_h245_RequestModeRejectCause ( tvbuff_t * tvb _U_ , int offset _U_ , asn1_ctx_t * actx _U_ , proto_tree * tree _U_ , int hf_index _U_ ) {
 offset = dissect_per_choice ( tvb , offset , actx , tree , hf_index , ett_h245_RequestModeRejectCause , RequestModeRejectCause_choice , NULL ) ;
 return offset ;
 }


static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
{
	BUG_ON((unsigned)n > 0xFF);
	_set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
}


int ec_GF2m_precompute_mult ( EC_GROUP * group , BN_CTX * ctx ) {
 return ec_wNAF_precompute_mult ( group , ctx ) ;
 }


static void decode_lowdelay(DiracContext *s) { AVCodecContext *avctx = s->avctx; int slice_x, slice_y, bytes, bufsize; const uint8_t *buf; struct lowdelay_slice *slices; int slice_num = 0; slices = av_mallocz_array(s->lowdelay.num_x, s->lowdelay.num_y * sizeof(struct lowdelay_slice)); align_get_bits(&s->gb); /*[DIRAC_STD] 13.5.2 Slices. slice(sx,sy) */ buf = s->gb.buffer + get_bits_count(&s->gb)/8; bufsize = get_bits_left(&s->gb); for (slice_y = 0; bufsize > 0 && slice_y < s->lowdelay.num_y; slice_y++) for (slice_x = 0; bufsize > 0 && slice_x < s->lowdelay.num_x; slice_x++) { bytes = (slice_num+1) * s->lowdelay.bytes.num / s->lowdelay.bytes.den - slice_num * s->lowdelay.bytes.num / s->lowdelay.bytes.den; slices[slice_num].bytes = bytes; slices[slice_num].slice_x = slice_x; slices[slice_num].slice_y = slice_y; init_get_bits(&slices[slice_num].gb, buf, bufsize); slice_num++; buf += bytes; bufsize -= bytes*8; } avctx->execute(avctx, decode_lowdelay_slice, slices, NULL, slice_num, sizeof(struct lowdelay_slice)); /* [DIRAC_STD] 13.5.2 Slices */ intra_dc_prediction(&s->plane[0].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ intra_dc_prediction(&s->plane[1].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ intra_dc_prediction(&s->plane[2].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ av_free(slices); }


static inline void native_load_idt(const struct desc_ptr *dtr)
{
	asm volatile("lidt %0"::"m" (*dtr));
}


static inline int desc_empty(const void *ptr)
{
	const u32 *desc = ptr;
	return !(desc[0] | desc[1]);
}


static inline void native_load_gdt(const struct desc_ptr *dtr)
{
	asm volatile("lgdt %0"::"m" (*dtr));
}


static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt, int *serial) { int got_picture; if (packet_queue_get(&is->videoq, pkt, 1, serial) < 0) return -1; if (pkt->data == flush_pkt.data) { avcodec_flush_buffers(is->video_st->codec); SDL_LockMutex(is->pictq_mutex); // Make sure there are no long delay timers (ideally we should just flush the queue but that's harder) while (is->pictq_size && !is->videoq.abort_request) { SDL_CondWait(is->pictq_cond, is->pictq_mutex); } is->video_current_pos = -1; is->frame_last_pts = AV_NOPTS_VALUE; is->frame_last_duration = 0; is->frame_timer = (double)av_gettime() / 1000000.0; is->frame_last_dropped_pts = AV_NOPTS_VALUE; SDL_UnlockMutex(is->pictq_mutex); return 0; } if(avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt) < 0) return 0; if (got_picture) { int ret = 1; if (decoder_reorder_pts == -1) { *pts = av_frame_get_best_effort_timestamp(frame); } else if (decoder_reorder_pts) { *pts = frame->pkt_pts; } else { *pts = frame->pkt_dts; } if (*pts == AV_NOPTS_VALUE) { *pts = 0; } if (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) { SDL_LockMutex(is->pictq_mutex); if (is->frame_last_pts != AV_NOPTS_VALUE && *pts) { double clockdiff = get_video_clock(is) - get_master_clock(is); double dpts = av_q2d(is->video_st->time_base) * *pts; double ptsdiff = dpts - is->frame_last_pts; if (fabs(clockdiff) < AV_NOSYNC_THRESHOLD && ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD && clockdiff + ptsdiff - is->frame_last_filter_delay < 0) { is->frame_last_dropped_pos = pkt->pos; is->frame_last_dropped_pts = dpts; is->frame_drops_early++; ret = 0; } } SDL_UnlockMutex(is->pictq_mutex); } return ret; } return 0; }


static void msix_mmio_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { PCIDevice *dev = opaque; unsigned int offset = addr & (MSIX_PAGE_SIZE - 1) & ~0x3; int vector = offset / PCI_MSIX_ENTRY_SIZE; pci_set_long(dev->msix_table_page + offset, val); msix_handle_mask_update(dev, vector);


static void evhttp_connection_start_detectclose ( struct evhttp_connection * evcon ) {
 evcon -> flags |= EVHTTP_CON_CLOSEDETECT ;
 if ( event_initialized ( & evcon -> close_ev ) ) event_del ( & evcon -> close_ev ) ;
 event_set ( & evcon -> close_ev , evcon -> fd , EV_READ , evhttp_detect_close_cb , evcon ) ;
 EVHTTP_BASE_SET ( evcon , & evcon -> close_ev ) ;
 event_add ( & evcon -> close_ev , NULL ) ;
 }


static inline void native_store_idt(struct desc_ptr *dtr)
{
	asm volatile("sidt %0":"=m" (*dtr));
}


static void mmubooke_create_initial_mapping(CPUPPCState *env, target_ulong va, hwaddr pa) { ppcemb_tlb_t *tlb = &env->tlb.tlbe[0]; tlb->attr = 0; tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4); tlb->size = 1 << 31; /* up to 0x80000000 */ tlb->EPN = va & TARGET_PAGE_MASK; tlb->RPN = pa & TARGET_PAGE_MASK; tlb->PID = 0; tlb = &env->tlb.tlbe[1]; tlb->attr = 0; tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4); tlb->size = 1 << 31; /* up to 0xffffffff */ tlb->EPN = 0x80000000 & TARGET_PAGE_MASK; tlb->RPN = 0x80000000 & TARGET_PAGE_MASK; tlb->PID = 0; }


static void _reconnectToDB ( ArchiveHandle * AH , const char * dbname ) {
 if ( RestoringToDB ( AH ) ) ReconnectToServer ( AH , dbname , NULL ) ;
 else {
 if ( dbname ) {
 PQExpBufferData connectbuf ;
 initPQExpBuffer ( & connectbuf ) ;
 appendPsqlMetaConnect ( & connectbuf , dbname ) ;
 ahprintf ( AH , "%s\n" , connectbuf . data ) ;
 termPQExpBuffer ( & connectbuf ) ;
 }
 else ahprintf ( AH , "%s\n" , "\\connect -\n" ) ;
 }
 if ( AH -> currUser ) free ( AH -> currUser ) ;
 AH -> currUser = NULL ;
 if ( AH -> currSchema ) free ( AH -> currSchema ) ;
 AH -> currSchema = NULL ;
 if ( AH -> currTablespace ) free ( AH -> currTablespace ) ;
 AH -> currTablespace = NULL ;
 AH -> currWithOids = - 1 ;
 _doSetFixedOutputState ( AH ) ;
 }