project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
FFmpeg | 86dfcfd0e30d6645eea2c63c1c60a0550e7c97ea | 1 | int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
int tag;
if (fc->nb_streams < 1)
return 0;
st = fc->streams[fc->nb_streams-1];
avio_rb32(pb); /* version + flags */
ff_mp4_read_descr(fc, pb, &tag);
if (tag == MP4ESDescrTag) {
ff_mp4_parse_es_descr(pb, NULL);
} else
avio_rb16(pb); /* ID */
ff_mp4_read_descr(fc, pb, &tag);
if (tag == MP4DecConfigDescrTag)
ff_mp4_read_dec_config_descr(fc, st, pb);
return 0;
}
| 14,315 |
qemu | 6ab3fc32ea640026726bc5f9f4db622d0954fb8a | 1 | static void usb_serial_handle_data(USBDevice *dev, USBPacket *p)
{
USBSerialState *s = (USBSerialState *)dev;
uint8_t devep = p->ep->nr;
struct iovec *iov;
uint8_t header[2];
int i, first_len, len;
switch (p->pid) {
case USB_TOKEN_OUT:
if (devep != 2)
goto fail;
for (i = 0; i < p->iov.niov; i++) {
iov = p->iov.iov + i;
qemu_chr_fe_write(s->cs, iov->iov_base, iov->iov_len);
}
p->actual_length = p->iov.size;
break;
case USB_TOKEN_IN:
if (devep != 1)
goto fail;
first_len = RECV_BUF - s->recv_ptr;
len = p->iov.size;
if (len <= 2) {
p->status = USB_RET_NAK;
break;
}
header[0] = usb_get_modem_lines(s) | 1;
/* We do not have the uart details */
/* handle serial break */
if (s->event_trigger && s->event_trigger & FTDI_BI) {
s->event_trigger &= ~FTDI_BI;
header[1] = FTDI_BI;
usb_packet_copy(p, header, 2);
break;
} else {
header[1] = 0;
}
len -= 2;
if (len > s->recv_used)
len = s->recv_used;
if (!len) {
p->status = USB_RET_NAK;
break;
}
if (first_len > len)
first_len = len;
usb_packet_copy(p, header, 2);
usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len);
if (len > first_len)
usb_packet_copy(p, s->recv_buf, len - first_len);
s->recv_used -= len;
s->recv_ptr = (s->recv_ptr + len) % RECV_BUF;
break;
default:
DPRINTF("Bad token\n");
fail:
p->status = USB_RET_STALL;
break;
}
}
| 14,316 |
FFmpeg | 4d33873c2990b8d6096f60fef384f0efc4482b55 | 1 | int ff_hevc_decode_nal_pps(HEVCContext *s)
{
GetBitContext *gb = &s->HEVClc.gb;
HEVCSPS *sps = NULL;
int pic_area_in_ctbs, pic_area_in_min_cbs, pic_area_in_min_tbs;
int log2_diff_ctb_min_tb_size;
int i, j, x, y, ctb_addr_rs, tile_id;
int ret = 0;
int pps_id = 0;
AVBufferRef *pps_buf;
HEVCPPS *pps = av_mallocz(sizeof(*pps));
if (!pps)
return AVERROR(ENOMEM);
pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps),
hevc_pps_free, NULL, 0);
if (!pps_buf) {
av_freep(&pps);
return AVERROR(ENOMEM);
}
av_log(s->avctx, AV_LOG_DEBUG, "Decoding PPS\n");
// Default values
pps->loop_filter_across_tiles_enabled_flag = 1;
pps->num_tile_columns = 1;
pps->num_tile_rows = 1;
pps->uniform_spacing_flag = 1;
pps->disable_dbf = 0;
pps->beta_offset = 0;
pps->tc_offset = 0;
// Coded parameters
pps_id = get_ue_golomb_long(gb);
if (pps_id >= MAX_PPS_COUNT) {
av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
ret = AVERROR_INVALIDDATA;
goto err;
}
pps->sps_id = get_ue_golomb_long(gb);
if (pps->sps_id >= MAX_SPS_COUNT) {
av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id);
ret = AVERROR_INVALIDDATA;
goto err;
}
if (!s->sps_list[pps->sps_id]) {
av_log(s->avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id);
ret = AVERROR_INVALIDDATA;
goto err;
}
sps = (HEVCSPS *)s->sps_list[pps->sps_id]->data;
pps->dependent_slice_segments_enabled_flag = get_bits1(gb);
pps->output_flag_present_flag = get_bits1(gb);
pps->num_extra_slice_header_bits = get_bits(gb, 3);
pps->sign_data_hiding_flag = get_bits1(gb);
pps->cabac_init_present_flag = get_bits1(gb);
pps->num_ref_idx_l0_default_active = get_ue_golomb_long(gb) + 1;
pps->num_ref_idx_l1_default_active = get_ue_golomb_long(gb) + 1;
pps->pic_init_qp_minus26 = get_se_golomb(gb);
pps->constrained_intra_pred_flag = get_bits1(gb);
pps->transform_skip_enabled_flag = get_bits1(gb);
pps->cu_qp_delta_enabled_flag = get_bits1(gb);
pps->diff_cu_qp_delta_depth = 0;
if (pps->cu_qp_delta_enabled_flag)
pps->diff_cu_qp_delta_depth = get_ue_golomb_long(gb);
pps->cb_qp_offset = get_se_golomb(gb);
if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) {
av_log(s->avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n",
pps->cb_qp_offset);
ret = AVERROR_INVALIDDATA;
goto err;
}
pps->cr_qp_offset = get_se_golomb(gb);
if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) {
av_log(s->avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n",
pps->cr_qp_offset);
ret = AVERROR_INVALIDDATA;
goto err;
}
pps->pic_slice_level_chroma_qp_offsets_present_flag = get_bits1(gb);
pps->weighted_pred_flag = get_bits1(gb);
pps->weighted_bipred_flag = get_bits1(gb);
pps->transquant_bypass_enable_flag = get_bits1(gb);
pps->tiles_enabled_flag = get_bits1(gb);
pps->entropy_coding_sync_enabled_flag = get_bits1(gb);
if (pps->tiles_enabled_flag) {
pps->num_tile_columns = get_ue_golomb_long(gb) + 1;
pps->num_tile_rows = get_ue_golomb_long(gb) + 1;
if (pps->num_tile_columns == 0 ||
pps->num_tile_columns >= sps->width) {
av_log(s->avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n",
pps->num_tile_columns - 1);
ret = AVERROR_INVALIDDATA;
goto err;
}
if (pps->num_tile_rows == 0 ||
pps->num_tile_rows >= sps->height) {
av_log(s->avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n",
pps->num_tile_rows - 1);
ret = AVERROR_INVALIDDATA;
goto err;
}
pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
if (!pps->column_width || !pps->row_height) {
ret = AVERROR(ENOMEM);
goto err;
}
pps->uniform_spacing_flag = get_bits1(gb);
if (!pps->uniform_spacing_flag) {
uint64_t sum = 0;
for (i = 0; i < pps->num_tile_columns - 1; i++) {
pps->column_width[i] = get_ue_golomb_long(gb) + 1;
sum += pps->column_width[i];
}
if (sum >= sps->ctb_width) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid tile widths.\n");
ret = AVERROR_INVALIDDATA;
goto err;
}
pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum;
sum = 0;
for (i = 0; i < pps->num_tile_rows - 1; i++) {
pps->row_height[i] = get_ue_golomb_long(gb) + 1;
sum += pps->row_height[i];
}
if (sum >= sps->ctb_height) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid tile heights.\n");
ret = AVERROR_INVALIDDATA;
goto err;
}
pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum;
}
pps->loop_filter_across_tiles_enabled_flag = get_bits1(gb);
}
pps->seq_loop_filter_across_slices_enabled_flag = get_bits1(gb);
pps->deblocking_filter_control_present_flag = get_bits1(gb);
if (pps->deblocking_filter_control_present_flag) {
pps->deblocking_filter_override_enabled_flag = get_bits1(gb);
pps->disable_dbf = get_bits1(gb);
if (!pps->disable_dbf) {
pps->beta_offset = get_se_golomb(gb) * 2;
pps->tc_offset = get_se_golomb(gb) * 2;
if (pps->beta_offset/2 < -6 || pps->beta_offset/2 > 6) {
av_log(s->avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n",
pps->beta_offset/2);
ret = AVERROR_INVALIDDATA;
goto err;
}
if (pps->tc_offset/2 < -6 || pps->tc_offset/2 > 6) {
av_log(s->avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n",
pps->tc_offset/2);
ret = AVERROR_INVALIDDATA;
goto err;
}
}
}
pps->scaling_list_data_present_flag = get_bits1(gb);
if (pps->scaling_list_data_present_flag) {
set_default_scaling_list_data(&pps->scaling_list);
ret = scaling_list_data(s, &pps->scaling_list);
if (ret < 0)
goto err;
}
pps->lists_modification_present_flag = get_bits1(gb);
pps->log2_parallel_merge_level = get_ue_golomb_long(gb) + 2;
if (pps->log2_parallel_merge_level > sps->log2_ctb_size) {
av_log(s->avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n",
pps->log2_parallel_merge_level - 2);
ret = AVERROR_INVALIDDATA;
goto err;
}
pps->slice_header_extension_present_flag = get_bits1(gb);
skip_bits1(gb); // pps_extension_flag
// Inferred parameters
pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd));
pps->row_bd = av_malloc_array(pps->num_tile_rows + 1, sizeof(*pps->row_bd));
pps->col_idxX = av_malloc_array(sps->ctb_width, sizeof(*pps->col_idxX));
if (!pps->col_bd || !pps->row_bd || !pps->col_idxX) {
ret = AVERROR(ENOMEM);
goto err;
}
if (pps->uniform_spacing_flag) {
if (!pps->column_width) {
pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
}
if (!pps->column_width || !pps->row_height) {
ret = AVERROR(ENOMEM);
goto err;
}
for (i = 0; i < pps->num_tile_columns; i++) {
pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns -
(i * sps->ctb_width) / pps->num_tile_columns;
}
for (i = 0; i < pps->num_tile_rows; i++) {
pps->row_height[i] = ((i + 1) * sps->ctb_height) / pps->num_tile_rows -
(i * sps->ctb_height) / pps->num_tile_rows;
}
}
pps->col_bd[0] = 0;
for (i = 0; i < pps->num_tile_columns; i++)
pps->col_bd[i + 1] = pps->col_bd[i] + pps->column_width[i];
pps->row_bd[0] = 0;
for (i = 0; i < pps->num_tile_rows; i++)
pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i];
for (i = 0, j = 0; i < sps->ctb_width; i++) {
if (i > pps->col_bd[j])
j++;
pps->col_idxX[i] = j;
}
/**
* 6.5
*/
pic_area_in_ctbs = sps->ctb_width * sps->ctb_height;
pic_area_in_min_cbs = sps->min_cb_width * sps->min_cb_height;
pic_area_in_min_tbs = sps->min_tb_width * sps->min_tb_height;
pps->ctb_addr_rs_to_ts = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_rs_to_ts));
pps->ctb_addr_ts_to_rs = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_ts_to_rs));
pps->tile_id = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->tile_id));
pps->min_cb_addr_zs = av_malloc_array(pic_area_in_min_cbs, sizeof(*pps->min_cb_addr_zs));
pps->min_tb_addr_zs = av_malloc_array(pic_area_in_min_tbs, sizeof(*pps->min_tb_addr_zs));
if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs ||
!pps->tile_id || !pps->min_cb_addr_zs || !pps->min_tb_addr_zs) {
ret = AVERROR(ENOMEM);
goto err;
}
for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) {
int tb_x = ctb_addr_rs % sps->ctb_width;
int tb_y = ctb_addr_rs / sps->ctb_width;
int tile_x = 0;
int tile_y = 0;
int val = 0;
for (i = 0; i < pps->num_tile_columns; i++) {
if (tb_x < pps->col_bd[i + 1]) {
tile_x = i;
break;
}
}
for (i = 0; i < pps->num_tile_rows; i++) {
if (tb_y < pps->row_bd[i + 1]) {
tile_y = i;
break;
}
}
for (i = 0; i < tile_x; i++)
val += pps->row_height[tile_y] * pps->column_width[i];
for (i = 0; i < tile_y; i++)
val += sps->ctb_width * pps->row_height[i];
val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] +
tb_x - pps->col_bd[tile_x];
pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val;
pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs;
}
for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++)
for (i = 0; i < pps->num_tile_columns; i++, tile_id++)
for (y = pps->row_bd[j]; y < pps->row_bd[j + 1]; y++)
for (x = pps->col_bd[i]; x < pps->col_bd[i + 1]; x++)
pps->tile_id[pps->ctb_addr_rs_to_ts[y * sps->ctb_width + x]] = tile_id;
pps->tile_pos_rs = av_malloc_array(tile_id, sizeof(*pps->tile_pos_rs));
if (!pps->tile_pos_rs) {
ret = AVERROR(ENOMEM);
goto err;
}
for (j = 0; j < pps->num_tile_rows; j++)
for (i = 0; i < pps->num_tile_columns; i++)
pps->tile_pos_rs[j * pps->num_tile_columns + i] = pps->row_bd[j] * sps->ctb_width + pps->col_bd[i];
for (y = 0; y < sps->min_cb_height; y++) {
for (x = 0; x < sps->min_cb_width; x++) {
int tb_x = x >> sps->log2_diff_max_min_coding_block_size;
int tb_y = y >> sps->log2_diff_max_min_coding_block_size;
int ctb_addr_rs = sps->ctb_width * tb_y + tb_x;
int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] <<
(sps->log2_diff_max_min_coding_block_size * 2);
for (i = 0; i < sps->log2_diff_max_min_coding_block_size; i++) {
int m = 1 << i;
val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
}
pps->min_cb_addr_zs[y * sps->min_cb_width + x] = val;
}
}
log2_diff_ctb_min_tb_size = sps->log2_ctb_size - sps->log2_min_tb_size;
for (y = 0; y < sps->min_tb_height; y++) {
for (x = 0; x < sps->min_tb_width; x++) {
int tb_x = x >> log2_diff_ctb_min_tb_size;
int tb_y = y >> log2_diff_ctb_min_tb_size;
int ctb_addr_rs = sps->ctb_width * tb_y + tb_x;
int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] <<
(log2_diff_ctb_min_tb_size * 2);
for (i = 0; i < log2_diff_ctb_min_tb_size; i++) {
int m = 1 << i;
val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
}
pps->min_tb_addr_zs[y * sps->min_tb_width + x] = val;
}
}
av_buffer_unref(&s->pps_list[pps_id]);
s->pps_list[pps_id] = pps_buf;
return 0;
err:
av_buffer_unref(&pps_buf);
return ret;
}
| 14,317 |
qemu | 80a15e3e2eed96926d886693663503985c9a98bb | 1 | static int raw_read_options(QDict *options, BlockDriverState *bs,
BDRVRawState *s, Error **errp)
{
Error *local_err = NULL;
QemuOpts *opts = NULL;
int64_t real_size = 0;
int ret;
real_size = bdrv_getlength(bs->file->bs);
if (real_size < 0) {
error_setg_errno(errp, -real_size, "Could not get image size");
return real_size;
}
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto end;
}
s->offset = qemu_opt_get_size(opts, "offset", 0);
if (s->offset > real_size) {
error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than "
"size of the containing file (%" PRId64 ")",
s->offset, real_size);
ret = -EINVAL;
goto end;
}
if (qemu_opt_find(opts, "size") != NULL) {
s->size = qemu_opt_get_size(opts, "size", 0);
s->has_size = true;
} else {
s->has_size = false;
s->size = real_size - s->offset;
}
/* Check size and offset */
if ((real_size - s->offset) < s->size) {
error_setg(errp, "The sum of offset (%" PRIu64 ") and size "
"(%" PRIu64 ") has to be smaller or equal to the "
" actual size of the containing file (%" PRId64 ")",
s->offset, s->size, real_size);
ret = -EINVAL;
goto end;
}
/* Make sure size is multiple of BDRV_SECTOR_SIZE to prevent rounding
* up and leaking out of the specified area. */
if (!QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) {
error_setg(errp, "Specified size is not multiple of %llu",
BDRV_SECTOR_SIZE);
ret = -EINVAL;
goto end;
}
ret = 0;
end:
qemu_opts_del(opts);
return ret;
}
| 14,318 |
FFmpeg | 8b2fce0d3f5a56c40c28899c9237210ca8f9cf75 | 1 | inline static void RENAME(hcscale)(uint16_t *dst, long dstWidth, uint8_t *src1, uint8_t *src2,
int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter,
int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode,
int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter,
int32_t *mmx2FilterPos, uint8_t *pal)
{
if (srcFormat==PIX_FMT_YUYV422)
{
RENAME(yuy2ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_UYVY422)
{
RENAME(uyvyToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_RGB32)
{
RENAME(bgr32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_BGR24)
{
RENAME(bgr24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_BGR565)
{
RENAME(bgr16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_BGR555)
{
RENAME(bgr15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_BGR32)
{
RENAME(rgb32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_RGB24)
{
RENAME(rgb24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_RGB565)
{
RENAME(rgb16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (srcFormat==PIX_FMT_RGB555)
{
RENAME(rgb15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
else if (isGray(srcFormat))
{
return;
}
else if (srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE)
{
RENAME(palToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW, pal);
src1= formatConvBuffer;
src2= formatConvBuffer+2048;
}
#ifdef HAVE_MMX
// use the new MMX scaler if the mmx2 can't be used (it is faster than the x86 ASM one)
if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed))
#else
if (!(flags&SWS_FAST_BILINEAR))
#endif
{
RENAME(hScale)(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
RENAME(hScale)(dst+2048, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
}
else // Fast Bilinear upscale / crap downscale
{
#if defined(ARCH_X86)
#ifdef HAVE_MMX2
int i;
#if defined(PIC)
uint64_t ebxsave __attribute__((aligned(8)));
#endif
if (canMMX2BeUsed)
{
asm volatile(
#if defined(PIC)
"mov %%"REG_b", %6 \n\t"
#endif
"pxor %%mm7, %%mm7 \n\t"
"mov %0, %%"REG_c" \n\t"
"mov %1, %%"REG_D" \n\t"
"mov %2, %%"REG_d" \n\t"
"mov %3, %%"REG_b" \n\t"
"xor %%"REG_a", %%"REG_a" \n\t" // i
PREFETCH" (%%"REG_c") \n\t"
PREFETCH" 32(%%"REG_c") \n\t"
PREFETCH" 64(%%"REG_c") \n\t"
#ifdef ARCH_X86_64
#define FUNNY_UV_CODE \
"movl (%%"REG_b"), %%esi \n\t"\
"call *%4 \n\t"\
"movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\
"add %%"REG_S", %%"REG_c" \n\t"\
"add %%"REG_a", %%"REG_D" \n\t"\
"xor %%"REG_a", %%"REG_a" \n\t"\
#else
#define FUNNY_UV_CODE \
"movl (%%"REG_b"), %%esi \n\t"\
"call *%4 \n\t"\
"addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\
"add %%"REG_a", %%"REG_D" \n\t"\
"xor %%"REG_a", %%"REG_a" \n\t"\
#endif /* ARCH_X86_64 */
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
"xor %%"REG_a", %%"REG_a" \n\t" // i
"mov %5, %%"REG_c" \n\t" // src
"mov %1, %%"REG_D" \n\t" // buf1
"add $4096, %%"REG_D" \n\t"
PREFETCH" (%%"REG_c") \n\t"
PREFETCH" 32(%%"REG_c") \n\t"
PREFETCH" 64(%%"REG_c") \n\t"
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
FUNNY_UV_CODE
#if defined(PIC)
"mov %6, %%"REG_b" \n\t"
#endif
:: "m" (src1), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos),
"m" (funnyUVCode), "m" (src2)
#if defined(PIC)
,"m" (ebxsave)
#endif
: "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
#if !defined(PIC)
,"%"REG_b
#endif
);
for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
{
//printf("%d %d %d\n", dstWidth, i, srcW);
dst[i] = src1[srcW-1]*128;
dst[i+2048] = src2[srcW-1]*128;
}
}
else
{
#endif /* HAVE_MMX2 */
long xInc_shr16 = (long) (xInc >> 16);
uint16_t xInc_mask = xInc & 0xffff;
asm volatile(
"xor %%"REG_a", %%"REG_a" \n\t" // i
"xor %%"REG_d", %%"REG_d" \n\t" // xx
"xorl %%ecx, %%ecx \n\t" // 2*xalpha
ASMALIGN(4)
"1: \n\t"
"mov %0, %%"REG_S" \n\t"
"movzbl (%%"REG_S", %%"REG_d"), %%edi \n\t" //src[xx]
"movzbl 1(%%"REG_S", %%"REG_d"), %%esi \n\t" //src[xx+1]
"subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
"imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
"shll $16, %%edi \n\t"
"addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
"mov %1, %%"REG_D" \n\t"
"shrl $9, %%esi \n\t"
"movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t"
"movzbl (%5, %%"REG_d"), %%edi \n\t" //src[xx]
"movzbl 1(%5, %%"REG_d"), %%esi \n\t" //src[xx+1]
"subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
"imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
"shll $16, %%edi \n\t"
"addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
"mov %1, %%"REG_D" \n\t"
"shrl $9, %%esi \n\t"
"movw %%si, 4096(%%"REG_D", %%"REG_a", 2) \n\t"
"addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
"adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry
"add $1, %%"REG_a" \n\t"
"cmp %2, %%"REG_a" \n\t"
" jb 1b \n\t"
/* GCC-3.3 makes MPlayer crash on IA-32 machines when using "g" operand here,
which is needed to support GCC-4.0 */
#if defined(ARCH_X86_64) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
:: "m" (src1), "m" (dst), "g" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
#else
:: "m" (src1), "m" (dst), "m" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask),
#endif
"r" (src2)
: "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi"
);
#ifdef HAVE_MMX2
} //if MMX2 can't be used
#endif
#else
int i;
unsigned int xpos=0;
for (i=0;i<dstWidth;i++)
{
register unsigned int xx=xpos>>16;
register unsigned int xalpha=(xpos&0xFFFF)>>9;
dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
/* slower
dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha;
dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha;
*/
xpos+=xInc;
}
#endif /* defined(ARCH_X86) */
}
}
| 14,319 |
qemu | bf43330aa418908f7a5e2acda28ac1a8ed0d8ad6 | 1 | uint64_t cpu_tick_get_count(CPUTimer *timer)
{
uint64_t real_count = timer_to_cpu_ticks(
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - timer->clock_offset,
timer->frequency);
TIMER_DPRINTF("%s get_count count=0x%016lx (%s) p=%p\n",
timer->name, real_count,
timer->disabled?"disabled":"enabled", timer);
if (timer->disabled)
real_count |= timer->disabled_mask;
return real_count;
}
| 14,320 |
FFmpeg | 5c720657c23afd798ae0db7c7362eb859a89ab3d | 1 | static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
char color_parameter_type[5] = { 0 };
int color_primaries, color_trc, color_matrix;
if (c->fc->nb_streams < 1)
return 0;
st = c->fc->streams[c->fc->nb_streams - 1];
avio_read(pb, color_parameter_type, 4);
if (strncmp(color_parameter_type, "nclx", 4) &&
strncmp(color_parameter_type, "nclc", 4)) {
av_log(c->fc, AV_LOG_WARNING, "unsupported color_parameter_type %s\n",
color_parameter_type);
return 0;
}
color_primaries = avio_rb16(pb);
color_trc = avio_rb16(pb);
color_matrix = avio_rb16(pb);
av_log(c->fc, AV_LOG_TRACE,
"%s: pri %"PRIu16" trc %"PRIu16" matrix %"PRIu16"",
color_parameter_type, color_primaries, color_trc, color_matrix);
if (!strncmp(color_parameter_type, "nclx", 4)) {
uint8_t color_range = avio_r8(pb) >> 7;
av_log(c->fc, AV_LOG_TRACE, " full %"PRIu8"", color_range);
if (color_range)
st->codec->color_range = AVCOL_RANGE_JPEG;
else
st->codec->color_range = AVCOL_RANGE_MPEG;
/* 14496-12 references JPEG XR specs (rather than the more complete
* 23001-8) so some adjusting is required */
if (color_primaries >= AVCOL_PRI_FILM)
color_primaries = AVCOL_PRI_UNSPECIFIED;
if ((color_trc >= AVCOL_TRC_LINEAR &&
color_trc <= AVCOL_TRC_LOG_SQRT) ||
color_trc >= AVCOL_TRC_BT2020_10)
color_trc = AVCOL_TRC_UNSPECIFIED;
if (color_matrix >= AVCOL_SPC_BT2020_NCL)
color_matrix = AVCOL_SPC_UNSPECIFIED;
st->codec->color_primaries = color_primaries;
st->codec->color_trc = color_trc;
st->codec->colorspace = color_matrix;
} else if (!strncmp(color_parameter_type, "nclc", 4)) {
/* color primaries, Table 4-4 */
switch (color_primaries) {
case 1: st->codec->color_primaries = AVCOL_PRI_BT709; break;
case 5: st->codec->color_primaries = AVCOL_PRI_SMPTE170M; break;
case 6: st->codec->color_primaries = AVCOL_PRI_SMPTE240M; break;
}
/* color transfer, Table 4-5 */
switch (color_trc) {
case 1: st->codec->color_trc = AVCOL_TRC_BT709; break;
case 7: st->codec->color_trc = AVCOL_TRC_SMPTE240M; break;
}
/* color matrix, Table 4-6 */
switch (color_matrix) {
case 1: st->codec->colorspace = AVCOL_SPC_BT709; break;
case 6: st->codec->colorspace = AVCOL_SPC_BT470BG; break;
case 7: st->codec->colorspace = AVCOL_SPC_SMPTE240M; break;
}
}
av_log(c->fc, AV_LOG_TRACE, "\n");
return 0;
}
| 14,321 |
qemu | 0c53d7342b4e8412f3b81eed67f053304813dc5d | 1 | void gen_intermediate_code(CPUOpenRISCState *env, struct TranslationBlock *tb)
{
OpenRISCCPU *cpu = openrisc_env_get_cpu(env);
CPUState *cs = CPU(cpu);
struct DisasContext ctx, *dc = &ctx;
uint32_t pc_start;
uint32_t next_page_start;
int num_insns;
int max_insns;
pc_start = tb->pc;
dc->tb = tb;
dc->is_jmp = DISAS_NEXT;
dc->ppc = pc_start;
dc->pc = pc_start;
dc->flags = cpu->env.cpucfgr;
dc->mem_idx = cpu_mmu_index(&cpu->env, false);
dc->synced_flags = dc->tb_flags = tb->flags;
dc->delayed_branch = !!(dc->tb_flags & D_FLAG);
dc->singlestep_enabled = cs->singlestep_enabled;
next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
num_insns = 0;
max_insns = tb->cflags & CF_COUNT_MASK;
if (max_insns == 0) {
max_insns = CF_COUNT_MASK;
}
if (max_insns > TCG_MAX_INSNS) {
max_insns = TCG_MAX_INSNS;
}
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
&& qemu_log_in_addr_range(pc_start)) {
qemu_log_lock();
qemu_log("----------------\n");
qemu_log("IN: %s\n", lookup_symbol(pc_start));
}
gen_tb_start(tb);
do {
tcg_gen_insn_start(dc->pc);
num_insns++;
if (unlikely(cpu_breakpoint_test(cs, dc->pc, BP_ANY))) {
tcg_gen_movi_tl(cpu_pc, dc->pc);
gen_exception(dc, EXCP_DEBUG);
dc->is_jmp = DISAS_UPDATE;
/* The address covered by the breakpoint must be included in
[tb->pc, tb->pc + tb->size) in order to for it to be
properly cleared -- thus we increment the PC here so that
the logic setting tb->size below does the right thing. */
dc->pc += 4;
break;
}
if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {
gen_io_start();
}
dc->ppc = dc->pc - 4;
dc->npc = dc->pc + 4;
tcg_gen_movi_tl(cpu_ppc, dc->ppc);
tcg_gen_movi_tl(cpu_npc, dc->npc);
disas_openrisc_insn(dc, cpu);
dc->pc = dc->npc;
/* delay slot */
if (dc->delayed_branch) {
dc->delayed_branch--;
if (!dc->delayed_branch) {
dc->tb_flags &= ~D_FLAG;
gen_sync_flags(dc);
tcg_gen_mov_tl(cpu_pc, jmp_pc);
tcg_gen_mov_tl(cpu_npc, jmp_pc);
tcg_gen_movi_tl(jmp_pc, 0);
tcg_gen_exit_tb(0);
dc->is_jmp = DISAS_JUMP;
break;
}
}
} while (!dc->is_jmp
&& !tcg_op_buf_full()
&& !cs->singlestep_enabled
&& !singlestep
&& (dc->pc < next_page_start)
&& num_insns < max_insns);
if (tb->cflags & CF_LAST_IO) {
gen_io_end();
}
if (dc->is_jmp == DISAS_NEXT) {
dc->is_jmp = DISAS_UPDATE;
tcg_gen_movi_tl(cpu_pc, dc->pc);
}
if (unlikely(cs->singlestep_enabled)) {
if (dc->is_jmp == DISAS_NEXT) {
tcg_gen_movi_tl(cpu_pc, dc->pc);
}
gen_exception(dc, EXCP_DEBUG);
} else {
switch (dc->is_jmp) {
case DISAS_NEXT:
gen_goto_tb(dc, 0, dc->pc);
break;
default:
case DISAS_JUMP:
break;
case DISAS_UPDATE:
/* indicate that the hash table must be used
to find the next TB */
tcg_gen_exit_tb(0);
break;
case DISAS_TB_JUMP:
/* nothing more to generate */
break;
}
}
gen_tb_end(tb, num_insns);
tb->size = dc->pc - pc_start;
tb->icount = num_insns;
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
&& qemu_log_in_addr_range(pc_start)) {
log_target_disas(cs, pc_start, tb->size, 0);
qemu_log("\n");
qemu_log_unlock();
}
}
| 14,322 |
FFmpeg | b6eaa3928e198554a3934dd5ad6eac4d16f27df2 | 1 | static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
{
int status;
AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
VTContext *vtctx = avctx->internal->hwaccel_priv_data;
av_buffer_unref(&frame->buf[0]);
if (!videotoolbox->session || !vtctx->bitstream)
return AVERROR_INVALIDDATA;
status = videotoolbox_session_decode_frame(avctx);
if (status) {
av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
return AVERROR_UNKNOWN;
}
if (!vtctx->frame)
return AVERROR_UNKNOWN;
return ff_videotoolbox_buffer_create(vtctx, frame);
}
| 14,323 |
qemu | e8a40bf71d606f9f87866fb2461eaed52814b38e | 1 | static void block_job_completed_single(BlockJob *job)
{
if (!job->ret) {
if (job->driver->commit) {
job->driver->commit(job);
} else {
if (job->driver->abort) {
job->driver->abort(job);
if (job->cb) {
job->cb(job->opaque, job->ret);
if (block_job_is_cancelled(job)) {
block_job_event_cancelled(job);
} else {
const char *msg = NULL;
if (job->ret < 0) {
msg = strerror(-job->ret);
block_job_event_completed(job, msg);
if (job->txn) {
QLIST_REMOVE(job, txn_list);
block_job_txn_unref(job->txn);
block_job_unref(job);
| 14,325 |
qemu | 66a08cbe6ad1aebec8eecf58b3ba042e19dd1649 | 1 | static UHCIQueue *uhci_queue_get(UHCIState *s, UHCI_TD *td, USBEndpoint *ep)
{
uint32_t token = uhci_queue_token(td);
UHCIQueue *queue;
QTAILQ_FOREACH(queue, &s->queues, next) {
if (queue->token == token) {
return queue;
}
}
queue = g_new0(UHCIQueue, 1);
queue->uhci = s;
queue->token = token;
queue->ep = ep;
QTAILQ_INIT(&queue->asyncs);
QTAILQ_INSERT_HEAD(&s->queues, queue, next);
trace_usb_uhci_queue_add(queue->token);
return queue;
}
| 14,326 |
qemu | e1cf5582644ef63528993fb2b88dd3b43b9914c6 | 1 | HBitmap *hbitmap_alloc(uint64_t size, int granularity)
{
HBitmap *hb = g_malloc0(sizeof (struct HBitmap));
unsigned i;
assert(granularity >= 0 && granularity < 64);
size = (size + (1ULL << granularity) - 1) >> granularity;
assert(size <= ((uint64_t)1 << HBITMAP_LOG_MAX_SIZE));
hb->size = size;
hb->granularity = granularity;
for (i = HBITMAP_LEVELS; i-- > 0; ) {
size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
hb->levels[i] = g_malloc0(size * sizeof(unsigned long));
}
/* We necessarily have free bits in level 0 due to the definition
* of HBITMAP_LEVELS, so use one for a sentinel. This speeds up
* hbitmap_iter_skip_words.
*/
assert(size == 1);
hb->levels[0][0] |= 1UL << (BITS_PER_LONG - 1);
return hb;
}
| 14,327 |
FFmpeg | 1c9215e580b6436d1aff3c0118ef01269712ebd9 | 0 | static int mp3_read_header(AVFormatContext *s)
{
MP3DecContext *mp3 = s->priv_data;
AVStream *st;
int64_t off;
int ret;
int i;
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = AV_CODEC_ID_MP3;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->start_time = 0;
// lcm of all mp3 sample rates
avpriv_set_pts_info(st, 64, 1, 14112000);
s->pb->maxsize = -1;
off = avio_tell(s->pb);
if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
ff_id3v1_read(s);
if(s->pb->seekable)
mp3->filesize = avio_size(s->pb);
if (mp3_parse_vbr_tags(s, st, off) < 0)
avio_seek(s->pb, off, SEEK_SET);
ret = ff_replaygain_export(st, s->metadata);
if (ret < 0)
return ret;
off = avio_tell(s->pb);
for (i = 0; i < 64 * 1024; i++) {
uint32_t header, header2;
int frame_size;
if (!(i&1023))
ffio_ensure_seekback(s->pb, i + 1024 + 4);
frame_size = check(s->pb, off + i, &header);
if (frame_size > 0) {
avio_seek(s->pb, off, SEEK_SET);
ffio_ensure_seekback(s->pb, i + 1024 + frame_size + 4);
if (check(s->pb, off + i + frame_size, &header2) >= 0 &&
(header & SAME_HEADER_MASK) == (header2 & SAME_HEADER_MASK))
{
av_log(s, AV_LOG_INFO, "Skipping %d bytes of junk at %"PRId64".\n", i, off);
avio_seek(s->pb, off + i, SEEK_SET);
break;
}
}
avio_seek(s->pb, off, SEEK_SET);
}
// the seek index is relative to the end of the xing vbr headers
for (i = 0; i < st->nb_index_entries; i++)
st->index_entries[i].pos += avio_tell(s->pb);
/* the parameters will be extracted from the compressed bitstream */
return 0;
}
| 14,328 |
FFmpeg | d150a147dac67faeaf6b1f25a523ae330168ee1e | 0 | static av_cold int close_decoder(AVCodecContext *avctx)
{
PGSSubContext *ctx = avctx->priv_data;
av_freep(&ctx->picture.rle);
ctx->picture.rle_buffer_size = 0;
return 0;
}
| 14,329 |
FFmpeg | 4d2f83f8acb6c6444c3b276e15c5369d28b7c037 | 0 | static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
GSMParseContext *s = s1->priv_data;
ParseContext *pc = &s->pc;
int next;
if (!s->block_size) {
switch (avctx->codec_id) {
case AV_CODEC_ID_GSM:
s->block_size = GSM_BLOCK_SIZE;
s->duration = GSM_FRAME_SIZE;
break;
case AV_CODEC_ID_GSM_MS:
s->block_size = GSM_MS_BLOCK_SIZE;
s->duration = GSM_FRAME_SIZE * 2;
break;
default:
return AVERROR(EINVAL);
}
}
if (!s->remaining)
s->remaining = s->block_size;
if (s->remaining <= buf_size) {
next = s->remaining;
s->remaining = 0;
} else {
next = END_NOT_FOUND;
s->remaining -= buf_size;
}
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
*poutbuf = NULL;
*poutbuf_size = 0;
return buf_size;
}
s1->duration = s->duration;
*poutbuf = buf;
*poutbuf_size = buf_size;
return next;
}
| 14,330 |
FFmpeg | d597655f771979c70c08f8f8ed84c1319da121e8 | 0 | static void put_ebml_uint(ByteIOContext *pb, unsigned int elementid, uint64_t val)
{
int i, bytes = 1;
while (val >> bytes*8) bytes++;
put_ebml_id(pb, elementid);
put_ebml_num(pb, bytes, 0);
for (i = bytes - 1; i >= 0; i--)
put_byte(pb, val >> i*8);
}
| 14,331 |
FFmpeg | b2a8850969b89151677253be4d99e0ba29212749 | 0 | static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
{
VideoState *is = opaque;
int audio_size, len1;
int bytes_per_sec;
int frame_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, 1, is->audio_tgt.fmt, 1);
double pts;
audio_callback_time = av_gettime();
while (len > 0) {
if (is->audio_buf_index >= is->audio_buf_size) {
audio_size = audio_decode_frame(is, &pts);
if (audio_size < 0) {
/* if error, just output silence */
is->audio_buf = is->silence_buf;
is->audio_buf_size = sizeof(is->silence_buf) / frame_size * frame_size;
} else {
if (is->show_mode != SHOW_MODE_VIDEO)
update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
is->audio_buf_size = audio_size;
}
is->audio_buf_index = 0;
}
len1 = is->audio_buf_size - is->audio_buf_index;
if (len1 > len)
len1 = len;
memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
len -= len1;
stream += len1;
is->audio_buf_index += len1;
}
bytes_per_sec = is->audio_tgt.freq * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt);
is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index;
/* Let's assume the audio driver that is used by SDL has two periods. */
is->audio_current_pts = is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / bytes_per_sec;
is->audio_current_pts_drift = is->audio_current_pts - audio_callback_time / 1000000.0;
check_external_clock_sync(is, is->audio_current_pts);
}
| 14,332 |
qemu | b8852e87d9d113096342c3e0977266cda0fe9ee5 | 1 | static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
{
char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
char *p_name, *tmp_str;
/* the descriptor offset = 0x200 */
if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
return -1;
tmp_str = strstr(desc,"parentCID");
pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
if ((p_name = strstr(desc,"CID")) != NULL) {
p_name += sizeof("CID");
snprintf(p_name, sizeof(desc) - (p_name - desc), "%x\n", cid);
pstrcat(desc, sizeof(desc), tmp_desc);
}
if (bdrv_pwrite(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
return -1;
return 0;
}
| 14,334 |
FFmpeg | 636ced8e1dc8248a1353b416240b93d70ad03edb | 1 | static int process_input(void)
{
InputFile *ifile;
AVFormatContext *is;
InputStream *ist;
AVPacket pkt;
int ret, i, j;
/* select the stream that we must read now */
ifile = select_input_file();
/* if none, if is finished */
if (!ifile) {
if (got_eagain()) {
reset_eagain();
av_usleep(10000);
return AVERROR(EAGAIN);
}
av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from.\n");
return AVERROR_EOF;
}
is = ifile->ctx;
ret = get_input_packet(ifile, &pkt);
if (ret == AVERROR(EAGAIN)) {
ifile->eagain = 1;
return ret;
}
if (ret < 0) {
if (ret != AVERROR_EOF) {
print_error(is->filename, ret);
if (exit_on_error)
exit(1);
}
ifile->eof_reached = 1;
for (i = 0; i < ifile->nb_streams; i++) {
ist = input_streams[ifile->ist_index + i];
if (ist->decoding_needed)
output_packet(ist, NULL);
/* mark all outputs that don't go through lavfi as finished */
for (j = 0; j < nb_output_streams; j++) {
OutputStream *ost = output_streams[j];
if (ost->source_index == ifile->ist_index + i &&
(ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE))
ost->finished= 1;
}
}
return AVERROR(EAGAIN);
}
reset_eagain();
if (do_pkt_dump) {
av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump,
is->streams[pkt.stream_index]);
}
/* the following test is needed in case new streams appear
dynamically in stream : we ignore them */
if (pkt.stream_index >= ifile->nb_streams)
goto discard_packet;
ist = input_streams[ifile->ist_index + pkt.stream_index];
if (ist->discard)
goto discard_packet;
if (pkt.dts != AV_NOPTS_VALUE)
pkt.dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
if (pkt.pts != AV_NOPTS_VALUE)
pkt.pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
if (pkt.pts != AV_NOPTS_VALUE)
pkt.pts *= ist->ts_scale;
if (pkt.dts != AV_NOPTS_VALUE)
pkt.dts *= ist->ts_scale;
if (pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
(is->iformat->flags & AVFMT_TS_DISCONT)) {
int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
int64_t delta = pkt_dts - ist->next_dts;
if ((FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE || pkt_dts + 1 < ist->last_dts) && !copy_ts) {
ifile->ts_offset -= delta;
av_log(NULL, AV_LOG_DEBUG,
"timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
delta, ifile->ts_offset);
pkt.dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
if (pkt.pts != AV_NOPTS_VALUE)
pkt.pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
}
}
ret = output_packet(ist, &pkt);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d\n",
ist->file_index, ist->st->index);
if (exit_on_error)
exit(1);
}
discard_packet:
av_free_packet(&pkt);
return 0;
}
| 14,335 |
qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 | 1 | static int get_int32_le(QEMUFile *f, void *pv, size_t size)
{
int32_t *cur = pv;
int32_t loaded;
qemu_get_sbe32s(f, &loaded);
if (loaded >= 0 && loaded <= *cur) {
*cur = loaded;
return 0;
}
return -EINVAL;
}
| 14,336 |
FFmpeg | 9aebea0a4de1dc19c6309694cb1a5cd7554438cc | 1 | static int h264_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
H264Context *h = avctx->priv_data;
AVFrame *pict = data;
int buf_index = 0;
H264Picture *out;
int i, out_idx;
int ret;
h->flags = avctx->flags;
h->setup_finished = 0;
if (h->backup_width != -1) {
avctx->width = h->backup_width;
h->backup_width = -1;
}
if (h->backup_height != -1) {
avctx->height = h->backup_height;
h->backup_height = -1;
}
if (h->backup_pix_fmt != AV_PIX_FMT_NONE) {
avctx->pix_fmt = h->backup_pix_fmt;
h->backup_pix_fmt = AV_PIX_FMT_NONE;
}
ff_h264_unref_picture(h, &h->last_pic_for_ec);
/* end of stream, output what is still in the buffers */
if (buf_size == 0) {
out:
h->cur_pic_ptr = NULL;
h->first_field = 0;
// FIXME factorize this with the output code below
out = h->delayed_pic[0];
out_idx = 0;
for (i = 1;
h->delayed_pic[i] &&
!h->delayed_pic[i]->f->key_frame &&
!h->delayed_pic[i]->mmco_reset;
i++)
if (h->delayed_pic[i]->poc < out->poc) {
out = h->delayed_pic[i];
out_idx = i;
}
for (i = out_idx; h->delayed_pic[i]; i++)
h->delayed_pic[i] = h->delayed_pic[i + 1];
if (out) {
out->reference &= ~DELAYED_PIC_REF;
ret = output_frame(h, pict, out);
if (ret < 0)
return ret;
*got_frame = 1;
}
return buf_index;
}
if (h->is_avc && av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) {
int side_size;
uint8_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size);
if (is_extra(side, side_size))
ff_h264_decode_extradata(h, side, side_size);
}
if(h->is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
if (is_extra(buf, buf_size))
return ff_h264_decode_extradata(h, buf, buf_size);
}
buf_index = decode_nal_units(h, buf, buf_size, 0);
if (buf_index < 0)
return AVERROR_INVALIDDATA;
if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {
av_assert0(buf_index <= buf_size);
goto out;
}
if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {
if (avctx->skip_frame >= AVDISCARD_NONREF ||
buf_size >= 4 && !memcmp("Q264", buf, 4))
return buf_size;
av_log(avctx, AV_LOG_ERROR, "no frame!\n");
return AVERROR_INVALIDDATA;
}
if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||
(h->mb_y >= h->mb_height && h->mb_height)) {
if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)
decode_postinit(h, 1);
if ((ret = ff_h264_field_end(h, &h->slice_ctx[0], 0)) < 0)
return ret;
/* Wait for second field. */
*got_frame = 0;
if (h->next_output_pic && (
h->next_output_pic->recovered)) {
if (!h->next_output_pic->recovered)
h->next_output_pic->f->flags |= AV_FRAME_FLAG_CORRUPT;
if (!h->avctx->hwaccel &&
(h->next_output_pic->field_poc[0] == INT_MAX ||
h->next_output_pic->field_poc[1] == INT_MAX)
) {
int p;
AVFrame *f = h->next_output_pic->f;
int field = h->next_output_pic->field_poc[0] == INT_MAX;
uint8_t *dst_data[4];
int linesizes[4];
const uint8_t *src_data[4];
av_log(h->avctx, AV_LOG_DEBUG, "Duplicating field %d to fill missing\n", field);
for (p = 0; p<4; p++) {
dst_data[p] = f->data[p] + (field^1)*f->linesize[p];
src_data[p] = f->data[p] + field *f->linesize[p];
linesizes[p] = 2*f->linesize[p];
}
av_image_copy(dst_data, linesizes, src_data, linesizes,
f->format, f->width, f->height>>1);
}
ret = output_frame(h, pict, h->next_output_pic);
if (ret < 0)
return ret;
*got_frame = 1;
if (CONFIG_MPEGVIDEO) {
ff_print_debug_info2(h->avctx, pict, NULL,
h->next_output_pic->mb_type,
h->next_output_pic->qscale_table,
h->next_output_pic->motion_val,
&h->low_delay,
h->mb_width, h->mb_height, h->mb_stride, 1);
}
}
}
av_assert0(pict->buf[0] || !*got_frame);
ff_h264_unref_picture(h, &h->last_pic_for_ec);
return get_consumed_bytes(buf_index, buf_size);
}
| 14,337 |
FFmpeg | 4162ceea93684f3cd656dc21d30903e102a44e73 | 1 | static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset)
{
MXFContext *mxf = arg;
MXFPartition *partition, *tmp_part;
UID op;
uint64_t footer_partition;
uint32_t nb_essence_containers;
tmp_part = av_realloc_array(mxf->partitions, mxf->partitions_count + 1, sizeof(*mxf->partitions));
if (!tmp_part)
return AVERROR(ENOMEM);
mxf->partitions = tmp_part;
if (mxf->parsing_backward) {
/* insert the new partition pack in the middle
* this makes the entries in mxf->partitions sorted by offset */
memmove(&mxf->partitions[mxf->last_forward_partition+1],
&mxf->partitions[mxf->last_forward_partition],
(mxf->partitions_count - mxf->last_forward_partition)*sizeof(*mxf->partitions));
partition = mxf->current_partition = &mxf->partitions[mxf->last_forward_partition];
} else {
mxf->last_forward_partition++;
partition = mxf->current_partition = &mxf->partitions[mxf->partitions_count];
}
memset(partition, 0, sizeof(*partition));
mxf->partitions_count++;
partition->pack_length = avio_tell(pb) - klv_offset + size;
switch(uid[13]) {
case 2:
partition->type = Header;
break;
case 3:
partition->type = BodyPartition;
break;
case 4:
partition->type = Footer;
break;
default:
av_log(mxf->fc, AV_LOG_ERROR, "unknown partition type %i\n", uid[13]);
return AVERROR_INVALIDDATA;
}
/* consider both footers to be closed (there is only Footer and CompleteFooter) */
partition->closed = partition->type == Footer || !(uid[14] & 1);
partition->complete = uid[14] > 2;
avio_skip(pb, 4);
partition->kag_size = avio_rb32(pb);
partition->this_partition = avio_rb64(pb);
partition->previous_partition = avio_rb64(pb);
footer_partition = avio_rb64(pb);
partition->header_byte_count = avio_rb64(pb);
partition->index_byte_count = avio_rb64(pb);
partition->index_sid = avio_rb32(pb);
avio_skip(pb, 8);
partition->body_sid = avio_rb32(pb);
avio_read(pb, op, sizeof(UID));
nb_essence_containers = avio_rb32(pb);
/* some files don'thave FooterPartition set in every partition */
if (footer_partition) {
if (mxf->footer_partition && mxf->footer_partition != footer_partition) {
av_log(mxf->fc, AV_LOG_ERROR,
"inconsistent FooterPartition value: %"PRIu64" != %"PRIu64"\n",
mxf->footer_partition, footer_partition);
} else {
mxf->footer_partition = footer_partition;
}
}
av_dlog(mxf->fc,
"PartitionPack: ThisPartition = 0x%"PRIX64
", PreviousPartition = 0x%"PRIX64", "
"FooterPartition = 0x%"PRIX64", IndexSID = %i, BodySID = %i\n",
partition->this_partition,
partition->previous_partition, footer_partition,
partition->index_sid, partition->body_sid);
/* sanity check PreviousPartition if set */
if (partition->previous_partition &&
mxf->run_in + partition->previous_partition >= klv_offset) {
av_log(mxf->fc, AV_LOG_ERROR,
"PreviousPartition points to this partition or forward\n");
return AVERROR_INVALIDDATA;
}
if (op[12] == 1 && op[13] == 1) mxf->op = OP1a;
else if (op[12] == 1 && op[13] == 2) mxf->op = OP1b;
else if (op[12] == 1 && op[13] == 3) mxf->op = OP1c;
else if (op[12] == 2 && op[13] == 1) mxf->op = OP2a;
else if (op[12] == 2 && op[13] == 2) mxf->op = OP2b;
else if (op[12] == 2 && op[13] == 3) mxf->op = OP2c;
else if (op[12] == 3 && op[13] == 1) mxf->op = OP3a;
else if (op[12] == 3 && op[13] == 2) mxf->op = OP3b;
else if (op[12] == 3 && op[13] == 3) mxf->op = OP3c;
else if (op[12] == 64&& op[13] == 1) mxf->op = OPSONYOpt;
else if (op[12] == 0x10) {
/* SMPTE 390m: "There shall be exactly one essence container"
* The following block deals with files that violate this, namely:
* 2011_DCPTEST_24FPS.V.mxf - two ECs, OP1a
* abcdefghiv016f56415e.mxf - zero ECs, OPAtom, output by Avid AirSpeed */
if (nb_essence_containers != 1) {
MXFOP op = nb_essence_containers ? OP1a : OPAtom;
/* only nag once */
if (!mxf->op)
av_log(mxf->fc, AV_LOG_WARNING, "\"OPAtom\" with %u ECs - assuming %s\n",
nb_essence_containers, op == OP1a ? "OP1a" : "OPAtom");
mxf->op = op;
} else
mxf->op = OPAtom;
} else {
av_log(mxf->fc, AV_LOG_ERROR, "unknown operational pattern: %02xh %02xh - guessing OP1a\n", op[12], op[13]);
mxf->op = OP1a;
}
if (partition->kag_size <= 0 || partition->kag_size > (1 << 20)) {
av_log(mxf->fc, AV_LOG_WARNING, "invalid KAGSize %i - guessing ", partition->kag_size);
if (mxf->op == OPSONYOpt)
partition->kag_size = 512;
else
partition->kag_size = 1;
av_log(mxf->fc, AV_LOG_WARNING, "%i\n", partition->kag_size);
}
return 0;
}
| 14,338 |
qemu | 7f0317cfc8da620cdb38cb5cfec5f82b8dd05403 | 1 | void commit_start(BlockDriverState *bs, BlockDriverState *base,
BlockDriverState *top, int64_t speed,
BlockdevOnError on_error, BlockCompletionFunc *cb,
void *opaque, const char *backing_file_str, Error **errp)
{
CommitBlockJob *s;
BlockReopenQueue *reopen_queue = NULL;
int orig_overlay_flags;
int orig_base_flags;
BlockDriverState *overlay_bs;
Error *local_err = NULL;
assert(top != bs);
if (top == base) {
error_setg(errp, "Invalid files for merge: top and base are the same");
return;
}
overlay_bs = bdrv_find_overlay(bs, top);
if (overlay_bs == NULL) {
error_setg(errp, "Could not find overlay image for %s:", top->filename);
return;
}
s = block_job_create(&commit_job_driver, bs, speed, cb, opaque, errp);
if (!s) {
return;
}
orig_base_flags = bdrv_get_flags(base);
orig_overlay_flags = bdrv_get_flags(overlay_bs);
/* convert base & overlay_bs to r/w, if necessary */
if (!(orig_overlay_flags & BDRV_O_RDWR)) {
reopen_queue = bdrv_reopen_queue(reopen_queue, overlay_bs, NULL,
orig_overlay_flags | BDRV_O_RDWR);
}
if (!(orig_base_flags & BDRV_O_RDWR)) {
reopen_queue = bdrv_reopen_queue(reopen_queue, base, NULL,
orig_base_flags | BDRV_O_RDWR);
}
if (reopen_queue) {
bdrv_reopen_multiple(reopen_queue, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
block_job_unref(&s->common);
return;
}
}
s->base = blk_new();
blk_insert_bs(s->base, base);
s->top = blk_new();
blk_insert_bs(s->top, top);
s->active = bs;
s->base_flags = orig_base_flags;
s->orig_overlay_flags = orig_overlay_flags;
s->backing_file_str = g_strdup(backing_file_str);
s->on_error = on_error;
s->common.co = qemu_coroutine_create(commit_run);
trace_commit_start(bs, base, top, s, s->common.co, opaque);
qemu_coroutine_enter(s->common.co, s);
}
| 14,339 |
qemu | ad0ebb91cd8b5fdc4a583b03645677771f420a46 | 1 | int spapr_tce_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, void *buf,
uint32_t size)
{
#ifdef DEBUG_TCE
fprintf(stderr, "spapr_tce_dma_write taddr=0x%llx size=0x%x\n",
(unsigned long long)taddr, size);
#endif
/* Check for bypass */
if (dev->flags & VIO_PAPR_FLAG_DMA_BYPASS) {
cpu_physical_memory_read(taddr, buf, size);
return 0;
}
while (size) {
uint64_t tce;
uint32_t lsize;
uint64_t txaddr;
/* Check if we are in bound */
if (taddr >= dev->rtce_window_size) {
#ifdef DEBUG_TCE
fprintf(stderr, "spapr_tce_dma_read out of bounds\n");
#endif
return H_DEST_PARM;
}
tce = dev->rtce_table[taddr >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;
/* How much til end of page ? */
lsize = MIN(size, ((~taddr) & SPAPR_VIO_TCE_PAGE_MASK) + 1);
/* Check TCE */
if (!(tce & 1)) {
return H_DEST_PARM;
}
/* Translate */
txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |
(taddr & SPAPR_VIO_TCE_PAGE_MASK);
#ifdef DEBUG_TCE
fprintf(stderr, " -> write to txaddr=0x%llx, size=0x%x\n",
(unsigned long long)txaddr, lsize);
#endif
/* Do it */
cpu_physical_memory_read(txaddr, buf, lsize);
buf += lsize;
taddr += lsize;
size -= lsize;
}
return H_SUCCESS;
}
| 14,340 |
FFmpeg | d6604b29ef544793479d7fb4e05ef6622bb3e534 | 0 | static av_cold int sunrast_encode_init(AVCodecContext *avctx)
{
SUNRASTContext *s = avctx->priv_data;
switch (avctx->coder_type) {
case FF_CODER_TYPE_RLE:
s->type = RT_BYTE_ENCODED;
break;
case FF_CODER_TYPE_RAW:
s->type = RT_STANDARD;
break;
default:
av_log(avctx, AV_LOG_ERROR, "invalid coder_type\n");
return AVERROR(EINVAL);
}
avctx->coded_frame = av_frame_alloc();
if (!avctx->coded_frame)
return AVERROR(ENOMEM);
avctx->coded_frame->key_frame = 1;
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
s->maptype = RMT_NONE;
s->maplength = 0;
switch (avctx->pix_fmt) {
case AV_PIX_FMT_MONOWHITE:
s->depth = 1;
break;
case AV_PIX_FMT_PAL8 :
s->maptype = RMT_EQUAL_RGB;
s->maplength = 3 * 256;
/* fall-through */
case AV_PIX_FMT_GRAY8:
s->depth = 8;
break;
case AV_PIX_FMT_BGR24:
s->depth = 24;
break;
default:
return AVERROR_BUG;
}
s->length = avctx->height * (FFALIGN(avctx->width * s->depth, 16) >> 3);
s->size = 32 + s->maplength +
s->length * (s->type == RT_BYTE_ENCODED ? 2 : 1);
return 0;
}
| 14,341 |
FFmpeg | 99b823f0a1be42abc0f3a6a0da946c4464db5fb6 | 1 | static void frame_end(MpegEncContext *s)
{
if (s->unrestricted_mv &&
s->current_picture.reference &&
!s->intra_only) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
int hshift = desc->log2_chroma_w;
int vshift = desc->log2_chroma_h;
s->mpvencdsp.draw_edges(s->current_picture.f->data[0],
s->current_picture.f->linesize[0],
s->h_edge_pos, s->v_edge_pos,
EDGE_WIDTH, EDGE_WIDTH,
EDGE_TOP | EDGE_BOTTOM);
s->mpvencdsp.draw_edges(s->current_picture.f->data[1],
s->current_picture.f->linesize[1],
s->h_edge_pos >> hshift,
s->v_edge_pos >> vshift,
EDGE_WIDTH >> hshift,
EDGE_WIDTH >> vshift,
EDGE_TOP | EDGE_BOTTOM);
s->mpvencdsp.draw_edges(s->current_picture.f->data[2],
s->current_picture.f->linesize[2],
s->h_edge_pos >> hshift,
s->v_edge_pos >> vshift,
EDGE_WIDTH >> hshift,
EDGE_WIDTH >> vshift,
EDGE_TOP | EDGE_BOTTOM);
}
emms_c();
s->last_pict_type = s->pict_type;
s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality;
if (s->pict_type!= AV_PICTURE_TYPE_B)
s->last_non_b_pict_type = s->pict_type;
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f);
FF_ENABLE_DEPRECATION_WARNINGS
#endif
#if FF_API_ERROR_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
memcpy(s->current_picture.f->error, s->current_picture.encoding_error,
sizeof(s->current_picture.encoding_error));
FF_ENABLE_DEPRECATION_WARNINGS
#endif
} | 14,342 |
qemu | e2f0c49ffae8d3a00272c3cbc68850cc5aafbffa | 1 | static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
int start_track, format, msf, toclen;
uint64_t nb_sectors;
msf = req->cmd.buf[1] & 2;
format = req->cmd.buf[2] & 0xf;
start_track = req->cmd.buf[6];
bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track, format, msf >> 1);
nb_sectors /= s->qdev.blocksize / 512;
switch (format) {
case 0:
toclen = cdrom_read_toc(nb_sectors, outbuf, msf, start_track);
break;
case 1:
/* multi session : only a single session defined */
toclen = 12;
memset(outbuf, 0, 12);
outbuf[1] = 0x0a;
outbuf[2] = 0x01;
outbuf[3] = 0x01;
break;
case 2:
toclen = cdrom_read_toc_raw(nb_sectors, outbuf, msf, start_track);
break;
default:
return -1;
}
if (toclen > req->cmd.xfer) {
toclen = req->cmd.xfer;
}
return toclen;
}
| 14,343 |
qemu | 2d528d45ecf5ee3c1a566a9f3d664464925ef830 | 1 | static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
{
CharDriverState *chr;
WinCharState *s;
chr = qemu_chr_alloc();
s = g_malloc0(sizeof(WinCharState));
s->hcom = fd_out;
chr->opaque = s;
chr->chr_write = win_chr_write;
return chr;
}
| 14,344 |
FFmpeg | a0c624e299730c8c5800375c2f5f3c6c200053ff | 1 | static av_cold int v4l2_decode_init(AVCodecContext *avctx)
{
V4L2m2mContext *s = avctx->priv_data;
V4L2Context *capture = &s->capture;
V4L2Context *output = &s->output;
int ret;
/* if these dimensions are invalid (ie, 0 or too small) an event will be raised
* by the v4l2 driver; this event will trigger a full pipeline reconfig and
* the proper values will be retrieved from the kernel driver.
*/
output->height = capture->height = avctx->coded_height;
output->width = capture->width = avctx->coded_width;
output->av_codec_id = avctx->codec_id;
output->av_pix_fmt = AV_PIX_FMT_NONE;
capture->av_codec_id = AV_CODEC_ID_RAWVIDEO;
capture->av_pix_fmt = avctx->pix_fmt;
ret = ff_v4l2_m2m_codec_init(avctx);
if (ret) {
av_log(avctx, AV_LOG_ERROR, "can't configure decoder\n");
return ret;
}
return v4l2_prepare_decoder(s);
}
| 14,345 |
FFmpeg | 014b178f84fd6c5766e6a626a83f15a0dc635c90 | 1 | static int16_t square_root(int val)
{
return (ff_sqrt(val << 1) >> 1) & (~1);
}
| 14,346 |
FFmpeg | 0d3a51e5d279dd2a56c81ba7a81a70128c5a7545 | 1 | static int process_audio_header_eacs(AVFormatContext *s)
{
EaDemuxContext *ea = s->priv_data;
AVIOContext *pb = s->pb;
int compression_type;
ea->sample_rate = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb);
ea->bytes = avio_r8(pb); /* 1=8-bit, 2=16-bit */
ea->num_channels = avio_r8(pb);
compression_type = avio_r8(pb);
avio_skip(pb, 13);
switch (compression_type) {
case 0:
switch (ea->bytes) {
case 1: ea->audio_codec = CODEC_ID_PCM_S8; break;
case 2: ea->audio_codec = CODEC_ID_PCM_S16LE; break;
break;
case 1: ea->audio_codec = CODEC_ID_PCM_MULAW; ea->bytes = 1; break;
case 2: ea->audio_codec = CODEC_ID_ADPCM_IMA_EA_EACS; break;
default:
av_log (s, AV_LOG_ERROR, "unsupported stream type; audio compression_type=%i\n", compression_type);
return 1;
| 14,347 |
qemu | b946a1533209f61a93e34898aebb5b43154b99c3 | 1 | void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
{
NE2000State *s;
qemu_check_nic_model(nd, "ne2k_isa");
s = qemu_mallocz(sizeof(NE2000State));
register_ioport_write(base, 16, 1, ne2000_ioport_write, s);
register_ioport_read(base, 16, 1, ne2000_ioport_read, s);
register_ioport_write(base + 0x10, 1, 1, ne2000_asic_ioport_write, s);
register_ioport_read(base + 0x10, 1, 1, ne2000_asic_ioport_read, s);
register_ioport_write(base + 0x10, 2, 2, ne2000_asic_ioport_write, s);
register_ioport_read(base + 0x10, 2, 2, ne2000_asic_ioport_read, s);
register_ioport_write(base + 0x1f, 1, 1, ne2000_reset_ioport_write, s);
register_ioport_read(base + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
s->irq = irq;
memcpy(s->macaddr, nd->macaddr, 6);
ne2000_reset(s);
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
ne2000_receive, ne2000_can_receive, s);
qemu_format_nic_info_str(s->vc, s->macaddr);
register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
}
| 14,348 |
FFmpeg | 786594184a1797cc4b573001f3eeb188d5912062 | 1 | static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid,
unsigned int pid)
{
struct Program *p = get_program(ts, programid);
int i;
if (!p)
return;
if (p->nb_pids >= MAX_PIDS_PER_PROGRAM)
return;
for (i = 0; i < MAX_PIDS_PER_PROGRAM; i++)
if (p->pids[i] == pid)
return;
p->pids[p->nb_pids++] = pid;
}
| 14,349 |
qemu | dede4188cc817a039154ed2ecd7f3285f6b94056 | 1 | static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,
uint8_t* heads, uint8_t* secs_per_cyl)
{
uint32_t cyls_times_heads;
if (total_sectors > 65535 * 16 * 255)
return -EFBIG;
if (total_sectors > 65535 * 16 * 63) {
*secs_per_cyl = 255;
*heads = 16;
cyls_times_heads = total_sectors / *secs_per_cyl;
} else {
*secs_per_cyl = 17;
cyls_times_heads = total_sectors / *secs_per_cyl;
*heads = (cyls_times_heads + 1023) / 1024;
if (*heads < 4)
*heads = 4;
if (cyls_times_heads >= (*heads * 1024) || *heads > 16) {
*secs_per_cyl = 31;
*heads = 16;
cyls_times_heads = total_sectors / *secs_per_cyl;
}
if (cyls_times_heads >= (*heads * 1024)) {
*secs_per_cyl = 63;
*heads = 16;
cyls_times_heads = total_sectors / *secs_per_cyl;
}
}
// Note: Rounding up deviates from the Virtual PC behaviour
// However, we need this to avoid truncating images in qemu-img convert
*cyls = (cyls_times_heads + *heads - 1) / *heads;
return 0;
}
| 14,351 |
qemu | 7d1b0095bff7157e856d1d0e6c4295641ced2752 | 1 | static inline void gen_arm_shift_reg(TCGv var, int shiftop,
TCGv shift, int flags)
{
if (flags) {
switch (shiftop) {
case 0: gen_helper_shl_cc(var, var, shift); break;
case 1: gen_helper_shr_cc(var, var, shift); break;
case 2: gen_helper_sar_cc(var, var, shift); break;
case 3: gen_helper_ror_cc(var, var, shift); break;
}
} else {
switch (shiftop) {
case 0: gen_helper_shl(var, var, shift); break;
case 1: gen_helper_shr(var, var, shift); break;
case 2: gen_helper_sar(var, var, shift); break;
case 3: tcg_gen_andi_i32(shift, shift, 0x1f);
tcg_gen_rotr_i32(var, var, shift); break;
}
}
dead_tmp(shift);
}
| 14,352 |
FFmpeg | 2da0d70d5eebe42f9fcd27ee554419ebe2a5da06 | 1 | static inline void RENAME(bgr15ToY)(uint8_t *dst, uint8_t *src, int width)
{
int i;
for(i=0; i<width; i++)
{
int d= ((uint16_t*)src)[i];
int b= d&0x1F;
int g= (d>>5)&0x1F;
int r= (d>>10)&0x1F;
dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16;
}
}
| 14,353 |
FFmpeg | 65988b991659fea72365be53e17d10953c0f8f78 | 1 | static void decode_gain_info(GetBitContext *gb, int *gaininfo)
{
int i, n;
while (get_bits1(gb)) {
/* NOTHING */
}
n = get_bits_count(gb) - 1; // amount of elements*2 to update
i = 0;
while (n--) {
int index = get_bits(gb, 3);
int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1;
while (i <= index)
gaininfo[i++] = gain;
}
while (i <= 8)
gaininfo[i++] = 0;
}
| 14,355 |
FFmpeg | 7cc84d241ba6ef8e27e4d057176a4ad385ad3d59 | 1 | static int decode_b_picture_primary_header(VC9Context *v)
{
GetBitContext *gb = &v->s.gb;
int pqindex;
/* Prolog common to all frametypes should be done in caller */
if (v->profile == PROFILE_SIMPLE)
{
av_log(v->s.avctx, AV_LOG_ERROR, "Found a B frame while in Simple Profile!\n");
return FRAME_SKIPED;
}
v->bfraction = vc9_bfraction_lut[get_vlc2(gb, vc9_bfraction_vlc.table,
VC9_BFRACTION_VLC_BITS, 2)];
if (v->bfraction < -1)
{
av_log(v->s.avctx, AV_LOG_ERROR, "Invalid BFRaction\n");
return FRAME_SKIPED;
}
else if (!v->bfraction)
{
/* We actually have a BI frame */
v->s.pict_type = BI_TYPE;
v->buffer_fullness = get_bits(gb, 7);
}
/* Read the quantization stuff */
pqindex = get_bits(gb, 5);
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = pquant_table[0][pqindex];
else
{
v->pq = pquant_table[v->quantizer_mode-1][pqindex];
}
if (pqindex < 9) v->halfpq = get_bits(gb, 1);
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
v->pquantizer = get_bits(gb, 1);
if (v->profile > PROFILE_MAIN)
{
if (v->postprocflag) v->postproc = get_bits(gb, 2);
if (v->extended_mv == 1 && v->s.pict_type != BI_TYPE)
v->mvrange = get_prefix(gb, 0, 3);
}
else
{
if (v->extended_mv == 1)
v->mvrange = get_prefix(gb, 0, 3);
}
/* Read the MV mode */
if (v->s.pict_type != BI_TYPE)
{
v->mv_mode = get_bits(gb, 1);
if (v->pq < 13)
{
if (!v->mv_mode)
{
v->mv_mode = get_bits(gb, 2);
if (v->mv_mode)
av_log(v->s.avctx, AV_LOG_ERROR,
"mv_mode for lowquant B frame was %i\n", v->mv_mode);
}
}
else
{
if (!v->mv_mode)
{
if (get_bits(gb, 1))
av_log(v->s.avctx, AV_LOG_ERROR,
"mv_mode for highquant B frame was %i\n", v->mv_mode);
}
v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping
}
}
return 0;
}
| 14,357 |
qemu | 8841d9dfc7f871cec7c3401a8a2d31ad34e881f7 | 1 | static inline void check_privileged(DisasContext *s)
{
if (s->tb->flags & (PSW_MASK_PSTATE >> 32)) {
gen_program_exception(s, PGM_PRIVILEGED);
}
}
| 14,358 |
FFmpeg | 7cc84d241ba6ef8e27e4d057176a4ad385ad3d59 | 1 | static int decode_p_mbs(VC9Context *v)
{
MpegEncContext *s = &v->s;
GetBitContext *gb = &v->s.gb;
int current_mb = 0, i; /* MB/Block Position info */
uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy,
*p_cbpcy /* Pointer to skip some math */;
int hybrid_pred; /* Prediction types */
int mv_mode_bit = 0;
int mqdiff, mquant; /* MB quantization */
int ttmb; /* MB Transform type */
static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
offset_table[6] = { 0, 1, 3, 7, 15, 31 };
int mb_has_coeffs = 1; /* last_flag */
int dmv_x, dmv_y; /* Differential MV components */
int k_x, k_y; /* Long MV fixed bitlength */
int hpel_flag; /* Some MB properties */
int index, index1; /* LUT indices */
int val, sign; /* MVDATA temp values */
/* Select ttmb table depending on pq */
if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0];
else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1];
else v->ttmb_vlc = &vc9_ttmb_vlc[2];
/* Select proper long MV range */
switch (v->mvrange)
{
case 1: k_x = 10; k_y = 9; break;
case 2: k_x = 12; k_y = 10; break;
case 3: k_x = 13; k_y = 11; break;
default: /*case 0 too */ k_x = 9; k_y = 8; break;
}
hpel_flag = v->mv_mode & 1; //MV_PMODE is HPEL
k_x -= hpel_flag;
k_y -= hpel_flag;
/* Reset CBPCY predictors */
memset(v->previous_line_cbpcy, 0, s->mb_stride<<2);
for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++)
{
/* Init CBPCY for line */
*((uint32_t*)previous_cbpcy) = 0x00000000;
p_cbpcy = v->previous_line_cbpcy+4;
for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++, p_cbpcy += 4)
{
if (v->mv_type_mb_plane.is_raw)
v->mv_type_mb_plane.data[current_mb] = get_bits(gb, 1);
if (v->skip_mb_plane.is_raw)
v->skip_mb_plane.data[current_mb] = get_bits(gb, 1);
if (!mv_mode_bit) /* 1MV mode */
{
if (!v->skip_mb_plane.data[current_mb])
{
GET_MVDATA(dmv_x, dmv_y);
/* hybrid mv pred, 8.3.5.3.4 */
if (v->mv_mode == MV_PMODE_1MV ||
v->mv_mode == MV_PMODE_MIXED_MV)
hybrid_pred = get_bits(gb, 1);
if (s->mb_intra && !mb_has_coeffs)
{
GET_MQUANT();
s->ac_pred = get_bits(gb, 1);
}
else if (mb_has_coeffs)
{
if (s->mb_intra) s->ac_pred = get_bits(gb, 1);
predicted_cbpcy = get_vlc2(gb, v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS, 2);
cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) ? previous_cbpcy[1] : p_cbpcy[2];
cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01);
cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3];
cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01);
cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) ? previous_cbpcy[3] : cbpcy[0];
cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01);
cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1];
cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01);
//GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS);
GET_MQUANT();
}
if (!v->ttmbf)
ttmb = get_vlc2(gb, v->ttmb_vlc->table,
VC9_TTMB_VLC_BITS, 12);
/* TODO: decode blocks from that mb wrt cbpcy */
}
else //Skipped
{
/* hybrid mv pred, 8.3.5.3.4 */
if (v->mv_mode == MV_PMODE_1MV ||
v->mv_mode == MV_PMODE_MIXED_MV)
hybrid_pred = get_bits(gb, 1);
}
} //1MV mode
else //4MV mode
{
if (!v->skip_mb_plane.data[current_mb] /* unskipped MB */)
{
/* Get CBPCY */
GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS);
for (i=0; i<4; i++) //For all 4 Y blocks
{
if (cbpcy[i] /* cbpcy set for this block */)
{
GET_MVDATA(dmv_x, dmv_y);
}
if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
hybrid_pred = get_bits(gb, 1);
GET_MQUANT();
if (s->mb_intra /* One of the 4 blocks is intra */ &&
index /* non-zero pred for that block */)
s->ac_pred = get_bits(gb, 1);
if (!v->ttmbf)
ttmb = get_vlc2(gb, v->ttmb_vlc->table,
VC9_TTMB_VLC_BITS, 12);
/* TODO: Process blocks wrt cbpcy */
}
}
else //Skipped MB
{
for (i=0; i<4; i++) //All 4 Y blocks
{
if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
hybrid_pred = get_bits(gb, 1);
/* TODO: do something */
}
}
}
/* Update for next block */
#if TRACE > 2
av_log(s->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i,"
" cbpcy=%i%i%i%i\n", current_mb,
p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3],
previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3],
cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]);
#endif
*((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
*((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
current_mb++;
}
}
return 0;
}
| 14,361 |
qemu | 4c315c27661502a0813b129e41c0bf640c34a8d6 | 1 | static void fsl_imx25_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
dc->realize = fsl_imx25_realize;
} | 14,363 |
FFmpeg | 29ce0433743c8cb0bfa4b0e174437212d31730fb | 0 | SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
{
SwsFunc t = NULL;
#if (HAVE_MMX2 || HAVE_MMX) && CONFIG_GPL
t = ff_yuv2rgb_init_mmx(c);
#endif
#if HAVE_VIS
t = ff_yuv2rgb_init_vis(c);
#endif
#if CONFIG_MLIB
t = ff_yuv2rgb_init_mlib(c);
#endif
#if HAVE_ALTIVEC && CONFIG_GPL
if (c->flags & SWS_CPU_CAPS_ALTIVEC)
t = ff_yuv2rgb_init_altivec(c);
#endif
#if ARCH_BFIN
if (c->flags & SWS_CPU_CAPS_BFIN)
t = ff_yuv2rgb_get_func_ptr_bfin(c);
#endif
if (t)
return t;
av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found.\n");
switch (c->dstFormat) {
case PIX_FMT_RGB48BE:
case PIX_FMT_RGB48LE: return yuv2rgb_c_48;
case PIX_FMT_ARGB:
case PIX_FMT_ABGR: if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) return yuva2argb_c;
case PIX_FMT_RGBA:
case PIX_FMT_BGRA: return (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) ? yuva2rgba_c : yuv2rgb_c_32;
case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
case PIX_FMT_RGB565:
case PIX_FMT_BGR565:
case PIX_FMT_RGB555:
case PIX_FMT_BGR555: return yuv2rgb_c_16;
case PIX_FMT_RGB8:
case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither;
case PIX_FMT_RGB4:
case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither;
case PIX_FMT_RGB4_BYTE:
case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither;
case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither;
default:
assert(0);
}
return NULL;
}
| 14,364 |
FFmpeg | 67fa02ed794f9505bd9c3584c14bfb61c895f5bc | 0 | static inline void celt_encode_pulses(OpusRangeCoder *rc, int *y, uint32_t N, uint32_t K)
{
ff_opus_rc_enc_uint(rc, celt_icwrsi(N, y), CELT_PVQ_V(N, K));
}
| 14,365 |
qemu | 7372c2b926200db295412efbb53f93773b7f1754 | 1 | static void gen_partset_reg(int opsize, TCGv reg, TCGv val)
{
TCGv tmp;
switch (opsize) {
case OS_BYTE:
tcg_gen_andi_i32(reg, reg, 0xffffff00);
tmp = tcg_temp_new();
tcg_gen_ext8u_i32(tmp, val);
tcg_gen_or_i32(reg, reg, tmp);
break;
case OS_WORD:
tcg_gen_andi_i32(reg, reg, 0xffff0000);
tmp = tcg_temp_new();
tcg_gen_ext16u_i32(tmp, val);
tcg_gen_or_i32(reg, reg, tmp);
break;
case OS_LONG:
case OS_SINGLE:
tcg_gen_mov_i32(reg, val);
break;
default:
qemu_assert(0, "Bad operand size");
break;
}
}
| 14,368 |
qemu | e23a1b33b53d25510320b26d9f154e19c6c99725 | 1 | PCIBus *pci_apb_init(target_phys_addr_t special_base,
target_phys_addr_t mem_base,
qemu_irq *pic, PCIBus **bus2, PCIBus **bus3)
{
DeviceState *dev;
SysBusDevice *s;
APBState *d;
/* Ultrasparc PBM main bus */
dev = qdev_create(NULL, "pbm");
qdev_init(dev);
s = sysbus_from_qdev(dev);
/* apb_config */
sysbus_mmio_map(s, 0, special_base + 0x2000ULL);
/* pci_ioport */
sysbus_mmio_map(s, 1, special_base + 0x2000000ULL);
/* mem_config: XXX size should be 4G-prom */
sysbus_mmio_map(s, 2, special_base + 0x1000000ULL);
/* mem_data */
sysbus_mmio_map(s, 3, mem_base);
d = FROM_SYSBUS(APBState, s);
d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
pci_apb_set_irq, pci_pbm_map_irq, pic,
0, 32);
pci_create_simple(d->host_state.bus, 0, "pbm");
/* APB secondary busses */
*bus2 = pci_bridge_init(d->host_state.bus, 8, PCI_VENDOR_ID_SUN,
PCI_DEVICE_ID_SUN_SIMBA, pci_apb_map_irq,
"Advanced PCI Bus secondary bridge 1");
*bus3 = pci_bridge_init(d->host_state.bus, 9, PCI_VENDOR_ID_SUN,
PCI_DEVICE_ID_SUN_SIMBA, pci_apb_map_irq,
"Advanced PCI Bus secondary bridge 2");
return d->host_state.bus;
}
| 14,369 |
qemu | 5e39d89d20b17cf6fb7f09d181d34f17b2ae2160 | 1 | static void pc_numa_cpu(const void *data)
{
char *cli;
QDict *resp;
QList *cpus;
const QObject *e;
cli = make_cli(data, "-cpu pentium -smp 8,sockets=2,cores=2,threads=2 "
"-numa node,nodeid=0 -numa node,nodeid=1 "
"-numa cpu,node-id=1,socket-id=0 "
"-numa cpu,node-id=0,socket-id=1,core-id=0 "
"-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=0 "
"-numa cpu,node-id=1,socket-id=1,core-id=1,thread-id=1");
qtest_start(cli);
cpus = get_cpus(&resp);
g_assert(cpus);
while ((e = qlist_pop(cpus))) {
QDict *cpu, *props;
int64_t socket, core, thread, node;
cpu = qobject_to_qdict(e);
g_assert(qdict_haskey(cpu, "props"));
props = qdict_get_qdict(cpu, "props");
g_assert(qdict_haskey(props, "node-id"));
node = qdict_get_int(props, "node-id");
g_assert(qdict_haskey(props, "socket-id"));
socket = qdict_get_int(props, "socket-id");
g_assert(qdict_haskey(props, "core-id"));
core = qdict_get_int(props, "core-id");
g_assert(qdict_haskey(props, "thread-id"));
thread = qdict_get_int(props, "thread-id");
if (socket == 0) {
g_assert_cmpint(node, ==, 1);
} else if (socket == 1 && core == 0) {
g_assert_cmpint(node, ==, 0);
} else if (socket == 1 && core == 1 && thread == 0) {
g_assert_cmpint(node, ==, 0);
} else if (socket == 1 && core == 1 && thread == 1) {
g_assert_cmpint(node, ==, 1);
} else {
g_assert(false);
}
}
QDECREF(resp);
qtest_end();
g_free(cli);
}
| 14,370 |
qemu | 8d04fb55dec381bc5105cb47f29d918e579e8cbd | 1 | static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
{
CPUState *cs = CPU(cpu);
CPUX86State *env = &cpu->env;
VAPICHandlers *handlers;
uint8_t opcode[2];
uint32_t imm32 = 0;
target_ulong current_pc = 0;
target_ulong current_cs_base = 0;
uint32_t current_flags = 0;
if (smp_cpus == 1) {
handlers = &s->rom_state.up;
} else {
handlers = &s->rom_state.mp;
}
if (!kvm_enabled()) {
cpu_get_tb_cpu_state(env, ¤t_pc, ¤t_cs_base,
¤t_flags);
/* Account this instruction, because we will exit the tb.
This is the first instruction in the block. Therefore
there is no need in restoring CPU state. */
if (use_icount) {
--cs->icount_decr.u16.low;
}
}
pause_all_vcpus();
cpu_memory_rw_debug(cs, ip, opcode, sizeof(opcode), 0);
switch (opcode[0]) {
case 0x89: /* mov r32 to r/m32 */
patch_byte(cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */
patch_call(s, cpu, ip + 1, handlers->set_tpr);
break;
case 0x8b: /* mov r/m32 to r32 */
patch_byte(cpu, ip, 0x90);
patch_call(s, cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);
break;
case 0xa1: /* mov abs to eax */
patch_call(s, cpu, ip, handlers->get_tpr[0]);
break;
case 0xa3: /* mov eax to abs */
patch_call(s, cpu, ip, handlers->set_tpr_eax);
break;
case 0xc7: /* mov imm32, r/m32 (c7/0) */
patch_byte(cpu, ip, 0x68); /* push imm32 */
cpu_memory_rw_debug(cs, ip + 6, (void *)&imm32, sizeof(imm32), 0);
cpu_memory_rw_debug(cs, ip + 1, (void *)&imm32, sizeof(imm32), 1);
patch_call(s, cpu, ip + 5, handlers->set_tpr);
break;
case 0xff: /* push r/m32 */
patch_byte(cpu, ip, 0x50); /* push eax */
patch_call(s, cpu, ip + 1, handlers->get_tpr_stack);
break;
default:
abort();
}
resume_all_vcpus();
if (!kvm_enabled()) {
/* tb_lock will be reset when cpu_loop_exit_noexc longjmps
* back into the cpu_exec loop. */
tb_lock();
tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);
cpu_loop_exit_noexc(cs);
}
}
| 14,371 |
FFmpeg | 7cc84d241ba6ef8e27e4d057176a4ad385ad3d59 | 1 | static int vc9_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
uint8_t *buf, int buf_size)
{
VC9Context *v = avctx->priv_data;
MpegEncContext *s = &v->s;
int ret = FRAME_SKIPED, len, start_code;
AVFrame *pict = data;
uint8_t *tmp_buf;
v->s.avctx = avctx;
//buf_size = 0 -> last frame
if (!buf_size) return 0;
len = avpicture_get_size(avctx->pix_fmt, avctx->width,
avctx->height);
tmp_buf = (uint8_t *)av_mallocz(len);
avpicture_fill((AVPicture *)pict, tmp_buf, avctx->pix_fmt,
avctx->width, avctx->height);
if (avctx->codec_id == CODEC_ID_VC9)
{
#if 0
// search for IDU's
// FIXME
uint32_t scp = 0;
int scs = 0, i = 0;
while (i < buf_size)
{
for (; i < buf_size && scp != 0x000001; i++)
scp = ((scp<<8)|buf[i])&0xffffff;
if (scp != 0x000001)
break; // eof ?
scs = buf[i++];
init_get_bits(gb, buf+i, (buf_size-i)*8);
switch(scs)
{
case 0x0A: //Sequence End Code
return 0;
case 0x0B: //Slice Start Code
av_log(avctx, AV_LOG_ERROR, "Slice coding not supported\n");
return -1;
case 0x0C: //Field start code
av_log(avctx, AV_LOG_ERROR, "Interlaced coding not supported\n");
return -1;
case 0x0D: //Frame start code
break;
case 0x0E: //Entry point Start Code
if (v->profile <= MAIN_PROFILE)
av_log(avctx, AV_LOG_ERROR,
"Found an entry point in profile %i\n", v->profile);
advanced_entry_point_process(avctx, gb);
break;
case 0x0F: //Sequence header Start Code
decode_sequence_header(avctx, gb);
break;
default:
av_log(avctx, AV_LOG_ERROR,
"Unsupported IDU suffix %lX\n", scs);
}
i += get_bits_count(gb)*8;
}
#else
av_abort();
#endif
}
else
init_get_bits(&v->s.gb, buf, buf_size*8);
s->flags= avctx->flags;
s->flags2= avctx->flags2;
/* no supplementary picture */
if (buf_size == 0) {
/* special case for last picture */
if (s->low_delay==0 && s->next_picture_ptr) {
*pict= *(AVFrame*)s->next_picture_ptr;
s->next_picture_ptr= NULL;
*data_size = sizeof(AVFrame);
}
return 0;
}
//No IDU - we mimic ff_h263_decode_frame
s->bitstream_buffer_size=0;
if (!s->context_initialized) {
if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
return -1;
}
//we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
s->current_picture_ptr= &s->picture[ff_find_unused_picture(s, 0)];
}
#if HAS_ADVANCED_PROFILE
if (v->profile > PROFILE_MAIN)
ret= advanced_decode_picture_primary_header(v);
else
#endif
ret= standard_decode_picture_primary_header(v);
if (ret == FRAME_SKIPED) return buf_size;
/* skip if the header was thrashed */
if (ret < 0){
av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
return -1;
}
//No bug workaround yet, no DCT conformance
//WMV9 does have resized images
if (v->profile <= PROFILE_MAIN && v->multires){
//Parse context stuff in here, don't know how appliable it is
}
//Not sure about context initialization
// for hurry_up==5
s->current_picture.pict_type= s->pict_type;
s->current_picture.key_frame= s->pict_type == I_TYPE;
/* skip b frames if we dont have reference frames */
if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable))
return buf_size; //FIXME simulating all buffer consumed
/* skip b frames if we are in a hurry */
if(avctx->hurry_up && s->pict_type==B_TYPE)
return buf_size; //FIXME simulating all buffer consumed
/* skip everything if we are in a hurry>=5 */
if(avctx->hurry_up>=5)
return buf_size; //FIXME simulating all buffer consumed
if(s->next_p_frame_damaged){
if(s->pict_type==B_TYPE)
return buf_size; //FIXME simulating all buffer consumed
else
s->next_p_frame_damaged=0;
}
if(MPV_frame_start(s, avctx) < 0)
return -1;
ff_er_frame_start(s);
//wmv9 may or may not have skip bits
#if HAS_ADVANCED_PROFILE
if (v->profile > PROFILE_MAIN)
ret= advanced_decode_picture_secondary_header(v);
else
#endif
ret = standard_decode_picture_secondary_header(v);
if (ret<0) return FRAME_SKIPED; //FIXME Non fatal for now
//We consider the image coded in only one slice
#if HAS_ADVANCED_PROFILE
if (v->profile > PROFILE_MAIN)
{
switch(s->pict_type)
{
case I_TYPE: ret = advanced_decode_i_mbs(v); break;
case P_TYPE: ret = decode_p_mbs(v); break;
case B_TYPE:
case BI_TYPE: ret = decode_b_mbs(v); break;
default: ret = FRAME_SKIPED;
}
if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures
}
else
#endif
{
switch(s->pict_type)
{
case I_TYPE: ret = standard_decode_i_mbs(v); break;
case P_TYPE: ret = decode_p_mbs(v); break;
case B_TYPE:
case BI_TYPE: ret = decode_b_mbs(v); break;
default: ret = FRAME_SKIPED;
}
if (ret == FRAME_SKIPED) return buf_size;
}
ff_er_frame_end(s);
MPV_frame_end(s);
assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
assert(s->current_picture.pict_type == s->pict_type);
if(s->pict_type==B_TYPE || s->low_delay){
*pict= *(AVFrame*)&s->current_picture;
ff_print_debug_info(s, pict);
} else {
*pict= *(AVFrame*)&s->last_picture;
if(pict)
ff_print_debug_info(s, pict);
}
/* Return the Picture timestamp as the frame number */
/* we substract 1 because it is added on utils.c */
avctx->frame_number = s->picture_number - 1;
/* dont output the last pic after seeking */
if(s->last_picture_ptr || s->low_delay)
*data_size = sizeof(AVFrame);
av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n",
get_bits_count(&s->gb), buf_size*8);
/* Fake consumption of all data */
*data_size = len;
return buf_size; //Number of bytes consumed
}
| 14,374 |
qemu | 4482e05cbbb7e50e476f6a9500cf0b38913bd939 | 1 | static void lm32_uclinux_init(MachineState *machine)
{
const char *cpu_model = machine->cpu_model;
const char *kernel_filename = machine->kernel_filename;
const char *kernel_cmdline = machine->kernel_cmdline;
const char *initrd_filename = machine->initrd_filename;
LM32CPU *cpu;
CPULM32State *env;
DriveInfo *dinfo;
MemoryRegion *address_space_mem = get_system_memory();
MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
qemu_irq irq[32];
HWSetup *hw;
ResetInfo *reset_info;
int i;
/* memory map */
hwaddr flash_base = 0x04000000;
size_t flash_sector_size = 256 * 1024;
size_t flash_size = 32 * 1024 * 1024;
hwaddr ram_base = 0x08000000;
size_t ram_size = 64 * 1024 * 1024;
hwaddr uart0_base = 0x80000000;
hwaddr timer0_base = 0x80002000;
hwaddr timer1_base = 0x80010000;
hwaddr timer2_base = 0x80012000;
int uart0_irq = 0;
int timer0_irq = 1;
int timer1_irq = 20;
int timer2_irq = 21;
hwaddr hwsetup_base = 0x0bffe000;
hwaddr cmdline_base = 0x0bfff000;
hwaddr initrd_base = 0x08400000;
size_t initrd_max = 0x01000000;
reset_info = g_malloc0(sizeof(ResetInfo));
if (cpu_model == NULL) {
cpu_model = "lm32-full";
}
cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
if (cpu == NULL) {
fprintf(stderr, "qemu: unable to find CPU '%s'\n", cpu_model);
exit(1);
}
env = &cpu->env;
reset_info->cpu = cpu;
reset_info->flash_base = flash_base;
memory_region_allocate_system_memory(phys_ram, NULL,
"lm32_uclinux.sdram", ram_size);
memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
dinfo = drive_get(IF_PFLASH, 0, 0);
/* Spansion S29NS128P */
pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
flash_sector_size, flash_size / flash_sector_size,
1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
/* create irq lines */
env->pic_state = lm32_pic_init(qemu_allocate_irq(cpu_irq_handler, env, 0));
for (i = 0; i < 32; i++) {
irq[i] = qdev_get_gpio_in(env->pic_state, i);
}
lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
sysbus_create_simple("lm32-timer", timer2_base, irq[timer2_irq]);
/* make sure juart isn't the first chardev */
env->juart_state = lm32_juart_init(serial_hds[1]);
reset_info->bootstrap_pc = flash_base;
if (kernel_filename) {
uint64_t entry;
int kernel_size;
kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
1, EM_LATTICEMICO32, 0, 0);
reset_info->bootstrap_pc = entry;
if (kernel_size < 0) {
kernel_size = load_image_targphys(kernel_filename, ram_base,
ram_size);
reset_info->bootstrap_pc = ram_base;
}
if (kernel_size < 0) {
fprintf(stderr, "qemu: could not load kernel '%s'\n",
kernel_filename);
exit(1);
}
}
/* generate a rom with the hardware description */
hw = hwsetup_init();
hwsetup_add_cpu(hw, "LM32", 75000000);
hwsetup_add_flash(hw, "flash", flash_base, flash_size);
hwsetup_add_ddr_sdram(hw, "ddr_sdram", ram_base, ram_size);
hwsetup_add_timer(hw, "timer0", timer0_base, timer0_irq);
hwsetup_add_timer(hw, "timer1_dev_only", timer1_base, timer1_irq);
hwsetup_add_timer(hw, "timer2_dev_only", timer2_base, timer2_irq);
hwsetup_add_uart(hw, "uart", uart0_base, uart0_irq);
hwsetup_add_trailer(hw);
hwsetup_create_rom(hw, hwsetup_base);
hwsetup_free(hw);
reset_info->hwsetup_base = hwsetup_base;
if (kernel_cmdline && strlen(kernel_cmdline)) {
pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
kernel_cmdline);
reset_info->cmdline_base = cmdline_base;
}
if (initrd_filename) {
size_t initrd_size;
initrd_size = load_image_targphys(initrd_filename, initrd_base,
initrd_max);
reset_info->initrd_base = initrd_base;
reset_info->initrd_size = initrd_size;
}
qemu_register_reset(main_cpu_reset, reset_info);
}
| 14,375 |
qemu | 38ee14f4f33f8836fc0e209ca59c6ae8c6edf380 | 1 | static int vnc_update_client(VncState *vs, int has_dirty)
{
if (vs->need_update && vs->csock != -1) {
VncDisplay *vd = vs->vd;
VncJob *job;
int y;
int width, height;
int n = 0;
if (vs->output.offset && !vs->audio_cap && !vs->force_update)
/* kernel send buffers are full -> drop frames to throttle */
return 0;
if (!has_dirty && !vs->audio_cap && !vs->force_update)
return 0;
/*
* Send screen updates to the vnc client using the server
* surface and server dirty map. guest surface updates
* happening in parallel don't disturb us, the next pass will
* send them to the client.
*/
job = vnc_job_new(vs);
width = MIN(pixman_image_get_width(vd->server), vs->client_width);
height = MIN(pixman_image_get_height(vd->server), vs->client_height);
for (y = 0; y < height; y++) {
int x;
int last_x = -1;
for (x = 0; x < width / 16; x++) {
if (test_and_clear_bit(x, vs->dirty[y])) {
if (last_x == -1) {
last_x = x;
}
} else {
if (last_x != -1) {
int h = find_and_clear_dirty_height(vs, y, last_x, x,
height);
n += vnc_job_add_rect(job, last_x * 16, y,
(x - last_x) * 16, h);
}
last_x = -1;
}
}
if (last_x != -1) {
int h = find_and_clear_dirty_height(vs, y, last_x, x, height);
n += vnc_job_add_rect(job, last_x * 16, y,
(x - last_x) * 16, h);
}
}
vnc_job_push(job);
vs->force_update = 0;
return n;
}
if (vs->csock == -1)
vnc_disconnect_finish(vs);
return 0;
}
| 14,377 |
qemu | 47d4be12c3997343e436c6cca89aefbbbeb70863 | 1 | static void test_qemu_strtol_empty(void)
{
const char *str = "";
char f = 'X';
const char *endptr = &f;
long res = 999;
int err;
err = qemu_strtol(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0);
g_assert(endptr == str);
}
| 14,378 |
qemu | 2ad645d2854746b55ddfd1d8e951f689cca5d78f | 1 | static void test_endianness(gconstpointer data)
{
const TestCase *test = data;
char *args;
args = g_strdup_printf("-display none -M %s%s%s -device pc-testdev",
test->machine,
test->superio ? " -device " : "",
test->superio ?: "");
qtest_start(args);
isa_outl(test, 0xe0, 0x87654321);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);
g_assert_cmphex(isa_inb(test, 0xe3), ==, 0x87);
g_assert_cmphex(isa_inb(test, 0xe2), ==, 0x65);
g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x43);
g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x21);
isa_outw(test, 0xe2, 0x8866);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x88664321);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8866);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);
g_assert_cmphex(isa_inb(test, 0xe3), ==, 0x88);
g_assert_cmphex(isa_inb(test, 0xe2), ==, 0x66);
g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x43);
g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x21);
isa_outw(test, 0xe0, 0x4422);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x88664422);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8866);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4422);
g_assert_cmphex(isa_inb(test, 0xe3), ==, 0x88);
g_assert_cmphex(isa_inb(test, 0xe2), ==, 0x66);
g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x44);
g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x22);
isa_outb(test, 0xe3, 0x87);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87664422);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8766);
g_assert_cmphex(isa_inb(test, 0xe3), ==, 0x87);
g_assert_cmphex(isa_inb(test, 0xe2), ==, 0x66);
g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x44);
g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x22);
isa_outb(test, 0xe2, 0x65);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654422);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4422);
g_assert_cmphex(isa_inb(test, 0xe3), ==, 0x87);
g_assert_cmphex(isa_inb(test, 0xe2), ==, 0x65);
g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x44);
g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x22);
isa_outb(test, 0xe1, 0x43);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654322);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4322);
g_assert_cmphex(isa_inb(test, 0xe3), ==, 0x87);
g_assert_cmphex(isa_inb(test, 0xe2), ==, 0x65);
g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x43);
g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x22);
isa_outb(test, 0xe0, 0x21);
g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
g_assert_cmphex(isa_inw(test, 0xe2), ==, 0x8765);
g_assert_cmphex(isa_inw(test, 0xe0), ==, 0x4321);
g_assert_cmphex(isa_inb(test, 0xe3), ==, 0x87);
g_assert_cmphex(isa_inb(test, 0xe2), ==, 0x65);
g_assert_cmphex(isa_inb(test, 0xe1), ==, 0x43);
g_assert_cmphex(isa_inb(test, 0xe0), ==, 0x21);
qtest_quit(global_qtest);
g_free(args);
}
| 14,380 |
qemu | e8ede0a8bb5298a6979bcf7ed84ef64a64a4e3fe | 0 | float32 HELPER(ucf64_negs)(float32 a)
{
return float32_chs(a);
}
| 14,381 |
qemu | 8a5956ad6392f115521dad774055c737c49fb0dd | 0 | static void *rcu_read_perf_test(void *arg)
{
int i;
long long n_reads_local = 0;
rcu_register_thread();
*(struct rcu_reader_data **)arg = &rcu_reader;
atomic_inc(&nthreadsrunning);
while (goflag == GOFLAG_INIT) {
g_usleep(1000);
}
while (goflag == GOFLAG_RUN) {
for (i = 0; i < RCU_READ_RUN; i++) {
rcu_read_lock();
rcu_read_unlock();
}
n_reads_local += RCU_READ_RUN;
}
atomic_add(&n_reads, n_reads_local);
rcu_unregister_thread();
return NULL;
}
| 14,382 |
FFmpeg | bbd977162590db4b29a5532e3e7102e054ff3ae0 | 0 | static inline int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffset)
{
int sign, coeff;
uint32_t buf;
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
if (buf & 0xAA800000) {
buf >>= 32 - 8;
SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
coeff = ff_interleaved_ue_golomb_vlc_code[buf];
} else {
unsigned ret = 1;
do {
buf >>= 32 - 8;
SKIP_BITS(re, gb,
FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
if (ff_interleaved_golomb_vlc_len[buf] != 9) {
ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1;
ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
break;
}
ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
} while (ret<0x8000000U && BITS_AVAILABLE(re, gb));
coeff = ret - 1;
}
if (coeff) {
coeff = (coeff * qfactor + qoffset + 2) >> 2;
sign = SHOW_SBITS(re, gb, 1);
LAST_SKIP_BITS(re, gb, 1);
coeff = (coeff ^ sign) - sign;
}
CLOSE_READER(re, gb);
return coeff;
}
| 14,383 |
qemu | f07b6003b6cebaa5404d702ad8aca181580e4d6c | 0 | static CharDriverState *qemu_chr_open_tcp(const char *host_str,
int is_telnet,
int is_unix)
{
CharDriverState *chr = NULL;
TCPCharDriver *s = NULL;
int fd = -1, ret, err, val;
int is_listen = 0;
int is_waitconnect = 1;
int do_nodelay = 0;
const char *ptr;
struct sockaddr_in saddr;
#ifndef _WIN32
struct sockaddr_un uaddr;
#endif
struct sockaddr *addr;
socklen_t addrlen;
#ifndef _WIN32
if (is_unix) {
addr = (struct sockaddr *)&uaddr;
addrlen = sizeof(uaddr);
if (parse_unix_path(&uaddr, host_str) < 0)
goto fail;
} else
#endif
{
addr = (struct sockaddr *)&saddr;
addrlen = sizeof(saddr);
if (parse_host_port(&saddr, host_str) < 0)
goto fail;
}
ptr = host_str;
while((ptr = strchr(ptr,','))) {
ptr++;
if (!strncmp(ptr,"server",6)) {
is_listen = 1;
} else if (!strncmp(ptr,"nowait",6)) {
is_waitconnect = 0;
} else if (!strncmp(ptr,"nodelay",6)) {
do_nodelay = 1;
} else {
printf("Unknown option: %s\n", ptr);
goto fail;
}
}
if (!is_listen)
is_waitconnect = 0;
chr = qemu_mallocz(sizeof(CharDriverState));
if (!chr)
goto fail;
s = qemu_mallocz(sizeof(TCPCharDriver));
if (!s)
goto fail;
#ifndef _WIN32
if (is_unix)
fd = socket(PF_UNIX, SOCK_STREAM, 0);
else
#endif
fd = socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0)
goto fail;
if (!is_waitconnect)
socket_set_nonblock(fd);
s->connected = 0;
s->fd = -1;
s->listen_fd = -1;
s->is_unix = is_unix;
s->do_nodelay = do_nodelay && !is_unix;
chr->opaque = s;
chr->chr_write = tcp_chr_write;
chr->chr_close = tcp_chr_close;
if (is_listen) {
/* allow fast reuse */
#ifndef _WIN32
if (is_unix) {
char path[109];
pstrcpy(path, sizeof(path), uaddr.sun_path);
unlink(path);
} else
#endif
{
val = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
}
ret = bind(fd, addr, addrlen);
if (ret < 0)
goto fail;
ret = listen(fd, 0);
if (ret < 0)
goto fail;
s->listen_fd = fd;
qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
if (is_telnet)
s->do_telnetopt = 1;
} else {
for(;;) {
ret = connect(fd, addr, addrlen);
if (ret < 0) {
err = socket_error();
if (err == EINTR || err == EWOULDBLOCK) {
} else if (err == EINPROGRESS) {
break;
#ifdef _WIN32
} else if (err == WSAEALREADY) {
break;
#endif
} else {
goto fail;
}
} else {
s->connected = 1;
break;
}
}
s->fd = fd;
socket_set_nodelay(fd);
if (s->connected)
tcp_chr_connect(chr);
else
qemu_set_fd_handler(s->fd, NULL, tcp_chr_connect, chr);
}
if (is_listen && is_waitconnect) {
printf("QEMU waiting for connection on: %s\n", host_str);
tcp_chr_accept(chr);
socket_set_nonblock(s->listen_fd);
}
return chr;
fail:
if (fd >= 0)
closesocket(fd);
qemu_free(s);
qemu_free(chr);
return NULL;
}
| 14,384 |
qemu | 6e6efd612f58726189893fd4d948b7fc10acd872 | 0 | void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
const ARMCPRegInfo *r, void *opaque)
{
/* Define implementations of coprocessor registers.
* We store these in a hashtable because typically
* there are less than 150 registers in a space which
* is 16*16*16*8*8 = 262144 in size.
* Wildcarding is supported for the crm, opc1 and opc2 fields.
* If a register is defined twice then the second definition is
* used, so this can be used to define some generic registers and
* then override them with implementation specific variations.
* At least one of the original and the second definition should
* include ARM_CP_OVERRIDE in its type bits -- this is just a guard
* against accidental use.
*/
int crm, opc1, opc2;
int crmmin = (r->crm == CP_ANY) ? 0 : r->crm;
int crmmax = (r->crm == CP_ANY) ? 15 : r->crm;
int opc1min = (r->opc1 == CP_ANY) ? 0 : r->opc1;
int opc1max = (r->opc1 == CP_ANY) ? 7 : r->opc1;
int opc2min = (r->opc2 == CP_ANY) ? 0 : r->opc2;
int opc2max = (r->opc2 == CP_ANY) ? 7 : r->opc2;
/* 64 bit registers have only CRm and Opc1 fields */
assert(!((r->type & ARM_CP_64BIT) && (r->opc2 || r->crn)));
/* Check that the register definition has enough info to handle
* reads and writes if they are permitted.
*/
if (!(r->type & (ARM_CP_SPECIAL|ARM_CP_CONST))) {
if (r->access & PL3_R) {
assert(r->fieldoffset || r->readfn);
}
if (r->access & PL3_W) {
assert(r->fieldoffset || r->writefn);
}
}
/* Bad type field probably means missing sentinel at end of reg list */
assert(cptype_valid(r->type));
for (crm = crmmin; crm <= crmmax; crm++) {
for (opc1 = opc1min; opc1 <= opc1max; opc1++) {
for (opc2 = opc2min; opc2 <= opc2max; opc2++) {
uint32_t *key = g_new(uint32_t, 1);
ARMCPRegInfo *r2 = g_memdup(r, sizeof(ARMCPRegInfo));
int is64 = (r->type & ARM_CP_64BIT) ? 1 : 0;
*key = ENCODE_CP_REG(r->cp, is64, r->crn, crm, opc1, opc2);
if (opaque) {
r2->opaque = opaque;
}
/* Make sure reginfo passed to helpers for wildcarded regs
* has the correct crm/opc1/opc2 for this reg, not CP_ANY:
*/
r2->crm = crm;
r2->opc1 = opc1;
r2->opc2 = opc2;
/* By convention, for wildcarded registers only the first
* entry is used for migration; the others are marked as
* NO_MIGRATE so we don't try to transfer the register
* multiple times. Special registers (ie NOP/WFI) are
* never migratable.
*/
if ((r->type & ARM_CP_SPECIAL) ||
((r->crm == CP_ANY) && crm != 0) ||
((r->opc1 == CP_ANY) && opc1 != 0) ||
((r->opc2 == CP_ANY) && opc2 != 0)) {
r2->type |= ARM_CP_NO_MIGRATE;
}
/* Overriding of an existing definition must be explicitly
* requested.
*/
if (!(r->type & ARM_CP_OVERRIDE)) {
ARMCPRegInfo *oldreg;
oldreg = g_hash_table_lookup(cpu->cp_regs, key);
if (oldreg && !(oldreg->type & ARM_CP_OVERRIDE)) {
fprintf(stderr, "Register redefined: cp=%d %d bit "
"crn=%d crm=%d opc1=%d opc2=%d, "
"was %s, now %s\n", r2->cp, 32 + 32 * is64,
r2->crn, r2->crm, r2->opc1, r2->opc2,
oldreg->name, r2->name);
g_assert_not_reached();
}
}
g_hash_table_insert(cpu->cp_regs, key, r2);
}
}
}
}
| 14,385 |
qemu | 241999bf4c0dd75d300ceee46f7ad28b3a39fe97 | 0 | static void sdhci_sdma_transfer_single_block(SDHCIState *s)
{
int n;
uint32_t datacnt = s->blksize & 0x0fff;
if (s->trnmod & SDHC_TRNS_READ) {
for (n = 0; n < datacnt; n++) {
s->fifo_buffer[n] = sdbus_read_data(&s->sdbus);
}
dma_memory_write(&address_space_memory, s->sdmasysad, s->fifo_buffer,
datacnt);
} else {
dma_memory_read(&address_space_memory, s->sdmasysad, s->fifo_buffer,
datacnt);
for (n = 0; n < datacnt; n++) {
sdbus_write_data(&s->sdbus, s->fifo_buffer[n]);
}
}
if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {
s->blkcnt--;
}
sdhci_end_transfer(s);
}
| 14,389 |
qemu | 245f7b51c0ea04fb2224b1127430a096c91aee70 | 0 | static int tight_compress_data(VncState *vs, int stream_id, size_t bytes,
int level, int strategy)
{
z_streamp zstream = &vs->tight_stream[stream_id];
int previous_out;
if (bytes < VNC_TIGHT_MIN_TO_COMPRESS) {
vnc_write(vs, vs->tight.buffer, vs->tight.offset);
return bytes;
}
if (tight_init_stream(vs, stream_id, level, strategy)) {
return -1;
}
/* reserve memory in output buffer */
buffer_reserve(&vs->tight_zlib, bytes + 64);
/* set pointers */
zstream->next_in = vs->tight.buffer;
zstream->avail_in = vs->tight.offset;
zstream->next_out = vs->tight_zlib.buffer + vs->tight_zlib.offset;
zstream->avail_out = vs->tight_zlib.capacity - vs->tight_zlib.offset;
zstream->data_type = Z_BINARY;
previous_out = zstream->total_out;
/* start encoding */
if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {
fprintf(stderr, "VNC: error during tight compression\n");
return -1;
}
vs->tight_zlib.offset = vs->tight_zlib.capacity - zstream->avail_out;
bytes = zstream->total_out - previous_out;
tight_send_compact_size(vs, bytes);
vnc_write(vs, vs->tight_zlib.buffer, bytes);
buffer_reset(&vs->tight_zlib);
return bytes;
}
| 14,391 |
qemu | bec93d7283b635aabaf0bbff67b6da7fc99e020a | 0 | static void gen_compute_eflags_p(DisasContext *s, TCGv reg)
{
gen_compute_eflags(s);
tcg_gen_shri_tl(reg, cpu_cc_src, 2);
tcg_gen_andi_tl(reg, reg, 1);
}
| 14,392 |
FFmpeg | 40fbf3204208f89a0626f85ce6dd06ca0741583b | 0 | int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
{
int ret;
av_frame_unref(frame);
if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
return AVERROR(EINVAL);
if (avctx->codec->receive_frame) {
if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
return AVERROR_EOF;
return avctx->codec->receive_frame(avctx, frame);
}
// Emulation via old API.
if (!avctx->internal->buffer_frame->buf[0]) {
if (!avctx->internal->buffer_pkt->size && !avctx->internal->draining)
return AVERROR(EAGAIN);
while (1) {
if ((ret = do_decode(avctx, avctx->internal->buffer_pkt)) < 0) {
av_packet_unref(avctx->internal->buffer_pkt);
return ret;
}
// Some audio decoders may consume partial data without returning
// a frame (fate-wmapro-2ch). There is no way to make the caller
// call avcodec_receive_frame() again without returning a frame,
// so try to decode more in these cases.
if (avctx->internal->buffer_frame->buf[0] ||
!avctx->internal->buffer_pkt->size)
break;
}
}
if (!avctx->internal->buffer_frame->buf[0])
return avctx->internal->draining ? AVERROR_EOF : AVERROR(EAGAIN);
av_frame_move_ref(frame, avctx->internal->buffer_frame);
return 0;
}
| 14,394 |
qemu | b3db211f3c80bb996a704d665fe275619f728bd4 | 0 | static void test_visitor_out_no_string(TestOutputVisitorData *data,
const void *unused)
{
char *string = NULL;
QObject *obj;
/* A null string should return "" */
visit_type_str(data->ov, NULL, &string, &error_abort);
obj = visitor_get(data);
g_assert(qobject_type(obj) == QTYPE_QSTRING);
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, "");
}
| 14,395 |
qemu | 2a48d99335c572b0d3da59c1387ad131ea6ee590 | 0 | static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
{
int ret = 0, offset, cpus_offset;
CPUState *cs;
char cpu_model[32];
int smt = kvmppc_smt_threads();
uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)};
CPU_FOREACH(cs) {
PowerPCCPU *cpu = POWERPC_CPU(cs);
DeviceClass *dc = DEVICE_GET_CLASS(cs);
int index = ppc_get_vcpu_dt_id(cpu);
uint32_t associativity[] = {cpu_to_be32(0x5),
cpu_to_be32(0x0),
cpu_to_be32(0x0),
cpu_to_be32(0x0),
cpu_to_be32(cs->numa_node),
cpu_to_be32(index)};
if ((index % smt) != 0) {
continue;
}
snprintf(cpu_model, 32, "%s@%x", dc->fw_name, index);
cpus_offset = fdt_path_offset(fdt, "/cpus");
if (cpus_offset < 0) {
cpus_offset = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"),
"cpus");
if (cpus_offset < 0) {
return cpus_offset;
}
}
offset = fdt_subnode_offset(fdt, cpus_offset, cpu_model);
if (offset < 0) {
offset = fdt_add_subnode(fdt, cpus_offset, cpu_model);
if (offset < 0) {
return offset;
}
}
if (nb_numa_nodes > 1) {
ret = fdt_setprop(fdt, offset, "ibm,associativity", associativity,
sizeof(associativity));
if (ret < 0) {
return ret;
}
}
ret = fdt_setprop(fdt, offset, "ibm,pft-size",
pft_size_prop, sizeof(pft_size_prop));
if (ret < 0) {
return ret;
}
ret = spapr_fixup_cpu_smt_dt(fdt, offset, cpu,
smp_threads);
if (ret < 0) {
return ret;
}
}
return ret;
}
| 14,397 |
qemu | a7812ae412311d7d47f8aa85656faadac9d64b56 | 0 | static always_inline void gen_excp (DisasContext *ctx,
int exception, int error_code)
{
TCGv tmp1, tmp2;
tcg_gen_movi_i64(cpu_pc, ctx->pc);
tmp1 = tcg_const_i32(exception);
tmp2 = tcg_const_i32(error_code);
tcg_gen_helper_0_2(helper_excp, tmp1, tmp2);
tcg_temp_free(tmp2);
tcg_temp_free(tmp1);
}
| 14,398 |
qemu | 42a268c241183877192c376d03bd9b6d527407c7 | 0 | static bool gen_check_loop_end(DisasContext *dc, int slot)
{
if (option_enabled(dc, XTENSA_OPTION_LOOP) &&
!(dc->tb->flags & XTENSA_TBFLAG_EXCM) &&
dc->next_pc == dc->lend) {
int label = gen_new_label();
gen_advance_ccount(dc);
tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_SR[LCOUNT], 0, label);
tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_SR[LCOUNT], 1);
gen_jumpi(dc, dc->lbeg, slot);
gen_set_label(label);
gen_jumpi(dc, dc->next_pc, -1);
return true;
}
return false;
}
| 14,399 |
qemu | 056fca7b51d949aa0e18e0eb647838874a53bcbe | 0 | int i2c_send(I2CBus *bus, uint8_t data)
{
I2CSlaveClass *sc;
I2CNode *node;
int ret = 0;
QLIST_FOREACH(node, &bus->current_devs, next) {
sc = I2C_SLAVE_GET_CLASS(node->elt);
if (sc->send) {
ret = ret || sc->send(node->elt, data);
} else {
ret = -1;
}
}
return ret ? -1 : 0;
}
| 14,400 |
FFmpeg | e9e87822022fc81f92866f870ecedfd2f6272ac9 | 0 | static int find_image_range(int *pfirst_index, int *plast_index,
const char *path, int start_index, int start_index_range)
{
char buf[1024];
int range, last_index, range1, first_index;
/* find the first image */
for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0) {
*pfirst_index =
*plast_index = 1;
if (avio_check(buf, AVIO_FLAG_READ) > 0)
return 0;
return -1;
}
if (avio_check(buf, AVIO_FLAG_READ) > 0)
break;
}
if (first_index == start_index + start_index_range)
goto fail;
/* find the last image */
last_index = first_index;
for (;;) {
range = 0;
for (;;) {
if (!range)
range1 = 1;
else
range1 = 2 * range;
if (av_get_frame_filename(buf, sizeof(buf), path,
last_index + range1) < 0)
goto fail;
if (avio_check(buf, AVIO_FLAG_READ) <= 0)
break;
range = range1;
/* just in case... */
if (range >= (1 << 30))
goto fail;
}
/* we are sure than image last_index + range exists */
if (!range)
break;
last_index += range;
}
*pfirst_index = first_index;
*plast_index = last_index;
return 0;
fail:
return -1;
}
| 14,401 |
qemu | a0efbf16604770b9d805bcf210ec29942321134f | 0 | start_list(Visitor *v, const char *name, GenericList **list, size_t size,
Error **errp)
{
StringInputVisitor *siv = to_siv(v);
/* We don't support visits without a list */
assert(list);
if (parse_str(siv, name, errp) < 0) {
*list = NULL;
return;
}
siv->cur_range = g_list_first(siv->ranges);
if (siv->cur_range) {
Range *r = siv->cur_range->data;
if (r) {
siv->cur = r->begin;
}
*list = g_malloc0(size);
} else {
*list = NULL;
}
}
| 14,403 |
qemu | 3ec39b2d20a25505382619e31e6572e3d04f311e | 0 | static int xio3130_downstream_initfn(PCIDevice *d)
{
PCIBridge* br = DO_UPCAST(PCIBridge, dev, d);
PCIEPort *p = DO_UPCAST(PCIEPort, br, br);
PCIESlot *s = DO_UPCAST(PCIESlot, port, p);
int rc;
int tmp;
rc = pci_bridge_initfn(d);
if (rc < 0) {
return rc;
}
pcie_port_init_reg(d);
pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_TI);
pci_config_set_device_id(d->config, PCI_DEVICE_ID_TI_XIO3130D);
d->config[PCI_REVISION_ID] = XIO3130_REVISION;
rc = msi_init(d, XIO3130_MSI_OFFSET, XIO3130_MSI_NR_VECTOR,
XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);
if (rc < 0) {
goto err_bridge;
}
rc = pci_bridge_ssvid_init(d, XIO3130_SSVID_OFFSET,
XIO3130_SSVID_SVID, XIO3130_SSVID_SSID);
if (rc < 0) {
goto err_bridge;
}
rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_DOWNSTREAM,
p->port);
if (rc < 0) {
goto err_msi;
}
pcie_cap_flr_init(d);
pcie_cap_deverr_init(d);
pcie_cap_slot_init(d, s->slot);
pcie_chassis_create(s->chassis);
rc = pcie_chassis_add_slot(s);
if (rc < 0) {
goto err_pcie_cap;
}
pcie_cap_ari_init(d);
rc = pcie_aer_init(d, XIO3130_AER_OFFSET);
if (rc < 0) {
goto err;
}
return 0;
err:
pcie_chassis_del_slot(s);
err_pcie_cap:
pcie_cap_exit(d);
err_msi:
msi_uninit(d);
err_bridge:
tmp = pci_bridge_exitfn(d);
assert(!tmp);
return rc;
}
| 14,404 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | void imx_timerg_create(const target_phys_addr_t addr,
qemu_irq irq,
DeviceState *ccm)
{
IMXTimerGState *pp;
DeviceState *dev;
dev = sysbus_create_simple("imx_timerg", addr, irq);
pp = container_of(dev, IMXTimerGState, busdev.qdev);
pp->ccm = ccm;
}
| 14,406 |
qemu | 539de1246d355d3b8aa33fb7cde732352d8827c7 | 0 | static int mig_save_device_bulk(Monitor *mon, QEMUFile *f,
BlkMigDevState *bmds)
{
int64_t total_sectors = bmds->total_sectors;
int64_t cur_sector = bmds->cur_sector;
BlockDriverState *bs = bmds->bs;
BlkMigBlock *blk;
int nr_sectors;
if (bmds->shared_base) {
while (cur_sector < total_sectors &&
!bdrv_is_allocated(bs, cur_sector, MAX_IS_ALLOCATED_SEARCH,
&nr_sectors)) {
cur_sector += nr_sectors;
}
}
if (cur_sector >= total_sectors) {
bmds->cur_sector = bmds->completed_sectors = total_sectors;
return 1;
}
bmds->completed_sectors = cur_sector;
cur_sector &= ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1);
/* we are going to transfer a full block even if it is not allocated */
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
if (total_sectors - cur_sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
nr_sectors = total_sectors - cur_sector;
}
blk = g_malloc(sizeof(BlkMigBlock));
blk->buf = g_malloc(BLOCK_SIZE);
blk->bmds = bmds;
blk->sector = cur_sector;
blk->nr_sectors = nr_sectors;
blk->iov.iov_base = blk->buf;
blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
if (block_mig_state.submitted == 0) {
block_mig_state.prev_time_offset = qemu_get_clock_ns(rt_clock);
}
blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov,
nr_sectors, blk_mig_read_cb, blk);
block_mig_state.submitted++;
bdrv_reset_dirty(bs, cur_sector, nr_sectors);
bmds->cur_sector = cur_sector + nr_sectors;
return (bmds->cur_sector >= total_sectors);
}
| 14,407 |
qemu | fb1a3a051d89975f26296163066bb0745ecca49d | 0 | int64_t qemu_clock_get_ns(QEMUClockType type)
{
int64_t now, last;
QEMUClock *clock = qemu_clock_ptr(type);
switch (type) {
case QEMU_CLOCK_REALTIME:
return get_clock();
default:
case QEMU_CLOCK_VIRTUAL:
if (use_icount) {
return cpu_get_icount();
} else {
return cpu_get_clock();
}
case QEMU_CLOCK_HOST:
now = get_clock_realtime();
last = clock->last;
clock->last = now;
if (now < last) {
notifier_list_notify(&clock->reset_notifiers, &now);
}
return now;
case QEMU_CLOCK_VIRTUAL_RT:
return cpu_get_clock();
}
}
| 14,408 |
qemu | fda4096fca83dcdc72e0fc0e4a1ae6e7724fb5e0 | 0 | static void test_acpi_q35_tcg_cphp(void)
{
test_data data;
memset(&data, 0, sizeof(data));
data.machine = MACHINE_Q35;
data.variant = ".cphp";
test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6"
" -numa node -numa node",
&data);
free_test_data(&data);
}
| 14,409 |
qemu | 9e6636c72d8d6f0605e23ed820c8487686882b12 | 0 | int block_job_set_speed(BlockJob *job, int64_t value)
{
int rc;
if (!job->job_type->set_speed) {
return -ENOTSUP;
}
rc = job->job_type->set_speed(job, value);
if (rc == 0) {
job->speed = value;
}
return rc;
}
| 14,411 |
qemu | fda4096fca83dcdc72e0fc0e4a1ae6e7724fb5e0 | 0 | static void test_acpi_q35_tcg_memhp(void)
{
test_data data;
memset(&data, 0, sizeof(data));
data.machine = MACHINE_Q35;
data.variant = ".memhp";
test_acpi_one(" -m 128,slots=3,maxmem=1G -numa node", &data);
free_test_data(&data);
}
| 14,412 |
qemu | 81e3e75b6461c53724fe7c7918bc54468fcdaf9d | 0 | void pci_bus_reset(PCIBus *bus)
{
int i;
for (i = 0; i < bus->nirq; i++) {
bus->irq_count[i] = 0;
}
for (i = 0; i < ARRAY_SIZE(bus->devices); ++i) {
if (bus->devices[i]) {
pci_device_reset(bus->devices[i]);
}
}
}
| 14,414 |
qemu | 4086182fcd9b106345b5cc535d78bcc6d13a7683 | 0 | static bool invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd)
{
bool is_cap = cmd->mhandler.cmd_new == do_qmp_capabilities;
if (is_cap && qmp_cmd_mode(mon)) {
qerror_report(ERROR_CLASS_COMMAND_NOT_FOUND,
"Capabilities negotiation is already complete, command "
"'%s' ignored", cmd->name);
return true;
}
if (!is_cap && !qmp_cmd_mode(mon)) {
qerror_report(ERROR_CLASS_COMMAND_NOT_FOUND,
"Expecting capabilities negotiation with "
"'qmp_capabilities' before command '%s'", cmd->name);
return true;
}
return false;
}
| 14,415 |
FFmpeg | a8ff69ce2bad1c4bb043e88ea35f5ab5691d4f3c | 0 | static int encode_ext_header(Wmv2Context *w){
MpegEncContext * const s= &w->s;
PutBitContext pb;
int code;
init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size);
put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));
put_bits(&pb, 1, w->mspel_bit=1);
put_bits(&pb, 1, w->flag3=1);
put_bits(&pb, 1, w->abt_flag=1);
put_bits(&pb, 1, w->j_type_bit=1);
put_bits(&pb, 1, w->top_left_mv_flag=0);
put_bits(&pb, 1, w->per_mb_rl_bit=1);
put_bits(&pb, 3, code=1);
flush_put_bits(&pb);
s->slice_height = s->mb_height / code;
return 0;
}
| 14,416 |
qemu | db78ef5b0a93b16ad56b70a70e21b1c5e7d06ba8 | 0 | static int sd_schedule_bh(QEMUBHFunc *cb, SheepdogAIOCB *acb)
{
if (acb->bh) {
error_report("bug: %d %d\n", acb->aiocb_type, acb->aiocb_type);
return -EIO;
}
acb->bh = qemu_bh_new(cb, acb);
if (!acb->bh) {
error_report("oom: %d %d\n", acb->aiocb_type, acb->aiocb_type);
return -EIO;
}
qemu_bh_schedule(acb->bh);
return 0;
}
| 14,417 |
qemu | 8928c9c43df1a0eeda1ae2e9582beb34dce49330 | 0 | static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr,
UHCI_TD *td, uint32_t td_addr, uint32_t *int_mask)
{
int len = 0, max_len;
bool spd;
bool queuing = (q != NULL);
uint8_t pid = td->token & 0xff;
UHCIAsync *async = uhci_async_find_td(s, td_addr);
if (async) {
if (uhci_queue_verify(async->queue, qh_addr, td, td_addr, queuing)) {
assert(q == NULL || q == async->queue);
q = async->queue;
} else {
uhci_queue_free(async->queue, "guest re-used pending td");
async = NULL;
}
}
if (q == NULL) {
q = uhci_queue_find(s, td);
if (q && !uhci_queue_verify(q, qh_addr, td, td_addr, queuing)) {
uhci_queue_free(q, "guest re-used qh");
q = NULL;
}
}
if (q) {
q->valid = 32;
}
/* Is active ? */
if (!(td->ctrl & TD_CTRL_ACTIVE)) {
if (async) {
/* Guest marked a pending td non-active, cancel the queue */
uhci_queue_free(async->queue, "pending td non-active");
}
/*
* ehci11d spec page 22: "Even if the Active bit in the TD is already
* cleared when the TD is fetched ... an IOC interrupt is generated"
*/
if (td->ctrl & TD_CTRL_IOC) {
*int_mask |= 0x01;
}
return TD_RESULT_NEXT_QH;
}
if (async) {
if (!async->done)
return TD_RESULT_ASYNC_CONT;
if (queuing) {
/* we are busy filling the queue, we are not prepared
to consume completed packages then, just leave them
in async state */
return TD_RESULT_ASYNC_CONT;
}
uhci_async_unlink(async);
goto done;
}
/* Allocate new packet */
if (q == NULL) {
USBDevice *dev = uhci_find_device(s, (td->token >> 8) & 0x7f);
USBEndpoint *ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf);
q = uhci_queue_new(s, qh_addr, td, ep);
}
async = uhci_async_alloc(q, td_addr);
max_len = ((td->token >> 21) + 1) & 0x7ff;
spd = (pid == USB_TOKEN_IN && (td->ctrl & TD_CTRL_SPD) != 0);
usb_packet_setup(&async->packet, pid, q->ep, td_addr, spd,
(td->ctrl & TD_CTRL_IOC) != 0);
qemu_sglist_add(&async->sgl, td->buffer, max_len);
usb_packet_map(&async->packet, &async->sgl);
switch(pid) {
case USB_TOKEN_OUT:
case USB_TOKEN_SETUP:
len = usb_handle_packet(q->ep->dev, &async->packet);
if (len >= 0)
len = max_len;
break;
case USB_TOKEN_IN:
len = usb_handle_packet(q->ep->dev, &async->packet);
break;
default:
/* invalid pid : frame interrupted */
usb_packet_unmap(&async->packet, &async->sgl);
uhci_async_free(async);
s->status |= UHCI_STS_HCPERR;
uhci_update_irq(s);
return TD_RESULT_STOP_FRAME;
}
if (len == USB_RET_ASYNC) {
uhci_async_link(async);
if (!queuing) {
uhci_queue_fill(q, td);
}
return TD_RESULT_ASYNC_START;
}
async->packet.result = len;
done:
len = uhci_complete_td(s, td, async, int_mask);
usb_packet_unmap(&async->packet, &async->sgl);
uhci_async_free(async);
return len;
}
| 14,418 |
qemu | 079d0b7f1eedcc634c371fe05b617fdc55c8b762 | 0 | static int ccid_handle_data(USBDevice *dev, USBPacket *p)
{
USBCCIDState *s = DO_UPCAST(USBCCIDState, dev, dev);
int ret = 0;
uint8_t buf[2];
switch (p->pid) {
case USB_TOKEN_OUT:
ret = ccid_handle_bulk_out(s, p);
break;
case USB_TOKEN_IN:
switch (p->devep & 0xf) {
case CCID_BULK_IN_EP:
if (!p->iov.size) {
ret = USB_RET_NAK;
} else {
ret = ccid_bulk_in_copy_to_guest(s, p);
}
break;
case CCID_INT_IN_EP:
if (s->notify_slot_change) {
/* page 56, RDR_to_PC_NotifySlotChange */
buf[0] = CCID_MESSAGE_TYPE_RDR_to_PC_NotifySlotChange;
buf[1] = s->bmSlotICCState;
usb_packet_copy(p, buf, 2);
ret = 2;
s->notify_slot_change = false;
s->bmSlotICCState &= ~SLOT_0_CHANGED_MASK;
DPRINTF(s, D_INFO,
"handle_data: int_in: notify_slot_change %X, "
"requested len %zd\n",
s->bmSlotICCState, p->iov.size);
}
break;
default:
DPRINTF(s, 1, "Bad endpoint\n");
ret = USB_RET_STALL;
break;
}
break;
default:
DPRINTF(s, 1, "Bad token\n");
ret = USB_RET_STALL;
break;
}
return ret;
}
| 14,419 |
qemu | 7ad4c7200111d20eb97eed4f46b6026e3f0b0eef | 0 | char *g_strconcat(const char *s, ...)
{
char *s;
/*
* Can't model: last argument must be null, the others
* null-terminated strings
*/
s = __coverity_alloc_nosize__();
__coverity_writeall__(s);
__coverity_mark_as_afm_allocated__(s, AFM_free);
return s;
}
| 14,420 |
qemu | bc7c08a2c375acb7ae4d433054415588b176d34c | 0 | static void test_qemu_strtoul_max(void)
{
char *str = g_strdup_printf("%lu", ULONG_MAX);
char f = 'X';
const char *endptr = &f;
unsigned long res = 999;
int err;
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, ULONG_MAX);
g_assert(endptr == str + strlen(str));
g_free(str);
}
| 14,421 |
qemu | fe52840c8760122257be7b7e4893dd951480a71f | 0 | static int coroutine_enter_func(void *arg)
{
Coroutine *co = arg;
qemu_coroutine_enter(co, NULL);
return 0;
}
| 14,422 |
qemu | ac531cb6e542b1e61d668604adf9dc5306a948c0 | 0 | START_TEST(qdict_new_test)
{
QDict *qdict;
qdict = qdict_new();
fail_unless(qdict != NULL);
fail_unless(qdict_size(qdict) == 0);
fail_unless(qdict->base.refcnt == 1);
fail_unless(qobject_type(QOBJECT(qdict)) == QTYPE_QDICT);
// destroy doesn't exit yet
free(qdict);
}
| 14,423 |
qemu | 847a6473206607bc6c84f6c537a0fe603ff7aaa6 | 0 | int print_insn_xtensa(bfd_vma memaddr, struct disassemble_info *info)
{
xtensa_isa isa = info->private_data;
xtensa_insnbuf insnbuf = xtensa_insnbuf_alloc(isa);
xtensa_insnbuf slotbuf = xtensa_insnbuf_alloc(isa);
bfd_byte *buffer = g_malloc(1);
int status = info->read_memory_func(memaddr, buffer, 1, info);
xtensa_format fmt;
unsigned slot, slots;
unsigned len;
if (status) {
info->memory_error_func(status, memaddr, info);
len = -1;
goto out;
}
len = xtensa_isa_length_from_chars(isa, buffer);
if (len == XTENSA_UNDEFINED) {
info->fprintf_func(info->stream, ".byte 0x%02x", buffer[0]);
len = 1;
goto out;
}
buffer = g_realloc(buffer, len);
status = info->read_memory_func(memaddr + 1, buffer + 1, len - 1, info);
if (status) {
info->fprintf_func(info->stream, ".byte 0x%02x", buffer[0]);
info->memory_error_func(status, memaddr + 1, info);
len = 1;
goto out;
}
xtensa_insnbuf_from_chars(isa, insnbuf, buffer, len);
fmt = xtensa_format_decode(isa, insnbuf);
if (fmt == XTENSA_UNDEFINED) {
unsigned i;
for (i = 0; i < len; ++i) {
info->fprintf_func(info->stream, "%s 0x%02x",
i ? ", " : ".byte ", buffer[i]);
}
goto out;
}
slots = xtensa_format_num_slots(isa, fmt);
if (slots > 1) {
info->fprintf_func(info->stream, "{ ");
}
for (slot = 0; slot < slots; ++slot) {
xtensa_opcode opc;
unsigned opnd, vopnd, opnds;
if (slot) {
info->fprintf_func(info->stream, "; ");
}
xtensa_format_get_slot(isa, fmt, slot, insnbuf, slotbuf);
opc = xtensa_opcode_decode(isa, fmt, slot, slotbuf);
if (opc == XTENSA_UNDEFINED) {
info->fprintf_func(info->stream, "???");
continue;
}
opnds = xtensa_opcode_num_operands(isa, opc);
info->fprintf_func(info->stream, "%s", xtensa_opcode_name(isa, opc));
for (opnd = vopnd = 0; opnd < opnds; ++opnd) {
if (xtensa_operand_is_visible(isa, opc, opnd)) {
uint32_t v = 0xbadc0de;
int rc;
info->fprintf_func(info->stream, vopnd ? ", " : "\t");
xtensa_operand_get_field(isa, opc, opnd, fmt, slot,
slotbuf, &v);
rc = xtensa_operand_decode(isa, opc, opnd, &v);
if (rc == XTENSA_UNDEFINED) {
info->fprintf_func(info->stream, "???");
} else if (xtensa_operand_is_register(isa, opc, opnd)) {
xtensa_regfile rf = xtensa_operand_regfile(isa, opc, opnd);
info->fprintf_func(info->stream, "%s%d",
xtensa_regfile_shortname(isa, rf), v);
} else if (xtensa_operand_is_PCrelative(isa, opc, opnd)) {
xtensa_operand_undo_reloc(isa, opc, opnd, &v, memaddr);
info->fprintf_func(info->stream, "0x%x", v);
} else {
info->fprintf_func(info->stream, "%d", v);
}
++vopnd;
}
}
}
if (slots > 1) {
info->fprintf_func(info->stream, " }");
}
out:
g_free(buffer);
xtensa_insnbuf_free(isa, insnbuf);
xtensa_insnbuf_free(isa, slotbuf);
return len;
}
| 14,424 |
qemu | ac4b0d0c4feb291643c0e8a07a92e449e13881b5 | 0 | char *qemu_strdup(const char *str)
{
char *ptr;
size_t len = strlen(str);
ptr = qemu_malloc(len + 1);
if (!ptr)
return NULL;
pstrcpy(ptr, len + 1, str);
return ptr;
}
| 14,425 |
qemu | 4be746345f13e99e468c60acbd3a355e8183e3ce | 0 | static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
{
int64_t start, end, nb_sectors;
QEMUIOVector iov;
if (!s->bdrv || bdrv_is_read_only(s->bdrv)) {
return;
}
assert(!(len % BDRV_SECTOR_SIZE));
start = off / BDRV_SECTOR_SIZE;
end = (off + len) / BDRV_SECTOR_SIZE;
nb_sectors = end - start;
qemu_iovec_init(&iov, 1);
qemu_iovec_add(&iov, s->storage + (start * BDRV_SECTOR_SIZE),
nb_sectors * BDRV_SECTOR_SIZE);
bdrv_aio_writev(s->bdrv, start, &iov, nb_sectors, bdrv_sync_complete, NULL);
}
| 14,426 |
qemu | 375092332eeaa6e47561ce47fd36144cdaf964d0 | 0 | static ssize_t test_block_read_func(QCryptoBlock *block,
size_t offset,
uint8_t *buf,
size_t buflen,
Error **errp,
void *opaque)
{
Buffer *header = opaque;
g_assert_cmpint(offset + buflen, <=, header->capacity);
memcpy(buf, header->buffer + offset, buflen);
return buflen;
}
| 14,428 |
qemu | 7f6613cedc59fa849105668ae971dc31004bca1c | 0 | static void decode_micromips32_opc (CPUMIPSState *env, DisasContext *ctx,
uint16_t insn_hw1)
{
int32_t offset;
uint16_t insn;
int rt, rs, rd, rr;
int16_t imm;
uint32_t op, minor, mips32_op;
uint32_t cond, fmt, cc;
insn = cpu_lduw_code(env, ctx->pc + 2);
ctx->opcode = (ctx->opcode << 16) | insn;
rt = (ctx->opcode >> 21) & 0x1f;
rs = (ctx->opcode >> 16) & 0x1f;
rd = (ctx->opcode >> 11) & 0x1f;
rr = (ctx->opcode >> 6) & 0x1f;
imm = (int16_t) ctx->opcode;
op = (ctx->opcode >> 26) & 0x3f;
switch (op) {
case POOL32A:
minor = ctx->opcode & 0x3f;
switch (minor) {
case 0x00:
minor = (ctx->opcode >> 6) & 0xf;
switch (minor) {
case SLL32:
mips32_op = OPC_SLL;
goto do_shifti;
case SRA:
mips32_op = OPC_SRA;
goto do_shifti;
case SRL32:
mips32_op = OPC_SRL;
goto do_shifti;
case ROTR:
mips32_op = OPC_ROTR;
do_shifti:
gen_shift_imm(ctx, mips32_op, rt, rs, rd);
break;
default:
goto pool32a_invalid;
}
break;
case 0x10:
minor = (ctx->opcode >> 6) & 0xf;
switch (minor) {
/* Arithmetic */
case ADD:
mips32_op = OPC_ADD;
goto do_arith;
case ADDU32:
mips32_op = OPC_ADDU;
goto do_arith;
case SUB:
mips32_op = OPC_SUB;
goto do_arith;
case SUBU32:
mips32_op = OPC_SUBU;
goto do_arith;
case MUL:
mips32_op = OPC_MUL;
do_arith:
gen_arith(ctx, mips32_op, rd, rs, rt);
break;
/* Shifts */
case SLLV:
mips32_op = OPC_SLLV;
goto do_shift;
case SRLV:
mips32_op = OPC_SRLV;
goto do_shift;
case SRAV:
mips32_op = OPC_SRAV;
goto do_shift;
case ROTRV:
mips32_op = OPC_ROTRV;
do_shift:
gen_shift(ctx, mips32_op, rd, rs, rt);
break;
/* Logical operations */
case AND:
mips32_op = OPC_AND;
goto do_logic;
case OR32:
mips32_op = OPC_OR;
goto do_logic;
case NOR:
mips32_op = OPC_NOR;
goto do_logic;
case XOR32:
mips32_op = OPC_XOR;
do_logic:
gen_logic(ctx, mips32_op, rd, rs, rt);
break;
/* Set less than */
case SLT:
mips32_op = OPC_SLT;
goto do_slt;
case SLTU:
mips32_op = OPC_SLTU;
do_slt:
gen_slt(ctx, mips32_op, rd, rs, rt);
break;
default:
goto pool32a_invalid;
}
break;
case 0x18:
minor = (ctx->opcode >> 6) & 0xf;
switch (minor) {
/* Conditional moves */
case MOVN:
mips32_op = OPC_MOVN;
goto do_cmov;
case MOVZ:
mips32_op = OPC_MOVZ;
do_cmov:
gen_cond_move(ctx, mips32_op, rd, rs, rt);
break;
case LWXS:
gen_ldxs(ctx, rs, rt, rd);
break;
default:
goto pool32a_invalid;
}
break;
case INS:
gen_bitops(ctx, OPC_INS, rt, rs, rr, rd);
return;
case EXT:
gen_bitops(ctx, OPC_EXT, rt, rs, rr, rd);
return;
case POOL32AXF:
gen_pool32axf(env, ctx, rt, rs);
break;
case 0x07:
generate_exception(ctx, EXCP_BREAK);
break;
default:
pool32a_invalid:
MIPS_INVAL("pool32a");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case POOL32B:
minor = (ctx->opcode >> 12) & 0xf;
switch (minor) {
case CACHE:
check_cp0_enabled(ctx);
/* Treat as no-op. */
break;
case LWC2:
case SWC2:
/* COP2: Not implemented. */
generate_exception_err(ctx, EXCP_CpU, 2);
break;
case LWP:
case SWP:
#ifdef TARGET_MIPS64
case LDP:
case SDP:
#endif
gen_ldst_pair(ctx, minor, rt, rs, SIMM(ctx->opcode, 0, 12));
break;
case LWM32:
case SWM32:
#ifdef TARGET_MIPS64
case LDM:
case SDM:
#endif
gen_ldst_multiple(ctx, minor, rt, rs, SIMM(ctx->opcode, 0, 12));
break;
default:
MIPS_INVAL("pool32b");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case POOL32F:
if (env->CP0_Config1 & (1 << CP0C1_FP)) {
minor = ctx->opcode & 0x3f;
check_cp1_enabled(ctx);
switch (minor) {
case ALNV_PS:
mips32_op = OPC_ALNV_PS;
goto do_madd;
case MADD_S:
mips32_op = OPC_MADD_S;
goto do_madd;
case MADD_D:
mips32_op = OPC_MADD_D;
goto do_madd;
case MADD_PS:
mips32_op = OPC_MADD_PS;
goto do_madd;
case MSUB_S:
mips32_op = OPC_MSUB_S;
goto do_madd;
case MSUB_D:
mips32_op = OPC_MSUB_D;
goto do_madd;
case MSUB_PS:
mips32_op = OPC_MSUB_PS;
goto do_madd;
case NMADD_S:
mips32_op = OPC_NMADD_S;
goto do_madd;
case NMADD_D:
mips32_op = OPC_NMADD_D;
goto do_madd;
case NMADD_PS:
mips32_op = OPC_NMADD_PS;
goto do_madd;
case NMSUB_S:
mips32_op = OPC_NMSUB_S;
goto do_madd;
case NMSUB_D:
mips32_op = OPC_NMSUB_D;
goto do_madd;
case NMSUB_PS:
mips32_op = OPC_NMSUB_PS;
do_madd:
gen_flt3_arith(ctx, mips32_op, rd, rr, rs, rt);
break;
case CABS_COND_FMT:
cond = (ctx->opcode >> 6) & 0xf;
cc = (ctx->opcode >> 13) & 0x7;
fmt = (ctx->opcode >> 10) & 0x3;
switch (fmt) {
case 0x0:
gen_cmpabs_s(ctx, cond, rt, rs, cc);
break;
case 0x1:
gen_cmpabs_d(ctx, cond, rt, rs, cc);
break;
case 0x2:
gen_cmpabs_ps(ctx, cond, rt, rs, cc);
break;
default:
goto pool32f_invalid;
}
break;
case C_COND_FMT:
cond = (ctx->opcode >> 6) & 0xf;
cc = (ctx->opcode >> 13) & 0x7;
fmt = (ctx->opcode >> 10) & 0x3;
switch (fmt) {
case 0x0:
gen_cmp_s(ctx, cond, rt, rs, cc);
break;
case 0x1:
gen_cmp_d(ctx, cond, rt, rs, cc);
break;
case 0x2:
gen_cmp_ps(ctx, cond, rt, rs, cc);
break;
default:
goto pool32f_invalid;
}
break;
case POOL32FXF:
gen_pool32fxf(ctx, rt, rs);
break;
case 0x00:
/* PLL foo */
switch ((ctx->opcode >> 6) & 0x7) {
case PLL_PS:
mips32_op = OPC_PLL_PS;
goto do_ps;
case PLU_PS:
mips32_op = OPC_PLU_PS;
goto do_ps;
case PUL_PS:
mips32_op = OPC_PUL_PS;
goto do_ps;
case PUU_PS:
mips32_op = OPC_PUU_PS;
goto do_ps;
case CVT_PS_S:
mips32_op = OPC_CVT_PS_S;
do_ps:
gen_farith(ctx, mips32_op, rt, rs, rd, 0);
break;
default:
goto pool32f_invalid;
}
break;
case 0x08:
/* [LS][WDU]XC1 */
switch ((ctx->opcode >> 6) & 0x7) {
case LWXC1:
mips32_op = OPC_LWXC1;
goto do_ldst_cp1;
case SWXC1:
mips32_op = OPC_SWXC1;
goto do_ldst_cp1;
case LDXC1:
mips32_op = OPC_LDXC1;
goto do_ldst_cp1;
case SDXC1:
mips32_op = OPC_SDXC1;
goto do_ldst_cp1;
case LUXC1:
mips32_op = OPC_LUXC1;
goto do_ldst_cp1;
case SUXC1:
mips32_op = OPC_SUXC1;
do_ldst_cp1:
gen_flt3_ldst(ctx, mips32_op, rd, rd, rt, rs);
break;
default:
goto pool32f_invalid;
}
break;
case 0x18:
/* 3D insns */
fmt = (ctx->opcode >> 9) & 0x3;
switch ((ctx->opcode >> 6) & 0x7) {
case RSQRT2_FMT:
switch (fmt) {
case FMT_SDPS_S:
mips32_op = OPC_RSQRT2_S;
goto do_3d;
case FMT_SDPS_D:
mips32_op = OPC_RSQRT2_D;
goto do_3d;
case FMT_SDPS_PS:
mips32_op = OPC_RSQRT2_PS;
goto do_3d;
default:
goto pool32f_invalid;
}
break;
case RECIP2_FMT:
switch (fmt) {
case FMT_SDPS_S:
mips32_op = OPC_RECIP2_S;
goto do_3d;
case FMT_SDPS_D:
mips32_op = OPC_RECIP2_D;
goto do_3d;
case FMT_SDPS_PS:
mips32_op = OPC_RECIP2_PS;
goto do_3d;
default:
goto pool32f_invalid;
}
break;
case ADDR_PS:
mips32_op = OPC_ADDR_PS;
goto do_3d;
case MULR_PS:
mips32_op = OPC_MULR_PS;
do_3d:
gen_farith(ctx, mips32_op, rt, rs, rd, 0);
break;
default:
goto pool32f_invalid;
}
break;
case 0x20:
/* MOV[FT].fmt and PREFX */
cc = (ctx->opcode >> 13) & 0x7;
fmt = (ctx->opcode >> 9) & 0x3;
switch ((ctx->opcode >> 6) & 0x7) {
case MOVF_FMT:
switch (fmt) {
case FMT_SDPS_S:
gen_movcf_s(rs, rt, cc, 0);
break;
case FMT_SDPS_D:
gen_movcf_d(ctx, rs, rt, cc, 0);
break;
case FMT_SDPS_PS:
gen_movcf_ps(rs, rt, cc, 0);
break;
default:
goto pool32f_invalid;
}
break;
case MOVT_FMT:
switch (fmt) {
case FMT_SDPS_S:
gen_movcf_s(rs, rt, cc, 1);
break;
case FMT_SDPS_D:
gen_movcf_d(ctx, rs, rt, cc, 1);
break;
case FMT_SDPS_PS:
gen_movcf_ps(rs, rt, cc, 1);
break;
default:
goto pool32f_invalid;
}
break;
case PREFX:
break;
default:
goto pool32f_invalid;
}
break;
#define FINSN_3ARG_SDPS(prfx) \
switch ((ctx->opcode >> 8) & 0x3) { \
case FMT_SDPS_S: \
mips32_op = OPC_##prfx##_S; \
goto do_fpop; \
case FMT_SDPS_D: \
mips32_op = OPC_##prfx##_D; \
goto do_fpop; \
case FMT_SDPS_PS: \
mips32_op = OPC_##prfx##_PS; \
goto do_fpop; \
default: \
goto pool32f_invalid; \
}
case 0x30:
/* regular FP ops */
switch ((ctx->opcode >> 6) & 0x3) {
case ADD_FMT:
FINSN_3ARG_SDPS(ADD);
break;
case SUB_FMT:
FINSN_3ARG_SDPS(SUB);
break;
case MUL_FMT:
FINSN_3ARG_SDPS(MUL);
break;
case DIV_FMT:
fmt = (ctx->opcode >> 8) & 0x3;
if (fmt == 1) {
mips32_op = OPC_DIV_D;
} else if (fmt == 0) {
mips32_op = OPC_DIV_S;
} else {
goto pool32f_invalid;
}
goto do_fpop;
default:
goto pool32f_invalid;
}
break;
case 0x38:
/* cmovs */
switch ((ctx->opcode >> 6) & 0x3) {
case MOVN_FMT:
FINSN_3ARG_SDPS(MOVN);
break;
case MOVZ_FMT:
FINSN_3ARG_SDPS(MOVZ);
break;
default:
goto pool32f_invalid;
}
break;
do_fpop:
gen_farith(ctx, mips32_op, rt, rs, rd, 0);
break;
default:
pool32f_invalid:
MIPS_INVAL("pool32f");
generate_exception(ctx, EXCP_RI);
break;
}
} else {
generate_exception_err(ctx, EXCP_CpU, 1);
}
break;
case POOL32I:
minor = (ctx->opcode >> 21) & 0x1f;
switch (minor) {
case BLTZ:
mips32_op = OPC_BLTZ;
goto do_branch;
case BLTZAL:
mips32_op = OPC_BLTZAL;
goto do_branch;
case BLTZALS:
mips32_op = OPC_BLTZALS;
goto do_branch;
case BGEZ:
mips32_op = OPC_BGEZ;
goto do_branch;
case BGEZAL:
mips32_op = OPC_BGEZAL;
goto do_branch;
case BGEZALS:
mips32_op = OPC_BGEZALS;
goto do_branch;
case BLEZ:
mips32_op = OPC_BLEZ;
goto do_branch;
case BGTZ:
mips32_op = OPC_BGTZ;
do_branch:
gen_compute_branch(ctx, mips32_op, 4, rs, -1, imm << 1);
break;
/* Traps */
case TLTI:
mips32_op = OPC_TLTI;
goto do_trapi;
case TGEI:
mips32_op = OPC_TGEI;
goto do_trapi;
case TLTIU:
mips32_op = OPC_TLTIU;
goto do_trapi;
case TGEIU:
mips32_op = OPC_TGEIU;
goto do_trapi;
case TNEI:
mips32_op = OPC_TNEI;
goto do_trapi;
case TEQI:
mips32_op = OPC_TEQI;
do_trapi:
gen_trap(ctx, mips32_op, rs, -1, imm);
break;
case BNEZC:
case BEQZC:
gen_compute_branch(ctx, minor == BNEZC ? OPC_BNE : OPC_BEQ,
4, rs, 0, imm << 1);
/* Compact branches don't have a delay slot, so just let
the normal delay slot handling take us to the branch
target. */
break;
case LUI:
gen_logic_imm(ctx, OPC_LUI, rs, -1, imm);
break;
case SYNCI:
break;
case BC2F:
case BC2T:
/* COP2: Not implemented. */
generate_exception_err(ctx, EXCP_CpU, 2);
break;
case BC1F:
mips32_op = (ctx->opcode & (1 << 16)) ? OPC_BC1FANY2 : OPC_BC1F;
goto do_cp1branch;
case BC1T:
mips32_op = (ctx->opcode & (1 << 16)) ? OPC_BC1TANY2 : OPC_BC1T;
goto do_cp1branch;
case BC1ANY4F:
mips32_op = OPC_BC1FANY4;
goto do_cp1mips3d;
case BC1ANY4T:
mips32_op = OPC_BC1TANY4;
do_cp1mips3d:
check_cop1x(ctx);
check_insn(ctx, ASE_MIPS3D);
/* Fall through */
do_cp1branch:
gen_compute_branch1(ctx, mips32_op,
(ctx->opcode >> 18) & 0x7, imm << 1);
break;
case BPOSGE64:
case BPOSGE32:
/* MIPS DSP: not implemented */
/* Fall through */
default:
MIPS_INVAL("pool32i");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case POOL32C:
minor = (ctx->opcode >> 12) & 0xf;
switch (minor) {
case LWL:
mips32_op = OPC_LWL;
goto do_ld_lr;
case SWL:
mips32_op = OPC_SWL;
goto do_st_lr;
case LWR:
mips32_op = OPC_LWR;
goto do_ld_lr;
case SWR:
mips32_op = OPC_SWR;
goto do_st_lr;
#if defined(TARGET_MIPS64)
case LDL:
mips32_op = OPC_LDL;
goto do_ld_lr;
case SDL:
mips32_op = OPC_SDL;
goto do_st_lr;
case LDR:
mips32_op = OPC_LDR;
goto do_ld_lr;
case SDR:
mips32_op = OPC_SDR;
goto do_st_lr;
case LWU:
mips32_op = OPC_LWU;
goto do_ld_lr;
case LLD:
mips32_op = OPC_LLD;
goto do_ld_lr;
#endif
case LL:
mips32_op = OPC_LL;
goto do_ld_lr;
do_ld_lr:
gen_ld(ctx, mips32_op, rt, rs, SIMM(ctx->opcode, 0, 12));
break;
do_st_lr:
gen_st(ctx, mips32_op, rt, rs, SIMM(ctx->opcode, 0, 12));
break;
case SC:
gen_st_cond(ctx, OPC_SC, rt, rs, SIMM(ctx->opcode, 0, 12));
break;
#if defined(TARGET_MIPS64)
case SCD:
gen_st_cond(ctx, OPC_SCD, rt, rs, SIMM(ctx->opcode, 0, 12));
break;
#endif
case PREF:
/* Treat as no-op */
break;
default:
MIPS_INVAL("pool32c");
generate_exception(ctx, EXCP_RI);
break;
}
break;
case ADDI32:
mips32_op = OPC_ADDI;
goto do_addi;
case ADDIU32:
mips32_op = OPC_ADDIU;
do_addi:
gen_arith_imm(ctx, mips32_op, rt, rs, imm);
break;
/* Logical operations */
case ORI32:
mips32_op = OPC_ORI;
goto do_logici;
case XORI32:
mips32_op = OPC_XORI;
goto do_logici;
case ANDI32:
mips32_op = OPC_ANDI;
do_logici:
gen_logic_imm(ctx, mips32_op, rt, rs, imm);
break;
/* Set less than immediate */
case SLTI32:
mips32_op = OPC_SLTI;
goto do_slti;
case SLTIU32:
mips32_op = OPC_SLTIU;
do_slti:
gen_slt_imm(ctx, mips32_op, rt, rs, imm);
break;
case JALX32:
offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
gen_compute_branch(ctx, OPC_JALX, 4, rt, rs, offset);
break;
case JALS32:
offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 1;
gen_compute_branch(ctx, OPC_JALS, 4, rt, rs, offset);
break;
case BEQ32:
gen_compute_branch(ctx, OPC_BEQ, 4, rt, rs, imm << 1);
break;
case BNE32:
gen_compute_branch(ctx, OPC_BNE, 4, rt, rs, imm << 1);
break;
case J32:
gen_compute_branch(ctx, OPC_J, 4, rt, rs,
(int32_t)(ctx->opcode & 0x3FFFFFF) << 1);
break;
case JAL32:
gen_compute_branch(ctx, OPC_JAL, 4, rt, rs,
(int32_t)(ctx->opcode & 0x3FFFFFF) << 1);
break;
/* Floating point (COP1) */
case LWC132:
mips32_op = OPC_LWC1;
goto do_cop1;
case LDC132:
mips32_op = OPC_LDC1;
goto do_cop1;
case SWC132:
mips32_op = OPC_SWC1;
goto do_cop1;
case SDC132:
mips32_op = OPC_SDC1;
do_cop1:
gen_cop1_ldst(env, ctx, mips32_op, rt, rs, imm);
break;
case ADDIUPC:
{
int reg = mmreg(ZIMM(ctx->opcode, 23, 3));
int offset = SIMM(ctx->opcode, 0, 23) << 2;
gen_addiupc(ctx, reg, offset, 0, 0);
}
break;
/* Loads and stores */
case LB32:
mips32_op = OPC_LB;
goto do_ld;
case LBU32:
mips32_op = OPC_LBU;
goto do_ld;
case LH32:
mips32_op = OPC_LH;
goto do_ld;
case LHU32:
mips32_op = OPC_LHU;
goto do_ld;
case LW32:
mips32_op = OPC_LW;
goto do_ld;
#ifdef TARGET_MIPS64
case LD32:
mips32_op = OPC_LD;
goto do_ld;
case SD32:
mips32_op = OPC_SD;
goto do_st;
#endif
case SB32:
mips32_op = OPC_SB;
goto do_st;
case SH32:
mips32_op = OPC_SH;
goto do_st;
case SW32:
mips32_op = OPC_SW;
goto do_st;
do_ld:
gen_ld(ctx, mips32_op, rt, rs, imm);
break;
do_st:
gen_st(ctx, mips32_op, rt, rs, imm);
break;
default:
generate_exception(ctx, EXCP_RI);
break;
}
}
| 14,430 |
qemu | 1792d7d0a2dc18496e8fc52906163f9f73f3d931 | 0 | static void test_qga_guest_exec(gconstpointer fix)
{
const TestFixture *fixture = fix;
QDict *ret, *val;
const gchar *out;
guchar *decoded;
int64_t pid, now, exitcode;
gsize len;
bool exited;
/* exec 'echo foo bar' */
ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {"
" 'path': '/bin/echo', 'arg': [ '-n', '\" test_str \"' ],"
" 'capture-output': true } }");
g_assert_nonnull(ret);
qmp_assert_no_error(ret);
val = qdict_get_qdict(ret, "return");
pid = qdict_get_int(val, "pid");
g_assert_cmpint(pid, >, 0);
QDECREF(ret);
/* wait for completion */
now = g_get_monotonic_time();
do {
ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status',"
" 'arguments': { 'pid': %" PRId64 " } }", pid);
g_assert_nonnull(ret);
val = qdict_get_qdict(ret, "return");
exited = qdict_get_bool(val, "exited");
if (!exited) {
QDECREF(ret);
}
} while (!exited &&
g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND);
g_assert(exited);
/* check stdout */
exitcode = qdict_get_int(val, "exitcode");
g_assert_cmpint(exitcode, ==, 0);
out = qdict_get_str(val, "out-data");
decoded = g_base64_decode(out, &len);
g_assert_cmpint(len, ==, 12);
g_assert_cmpstr((char *)decoded, ==, "\" test_str \"");
g_free(decoded);
QDECREF(ret);
}
| 14,431 |
qemu | 7df953bd456da45f761064974820ab5c3fd7b2aa | 0 | static void vtd_do_iommu_translate(VTDAddressSpace *vtd_as, uint8_t bus_num,
uint8_t devfn, hwaddr addr, bool is_write,
IOMMUTLBEntry *entry)
{
IntelIOMMUState *s = vtd_as->iommu_state;
VTDContextEntry ce;
VTDContextCacheEntry *cc_entry = &vtd_as->context_cache_entry;
uint64_t slpte;
uint32_t level;
uint16_t source_id = vtd_make_source_id(bus_num, devfn);
int ret_fr;
bool is_fpd_set = false;
bool reads = true;
bool writes = true;
VTDIOTLBEntry *iotlb_entry;
/* Check if the request is in interrupt address range */
if (vtd_is_interrupt_addr(addr)) {
if (is_write) {
/* FIXME: since we don't know the length of the access here, we
* treat Non-DWORD length write requests without PASID as
* interrupt requests, too. Withoud interrupt remapping support,
* we just use 1:1 mapping.
*/
VTD_DPRINTF(MMU, "write request to interrupt address "
"gpa 0x%"PRIx64, addr);
entry->iova = addr & VTD_PAGE_MASK_4K;
entry->translated_addr = addr & VTD_PAGE_MASK_4K;
entry->addr_mask = ~VTD_PAGE_MASK_4K;
entry->perm = IOMMU_WO;
return;
} else {
VTD_DPRINTF(GENERAL, "error: read request from interrupt address "
"gpa 0x%"PRIx64, addr);
vtd_report_dmar_fault(s, source_id, addr, VTD_FR_READ, is_write);
return;
}
}
/* Try to fetch slpte form IOTLB */
iotlb_entry = vtd_lookup_iotlb(s, source_id, addr);
if (iotlb_entry) {
VTD_DPRINTF(CACHE, "hit iotlb sid 0x%"PRIx16 " gpa 0x%"PRIx64
" slpte 0x%"PRIx64 " did 0x%"PRIx16, source_id, addr,
iotlb_entry->slpte, iotlb_entry->domain_id);
slpte = iotlb_entry->slpte;
reads = iotlb_entry->read_flags;
writes = iotlb_entry->write_flags;
goto out;
}
/* Try to fetch context-entry from cache first */
if (cc_entry->context_cache_gen == s->context_cache_gen) {
VTD_DPRINTF(CACHE, "hit context-cache bus %d devfn %d "
"(hi %"PRIx64 " lo %"PRIx64 " gen %"PRIu32 ")",
bus_num, devfn, cc_entry->context_entry.hi,
cc_entry->context_entry.lo, cc_entry->context_cache_gen);
ce = cc_entry->context_entry;
is_fpd_set = ce.lo & VTD_CONTEXT_ENTRY_FPD;
} else {
ret_fr = vtd_dev_to_context_entry(s, bus_num, devfn, &ce);
is_fpd_set = ce.lo & VTD_CONTEXT_ENTRY_FPD;
if (ret_fr) {
ret_fr = -ret_fr;
if (is_fpd_set && vtd_is_qualified_fault(ret_fr)) {
VTD_DPRINTF(FLOG, "fault processing is disabled for DMA "
"requests through this context-entry "
"(with FPD Set)");
} else {
vtd_report_dmar_fault(s, source_id, addr, ret_fr, is_write);
}
return;
}
/* Update context-cache */
VTD_DPRINTF(CACHE, "update context-cache bus %d devfn %d "
"(hi %"PRIx64 " lo %"PRIx64 " gen %"PRIu32 "->%"PRIu32 ")",
bus_num, devfn, ce.hi, ce.lo,
cc_entry->context_cache_gen, s->context_cache_gen);
cc_entry->context_entry = ce;
cc_entry->context_cache_gen = s->context_cache_gen;
}
ret_fr = vtd_gpa_to_slpte(&ce, addr, is_write, &slpte, &level,
&reads, &writes);
if (ret_fr) {
ret_fr = -ret_fr;
if (is_fpd_set && vtd_is_qualified_fault(ret_fr)) {
VTD_DPRINTF(FLOG, "fault processing is disabled for DMA requests "
"through this context-entry (with FPD Set)");
} else {
vtd_report_dmar_fault(s, source_id, addr, ret_fr, is_write);
}
return;
}
vtd_update_iotlb(s, source_id, VTD_CONTEXT_ENTRY_DID(ce.hi), addr, slpte,
reads, writes);
out:
entry->iova = addr & VTD_PAGE_MASK_4K;
entry->translated_addr = vtd_get_slpte_addr(slpte) & VTD_PAGE_MASK_4K;
entry->addr_mask = ~VTD_PAGE_MASK_4K;
entry->perm = (writes ? 2 : 0) + (reads ? 1 : 0);
}
| 14,432 |
qemu | 363e13f86eb60bce1e112a35a4c107505a69c9fe | 0 | static void single_quote_string(void)
{
int i;
struct {
const char *encoded;
const char *decoded;
} test_cases[] = {
{ "'hello world'", "hello world" },
{ "'the quick brown fox \\' jumped over the fence'",
"the quick brown fox ' jumped over the fence" },
{}
};
for (i = 0; test_cases[i].encoded; i++) {
QObject *obj;
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
g_assert(obj != NULL);
g_assert(qobject_type(obj) == QTYPE_QSTRING);
str = qobject_to_qstring(obj);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
QDECREF(str);
}
}
| 14,433 |
qemu | 2795ecf681107d55e4113592b3045ece5f6e7b3b | 0 | static int alloc_refcount_block(BlockDriverState *bs,
int64_t cluster_index, uint16_t **refcount_block)
{
BDRVQcowState *s = bs->opaque;
unsigned int refcount_table_index;
int ret;
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC);
/* Find the refcount block for the given cluster */
refcount_table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);
if (refcount_table_index < s->refcount_table_size) {
uint64_t refcount_block_offset =
s->refcount_table[refcount_table_index];
/* If it's already there, we're done */
if (refcount_block_offset) {
return load_refcount_block(bs, refcount_block_offset,
(void**) refcount_block);
}
}
/*
* If we came here, we need to allocate something. Something is at least
* a cluster for the new refcount block. It may also include a new refcount
* table if the old refcount table is too small.
*
* Note that allocating clusters here needs some special care:
*
* - We can't use the normal qcow2_alloc_clusters(), it would try to
* increase the refcount and very likely we would end up with an endless
* recursion. Instead we must place the refcount blocks in a way that
* they can describe them themselves.
*
* - We need to consider that at this point we are inside update_refcounts
* and doing the initial refcount increase. This means that some clusters
* have already been allocated by the caller, but their refcount isn't
* accurate yet. free_cluster_index tells us where this allocation ends
* as long as we don't overwrite it by freeing clusters.
*
* - alloc_clusters_noref and qcow2_free_clusters may load a different
* refcount block into the cache
*/
*refcount_block = NULL;
/* We write to the refcount table, so we might depend on L2 tables */
qcow2_cache_flush(bs, s->l2_table_cache);
/* Allocate the refcount block itself and mark it as used */
int64_t new_block = alloc_clusters_noref(bs, s->cluster_size);
if (new_block < 0) {
return new_block;
}
#ifdef DEBUG_ALLOC2
fprintf(stderr, "qcow2: Allocate refcount block %d for %" PRIx64
" at %" PRIx64 "\n",
refcount_table_index, cluster_index << s->cluster_bits, new_block);
#endif
if (in_same_refcount_block(s, new_block, cluster_index << s->cluster_bits)) {
/* Zero the new refcount block before updating it */
ret = qcow2_cache_get_empty(bs, s->refcount_block_cache, new_block,
(void**) refcount_block);
if (ret < 0) {
goto fail_block;
}
memset(*refcount_block, 0, s->cluster_size);
/* The block describes itself, need to update the cache */
int block_index = (new_block >> s->cluster_bits) &
((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
(*refcount_block)[block_index] = cpu_to_be16(1);
} else {
/* Described somewhere else. This can recurse at most twice before we
* arrive at a block that describes itself. */
ret = update_refcount(bs, new_block, s->cluster_size, 1);
if (ret < 0) {
goto fail_block;
}
bdrv_flush(bs->file);
/* Initialize the new refcount block only after updating its refcount,
* update_refcount uses the refcount cache itself */
ret = qcow2_cache_get_empty(bs, s->refcount_block_cache, new_block,
(void**) refcount_block);
if (ret < 0) {
goto fail_block;
}
memset(*refcount_block, 0, s->cluster_size);
}
/* Now the new refcount block needs to be written to disk */
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE);
qcow2_cache_entry_mark_dirty(s->refcount_block_cache, *refcount_block);
ret = qcow2_cache_flush(bs, s->refcount_block_cache);
if (ret < 0) {
goto fail_block;
}
/* If the refcount table is big enough, just hook the block up there */
if (refcount_table_index < s->refcount_table_size) {
uint64_t data64 = cpu_to_be64(new_block);
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_HOOKUP);
ret = bdrv_pwrite_sync(bs->file,
s->refcount_table_offset + refcount_table_index * sizeof(uint64_t),
&data64, sizeof(data64));
if (ret < 0) {
goto fail_block;
}
s->refcount_table[refcount_table_index] = new_block;
return 0;
}
ret = qcow2_cache_put(bs, s->refcount_block_cache, (void**) refcount_block);
if (ret < 0) {
goto fail_block;
}
/*
* If we come here, we need to grow the refcount table. Again, a new
* refcount table needs some space and we can't simply allocate to avoid
* endless recursion.
*
* Therefore let's grab new refcount blocks at the end of the image, which
* will describe themselves and the new refcount table. This way we can
* reference them only in the new table and do the switch to the new
* refcount table at once without producing an inconsistent state in
* between.
*/
BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_GROW);
/* Calculate the number of refcount blocks needed so far */
uint64_t refcount_block_clusters = 1 << (s->cluster_bits - REFCOUNT_SHIFT);
uint64_t blocks_used = (s->free_cluster_index +
refcount_block_clusters - 1) / refcount_block_clusters;
/* And now we need at least one block more for the new metadata */
uint64_t table_size = next_refcount_table_size(s, blocks_used + 1);
uint64_t last_table_size;
uint64_t blocks_clusters;
do {
uint64_t table_clusters = size_to_clusters(s, table_size);
blocks_clusters = 1 +
((table_clusters + refcount_block_clusters - 1)
/ refcount_block_clusters);
uint64_t meta_clusters = table_clusters + blocks_clusters;
last_table_size = table_size;
table_size = next_refcount_table_size(s, blocks_used +
((meta_clusters + refcount_block_clusters - 1)
/ refcount_block_clusters));
} while (last_table_size != table_size);
#ifdef DEBUG_ALLOC2
fprintf(stderr, "qcow2: Grow refcount table %" PRId32 " => %" PRId64 "\n",
s->refcount_table_size, table_size);
#endif
/* Create the new refcount table and blocks */
uint64_t meta_offset = (blocks_used * refcount_block_clusters) *
s->cluster_size;
uint64_t table_offset = meta_offset + blocks_clusters * s->cluster_size;
uint16_t *new_blocks = g_malloc0(blocks_clusters * s->cluster_size);
uint64_t *new_table = g_malloc0(table_size * sizeof(uint64_t));
assert(meta_offset >= (s->free_cluster_index * s->cluster_size));
/* Fill the new refcount table */
memcpy(new_table, s->refcount_table,
s->refcount_table_size * sizeof(uint64_t));
new_table[refcount_table_index] = new_block;
int i;
for (i = 0; i < blocks_clusters; i++) {
new_table[blocks_used + i] = meta_offset + (i * s->cluster_size);
}
/* Fill the refcount blocks */
uint64_t table_clusters = size_to_clusters(s, table_size * sizeof(uint64_t));
int block = 0;
for (i = 0; i < table_clusters + blocks_clusters; i++) {
new_blocks[block++] = cpu_to_be16(1);
}
/* Write refcount blocks to disk */
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS);
ret = bdrv_pwrite_sync(bs->file, meta_offset, new_blocks,
blocks_clusters * s->cluster_size);
g_free(new_blocks);
if (ret < 0) {
goto fail_table;
}
/* Write refcount table to disk */
for(i = 0; i < table_size; i++) {
cpu_to_be64s(&new_table[i]);
}
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE);
ret = bdrv_pwrite_sync(bs->file, table_offset, new_table,
table_size * sizeof(uint64_t));
if (ret < 0) {
goto fail_table;
}
for(i = 0; i < table_size; i++) {
cpu_to_be64s(&new_table[i]);
}
/* Hook up the new refcount table in the qcow2 header */
uint8_t data[12];
cpu_to_be64w((uint64_t*)data, table_offset);
cpu_to_be32w((uint32_t*)(data + 8), table_clusters);
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE);
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, refcount_table_offset),
data, sizeof(data));
if (ret < 0) {
goto fail_table;
}
/* And switch it in memory */
uint64_t old_table_offset = s->refcount_table_offset;
uint64_t old_table_size = s->refcount_table_size;
g_free(s->refcount_table);
s->refcount_table = new_table;
s->refcount_table_size = table_size;
s->refcount_table_offset = table_offset;
/* Free old table. Remember, we must not change free_cluster_index */
uint64_t old_free_cluster_index = s->free_cluster_index;
qcow2_free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t));
s->free_cluster_index = old_free_cluster_index;
ret = load_refcount_block(bs, new_block, (void**) refcount_block);
if (ret < 0) {
return ret;
}
return new_block;
fail_table:
g_free(new_table);
fail_block:
if (*refcount_block != NULL) {
qcow2_cache_put(bs, s->refcount_block_cache, (void**) refcount_block);
}
return ret;
}
| 14,434 |
qemu | a7812ae412311d7d47f8aa85656faadac9d64b56 | 0 | static always_inline void gen_qemu_stg (TCGv t0, TCGv t1, int flags)
{
TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
tcg_gen_helper_1_1(helper_g_to_memory, tmp, t0);
tcg_gen_qemu_st64(tmp, t1, flags);
tcg_temp_free(tmp);
}
| 14,435 |
qemu | 0b742797aaada3a2e243175a69d542d2ed997aac | 0 | static void test_qemu_strtosz_erange(void)
{
const char *str = "10E";
char *endptr = NULL;
int64_t res;
res = qemu_strtosz(str, &endptr);
g_assert_cmpint(res, ==, -ERANGE);
g_assert(endptr == str + 3);
}
| 14,436 |
qemu | 7285477ab11831b1cf56e45878a89170dd06d9b9 | 0 | static uint32_t scsi_init_iovec(SCSIDiskReq *r)
{
r->iov.iov_len = MIN(r->sector_count * 512, SCSI_DMA_BUF_SIZE);
qemu_iovec_init_external(&r->qiov, &r->iov, 1);
return r->qiov.size / 512;
}
| 14,437 |
FFmpeg | fd92dafaff8844b5fedf94679b93d953939a7f7b | 0 | static int read_dct_coeffs(BitstreamContext *bc, int32_t block[64],
const uint8_t *scan,
const int32_t quant_matrices[16][64], int q)
{
int coef_list[128];
int mode_list[128];
int i, t, bits, ccoef, mode;
int list_start = 64, list_end = 64, list_pos;
int coef_count = 0;
int coef_idx[64];
int quant_idx;
const int32_t *quant;
coef_list[list_end] = 4; mode_list[list_end++] = 0;
coef_list[list_end] = 24; mode_list[list_end++] = 0;
coef_list[list_end] = 44; mode_list[list_end++] = 0;
coef_list[list_end] = 1; mode_list[list_end++] = 3;
coef_list[list_end] = 2; mode_list[list_end++] = 3;
coef_list[list_end] = 3; mode_list[list_end++] = 3;
for (bits = bitstream_read(bc, 4) - 1; bits >= 0; bits--) {
list_pos = list_start;
while (list_pos < list_end) {
if (!(mode_list[list_pos] | coef_list[list_pos]) || !bitstream_read_bit(bc)) {
list_pos++;
continue;
}
ccoef = coef_list[list_pos];
mode = mode_list[list_pos];
switch (mode) {
case 0:
coef_list[list_pos] = ccoef + 4;
mode_list[list_pos] = 1;
case 2:
if (mode == 2) {
coef_list[list_pos] = 0;
mode_list[list_pos++] = 0;
}
for (i = 0; i < 4; i++, ccoef++) {
if (bitstream_read_bit(bc)) {
coef_list[--list_start] = ccoef;
mode_list[ list_start] = 3;
} else {
if (!bits) {
t = 1 - (bitstream_read_bit(bc) << 1);
} else {
t = bitstream_read(bc, bits) | 1 << bits;
t = bitstream_apply_sign(bc, t);
}
block[scan[ccoef]] = t;
coef_idx[coef_count++] = ccoef;
}
}
break;
case 1:
mode_list[list_pos] = 2;
for (i = 0; i < 3; i++) {
ccoef += 4;
coef_list[list_end] = ccoef;
mode_list[list_end++] = 2;
}
break;
case 3:
if (!bits) {
t = 1 - (bitstream_read_bit(bc) << 1);
} else {
t = bitstream_read(bc, bits) | 1 << bits;
t = bitstream_apply_sign(bc, t);
}
block[scan[ccoef]] = t;
coef_idx[coef_count++] = ccoef;
coef_list[list_pos] = 0;
mode_list[list_pos++] = 0;
break;
}
}
}
if (q == -1) {
quant_idx = bitstream_read(bc, 4);
} else {
quant_idx = q;
}
if (quant_idx >= 16)
return AVERROR_INVALIDDATA;
quant = quant_matrices[quant_idx];
block[0] = (block[0] * quant[0]) >> 11;
for (i = 0; i < coef_count; i++) {
int idx = coef_idx[i];
block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;
}
return 0;
}
| 14,438 |
qemu | 28f082469650a0f4c0e37b4ccd6f9514b1a0698d | 0 | bool qemu_co_queue_next(CoQueue *queue)
{
Coroutine *next;
next = QTAILQ_FIRST(&queue->entries);
if (next) {
QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
QTAILQ_INSERT_TAIL(&unlock_bh_queue, next, co_queue_next);
trace_qemu_co_queue_next(next);
qemu_bh_schedule(unlock_bh);
}
return (next != NULL);
}
| 14,439 |
FFmpeg | ee9f36a88eb3e2706ea659acb0ca80c414fa5d8a | 0 | static int nut_write_packet(AVFormatContext *s, int stream_index,
const uint8_t *buf, int size, int64_t pts)
{
NUTContext *nut = s->priv_data;
StreamContext *stream= &nut->stream[stream_index];
ByteIOContext *bc = &s->pb;
int key_frame = 0, full_pts=0;
AVCodecContext *enc;
int64_t lsb_pts, delta_pts;
int frame_type, best_length, frame_code, flags, i, size_mul, size_lsb;
const int64_t frame_start= url_ftell(bc);
if (stream_index > s->nb_streams)
return 1;
pts= (av_rescale(pts, stream->rate_num, stream->rate_den) + AV_TIME_BASE/2) / AV_TIME_BASE;
enc = &s->streams[stream_index]->codec;
key_frame = enc->coded_frame->key_frame;
delta_pts= pts - stream->last_pts;
frame_type=0;
if(frame_start + size + 20 - FFMAX(nut->last_frame_start[1], nut->last_frame_start[2]) > MAX_TYPE1_DISTANCE)
frame_type=1;
if(key_frame){
if(frame_type==1 && frame_start + size - nut->last_frame_start[2] > MAX_TYPE2_DISTANCE)
frame_type=2;
if(!stream->last_key_frame)
frame_type=2;
}
if(frame_type>0){
update_packetheader(nut, bc, 0);
reset(s);
full_pts=1;
}
//FIXME ensure that the timestamp can be represented by either delta or lsb or full_pts=1
lsb_pts = pts & ((1 << stream->msb_timestamp_shift)-1);
best_length=INT_MAX;
frame_code= -1;
for(i=0; i<256; i++){
int stream_id_plus1= nut->frame_code[i].stream_id_plus1;
int fc_key_frame= stream->last_key_frame;
int length=0;
size_mul= nut->frame_code[i].size_mul;
size_lsb= nut->frame_code[i].size_lsb;
flags= nut->frame_code[i].flags;
if(stream_id_plus1 == 0) length+= get_length(stream_index);
else if(stream_id_plus1 - 1 != stream_index)
continue;
if(flags & FLAG_PRED_KEY_FRAME){
if(flags & FLAG_KEY_FRAME)
fc_key_frame= !fc_key_frame;
}else{
fc_key_frame= !!(flags & FLAG_KEY_FRAME);
}
assert(key_frame==0 || key_frame==1);
if(fc_key_frame != key_frame)
continue;
if((!!(flags & FLAG_FRAME_TYPE)) != (frame_type > 0))
continue;
if(size_mul <= size_lsb){
int p= stream->lru_size[size_lsb - size_mul];
if(p != size)
continue;
}else{
if(size % size_mul != size_lsb)
continue;
if(flags & FLAG_DATA_SIZE)
length += get_length(size / size_mul);
else if(size/size_mul)
continue;
}
if(full_pts != ((flags & FLAG_PTS) && (flags & FLAG_FULL_PTS)))
continue;
if(flags&FLAG_PTS){
if(flags&FLAG_FULL_PTS){
length += get_length(pts);
}else{
length += get_length(lsb_pts);
}
}else{
int delta= stream->lru_pts_delta[(flags & 12)>>2];
if(delta != pts - stream->last_pts)
continue;
assert(frame_type == 0);
}
if(length < best_length){
best_length= length;
frame_code=i;
}
// av_log(s, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d %d %d\n", key_frame, frame_type, full_pts, size, stream_index, flags, size_mul, size_lsb, stream_id_plus1, length);
}
assert(frame_code != -1);
flags= nut->frame_code[frame_code].flags;
size_mul= nut->frame_code[frame_code].size_mul;
size_lsb= nut->frame_code[frame_code].size_lsb;
#if 0
best_length /= 7;
best_length ++; //frame_code
if(frame_type>0){
best_length += 4; //packet header
if(frame_type>1)
best_length += 8; // startcode
}
av_log(s, AV_LOG_DEBUG, "kf:%d ft:%d pt:%d fc:%2X len:%2d size:%d stream:%d flag:%d mul:%d lsb:%d s+1:%d pts_delta:%d\n", key_frame, frame_type, full_pts ? 2 : ((flags & FLAG_PTS) ? 1 : 0), frame_code, best_length, size, stream_index, flags, size_mul, size_lsb, nut->frame_code[frame_code].stream_id_plus1,(int)(pts - stream->last_pts));
#endif
if (frame_type==2)
put_be64(bc, KEYFRAME_STARTCODE);
put_byte(bc, frame_code);
if(frame_type>0)
put_packetheader(nut, bc, FFMAX(size+20, MAX_TYPE1_DISTANCE));
if(nut->frame_code[frame_code].stream_id_plus1 == 0)
put_v(bc, stream_index);
if (flags & FLAG_PTS){
if (flags & FLAG_FULL_PTS)
put_v(bc, pts);
else
put_v(bc, lsb_pts);
}
if(flags & FLAG_DATA_SIZE)
put_v(bc, size / size_mul);
if(size > MAX_TYPE1_DISTANCE){
assert(frame_type > 0);
update_packetheader(nut, bc, size);
}
put_buffer(bc, buf, size);
update(nut, stream_index, frame_start, frame_type, frame_code, key_frame, size, pts);
return 0;
}
| 14,440 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.