id
int32
0
27.3k
func
stringlengths
26
142k
target
bool
2 classes
project
stringclasses
2 values
commit_id
stringlengths
40
40
8,820
void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size) { const uint16_t *end; uint8_t *d = (uint8_t *)dst; const uint16_t *s = (const uint16_t *)src; end = s + src_size/2; while(s < end) { register uint16_t bgr; bgr = *s++; #ifdef WORDS_BIGENDIAN *d++ = 0; *d++ = (bgr&0x1F)<<3; *d++ = (bgr&0x3E0)>>2; *d++ = (bgr&0x7C00)>>7; #else *d++ = (bgr&0x7C00)>>7; *d++ = (bgr&0x3E0)>>2; *d++ = (bgr&0x1F)<<3; *d++ = 0; #endif } }
true
FFmpeg
6e42e6c4b410dbef8b593c2d796a5dad95f89ee4
8,821
static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) { void *val; if (min_size < *size) return 0; min_size = FFMAX(17 * min_size / 16 + 32, min_size); av_freep(ptr); val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size); memcpy(ptr, &val, sizeof(val)); if (!val) min_size = 0; *size = min_size; return 1; }
true
FFmpeg
b3415e4c5f9205820fd6c9211ad50a4df2692a36
8,822
int qcow2_update_header(BlockDriverState *bs) BDRVQcowState *s = bs->opaque; QCowHeader *header; char *buf; size_t buflen = s->cluster_size; int ret; uint64_t total_size; uint32_t refcount_table_clusters; size_t header_length; Qcow2UnknownHeaderExtension *uext; buf = qemu_blockalign(bs, buflen); /* Header structure */ header = (QCowHeader*) buf; if (buflen < sizeof(*header)) { ret = -ENOSPC; goto fail; } header_length = sizeof(*header) + s->unknown_header_fields_size; total_size = bs->total_sectors * BDRV_SECTOR_SIZE; refcount_table_clusters = s->refcount_table_size >> (s->cluster_bits - 3); *header = (QCowHeader) { /* Version 2 fields */ .magic = cpu_to_be32(QCOW_MAGIC), .version = cpu_to_be32(s->qcow_version), .backing_file_offset = 0, .backing_file_size = 0, .cluster_bits = cpu_to_be32(s->cluster_bits), .size = cpu_to_be64(total_size), .crypt_method = cpu_to_be32(s->crypt_method_header), .l1_size = cpu_to_be32(s->l1_size), .l1_table_offset = cpu_to_be64(s->l1_table_offset), .refcount_table_offset = cpu_to_be64(s->refcount_table_offset), .refcount_table_clusters = cpu_to_be32(refcount_table_clusters), .nb_snapshots = cpu_to_be32(s->nb_snapshots), .snapshots_offset = cpu_to_be64(s->snapshots_offset), /* Version 3 fields */ .incompatible_features = cpu_to_be64(s->incompatible_features), .compatible_features = cpu_to_be64(s->compatible_features), .autoclear_features = cpu_to_be64(s->autoclear_features), .refcount_order = cpu_to_be32(3 + REFCOUNT_SHIFT), .header_length = cpu_to_be32(header_length), }; /* For older versions, write a shorter header */ switch (s->qcow_version) { case 2: ret = offsetof(QCowHeader, incompatible_features); break; case 3: ret = sizeof(*header); break; default: ret = -EINVAL; goto fail; } buf += ret; buflen -= ret; memset(buf, 0, buflen); /* Preserve any unknown field in the header */ if (s->unknown_header_fields_size) { if (buflen < s->unknown_header_fields_size) { ret = -ENOSPC; goto fail; } memcpy(buf, s->unknown_header_fields, s->unknown_header_fields_size); buf += s->unknown_header_fields_size; buflen -= s->unknown_header_fields_size; } /* Backing file format header extension */ if (*bs->backing_format) { ret = header_ext_add(buf, QCOW2_EXT_MAGIC_BACKING_FORMAT, bs->backing_format, strlen(bs->backing_format), buflen); if (ret < 0) { goto fail; } buf += ret; buflen -= ret; } /* Feature table */ Qcow2Feature features[] = { .bit = QCOW2_INCOMPAT_DIRTY_BITNR, .name = "dirty bit", .type = QCOW2_FEAT_TYPE_COMPATIBLE, .bit = QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR, .name = "lazy refcounts", }; ret = header_ext_add(buf, QCOW2_EXT_MAGIC_FEATURE_TABLE, features, sizeof(features), buflen); if (ret < 0) { goto fail; } buf += ret; buflen -= ret; /* Keep unknown header extensions */ QLIST_FOREACH(uext, &s->unknown_header_ext, next) { ret = header_ext_add(buf, uext->magic, uext->data, uext->len, buflen); if (ret < 0) { goto fail; } buf += ret; buflen -= ret; } /* End of header extensions */ ret = header_ext_add(buf, QCOW2_EXT_MAGIC_END, NULL, 0, buflen); if (ret < 0) { goto fail; } buf += ret; buflen -= ret; /* Backing file name */ if (*bs->backing_file) { size_t backing_file_len = strlen(bs->backing_file); if (buflen < backing_file_len) { ret = -ENOSPC; goto fail; } /* Using strncpy is ok here, since buf is not NUL-terminated. */ strncpy(buf, bs->backing_file, buflen); header->backing_file_offset = cpu_to_be64(buf - ((char*) header)); header->backing_file_size = cpu_to_be32(backing_file_len); } /* Write the new header */ ret = bdrv_pwrite(bs->file, 0, header, s->cluster_size); if (ret < 0) { goto fail; } ret = 0; fail: qemu_vfree(header); return ret; }
true
qemu
69c98726537627e708abb8fcb33e3a2b10e40bf1
8,823
void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp) { #if HAVE_YASM int mm_flags = av_get_cpu_flags(); if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) { fdsp->vector_fmul = ff_vector_fmul_sse; fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse; } if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) { fdsp->vector_fmul = ff_vector_fmul_avx; fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx; } #endif }
false
FFmpeg
e0c6cce44729d94e2a5507a4b6d031f23e8bd7b6
8,824
static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk, Jpeg2000Component *comp, Jpeg2000T1Context *t1, Jpeg2000Band *band) { int i, j; int w = cblk->coord[0][1] - cblk->coord[0][0]; for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) { float *datap = &comp->f_data[(comp->coord[0][1] - comp->coord[0][0]) * (y + j) + x]; int *src = t1->data[j]; for (i = 0; i < w; ++i) datap[i] = src[i] * band->f_stepsize; } }
false
FFmpeg
f1e173049ecc9de03817385ba8962d14cba779db
8,826
static int read_extra_header(FFV1Context *f) { RangeCoder *const c = &f->c; uint8_t state[CONTEXT_SIZE]; int i, j, k, ret; uint8_t state2[32][CONTEXT_SIZE]; memset(state2, 128, sizeof(state2)); memset(state, 128, sizeof(state)); ff_init_range_decoder(c, f->avctx->extradata, f->avctx->extradata_size); ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8); f->version = get_symbol(c, state, 0); if (f->version < 2) { av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n"); return AVERROR_INVALIDDATA; } if (f->version > 2) { c->bytestream_end -= 4; f->micro_version = get_symbol(c, state, 0); if (f->micro_version < 0) return AVERROR_INVALIDDATA; } f->ac = f->avctx->coder_type = get_symbol(c, state, 0); if (f->ac > 1) { for (i = 1; i < 256; i++) f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i]; } f->colorspace = get_symbol(c, state, 0); //YUV cs type f->avctx->bits_per_raw_sample = get_symbol(c, state, 0); f->chroma_planes = get_rac(c, state); f->chroma_h_shift = get_symbol(c, state, 0); f->chroma_v_shift = get_symbol(c, state, 0); f->transparency = get_rac(c, state); f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency; f->num_h_slices = 1 + get_symbol(c, state, 0); f->num_v_slices = 1 + get_symbol(c, state, 0); if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) { av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", f->chroma_h_shift, f->chroma_v_shift); return AVERROR_INVALIDDATA; } if (f->num_h_slices > (unsigned)f->width || !f->num_h_slices || f->num_v_slices > (unsigned)f->height || !f->num_v_slices ) { av_log(f->avctx, AV_LOG_ERROR, "slice count invalid\n"); return AVERROR_INVALIDDATA; } f->quant_table_count = get_symbol(c, state, 0); if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES) return AVERROR_INVALIDDATA; for (i = 0; i < f->quant_table_count; i++) { f->context_count[i] = read_quant_tables(c, f->quant_tables[i]); if (f->context_count[i] < 0) { av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); return AVERROR_INVALIDDATA; } } if ((ret = ff_ffv1_allocate_initial_states(f)) < 0) return ret; for (i = 0; i < f->quant_table_count; i++) if (get_rac(c, state)) { for (j = 0; j < f->context_count[i]; j++) for (k = 0; k < CONTEXT_SIZE; k++) { int pred = j ? f->initial_states[i][j - 1][k] : 128; f->initial_states[i][j][k] = (pred + get_symbol(c, state2[k], 1)) & 0xFF; } } if (f->version > 2) { f->ec = get_symbol(c, state, 0); if (f->micro_version > 2) f->intra = get_symbol(c, state, 0); } if (f->version > 2) { unsigned v; v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size); if (v) { av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v); return AVERROR_INVALIDDATA; } } if (f->avctx->debug & FF_DEBUG_PICT_INFO) av_log(f->avctx, AV_LOG_DEBUG, "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d\n", f->version, f->micro_version, f->ac, f->colorspace, f->avctx->bits_per_raw_sample, f->chroma_planes, f->chroma_h_shift, f->chroma_v_shift, f->transparency, f->num_h_slices, f->num_v_slices, f->quant_table_count, f->ec, f->intra ); return 0; }
false
FFmpeg
eac161451d248fdd375d403f9bb7d0bec68bc40b
8,828
int ff_v4l2_m2m_codec_end(AVCodecContext *avctx) { V4L2m2mContext* s = avctx->priv_data; int ret; ret = ff_v4l2_context_set_status(&s->output, VIDIOC_STREAMOFF); if (ret) av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", s->output.name); ret = ff_v4l2_context_set_status(&s->capture, VIDIOC_STREAMOFF); if (ret) av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", s->capture.name); ff_v4l2_context_release(&s->output); if (atomic_load(&s->refcount)) av_log(avctx, AV_LOG_ERROR, "ff_v4l2m2m_codec_end leaving pending buffers\n"); ff_v4l2_context_release(&s->capture); sem_destroy(&s->refsync); /* release the hardware */ if (close(s->fd) < 0 ) av_log(avctx, AV_LOG_ERROR, "failure closing %s (%s)\n", s->devname, av_err2str(AVERROR(errno))); s->fd = -1; return 0; }
true
FFmpeg
a0c624e299730c8c5800375c2f5f3c6c200053ff
8,829
static void spr_read_tbl(DisasContext *ctx, int gprn, int sprn) { if (ctx->tb->cflags & CF_USE_ICOUNT) { gen_io_start(); } gen_helper_load_tbl(cpu_gpr[gprn], cpu_env); if (ctx->tb->cflags & CF_USE_ICOUNT) { gen_io_end(); gen_stop_exception(ctx); } }
true
qemu
c5a49c63fa26e8825ad101dfe86339ae4c216539
8,830
void vnc_client_read(void *opaque) { VncState *vs = opaque; long ret; buffer_reserve(&vs->input, 4096); #ifdef CONFIG_VNC_TLS if (vs->tls.session) { ret = gnutls_read(vs->tls.session, buffer_end(&vs->input), 4096); if (ret < 0) { if (ret == GNUTLS_E_AGAIN) errno = EAGAIN; else errno = EIO; ret = -1; } } else #endif /* CONFIG_VNC_TLS */ ret = recv(vs->csock, buffer_end(&vs->input), 4096, 0); ret = vnc_client_io_error(vs, ret, socket_error()); if (!ret) return; vs->input.offset += ret; while (vs->read_handler && vs->input.offset >= vs->read_handler_expect) { size_t len = vs->read_handler_expect; int ret; ret = vs->read_handler(vs, vs->input.buffer, len); if (vs->csock == -1) return; if (!ret) { memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len)); vs->input.offset -= len; } else { vs->read_handler_expect = ret; } } }
true
qemu
2f9606b3736c3be4dbd606c46525c7b770ced119
8,831
static void test_bmdma_short_prdt(void) { QPCIDevice *dev; QPCIBar bmdma_bar, ide_bar; uint8_t status; PrdtEntry prdt[] = { { .addr = 0, .size = cpu_to_le32(0x10 | PRDT_EOT), }, }; dev = get_pci_device(&bmdma_bar, &ide_bar); /* Normal request */ status = send_dma_request(CMD_READ_DMA, 0, 1, prdt, ARRAY_SIZE(prdt), NULL); g_assert_cmphex(status, ==, 0); assert_bit_clear(qpci_io_readb(dev, ide_bar, reg_status), DF | ERR); /* Abort the request before it completes */ status = send_dma_request(CMD_READ_DMA | CMDF_ABORT, 0, 1, prdt, ARRAY_SIZE(prdt), NULL); g_assert_cmphex(status, ==, 0); assert_bit_clear(qpci_io_readb(dev, ide_bar, reg_status), DF | ERR); }
true
qemu
f5aa4bdc766190b95d18be27d5cdf4d80c35b33c
8,832
int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb) { int startcode, v; /* search next start code */ align_get_bits(gb); if(s->avctx->codec_tag == ff_get_fourcc("WV1F") && show_bits(gb, 24) == 0x575630){ skip_bits(gb, 24); if(get_bits(gb, 8) == 0xF0) return decode_vop_header(s, gb); } startcode = 0xff; for(;;) { v = get_bits(gb, 8); startcode = ((startcode << 8) | v) & 0xffffffff; if(get_bits_count(gb) >= gb->size_in_bits){ if(gb->size_in_bits==8 && (s->divx_version || s->xvid_build)){ av_log(s->avctx, AV_LOG_ERROR, "frame skip %d\n", gb->size_in_bits); return FRAME_SKIPPED; //divx bug }else return -1; //end of stream } if((startcode&0xFFFFFF00) != 0x100) continue; //no startcode if(s->avctx->debug&FF_DEBUG_STARTCODE){ av_log(s->avctx, AV_LOG_DEBUG, "startcode: %3X ", startcode); if (startcode<=0x11F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Start"); else if(startcode<=0x12F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Layer Start"); else if(startcode<=0x13F) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); else if(startcode<=0x15F) av_log(s->avctx, AV_LOG_DEBUG, "FGS bp start"); else if(startcode<=0x1AF) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); else if(startcode==0x1B0) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq Start"); else if(startcode==0x1B1) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq End"); else if(startcode==0x1B2) av_log(s->avctx, AV_LOG_DEBUG, "User Data"); else if(startcode==0x1B3) av_log(s->avctx, AV_LOG_DEBUG, "Group of VOP start"); else if(startcode==0x1B4) av_log(s->avctx, AV_LOG_DEBUG, "Video Session Error"); else if(startcode==0x1B5) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Start"); else if(startcode==0x1B6) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Plane start"); else if(startcode==0x1B7) av_log(s->avctx, AV_LOG_DEBUG, "slice start"); else if(startcode==0x1B8) av_log(s->avctx, AV_LOG_DEBUG, "extension start"); else if(startcode==0x1B9) av_log(s->avctx, AV_LOG_DEBUG, "fgs start"); else if(startcode==0x1BA) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object start"); else if(startcode==0x1BB) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object Plane start"); else if(startcode==0x1BC) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object start"); else if(startcode==0x1BD) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object Plane start"); else if(startcode==0x1BE) av_log(s->avctx, AV_LOG_DEBUG, "Still Texture Object start"); else if(startcode==0x1BF) av_log(s->avctx, AV_LOG_DEBUG, "Texture Spatial Layer start"); else if(startcode==0x1C0) av_log(s->avctx, AV_LOG_DEBUG, "Texture SNR Layer start"); else if(startcode==0x1C1) av_log(s->avctx, AV_LOG_DEBUG, "Texture Tile start"); else if(startcode==0x1C2) av_log(s->avctx, AV_LOG_DEBUG, "Texture Shape Layer start"); else if(startcode==0x1C3) av_log(s->avctx, AV_LOG_DEBUG, "stuffing start"); else if(startcode<=0x1C5) av_log(s->avctx, AV_LOG_DEBUG, "reserved"); else if(startcode<=0x1FF) av_log(s->avctx, AV_LOG_DEBUG, "System start"); av_log(s->avctx, AV_LOG_DEBUG, " at %d\n", get_bits_count(gb)); } if(startcode >= 0x120 && startcode <= 0x12F){ if(decode_vol_header(s, gb) < 0) return -1; } else if(startcode == USER_DATA_STARTCODE){ decode_user_data(s, gb); } else if(startcode == GOP_STARTCODE){ mpeg4_decode_gop_header(s, gb); } else if(startcode == VOP_STARTCODE){ return decode_vop_header(s, gb); } align_get_bits(gb); startcode = 0xff; } }
true
FFmpeg
63d33cf4390a9280b1ba42ee722f3140cf1cad3e
8,833
SwsFunc yuv2rgb_init_altivec (SwsContext *c) { if (!(c->flags & SWS_CPU_CAPS_ALTIVEC)) return NULL; /* and this seems not to matter too much I tried a bunch of videos with abnormal widths and mplayer crashes else where. mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv boom with X11 bad match. */ if ((c->srcW & 0xf) != 0) return NULL; switch (c->srcFormat) { case PIX_FMT_YUV410P: case PIX_FMT_YUV420P: /*case IMGFMT_CLPL: ??? */ case PIX_FMT_GRAY8: case PIX_FMT_NV12: case PIX_FMT_NV21: if ((c->srcH & 0x1) != 0) return NULL; switch(c->dstFormat){ case PIX_FMT_RGB24: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n"); return altivec_yuv2_rgb24; case PIX_FMT_BGR24: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n"); return altivec_yuv2_bgr24; case PIX_FMT_ARGB: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n"); return altivec_yuv2_argb; case PIX_FMT_ABGR: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n"); return altivec_yuv2_abgr; case PIX_FMT_RGBA: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n"); return altivec_yuv2_rgba; case PIX_FMT_BGRA: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n"); return altivec_yuv2_bgra; default: return NULL; } break; case PIX_FMT_UYVY422: switch(c->dstFormat){ case PIX_FMT_BGR32: av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n"); return altivec_uyvy_rgb32; default: return NULL; } break; } return NULL; }
true
FFmpeg
428098165de4c3edfe42c1b7f00627d287015863
8,834
static void string_output_append(StringOutputVisitor *sov, int64_t a) { Range *r = g_malloc0(sizeof(*r)); r->begin = a; r->end = a + 1; sov->ranges = g_list_insert_sorted_merged(sov->ranges, r, range_compare); }
true
qemu
7c47959d0cb05db43014141a156ada0b6d53a750
8,836
static void run_postproc(AVCodecContext *avctx, AVFrame *frame) { DDSContext *ctx = avctx->priv_data; int i, x_off; switch (ctx->postproc) { case DDS_ALPHA_EXP: /* Alpha-exponential mode divides each channel by the maximum * R, G or B value, and stores the multiplying factor in the * alpha channel. */ av_log(avctx, AV_LOG_DEBUG, "Post-processing alpha exponent.\n"); for (i = 0; i < frame->linesize[0] * frame->height; i += 4) { uint8_t *src = frame->data[0] + i; int r = src[0]; int g = src[1]; int b = src[2]; int a = src[3]; src[0] = r * a / 255; src[1] = g * a / 255; src[2] = b * a / 255; src[3] = 255; } break; case DDS_NORMAL_MAP: /* Normal maps work in the XYZ color space and they encode * X in R or in A, depending on the texture type, Y in G and * derive Z with a square root of the distance. * * http://www.realtimecollisiondetection.net/blog/?p=28 */ av_log(avctx, AV_LOG_DEBUG, "Post-processing normal map.\n"); x_off = ctx->tex_ratio == 8 ? 0 : 3; for (i = 0; i < frame->linesize[0] * frame->height; i += 4) { uint8_t *src = frame->data[0] + i; int x = src[x_off]; int y = src[1]; int z = 127; int d = (255 * 255 - x * x - y * y) / 2; if (d > 0) z = rint(sqrtf(d)); src[0] = x; src[1] = y; src[2] = z; src[3] = 255; } break; case DDS_RAW_YCOCG: /* Data is Y-Co-Cg-A and not RGBA, but they are represented * with the same masks in the DDPF header. */ av_log(avctx, AV_LOG_DEBUG, "Post-processing raw YCoCg.\n"); for (i = 0; i < frame->linesize[0] * frame->height; i += 4) { uint8_t *src = frame->data[0] + i; int a = src[0]; int cg = src[1] - 128; int co = src[2] - 128; int y = src[3]; src[0] = av_clip_uint8(y + co - cg); src[1] = av_clip_uint8(y + cg); src[2] = av_clip_uint8(y - co - cg); src[3] = a; } break; case DDS_SWAP_ALPHA: /* Alpha and Luma are stored swapped. */ av_log(avctx, AV_LOG_DEBUG, "Post-processing swapped Luma/Alpha.\n"); for (i = 0; i < frame->linesize[0] * frame->height; i += 2) { uint8_t *src = frame->data[0] + i; FFSWAP(uint8_t, src[0], src[1]); } break; case DDS_SWIZZLE_A2XY: /* Swap R and G, often used to restore a standard RGTC2. */ av_log(avctx, AV_LOG_DEBUG, "Post-processing A2XY swizzle.\n"); do_swizzle(frame, 0, 1); break; case DDS_SWIZZLE_RBXG: /* Swap G and A, then B and new A (G). */ av_log(avctx, AV_LOG_DEBUG, "Post-processing RBXG swizzle.\n"); do_swizzle(frame, 1, 3); do_swizzle(frame, 2, 3); break; case DDS_SWIZZLE_RGXB: /* Swap B and A. */ av_log(avctx, AV_LOG_DEBUG, "Post-processing RGXB swizzle.\n"); do_swizzle(frame, 2, 3); break; case DDS_SWIZZLE_RXBG: /* Swap G and A. */ av_log(avctx, AV_LOG_DEBUG, "Post-processing RXBG swizzle.\n"); do_swizzle(frame, 1, 3); break; case DDS_SWIZZLE_RXGB: /* Swap R and A (misleading name). */ av_log(avctx, AV_LOG_DEBUG, "Post-processing RXGB swizzle.\n"); do_swizzle(frame, 0, 3); break; case DDS_SWIZZLE_XGBR: /* Swap B and A, then R and new A (B). */ av_log(avctx, AV_LOG_DEBUG, "Post-processing XGBR swizzle.\n"); do_swizzle(frame, 2, 3); do_swizzle(frame, 0, 3); break; case DDS_SWIZZLE_XGXR: /* Swap G and A, then R and new A (G), then new R (G) and new G (A). * This variant does not store any B component. */ av_log(avctx, AV_LOG_DEBUG, "Post-processing XGXR swizzle.\n"); do_swizzle(frame, 1, 3); do_swizzle(frame, 0, 3); do_swizzle(frame, 0, 1); break; case DDS_SWIZZLE_XRBG: /* Swap G and A, then R and new A (G). */ av_log(avctx, AV_LOG_DEBUG, "Post-processing XRBG swizzle.\n"); do_swizzle(frame, 1, 3); do_swizzle(frame, 0, 3); break; } }
false
FFmpeg
6eb2505855fa832ba7d0a1c2fb9f92c41c5446e3
8,839
static void ipvideo_decode_format_10_opcodes(IpvideoContext *s, AVFrame *frame) { int pass, x, y, changed_block; int16_t opcode, skip; GetByteContext decoding_map_ptr; GetByteContext skip_map_ptr; bytestream2_skip(&s->stream_ptr, 14); /* data starts 14 bytes in */ /* this is PAL8, so make the palette available */ memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); s->stride = frame->linesize[0]; s->line_inc = s->stride - 8; s->upper_motion_limit_offset = (s->avctx->height - 8) * frame->linesize[0] + (s->avctx->width - 8) * (1 + s->is_16bpp); bytestream2_init(&decoding_map_ptr, s->decoding_map, s->decoding_map_size); bytestream2_init(&skip_map_ptr, s->skip_map, s->skip_map_size); for (pass = 0; pass < 2; ++pass) { bytestream2_seek(&decoding_map_ptr, 0, SEEK_SET); bytestream2_seek(&skip_map_ptr, 0, SEEK_SET); skip = bytestream2_get_le16(&skip_map_ptr); for (y = 0; y < s->avctx->height; y += 8) { for (x = 0; x < s->avctx->width; x += 8) { s->pixel_ptr = s->cur_decode_frame->data[0] + x + y * s->cur_decode_frame->linesize[0]; while (skip <= 0 && bytestream2_get_bytes_left(&decoding_map_ptr) > 1) { if (skip != -0x8000 && skip) { opcode = bytestream2_get_le16(&decoding_map_ptr); ipvideo_format_10_passes[pass](s, frame, opcode); break; } skip = bytestream2_get_le16(&skip_map_ptr); } skip *= 2; } } } bytestream2_seek(&skip_map_ptr, 0, SEEK_SET); skip = bytestream2_get_le16(&skip_map_ptr); for (y = 0; y < s->avctx->height; y += 8) { for (x = 0; x < s->avctx->width; x += 8) { changed_block = 0; s->pixel_ptr = frame->data[0] + x + y*frame->linesize[0]; while (skip <= 0) { if (skip != -0x8000 && skip) { changed_block = 1; break; } if (bytestream2_get_bytes_left(&skip_map_ptr) < 2) return; skip = bytestream2_get_le16(&skip_map_ptr); } if (changed_block) { copy_from(s, s->cur_decode_frame, frame, 0, 0); } else { /* Don't try to copy last_frame data on the first frame */ if (s->avctx->frame_number) copy_from(s, s->last_frame, frame, 0, 0); } skip *= 2; } } FFSWAP(AVFrame*, s->prev_decode_frame, s->cur_decode_frame); if (bytestream2_get_bytes_left(&s->stream_ptr) > 1) { av_log(s->avctx, AV_LOG_DEBUG, "decode finished with %d bytes left over\n", bytestream2_get_bytes_left(&s->stream_ptr)); } }
false
FFmpeg
f0edab6e63ecee29cb68230100f0c2fb5468284c
8,840
static uint64_t omap_clkm_read(void *opaque, target_phys_addr_t addr, unsigned size) { struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque; if (size != 2) { return omap_badwidth_read16(opaque, addr); } switch (addr) { case 0x00: /* ARM_CKCTL */ return s->clkm.arm_ckctl; case 0x04: /* ARM_IDLECT1 */ return s->clkm.arm_idlect1; case 0x08: /* ARM_IDLECT2 */ return s->clkm.arm_idlect2; case 0x0c: /* ARM_EWUPCT */ return s->clkm.arm_ewupct; case 0x10: /* ARM_RSTCT1 */ return s->clkm.arm_rstct1; case 0x14: /* ARM_RSTCT2 */ return s->clkm.arm_rstct2; case 0x18: /* ARM_SYSST */ return (s->clkm.clocking_scheme << 11) | s->clkm.cold_start; case 0x1c: /* ARM_CKOUT1 */ return s->clkm.arm_ckout1; case 0x20: /* ARM_CKOUT2 */ break; } OMAP_BAD_REG(addr); return 0; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
8,841
static int xen_pt_msgaddr32_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry, uint32_t *val, uint32_t dev_value, uint32_t valid_mask) { XenPTRegInfo *reg = cfg_entry->reg; uint32_t writable_mask = 0; uint32_t old_addr = cfg_entry->data; /* modify emulate register */ writable_mask = reg->emu_mask & ~reg->ro_mask & valid_mask; cfg_entry->data = XEN_PT_MERGE_VALUE(*val, cfg_entry->data, writable_mask); s->msi->addr_lo = cfg_entry->data; /* create value for writing to I/O device register */ *val = XEN_PT_MERGE_VALUE(*val, dev_value, 0); /* update MSI */ if (cfg_entry->data != old_addr) { if (s->msi->mapped) { xen_pt_msi_update(s); } } return 0; }
false
qemu
e2779de053b64f023de382fd87b3596613d47d1e
8,842
static void bdrv_qed_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVQEDState *s = bs->opaque; bs->bl.write_zeroes_alignment = s->header.cluster_size >> BDRV_SECTOR_BITS; }
false
qemu
cf081fca4e3cc02a309659b571ab0c5b225ea4cf
8,843
int block_signals(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; sigset_t set; int pending; /* It's OK to block everything including SIGSEGV, because we won't * run any further guest code before unblocking signals in * process_pending_signals(). */ sigfillset(&set); sigprocmask(SIG_SETMASK, &set, 0); pending = atomic_xchg(&ts->signal_pending, 1); return pending; }
false
qemu
9be385980d37e8f4fd33f605f5fb1c3d144170a8
8,844
static void poll_set_started(AioContext *ctx, bool started) { AioHandler *node; if (started == ctx->poll_started) { return; } ctx->poll_started = started; qemu_lockcnt_inc(&ctx->list_lock); QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) { IOHandler *fn; if (node->deleted) { continue; } if (started) { fn = node->io_poll_begin; } else { fn = node->io_poll_end; } if (fn) { fn(node->opaque); } } qemu_lockcnt_dec(&ctx->list_lock); }
false
qemu
c2b38b277a7882a592f4f2ec955084b2b756daaa
8,845
void qemu_iohandler_fill(GArray *pollfds) { IOHandlerRecord *ioh; QLIST_FOREACH(ioh, &io_handlers, next) { int events = 0; if (ioh->deleted) continue; if (ioh->fd_read && (!ioh->fd_read_poll || ioh->fd_read_poll(ioh->opaque) != 0)) { events |= G_IO_IN | G_IO_HUP | G_IO_ERR; } if (ioh->fd_write) { events |= G_IO_OUT | G_IO_ERR; } if (events) { GPollFD pfd = { .fd = ioh->fd, .events = events, }; ioh->pollfds_idx = pollfds->len; g_array_append_val(pollfds, pfd); } else { ioh->pollfds_idx = -1; } } }
false
qemu
6484e422479c93f28e3f8a68258b0eacd3b31e6d
8,847
static void powernv_create_core_node(PnvChip *chip, PnvCore *pc, void *fdt) { CPUState *cs = CPU(DEVICE(pc->threads)); DeviceClass *dc = DEVICE_GET_CLASS(cs); PowerPCCPU *cpu = POWERPC_CPU(cs); int smt_threads = CPU_CORE(pc)->nr_threads; CPUPPCState *env = &cpu->env; PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs); uint32_t servers_prop[smt_threads]; int i; uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40), 0xffffffff, 0xffffffff}; uint32_t tbfreq = PNV_TIMEBASE_FREQ; uint32_t cpufreq = 1000000000; uint32_t page_sizes_prop[64]; size_t page_sizes_prop_size; const uint8_t pa_features[] = { 24, 0, 0xf6, 0x3f, 0xc7, 0xc0, 0x80, 0xf0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 }; int offset; char *nodename; int cpus_offset = get_cpus_node(fdt); nodename = g_strdup_printf("%s@%x", dc->fw_name, pc->pir); offset = fdt_add_subnode(fdt, cpus_offset, nodename); _FDT(offset); g_free(nodename); _FDT((fdt_setprop_cell(fdt, offset, "ibm,chip-id", chip->chip_id))); _FDT((fdt_setprop_cell(fdt, offset, "reg", pc->pir))); _FDT((fdt_setprop_cell(fdt, offset, "ibm,pir", pc->pir))); _FDT((fdt_setprop_string(fdt, offset, "device_type", "cpu"))); _FDT((fdt_setprop_cell(fdt, offset, "cpu-version", env->spr[SPR_PVR]))); _FDT((fdt_setprop_cell(fdt, offset, "d-cache-block-size", env->dcache_line_size))); _FDT((fdt_setprop_cell(fdt, offset, "d-cache-line-size", env->dcache_line_size))); _FDT((fdt_setprop_cell(fdt, offset, "i-cache-block-size", env->icache_line_size))); _FDT((fdt_setprop_cell(fdt, offset, "i-cache-line-size", env->icache_line_size))); if (pcc->l1_dcache_size) { _FDT((fdt_setprop_cell(fdt, offset, "d-cache-size", pcc->l1_dcache_size))); } else { error_report("Warning: Unknown L1 dcache size for cpu"); } if (pcc->l1_icache_size) { _FDT((fdt_setprop_cell(fdt, offset, "i-cache-size", pcc->l1_icache_size))); } else { error_report("Warning: Unknown L1 icache size for cpu"); } _FDT((fdt_setprop_cell(fdt, offset, "timebase-frequency", tbfreq))); _FDT((fdt_setprop_cell(fdt, offset, "clock-frequency", cpufreq))); _FDT((fdt_setprop_cell(fdt, offset, "ibm,slb-size", env->slb_nr))); _FDT((fdt_setprop_string(fdt, offset, "status", "okay"))); _FDT((fdt_setprop(fdt, offset, "64-bit", NULL, 0))); if (env->spr_cb[SPR_PURR].oea_read) { _FDT((fdt_setprop(fdt, offset, "ibm,purr", NULL, 0))); } if (env->mmu_model & POWERPC_MMU_1TSEG) { _FDT((fdt_setprop(fdt, offset, "ibm,processor-segment-sizes", segs, sizeof(segs)))); } /* Advertise VMX/VSX (vector extensions) if available * 0 / no property == no vector extensions * 1 == VMX / Altivec available * 2 == VSX available */ if (env->insns_flags & PPC_ALTIVEC) { uint32_t vmx = (env->insns_flags2 & PPC2_VSX) ? 2 : 1; _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", vmx))); } /* Advertise DFP (Decimal Floating Point) if available * 0 / no property == no DFP * 1 == DFP available */ if (env->insns_flags2 & PPC2_DFP) { _FDT((fdt_setprop_cell(fdt, offset, "ibm,dfp", 1))); } page_sizes_prop_size = ppc_create_page_sizes_prop(env, page_sizes_prop, sizeof(page_sizes_prop)); if (page_sizes_prop_size) { _FDT((fdt_setprop(fdt, offset, "ibm,segment-page-sizes", page_sizes_prop, page_sizes_prop_size))); } _FDT((fdt_setprop(fdt, offset, "ibm,pa-features", pa_features, sizeof(pa_features)))); /* Build interrupt servers properties */ for (i = 0; i < smt_threads; i++) { servers_prop[i] = cpu_to_be32(pc->pir + i); } _FDT((fdt_setprop(fdt, offset, "ibm,ppc-interrupt-server#s", servers_prop, sizeof(servers_prop)))); }
false
qemu
3dc6f8693694a649a9c83f1e2746565b47683923
8,848
static void test_bh_flush(void) { BHTestData data = { .n = 0 }; data.bh = aio_bh_new(ctx, bh_test_cb, &data); qemu_bh_schedule(data.bh); g_assert_cmpint(data.n, ==, 0); wait_for_aio(); g_assert_cmpint(data.n, ==, 1); g_assert(!aio_poll(ctx, false)); g_assert_cmpint(data.n, ==, 1); qemu_bh_delete(data.bh); }
false
qemu
acfb23ad3dd8d0ab385a10e483776ba7dcf927ad
8,849
static int spapr_tce_table_realize(DeviceState *dev) { sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev); if (kvm_enabled()) { tcet->table = kvmppc_create_spapr_tce(tcet->liobn, tcet->window_size, &tcet->fd); } if (!tcet->table) { size_t table_size = (tcet->window_size >> SPAPR_TCE_PAGE_SHIFT) * sizeof(uint64_t); tcet->table = g_malloc0(table_size); } tcet->nb_table = tcet->window_size >> SPAPR_TCE_PAGE_SHIFT; trace_spapr_iommu_new_table(tcet->liobn, tcet, tcet->table, tcet->fd); memory_region_init_iommu(&tcet->iommu, OBJECT(dev), &spapr_iommu_ops, "iommu-spapr", UINT64_MAX); QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list); vmstate_register(DEVICE(tcet), tcet->liobn, &vmstate_spapr_tce_table, tcet); return 0; }
false
qemu
cca7fad5765251fece44cd230156a101867522dd
8,850
static int avi_write_header(AVFormatContext *s) { AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; AVCodecContext *stream, *video_enc; int64_t list1, list2, strh, strf; AVDictionaryEntry *t = NULL; if (s->nb_streams > AVI_MAX_STREAM_COUNT) { av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n", AVI_MAX_STREAM_COUNT); return -1; } for (n = 0; n < s->nb_streams; n++) { s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream)); if (!s->streams[n]->priv_data) return AVERROR(ENOMEM); } /* header list */ avi->riff_id = 0; list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl"); /* avi header */ ffio_wfourcc(pb, "avih"); avio_wl32(pb, 14 * 4); bitrate = 0; video_enc = NULL; for (n = 0; n < s->nb_streams; n++) { stream = s->streams[n]->codec; bitrate += stream->bit_rate; if (stream->codec_type == AVMEDIA_TYPE_VIDEO) video_enc = stream; } nb_frames = 0; if (video_enc) avio_wl32(pb, (uint32_t) (INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den)); else avio_wl32(pb, 0); avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */ avio_wl32(pb, 0); /* padding */ if (!pb->seekable) avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */ else avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */ avi->frames_hdr_all = avio_tell(pb); /* remember this offset to fill later */ avio_wl32(pb, nb_frames); /* nb frames, filled later */ avio_wl32(pb, 0); /* initial frame */ avio_wl32(pb, s->nb_streams); /* nb streams */ avio_wl32(pb, 1024 * 1024); /* suggested buffer size */ if (video_enc) { avio_wl32(pb, video_enc->width); avio_wl32(pb, video_enc->height); } else { avio_wl32(pb, 0); avio_wl32(pb, 0); } avio_wl32(pb, 0); /* reserved */ avio_wl32(pb, 0); /* reserved */ avio_wl32(pb, 0); /* reserved */ avio_wl32(pb, 0); /* reserved */ /* stream list */ for (i = 0; i < n; i++) { AVIStream *avist = s->streams[i]->priv_data; list2 = ff_start_tag(pb, "LIST"); ffio_wfourcc(pb, "strl"); stream = s->streams[i]->codec; /* stream generic header */ strh = ff_start_tag(pb, "strh"); switch (stream->codec_type) { case AVMEDIA_TYPE_SUBTITLE: // XSUB subtitles behave like video tracks, other subtitles // are not (yet) supported. if (stream->codec_id != AV_CODEC_ID_XSUB) { av_log(s, AV_LOG_ERROR, "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n"); return AVERROR_PATCHWELCOME; } case AVMEDIA_TYPE_VIDEO: ffio_wfourcc(pb, "vids"); break; case AVMEDIA_TYPE_AUDIO: ffio_wfourcc(pb, "auds"); break; // case AVMEDIA_TYPE_TEXT: // ffio_wfourcc(pb, "txts"); // break; case AVMEDIA_TYPE_DATA: ffio_wfourcc(pb, "dats"); break; } if (stream->codec_type == AVMEDIA_TYPE_VIDEO || stream->codec_id == AV_CODEC_ID_XSUB) avio_wl32(pb, stream->codec_tag); else avio_wl32(pb, 1); avio_wl32(pb, 0); /* flags */ avio_wl16(pb, 0); /* priority */ avio_wl16(pb, 0); /* language */ avio_wl32(pb, 0); /* initial frame */ ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); avio_wl32(pb, au_scale); /* scale */ avio_wl32(pb, au_byterate); /* rate */ avpriv_set_pts_info(s->streams[i], 64, au_scale, au_byterate); avio_wl32(pb, 0); /* start */ /* remember this offset to fill later */ avist->frames_hdr_strm = avio_tell(pb); if (!pb->seekable) /* FIXME: this may be broken, but who cares */ avio_wl32(pb, AVI_MAX_RIFF_SIZE); else avio_wl32(pb, 0); /* length, XXX: filled later */ /* suggested buffer size */ //FIXME set at the end to largest chunk if (stream->codec_type == AVMEDIA_TYPE_VIDEO) avio_wl32(pb, 1024 * 1024); else if (stream->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl32(pb, 12 * 1024); else avio_wl32(pb, 0); avio_wl32(pb, -1); /* quality */ avio_wl32(pb, au_ssize); /* sample size */ avio_wl32(pb, 0); avio_wl16(pb, stream->width); avio_wl16(pb, stream->height); ff_end_tag(pb, strh); if (stream->codec_type != AVMEDIA_TYPE_DATA) { strf = ff_start_tag(pb, "strf"); switch (stream->codec_type) { case AVMEDIA_TYPE_SUBTITLE: /* XSUB subtitles behave like video tracks, other subtitles * are not (yet) supported. */ if (stream->codec_id != AV_CODEC_ID_XSUB) break; case AVMEDIA_TYPE_VIDEO: ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0); break; case AVMEDIA_TYPE_AUDIO: if (ff_put_wav_header(pb, stream) < 0) return -1; break; default: return -1; } ff_end_tag(pb, strf); if ((t = av_dict_get(s->streams[i]->metadata, "title", NULL, 0))) { ff_riff_write_info_tag(s->pb, "strn", t->value); t = NULL; } } if (pb->seekable) { unsigned char tag[5]; int j; /* Starting to lay out AVI OpenDML master index. * We want to make it JUNK entry for now, since we'd * like to get away without making AVI an OpenDML one * for compatibility reasons. */ avist->indexes.entry = avist->indexes.ents_allocated = 0; avist->indexes.indx_start = ff_start_tag(pb, "JUNK"); avio_wl16(pb, 4); /* wLongsPerEntry */ avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */ avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */ ffio_wfourcc(pb, avi_stream2fourcc(tag, i, stream->codec_type)); /* dwChunkId */ avio_wl64(pb, 0); /* dwReserved[3] */ // avio_wl32(pb, 0); /* Must be 0. */ for (j = 0; j < AVI_MASTER_INDEX_SIZE * 2; j++) avio_wl64(pb, 0); ff_end_tag(pb, avist->indexes.indx_start); } if (stream->codec_type == AVMEDIA_TYPE_VIDEO && s->streams[i]->sample_aspect_ratio.num > 0 && s->streams[i]->sample_aspect_ratio.den > 0) { int vprp = ff_start_tag(pb, "vprp"); AVRational dar = av_mul_q(s->streams[i]->sample_aspect_ratio, (AVRational) { stream->width, stream->height }); int num, den; av_reduce(&num, &den, dar.num, dar.den, 0xFFFF); avio_wl32(pb, 0); // video format = unknown avio_wl32(pb, 0); // video standard = unknown avio_wl32(pb, lrintf(1.0 / av_q2d(stream->time_base))); avio_wl32(pb, stream->width); avio_wl32(pb, stream->height); avio_wl16(pb, den); avio_wl16(pb, num); avio_wl32(pb, stream->width); avio_wl32(pb, stream->height); avio_wl32(pb, 1); // progressive FIXME avio_wl32(pb, stream->height); avio_wl32(pb, stream->width); avio_wl32(pb, stream->height); avio_wl32(pb, stream->width); avio_wl32(pb, 0); avio_wl32(pb, 0); avio_wl32(pb, 0); avio_wl32(pb, 0); ff_end_tag(pb, vprp); } ff_end_tag(pb, list2); } if (pb->seekable) { /* AVI could become an OpenDML one, if it grows beyond 2Gb range */ avi->odml_list = ff_start_tag(pb, "JUNK"); ffio_wfourcc(pb, "odml"); ffio_wfourcc(pb, "dmlh"); avio_wl32(pb, 248); for (i = 0; i < 248; i += 4) avio_wl32(pb, 0); ff_end_tag(pb, avi->odml_list); } ff_end_tag(pb, list1); ff_riff_write_info(s); /* some padding for easier tag editing */ list2 = ff_start_tag(pb, "JUNK"); for (i = 0; i < 1016; i += 4) avio_wl32(pb, 0); ff_end_tag(pb, list2); avi->movi_list = ff_start_tag(pb, "LIST"); ffio_wfourcc(pb, "movi"); avio_flush(pb); return 0; }
false
FFmpeg
c3311d472a7528c67f76d0d061704ae70a99b32e
8,851
void ide_dma_cb(void *opaque, int ret) { IDEState *s = opaque; int n; int64_t sector_num; bool stay_active = false; if (ret == -ECANCELED) { return; } if (ret < 0) { int op = IDE_RETRY_DMA; if (s->dma_cmd == IDE_DMA_READ) op |= IDE_RETRY_READ; else if (s->dma_cmd == IDE_DMA_TRIM) op |= IDE_RETRY_TRIM; if (ide_handle_rw_error(s, -ret, op)) { return; } } n = s->io_buffer_size >> 9; if (n > s->nsector) { /* The PRDs were longer than needed for this request. Shorten them so * we don't get a negative remainder. The Active bit must remain set * after the request completes. */ n = s->nsector; stay_active = true; } sector_num = ide_get_sector(s); if (n > 0) { dma_buf_commit(s); sector_num += n; ide_set_sector(s, sector_num); s->nsector -= n; } /* end of transfer ? */ if (s->nsector == 0) { s->status = READY_STAT | SEEK_STAT; ide_set_irq(s->bus); goto eot; } /* launch next transfer */ n = s->nsector; s->io_buffer_index = 0; s->io_buffer_size = n * 512; if (s->bus->dma->ops->prepare_buf(s->bus->dma, ide_cmd_is_read(s)) == 0) { /* The PRDs were too short. Reset the Active bit, but don't raise an * interrupt. */ s->status = READY_STAT | SEEK_STAT; goto eot; } #ifdef DEBUG_AIO printf("ide_dma_cb: sector_num=%" PRId64 " n=%d, cmd_cmd=%d\n", sector_num, n, s->dma_cmd); #endif if ((s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) && !ide_sect_range_ok(s, sector_num, n)) { dma_buf_commit(s); ide_dma_error(s); return; } switch (s->dma_cmd) { case IDE_DMA_READ: s->bus->dma->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num, ide_dma_cb, s); break; case IDE_DMA_WRITE: s->bus->dma->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num, ide_dma_cb, s); break; case IDE_DMA_TRIM: s->bus->dma->aiocb = dma_bdrv_io(s->bs, &s->sg, sector_num, ide_issue_trim, ide_dma_cb, s, DMA_DIRECTION_TO_DEVICE); break; } return; eot: if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) { block_acct_done(bdrv_get_stats(s->bs), &s->acct); } ide_set_inactive(s, stay_active); }
false
qemu
4be746345f13e99e468c60acbd3a355e8183e3ce
8,852
int load_elf(const char *filename, int64_t address_offset, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr, int big_endian, int elf_machine, int clear_lsb) { int fd, data_order, target_data_order, must_swab, ret; uint8_t e_ident[EI_NIDENT]; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) { perror(filename); return -1; } if (read(fd, e_ident, sizeof(e_ident)) != sizeof(e_ident)) goto fail; if (e_ident[0] != ELFMAG0 || e_ident[1] != ELFMAG1 || e_ident[2] != ELFMAG2 || e_ident[3] != ELFMAG3) goto fail; #ifdef HOST_WORDS_BIGENDIAN data_order = ELFDATA2MSB; #else data_order = ELFDATA2LSB; #endif must_swab = data_order != e_ident[EI_DATA]; if (big_endian) { target_data_order = ELFDATA2MSB; } else { target_data_order = ELFDATA2LSB; } if (target_data_order != e_ident[EI_DATA]) return -1; lseek(fd, 0, SEEK_SET); if (e_ident[EI_CLASS] == ELFCLASS64) { ret = load_elf64(fd, address_offset, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb); } else { ret = load_elf32(fd, address_offset, must_swab, pentry, lowaddr, highaddr, elf_machine, clear_lsb); } close(fd); return ret; fail: close(fd); return -1; }
false
qemu
45a50b1668822c23afc2a89f724654e176518bc4
8,854
static CharDriverState *qemu_chr_open_pty(const char *id, ChardevBackend *backend, ChardevReturn *ret, Error **errp) { CharDriverState *chr; PtyCharDriver *s; int master_fd, slave_fd; char pty_name[PATH_MAX]; master_fd = qemu_openpty_raw(&slave_fd, pty_name); if (master_fd < 0) { error_setg_errno(errp, errno, "Failed to create PTY"); return NULL; } close(slave_fd); qemu_set_nonblock(master_fd); chr = qemu_chr_alloc(); chr->filename = g_strdup_printf("pty:%s", pty_name); ret->pty = g_strdup(pty_name); ret->has_pty = true; fprintf(stderr, "char device redirected to %s (label %s)\n", pty_name, id); s = g_new0(PtyCharDriver, 1); chr->opaque = s; chr->chr_write = pty_chr_write; chr->chr_update_read_handler = pty_chr_update_read_handler; chr->chr_close = pty_chr_close; chr->chr_add_watch = pty_chr_add_watch; chr->explicit_be_open = true; s->fd = io_channel_from_fd(master_fd); s->timer_tag = 0; return chr; }
false
qemu
d0d7708ba29cbcc343364a46bff981e0ff88366f
8,856
static uint64_t cirrus_linear_read(void *opaque, target_phys_addr_t addr, unsigned size) { CirrusVGAState *s = opaque; uint32_t ret; addr &= s->cirrus_addr_mask; if (((s->vga.sr[0x17] & 0x44) == 0x44) && ((addr & s->linear_mmio_mask) == s->linear_mmio_mask)) { /* memory-mapped I/O */ ret = cirrus_mmio_blt_read(s, addr & 0xff); } else if (0) { /* XXX handle bitblt */ ret = 0xff; } else { /* video memory */ if ((s->vga.gr[0x0B] & 0x14) == 0x14) { addr <<= 4; } else if (s->vga.gr[0x0B] & 0x02) { addr <<= 3; } addr &= s->cirrus_addr_mask; ret = *(s->vga.vram_ptr + addr); } return ret; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
8,857
static int qemu_gluster_create(const char *filename, QemuOpts *opts, Error **errp) { BlockdevOptionsGluster *gconf; struct glfs *glfs; struct glfs_fd *fd; int ret = 0; int prealloc = 0; int64_t total_size = 0; char *tmp = NULL; gconf = g_new0(BlockdevOptionsGluster, 1); gconf->debug = qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG, GLUSTER_DEBUG_DEFAULT); if (gconf->debug < 0) { gconf->debug = 0; } else if (gconf->debug > GLUSTER_DEBUG_MAX) { gconf->debug = GLUSTER_DEBUG_MAX; } gconf->has_debug = true; gconf->logfile = qemu_opt_get_del(opts, GLUSTER_OPT_LOGFILE); if (!gconf->logfile) { gconf->logfile = g_strdup(GLUSTER_LOGFILE_DEFAULT); } gconf->has_logfile = true; glfs = qemu_gluster_init(gconf, filename, NULL, errp); if (!glfs) { ret = -errno; goto out; } total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE); tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); if (!tmp || !strcmp(tmp, "off")) { prealloc = 0; } else if (!strcmp(tmp, "full") && gluster_supports_zerofill()) { prealloc = 1; } else { error_setg(errp, "Invalid preallocation mode: '%s'" " or GlusterFS doesn't support zerofill API", tmp); ret = -EINVAL; goto out; } fd = glfs_creat(glfs, gconf->path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR); if (!fd) { ret = -errno; } else { if (!glfs_ftruncate(fd, total_size)) { if (prealloc && qemu_gluster_zerofill(fd, 0, total_size)) { ret = -errno; } } else { ret = -errno; } if (glfs_close(fd) != 0) { ret = -errno; } } out: g_free(tmp); qapi_free_BlockdevOptionsGluster(gconf); glfs_clear_preopened(glfs); return ret; }
false
qemu
df3a429ae82c0f45becdfab105617701d75e0f05
8,859
static void memory_region_iorange_read(IORange *iorange, uint64_t offset, unsigned width, uint64_t *data) { MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange); if (mr->ops->old_portio) { const MemoryRegionPortio *mrp = find_portio(mr, offset, width, false); *data = ((uint64_t)1 << (width * 8)) - 1; if (mrp) { *data = mrp->read(mr->opaque, offset - mrp->offset); } return; } *data = mr->ops->read(mr->opaque, offset, width); }
false
qemu
3a130f4ef07f4532500473aeab43c86a3c2991c8
8,860
static int ide_drive_initfn(IDEDevice *dev) { return ide_dev_initfn(dev, bdrv_get_type_hint(dev->conf.bs) == BDRV_TYPE_CDROM ? IDE_CD : IDE_HD); }
false
qemu
95b5edcd92d64c7b8fe9f2e3e0725fdf84be0dfa
8,861
static av_cold void h264dsp_init_neon(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) { #if HAVE_NEON if (bit_depth == 8) { c->h264_v_loop_filter_luma = ff_h264_v_loop_filter_luma_neon; c->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_neon; if(chroma_format_idc == 1){ c->h264_v_loop_filter_chroma = ff_h264_v_loop_filter_chroma_neon; c->h264_h_loop_filter_chroma = ff_h264_h_loop_filter_chroma_neon; } c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16_neon; c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_8_neon; c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_4_neon; c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16_neon; c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_8_neon; c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_4_neon; c->h264_idct_add = ff_h264_idct_add_neon; c->h264_idct_dc_add = ff_h264_idct_dc_add_neon; c->h264_idct_add16 = ff_h264_idct_add16_neon; c->h264_idct_add16intra = ff_h264_idct_add16intra_neon; if (chroma_format_idc <= 1) c->h264_idct_add8 = ff_h264_idct_add8_neon; c->h264_idct8_add = ff_h264_idct8_add_neon; c->h264_idct8_dc_add = ff_h264_idct8_dc_add_neon; c->h264_idct8_add4 = ff_h264_idct8_add4_neon; } #endif // HAVE_NEON }
false
FFmpeg
f9f9ae1b77e4fb1bffa6b23be7bd20e514b8ba7b
8,863
int load_vmstate(Monitor *mon, const char *name) { DriveInfo *dinfo; BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn; QEMUFile *f; int ret; bs = get_bs_snapshots(); if (!bs) { monitor_printf(mon, "No block device supports snapshots\n"); return -EINVAL; } /* Flush all IO requests so they don't interfere with the new state. */ qemu_aio_flush(); TAILQ_FOREACH(dinfo, &drives, next) { bs1 = dinfo->bdrv; if (bdrv_has_snapshot(bs1)) { ret = bdrv_snapshot_goto(bs1, name); if (ret < 0) { if (bs != bs1) monitor_printf(mon, "Warning: "); switch(ret) { case -ENOTSUP: monitor_printf(mon, "Snapshots not supported on device '%s'\n", bdrv_get_device_name(bs1)); break; case -ENOENT: monitor_printf(mon, "Could not find snapshot '%s' on " "device '%s'\n", name, bdrv_get_device_name(bs1)); break; default: monitor_printf(mon, "Error %d while activating snapshot on" " '%s'\n", ret, bdrv_get_device_name(bs1)); break; } /* fatal on snapshot block device */ if (bs == bs1) return 0; } } } /* Don't even try to load empty VM states */ ret = bdrv_snapshot_find(bs, &sn, name); if ((ret >= 0) && (sn.vm_state_size == 0)) return -EINVAL; /* restore the VM state */ f = qemu_fopen_bdrv(bs, 0); if (!f) { monitor_printf(mon, "Could not open VM state file\n"); return -EINVAL; } ret = qemu_loadvm_state(f); qemu_fclose(f); if (ret < 0) { monitor_printf(mon, "Error %d while loading VM state\n", ret); return ret; } return 0; }
false
qemu
72cf2d4f0e181d0d3a3122e04129c58a95da713e
8,865
static void spapr_tce_reset(DeviceState *dev) { sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev); size_t table_size = tcet->nb_table * sizeof(uint64_t); tcet->bypass = false; memset(tcet->table, 0, table_size); }
false
qemu
ee9a569ab88edd0755402aaf31ec0c69decf7756
8,867
AVIOContext *avio_alloc_context( unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t (*seek)(void *opaque, int64_t offset, int whence)) { AVIOContext *s = av_mallocz(sizeof(AVIOContext)); ffio_init_context(s, buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek); return s; }
true
FFmpeg
9e2dabed4a7bf21e3e0c0f4ddc895f8ed90fa839
8,868
static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str, int legacy_format) { struct in_addr server = { .s_addr = 0 }; struct GuestFwd *fwd; const char *p; char buf[128]; char *end; int port; p = config_str; if (legacy_format) { if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { goto fail_syntax; } } else { if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { goto fail_syntax; } if (strcmp(buf, "tcp") && buf[0] != '\0') { goto fail_syntax; } if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { goto fail_syntax; } if (buf[0] != '\0' && !inet_aton(buf, &server)) { goto fail_syntax; } if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) { goto fail_syntax; } } port = strtol(buf, &end, 10); if (*end != '\0' || port < 1 || port > 65535) { goto fail_syntax; } fwd = qemu_malloc(sizeof(struct GuestFwd)); snprintf(buf, sizeof(buf), "guestfwd.tcp:%d", port); fwd->hd = qemu_chr_open(buf, p, NULL); if (!fwd->hd) { config_error(mon, "could not open guest forwarding device '%s'\n", buf); qemu_free(fwd); return; } if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) { config_error(mon, "conflicting/invalid host:port in guest forwarding " "rule '%s'\n", config_str); qemu_free(fwd); return; } fwd->server = server; fwd->port = port; fwd->slirp = s->slirp; qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read, NULL, fwd); return; fail_syntax: config_error(mon, "invalid guest forwarding rule '%s'\n", config_str); }
true
qemu
0752706de257b38763006ff5bb6b39a97e669ba2
8,869
int s390_virtio_hypercall(CPUState *env, uint64_t mem, uint64_t hypercall) { int r = 0, i; dprintf("KVM hypercall: %ld\n", hypercall); switch (hypercall) { case KVM_S390_VIRTIO_NOTIFY: if (mem > ram_size) { VirtIOS390Device *dev = s390_virtio_bus_find_vring(s390_bus, mem, &i); if (dev) { virtio_queue_notify(dev->vdev, i); } else { r = -EINVAL; } } else { /* Early printk */ } break; case KVM_S390_VIRTIO_RESET: { VirtIOS390Device *dev; dev = s390_virtio_bus_find_mem(s390_bus, mem); virtio_reset(dev->vdev); s390_virtio_device_sync(dev); break; } case KVM_S390_VIRTIO_SET_STATUS: { VirtIOS390Device *dev; dev = s390_virtio_bus_find_mem(s390_bus, mem); if (dev) { s390_virtio_device_update_status(dev); } else { r = -EINVAL; } break; } default: r = -EINVAL; break; } return r; }
true
qemu
e9d86b760cca52dc35c7716873c342eb03c22b61
8,870
PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem, hwaddr base) { DeviceState *dev; PXA2xxPCMCIAState *s; dev = qdev_create(NULL, TYPE_PXA2XX_PCMCIA); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); s = PXA2XX_PCMCIA(dev); if (base == 0x30000000) { s->slot.slot_string = "PXA PC Card Socket 1"; } else { s->slot.slot_string = "PXA PC Card Socket 0"; } qdev_init_nofail(dev); return s; }
true
qemu
7797a73947d5c0e63dd5552b348cf66c384b4555
8,871
static void qxl_exit_vga_mode(PCIQXLDevice *d) { if (d->mode != QXL_MODE_VGA) { return; } trace_qxl_exit_vga_mode(d->id); qxl_destroy_primary(d, QXL_SYNC); }
true
qemu
0f7bfd8198ffad58a5095ac5d7a46288ea7f5c6e
8,872
static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx, float *samples, const double *lsps, const double *prev_lsps, float *excitation, float *synth) { WMAVoiceContext *s = ctx->priv_data; int n, n_blocks_x2, log_n_blocks_x2, cur_pitch_val; int pitch[MAX_BLOCKS], last_block_pitch; /* Parse frame type ("frame header"), see frame_descs */ int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)], block_nsamples; if (bd_idx < 0) { av_log(ctx, AV_LOG_ERROR, "Invalid frame type VLC code, skipping\n"); return -1; } block_nsamples = MAX_FRAMESIZE / frame_descs[bd_idx].n_blocks; /* Pitch calculation for ACB_TYPE_ASYMMETRIC ("pitch-per-frame") */ if (frame_descs[bd_idx].acb_type == ACB_TYPE_ASYMMETRIC) { /* Pitch is provided per frame, which is interpreted as the pitch of * the last sample of the last block of this frame. We can interpolate * the pitch of other blocks (and even pitch-per-sample) by gradually * incrementing/decrementing prev_frame_pitch to cur_pitch_val. */ n_blocks_x2 = frame_descs[bd_idx].n_blocks << 1; log_n_blocks_x2 = frame_descs[bd_idx].log_n_blocks + 1; cur_pitch_val = s->min_pitch_val + get_bits(gb, s->pitch_nbits); cur_pitch_val = FFMIN(cur_pitch_val, s->max_pitch_val - 1); if (s->last_acb_type == ACB_TYPE_NONE || 20 * abs(cur_pitch_val - s->last_pitch_val) > (cur_pitch_val + s->last_pitch_val)) s->last_pitch_val = cur_pitch_val; /* pitch per block */ for (n = 0; n < frame_descs[bd_idx].n_blocks; n++) { int fac = n * 2 + 1; pitch[n] = (MUL16(fac, cur_pitch_val) + MUL16((n_blocks_x2 - fac), s->last_pitch_val) + frame_descs[bd_idx].n_blocks) >> log_n_blocks_x2; } /* "pitch-diff-per-sample" for calculation of pitch per sample */ s->pitch_diff_sh16 = ((cur_pitch_val - s->last_pitch_val) << 16) / MAX_FRAMESIZE; } /* Global gain (if silence) and pitch-adaptive window coordinates */ switch (frame_descs[bd_idx].fcb_type) { case FCB_TYPE_SILENCE: s->silence_gain = wmavoice_gain_silence[get_bits(gb, 8)]; break; case FCB_TYPE_AW_PULSES: aw_parse_coords(s, gb, pitch); break; } for (n = 0; n < frame_descs[bd_idx].n_blocks; n++) { int bl_pitch_sh2; /* Pitch calculation for ACB_TYPE_HAMMING ("pitch-per-block") */ switch (frame_descs[bd_idx].acb_type) { case ACB_TYPE_HAMMING: { /* Pitch is given per block. Per-block pitches are encoded as an * absolute value for the first block, and then delta values * relative to this value) for all subsequent blocks. The scale of * this pitch value is semi-logaritmic compared to its use in the * decoder, so we convert it to normal scale also. */ int block_pitch, t1 = (s->block_conv_table[1] - s->block_conv_table[0]) << 2, t2 = (s->block_conv_table[2] - s->block_conv_table[1]) << 1, t3 = s->block_conv_table[3] - s->block_conv_table[2] + 1; if (n == 0) { block_pitch = get_bits(gb, s->block_pitch_nbits); } else block_pitch = last_block_pitch - s->block_delta_pitch_hrange + get_bits(gb, s->block_delta_pitch_nbits); /* Convert last_ so that any next delta is within _range */ last_block_pitch = av_clip(block_pitch, s->block_delta_pitch_hrange, s->block_pitch_range - s->block_delta_pitch_hrange); /* Convert semi-log-style scale back to normal scale */ if (block_pitch < t1) { bl_pitch_sh2 = (s->block_conv_table[0] << 2) + block_pitch; } else { block_pitch -= t1; if (block_pitch < t2) { bl_pitch_sh2 = (s->block_conv_table[1] << 2) + (block_pitch << 1); } else { block_pitch -= t2; if (block_pitch < t3) { bl_pitch_sh2 = (s->block_conv_table[2] + block_pitch) << 2; } else bl_pitch_sh2 = s->block_conv_table[3] << 2; } } pitch[n] = bl_pitch_sh2 >> 2; break; } case ACB_TYPE_ASYMMETRIC: { bl_pitch_sh2 = pitch[n] << 2; break; } default: // ACB_TYPE_NONE has no pitch bl_pitch_sh2 = 0; break; } synth_block(s, gb, n, block_nsamples, bl_pitch_sh2, lsps, prev_lsps, &frame_descs[bd_idx], &excitation[n * block_nsamples], &synth[n * block_nsamples]); } /* Averaging projection filter, if applicable. Else, just copy samples * from synthesis buffer */ if (s->do_apf) { double i_lsps[MAX_LSPS]; float lpcs[MAX_LSPS]; for (n = 0; n < s->lsps; n++) // LSF -> LSP i_lsps[n] = cos(0.5 * (prev_lsps[n] + lsps[n])); ff_acelp_lspd2lpc(i_lsps, lpcs, s->lsps >> 1); postfilter(s, synth, samples, 80, lpcs, &s->zero_exc_pf[s->history_nsamples + MAX_FRAMESIZE * frame_idx], frame_descs[bd_idx].fcb_type, pitch[0]); for (n = 0; n < s->lsps; n++) // LSF -> LSP i_lsps[n] = cos(lsps[n]); ff_acelp_lspd2lpc(i_lsps, lpcs, s->lsps >> 1); postfilter(s, &synth[80], &samples[80], 80, lpcs, &s->zero_exc_pf[s->history_nsamples + MAX_FRAMESIZE * frame_idx + 80], frame_descs[bd_idx].fcb_type, pitch[0]); } else memcpy(samples, synth, 160 * sizeof(synth[0])); /* Cache values for next frame */ s->frame_cntr++; if (s->frame_cntr >= 0xFFFF) s->frame_cntr -= 0xFFFF; // i.e. modulo (%) s->last_acb_type = frame_descs[bd_idx].acb_type; switch (frame_descs[bd_idx].acb_type) { case ACB_TYPE_NONE: s->last_pitch_val = 0; break; case ACB_TYPE_ASYMMETRIC: s->last_pitch_val = cur_pitch_val; break; case ACB_TYPE_HAMMING: s->last_pitch_val = pitch[frame_descs[bd_idx].n_blocks - 1]; break; } return 0; }
true
FFmpeg
96a08d8627301dae41a7697ea4346cc9981df17c
8,875
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd) { int64_t r = 0; av_assert2(c > 0); av_assert2(b >=0); av_assert2((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4); if (c <= 0 || b < 0 || !((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4)) return INT64_MIN; if (rnd & AV_ROUND_PASS_MINMAX) { if (a == INT64_MIN || a == INT64_MAX) return a; rnd -= AV_ROUND_PASS_MINMAX; } if (a < 0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd >> 1) & 1)); if (rnd == AV_ROUND_NEAR_INF) r = c / 2; else if (rnd & 1) r = c - 1; if (b <= INT_MAX && c <= INT_MAX) { if (a <= INT_MAX) return (a * b + r) / c; else return a / c * b + (a % c * b + r) / c; } else { #if 1 uint64_t a0 = a & 0xFFFFFFFF; uint64_t a1 = a >> 32; uint64_t b0 = b & 0xFFFFFFFF; uint64_t b1 = b >> 32; uint64_t t1 = a0 * b1 + a1 * b0; uint64_t t1a = t1 << 32; int i; a0 = a0 * b0 + t1a; a1 = a1 * b1 + (t1 >> 32) + (a0 < t1a); a0 += r; a1 += a0 < r; for (i = 63; i >= 0; i--) { a1 += a1 + ((a0 >> i) & 1); t1 += t1; if (c <= a1) { a1 -= c; t1++; } } return t1; } #else AVInteger ai; ai = av_mul_i(av_int2i(a), av_int2i(b)); ai = av_add_i(ai, av_int2i(r)); return av_i2int(av_div_i(ai, av_int2i(c))); } #endif }
false
FFmpeg
25e37f5ea92d4201976a59ae306ce848d257a7e6
8,876
static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size) { uint8_t *dest = dst; const uint8_t *s = src; const uint8_t *end; #if COMPILE_TEMPLATE_MMX const uint8_t *mm_end; #endif end = s + src_size; #if COMPILE_TEMPLATE_MMX __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); mm_end = end - 23; __asm__ volatile("movq %0, %%mm7"::"m"(mask32a):"memory"); while (s < mm_end) { __asm__ volatile( PREFETCH" 32%1 \n\t" "movd %1, %%mm0 \n\t" "punpckldq 3%1, %%mm0 \n\t" "movd 6%1, %%mm1 \n\t" "punpckldq 9%1, %%mm1 \n\t" "movd 12%1, %%mm2 \n\t" "punpckldq 15%1, %%mm2 \n\t" "movd 18%1, %%mm3 \n\t" "punpckldq 21%1, %%mm3 \n\t" "por %%mm7, %%mm0 \n\t" "por %%mm7, %%mm1 \n\t" "por %%mm7, %%mm2 \n\t" "por %%mm7, %%mm3 \n\t" MOVNTQ" %%mm0, %0 \n\t" MOVNTQ" %%mm1, 8%0 \n\t" MOVNTQ" %%mm2, 16%0 \n\t" MOVNTQ" %%mm3, 24%0" :"=m"(*dest) :"m"(*s) :"memory"); dest += 32; s += 24; } __asm__ volatile(SFENCE:::"memory"); __asm__ volatile(EMMS:::"memory"); #endif while (s < end) { #if HAVE_BIGENDIAN /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */ *dest++ = 255; *dest++ = s[2]; *dest++ = s[1]; *dest++ = s[0]; s+=3; #else *dest++ = *s++; *dest++ = *s++; *dest++ = *s++; *dest++ = 255; #endif } }
false
FFmpeg
d1adad3cca407f493c3637e20ecd4f7124e69212
8,877
static void FUNC(transquant_bypass16x16)(uint8_t *_dst, int16_t *coeffs, ptrdiff_t stride) { int x, y; pixel *dst = (pixel *)_dst; stride /= sizeof(pixel); for (y = 0; y < 16; y++) { for (x = 0; x < 16; x++) { dst[x] += *coeffs; coeffs++; } dst += stride; } }
false
FFmpeg
c9fe0caf7a1abde7ca0b1a359f551103064867b1
8,879
static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* format) { AVCodecContext *avctx = opaque; CuvidContext *ctx = avctx->priv_data; AVHWFramesContext *hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data; CUVIDDECODECREATEINFO cuinfo; int surface_fmt; enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA, AV_PIX_FMT_NONE, // Will be updated below AV_PIX_FMT_NONE }; av_log(avctx, AV_LOG_TRACE, "pfnSequenceCallback, progressive_sequence=%d\n", format->progressive_sequence); ctx->internal_error = 0; switch (format->bit_depth_luma_minus8) { case 0: // 8-bit pix_fmts[1] = AV_PIX_FMT_NV12; break; case 2: // 10-bit pix_fmts[1] = AV_PIX_FMT_P010; break; case 4: // 12-bit pix_fmts[1] = AV_PIX_FMT_P016; break; default: av_log(avctx, AV_LOG_ERROR, "unsupported bit depth: %d\n", format->bit_depth_luma_minus8 + 8); ctx->internal_error = AVERROR(EINVAL); return 0; } surface_fmt = ff_get_format(avctx, pix_fmts); if (surface_fmt < 0) { av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", surface_fmt); ctx->internal_error = AVERROR(EINVAL); return 0; } av_log(avctx, AV_LOG_VERBOSE, "Formats: Original: %s | HW: %s | SW: %s\n", av_get_pix_fmt_name(avctx->pix_fmt), av_get_pix_fmt_name(surface_fmt), av_get_pix_fmt_name(avctx->sw_pix_fmt)); avctx->pix_fmt = surface_fmt; // Update our hwframe ctx, as the get_format callback might have refreshed it! if (avctx->hw_frames_ctx) { av_buffer_unref(&ctx->hwframe); ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx); if (!ctx->hwframe) { ctx->internal_error = AVERROR(ENOMEM); return 0; } hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data; } avctx->width = format->display_area.right; avctx->height = format->display_area.bottom; ff_set_sar(avctx, av_div_q( (AVRational){ format->display_aspect_ratio.x, format->display_aspect_ratio.y }, (AVRational){ avctx->width, avctx->height })); if (!format->progressive_sequence && ctx->deint_mode == cudaVideoDeinterlaceMode_Weave) avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT; else avctx->flags &= ~AV_CODEC_FLAG_INTERLACED_DCT; if (format->video_signal_description.video_full_range_flag) avctx->color_range = AVCOL_RANGE_JPEG; else avctx->color_range = AVCOL_RANGE_MPEG; avctx->color_primaries = format->video_signal_description.color_primaries; avctx->color_trc = format->video_signal_description.transfer_characteristics; avctx->colorspace = format->video_signal_description.matrix_coefficients; if (format->bitrate) avctx->bit_rate = format->bitrate; if (format->frame_rate.numerator && format->frame_rate.denominator) { avctx->framerate.num = format->frame_rate.numerator; avctx->framerate.den = format->frame_rate.denominator; } if (ctx->cudecoder && avctx->coded_width == format->coded_width && avctx->coded_height == format->coded_height && ctx->chroma_format == format->chroma_format && ctx->codec_type == format->codec) return 1; if (ctx->cudecoder) { av_log(avctx, AV_LOG_TRACE, "Re-initializing decoder\n"); ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder)); if (ctx->internal_error < 0) return 0; ctx->cudecoder = NULL; } if (hwframe_ctx->pool && ( hwframe_ctx->width < avctx->width || hwframe_ctx->height < avctx->height || hwframe_ctx->format != AV_PIX_FMT_CUDA || hwframe_ctx->sw_format != avctx->sw_pix_fmt)) { av_log(avctx, AV_LOG_ERROR, "AVHWFramesContext is already initialized with incompatible parameters\n"); ctx->internal_error = AVERROR(EINVAL); return 0; } if (format->chroma_format != cudaVideoChromaFormat_420) { av_log(avctx, AV_LOG_ERROR, "Chroma formats other than 420 are not supported\n"); ctx->internal_error = AVERROR(EINVAL); return 0; } avctx->coded_width = format->coded_width; avctx->coded_height = format->coded_height; ctx->chroma_format = format->chroma_format; memset(&cuinfo, 0, sizeof(cuinfo)); cuinfo.CodecType = ctx->codec_type = format->codec; cuinfo.ChromaFormat = format->chroma_format; switch (avctx->sw_pix_fmt) { case AV_PIX_FMT_NV12: cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12; break; case AV_PIX_FMT_P010: case AV_PIX_FMT_P016: cuinfo.OutputFormat = cudaVideoSurfaceFormat_P016; break; default: av_log(avctx, AV_LOG_ERROR, "Output formats other than NV12, P010 or P016 are not supported\n"); ctx->internal_error = AVERROR(EINVAL); return 0; } cuinfo.ulWidth = avctx->coded_width; cuinfo.ulHeight = avctx->coded_height; cuinfo.ulTargetWidth = cuinfo.ulWidth; cuinfo.ulTargetHeight = cuinfo.ulHeight; cuinfo.target_rect.left = 0; cuinfo.target_rect.top = 0; cuinfo.target_rect.right = cuinfo.ulWidth; cuinfo.target_rect.bottom = cuinfo.ulHeight; cuinfo.ulNumDecodeSurfaces = ctx->nb_surfaces; cuinfo.ulNumOutputSurfaces = 1; cuinfo.ulCreationFlags = cudaVideoCreate_PreferCUVID; cuinfo.bitDepthMinus8 = format->bit_depth_luma_minus8; if (format->progressive_sequence) { ctx->deint_mode = cuinfo.DeinterlaceMode = cudaVideoDeinterlaceMode_Weave; } else { cuinfo.DeinterlaceMode = ctx->deint_mode; } if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave) avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1}); ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&ctx->cudecoder, &cuinfo)); if (ctx->internal_error < 0) return 0; if (!hwframe_ctx->pool) { hwframe_ctx->format = AV_PIX_FMT_CUDA; hwframe_ctx->sw_format = avctx->sw_pix_fmt; hwframe_ctx->width = avctx->width; hwframe_ctx->height = avctx->height; if ((ctx->internal_error = av_hwframe_ctx_init(ctx->hwframe)) < 0) { av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_init failed\n"); return 0; } } return 1; }
false
FFmpeg
ce79410bba776d4121685654056f2b4e39bbd3f7
8,880
static void set_stream_info_from_input_stream(AVStream *st, struct playlist *pls, AVStream *ist) { avcodec_parameters_copy(st->codecpar, ist->codecpar); if (pls->is_id3_timestamped) /* custom timestamps via id3 */ avpriv_set_pts_info(st, 33, 1, MPEG_TIME_BASE); else avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den); st->internal->need_context_update = 1; }
false
FFmpeg
e2193b53eab9f207544a75ebaf51871b7a1a7931
8,882
void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size) { const uint8_t *r, *end = buf1 + size; RTPMuxContext *s = s1->priv_data; s->timestamp = s->cur_timestamp; s->buf_ptr = s->buf; if (s->nal_length_size) r = ff_avc_mp4_find_startcode(buf1, end, s->nal_length_size) ? buf1 : end; else r = ff_avc_find_startcode(buf1, end); while (r < end) { const uint8_t *r1; if (s->nal_length_size) { r1 = ff_avc_mp4_find_startcode(r, end, s->nal_length_size); if (!r1) r1 = end; r += s->nal_length_size; } else { while (!*(r++)); r1 = ff_avc_find_startcode(r, end); } nal_send(s1, r, r1 - r, r1 == end); r = r1; } flush_buffered(s1, 1); }
true
FFmpeg
c82bf15dca00f67a701d126e47ea9075fc9459cb
8,883
static inline void idct4col_put(uint8_t *dest, int line_size, const DCTELEM *col) { int c0, c1, c2, c3, a0, a1, a2, a3; const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; a0 = col[8*0]; a1 = col[8*2]; a2 = col[8*4]; a3 = col[8*6]; c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c1 = a1 * C1 + a3 * C2; c3 = a1 * C2 - a3 * C1; dest[0] = cm[(c0 + c1) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c2 + c3) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c2 - c3) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c0 - c1) >> C_SHIFT]; }
true
FFmpeg
c23acbaed40101c677dfcfbbfe0d2c230a8e8f44
8,884
static ExitStatus gen_fbcond(DisasContext *ctx, TCGCond cond, int ra, int32_t disp) { TCGv cmp_tmp = tcg_temp_new(); gen_fold_mzero(cond, cmp_tmp, load_fpr(ctx, ra)); return gen_bcond_internal(ctx, cond, cmp_tmp, disp); }
true
qemu
6a9b110d54b885dbb29872a142cc4d2a402fada8
8,885
int cpu_ppc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, int is_user, int is_softmmu) { mmu_ctx_t ctx; int access_type; int ret = 0; if (rw == 2) { /* code access */ rw = 0; access_type = ACCESS_CODE; } else { /* data access */ /* XXX: put correct access by using cpu_restore_state() correctly */ access_type = ACCESS_INT; // access_type = env->access_type; } ret = get_physical_address(env, &ctx, address, rw, access_type, 1); if (ret == 0) { ret = tlb_set_page(env, address & TARGET_PAGE_MASK, ctx.raddr & TARGET_PAGE_MASK, ctx.prot, is_user, is_softmmu); } else if (ret < 0) { #if defined (DEBUG_MMU) if (loglevel != 0) cpu_dump_state(env, logfile, fprintf, 0); #endif if (access_type == ACCESS_CODE) { switch (ret) { case -1: /* No matches in page tables or TLB */ switch (env->mmu_model) { case POWERPC_MMU_SOFT_6xx: env->exception_index = POWERPC_EXCP_IFTLB; env->error_code = 1 << 18; env->spr[SPR_IMISS] = address; env->spr[SPR_ICMP] = 0x80000000 | ctx.ptem; goto tlb_miss; case POWERPC_MMU_SOFT_74xx: env->exception_index = POWERPC_EXCP_IFTLB; goto tlb_miss_74xx; case POWERPC_MMU_SOFT_4xx: case POWERPC_MMU_SOFT_4xx_Z: env->exception_index = POWERPC_EXCP_ITLB; env->error_code = 0; env->spr[SPR_40x_DEAR] = address; env->spr[SPR_40x_ESR] = 0x00000000; break; case POWERPC_MMU_32B: #if defined(TARGET_PPC64) case POWERPC_MMU_64B: case POWERPC_MMU_64BRIDGE: #endif env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x40000000; break; case POWERPC_MMU_601: /* XXX: TODO */ cpu_abort(env, "MMU model not implemented\n"); return -1; case POWERPC_MMU_BOOKE: /* XXX: TODO */ cpu_abort(env, "MMU model not implemented\n"); return -1; case POWERPC_MMU_BOOKE_FSL: /* XXX: TODO */ cpu_abort(env, "MMU model not implemented\n"); return -1; case POWERPC_MMU_REAL_4xx: cpu_abort(env, "PowerPC 401 should never raise any MMU " "exceptions\n"); return -1; default: cpu_abort(env, "Unknown or invalid MMU model\n"); return -1; } break; case -2: /* Access rights violation */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x08000000; break; case -3: /* No execute protection violation */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x10000000; break; case -4: /* Direct store exception */ /* No code fetch is allowed in direct-store areas */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x10000000; break; #if defined(TARGET_PPC64) case -5: /* No match in segment table */ env->exception_index = POWERPC_EXCP_ISEG; env->error_code = 0; break; #endif } } else { switch (ret) { case -1: /* No matches in page tables or TLB */ switch (env->mmu_model) { case POWERPC_MMU_SOFT_6xx: if (rw == 1) { env->exception_index = POWERPC_EXCP_DSTLB; env->error_code = 1 << 16; } else { env->exception_index = POWERPC_EXCP_DLTLB; env->error_code = 0; } env->spr[SPR_DMISS] = address; env->spr[SPR_DCMP] = 0x80000000 | ctx.ptem; tlb_miss: env->error_code |= ctx.key << 19; env->spr[SPR_HASH1] = ctx.pg_addr[0]; env->spr[SPR_HASH2] = ctx.pg_addr[1]; break; case POWERPC_MMU_SOFT_74xx: if (rw == 1) { env->exception_index = POWERPC_EXCP_DSTLB; } else { env->exception_index = POWERPC_EXCP_DLTLB; } tlb_miss_74xx: /* Implement LRU algorithm */ env->error_code = ctx.key << 19; env->spr[SPR_TLBMISS] = (address & ~((target_ulong)0x3)) | ((env->last_way + 1) & (env->nb_ways - 1)); env->spr[SPR_PTEHI] = 0x80000000 | ctx.ptem; break; case POWERPC_MMU_SOFT_4xx: case POWERPC_MMU_SOFT_4xx_Z: env->exception_index = POWERPC_EXCP_DTLB; env->error_code = 0; env->spr[SPR_40x_DEAR] = address; if (rw) env->spr[SPR_40x_ESR] = 0x00800000; else env->spr[SPR_40x_ESR] = 0x00000000; break; case POWERPC_MMU_32B: #if defined(TARGET_PPC64) case POWERPC_MMU_64B: case POWERPC_MMU_64BRIDGE: #endif env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) env->spr[SPR_DSISR] = 0x42000000; else env->spr[SPR_DSISR] = 0x40000000; break; case POWERPC_MMU_601: /* XXX: TODO */ cpu_abort(env, "MMU model not implemented\n"); return -1; case POWERPC_MMU_BOOKE: /* XXX: TODO */ cpu_abort(env, "MMU model not implemented\n"); return -1; case POWERPC_MMU_BOOKE_FSL: /* XXX: TODO */ cpu_abort(env, "MMU model not implemented\n"); return -1; case POWERPC_MMU_REAL_4xx: cpu_abort(env, "PowerPC 401 should never raise any MMU " "exceptions\n"); return -1; default: cpu_abort(env, "Unknown or invalid MMU model\n"); return -1; } break; case -2: /* Access rights violation */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) env->spr[SPR_DSISR] = 0x0A000000; else env->spr[SPR_DSISR] = 0x08000000; break; case -4: /* Direct store exception */ switch (access_type) { case ACCESS_FLOAT: /* Floating point load/store */ env->exception_index = POWERPC_EXCP_ALIGN; env->error_code = POWERPC_EXCP_ALIGN_FP; env->spr[SPR_DAR] = address; break; case ACCESS_RES: /* lwarx, ldarx or stwcx. */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) env->spr[SPR_DSISR] = 0x06000000; else env->spr[SPR_DSISR] = 0x04000000; break; case ACCESS_EXT: /* eciwx or ecowx */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) env->spr[SPR_DSISR] = 0x06100000; else env->spr[SPR_DSISR] = 0x04100000; break; default: printf("DSI: invalid exception (%d)\n", ret); env->exception_index = POWERPC_EXCP_PROGRAM; env->error_code = POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL; env->spr[SPR_DAR] = address; break; } break; #if defined(TARGET_PPC64) case -5: /* No match in segment table */ env->exception_index = POWERPC_EXCP_DSEG; env->error_code = 0; env->spr[SPR_DAR] = address; break; #endif } } #if 0 printf("%s: set exception to %d %02x\n", __func__, env->exception, env->error_code); #endif ret = 1; } return ret; }
true
qemu
12de9a396acbc95e25c5d60ed097cc55777eaaed
8,886
static inline void writer_print_string(WriterContext *wctx, const char *key, const char *val) { wctx->writer->print_string(wctx, key, val); wctx->nb_item++; }
false
FFmpeg
0491a2a07a44f6e5e6f34081835e402c07025fd2
8,887
static av_cold int cinvideo_decode_init(AVCodecContext *avctx) { CinVideoContext *cin = avctx->priv_data; unsigned int i; cin->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_PAL8; cin->frame.data[0] = NULL; cin->bitmap_size = avctx->width * avctx->height; for (i = 0; i < 3; ++i) { cin->bitmap_table[i] = av_mallocz(cin->bitmap_size); if (!cin->bitmap_table[i]) av_log(avctx, AV_LOG_ERROR, "Can't allocate bitmap buffers.\n"); } return 0; }
false
FFmpeg
3b199d29cd597a3518136d78860e172060b9e83d
8,888
static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile, unsigned *nb_files_alloc) { ConcatContext *cat = avf->priv_data; ConcatFile *file; char *url; size_t url_len; url_len = strlen(avf->filename) + strlen(filename) + 16; if (!(url = av_malloc(url_len))) return AVERROR(ENOMEM); ff_make_absolute_url(url, url_len, avf->filename, filename); av_free(filename); if (cat->nb_files >= *nb_files_alloc) { unsigned n = FFMAX(*nb_files_alloc * 2, 16); ConcatFile *new_files; if (n <= cat->nb_files || n > SIZE_MAX / sizeof(*cat->files) || !(new_files = av_realloc(cat->files, n * sizeof(*cat->files)))) return AVERROR(ENOMEM); cat->files = new_files; *nb_files_alloc = n; } file = &cat->files[cat->nb_files++]; memset(file, 0, sizeof(*file)); *rfile = file; file->url = url; file->start_time = AV_NOPTS_VALUE; file->duration = AV_NOPTS_VALUE; return 0; }
false
FFmpeg
8976ef7aec4c62e41a0abb50d2bf4dbfa3508e2a
8,889
int kvm_arch_remove_hw_breakpoint(target_ulong addr, target_ulong len, int type) { return -EINVAL; }
true
qemu
88365d17d586bcf0d9f4432447db345f72278a2a
8,890
static double compute_target_time(double frame_current_pts, VideoState *is) { double delay, sync_threshold, diff; /* compute nominal delay */ delay = frame_current_pts - is->frame_last_pts; if (delay <= 0 || delay >= 10.0) { /* if incorrect delay, use previous one */ delay = is->frame_last_delay; } else { is->frame_last_delay = delay; } is->frame_last_pts = frame_current_pts; /* update delay to follow master synchronisation source */ if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) || is->av_sync_type == AV_SYNC_EXTERNAL_CLOCK)) { /* if video is slave, we try to correct big delays by duplicating or deleting a frame */ diff = get_video_clock(is) - get_master_clock(is); /* skip or repeat frame. We take into account the delay to compute the threshold. I still don't know if it is the best guess */ sync_threshold = FFMAX(AV_SYNC_THRESHOLD, delay); if (fabs(diff) < AV_NOSYNC_THRESHOLD) { if (diff <= -sync_threshold) delay = 0; else if (diff >= sync_threshold) delay = 2 * delay; } } is->frame_timer += delay; av_log(NULL, AV_LOG_TRACE, "video: delay=%0.3f pts=%0.3f A-V=%f\n", delay, frame_current_pts, -diff); return is->frame_timer; }
true
FFmpeg
06f4b1e37a08f3fd269ecbfeb0181129e5bfc86e
8,891
long target_mmap(target_ulong start, target_ulong len, int prot, int flags, int fd, target_ulong offset) { target_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len; long host_start; #if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__) || \ defined(__ia64) || defined(__mips__) static target_ulong last_start = 0x40000000; #elif defined(__CYGWIN__) /* Cygwin doesn't have a whole lot of address space. */ static target_ulong last_start = 0x18000000; #endif #ifdef DEBUG_MMAP { printf("mmap: start=0x%lx len=0x%lx prot=%c%c%c flags=", start, len, prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); if (flags & MAP_FIXED) printf("MAP_FIXED "); if (flags & MAP_ANONYMOUS) printf("MAP_ANON "); switch(flags & MAP_TYPE) { case MAP_PRIVATE: printf("MAP_PRIVATE "); break; case MAP_SHARED: printf("MAP_SHARED "); break; default: printf("[MAP_TYPE=0x%x] ", flags & MAP_TYPE); break; } printf("fd=%d offset=%lx\n", fd, offset); } #endif if (offset & ~TARGET_PAGE_MASK) { errno = EINVAL; return -1; } len = TARGET_PAGE_ALIGN(len); if (len == 0) return start; real_start = start & qemu_host_page_mask; if (!(flags & MAP_FIXED)) { #if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__) || \ defined(__ia64) || defined(__mips__) || defined(__CYGWIN__) /* tell the kernel to search at the same place as i386 */ if (real_start == 0) { real_start = last_start; last_start += HOST_PAGE_ALIGN(len); } #endif if (0 && qemu_host_page_size != qemu_real_host_page_size) { /* NOTE: this code is only for debugging with '-p' option */ /* ??? Can also occur when TARGET_PAGE_SIZE > host page size. */ /* reserve a memory area */ /* ??? This needs fixing for remapping. */ abort(); host_len = HOST_PAGE_ALIGN(len) + qemu_host_page_size - TARGET_PAGE_SIZE; real_start = (long)mmap(g2h(real_start), host_len, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (real_start == -1) return real_start; real_end = real_start + host_len; start = HOST_PAGE_ALIGN(real_start); end = start + HOST_PAGE_ALIGN(len); if (start > real_start) munmap((void *)real_start, start - real_start); if (end < real_end) munmap((void *)end, real_end - end); /* use it as a fixed mapping */ flags |= MAP_FIXED; } else { /* if not fixed, no need to do anything */ host_offset = offset & qemu_host_page_mask; host_len = len + offset - host_offset; host_start = (long)mmap(real_start ? g2h(real_start) : NULL, host_len, prot, flags, fd, host_offset); if (host_start == -1) return host_start; /* update start so that it points to the file position at 'offset' */ if (!(flags & MAP_ANONYMOUS)) host_start += offset - host_offset; start = h2g(host_start); goto the_end1; } } if (start & ~TARGET_PAGE_MASK) { errno = EINVAL; return -1; } end = start + len; real_end = HOST_PAGE_ALIGN(end); /* worst case: we cannot map the file because the offset is not aligned, so we read it */ if (!(flags & MAP_ANONYMOUS) && (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) { /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & MAP_TYPE) == MAP_SHARED && (prot & PROT_WRITE)) { errno = EINVAL; return -1; } retaddr = target_mmap(start, len, prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr == -1) return retaddr; pread(fd, g2h(start), len, offset); if (!(prot & PROT_WRITE)) { ret = target_mprotect(start, len, prot); if (ret != 0) return ret; } goto the_end; } /* handle the start of the mapping */ if (start > real_start) { if (real_end == real_start + qemu_host_page_size) { /* one single host page */ ret = mmap_frag(real_start, start, end, prot, flags, fd, offset); if (ret == -1) return ret; goto the_end1; } ret = mmap_frag(real_start, start, real_start + qemu_host_page_size, prot, flags, fd, offset); if (ret == -1) return ret; real_start += qemu_host_page_size; } /* handle the end of the mapping */ if (end < real_end) { ret = mmap_frag(real_end - qemu_host_page_size, real_end - qemu_host_page_size, real_end, prot, flags, fd, offset + real_end - qemu_host_page_size - start); if (ret == -1) return ret; real_end -= qemu_host_page_size; } /* map the middle (easier) */ if (real_start < real_end) { unsigned long offset1; if (flags & MAP_ANONYMOUS) offset1 = 0; else offset1 = offset + real_start - start; ret = (long)mmap(g2h(real_start), real_end - real_start, prot, flags, fd, offset1); if (ret == -1) return ret; } the_end1: page_set_flags(start, start + len, prot | PAGE_VALID); the_end: #ifdef DEBUG_MMAP printf("ret=0x%lx\n", (long)start); page_dump(stdout); printf("\n"); #endif return start; }
true
qemu
4118a97030aa9bd1d520d1d06bbe0655d829df04
8,892
read_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, pflag = 0, qflag = 0, vflag = 0; int Pflag = 0, sflag = 0, lflag = 0; int c, cnt; char *buf; int64_t offset; int count; /* Some compilers get confused and warn if this is not initialized. */ int total = 0; int pattern = 0, pattern_offset = 0, pattern_count = 0; while ((c = getopt(argc, argv, "Cl:pP:qs:v")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'l': lflag = 1; pattern_count = cvtnum(optarg); if (pattern_count < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'p': pflag = 1; break; case 'P': Pflag = 1; pattern = atoi(optarg); break; case 'q': qflag = 1; break; case 's': sflag = 1; pattern_offset = cvtnum(optarg); if (pattern_offset < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'v': vflag = 1; break; default: return command_usage(&read_cmd); } } if (optind != argc - 2) return command_usage(&read_cmd); offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } optind++; count = cvtnum(argv[optind]); if (count < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } if (!Pflag && (lflag || sflag)) { return command_usage(&read_cmd); } if (!lflag) { pattern_count = count - pattern_offset; } if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) { printf("pattern verfication range exceeds end of read data\n"); return 0; } if (!pflag) if (offset & 0x1ff) { printf("offset %lld is not sector aligned\n", (long long)offset); return 0; if (count & 0x1ff) { printf("count %d is not sector aligned\n", count); return 0; } } buf = qemu_io_alloc(count, 0xab); gettimeofday(&t1, NULL); if (pflag) cnt = do_pread(buf, offset, count, &total); else cnt = do_read(buf, offset, count, &total); gettimeofday(&t2, NULL); if (cnt < 0) { printf("read failed: %s\n", strerror(-cnt)); return 0; } if (Pflag) { void* cmp_buf = malloc(pattern_count); memset(cmp_buf, pattern, pattern_count); if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) { printf("Pattern verification failed at offset %lld, " "%d bytes\n", (long long) offset + pattern_offset, pattern_count); } free(cmp_buf); } if (qflag) return 0; if (vflag) dump_buffer(buf, offset, count); /* Finally, report back -- -C gives a parsable format */ t2 = tsub(t2, t1); print_report("read", &t2, offset, count, total, cnt, Cflag); qemu_io_free(buf); return 0; }
true
qemu
7d8abfcb50a33aed369bbd267852cf04009c49e9
8,893
e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; struct e1000_rx_desc desc; target_phys_addr_t base; unsigned int n, rdt; uint32_t rdh_start; uint16_t vlan_special = 0; uint8_t vlan_status = 0, vlan_offset = 0; uint8_t min_buf[MIN_BUF_SIZE]; size_t desc_offset; size_t desc_size; size_t total_size; if (!(s->mac_reg[RCTL] & E1000_RCTL_EN)) return -1; /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { memcpy(min_buf, buf, size); memset(&min_buf[size], 0, sizeof(min_buf) - size); buf = min_buf; size = sizeof(min_buf); } if (!receive_filter(s, buf, size)) return size; if (vlan_enabled(s) && is_vlan_packet(s, buf)) { vlan_special = cpu_to_le16(be16_to_cpup((uint16_t *)(buf + 14))); memmove((uint8_t *)buf + 4, buf, 12); vlan_status = E1000_RXD_STAT_VP; vlan_offset = 4; size -= 4; } rdh_start = s->mac_reg[RDH]; desc_offset = 0; total_size = size + fcs_len(s); do { desc_size = total_size - desc_offset; if (desc_size > s->rxbuf_size) { desc_size = s->rxbuf_size; } if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) { /* Discard all data written so far */ s->mac_reg[RDH] = rdh_start; set_ics(s, 0, E1000_ICS_RXO); return -1; } base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] + sizeof(desc) * s->mac_reg[RDH]; cpu_physical_memory_read(base, (void *)&desc, sizeof(desc)); desc.special = vlan_special; desc.status |= (vlan_status | E1000_RXD_STAT_DD); if (desc.buffer_addr) { if (desc_offset < size) { size_t copy_size = size - desc_offset; if (copy_size > s->rxbuf_size) { copy_size = s->rxbuf_size; } cpu_physical_memory_write(le64_to_cpu(desc.buffer_addr), (void *)(buf + desc_offset + vlan_offset), copy_size); } desc_offset += desc_size; desc.length = cpu_to_le16(desc_size); if (desc_offset >= total_size) { desc.status |= E1000_RXD_STAT_EOP | E1000_RXD_STAT_IXSM; } else { /* Guest zeroing out status is not a hardware requirement. Clear EOP in case guest didn't do it. */ desc.status &= ~E1000_RXD_STAT_EOP; } } else { // as per intel docs; skip descriptors with null buf addr DBGOUT(RX, "Null RX descriptor!!\n"); } cpu_physical_memory_write(base, (void *)&desc, sizeof(desc)); if (++s->mac_reg[RDH] * sizeof(desc) >= s->mac_reg[RDLEN]) s->mac_reg[RDH] = 0; s->check_rxov = 1; /* see comment in start_xmit; same here */ if (s->mac_reg[RDH] == rdh_start) { DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n", rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]); set_ics(s, 0, E1000_ICS_RXO); return -1; } } while (desc_offset < total_size); s->mac_reg[GPRC]++; s->mac_reg[TPR]++; /* TOR - Total Octets Received: * This register includes bytes received in a packet from the <Destination * Address> field through the <CRC> field, inclusively. */ n = s->mac_reg[TORL] + size + /* Always include FCS length. */ 4; if (n < s->mac_reg[TORL]) s->mac_reg[TORH]++; s->mac_reg[TORL] = n; n = E1000_ICS_RXT0; if ((rdt = s->mac_reg[RDT]) < s->mac_reg[RDH]) rdt += s->mac_reg[RDLEN] / sizeof(desc); if (((rdt - s->mac_reg[RDH]) * sizeof(desc)) <= s->mac_reg[RDLEN] >> s->rxbuf_min_shift) n |= E1000_ICS_RXDMT0; set_ics(s, 0, n); return size; }
true
qemu
322fd48afbed1ef7b834ac343a0c8687bcb33695
8,894
static void ehci_update_frindex(EHCIState *ehci, int uframes) { int i; if (!ehci_enabled(ehci) && ehci->pstate == EST_INACTIVE) { return; } for (i = 0; i < uframes; i++) { ehci->frindex++; if (ehci->frindex == 0x00002000) { ehci_raise_irq(ehci, USBSTS_FLR); } if (ehci->frindex == 0x00004000) { ehci_raise_irq(ehci, USBSTS_FLR); ehci->frindex = 0; if (ehci->usbsts_frindex >= 0x00004000) { ehci->usbsts_frindex -= 0x00004000; } else { ehci->usbsts_frindex = 0; } } } }
true
qemu
72aa364b1d9daa889bb5898ea4aded9d27fd1c96
8,895
static int tee_write_header(AVFormatContext *avf) { TeeContext *tee = avf->priv_data; unsigned nb_slaves = 0, i; const char *filename = avf->filename; char *slaves[MAX_SLAVES]; int ret; while (*filename) { if (nb_slaves == MAX_SLAVES) { av_log(avf, AV_LOG_ERROR, "Maximum %d slave muxers reached.\n", MAX_SLAVES); ret = AVERROR_PATCHWELCOME; goto fail; } if (!(slaves[nb_slaves++] = av_get_token(&filename, slave_delim))) { ret = AVERROR(ENOMEM); goto fail; } if (strspn(filename, slave_delim)) filename++; } for (i = 0; i < nb_slaves; i++) { if ((ret = open_slave(avf, slaves[i], &tee->slaves[i])) < 0) goto fail; log_slave(&tee->slaves[i], avf, AV_LOG_VERBOSE); av_freep(&slaves[i]); } tee->nb_slaves = nb_slaves; for (i = 0; i < avf->nb_streams; i++) { int j, mapped = 0; for (j = 0; j < tee->nb_slaves; j++) mapped += tee->slaves[j].stream_map[i] >= 0; if (!mapped) av_log(avf, AV_LOG_WARNING, "Input stream #%d is not mapped " "to any slave.\n", i); } return 0; fail: for (i = 0; i < nb_slaves; i++) av_freep(&slaves[i]); close_slaves(avf); return ret; }
true
FFmpeg
f9d7e9feec2a0fd7f7930d01876a70a9b8a4a3b9
8,896
static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type) { CssImage *css; trace_css_chpid_add(cssid, chpid, type); if (cssid > MAX_CSSID) { return -EINVAL; } css = channel_subsys.css[cssid]; if (!css) { return -EINVAL; } if (css->chpids[chpid].in_use) { return -EEXIST; } css->chpids[chpid].in_use = 1; css->chpids[chpid].type = type; css->chpids[chpid].is_virtual = 1; css_generate_chp_crws(cssid, chpid); return 0; }
true
qemu
882b3b97697affb36ca3d174f42f846232008979
8,897
iscsi_readcapacity10_cb(struct iscsi_context *iscsi, int status, void *command_data, void *opaque) { struct IscsiTask *itask = opaque; struct scsi_readcapacity10 *rc10; struct scsi_task *task = command_data; if (status != 0) { error_report("iSCSI: Failed to read capacity of iSCSI lun. %s", iscsi_get_error(iscsi)); itask->status = 1; itask->complete = 1; scsi_free_scsi_task(task); return; } rc10 = scsi_datain_unmarshall(task); if (rc10 == NULL) { error_report("iSCSI: Failed to unmarshall readcapacity10 data."); itask->status = 1; itask->complete = 1; scsi_free_scsi_task(task); return; } itask->iscsilun->block_size = rc10->block_size; if (rc10->lba == 0) { /* blank disk loaded */ itask->iscsilun->num_blocks = 0; } else { itask->iscsilun->num_blocks = rc10->lba + 1; } itask->bs->total_sectors = itask->iscsilun->num_blocks * itask->iscsilun->block_size / BDRV_SECTOR_SIZE ; itask->status = 0; itask->complete = 1; scsi_free_scsi_task(task); }
true
qemu
e829b0bb054ed3389e5b22dad61875e51674e629
8,898
bool qemu_net_queue_flush(NetQueue *queue) { while (!QTAILQ_EMPTY(&queue->packets)) { NetPacket *packet; int ret; packet = QTAILQ_FIRST(&queue->packets); QTAILQ_REMOVE(&queue->packets, packet, entry); ret = qemu_net_queue_deliver(queue, packet->sender, packet->flags, packet->data, packet->size); if (ret == 0) { queue->nq_count++; QTAILQ_INSERT_HEAD(&queue->packets, packet, entry); return false; } if (packet->sent_cb) { packet->sent_cb(packet->sender, ret); } g_free(packet); } return true; }
true
qemu
7d91ddd25e3a4e5008a2ac16127d51a34fd56bf1
8,899
void ffserver_parse_acl_row(FFServerStream *stream, FFServerStream* feed, FFServerIPAddressACL *ext_acl, const char *p, const char *filename, int line_num) { char arg[1024]; FFServerIPAddressACL acl; FFServerIPAddressACL *nacl; FFServerIPAddressACL **naclp; ffserver_get_arg(arg, sizeof(arg), &p); if (av_strcasecmp(arg, "allow") == 0) acl.action = IP_ALLOW; else if (av_strcasecmp(arg, "deny") == 0) acl.action = IP_DENY; else { fprintf(stderr, "%s:%d: ACL action '%s' should be ALLOW or DENY.\n", filename, line_num, arg); ffserver_get_arg(arg, sizeof(arg), &p); if (resolve_host(&acl.first, arg)) { fprintf(stderr, "%s:%d: ACL refers to invalid host or IP address '%s'\n", filename, line_num, arg); acl.last = acl.first; ffserver_get_arg(arg, sizeof(arg), &p); if (arg[0]) { if (resolve_host(&acl.last, arg)) { fprintf(stderr, "%s:%d: ACL refers to invalid host or IP address '%s'\n", filename, line_num, arg); nacl = av_mallocz(sizeof(*nacl)); naclp = 0; acl.next = 0; *nacl = acl; if (stream) naclp = &stream->acl; else if (feed) naclp = &feed->acl; else if (ext_acl) naclp = &ext_acl; else fprintf(stderr, "%s:%d: ACL found not in <Stream> or <Feed>\n", filename, line_num); if (naclp) { while (*naclp) naclp = &(*naclp)->next; *naclp = nacl; } else av_free(nacl); bail: return;
true
FFmpeg
f9315ea984efc1a58499664e27b75c37295381db
8,902
static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix, uint16_t **refcount_table, int64_t *nb_clusters) { BDRVQcowState *s = bs->opaque; int64_t i, size; int ret; for(i = 0; i < s->refcount_table_size; i++) { uint64_t offset, cluster; offset = s->refcount_table[i]; cluster = offset >> s->cluster_bits; /* Refcount blocks are cluster aligned */ if (offset_into_cluster(s, offset)) { fprintf(stderr, "ERROR refcount block %" PRId64 " is not " "cluster aligned; refcount table entry corrupted\n", i); res->corruptions++; continue; } if (cluster >= *nb_clusters) { fprintf(stderr, "%s refcount block %" PRId64 " is outside image\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); if (fix & BDRV_FIX_ERRORS) { int64_t old_nb_clusters = *nb_clusters; uint16_t *new_refcount_table; if (offset > INT64_MAX - s->cluster_size) { ret = -EINVAL; goto resize_fail; } ret = bdrv_truncate(bs->file, offset + s->cluster_size); if (ret < 0) { goto resize_fail; } size = bdrv_getlength(bs->file); if (size < 0) { ret = size; goto resize_fail; } *nb_clusters = size_to_clusters(s, size); assert(*nb_clusters >= old_nb_clusters); new_refcount_table = g_try_realloc(*refcount_table, *nb_clusters * sizeof(**refcount_table)); if (!new_refcount_table) { *nb_clusters = old_nb_clusters; res->check_errors++; return -ENOMEM; } *refcount_table = new_refcount_table; memset(*refcount_table + old_nb_clusters, 0, (*nb_clusters - old_nb_clusters) * sizeof(**refcount_table)); if (cluster >= *nb_clusters) { ret = -EINVAL; goto resize_fail; } res->corruptions_fixed++; ret = inc_refcounts(bs, res, refcount_table, nb_clusters, offset, s->cluster_size); if (ret < 0) { return ret; } /* No need to check whether the refcount is now greater than 1: * This area was just allocated and zeroed, so it can only be * exactly 1 after inc_refcounts() */ continue; resize_fail: res->corruptions++; fprintf(stderr, "ERROR could not resize image: %s\n", strerror(-ret)); } else { res->corruptions++; } continue; } if (offset != 0) { ret = inc_refcounts(bs, res, refcount_table, nb_clusters, offset, s->cluster_size); if (ret < 0) { return ret; } if ((*refcount_table)[cluster] != 1) { fprintf(stderr, "%s refcount block %" PRId64 " refcount=%d\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i, (*refcount_table)[cluster]); if (fix & BDRV_FIX_ERRORS) { int64_t new_offset; new_offset = realloc_refcount_block(bs, i, offset); if (new_offset < 0) { res->corruptions++; continue; } /* update refcounts */ if ((new_offset >> s->cluster_bits) >= *nb_clusters) { /* increase refcount_table size if necessary */ int old_nb_clusters = *nb_clusters; *nb_clusters = (new_offset >> s->cluster_bits) + 1; *refcount_table = g_renew(uint16_t, *refcount_table, *nb_clusters); memset(&(*refcount_table)[old_nb_clusters], 0, (*nb_clusters - old_nb_clusters) * sizeof(**refcount_table)); } (*refcount_table)[cluster]--; ret = inc_refcounts(bs, res, refcount_table, nb_clusters, new_offset, s->cluster_size); if (ret < 0) { return ret; } res->corruptions_fixed++; } else { res->corruptions++; } } } } return 0; }
true
qemu
f307b2558f61e068ce514f2dde2cad74c62036d6
8,904
static void handle_sys(DisasContext *s, uint32_t insn, bool isread, unsigned int op0, unsigned int op1, unsigned int op2, unsigned int crn, unsigned int crm, unsigned int rt) { const ARMCPRegInfo *ri; TCGv_i64 tcg_rt; ri = get_arm_cp_reginfo(s->cp_regs, ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)); if (!ri) { /* Unknown register; this might be a guest error or a QEMU * unimplemented feature. */ qemu_log_mask(LOG_UNIMP, "%s access to unsupported AArch64 " "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n", isread ? "read" : "write", op0, op1, crn, crm, op2); unallocated_encoding(s); return; } /* Check access permissions */ if (!cp_access_ok(s->current_pl, ri, isread)) { unallocated_encoding(s); return; } if (ri->accessfn) { /* Emit code to perform further access permissions checks at * runtime; this may result in an exception. */ TCGv_ptr tmpptr; gen_a64_set_pc_im(s->pc - 4); tmpptr = tcg_const_ptr(ri); gen_helper_access_check_cp_reg(cpu_env, tmpptr); tcg_temp_free_ptr(tmpptr); } /* Handle special cases first */ switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) { case ARM_CP_NOP: return; case ARM_CP_NZCV: tcg_rt = cpu_reg(s, rt); if (isread) { gen_get_nzcv(tcg_rt); } else { gen_set_nzcv(tcg_rt); } return; case ARM_CP_CURRENTEL: /* Reads as current EL value from pstate, which is * guaranteed to be constant by the tb flags. */ tcg_rt = cpu_reg(s, rt); tcg_gen_movi_i64(tcg_rt, s->current_pl << 2); return; default: break; } if (use_icount && (ri->type & ARM_CP_IO)) { gen_io_start(); } tcg_rt = cpu_reg(s, rt); if (isread) { if (ri->type & ARM_CP_CONST) { tcg_gen_movi_i64(tcg_rt, ri->resetvalue); } else if (ri->readfn) { TCGv_ptr tmpptr; tmpptr = tcg_const_ptr(ri); gen_helper_get_cp_reg64(tcg_rt, cpu_env, tmpptr); tcg_temp_free_ptr(tmpptr); } else { tcg_gen_ld_i64(tcg_rt, cpu_env, ri->fieldoffset); } } else { if (ri->type & ARM_CP_CONST) { /* If not forbidden by access permissions, treat as WI */ return; } else if (ri->writefn) { TCGv_ptr tmpptr; tmpptr = tcg_const_ptr(ri); gen_helper_set_cp_reg64(cpu_env, tmpptr, tcg_rt); tcg_temp_free_ptr(tmpptr); } else { tcg_gen_st_i64(tcg_rt, cpu_env, ri->fieldoffset); } } if (use_icount && (ri->type & ARM_CP_IO)) { /* I/O operations must end the TB here (whether read or write) */ gen_io_end(); s->is_jmp = DISAS_UPDATE; } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) { /* We default to ending the TB on a coprocessor register write, * but allow this to be suppressed by the register definition * (usually only necessary to work around guest bugs). */ s->is_jmp = DISAS_UPDATE; } }
true
qemu
8bcbf37caa87ba89bc391bad70039f942a98c7e3
8,905
soread(so) struct socket *so; { int n, nn, lss, total; struct sbuf *sb = &so->so_snd; int len = sb->sb_datalen - sb->sb_cc; struct iovec iov[2]; int mss = so->so_tcpcb->t_maxseg; DEBUG_CALL("soread"); DEBUG_ARG("so = %lx", (long )so); /* * No need to check if there's enough room to read. * soread wouldn't have been called if there weren't */ len = sb->sb_datalen - sb->sb_cc; iov[0].iov_base = sb->sb_wptr; if (sb->sb_wptr < sb->sb_rptr) { iov[0].iov_len = sb->sb_rptr - sb->sb_wptr; /* Should never succeed, but... */ if (iov[0].iov_len > len) iov[0].iov_len = len; if (iov[0].iov_len > mss) iov[0].iov_len -= iov[0].iov_len%mss; n = 1; } else { iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr; /* Should never succeed, but... */ if (iov[0].iov_len > len) iov[0].iov_len = len; len -= iov[0].iov_len; if (len) { iov[1].iov_base = sb->sb_data; iov[1].iov_len = sb->sb_rptr - sb->sb_data; if(iov[1].iov_len > len) iov[1].iov_len = len; total = iov[0].iov_len + iov[1].iov_len; if (total > mss) { lss = total%mss; if (iov[1].iov_len > lss) { iov[1].iov_len -= lss; n = 2; } else { lss -= iov[1].iov_len; iov[0].iov_len -= lss; n = 1; } } else n = 2; } else { if (iov[0].iov_len > mss) iov[0].iov_len -= iov[0].iov_len%mss; n = 1; } } #ifdef HAVE_READV nn = readv(so->s, (struct iovec *)iov, n); DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn)); #else nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0); #endif if (nn <= 0) { if (nn < 0 && (errno == EINTR || errno == EAGAIN)) return 0; else { DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno))); sofcantrcvmore(so); tcp_sockclosed(sototcpcb(so)); return -1; } } #ifndef HAVE_READV /* * If there was no error, try and read the second time round * We read again if n = 2 (ie, there's another part of the buffer) * and we read as much as we could in the first read * We don't test for <= 0 this time, because there legitimately * might not be any more data (since the socket is non-blocking), * a close will be detected on next iteration. * A return of -1 wont (shouldn't) happen, since it didn't happen above */ if (n == 2 && nn == iov[0].iov_len) { int ret; ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0); if (ret > 0) nn += ret; } DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn)); #endif /* Update fields */ sb->sb_cc += nn; sb->sb_wptr += nn; if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen)) sb->sb_wptr -= sb->sb_datalen; return nn; }
true
qemu
66029f6a2f717873f2d170681f0250801a6d0d39
8,907
static void decode_422_bitstream(HYuvContext *s, int count) { int i; count /= 2; if (count >= (get_bits_left(&s->gb)) / (31 * 4)) { for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1); READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2); } } else { for (i = 0; i < count; i++) { READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1); READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2); } } }
true
FFmpeg
42b6805cc1989f759f19e9d253527311741cbd3a
8,908
static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4], const DVprofile *sys) { int size, chan, i, j, d, of, smpls, freq, quant, half_ch; uint16_t lc, rc; const uint8_t* as_pack; uint8_t *pcm, ipcm; as_pack = dv_extract_pack(frame, dv_audio_source); if (!as_pack) /* No audio ? */ return 0; smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */ quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ if (quant > 1) return -1; /* unsupported quantization */ if (freq >= FF_ARRAY_ELEMS(dv_audio_frequency)) size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ half_ch = sys->difseg_size / 2; /* We work with 720p frames split in half, thus even frames have * channels 0,1 and odd 2,3. */ ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0; /* for each DIF channel */ for (chan = 0; chan < sys->n_difchan; chan++) { av_assert0(ipcm<4); pcm = ppcm[ipcm++]; if (!pcm) break; /* for each DIF segment */ for (i = 0; i < sys->difseg_size; i++) { frame += 6 * 80; /* skip DIF segment header */ if (quant == 1 && i == half_ch) { /* next stereo channel (12bit mode only) */ av_assert0(ipcm<4); pcm = ppcm[ipcm++]; if (!pcm) break; /* for each AV sequence */ for (j = 0; j < 9; j++) { for (d = 8; d < 80; d += 2) { if (quant == 0) { /* 16bit quantization */ of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride; if (of*2 >= size) continue; pcm[of*2] = frame[d+1]; // FIXME: maybe we have to admit pcm[of*2+1] = frame[d]; // that DV is a big-endian PCM if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) pcm[of*2+1] = 0; } else { /* 12bit quantization */ lc = ((uint16_t)frame[d] << 4) | ((uint16_t)frame[d+2] >> 4); rc = ((uint16_t)frame[d+1] << 4) | ((uint16_t)frame[d+2] & 0x0f); lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); of = sys->audio_shuffle[i%half_ch][j] + (d - 8) / 3 * sys->audio_stride; if (of*2 >= size) continue; pcm[of*2] = lc & 0xff; // FIXME: maybe we have to admit pcm[of*2+1] = lc >> 8; // that DV is a big-endian PCM of = sys->audio_shuffle[i%half_ch+half_ch][j] + (d - 8) / 3 * sys->audio_stride; pcm[of*2] = rc & 0xff; // FIXME: maybe we have to admit pcm[of*2+1] = rc >> 8; // that DV is a big-endian PCM ++d; frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ return size;
true
FFmpeg
3669915e93b3df63034857534245c3f2575d78ff
8,909
void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number) { int time_incr; int time_div, time_mod; if (s->pict_type == AV_PICTURE_TYPE_I) { if (!(s->avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) { if (s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy mpeg4_encode_visual_object_header(s); if (s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number == 0) // HACK, the reference sw is buggy mpeg4_encode_vol_header(s, 0, 0); } if (!(s->workaround_bugs & FF_BUG_MS)) mpeg4_encode_gop_header(s); } s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B; put_bits(&s->pb, 16, 0); /* vop header */ put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */ put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ time_div = FFUDIV(s->time, s->avctx->time_base.den); time_mod = FFUMOD(s->time, s->avctx->time_base.den); time_incr = time_div - s->last_time_base; av_assert0(time_incr >= 0); while (time_incr--) put_bits(&s->pb, 1, 1); put_bits(&s->pb, 1, 0); put_bits(&s->pb, 1, 1); /* marker */ put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ put_bits(&s->pb, 1, 1); /* marker */ put_bits(&s->pb, 1, 1); /* vop coded */ if (s->pict_type == AV_PICTURE_TYPE_P) { put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ } put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ if (!s->progressive_sequence) { put_bits(&s->pb, 1, s->current_picture_ptr->f->top_field_first); put_bits(&s->pb, 1, s->alternate_scan); } // FIXME sprite stuff put_bits(&s->pb, 5, s->qscale); if (s->pict_type != AV_PICTURE_TYPE_I) put_bits(&s->pb, 3, s->f_code); /* fcode_for */ if (s->pict_type == AV_PICTURE_TYPE_B) put_bits(&s->pb, 3, s->b_code); /* fcode_back */ }
true
FFmpeg
7c97946d6131b31340954a3f603b6bf92590a9a5
8,910
static int hls_slice_data_wpp(HEVCContext *s, const HEVCNAL *nal) { const uint8_t *data = nal->data; int length = nal->size; HEVCLocalContext *lc = s->HEVClc; int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int)); int *arg = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int)); int64_t offset; int startheader, cmpt = 0; int i, j, res = 0; if (!ret || !arg) { av_free(ret); av_free(arg); return AVERROR(ENOMEM); } if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * s->ps.sps->ctb_width >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) { av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n", s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, s->ps.sps->ctb_width, s->ps.sps->ctb_height ); res = AVERROR_INVALIDDATA; goto error; } ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1); if (!s->sList[1]) { for (i = 1; i < s->threads_number; i++) { s->sList[i] = av_malloc(sizeof(HEVCContext)); memcpy(s->sList[i], s, sizeof(HEVCContext)); s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); s->sList[i]->HEVClc = s->HEVClcList[i]; } } offset = (lc->gb.index >> 3); for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { startheader--; cmpt++; } } for (i = 1; i < s->sh.num_entry_point_offsets; i++) { offset += (s->sh.entry_point_offset[i - 1] - cmpt); for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) { if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) { startheader--; cmpt++; } } s->sh.size[i - 1] = s->sh.entry_point_offset[i] - cmpt; s->sh.offset[i - 1] = offset; } if (s->sh.num_entry_point_offsets != 0) { offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; if (length < offset) { av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); res = AVERROR_INVALIDDATA; goto error; } s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset; s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset; } s->data = data; for (i = 1; i < s->threads_number; i++) { s->sList[i]->HEVClc->first_qp_group = 1; s->sList[i]->HEVClc->qp_y = s->sList[0]->HEVClc->qp_y; memcpy(s->sList[i], s, sizeof(HEVCContext)); s->sList[i]->HEVClc = s->HEVClcList[i]; } avpriv_atomic_int_set(&s->wpp_err, 0); ff_reset_entries(s->avctx); for (i = 0; i <= s->sh.num_entry_point_offsets; i++) { arg[i] = i; ret[i] = 0; } if (s->ps.pps->entropy_coding_sync_enabled_flag) s->avctx->execute2(s->avctx, hls_decode_entry_wpp, arg, ret, s->sh.num_entry_point_offsets + 1); for (i = 0; i <= s->sh.num_entry_point_offsets; i++) res += ret[i]; error: av_free(ret); av_free(arg); return res; }
true
FFmpeg
214085852491448631dcecb008b5d172c11b8892
8,911
void qemu_file_reset_rate_limit(QEMUFile *f) { f->bytes_xfer = 0; }
true
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
8,912
static struct mmsghdr *build_l2tpv3_vector(NetL2TPV3State *s, int count) { int i; struct iovec *iov; struct mmsghdr *msgvec, *result; msgvec = g_malloc(sizeof(struct mmsghdr) * count); result = msgvec; for (i = 0; i < count ; i++) { msgvec->msg_hdr.msg_name = NULL; msgvec->msg_hdr.msg_namelen = 0; iov = g_malloc(sizeof(struct iovec) * IOVSIZE); msgvec->msg_hdr.msg_iov = iov; iov->iov_base = g_malloc(s->header_size); iov->iov_len = s->header_size; iov++ ; iov->iov_base = qemu_memalign(BUFFER_ALIGN, BUFFER_SIZE); iov->iov_len = BUFFER_SIZE; msgvec->msg_hdr.msg_iovlen = 2; msgvec->msg_hdr.msg_control = NULL; msgvec->msg_hdr.msg_controllen = 0; msgvec->msg_hdr.msg_flags = 0; msgvec++; } return result; }
true
qemu
58889fe50a7c5b8776cf3096a8fe611fb66c4e5c
8,913
int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { Coroutine *co; BdrvCoGetBlockStatusData data = { .bs = bs, .sector_num = sector_num, .nb_sectors = nb_sectors, .pnum = pnum, .done = false, }; if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_get_block_status_co_entry(&data); } else { co = qemu_coroutine_create(bdrv_get_block_status_co_entry); qemu_coroutine_enter(co, &data); while (!data.done) { qemu_aio_wait(); } } return data.ret; }
false
qemu
2572b37a4751cc967582d7d04f21d9bf97187ae5
8,914
static BlockDriverState *bdrv_new_open(const char *filename, const char *fmt, int flags, bool require_io, bool quiet) { BlockDriverState *bs; BlockDriver *drv; char password[256]; Error *local_err = NULL; int ret; bs = bdrv_new("image"); if (fmt) { drv = bdrv_find_format(fmt); if (!drv) { error_report("Unknown file format '%s'", fmt); goto fail; } } else { drv = NULL; } ret = bdrv_open(&bs, filename, NULL, NULL, flags, drv, &local_err); if (ret < 0) { error_report("Could not open '%s': %s", filename, error_get_pretty(local_err)); error_free(local_err); goto fail; } if (bdrv_is_encrypted(bs) && require_io) { qprintf(quiet, "Disk image '%s' is encrypted.\n", filename); if (read_password(password, sizeof(password)) < 0) { error_report("No password given"); goto fail; } if (bdrv_set_key(bs, password) < 0) { error_report("invalid password"); goto fail; } } return bs; fail: bdrv_unref(bs); return NULL; }
false
qemu
98522f63f40adaebc412481e1d2e9170160d4539
8,916
void monitor_init(CharDriverState *hd, int show_banner) { int i; if (is_first_init) { key_timer = qemu_new_timer(vm_clock, release_keys, NULL); if (!key_timer) return; for (i = 0; i < MAX_MON; i++) { monitor_hd[i] = NULL; } is_first_init = 0; } for (i = 0; i < MAX_MON; i++) { if (monitor_hd[i] == NULL) { monitor_hd[i] = hd; break; } } hide_banner = !show_banner; qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL); readline_start("", 0, monitor_handle_command1, NULL); }
false
qemu
396f929762d10ba2c7b38f7e8a2276dd066be2d7
8,917
void OPPROTO op_jz_T0_label(void) { if (!T0) GOTO_LABEL_PARAM(1); FORCE_RET(); }
false
qemu
6e0d8677cb443e7408c0b7a25a93c6596d7fa380
8,918
struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem, hwaddr base, qemu_irq irq, struct omap_dma_lcd_channel_s *dma, omap_clk clk) { struct omap_lcd_panel_s *s = (struct omap_lcd_panel_s *) g_malloc0(sizeof(struct omap_lcd_panel_s)); s->irq = irq; s->dma = dma; s->sysmem = sysmem; omap_lcdc_reset(s); memory_region_init_io(&s->iomem, &omap_lcdc_ops, s, "omap.lcdc", 0x100); memory_region_add_subregion(sysmem, base, &s->iomem); s->con = graphic_console_init(omap_update_display, omap_invalidate_display, omap_screen_dump, NULL, s); return s; }
false
qemu
2c62f08ddbf3fa80dc7202eb9a2ea60ae44e2cc5
8,919
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){ AVPacketList *pktl, **next_point, *this_pktl; int stream_count=0; int streams[MAX_STREAMS]; if(pkt){ AVStream *st= s->streams[ pkt->stream_index]; // assert(pkt->destruct != av_destruct_packet); //FIXME this_pktl = av_mallocz(sizeof(AVPacketList)); this_pktl->pkt= *pkt; if(pkt->destruct == av_destruct_packet) pkt->destruct= NULL; // not shared -> must keep original from being freed else av_dup_packet(&this_pktl->pkt); //shared -> must dup next_point = &s->packet_buffer; while(*next_point){ AVStream *st2= s->streams[ (*next_point)->pkt.stream_index]; int64_t left= st2->time_base.num * (int64_t)st ->time_base.den; int64_t right= st ->time_base.num * (int64_t)st2->time_base.den; if((*next_point)->pkt.dts * left > pkt->dts * right) //FIXME this can overflow break; next_point= &(*next_point)->next; } this_pktl->next= *next_point; *next_point= this_pktl; } memset(streams, 0, sizeof(streams)); pktl= s->packet_buffer; while(pktl){ //av_log(s, AV_LOG_DEBUG, "show st:%d dts:%"PRId64"\n", pktl->pkt.stream_index, pktl->pkt.dts); if(streams[ pktl->pkt.stream_index ] == 0) stream_count++; streams[ pktl->pkt.stream_index ]++; pktl= pktl->next; } if(s->nb_streams == stream_count || (flush && stream_count)){ pktl= s->packet_buffer; *out= pktl->pkt; s->packet_buffer= pktl->next; av_freep(&pktl); return 1; }else{ av_init_packet(out); return 0; } }
false
FFmpeg
6919e54c00b750cd3d9d756258d3677df52f96a9
8,920
int cpu_mb_handle_mmu_fault (CPUState *env, target_ulong address, int rw, int mmu_idx, int is_softmmu) { unsigned int hit; unsigned int mmu_available; int r = 1; int prot; mmu_available = 0; if (env->pvr.regs[0] & PVR0_USE_MMU) { mmu_available = 1; if ((env->pvr.regs[0] & PVR0_PVR_FULL_MASK) && (env->pvr.regs[11] & PVR11_USE_MMU) != PVR11_USE_MMU) { mmu_available = 0; } } /* Translate if the MMU is available and enabled. */ if (mmu_available && (env->sregs[SR_MSR] & MSR_VM)) { target_ulong vaddr, paddr; struct microblaze_mmu_lookup lu; hit = mmu_translate(&env->mmu, &lu, address, rw, mmu_idx); if (hit) { vaddr = address & TARGET_PAGE_MASK; paddr = lu.paddr + vaddr - lu.vaddr; DMMU(qemu_log("MMU map mmu=%d v=%x p=%x prot=%x\n", mmu_idx, vaddr, paddr, lu.prot)); r = tlb_set_page(env, vaddr, paddr, lu.prot, mmu_idx, is_softmmu); } else { env->sregs[SR_EAR] = address; DMMU(qemu_log("mmu=%d miss v=%x\n", mmu_idx, address)); switch (lu.err) { case ERR_PROT: env->sregs[SR_ESR] = rw == 2 ? 17 : 16; env->sregs[SR_ESR] |= (rw == 1) << 10; break; case ERR_MISS: env->sregs[SR_ESR] = rw == 2 ? 19 : 18; env->sregs[SR_ESR] |= (rw == 1) << 10; break; default: abort(); break; } if (env->exception_index == EXCP_MMU) { cpu_abort(env, "recursive faults\n"); } /* TLB miss. */ env->exception_index = EXCP_MMU; } } else { /* MMU disabled or not available. */ address &= TARGET_PAGE_MASK; prot = PAGE_BITS; r = tlb_set_page(env, address, address, prot, mmu_idx, is_softmmu); } return r; }
false
qemu
d4c430a80f000d722bb70287af4d4c184a8d7006
8,921
static uint64_t grlib_irqmp_read(void *opaque, target_phys_addr_t addr, unsigned size) { IRQMP *irqmp = opaque; IRQMPState *state; assert(irqmp != NULL); state = irqmp->state; assert(state != NULL); addr &= 0xff; /* global registers */ switch (addr) { case LEVEL_OFFSET: return state->level; case PENDING_OFFSET: return state->pending; case FORCE0_OFFSET: /* This register is an "alias" for the force register of CPU 0 */ return state->force[0]; case CLEAR_OFFSET: case MP_STATUS_OFFSET: /* Always read as 0 */ return 0; case BROADCAST_OFFSET: return state->broadcast; default: break; } /* mask registers */ if (addr >= MASK_OFFSET && addr < FORCE_OFFSET) { int cpu = (addr - MASK_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); return state->mask[cpu]; } /* force registers */ if (addr >= FORCE_OFFSET && addr < EXTENDED_OFFSET) { int cpu = (addr - FORCE_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); return state->force[cpu]; } /* extended (not supported) */ if (addr >= EXTENDED_OFFSET && addr < IRQMP_REG_SIZE) { int cpu = (addr - EXTENDED_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); return state->extended[cpu]; } trace_grlib_irqmp_readl_unknown(addr); return 0; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
8,922
Object *object_new_with_propv(const char *typename, Object *parent, const char *id, Error **errp, va_list vargs) { Object *obj; ObjectClass *klass; Error *local_err = NULL; klass = object_class_by_name(typename); if (!klass) { error_setg(errp, "invalid object type: %s", typename); return NULL; } if (object_class_is_abstract(klass)) { error_setg(errp, "object type '%s' is abstract", typename); return NULL; } obj = object_new(typename); if (object_set_propv(obj, &local_err, vargs) < 0) { goto error; } object_property_add_child(parent, id, obj, &local_err); if (local_err) { goto error; } if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) { user_creatable_complete(obj, &local_err); if (local_err) { object_unparent(obj); goto error; } } object_unref(OBJECT(obj)); return obj; error: if (local_err) { error_propagate(errp, local_err); } object_unref(obj); return NULL; }
false
qemu
621ff94d5074d88253a5818c6b9c4db718fbfc65
8,923
void start_auth_sasl(VncState *vs) { const char *mechlist = NULL; sasl_security_properties_t secprops; int err; char *localAddr, *remoteAddr; int mechlistlen; VNC_DEBUG("Initialize SASL auth %d\n", vs->csock); /* Get local & remote client addresses in form IPADDR;PORT */ if (!(localAddr = vnc_socket_local_addr("%s;%s", vs->csock))) goto authabort; if (!(remoteAddr = vnc_socket_remote_addr("%s;%s", vs->csock))) { free(localAddr); goto authabort; } err = sasl_server_new("vnc", NULL, /* FQDN - just delegates to gethostname */ NULL, /* User realm */ localAddr, remoteAddr, NULL, /* Callbacks, not needed */ SASL_SUCCESS_DATA, &vs->sasl.conn); free(localAddr); free(remoteAddr); localAddr = remoteAddr = NULL; if (err != SASL_OK) { VNC_DEBUG("sasl context setup failed %d (%s)", err, sasl_errstring(err, NULL, NULL)); vs->sasl.conn = NULL; goto authabort; } #ifdef CONFIG_VNC_TLS /* Inform SASL that we've got an external SSF layer from TLS/x509 */ if (vs->vd->auth == VNC_AUTH_VENCRYPT && vs->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL) { gnutls_cipher_algorithm_t cipher; sasl_ssf_t ssf; cipher = gnutls_cipher_get(vs->tls.session); if (!(ssf = (sasl_ssf_t)gnutls_cipher_get_key_size(cipher))) { VNC_DEBUG("%s", "cannot TLS get cipher size\n"); sasl_dispose(&vs->sasl.conn); vs->sasl.conn = NULL; goto authabort; } ssf *= 8; /* tls key size is bytes, sasl wants bits */ err = sasl_setprop(vs->sasl.conn, SASL_SSF_EXTERNAL, &ssf); if (err != SASL_OK) { VNC_DEBUG("cannot set SASL external SSF %d (%s)\n", err, sasl_errstring(err, NULL, NULL)); sasl_dispose(&vs->sasl.conn); vs->sasl.conn = NULL; goto authabort; } } else #endif /* CONFIG_VNC_TLS */ vs->sasl.wantSSF = 1; memset (&secprops, 0, sizeof secprops); /* Inform SASL that we've got an external SSF layer from TLS */ if (strncmp(vs->vd->display, "unix:", 5) == 0 #ifdef CONFIG_VNC_TLS /* Disable SSF, if using TLS+x509+SASL only. TLS without x509 is not sufficiently strong */ || (vs->vd->auth == VNC_AUTH_VENCRYPT && vs->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL) #endif /* CONFIG_VNC_TLS */ ) { /* If we've got TLS or UNIX domain sock, we don't care about SSF */ secprops.min_ssf = 0; secprops.max_ssf = 0; secprops.maxbufsize = 8192; secprops.security_flags = 0; } else { /* Plain TCP, better get an SSF layer */ secprops.min_ssf = 56; /* Good enough to require kerberos */ secprops.max_ssf = 100000; /* Arbitrary big number */ secprops.maxbufsize = 8192; /* Forbid any anonymous or trivially crackable auth */ secprops.security_flags = SASL_SEC_NOANONYMOUS | SASL_SEC_NOPLAINTEXT; } err = sasl_setprop(vs->sasl.conn, SASL_SEC_PROPS, &secprops); if (err != SASL_OK) { VNC_DEBUG("cannot set SASL security props %d (%s)\n", err, sasl_errstring(err, NULL, NULL)); sasl_dispose(&vs->sasl.conn); vs->sasl.conn = NULL; goto authabort; } err = sasl_listmech(vs->sasl.conn, NULL, /* Don't need to set user */ "", /* Prefix */ ",", /* Separator */ "", /* Suffix */ &mechlist, NULL, NULL); if (err != SASL_OK) { VNC_DEBUG("cannot list SASL mechanisms %d (%s)\n", err, sasl_errdetail(vs->sasl.conn)); sasl_dispose(&vs->sasl.conn); vs->sasl.conn = NULL; goto authabort; } VNC_DEBUG("Available mechanisms for client: '%s'\n", mechlist); if (!(vs->sasl.mechlist = strdup(mechlist))) { VNC_DEBUG("Out of memory"); sasl_dispose(&vs->sasl.conn); vs->sasl.conn = NULL; goto authabort; } mechlistlen = strlen(mechlist); vnc_write_u32(vs, mechlistlen); vnc_write(vs, mechlist, mechlistlen); vnc_flush(vs); VNC_DEBUG("Wait for client mechname length\n"); vnc_read_when(vs, protocol_client_auth_sasl_mechname_len, 4); return; authabort: vnc_client_error(vs); return; }
false
qemu
7e7e2ebc942da8285931ceabf12823e165dced8b
8,924
static void visitor_output_teardown(TestOutputVisitorData *data, const void *unused) { visit_free(data->ov); data->sov = NULL; data->ov = NULL; g_free(data->str); data->str = NULL; }
false
qemu
3b098d56979d2f7fd707c5be85555d114353a28d
8,925
static void megasas_port_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { megasas_mmio_write(opaque, addr & 0xff, val, size); }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
8,926
static inline void os_host_main_loop_wait(int *timeout) { }
false
qemu
15455536df5ef652759ccf465d5e6f73acb493df
8,928
uint32_t HELPER(ucf64_get_fpscr)(CPUUniCore32State *env) { int i; uint32_t fpscr; fpscr = (env->ucf64.xregs[UC32_UCF64_FPSCR] & UCF64_FPSCR_MASK); i = get_float_exception_flags(&env->ucf64.fp_status); fpscr |= ucf64_exceptbits_from_host(i); return fpscr; }
false
qemu
e8ede0a8bb5298a6979bcf7ed84ef64a64a4e3fe
8,929
static int img_resize(int argc, char **argv) { int c, ret, relative; const char *filename, *fmt, *size; int64_t n, total_size; BlockDriverState *bs = NULL; QemuOpts *param; static QemuOptsList resize_options = { .name = "resize_options", .head = QTAILQ_HEAD_INITIALIZER(resize_options.head), .desc = { { .name = BLOCK_OPT_SIZE, .type = QEMU_OPT_SIZE, .help = "Virtual disk size" }, { /* end of list */ } }, }; /* Remove size from argv manually so that negative numbers are not treated * as options by getopt. */ if (argc < 3) { help(); return 1; } size = argv[--argc]; /* Parse getopt arguments */ fmt = NULL; for(;;) { c = getopt(argc, argv, "f:h"); if (c == -1) { break; } switch(c) { case '?': case 'h': help(); break; case 'f': fmt = optarg; break; } } if (optind >= argc) { help(); } filename = argv[optind++]; /* Choose grow, shrink, or absolute resize mode */ switch (size[0]) { case '+': relative = 1; size++; break; case '-': relative = -1; size++; break; default: relative = 0; break; } /* Parse size */ param = qemu_opts_create(&resize_options, NULL, 0, NULL); if (qemu_opt_set(param, BLOCK_OPT_SIZE, size)) { /* Error message already printed when size parsing fails */ ret = -1; qemu_opts_del(param); goto out; } n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0); qemu_opts_del(param); bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR); if (!bs) { ret = -1; goto out; } if (relative) { total_size = bdrv_getlength(bs) + n * relative; } else { total_size = n; } if (total_size <= 0) { error_report("New image size must be positive"); ret = -1; goto out; } ret = bdrv_truncate(bs, total_size); switch (ret) { case 0: printf("Image resized.\n"); break; case -ENOTSUP: error_report("This image does not support resize"); break; case -EACCES: error_report("Image is read-only"); break; default: error_report("Error resizing image (%d)", -ret); break; } out: if (bs) { bdrv_delete(bs); } if (ret) { return 1; } return 0; }
false
qemu
f0536bb848ad6eb2709a7dc675f261bd160c751b
8,932
void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) { int i, target_code_size, max_target_code_size; int direct_jmp_count, direct_jmp2_count, cross_page; TranslationBlock *tb; struct qht_stats hst; tb_lock(); if (!tcg_enabled()) { cpu_fprintf(f, "TCG not enabled\n"); return; } target_code_size = 0; max_target_code_size = 0; cross_page = 0; direct_jmp_count = 0; direct_jmp2_count = 0; for (i = 0; i < tcg_ctx.tb_ctx.nb_tbs; i++) { tb = tcg_ctx.tb_ctx.tbs[i]; target_code_size += tb->size; if (tb->size > max_target_code_size) { max_target_code_size = tb->size; } if (tb->page_addr[1] != -1) { cross_page++; } if (tb->jmp_reset_offset[0] != TB_JMP_RESET_OFFSET_INVALID) { direct_jmp_count++; if (tb->jmp_reset_offset[1] != TB_JMP_RESET_OFFSET_INVALID) { direct_jmp2_count++; } } } /* XXX: avoid using doubles ? */ cpu_fprintf(f, "Translation buffer state:\n"); cpu_fprintf(f, "gen code size %td/%zd\n", tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer); cpu_fprintf(f, "TB count %d\n", tcg_ctx.tb_ctx.nb_tbs); cpu_fprintf(f, "TB avg target size %d max=%d bytes\n", tcg_ctx.tb_ctx.nb_tbs ? target_code_size / tcg_ctx.tb_ctx.nb_tbs : 0, max_target_code_size); cpu_fprintf(f, "TB avg host size %td bytes (expansion ratio: %0.1f)\n", tcg_ctx.tb_ctx.nb_tbs ? (tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) / tcg_ctx.tb_ctx.nb_tbs : 0, target_code_size ? (double) (tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) / target_code_size : 0); cpu_fprintf(f, "cross page TB count %d (%d%%)\n", cross_page, tcg_ctx.tb_ctx.nb_tbs ? (cross_page * 100) / tcg_ctx.tb_ctx.nb_tbs : 0); cpu_fprintf(f, "direct jump count %d (%d%%) (2 jumps=%d %d%%)\n", direct_jmp_count, tcg_ctx.tb_ctx.nb_tbs ? (direct_jmp_count * 100) / tcg_ctx.tb_ctx.nb_tbs : 0, direct_jmp2_count, tcg_ctx.tb_ctx.nb_tbs ? (direct_jmp2_count * 100) / tcg_ctx.tb_ctx.nb_tbs : 0); qht_statistics_init(&tcg_ctx.tb_ctx.htable, &hst); print_qht_statistics(f, cpu_fprintf, hst); qht_statistics_destroy(&hst); cpu_fprintf(f, "\nStatistics:\n"); cpu_fprintf(f, "TB flush count %u\n", atomic_read(&tcg_ctx.tb_ctx.tb_flush_count)); cpu_fprintf(f, "TB invalidate count %d\n", tcg_ctx.tb_ctx.tb_phys_invalidate_count); cpu_fprintf(f, "TLB flush count %d\n", tlb_flush_count); tcg_dump_info(f, cpu_fprintf); tb_unlock(); }
false
qemu
d40d3da00c10f0169a26985ecb65033bff536f2c
8,933
build_fadt(GArray *table_data, BIOSLinker *linker, AcpiPmInfo *pm, unsigned facs, unsigned dsdt, const char *oem_id, const char *oem_table_id) { AcpiFadtDescriptorRev1 *fadt = acpi_data_push(table_data, sizeof(*fadt)); fadt->firmware_ctrl = cpu_to_le32(facs); /* FACS address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, ACPI_BUILD_TABLE_FILE, &fadt->firmware_ctrl, sizeof fadt->firmware_ctrl); fadt->dsdt = cpu_to_le32(dsdt); /* DSDT address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, ACPI_BUILD_TABLE_FILE, &fadt->dsdt, sizeof fadt->dsdt); fadt_setup(fadt, pm); build_header(linker, table_data, (void *)fadt, "FACP", sizeof(*fadt), 1, oem_id, oem_table_id); }
false
qemu
4678124bb9bfb49e93b83f95c4d2feeb443ea38b
8,934
void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, int is_write, int is_user, uintptr_t retaddr) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; int target_el; bool same_el; if (retaddr) { /* now we have a real cpu fault */ cpu_restore_state(cs, retaddr); } target_el = exception_target_el(env); same_el = (arm_current_el(env) == target_el); env->exception.vaddress = vaddr; /* the DFSR for an alignment fault depends on whether we're using * the LPAE long descriptor format, or the short descriptor format */ if (arm_regime_using_lpae_format(env, cpu_mmu_index(env, false))) { env->exception.fsr = 0x21; } else { env->exception.fsr = 0x1; } if (is_write == 1 && arm_feature(env, ARM_FEATURE_V6)) { env->exception.fsr |= (1 << 11); } raise_exception(env, EXCP_DATA_ABORT, syn_data_abort(same_el, 0, 0, 0, is_write == 1, 0x21), target_el); }
false
qemu
deb2db996cbb9470b39ae1e383791ef34c4eb3c2
8,935
static void flash_sync_page(Flash *s, int page) { int bdrv_sector, nb_sectors; QEMUIOVector iov; if (!s->bdrv || bdrv_is_read_only(s->bdrv)) { return; } bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE; nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE); qemu_iovec_init(&iov, 1); qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors, bdrv_sync_complete, NULL); }
false
qemu
4be746345f13e99e468c60acbd3a355e8183e3ce
8,936
static int proxy_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) { int retval; retval = v9fs_request(fs_ctx->private, T_LSTAT, stbuf, "s", fs_path); if (retval < 0) { errno = -retval; return -1; } return retval; }
false
qemu
494a8ebe713055d3946183f4b395f85a18b43e9e
8,937
void bios_linker_loader_add_checksum(GArray *linker, const char *file, GArray *table, void *start, unsigned size, uint8_t *checksum) { BiosLinkerLoaderEntry entry; ptrdiff_t checksum_offset = (gchar *)checksum - table->data; ptrdiff_t start_offset = (gchar *)start - table->data; assert(checksum_offset >= 0); assert(start_offset >= 0); assert(checksum_offset + 1 <= table->len); assert(start_offset + size <= table->len); assert(*checksum == 0x0); memset(&entry, 0, sizeof entry); strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1); entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM); entry.cksum.offset = cpu_to_le32(checksum_offset); entry.cksum.start = cpu_to_le32(start_offset); entry.cksum.length = cpu_to_le32(size); g_array_append_vals(linker, &entry, sizeof entry); }
false
qemu
0e9b9edae7bebfd31fdbead4ccbbce03876a7edd
8,938
void backup_do_checkpoint(BlockJob *job, Error **errp) { BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common); int64_t len; assert(job->driver->job_type == BLOCK_JOB_TYPE_BACKUP); if (backup_job->sync_mode != MIRROR_SYNC_MODE_NONE) { error_setg(errp, "The backup job only supports block checkpoint in" " sync=none mode"); return; } len = DIV_ROUND_UP(backup_job->common.len, backup_job->cluster_size); bitmap_zero(backup_job->done_bitmap, len); }
false
qemu
a193b0f0a8d7735f4eb2ff863fd0902a5fa5eec6
8,939
int floatx80_is_nan( floatx80 a1 ) { floatx80u u; u.f = a1; return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 ); }
false
qemu
185698715dfb18c82ad2a5dbc169908602d43e81
8,940
static void taihu_cpld_writel (void *opaque, hwaddr addr, uint32_t value) { taihu_cpld_writel(opaque, addr, (value >> 24) & 0xFF); taihu_cpld_writel(opaque, addr + 1, (value >> 16) & 0xFF); taihu_cpld_writel(opaque, addr + 2, (value >> 8) & 0xFF); taihu_cpld_writeb(opaque, addr + 3, value & 0xFF); }
false
qemu
e2a176dfda32f5cf80703c2921a19fe75850c38c
8,941
static int mov_write_stts_tag(AVIOContext *pb, MOVTrack *track) { MOVStts *stts_entries; uint32_t entries = -1; uint32_t atom_size; int i; if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO && !track->audio_vbr) { stts_entries = av_malloc(sizeof(*stts_entries)); /* one entry */ if (!stts_entries) return AVERROR(ENOMEM); stts_entries[0].count = track->sample_count; stts_entries[0].duration = 1; entries = 1; } else { stts_entries = track->entry ? av_malloc_array(track->entry, sizeof(*stts_entries)) : /* worst case */ NULL; if (!stts_entries) return AVERROR(ENOMEM); for (i = 0; i < track->entry; i++) { int duration = get_cluster_duration(track, i); if (i && duration == stts_entries[entries].duration) { stts_entries[entries].count++; /* compress */ } else { entries++; stts_entries[entries].duration = duration; stts_entries[entries].count = 1; } } entries++; /* last one */ } atom_size = 16 + (entries * 8); avio_wb32(pb, atom_size); /* size */ ffio_wfourcc(pb, "stts"); avio_wb32(pb, 0); /* version & flags */ avio_wb32(pb, entries); /* entry count */ for (i = 0; i < entries; i++) { avio_wb32(pb, stts_entries[i].count); avio_wb32(pb, stts_entries[i].duration); } av_free(stts_entries); return atom_size; }
false
FFmpeg
95165f7c1b533c121b890fa1e82e8ed596cfc108
8,942
void qcrypto_cipher_free(QCryptoCipher *cipher) { QCryptoCipherBuiltin *ctxt = cipher->opaque; if (!cipher) { return; } ctxt->free(cipher); g_free(cipher); }
false
qemu
4f4f6976d80614e2d81cea4385885876f24bb257
8,943
static uint64_t omap_wd_timer_read(void *opaque, target_phys_addr_t addr, unsigned size) { struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) opaque; if (size != 2) { return omap_badwidth_read16(opaque, addr); } switch (addr) { case 0x00: /* CNTL_TIMER */ return (s->timer.ptv << 9) | (s->timer.ar << 8) | (s->timer.st << 7) | (s->free << 1); case 0x04: /* READ_TIMER */ return omap_timer_read(&s->timer); case 0x08: /* TIMER_MODE */ return s->mode << 15; } OMAP_BAD_REG(addr); return 0; }
false
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c