project
stringclasses 2
values | commit_id
stringlengths 40
40
| target
int64 0
1
| func
stringlengths 26
142k
| idx
int64 0
27.3k
|
---|---|---|---|---|
qemu | 01a720125f5e2f0a23d2682b39dead2fcc820066 | 1 | void helper_discard_movcal_backup(CPUSH4State *env)
{
memory_content *current = env->movcal_backup;
while(current)
{
memory_content *next = current->next;
free (current);
env->movcal_backup = current = next;
if (current == NULL)
env->movcal_backup_tail = &(env->movcal_backup);
}
}
| 4,423 |
qemu | 447b0d0b9ee8a0ac216c3186e0f3c427a1001f0c | 1 | static FlatView *address_space_get_flatview(AddressSpace *as)
{
FlatView *view;
rcu_read_lock();
view = atomic_rcu_read(&as->current_map);
flatview_ref(view);
rcu_read_unlock();
return view;
}
| 4,425 |
FFmpeg | 6e1a167c5564085385488b4f579e9efb987d4bfa | 1 | static int dx2_decode_slice_444(GetBitContext *gb, AVFrame *frame,
int line, int left,
uint8_t lru[3][8])
{
int x, y;
int width = frame->width;
int ystride = frame->linesize[0];
int ustride = frame->linesize[1];
int vstride = frame->linesize[2];
uint8_t *Y = frame->data[0] + ystride * line;
uint8_t *U = frame->data[1] + ustride * line;
uint8_t *V = frame->data[2] + vstride * line;
for (y = 0; y < left && get_bits_left(gb) > 16; y++) {
for (x = 0; x < width; x++) {
Y[x] = decode_sym(gb, lru[0]);
U[x] = decode_sym(gb, lru[1]) ^ 0x80;
V[x] = decode_sym(gb, lru[2]) ^ 0x80;
}
Y += ystride;
U += ustride;
V += vstride;
}
return y;
}
| 4,426 |
qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 | 1 | static size_t qemu_rdma_fill(RDMAContext *rdma, uint8_t *buf,
int size, int idx)
{
size_t len = 0;
if (rdma->wr_data[idx].control_len) {
DDDPRINTF("RDMA %" PRId64 " of %d bytes already in buffer\n",
rdma->wr_data[idx].control_len, size);
len = MIN(size, rdma->wr_data[idx].control_len);
memcpy(buf, rdma->wr_data[idx].control_curr, len);
rdma->wr_data[idx].control_curr += len;
rdma->wr_data[idx].control_len -= len;
}
return len;
}
| 4,428 |
FFmpeg | 4618637aca3b771b0bfb8fe15f3a080dacf9f0c0 | 1 | static void new_audio_stream(AVFormatContext *oc, int file_idx)
{
AVStream *st;
AVOutputStream *ost;
AVCodec *codec= NULL;
AVCodecContext *audio_enc;
enum CodecID codec_id;
st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
ffmpeg_exit(1);
}
ost = new_output_stream(oc, file_idx);
output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
if(!audio_stream_copy){
if (audio_codec_name) {
codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO, 1,
avcodec_opts[AVMEDIA_TYPE_AUDIO]->strict_std_compliance);
codec = avcodec_find_encoder_by_name(audio_codec_name);
output_codecs[nb_output_codecs-1] = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO);
codec = avcodec_find_encoder(codec_id);
}
}
avcodec_get_context_defaults3(st->codec, codec);
ost->bitstream_filters = audio_bitstream_filters;
audio_bitstream_filters= NULL;
avcodec_thread_init(st->codec, thread_count);
audio_enc = st->codec;
audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
if(audio_codec_tag)
audio_enc->codec_tag= audio_codec_tag;
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_opts[AVMEDIA_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
}
if (audio_stream_copy) {
st->stream_copy = 1;
audio_enc->channels = audio_channels;
audio_enc->sample_rate = audio_sample_rate;
} else {
audio_enc->codec_id = codec_id;
set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
if (audio_qscale > QSCALE_NONE) {
audio_enc->flags |= CODEC_FLAG_QSCALE;
audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
}
audio_enc->channels = audio_channels;
audio_enc->sample_fmt = audio_sample_fmt;
audio_enc->sample_rate = audio_sample_rate;
audio_enc->channel_layout = channel_layout;
if (av_get_channel_layout_nb_channels(channel_layout) != audio_channels)
audio_enc->channel_layout = 0;
choose_sample_fmt(st, codec);
choose_sample_rate(st, codec);
}
audio_enc->time_base= (AVRational){1, audio_sample_rate};
if (audio_language) {
av_metadata_set2(&st->metadata, "language", audio_language, 0);
av_freep(&audio_language);
}
/* reset some key parameters */
audio_disable = 0;
av_freep(&audio_codec_name);
audio_stream_copy = 0;
}
| 4,429 |
qemu | 185698715dfb18c82ad2a5dbc169908602d43e81 | 0 | uint32_t helper_efdctuf (uint64_t val)
{
CPU_DoubleU u;
float64 tmp;
u.ll = val;
/* NaN are not treated the same way IEEE 754 does */
if (unlikely(float64_is_nan(u.d)))
return 0;
tmp = uint64_to_float64(1ULL << 32, &env->vec_status);
u.d = float64_mul(u.d, tmp, &env->vec_status);
return float64_to_uint32(u.d, &env->vec_status);
}
| 4,430 |
qemu | bf937a7965c1d1a6dce4f615d0ead2e2ab505004 | 0 | static void bt_dummy_lmp_disconnect_master(struct bt_link_s *link)
{
fprintf(stderr, "%s: stray LMP_detach received, fixme\n", __func__);
exit(-1);
}
| 4,431 |
qemu | bd5c51ee6c4f1c79cae5ad2516d711a27b4ea8ec | 0 | static CharDriverState *qemu_chr_open_win_path(const char *filename)
{
CharDriverState *chr;
WinCharState *s;
chr = g_malloc0(sizeof(CharDriverState));
s = g_malloc0(sizeof(WinCharState));
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_close = win_chr_close;
if (win_chr_init(chr, filename) < 0) {
g_free(s);
g_free(chr);
return NULL;
}
qemu_chr_be_generic_open(chr);
return chr;
}
| 4,432 |
qemu | 4e256bef6552ee0b4c0c844077b44e4c7fcc05fc | 0 | void HELPER(pka)(CPUS390XState *env, uint64_t dest, uint64_t src,
uint32_t srclen)
{
uintptr_t ra = GETPC();
int i;
/* The destination operand is always 16 bytes long. */
const int destlen = 16;
/* The operands are processed from right to left. */
src += srclen - 1;
dest += destlen - 1;
for (i = 0; i < destlen; i++) {
uint8_t b = 0;
/* Start with a positive sign */
if (i == 0) {
b = 0xc;
} else if (srclen > 1) {
b = cpu_ldub_data_ra(env, src, ra) & 0x0f;
src--;
srclen--;
}
if (srclen > 1) {
b |= cpu_ldub_data_ra(env, src, ra) << 4;
src--;
srclen--;
}
cpu_stb_data_ra(env, dest, b, ra);
dest--;
}
}
| 4,433 |
qemu | fd56e0612b6454a282fa6a953fdb09281a98c589 | 0 | static void piix3_update_irq_levels(PIIX3State *piix3)
{
int pirq;
piix3->pic_levels = 0;
for (pirq = 0; pirq < PIIX_NUM_PIRQS; pirq++) {
piix3_set_irq_level(piix3, pirq,
pci_bus_get_irq_level(piix3->dev.bus, pirq));
}
}
| 4,434 |
qemu | f9aebe2ef52ff0dcb733999f57e00a7b430303c6 | 0 | static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
{
PCIDevice *s = container_of(pv, PCIDevice, config);
uint8_t *config;
int i;
assert(size == pci_config_size(s));
config = qemu_malloc(size);
qemu_get_buffer(f, config, size);
for (i = 0; i < size; ++i) {
if ((config[i] ^ s->config[i]) & s->cmask[i] & ~s->wmask[i]) {
qemu_free(config);
return -EINVAL;
}
}
memcpy(s->config, config, size);
pci_update_mappings(s);
qemu_free(config);
return 0;
}
| 4,435 |
FFmpeg | 2c69fcc2ffe671649e56dc981e9f4cd9d46a61be | 0 | static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t prefix, int length)
{
if(length > 32) {
av_log(NULL, AV_LOG_ERROR, "length too long\n");
return AVERROR_INVALIDDATA;
}
if(!get_bits1(gb)){ //Leaf
if(hc->current >= 256){
av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
return AVERROR_INVALIDDATA;
}
if(length){
hc->bits[hc->current] = prefix;
hc->lengths[hc->current] = length;
} else {
hc->bits[hc->current] = 0;
hc->lengths[hc->current] = 0;
}
hc->values[hc->current] = get_bits(gb, 8);
hc->current++;
if(hc->maxlength < length)
hc->maxlength = length;
return 0;
} else { //Node
int r;
length++;
r = smacker_decode_tree(gb, hc, prefix, length);
if(r)
return r;
return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length);
}
}
| 4,436 |
qemu | 891fb2cd4592b6fe76106a69e0ca40efbf82726a | 0 | static void usb_hub_handle_attach(USBDevice *dev)
{
USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
int i;
for (i = 0; i < NUM_PORTS; i++) {
usb_port_location(&s->ports[i].port, dev->port, i+1);
}
}
| 4,437 |
qemu | 4d68e86bb10159099da0798f74e7512955f15eec | 0 | static void __attribute__((destructor)) coroutine_pool_cleanup(void)
{
Coroutine *co;
Coroutine *tmp;
QSLIST_FOREACH_SAFE(co, &pool, pool_next, tmp) {
QSLIST_REMOVE_HEAD(&pool, pool_next);
qemu_coroutine_delete(co);
}
qemu_mutex_destroy(&pool_lock);
}
| 4,438 |
qemu | 7f61f4690dd153be98900a2a508b88989e692753 | 0 | pvscsi_on_cmd_setup_rings(PVSCSIState *s)
{
PVSCSICmdDescSetupRings *rc =
(PVSCSICmdDescSetupRings *) s->curr_cmd_data;
trace_pvscsi_on_cmd_arrived("PVSCSI_CMD_SETUP_RINGS");
pvscsi_dbg_dump_tx_rings_config(rc);
if (pvscsi_ring_init_data(&s->rings, rc) < 0) {
return PVSCSI_COMMAND_PROCESSING_FAILED;
}
s->rings_info_valid = TRUE;
return PVSCSI_COMMAND_PROCESSING_SUCCEEDED;
}
| 4,439 |
qemu | 0919ac787641db11024912651f3bc5764d4f1286 | 0 | static void omap1_mpu_reset(void *opaque)
{
struct omap_mpu_state_s *mpu = (struct omap_mpu_state_s *) opaque;
omap_inth_reset(mpu->ih[0]);
omap_inth_reset(mpu->ih[1]);
omap_dma_reset(mpu->dma);
omap_mpu_timer_reset(mpu->timer[0]);
omap_mpu_timer_reset(mpu->timer[1]);
omap_mpu_timer_reset(mpu->timer[2]);
omap_wd_timer_reset(mpu->wdt);
omap_os_timer_reset(mpu->os_timer);
omap_lcdc_reset(mpu->lcd);
omap_ulpd_pm_reset(mpu);
omap_pin_cfg_reset(mpu);
omap_mpui_reset(mpu);
omap_tipb_bridge_reset(mpu->private_tipb);
omap_tipb_bridge_reset(mpu->public_tipb);
omap_dpll_reset(&mpu->dpll[0]);
omap_dpll_reset(&mpu->dpll[1]);
omap_dpll_reset(&mpu->dpll[2]);
omap_uart_reset(mpu->uart[0]);
omap_uart_reset(mpu->uart[1]);
omap_uart_reset(mpu->uart[2]);
omap_mmc_reset(mpu->mmc);
omap_mpuio_reset(mpu->mpuio);
omap_uwire_reset(mpu->microwire);
omap_pwl_reset(mpu);
omap_pwt_reset(mpu);
omap_i2c_reset(mpu->i2c[0]);
omap_rtc_reset(mpu->rtc);
omap_mcbsp_reset(mpu->mcbsp1);
omap_mcbsp_reset(mpu->mcbsp2);
omap_mcbsp_reset(mpu->mcbsp3);
omap_lpg_reset(mpu->led[0]);
omap_lpg_reset(mpu->led[1]);
omap_clkm_reset(mpu);
cpu_reset(mpu->env);
}
| 4,441 |
qemu | b5302e1a9d8a47bd29a3e1876fba34be111728a2 | 0 | size_t slirp_socket_can_recv(struct in_addr guest_addr, int guest_port)
{
struct iovec iov[2];
struct socket *so;
if (!link_up)
return 0;
so = slirp_find_ctl_socket(guest_addr, guest_port);
if (!so || so->so_state & SS_NOFDREF)
return 0;
if (!CONN_CANFRCV(so) || so->so_snd.sb_cc >= (so->so_snd.sb_datalen/2))
return 0;
return sopreprbuf(so, iov, NULL);
}
| 4,444 |
qemu | e7c637967e6aad195b5f30cfd995913c9e0b4666 | 0 | static int bdrv_open_common(BlockDriverState *bs, const char *filename,
int flags, BlockDriver *drv)
{
int ret, open_flags;
assert(drv != NULL);
trace_bdrv_open_common(bs, filename, flags, drv->format_name);
bs->file = NULL;
bs->total_sectors = 0;
bs->encrypted = 0;
bs->valid_key = 0;
bs->open_flags = flags;
bs->buffer_alignment = 512;
pstrcpy(bs->filename, sizeof(bs->filename), filename);
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {
return -ENOTSUP;
}
bs->drv = drv;
bs->opaque = g_malloc0(drv->instance_size);
if (flags & BDRV_O_CACHE_WB)
bs->enable_write_cache = 1;
/*
* Clear flags that are internal to the block layer before opening the
* image.
*/
open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
/*
* Snapshots should be writable.
*/
if (bs->is_temporary) {
open_flags |= BDRV_O_RDWR;
}
/* Open the image, either directly or using a protocol */
if (drv->bdrv_file_open) {
ret = drv->bdrv_file_open(bs, filename, open_flags);
} else {
ret = bdrv_file_open(&bs->file, filename, open_flags);
if (ret >= 0) {
ret = drv->bdrv_open(bs, open_flags);
}
}
if (ret < 0) {
goto free_and_fail;
}
bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
ret = refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
goto free_and_fail;
}
#ifndef _WIN32
if (bs->is_temporary) {
unlink(filename);
}
#endif
return 0;
free_and_fail:
if (bs->file) {
bdrv_delete(bs->file);
bs->file = NULL;
}
g_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
return ret;
}
| 4,445 |
qemu | fae2afb10e3fdceab612c62a2b1e8b944ff578d9 | 0 | static void qxl_log_cmd_draw_copy(PCIQXLDevice *qxl, QXLCopy *copy, int group_id)
{
fprintf(stderr, " src %" PRIx64,
copy->src_bitmap);
qxl_log_image(qxl, copy->src_bitmap, group_id);
fprintf(stderr, " area");
qxl_log_rect(©->src_area);
fprintf(stderr, " rop %d", copy->rop_descriptor);
}
| 4,446 |
qemu | 8653c0158c23ec592f0041ab48b83d6cc6d152fe | 0 | int qemu_paio_cancel(int fd, struct qemu_paiocb *aiocb)
{
int ret;
pthread_mutex_lock(&lock);
if (!aiocb->active) {
TAILQ_REMOVE(&request_list, aiocb, node);
aiocb->ret = -ECANCELED;
ret = QEMU_PAIO_CANCELED;
} else if (aiocb->ret == -EINPROGRESS)
ret = QEMU_PAIO_NOTCANCELED;
else
ret = QEMU_PAIO_ALLDONE;
pthread_mutex_unlock(&lock);
return ret;
}
| 4,448 |
qemu | 024a6fbdb9d8cbc4d7f833b23db51c9d1004bc47 | 0 | int qdev_unplug(DeviceState *dev)
{
if (!dev->parent_bus->allow_hotplug) {
qerror_report(QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
return -1;
}
assert(dev->info->unplug != NULL);
if (dev->ref != 0) {
qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
return -1;
}
qdev_hot_removed = true;
return dev->info->unplug(dev);
}
| 4,449 |
qemu | 88c725c78e87eecb061f882177c7a6a2ac1059ad | 0 | int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
PCIDevice *dev)
{
struct kvm_irq_routing_entry kroute = {};
if (kvm_gsi_direct_mapping()) {
return 0;
}
if (!kvm_irqchip_in_kernel()) {
return -ENOSYS;
}
kroute.gsi = virq;
kroute.type = KVM_IRQ_ROUTING_MSI;
kroute.flags = 0;
kroute.u.msi.address_lo = (uint32_t)msg.address;
kroute.u.msi.address_hi = msg.address >> 32;
kroute.u.msi.data = le32_to_cpu(msg.data);
if (kvm_msi_devid_required()) {
kroute.flags = KVM_MSI_VALID_DEVID;
kroute.u.msi.devid = pci_requester_id(dev);
}
if (kvm_arch_fixup_msi_route(&kroute, msg.address, msg.data, dev)) {
return -EINVAL;
}
trace_kvm_irqchip_update_msi_route(virq);
return kvm_update_routing_entry(s, &kroute);
}
| 4,450 |
qemu | b40acf99bef69fa8ab0f9092ff162fde945eec12 | 0 | static const MemoryRegionPortio *find_portio(MemoryRegion *mr, uint64_t offset,
unsigned width, bool write)
{
const MemoryRegionPortio *mrp;
for (mrp = mr->ops->old_portio; mrp->size; ++mrp) {
if (offset >= mrp->offset && offset < mrp->offset + mrp->len
&& width == mrp->size
&& (write ? (bool)mrp->write : (bool)mrp->read)) {
return mrp;
}
}
return NULL;
}
| 4,451 |
qemu | 7f6613cedc59fa849105668ae971dc31004bca1c | 0 | static void gen_mftr(CPUMIPSState *env, DisasContext *ctx, int rt, int rd,
int u, int sel, int h)
{
int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
TCGv t0 = tcg_temp_local_new();
if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
(env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
tcg_gen_movi_tl(t0, -1);
else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
(env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
tcg_gen_movi_tl(t0, -1);
else if (u == 0) {
switch (rt) {
case 1:
switch (sel) {
case 1:
gen_helper_mftc0_vpecontrol(t0, cpu_env);
break;
case 2:
gen_helper_mftc0_vpeconf0(t0, cpu_env);
break;
default:
goto die;
break;
}
break;
case 2:
switch (sel) {
case 1:
gen_helper_mftc0_tcstatus(t0, cpu_env);
break;
case 2:
gen_helper_mftc0_tcbind(t0, cpu_env);
break;
case 3:
gen_helper_mftc0_tcrestart(t0, cpu_env);
break;
case 4:
gen_helper_mftc0_tchalt(t0, cpu_env);
break;
case 5:
gen_helper_mftc0_tccontext(t0, cpu_env);
break;
case 6:
gen_helper_mftc0_tcschedule(t0, cpu_env);
break;
case 7:
gen_helper_mftc0_tcschefback(t0, cpu_env);
break;
default:
gen_mfc0(ctx, t0, rt, sel);
break;
}
break;
case 10:
switch (sel) {
case 0:
gen_helper_mftc0_entryhi(t0, cpu_env);
break;
default:
gen_mfc0(ctx, t0, rt, sel);
break;
}
case 12:
switch (sel) {
case 0:
gen_helper_mftc0_status(t0, cpu_env);
break;
default:
gen_mfc0(ctx, t0, rt, sel);
break;
}
case 13:
switch (sel) {
case 0:
gen_helper_mftc0_cause(t0, cpu_env);
break;
default:
goto die;
break;
}
break;
case 14:
switch (sel) {
case 0:
gen_helper_mftc0_epc(t0, cpu_env);
break;
default:
goto die;
break;
}
break;
case 15:
switch (sel) {
case 1:
gen_helper_mftc0_ebase(t0, cpu_env);
break;
default:
goto die;
break;
}
break;
case 16:
switch (sel) {
case 0 ... 7:
gen_helper_mftc0_configx(t0, cpu_env, tcg_const_tl(sel));
break;
default:
goto die;
break;
}
break;
case 23:
switch (sel) {
case 0:
gen_helper_mftc0_debug(t0, cpu_env);
break;
default:
gen_mfc0(ctx, t0, rt, sel);
break;
}
break;
default:
gen_mfc0(ctx, t0, rt, sel);
}
} else switch (sel) {
/* GPR registers. */
case 0:
gen_helper_1e0i(mftgpr, t0, rt);
break;
/* Auxiliary CPU registers */
case 1:
switch (rt) {
case 0:
gen_helper_1e0i(mftlo, t0, 0);
break;
case 1:
gen_helper_1e0i(mfthi, t0, 0);
break;
case 2:
gen_helper_1e0i(mftacx, t0, 0);
break;
case 4:
gen_helper_1e0i(mftlo, t0, 1);
break;
case 5:
gen_helper_1e0i(mfthi, t0, 1);
break;
case 6:
gen_helper_1e0i(mftacx, t0, 1);
break;
case 8:
gen_helper_1e0i(mftlo, t0, 2);
break;
case 9:
gen_helper_1e0i(mfthi, t0, 2);
break;
case 10:
gen_helper_1e0i(mftacx, t0, 2);
break;
case 12:
gen_helper_1e0i(mftlo, t0, 3);
break;
case 13:
gen_helper_1e0i(mfthi, t0, 3);
break;
case 14:
gen_helper_1e0i(mftacx, t0, 3);
break;
case 16:
gen_helper_mftdsp(t0, cpu_env);
break;
default:
goto die;
}
break;
/* Floating point (COP1). */
case 2:
/* XXX: For now we support only a single FPU context. */
if (h == 0) {
TCGv_i32 fp0 = tcg_temp_new_i32();
gen_load_fpr32(fp0, rt);
tcg_gen_ext_i32_tl(t0, fp0);
tcg_temp_free_i32(fp0);
} else {
TCGv_i32 fp0 = tcg_temp_new_i32();
gen_load_fpr32h(fp0, rt);
tcg_gen_ext_i32_tl(t0, fp0);
tcg_temp_free_i32(fp0);
}
break;
case 3:
/* XXX: For now we support only a single FPU context. */
gen_helper_1e0i(cfc1, t0, rt);
break;
/* COP2: Not implemented. */
case 4:
case 5:
/* fall through */
default:
goto die;
}
LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
gen_store_gpr(t0, rd);
tcg_temp_free(t0);
return;
die:
tcg_temp_free(t0);
LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
generate_exception(ctx, EXCP_RI);
}
| 4,452 |
qemu | ad674e53b5cce265fadafbde2c6a4f190345cd00 | 0 | static void dbdma_cmdptr_save(DBDMA_channel *ch)
{
DBDMA_DPRINTF("dbdma_cmdptr_save 0x%08x\n",
be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]));
DBDMA_DPRINTF("xfer_status 0x%08x res_count 0x%04x\n",
le16_to_cpu(ch->current.xfer_status),
le16_to_cpu(ch->current.res_count));
cpu_physical_memory_write(be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]),
(uint8_t*)&ch->current, sizeof(dbdma_cmd));
}
| 4,453 |
qemu | 2374e73edafff0586cbfb67c333c5a7588f81fd5 | 0 | void helper_ldl_raw(uint64_t t0, uint64_t t1)
{
ldl_raw(t1, t0);
}
| 4,454 |
qemu | ba9bc59e1f5dc91caf35e0ef08da137b3a5e7386 | 0 | uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
uint32_t index, int reg)
{
struct kvm_cpuid2 *cpuid;
int i, max;
uint32_t ret = 0;
uint32_t cpuid_1_edx;
int has_kvm_features = 0;
max = 1;
while ((cpuid = try_get_cpuid(env->kvm_state, max)) == NULL) {
max *= 2;
}
for (i = 0; i < cpuid->nent; ++i) {
if (cpuid->entries[i].function == function &&
cpuid->entries[i].index == index) {
if (cpuid->entries[i].function == KVM_CPUID_FEATURES) {
has_kvm_features = 1;
}
switch (reg) {
case R_EAX:
ret = cpuid->entries[i].eax;
break;
case R_EBX:
ret = cpuid->entries[i].ebx;
break;
case R_ECX:
ret = cpuid->entries[i].ecx;
break;
case R_EDX:
ret = cpuid->entries[i].edx;
switch (function) {
case 1:
/* KVM before 2.6.30 misreports the following features */
ret |= CPUID_MTRR | CPUID_PAT | CPUID_MCE | CPUID_MCA;
break;
case 0x80000001:
/* On Intel, kvm returns cpuid according to the Intel spec,
* so add missing bits according to the AMD spec:
*/
cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX);
ret |= cpuid_1_edx & 0x183f7ff;
break;
}
break;
}
}
}
qemu_free(cpuid);
/* fallback for older kernels */
if (!has_kvm_features && (function == KVM_CPUID_FEATURES)) {
ret = get_para_features(env);
}
return ret;
}
| 4,455 |
qemu | e7d336959b7c01699702dcda4b54a822972d74a8 | 0 | int chsc_sei_nt2_have_event(void)
{
S390pciState *s = S390_PCI_HOST_BRIDGE(
object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE, NULL));
if (!s) {
return 0;
}
return !QTAILQ_EMPTY(&s->pending_sei);
}
| 4,456 |
qemu | 355b194369d02df7a97d554eef2a9cffe98d736f | 0 | static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
int opc)
{
int addr_regl, addr_reg1, addr_meml;
int data_regl, data_regh, data_reg1, data_reg2;
int mem_index, s_bits;
#if defined(CONFIG_SOFTMMU)
uint8_t *label1_ptr, *label2_ptr;
int sp_args;
#endif
#if TARGET_LONG_BITS == 64
# if defined(CONFIG_SOFTMMU)
uint8_t *label3_ptr;
# endif
int addr_regh, addr_reg2, addr_memh;
#endif
data_regl = *args++;
if (opc == 3) {
data_regh = *args++;
#if defined(TCG_TARGET_WORDS_BIGENDIAN)
data_reg1 = data_regh;
data_reg2 = data_regl;
#else
data_reg1 = data_regl;
data_reg2 = data_regh;
#endif
} else {
data_reg1 = data_regl;
data_reg2 = 0;
data_regh = 0;
}
addr_regl = *args++;
#if TARGET_LONG_BITS == 64
addr_regh = *args++;
# if defined(TCG_TARGET_WORDS_BIGENDIAN)
addr_reg1 = addr_regh;
addr_reg2 = addr_regl;
addr_memh = 0;
addr_meml = 4;
# else
addr_reg1 = addr_regl;
addr_reg2 = addr_regh;
addr_memh = 4;
addr_meml = 0;
# endif
#else
addr_reg1 = addr_regl;
addr_meml = 0;
#endif
mem_index = *args;
s_bits = opc;
#if defined(CONFIG_SOFTMMU)
tcg_out_opc_sa(s, OPC_SRL, TCG_REG_A0, addr_regl, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS);
tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_A0, TCG_REG_A0, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_A0, TCG_REG_A0, TCG_AREG0);
tcg_out_opc_imm(s, OPC_LW, TCG_REG_AT, TCG_REG_A0,
offsetof(CPUState, tlb_table[mem_index][0].addr_write) + addr_meml);
tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T0, TARGET_PAGE_MASK | ((1 << s_bits) - 1));
tcg_out_opc_reg(s, OPC_AND, TCG_REG_T0, TCG_REG_T0, addr_regl);
# if TARGET_LONG_BITS == 64
label3_ptr = s->code_ptr;
tcg_out_opc_br(s, OPC_BNE, TCG_REG_T0, TCG_REG_AT);
tcg_out_nop(s);
tcg_out_opc_imm(s, OPC_LW, TCG_REG_AT, TCG_REG_A0,
offsetof(CPUState, tlb_table[mem_index][0].addr_write) + addr_memh);
label1_ptr = s->code_ptr;
tcg_out_opc_br(s, OPC_BEQ, addr_regh, TCG_REG_AT);
tcg_out_nop(s);
reloc_pc16(label3_ptr, (tcg_target_long) s->code_ptr);
# else
label1_ptr = s->code_ptr;
tcg_out_opc_br(s, OPC_BEQ, TCG_REG_T0, TCG_REG_AT);
tcg_out_nop(s);
# endif
/* slow path */
sp_args = TCG_REG_A0;
tcg_out_mov(s, sp_args++, addr_reg1);
# if TARGET_LONG_BITS == 64
tcg_out_mov(s, sp_args++, addr_reg2);
# endif
switch(opc) {
case 0:
tcg_out_opc_imm(s, OPC_ANDI, sp_args++, data_reg1, 0xff);
break;
case 1:
tcg_out_opc_imm(s, OPC_ANDI, sp_args++, data_reg1, 0xffff);
break;
case 2:
tcg_out_mov(s, sp_args++, data_reg1);
break;
case 3:
sp_args = (sp_args + 1) & ~1;
tcg_out_mov(s, sp_args++, data_reg1);
tcg_out_mov(s, sp_args++, data_reg2);
break;
default:
tcg_abort();
}
if (sp_args > TCG_REG_A3) {
/* Push mem_index on the stack */
tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_AT, mem_index);
tcg_out_st(s, TCG_TYPE_I32, TCG_REG_AT, TCG_REG_SP, 16);
} else {
tcg_out_movi(s, TCG_TYPE_I32, sp_args, mem_index);
}
tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T9, (tcg_target_long)qemu_st_helpers[s_bits]);
tcg_out_opc_reg(s, OPC_JALR, TCG_REG_RA, TCG_REG_T9, 0);
tcg_out_nop(s);
label2_ptr = s->code_ptr;
tcg_out_opc_br(s, OPC_BEQ, TCG_REG_ZERO, TCG_REG_ZERO);
tcg_out_nop(s);
/* label1: fast path */
reloc_pc16(label1_ptr, (tcg_target_long) s->code_ptr);
tcg_out_opc_imm(s, OPC_LW, TCG_REG_A0, TCG_REG_A0,
offsetof(CPUState, tlb_table[mem_index][0].addend) + addr_meml);
tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_A0, TCG_REG_A0, addr_regl);
#else
if (GUEST_BASE == (int16_t)GUEST_BASE) {
tcg_out_opc_imm(s, OPC_ADDIU, TCG_REG_A0, addr_reg1, GUEST_BASE);
} else {
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_A0, GUEST_BASE);
tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_A0, TCG_REG_A0, addr_reg1);
}
#endif
switch(opc) {
case 0:
tcg_out_opc_imm(s, OPC_SB, data_reg1, TCG_REG_A0, 0);
break;
case 1:
if (TCG_NEED_BSWAP) {
tcg_out_bswap16(s, TCG_REG_T0, data_reg1);
tcg_out_opc_imm(s, OPC_SH, TCG_REG_T0, TCG_REG_A0, 0);
} else {
tcg_out_opc_imm(s, OPC_SH, data_reg1, TCG_REG_A0, 0);
}
break;
case 2:
if (TCG_NEED_BSWAP) {
tcg_out_bswap32(s, TCG_REG_T0, data_reg1);
tcg_out_opc_imm(s, OPC_SW, TCG_REG_T0, TCG_REG_A0, 0);
} else {
tcg_out_opc_imm(s, OPC_SW, data_reg1, TCG_REG_A0, 0);
}
break;
case 3:
if (TCG_NEED_BSWAP) {
tcg_out_bswap32(s, TCG_REG_T0, data_reg2);
tcg_out_opc_imm(s, OPC_SW, TCG_REG_T0, TCG_REG_A0, 0);
tcg_out_bswap32(s, TCG_REG_T0, data_reg1);
tcg_out_opc_imm(s, OPC_SW, TCG_REG_T0, TCG_REG_A0, 4);
} else {
tcg_out_opc_imm(s, OPC_SW, data_reg1, TCG_REG_A0, 0);
tcg_out_opc_imm(s, OPC_SW, data_reg2, TCG_REG_A0, 4);
}
break;
default:
tcg_abort();
}
#if defined(CONFIG_SOFTMMU)
reloc_pc16(label2_ptr, (tcg_target_long) s->code_ptr);
#endif
}
| 4,457 |
FFmpeg | d1adad3cca407f493c3637e20ecd4f7124e69212 | 0 | static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
{
#if COMPILE_TEMPLATE_MMX
__asm__ volatile(
"movq "MANGLE(bm01010101)", %%mm4 \n\t"
"mov %0, %%"REG_a" \n\t"
"1: \n\t"
"movq (%1, %%"REG_a",2), %%mm0 \n\t"
"movq 8(%1, %%"REG_a",2), %%mm1 \n\t"
"movq (%2, %%"REG_a",2), %%mm2 \n\t"
"movq 8(%2, %%"REG_a",2), %%mm3 \n\t"
"pand %%mm4, %%mm0 \n\t"
"pand %%mm4, %%mm1 \n\t"
"pand %%mm4, %%mm2 \n\t"
"pand %%mm4, %%mm3 \n\t"
"packuswb %%mm1, %%mm0 \n\t"
"packuswb %%mm3, %%mm2 \n\t"
"movq %%mm0, (%3, %%"REG_a") \n\t"
"movq %%mm2, (%4, %%"REG_a") \n\t"
"add $8, %%"REG_a" \n\t"
" js 1b \n\t"
: : "g" ((x86_reg)-width), "r" (src1+width*2), "r" (src2+width*2), "r" (dstU+width), "r" (dstV+width)
: "%"REG_a
);
#else
int i;
for (i=0; i<width; i++) {
dstU[i]= src1[2*i];
dstV[i]= src2[2*i];
}
#endif
}
| 4,458 |
qemu | c39ce112b60ffafbaf700853e32bea74cbb2c148 | 0 | static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
{
MSDState *s = (MSDState *)dev;
int ret = 0;
struct usb_msd_cbw cbw;
uint8_t devep = p->devep;
switch (p->pid) {
case USB_TOKEN_OUT:
if (devep != 2)
goto fail;
switch (s->mode) {
case USB_MSDM_CBW:
if (p->iov.size != 31) {
fprintf(stderr, "usb-msd: Bad CBW size");
goto fail;
}
usb_packet_copy(p, &cbw, 31);
if (le32_to_cpu(cbw.sig) != 0x43425355) {
fprintf(stderr, "usb-msd: Bad signature %08x\n",
le32_to_cpu(cbw.sig));
goto fail;
}
DPRINTF("Command on LUN %d\n", cbw.lun);
if (cbw.lun != 0) {
fprintf(stderr, "usb-msd: Bad LUN %d\n", cbw.lun);
goto fail;
}
s->tag = le32_to_cpu(cbw.tag);
s->data_len = le32_to_cpu(cbw.data_len);
if (s->data_len == 0) {
s->mode = USB_MSDM_CSW;
} else if (cbw.flags & 0x80) {
s->mode = USB_MSDM_DATAIN;
} else {
s->mode = USB_MSDM_DATAOUT;
}
DPRINTF("Command tag 0x%x flags %08x len %d data %d\n",
s->tag, cbw.flags, cbw.cmd_len, s->data_len);
s->residue = 0;
s->scsi_len = 0;
s->req = scsi_req_new(s->scsi_dev, s->tag, 0, NULL);
scsi_req_enqueue(s->req, cbw.cmd);
/* ??? Should check that USB and SCSI data transfer
directions match. */
if (s->mode != USB_MSDM_CSW && s->residue == 0) {
scsi_req_continue(s->req);
}
ret = p->result;
break;
case USB_MSDM_DATAOUT:
DPRINTF("Data out %zd/%d\n", p->iov.size, s->data_len);
if (p->iov.size > s->data_len) {
goto fail;
}
if (s->scsi_len) {
usb_msd_copy_data(s, p);
}
if (s->residue) {
int len = p->iov.size - p->result;
if (len) {
usb_packet_skip(p, len);
s->data_len -= len;
if (s->data_len == 0) {
s->mode = USB_MSDM_CSW;
}
}
}
if (p->result < p->iov.size) {
DPRINTF("Deferring packet %p\n", p);
s->packet = p;
ret = USB_RET_ASYNC;
} else {
ret = p->result;
}
break;
default:
DPRINTF("Unexpected write (len %zd)\n", p->iov.size);
goto fail;
}
break;
case USB_TOKEN_IN:
if (devep != 1)
goto fail;
switch (s->mode) {
case USB_MSDM_DATAOUT:
if (s->data_len != 0 || p->iov.size < 13) {
goto fail;
}
/* Waiting for SCSI write to complete. */
s->packet = p;
ret = USB_RET_ASYNC;
break;
case USB_MSDM_CSW:
DPRINTF("Command status %d tag 0x%x, len %zd\n",
s->result, s->tag, p->iov.size);
if (p->iov.size < 13) {
goto fail;
}
usb_msd_send_status(s, p);
s->mode = USB_MSDM_CBW;
ret = 13;
break;
case USB_MSDM_DATAIN:
DPRINTF("Data in %zd/%d, scsi_len %d\n",
p->iov.size, s->data_len, s->scsi_len);
if (s->scsi_len) {
usb_msd_copy_data(s, p);
}
if (s->residue) {
int len = p->iov.size - p->result;
if (len) {
usb_packet_skip(p, len);
s->data_len -= len;
if (s->data_len == 0) {
s->mode = USB_MSDM_CSW;
}
}
}
if (p->result < p->iov.size) {
DPRINTF("Deferring packet %p\n", p);
s->packet = p;
ret = USB_RET_ASYNC;
} else {
ret = p->result;
}
break;
default:
DPRINTF("Unexpected read (len %zd)\n", p->iov.size);
goto fail;
}
break;
default:
DPRINTF("Bad token\n");
fail:
ret = USB_RET_STALL;
break;
}
return ret;
}
| 4,459 |
qemu | 08fba7ac9b618516a5f1d096f78a7e2837fe0594 | 0 | static bool main_loop_should_exit(void)
{
RunState r;
ShutdownCause request;
if (qemu_debug_requested()) {
vm_stop(RUN_STATE_DEBUG);
}
if (qemu_suspend_requested()) {
qemu_system_suspend();
}
request = qemu_shutdown_requested();
if (request) {
qemu_kill_report();
/* TODO update event based on request */
qapi_event_send_shutdown(&error_abort);
if (no_shutdown) {
vm_stop(RUN_STATE_SHUTDOWN);
} else {
return true;
}
}
request = qemu_reset_requested();
if (request) {
pause_all_vcpus();
qemu_system_reset(request);
resume_all_vcpus();
if (!runstate_check(RUN_STATE_RUNNING) &&
!runstate_check(RUN_STATE_INMIGRATE)) {
runstate_set(RUN_STATE_PRELAUNCH);
}
}
if (qemu_wakeup_requested()) {
pause_all_vcpus();
qemu_system_reset(SHUTDOWN_CAUSE_NONE);
notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
wakeup_reason = QEMU_WAKEUP_REASON_NONE;
resume_all_vcpus();
qapi_event_send_wakeup(&error_abort);
}
if (qemu_powerdown_requested()) {
qemu_system_powerdown();
}
if (qemu_vmstop_requested(&r)) {
vm_stop(r);
}
return false;
}
| 4,460 |
qemu | 17444c9c84fd0c8679499198fd4ee3b155fb297f | 0 | soread(so)
struct socket *so;
{
int n, nn, lss, total;
struct sbuf *sb = &so->so_snd;
int len = sb->sb_datalen - sb->sb_cc;
struct iovec iov[2];
int mss = so->so_tcpcb->t_maxseg;
DEBUG_CALL("soread");
DEBUG_ARG("so = %lx", (long )so);
/*
* No need to check if there's enough room to read.
* soread wouldn't have been called if there weren't
*/
len = sb->sb_datalen - sb->sb_cc;
iov[0].iov_base = sb->sb_wptr;
if (sb->sb_wptr < sb->sb_rptr) {
iov[0].iov_len = sb->sb_rptr - sb->sb_wptr;
/* Should never succeed, but... */
if (iov[0].iov_len > len)
iov[0].iov_len = len;
if (iov[0].iov_len > mss)
iov[0].iov_len -= iov[0].iov_len%mss;
n = 1;
} else {
iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr;
/* Should never succeed, but... */
if (iov[0].iov_len > len) iov[0].iov_len = len;
len -= iov[0].iov_len;
if (len) {
iov[1].iov_base = sb->sb_data;
iov[1].iov_len = sb->sb_rptr - sb->sb_data;
if(iov[1].iov_len > len)
iov[1].iov_len = len;
total = iov[0].iov_len + iov[1].iov_len;
if (total > mss) {
lss = total%mss;
if (iov[1].iov_len > lss) {
iov[1].iov_len -= lss;
n = 2;
} else {
lss -= iov[1].iov_len;
iov[0].iov_len -= lss;
n = 1;
}
} else
n = 2;
} else {
if (iov[0].iov_len > mss)
iov[0].iov_len -= iov[0].iov_len%mss;
n = 1;
}
}
#ifdef HAVE_READV
nn = readv(so->s, (struct iovec *)iov, n);
DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
#else
nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
#endif
if (nn <= 0) {
if (nn < 0 && (errno == EINTR || errno == EAGAIN))
return 0;
else {
DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
sofcantrcvmore(so);
tcp_sockclosed(sototcpcb(so));
return -1;
}
}
#ifndef HAVE_READV
/*
* If there was no error, try and read the second time round
* We read again if n = 2 (ie, there's another part of the buffer)
* and we read as much as we could in the first read
* We don't test for <= 0 this time, because there legitimately
* might not be any more data (since the socket is non-blocking),
* a close will be detected on next iteration.
* A return of -1 wont (shouldn't) happen, since it didn't happen above
*/
if (n == 2 && nn == iov[0].iov_len)
nn += recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
#endif
/* Update fields */
sb->sb_cc += nn;
sb->sb_wptr += nn;
if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen))
sb->sb_wptr -= sb->sb_datalen;
return nn;
}
| 4,462 |
qemu | 64607d088132abdb25bf30d93e97d0c8df7b364c | 0 | static inline bool object_property_is_link(ObjectProperty *prop)
{
return strstart(prop->type, "link<", NULL);
}
| 4,463 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static uint64_t mpcore_scu_read(void *opaque, target_phys_addr_t offset,
unsigned size)
{
mpcore_priv_state *s = (mpcore_priv_state *)opaque;
int id;
/* SCU */
switch (offset) {
case 0x00: /* Control. */
return s->scu_control;
case 0x04: /* Configuration. */
id = ((1 << s->num_cpu) - 1) << 4;
return id | (s->num_cpu - 1);
case 0x08: /* CPU status. */
return 0;
case 0x0c: /* Invalidate all. */
return 0;
default:
hw_error("mpcore_priv_read: Bad offset %x\n", (int)offset);
}
}
| 4,464 |
FFmpeg | d712a5cddbfc12e21384f97a291aa64ea7e8005f | 1 | static int64_t run_opencl_bench(AVOpenCLExternalEnv *ext_opencl_env)
{
int i, arg = 0, width = 1920, height = 1088;
int64_t start, ret = 0;
cl_int status;
size_t kernel_len;
char *inbuf;
int *mask;
int buf_size = width * height * sizeof(char);
int mask_size = sizeof(uint32_t) * 128;
cl_mem cl_mask, cl_inbuf, cl_outbuf;
cl_kernel kernel = NULL;
cl_program program = NULL;
size_t local_work_size_2d[2] = {16, 16};
size_t global_work_size_2d[2] = {(size_t)width, (size_t)height};
if (!(inbuf = av_malloc(buf_size)) || !(mask = av_malloc(mask_size))) {
av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
ret = AVERROR(ENOMEM);
goto end;
}
fill_rand_int((int*)inbuf, buf_size/4);
fill_rand_int(mask, mask_size/4);
CREATEBUF(cl_mask, CL_MEM_READ_ONLY, mask_size);
CREATEBUF(cl_inbuf, CL_MEM_READ_ONLY, buf_size);
CREATEBUF(cl_outbuf, CL_MEM_READ_WRITE, buf_size);
kernel_len = strlen(ocl_bench_source);
program = clCreateProgramWithSource(ext_opencl_env->context, 1, &ocl_bench_source,
&kernel_len, &status);
if (status != CL_SUCCESS || !program) {
av_log(NULL, AV_LOG_ERROR, "OpenCL unable to create benchmark program\n");
ret = AVERROR_EXTERNAL;
goto end;
}
status = clBuildProgram(program, 1, &(ext_opencl_env->device_id), NULL, NULL, NULL);
if (status != CL_SUCCESS) {
av_log(NULL, AV_LOG_ERROR, "OpenCL unable to build benchmark program\n");
ret = AVERROR_EXTERNAL;
goto end;
}
kernel = clCreateKernel(program, "unsharp_bench", &status);
if (status != CL_SUCCESS) {
av_log(NULL, AV_LOG_ERROR, "OpenCL unable to create benchmark kernel\n");
ret = AVERROR_EXTERNAL;
goto end;
}
OCLCHECK(clEnqueueWriteBuffer, ext_opencl_env->command_queue, cl_inbuf, CL_TRUE, 0,
buf_size, inbuf, 0, NULL, NULL);
OCLCHECK(clEnqueueWriteBuffer, ext_opencl_env->command_queue, cl_mask, CL_TRUE, 0,
mask_size, mask, 0, NULL, NULL);
OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_inbuf);
OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_outbuf);
OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_mask);
OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_int), &width);
OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_int), &height);
start = av_gettime_relative();
for (i = 0; i < OPENCL_NB_ITER; i++)
OCLCHECK(clEnqueueNDRangeKernel, ext_opencl_env->command_queue, kernel, 2, NULL,
global_work_size_2d, local_work_size_2d, 0, NULL, NULL);
clFinish(ext_opencl_env->command_queue);
ret = (av_gettime_relative() - start)/OPENCL_NB_ITER;
end:
if (kernel)
clReleaseKernel(kernel);
if (program)
clReleaseProgram(program);
if (cl_inbuf)
clReleaseMemObject(cl_inbuf);
if (cl_outbuf)
clReleaseMemObject(cl_outbuf);
if (cl_mask)
clReleaseMemObject(cl_mask);
av_free(inbuf);
av_free(mask);
return ret;
}
| 4,465 |
qemu | f35bde2f8fb55541d4d7ddca50d64ce5a6ef384c | 1 | static int local_symlink(FsContext *fs_ctx, const char *oldpath,
const char *newpath, FsCred *credp)
{
int err = -1;
int serrno = 0;
/* Determine the security model */
if (fs_ctx->fs_sm == SM_MAPPED) {
int fd;
ssize_t oldpath_size, write_size;
fd = open(rpath(fs_ctx, newpath), O_CREAT|O_EXCL|O_RDWR,
SM_LOCAL_MODE_BITS);
if (fd == -1) {
return fd;
}
/* Write the oldpath (target) to the file. */
oldpath_size = strlen(oldpath) + 1;
do {
write_size = write(fd, (void *)oldpath, oldpath_size);
} while (write_size == -1 && errno == EINTR);
if (write_size != oldpath_size) {
serrno = errno;
close(fd);
err = -1;
goto err_end;
}
close(fd);
/* Set cleint credentials in symlink's xattr */
credp->fc_mode = credp->fc_mode|S_IFLNK;
err = local_set_xattr(rpath(fs_ctx, newpath), credp);
if (err == -1) {
serrno = errno;
goto err_end;
}
} else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) ||
(fs_ctx->fs_sm == SM_NONE)) {
err = symlink(oldpath, rpath(fs_ctx, newpath));
if (err) {
return err;
}
err = lchown(rpath(fs_ctx, newpath), credp->fc_uid, credp->fc_gid);
if (err == -1) {
/*
* If we fail to change ownership and if we are
* using security model none. Ignore the error
*/
if (fs_ctx->fs_sm != SM_NONE) {
serrno = errno;
goto err_end;
} else
err = 0;
}
}
return err;
err_end:
remove(rpath(fs_ctx, newpath));
errno = serrno;
return err;
}
| 4,466 |
FFmpeg | e3f13d3a87274d537d319a84e9104f44f84ec3b2 | 1 | static int parse_strk(AVFormatContext *s,
FourxmDemuxContext *fourxm, uint8_t *buf, int size,
int left)
{
AVStream *st;
int track;
/* check that there is enough data */
if (size != strk_SIZE || left < size + 8)
return AVERROR_INVALIDDATA;
track = AV_RL32(buf + 8);
if ((unsigned)track >= UINT_MAX / sizeof(AudioTrack) - 1) {
av_log(s, AV_LOG_ERROR, "current_track too large\n");
return AVERROR_INVALIDDATA;
}
if (track + 1 > fourxm->track_count) {
if (av_reallocp_array(&fourxm->tracks, track + 1, sizeof(AudioTrack)))
return AVERROR(ENOMEM);
memset(&fourxm->tracks[fourxm->track_count], 0,
sizeof(AudioTrack) * (track + 1 - fourxm->track_count));
fourxm->track_count = track + 1;
}
fourxm->tracks[track].adpcm = AV_RL32(buf + 12);
fourxm->tracks[track].channels = AV_RL32(buf + 36);
fourxm->tracks[track].sample_rate = AV_RL32(buf + 40);
fourxm->tracks[track].bits = AV_RL32(buf + 44);
fourxm->tracks[track].audio_pts = 0;
if (fourxm->tracks[track].channels <= 0 ||
fourxm->tracks[track].sample_rate <= 0 ||
fourxm->tracks[track].bits <= 0) {
av_log(s, AV_LOG_ERROR, "audio header invalid\n");
return AVERROR_INVALIDDATA;
}
if (!fourxm->tracks[track].adpcm && fourxm->tracks[track].bits<8) {
av_log(s, AV_LOG_ERROR, "bits unspecified for non ADPCM\n");
return AVERROR_INVALIDDATA;
}
if (fourxm->tracks[track].sample_rate > INT64_MAX / fourxm->tracks[track].bits / fourxm->tracks[track].channels) {
av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * %d * %d\n",
fourxm->tracks[track].sample_rate, fourxm->tracks[track].bits, fourxm->tracks[track].channels);
return AVERROR_INVALIDDATA;
}
/* allocate a new AVStream */
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->id = track;
avpriv_set_pts_info(st, 60, 1, fourxm->tracks[track].sample_rate);
fourxm->tracks[track].stream_index = st->index;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_tag = 0;
st->codecpar->channels = fourxm->tracks[track].channels;
st->codecpar->sample_rate = fourxm->tracks[track].sample_rate;
st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits;
st->codecpar->bit_rate = (int64_t)st->codecpar->channels *
st->codecpar->sample_rate *
st->codecpar->bits_per_coded_sample;
st->codecpar->block_align = st->codecpar->channels *
st->codecpar->bits_per_coded_sample;
if (fourxm->tracks[track].adpcm){
st->codecpar->codec_id = AV_CODEC_ID_ADPCM_4XM;
} else if (st->codecpar->bits_per_coded_sample == 8) {
st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
} else
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
return 0;
}
| 4,467 |
FFmpeg | 428098165de4c3edfe42c1b7f00627d287015863 | 1 | void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation)
{
union {
signed short tmp[8] __attribute__ ((aligned(16)));
vector signed short vec;
} buf;
buf.tmp[0] = ( (0xffffLL) * contrast>>8 )>>9; //cy
buf.tmp[1] = -256*brightness; //oy
buf.tmp[2] = (inv_table[0]>>3) *(contrast>>16)*(saturation>>16); //crv
buf.tmp[3] = (inv_table[1]>>3) *(contrast>>16)*(saturation>>16); //cbu
buf.tmp[4] = -((inv_table[2]>>1)*(contrast>>16)*(saturation>>16)); //cgu
buf.tmp[5] = -((inv_table[3]>>1)*(contrast>>16)*(saturation>>16)); //cgv
c->CSHIFT = (vector unsigned short)vec_splat_u16(2);
c->CY = vec_splat ((vector signed short)buf.vec, 0);
c->OY = vec_splat ((vector signed short)buf.vec, 1);
c->CRV = vec_splat ((vector signed short)buf.vec, 2);
c->CBU = vec_splat ((vector signed short)buf.vec, 3);
c->CGU = vec_splat ((vector signed short)buf.vec, 4);
c->CGV = vec_splat ((vector signed short)buf.vec, 5);
#if 0
{
int i;
char *v[6]={"cy","oy","crv","cbu","cgu","cgv"};
for (i=0; i<6;i++)
printf("%s %d ", v[i],buf.tmp[i] );
printf("\n");
}
#endif
return;
}
| 4,468 |
qemu | e61da14d60ba1cceacad8396adcb9662c7f690af | 1 | static void control_out(VirtIODevice *vdev, VirtQueue *vq)
{
VirtQueueElement elem;
VirtIOSerial *vser;
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
while (virtqueue_pop(vq, &elem)) {
handle_control_message(vser, elem.out_sg[0].iov_base);
virtqueue_push(vq, &elem, elem.out_sg[0].iov_len);
}
virtio_notify(vdev, vq);
}
| 4,469 |
qemu | e814dffcc9810ed77fe99081be9751b620a894c4 | 1 | static int img_amend(int argc, char **argv)
{
Error *err = NULL;
int c, ret = 0;
char *options = NULL;
QemuOptsList *create_opts = NULL;
QemuOpts *opts = NULL;
const char *fmt = NULL, *filename, *cache;
int flags;
bool quiet = false, progress = false;
BlockBackend *blk = NULL;
BlockDriverState *bs = NULL;
cache = BDRV_DEFAULT_CACHE;
for (;;) {
c = getopt(argc, argv, "ho:f:t:pq");
if (c == -1) {
break;
}
switch (c) {
case 'h':
case '?':
help();
break;
case 'o':
if (!is_valid_option_list(optarg)) {
error_report("Invalid option list: %s", optarg);
ret = -1;
goto out;
}
if (!options) {
options = g_strdup(optarg);
} else {
char *old_options = options;
options = g_strdup_printf("%s,%s", options, optarg);
g_free(old_options);
}
break;
case 'f':
fmt = optarg;
break;
case 't':
cache = optarg;
break;
case 'p':
progress = true;
break;
case 'q':
quiet = true;
break;
}
}
if (!options) {
error_exit("Must specify options (-o)");
}
if (quiet) {
progress = false;
}
qemu_progress_init(progress, 1.0);
filename = (optind == argc - 1) ? argv[argc - 1] : NULL;
if (fmt && has_help_option(options)) {
/* If a format is explicitly specified (and possibly no filename is
* given), print option help here */
ret = print_block_option_help(filename, fmt);
goto out;
}
if (optind != argc - 1) {
error_report("Expecting one image file name");
ret = -1;
goto out;
}
flags = BDRV_O_FLAGS | BDRV_O_RDWR;
ret = bdrv_parse_cache_flags(cache, &flags);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
goto out;
}
blk = img_open("image", filename, fmt, flags, true, quiet);
if (!blk) {
ret = -1;
goto out;
}
bs = blk_bs(blk);
fmt = bs->drv->format_name;
if (has_help_option(options)) {
/* If the format was auto-detected, print option help here */
ret = print_block_option_help(filename, fmt);
goto out;
}
if (!bs->drv->create_opts) {
error_report("Format driver '%s' does not support any options to amend",
fmt);
ret = -1;
goto out;
}
create_opts = qemu_opts_append(create_opts, bs->drv->create_opts);
opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
if (options) {
qemu_opts_do_parse(opts, options, NULL, &err);
if (err) {
error_report_err(err);
ret = -1;
goto out;
}
}
/* In case the driver does not call amend_status_cb() */
qemu_progress_print(0.f, 0);
ret = bdrv_amend_options(bs, opts, &amend_status_cb);
qemu_progress_print(100.f, 0);
if (ret < 0) {
error_report("Error while amending options: %s", strerror(-ret));
goto out;
}
out:
qemu_progress_end();
blk_unref(blk);
qemu_opts_del(opts);
qemu_opts_free(create_opts);
g_free(options);
if (ret) {
return 1;
}
return 0;
}
| 4,470 |
qemu | 967b75230b9720ea2b3ae49f38f8287026125f9f | 1 | static void powernv_populate_chip(PnvChip *chip, void *fdt)
{
PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
char *typename = pnv_core_typename(pcc->cpu_model);
size_t typesize = object_type_get_instance_size(typename);
int i;
for (i = 0; i < chip->nr_cores; i++) {
PnvCore *pnv_core = PNV_CORE(chip->cores + i * typesize);
powernv_create_core_node(chip, pnv_core, fdt);
}
if (chip->ram_size) {
powernv_populate_memory_node(fdt, chip->chip_id, chip->ram_start,
chip->ram_size);
}
g_free(typename);
} | 4,471 |
qemu | db12451decf7dfe0f083564183e135f2095228b9 | 1 | static int virtio_rng_load_device(VirtIODevice *vdev, QEMUFile *f,
int version_id)
{
/* We may have an element ready but couldn't process it due to a quota
* limit. Make sure to try again after live migration when the quota may
* have been reset.
*/
virtio_rng_process(VIRTIO_RNG(vdev));
return 0;
}
| 4,472 |
FFmpeg | 0a59055167eea3087a36d9091501d3bb52ed8ebe | 1 | static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, int16_t *block, int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
uint8_t * const scantable = s->intra_scantable.permutated;
const int qscale = s->qscale;
{
OPEN_READER(re, &s->gb);
i = -1;
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
level = (3 * qscale) >> 1;
level = (level - 1) | 1;
if (GET_CACHE(re, &s->gb) & 0x40000000)
level = -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
for (;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if (level != 0) {
i += run;
j = scantable[i];
level = ((level * 2 + 1) * qscale) >> 1;
level = (level - 1) | 1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
if (level == -128) {
level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);
} else if (level == 0) {
level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
}
i += run;
j = scantable[i];
if (level < 0) {
level = -level;
level = ((level * 2 + 1) * qscale) >> 1;
level = (level - 1) | 1;
level = -level;
} else {
level = ((level * 2 + 1) * qscale) >> 1;
level = (level - 1) | 1;
}
}
block[j] = level;
if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
UPDATE_CACHE(re, &s->gb);
}
end:
LAST_SKIP_BITS(re, &s->gb, 2);
CLOSE_READER(re, &s->gb);
}
s->block_last_index[n] = i;
return 0;
}
| 4,473 |
qemu | 4f4321c11ff6e98583846bfd6f0e81954924b003 | 1 | static int usb_net_handle_datain(USBNetState *s, USBPacket *p)
{
int ret = USB_RET_NAK;
if (s->in_ptr > s->in_len) {
s->in_ptr = s->in_len = 0;
ret = USB_RET_NAK;
return ret;
}
if (!s->in_len) {
ret = USB_RET_NAK;
return ret;
}
ret = s->in_len - s->in_ptr;
if (ret > p->len)
ret = p->len;
memcpy(p->data, &s->in_buf[s->in_ptr], ret);
s->in_ptr += ret;
if (s->in_ptr >= s->in_len &&
(is_rndis(s) || (s->in_len & (64 - 1)) || !ret)) {
/* no short packet necessary */
s->in_ptr = s->in_len = 0;
}
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: data in len %u return %d", p->len, ret);
{
int i;
fprintf(stderr, ":");
for (i = 0; i < ret; i++) {
if (!(i & 15))
fprintf(stderr, "\n%04x:", i);
fprintf(stderr, " %02x", p->data[i]);
}
fprintf(stderr, "\n\n");
}
#endif
return ret;
}
| 4,474 |
FFmpeg | 5e6ce28dabe002a6130f17b59c454bdee33088f7 | 0 | static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration)
{
int i;
MP3DecContext *mp3 = s->priv_data;
int fill_index = mp3->usetoc == 1 && duration > 0;
if (!filesize &&
!(filesize = avio_size(s->pb))) {
av_log(s, AV_LOG_WARNING, "Cannot determine file size, skipping TOC table.\n");
fill_index = 0;
}
for (i = 0; i < XING_TOC_COUNT; i++) {
uint8_t b = avio_r8(s->pb);
if (fill_index)
av_add_index_entry(s->streams[0],
av_rescale(b, filesize, 256),
av_rescale(i, duration, XING_TOC_COUNT),
0, 0, AVINDEX_KEYFRAME);
}
if (fill_index)
mp3->xing_toc = 1;
}
| 4,475 |
FFmpeg | 0105ed551cb9610c62b6920a301125781e1161a0 | 0 | void ff_put_h264_qpel8_mc00_msa(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride)
{
copy_width8_msa(src, stride, dst, stride, 8);
}
| 4,476 |
FFmpeg | 4315c7d35aa946fb3a0da9a30f08fb4e0ca8edfb | 0 | static int ape_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
APEContext *s = avctx->priv_data;
int16_t *samples = data;
uint32_t nblocks;
int i;
int blockstodecode;
int bytes_used;
/* should not happen but who knows */
if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) {
av_log (avctx, AV_LOG_ERROR, "Output buffer is too small.\n");
return AVERROR(EINVAL);
}
/* this should never be negative, but bad things will happen if it is, so
check it just to make sure. */
av_assert0(s->samples >= 0);
if(!s->samples){
uint32_t offset;
void *tmp_data;
if (buf_size < 8) {
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
return AVERROR_INVALIDDATA;
}
tmp_data = av_realloc(s->data, FFALIGN(buf_size, 4));
if (!tmp_data)
return AVERROR(ENOMEM);
s->data = tmp_data;
s->dsp.bswap_buf((uint32_t*)s->data, (const uint32_t*)buf, buf_size >> 2);
s->ptr = s->last_ptr = s->data;
s->data_end = s->data + buf_size;
nblocks = bytestream_get_be32(&s->ptr);
offset = bytestream_get_be32(&s->ptr);
if (offset > 3) {
av_log(avctx, AV_LOG_ERROR, "Incorrect offset passed\n");
s->data = NULL;
return AVERROR_INVALIDDATA;
}
if (s->data_end - s->ptr < offset) {
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
return AVERROR_INVALIDDATA;
}
s->ptr += offset;
if (!nblocks || nblocks > INT_MAX) {
av_log(avctx, AV_LOG_ERROR, "Invalid sample count: %u.\n", nblocks);
return AVERROR_INVALIDDATA;
}
s->samples = nblocks;
memset(s->decoded0, 0, sizeof(s->decoded0));
memset(s->decoded1, 0, sizeof(s->decoded1));
/* Initialize the frame decoder */
if (init_frame_decoder(s) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error reading frame header\n");
return AVERROR_INVALIDDATA;
}
}
if (!s->data) {
*data_size = 0;
return buf_size;
}
nblocks = s->samples;
blockstodecode = FFMIN(BLOCKS_PER_LOOP, nblocks);
s->error=0;
if ((s->channels == 1) || (s->frameflags & APE_FRAMECODE_PSEUDO_STEREO))
ape_unpack_mono(s, blockstodecode);
else
ape_unpack_stereo(s, blockstodecode);
emms_c();
if (s->error) {
s->samples=0;
av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n");
return AVERROR_INVALIDDATA;
}
for (i = 0; i < blockstodecode; i++) {
*samples++ = s->decoded0[i];
if(s->channels == 2)
*samples++ = s->decoded1[i];
}
s->samples -= blockstodecode;
*data_size = blockstodecode * 2 * s->channels;
bytes_used = s->samples ? s->ptr - s->last_ptr : buf_size;
s->last_ptr = s->ptr;
return bytes_used;
}
| 4,477 |
qemu | 07caea315a85ebfe90851f9c2e4ef3fdd24117b5 | 1 | static void sun4uv_init(ram_addr_t RAM_size,
const char *boot_devices,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model,
const struct hwdef *hwdef)
{
CPUState *env;
m48t59_t *nvram;
unsigned int i;
long initrd_size, kernel_size;
PCIBus *pci_bus, *pci_bus2, *pci_bus3;
qemu_irq *irq;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
DriveInfo *fd[MAX_FD];
void *fw_cfg;
/* init CPUs */
env = cpu_devinit(cpu_model, hwdef);
/* set up devices */
ram_init(0, RAM_size);
prom_init(hwdef->prom_addr, bios_name);
irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, irq, &pci_bus2,
&pci_bus3);
isa_mem_base = VGA_BASE;
pci_vga_init(pci_bus, 0, 0);
// XXX Should be pci_bus3
pci_ebus_init(pci_bus, -1);
i = 0;
if (hwdef->console_serial_base) {
serial_mm_init(hwdef->console_serial_base, 0, NULL, 115200,
serial_hds[i], 1);
i++;
}
for(; i < MAX_SERIAL_PORTS; i++) {
if (serial_hds[i]) {
serial_isa_init(i, serial_hds[i]);
}
}
for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
if (parallel_hds[i]) {
parallel_init(i, parallel_hds[i]);
}
}
for(i = 0; i < nb_nics; i++)
pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
fprintf(stderr, "qemu: too many IDE bus\n");
exit(1);
}
for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS,
i % MAX_IDE_DEVS);
}
pci_cmd646_ide_init(pci_bus, hd, 1);
isa_create_simple("i8042");
for(i = 0; i < MAX_FD; i++) {
fd[i] = drive_get(IF_FLOPPY, 0, i);
}
fdctrl_init_isa(fd);
nvram = m48t59_init_isa(0x0074, NVRAM_SIZE, 59);
initrd_size = 0;
kernel_size = sun4u_load_kernel(kernel_filename, initrd_filename,
ram_size, &initrd_size);
sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices,
KERNEL_LOAD_ADDR, kernel_size,
kernel_cmdline,
INITRD_LOAD_ADDR, initrd_size,
/* XXX: need an option to load a NVRAM image */
0,
graphic_width, graphic_height, graphic_depth,
(uint8_t *)&nd_table[0].macaddr);
fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
} else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
}
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width);
fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height);
fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth);
qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
}
| 4,480 |
qemu | 5e003f17ec518cd96f5d2ac23ce9e14144426235 | 1 | bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs)
{
bool ok = true;
BlockDriverState *bs;
BdrvNextIterator it;
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *ctx = bdrv_get_aio_context(bs);
aio_context_acquire(ctx);
if (bdrv_is_inserted(bs) && !bdrv_is_read_only(bs)) {
ok = bdrv_can_snapshot(bs);
}
aio_context_release(ctx);
if (!ok) {
goto fail;
}
}
fail:
*first_bad_bs = bs;
return ok;
} | 4,481 |
qemu | 6e24ee0c1e4b6c0c9c748acab77ecd113c942a4d | 1 | static void ps2_reset_keyboard(PS2KbdState *s)
{
trace_ps2_reset_keyboard(s);
s->scan_enabled = 1;
s->scancode_set = 2;
ps2_set_ledstate(s, 0);
} | 4,482 |
qemu | 72cf2d4f0e181d0d3a3122e04129c58a95da713e | 0 | int qemu_savevm_state_complete(QEMUFile *f)
{
SaveStateEntry *se;
TAILQ_FOREACH(se, &savevm_handlers, entry) {
if (se->save_live_state == NULL)
continue;
/* Section type */
qemu_put_byte(f, QEMU_VM_SECTION_END);
qemu_put_be32(f, se->section_id);
se->save_live_state(f, QEMU_VM_SECTION_END, se->opaque);
}
TAILQ_FOREACH(se, &savevm_handlers, entry) {
int len;
if (se->save_state == NULL && se->vmsd == NULL)
continue;
/* Section type */
qemu_put_byte(f, QEMU_VM_SECTION_FULL);
qemu_put_be32(f, se->section_id);
/* ID string */
len = strlen(se->idstr);
qemu_put_byte(f, len);
qemu_put_buffer(f, (uint8_t *)se->idstr, len);
qemu_put_be32(f, se->instance_id);
qemu_put_be32(f, se->version_id);
vmstate_save(f, se);
}
qemu_put_byte(f, QEMU_VM_EOF);
if (qemu_file_has_error(f))
return -EIO;
return 0;
}
| 4,483 |
qemu | d9f62dde1303286b24ac8ce88be27e2b9b9c5f46 | 0 | static GenericList *next_list(Visitor *v, GenericList **list, size_t size)
{
StringOutputVisitor *sov = to_sov(v);
GenericList *ret = NULL;
if (*list) {
if (sov->head) {
ret = *list;
} else {
ret = (*list)->next;
}
if (sov->head) {
if (ret && ret->next == NULL) {
sov->list_mode = LM_NONE;
}
sov->head = false;
} else {
if (ret && ret->next == NULL) {
sov->list_mode = LM_END;
}
}
}
return ret;
}
| 4,484 |
qemu | ba3186c4e473963ba83b5792f3d02d4ac0a76ba5 | 0 | static void curl_multi_timeout_do(void *arg)
{
#ifdef NEED_CURL_TIMER_CALLBACK
BDRVCURLState *s = (BDRVCURLState *)arg;
int running;
if (!s->multi) {
return;
}
aio_context_acquire(s->aio_context);
curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
curl_multi_check_completion(s);
aio_context_release(s->aio_context);
#else
abort();
#endif
}
| 4,485 |
qemu | 9a4c0e220d8a4f82b5665d0ee95ef94d8e1509d5 | 0 | static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
int n, bool assign)
{
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
VirtQueue *vq = virtio_get_queue(vdev, n);
bool legacy = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_LEGACY);
bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN);
bool fast_mmio = kvm_ioeventfd_any_length_enabled();
bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY;
MemoryRegion *modern_mr = &proxy->notify.mr;
MemoryRegion *modern_notify_mr = &proxy->notify_pio.mr;
MemoryRegion *legacy_mr = &proxy->bar;
hwaddr modern_addr = QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
virtio_get_queue_index(vq);
hwaddr legacy_addr = VIRTIO_PCI_QUEUE_NOTIFY;
if (assign) {
if (modern) {
if (fast_mmio) {
memory_region_add_eventfd(modern_mr, modern_addr, 0,
false, n, notifier);
} else {
memory_region_add_eventfd(modern_mr, modern_addr, 2,
false, n, notifier);
}
if (modern_pio) {
memory_region_add_eventfd(modern_notify_mr, 0, 2,
true, n, notifier);
}
}
if (legacy) {
memory_region_add_eventfd(legacy_mr, legacy_addr, 2,
true, n, notifier);
}
} else {
if (modern) {
if (fast_mmio) {
memory_region_del_eventfd(modern_mr, modern_addr, 0,
false, n, notifier);
} else {
memory_region_del_eventfd(modern_mr, modern_addr, 2,
false, n, notifier);
}
if (modern_pio) {
memory_region_del_eventfd(modern_notify_mr, 0, 2,
true, n, notifier);
}
}
if (legacy) {
memory_region_del_eventfd(legacy_mr, legacy_addr, 2,
true, n, notifier);
}
}
return 0;
}
| 4,486 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static uint64_t esp_pci_io_read(void *opaque, target_phys_addr_t addr,
unsigned int size)
{
PCIESPState *pci = opaque;
uint32_t ret;
if (addr < 0x40) {
/* SCSI core reg */
ret = esp_reg_read(&pci->esp, addr >> 2);
} else if (addr < 0x60) {
/* PCI DMA CCB */
ret = esp_pci_dma_read(pci, (addr - 0x40) >> 2);
} else if (addr == 0x70) {
/* DMA SCSI Bus and control */
trace_esp_pci_sbac_read(pci->sbac);
ret = pci->sbac;
} else {
/* Invalid region */
trace_esp_pci_error_invalid_read((int)addr);
ret = 0;
}
/* give only requested data */
ret >>= (addr & 3) * 8;
ret &= ~(~(uint64_t)0 << (8 * size));
return ret;
}
| 4,487 |
qemu | 5379229a2708df3a1506113315214c3ce5325859 | 0 | sorecvfrom(struct socket *so)
{
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(struct sockaddr_storage);
DEBUG_CALL("sorecvfrom");
DEBUG_ARG("so = %p", so);
if (so->so_type == IPPROTO_ICMP) { /* This is a "ping" reply */
char buff[256];
int len;
len = recvfrom(so->s, buff, 256, 0,
(struct sockaddr *)&addr, &addrlen);
/* XXX Check if reply is "correct"? */
if(len == -1 || len == 0) {
u_char code=ICMP_UNREACH_PORT;
if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
errno,strerror(errno)));
icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
} else {
icmp_reflect(so->so_m);
so->so_m = NULL; /* Don't m_free() it again! */
}
/* No need for this socket anymore, udp_detach it */
udp_detach(so);
} else { /* A "normal" UDP packet */
struct mbuf *m;
int len;
#ifdef _WIN32
unsigned long n;
#else
int n;
#endif
m = m_get(so->slirp);
if (!m) {
return;
}
m->m_data += IF_MAXLINKHDR;
/*
* XXX Shouldn't FIONREAD packets destined for port 53,
* but I don't know the max packet size for DNS lookups
*/
len = M_FREEROOM(m);
/* if (so->so_fport != htons(53)) { */
ioctlsocket(so->s, FIONREAD, &n);
if (n > len) {
n = (m->m_data - m->m_dat) + m->m_len + n + 1;
m_inc(m, n);
len = M_FREEROOM(m);
}
/* } */
m->m_len = recvfrom(so->s, m->m_data, len, 0,
(struct sockaddr *)&addr, &addrlen);
DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
m->m_len, errno,strerror(errno)));
if(m->m_len<0) {
u_char code=ICMP_UNREACH_PORT;
if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code));
icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
m_free(m);
} else {
/*
* Hack: domain name lookup will be used the most for UDP,
* and since they'll only be used once there's no need
* for the 4 minute (or whatever) timeout... So we time them
* out much quicker (10 seconds for now...)
*/
if (so->so_expire) {
if (so->so_fport == htons(53))
so->so_expire = curtime + SO_EXPIREFAST;
else
so->so_expire = curtime + SO_EXPIRE;
}
/*
* If this packet was destined for CTL_ADDR,
* make it look like that's where it came from, done by udp_output
*/
switch (so->so_ffamily) {
case AF_INET:
udp_output(so, m, (struct sockaddr_in *) &addr);
break;
default:
break;
}
} /* rx error */
} /* if ping packet */
}
| 4,489 |
qemu | 7bd427d801e1e3293a634d3c83beadaa90ffb911 | 0 | static int pxa2xx_rtc_init(SysBusDevice *dev)
{
PXA2xxRTCState *s = FROM_SYSBUS(PXA2xxRTCState, dev);
struct tm tm;
int wom;
int iomemtype;
s->rttr = 0x7fff;
s->rtsr = 0;
qemu_get_timedate(&tm, 0);
wom = ((tm.tm_mday - 1) / 7) + 1;
s->last_rcnr = (uint32_t) mktimegm(&tm);
s->last_rdcr = (wom << 20) | ((tm.tm_wday + 1) << 17) |
(tm.tm_hour << 12) | (tm.tm_min << 6) | tm.tm_sec;
s->last_rycr = ((tm.tm_year + 1900) << 9) |
((tm.tm_mon + 1) << 5) | tm.tm_mday;
s->last_swcr = (tm.tm_hour << 19) |
(tm.tm_min << 13) | (tm.tm_sec << 7);
s->last_rtcpicr = 0;
s->last_hz = s->last_sw = s->last_pi = qemu_get_clock(rt_clock);
s->rtc_hz = qemu_new_timer(rt_clock, pxa2xx_rtc_hz_tick, s);
s->rtc_rdal1 = qemu_new_timer(rt_clock, pxa2xx_rtc_rdal1_tick, s);
s->rtc_rdal2 = qemu_new_timer(rt_clock, pxa2xx_rtc_rdal2_tick, s);
s->rtc_swal1 = qemu_new_timer(rt_clock, pxa2xx_rtc_swal1_tick, s);
s->rtc_swal2 = qemu_new_timer(rt_clock, pxa2xx_rtc_swal2_tick, s);
s->rtc_pi = qemu_new_timer(rt_clock, pxa2xx_rtc_pi_tick, s);
sysbus_init_irq(dev, &s->rtc_irq);
iomemtype = cpu_register_io_memory(pxa2xx_rtc_readfn,
pxa2xx_rtc_writefn, s, DEVICE_NATIVE_ENDIAN);
sysbus_init_mmio(dev, 0x10000, iomemtype);
return 0;
}
| 4,490 |
FFmpeg | f5a669c229425cdac828c230addf10d6d9cbe3a7 | 0 | static int transcode(AVFormatContext **output_files,
int nb_output_files,
AVFormatContext **input_files,
int nb_input_files,
AVStreamMap *stream_maps, int nb_stream_maps)
{
int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0, step;
AVFormatContext *is, *os;
AVCodecContext *codec, *icodec;
AVOutputStream *ost, **ost_table = NULL;
AVInputStream *ist, **ist_table = NULL;
AVInputFile *file_table;
char error[1024];
int key;
int want_sdp = 1;
uint8_t no_packet[MAX_FILES]={0};
int no_packet_count=0;
int nb_frame_threshold[AVMEDIA_TYPE_NB]={0};
int nb_streams[AVMEDIA_TYPE_NB]={0};
file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));
if (!file_table)
goto fail;
/* input stream init */
j = 0;
for(i=0;i<nb_input_files;i++) {
is = input_files[i];
file_table[i].ist_index = j;
file_table[i].nb_streams = is->nb_streams;
j += is->nb_streams;
}
nb_istreams = j;
ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *));
if (!ist_table)
goto fail;
for(i=0;i<nb_istreams;i++) {
ist = av_mallocz(sizeof(AVInputStream));
if (!ist)
goto fail;
ist_table[i] = ist;
}
j = 0;
for(i=0;i<nb_input_files;i++) {
is = input_files[i];
for(k=0;k<is->nb_streams;k++) {
ist = ist_table[j++];
ist->st = is->streams[k];
ist->file_index = i;
ist->index = k;
ist->discard = 1; /* the stream is discarded by default
(changed later) */
if (rate_emu) {
ist->start = av_gettime();
}
}
}
/* output stream init */
nb_ostreams = 0;
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) {
av_dump_format(output_files[i], i, output_files[i]->filename, 1);
fprintf(stderr, "Output file #%d does not contain any stream\n", i);
ret = AVERROR(EINVAL);
goto fail;
}
nb_ostreams += os->nb_streams;
}
if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
fprintf(stderr, "Number of stream maps must match number of output streams\n");
ret = AVERROR(EINVAL);
goto fail;
}
/* Sanity check the mapping args -- do the input files & streams exist? */
for(i=0;i<nb_stream_maps;i++) {
int fi = stream_maps[i].file_index;
int si = stream_maps[i].stream_index;
if (fi < 0 || fi > nb_input_files - 1 ||
si < 0 || si > file_table[fi].nb_streams - 1) {
fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si);
ret = AVERROR(EINVAL);
goto fail;
}
fi = stream_maps[i].sync_file_index;
si = stream_maps[i].sync_stream_index;
if (fi < 0 || fi > nb_input_files - 1 ||
si < 0 || si > file_table[fi].nb_streams - 1) {
fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si);
ret = AVERROR(EINVAL);
goto fail;
}
}
ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
if (!ost_table)
goto fail;
for(k=0;k<nb_output_files;k++) {
os = output_files[k];
for(i=0;i<os->nb_streams;i++,n++) {
nb_streams[os->streams[i]->codec->codec_type]++;
}
}
for(step=1<<30; step; step>>=1){
int found_streams[AVMEDIA_TYPE_NB]={0};
for(j=0; j<AVMEDIA_TYPE_NB; j++)
nb_frame_threshold[j] += step;
for(j=0; j<nb_istreams; j++) {
int skip=0;
ist = ist_table[j];
if(opt_programid){
int pi,si;
AVFormatContext *f= input_files[ ist->file_index ];
skip=1;
for(pi=0; pi<f->nb_programs; pi++){
AVProgram *p= f->programs[pi];
if(p->id == opt_programid)
for(si=0; si<p->nb_stream_indexes; si++){
if(f->streams[ p->stream_index[si] ] == ist->st)
skip=0;
}
}
}
if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip
&& nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){
found_streams[ist->st->codec->codec_type]++;
}
}
for(j=0; j<AVMEDIA_TYPE_NB; j++)
if(found_streams[j] < nb_streams[j])
nb_frame_threshold[j] -= step;
}
n = 0;
for(k=0;k<nb_output_files;k++) {
os = output_files[k];
for(i=0;i<os->nb_streams;i++,n++) {
int found;
ost = ost_table[n] = output_streams_for_file[k][i];
ost->st = os->streams[i];
if (nb_stream_maps > 0) {
ost->source_index = file_table[stream_maps[n].file_index].ist_index +
stream_maps[n].stream_index;
/* Sanity check that the stream types match */
if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) {
int i= ost->file_index;
av_dump_format(output_files[i], i, output_files[i]->filename, 1);
fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
stream_maps[n].file_index, stream_maps[n].stream_index,
ost->file_index, ost->index);
ffmpeg_exit(1);
}
} else {
/* get corresponding input stream index : we select the first one with the right type */
found = 0;
for(j=0;j<nb_istreams;j++) {
int skip=0;
ist = ist_table[j];
if(opt_programid){
int pi,si;
AVFormatContext *f= input_files[ ist->file_index ];
skip=1;
for(pi=0; pi<f->nb_programs; pi++){
AVProgram *p= f->programs[pi];
if(p->id == opt_programid)
for(si=0; si<p->nb_stream_indexes; si++){
if(f->streams[ p->stream_index[si] ] == ist->st)
skip=0;
}
}
}
if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip &&
ist->st->codec->codec_type == ost->st->codec->codec_type &&
nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames) {
ost->source_index = j;
found = 1;
break;
}
}
if (!found) {
if(! opt_programid) {
/* try again and reuse existing stream */
for(j=0;j<nb_istreams;j++) {
ist = ist_table[j];
if ( ist->st->codec->codec_type == ost->st->codec->codec_type
&& ist->st->discard != AVDISCARD_ALL) {
ost->source_index = j;
found = 1;
}
}
}
if (!found) {
int i= ost->file_index;
av_dump_format(output_files[i], i, output_files[i]->filename, 1);
fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n",
ost->file_index, ost->index);
ffmpeg_exit(1);
}
}
}
ist = ist_table[ost->source_index];
ist->discard = 0;
ost->sync_ist = (nb_stream_maps > 0) ?
ist_table[file_table[stream_maps[n].sync_file_index].ist_index +
stream_maps[n].sync_stream_index] : ist;
}
}
/* for each output stream, we compute the right encoding parameters */
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
os = output_files[ost->file_index];
ist = ist_table[ost->source_index];
codec = ost->st->codec;
icodec = ist->st->codec;
if (metadata_streams_autocopy)
av_metadata_copy(&ost->st->metadata, ist->st->metadata,
AV_METADATA_DONT_OVERWRITE);
ost->st->disposition = ist->st->disposition;
codec->bits_per_raw_sample= icodec->bits_per_raw_sample;
codec->chroma_sample_location = icodec->chroma_sample_location;
if (ost->st->stream_copy) {
uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;
if (extra_size > INT_MAX)
goto fail;
/* if stream_copy is selected, no need to decode or encode */
codec->codec_id = icodec->codec_id;
codec->codec_type = icodec->codec_type;
if(!codec->codec_tag){
if( !os->oformat->codec_tag
|| av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id
|| av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0)
codec->codec_tag = icodec->codec_tag;
}
codec->bit_rate = icodec->bit_rate;
codec->rc_max_rate = icodec->rc_max_rate;
codec->rc_buffer_size = icodec->rc_buffer_size;
codec->extradata= av_mallocz(extra_size);
if (!codec->extradata)
goto fail;
memcpy(codec->extradata, icodec->extradata, icodec->extradata_size);
codec->extradata_size= icodec->extradata_size;
if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){
codec->time_base = icodec->time_base;
codec->time_base.num *= icodec->ticks_per_frame;
av_reduce(&codec->time_base.num, &codec->time_base.den,
codec->time_base.num, codec->time_base.den, INT_MAX);
}else
codec->time_base = ist->st->time_base;
switch(codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
if(audio_volume != 256) {
fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n");
ffmpeg_exit(1);
}
codec->channel_layout = icodec->channel_layout;
codec->sample_rate = icodec->sample_rate;
codec->channels = icodec->channels;
codec->frame_size = icodec->frame_size;
codec->audio_service_type = icodec->audio_service_type;
codec->block_align= icodec->block_align;
if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)
codec->block_align= 0;
if(codec->codec_id == CODEC_ID_AC3)
codec->block_align= 0;
break;
case AVMEDIA_TYPE_VIDEO:
codec->pix_fmt = icodec->pix_fmt;
codec->width = icodec->width;
codec->height = icodec->height;
codec->has_b_frames = icodec->has_b_frames;
if (!codec->sample_aspect_ratio.num) {
codec->sample_aspect_ratio =
ost->st->sample_aspect_ratio =
ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :
ist->st->codec->sample_aspect_ratio.num ?
ist->st->codec->sample_aspect_ratio : (AVRational){0, 1};
}
break;
case AVMEDIA_TYPE_SUBTITLE:
codec->width = icodec->width;
codec->height = icodec->height;
break;
case AVMEDIA_TYPE_DATA:
break;
default:
abort();
}
} else {
switch(codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ost->fifo= av_fifo_alloc(1024);
if(!ost->fifo)
goto fail;
ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE);
ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
icodec->request_channels = codec->channels;
ist->decoding_needed = 1;
ost->encoding_needed = 1;
ost->resample_sample_fmt = icodec->sample_fmt;
ost->resample_sample_rate = icodec->sample_rate;
ost->resample_channels = icodec->channels;
break;
case AVMEDIA_TYPE_VIDEO:
if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
ffmpeg_exit(1);
}
ost->video_resample = codec->width != icodec->width ||
codec->height != icodec->height ||
codec->pix_fmt != icodec->pix_fmt;
if (ost->video_resample) {
#if !CONFIG_AVFILTER
avcodec_get_frame_defaults(&ost->pict_tmp);
if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt,
codec->width, codec->height)) {
fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
ffmpeg_exit(1);
}
sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
ost->img_resample_ctx = sws_getContext(
icodec->width,
icodec->height,
icodec->pix_fmt,
codec->width,
codec->height,
codec->pix_fmt,
sws_flags, NULL, NULL, NULL);
if (ost->img_resample_ctx == NULL) {
fprintf(stderr, "Cannot get resampling context\n");
ffmpeg_exit(1);
}
#endif
codec->bits_per_raw_sample= frame_bits_per_raw_sample;
}
ost->resample_height = icodec->height;
ost->resample_width = icodec->width;
ost->resample_pix_fmt= icodec->pix_fmt;
ost->encoding_needed = 1;
ist->decoding_needed = 1;
#if CONFIG_AVFILTER
if (configure_video_filters(ist, ost)) {
fprintf(stderr, "Error opening filters!\n");
exit(1);
}
#endif
break;
case AVMEDIA_TYPE_SUBTITLE:
ost->encoding_needed = 1;
ist->decoding_needed = 1;
break;
default:
abort();
break;
}
/* two pass mode */
if (ost->encoding_needed && codec->codec_id != CODEC_ID_H264 &&
(codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
char logfilename[1024];
FILE *f;
snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,
i);
if (codec->flags & CODEC_FLAG_PASS1) {
f = fopen(logfilename, "wb");
if (!f) {
fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno));
ffmpeg_exit(1);
}
ost->logfile = f;
} else {
char *logbuffer;
size_t logbuffer_size;
if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename);
ffmpeg_exit(1);
}
codec->stats_in = logbuffer;
}
}
}
if(codec->codec_type == AVMEDIA_TYPE_VIDEO){
/* maximum video buffer size is 6-bytes per pixel, plus DPX header size */
int size= codec->width * codec->height;
bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 1664);
}
}
if (!bit_buffer)
bit_buffer = av_malloc(bit_buffer_size);
if (!bit_buffer) {
fprintf(stderr, "Cannot allocate %d bytes output buffer\n",
bit_buffer_size);
ret = AVERROR(ENOMEM);
goto fail;
}
/* open each encoder */
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost->encoding_needed) {
AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
AVCodecContext *dec = ist_table[ost->source_index]->st->codec;
if (!codec)
codec = avcodec_find_encoder(ost->st->codec->codec_id);
if (!codec) {
snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d",
ost->st->codec->codec_id, ost->file_index, ost->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
if (dec->subtitle_header) {
ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size);
if (!ost->st->codec->subtitle_header) {
ret = AVERROR(ENOMEM);
goto dump_format;
}
memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);
ost->st->codec->subtitle_header_size = dec->subtitle_header_size;
}
if (avcodec_open(ost->st->codec, codec) < 0) {
snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height",
ost->file_index, ost->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
extra_size += ost->st->codec->extradata_size;
}
}
/* open each decoder */
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
if (ist->decoding_needed) {
AVCodec *codec = i < nb_input_codecs ? input_codecs[i] : NULL;
if (!codec)
codec = avcodec_find_decoder(ist->st->codec->codec_id);
if (!codec) {
snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d",
ist->st->codec->codec_id, ist->file_index, ist->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
if (avcodec_open(ist->st->codec, codec) < 0) {
snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d",
ist->file_index, ist->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
//if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
// ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD;
}
}
/* init pts */
for(i=0;i<nb_istreams;i++) {
AVStream *st;
ist = ist_table[i];
st= ist->st;
ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0;
ist->next_pts = AV_NOPTS_VALUE;
ist->is_start = 1;
}
/* set meta data information from input file if required */
for (i=0;i<nb_meta_data_maps;i++) {
AVFormatContext *files[2];
AVMetadata **meta[2];
int j;
#define METADATA_CHECK_INDEX(index, nb_elems, desc)\
if ((index) < 0 || (index) >= (nb_elems)) {\
snprintf(error, sizeof(error), "Invalid %s index %d while processing metadata maps\n",\
(desc), (index));\
ret = AVERROR(EINVAL);\
goto dump_format;\
}
int out_file_index = meta_data_maps[i][0].file;
int in_file_index = meta_data_maps[i][1].file;
if (in_file_index < 0 || out_file_index < 0)
continue;
METADATA_CHECK_INDEX(out_file_index, nb_output_files, "output file")
METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")
files[0] = output_files[out_file_index];
files[1] = input_files[in_file_index];
for (j = 0; j < 2; j++) {
AVMetaDataMap *map = &meta_data_maps[i][j];
switch (map->type) {
case 'g':
meta[j] = &files[j]->metadata;
break;
case 's':
METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream")
meta[j] = &files[j]->streams[map->index]->metadata;
break;
case 'c':
METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter")
meta[j] = &files[j]->chapters[map->index]->metadata;
break;
case 'p':
METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program")
meta[j] = &files[j]->programs[map->index]->metadata;
break;
}
}
av_metadata_copy(meta[0], *meta[1], AV_METADATA_DONT_OVERWRITE);
}
/* copy global metadata by default */
if (metadata_global_autocopy) {
for (i = 0; i < nb_output_files; i++)
av_metadata_copy(&output_files[i]->metadata, input_files[0]->metadata,
AV_METADATA_DONT_OVERWRITE);
}
/* copy chapters according to chapter maps */
for (i = 0; i < nb_chapter_maps; i++) {
int infile = chapter_maps[i].in_file;
int outfile = chapter_maps[i].out_file;
if (infile < 0 || outfile < 0)
continue;
if (infile >= nb_input_files) {
snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile);
ret = AVERROR(EINVAL);
goto dump_format;
}
if (outfile >= nb_output_files) {
snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile);
ret = AVERROR(EINVAL);
goto dump_format;
}
copy_chapters(infile, outfile);
}
/* copy chapters from the first input file that has them*/
if (!nb_chapter_maps)
for (i = 0; i < nb_input_files; i++) {
if (!input_files[i]->nb_chapters)
continue;
for (j = 0; j < nb_output_files; j++)
if ((ret = copy_chapters(i, j)) < 0)
goto dump_format;
break;
}
/* open files and write file headers */
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
if (av_write_header(os) < 0) {
snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i);
ret = AVERROR(EINVAL);
goto dump_format;
}
if (strcmp(output_files[i]->oformat->name, "rtp")) {
want_sdp = 0;
}
}
dump_format:
/* dump the file output parameters - cannot be done before in case
of stream copy */
for(i=0;i<nb_output_files;i++) {
av_dump_format(output_files[i], i, output_files[i]->filename, 1);
}
/* dump the stream mapping */
if (verbose >= 0) {
fprintf(stderr, "Stream mapping:\n");
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
fprintf(stderr, " Stream #%d.%d -> #%d.%d",
ist_table[ost->source_index]->file_index,
ist_table[ost->source_index]->index,
ost->file_index,
ost->index);
if (ost->sync_ist != ist_table[ost->source_index])
fprintf(stderr, " [sync #%d.%d]",
ost->sync_ist->file_index,
ost->sync_ist->index);
fprintf(stderr, "\n");
}
}
if (ret) {
fprintf(stderr, "%s\n", error);
goto fail;
}
if (want_sdp) {
print_sdp(output_files, nb_output_files);
}
if (!using_stdin) {
if(verbose >= 0)
fprintf(stderr, "Press [q] to stop encoding\n");
avio_set_interrupt_cb(decode_interrupt_cb);
}
term_init();
timer_start = av_gettime();
for(; received_sigterm == 0;) {
int file_index, ist_index;
AVPacket pkt;
double ipts_min;
double opts_min;
redo:
ipts_min= 1e100;
opts_min= 1e100;
/* if 'q' pressed, exits */
if (!using_stdin) {
if (q_pressed)
break;
/* read_key() returns 0 on EOF */
key = read_key();
if (key == 'q')
break;
}
/* select the stream that we must read now by looking at the
smallest output pts */
file_index = -1;
for(i=0;i<nb_ostreams;i++) {
double ipts, opts;
ost = ost_table[i];
os = output_files[ost->file_index];
ist = ist_table[ost->source_index];
if(ist->is_past_recording_time || no_packet[ist->file_index])
continue;
opts = ost->st->pts.val * av_q2d(ost->st->time_base);
ipts = (double)ist->pts;
if (!file_table[ist->file_index].eof_reached){
if(ipts < ipts_min) {
ipts_min = ipts;
if(input_sync ) file_index = ist->file_index;
}
if(opts < opts_min) {
opts_min = opts;
if(!input_sync) file_index = ist->file_index;
}
}
if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){
file_index= -1;
break;
}
}
/* if none, if is finished */
if (file_index < 0) {
if(no_packet_count){
no_packet_count=0;
memset(no_packet, 0, sizeof(no_packet));
usleep(10000);
continue;
}
break;
}
/* finish if limit size exhausted */
if (limit_filesize != 0 && limit_filesize <= avio_tell(output_files[0]->pb))
break;
/* read a frame from it and output it in the fifo */
is = input_files[file_index];
ret= av_read_frame(is, &pkt);
if(ret == AVERROR(EAGAIN)){
no_packet[file_index]=1;
no_packet_count++;
continue;
}
if (ret < 0) {
file_table[file_index].eof_reached = 1;
if (opt_shortest)
break;
else
continue;
}
no_packet_count=0;
memset(no_packet, 0, sizeof(no_packet));
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 >= file_table[file_index].nb_streams)
goto discard_packet;
ist_index = file_table[file_index].ist_index + pkt.stream_index;
ist = ist_table[ist_index];
if (ist->discard)
goto discard_packet;
if (pkt.dts != AV_NOPTS_VALUE)
pkt.dts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
if (pkt.pts != AV_NOPTS_VALUE)
pkt.pts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
if (pkt.stream_index < nb_input_files_ts_scale[file_index]
&& input_files_ts_scale[file_index][pkt.stream_index]){
if(pkt.pts != AV_NOPTS_VALUE)
pkt.pts *= input_files_ts_scale[file_index][pkt.stream_index];
if(pkt.dts != AV_NOPTS_VALUE)
pkt.dts *= input_files_ts_scale[file_index][pkt.stream_index];
}
// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec->codec_type);
if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != 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_pts;
if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){
input_files_ts_offset[ist->file_index]-= delta;
if (verbose > 2)
fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]);
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);
}
}
/* finish if recording time exhausted */
if (recording_time != INT64_MAX &&
av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000}) >= 0) {
ist->is_past_recording_time = 1;
goto discard_packet;
}
//fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
if (verbose >= 0)
fprintf(stderr, "Error while decoding stream #%d.%d\n",
ist->file_index, ist->index);
if (exit_on_error)
ffmpeg_exit(1);
av_free_packet(&pkt);
goto redo;
}
discard_packet:
av_free_packet(&pkt);
/* dump report by using the output first video and audio streams */
print_report(output_files, ost_table, nb_ostreams, 0);
}
/* at the end of stream, we must flush the decoder buffers */
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
if (ist->decoding_needed) {
output_packet(ist, i, ost_table, nb_ostreams, NULL);
}
}
term_exit();
/* write the trailer if needed and close file */
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
av_write_trailer(os);
}
/* dump report by using the first video and audio streams */
print_report(output_files, ost_table, nb_ostreams, 1);
/* close each encoder */
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost->encoding_needed) {
av_freep(&ost->st->codec->stats_in);
avcodec_close(ost->st->codec);
}
#if CONFIG_AVFILTER
avfilter_graph_free(&ost->graph);
#endif
}
/* close each decoder */
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
if (ist->decoding_needed) {
avcodec_close(ist->st->codec);
}
}
/* finished ! */
ret = 0;
fail:
av_freep(&bit_buffer);
av_free(file_table);
if (ist_table) {
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
av_free(ist);
}
av_free(ist_table);
}
if (ost_table) {
for(i=0;i<nb_ostreams;i++) {
ost = ost_table[i];
if (ost) {
if (ost->st->stream_copy)
av_freep(&ost->st->codec->extradata);
if (ost->logfile) {
fclose(ost->logfile);
ost->logfile = NULL;
}
av_fifo_free(ost->fifo); /* works even if fifo is not
initialized but set to zero */
av_freep(&ost->st->codec->subtitle_header);
av_free(ost->pict_tmp.data[0]);
av_free(ost->forced_kf_pts);
if (ost->video_resample)
sws_freeContext(ost->img_resample_ctx);
if (ost->resample)
audio_resample_close(ost->resample);
if (ost->reformat_ctx)
av_audio_convert_free(ost->reformat_ctx);
av_free(ost);
}
}
av_free(ost_table);
}
return ret;
}
| 4,491 |
qemu | 4a1418e07bdcfaa3177739e04707ecaec75d89e1 | 0 | static void kqemu_vfree(void *ptr)
{
/* may be useful some day, but currently we do not need to free */
}
| 4,492 |
qemu | 9bf3eb2ca542dd9306cb2e72fc68e02ba3e56e2e | 0 | static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
{
int cond;
TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
int l1 = gen_new_label();
int l2 = gen_new_label();
if (tf)
cond = TCG_COND_EQ;
else
cond = TCG_COND_NE;
gen_load_fpr32(fp0, fs);
gen_load_fpr32h(fph0, fs);
gen_load_fpr32(fp1, fd);
gen_load_fpr32h(fph1, fd);
get_fp_cond(r_tmp1);
tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
tcg_gen_mov_i32(fp1, fp0);
tcg_temp_free(fp0);
gen_set_label(l1);
tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
tcg_gen_mov_i32(fph1, fph0);
tcg_temp_free(fph0);
gen_set_label(l2);
tcg_temp_free(r_tmp1);
tcg_temp_free(r_tmp2);
gen_store_fpr32(fp1, fd);
gen_store_fpr32h(fph1, fd);
tcg_temp_free(fp1);
tcg_temp_free(fph1);
}
| 4,493 |
qemu | 70ae65f5d91462e1905a53236179fde21cda3a2f | 0 | static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val)
{
BMDMAState *bm = opaque;
PCIIDEState *pci_dev = pci_from_bm(bm);
#ifdef DEBUG_IDE
printf("bmdma: writeb 0x%02x : 0x%02x\n", addr, val);
#endif
switch(addr & 3) {
case 1:
pci_dev->dev.config[MRDMODE] =
(pci_dev->dev.config[MRDMODE] & ~0x30) | (val & 0x30);
cmd646_update_irq(pci_dev);
break;
case 2:
bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06);
break;
case 3:
if (bm->unit == 0)
pci_dev->dev.config[UDIDETCR0] = val;
else
pci_dev->dev.config[UDIDETCR1] = val;
break;
}
}
| 4,496 |
qemu | a8170e5e97ad17ca169c64ba87ae2f53850dab4c | 0 | static uint64_t empty_slot_read(void *opaque, target_phys_addr_t addr,
unsigned size)
{
DPRINTF("read from " TARGET_FMT_plx "\n", addr);
return 0;
}
| 4,497 |
qemu | e1f8c729fa890c67bb4532f22c22ace6fb0e1aaf | 0 | static pxa2xx_timer_info *pxa2xx_timer_init(target_phys_addr_t base,
qemu_irq *irqs)
{
int i;
int iomemtype;
pxa2xx_timer_info *s;
s = (pxa2xx_timer_info *) qemu_mallocz(sizeof(pxa2xx_timer_info));
s->irq_enabled = 0;
s->oldclock = 0;
s->clock = 0;
s->lastload = qemu_get_clock(vm_clock);
s->reset3 = 0;
for (i = 0; i < 4; i ++) {
s->timer[i].value = 0;
s->timer[i].irq = irqs[i];
s->timer[i].info = s;
s->timer[i].num = i;
s->timer[i].level = 0;
s->timer[i].qtimer = qemu_new_timer(vm_clock,
pxa2xx_timer_tick, &s->timer[i]);
}
iomemtype = cpu_register_io_memory(pxa2xx_timer_readfn,
pxa2xx_timer_writefn, s, DEVICE_NATIVE_ENDIAN);
cpu_register_physical_memory(base, 0x00001000, iomemtype);
register_savevm(NULL, "pxa2xx_timer", 0, 0,
pxa2xx_timer_save, pxa2xx_timer_load, s);
return s;
}
| 4,498 |
qemu | 9ea63c05d90ba85d819f9b2472ce6dfba7a403b4 | 0 | static int do_subchannel_work(SubchDev *sch)
{
if (sch->do_subchannel_work) {
return sch->do_subchannel_work(sch);
} else {
return -EINVAL;
}
}
| 4,499 |
qemu | eb05e011e248c6fb6baee295e14fd206e136028c | 0 | void block_job_enter(BlockJob *job)
{
if (job->co && !job->busy) {
bdrv_coroutine_enter(blk_bs(job->blk), job->co);
}
}
| 4,500 |
qemu | 480e79aedd322fcfac17052caff21626ea7c78e2 | 0 | static int get_physical_address (CPUMIPSState *env, hwaddr *physical,
int *prot, target_ulong real_address,
int rw, int access_type, int mmu_idx)
{
/* User mode can only access useg/xuseg */
int user_mode = mmu_idx == MIPS_HFLAG_UM;
int supervisor_mode = mmu_idx == MIPS_HFLAG_SM;
int kernel_mode = !user_mode && !supervisor_mode;
#if defined(TARGET_MIPS64)
int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0;
int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0;
int KX = (env->CP0_Status & (1 << CP0St_KX)) != 0;
#endif
int ret = TLBRET_MATCH;
/* effective address (modified for KVM T&E kernel segments) */
target_ulong address = real_address;
#define USEG_LIMIT 0x7FFFFFFFUL
#define KSEG0_BASE 0x80000000UL
#define KSEG1_BASE 0xA0000000UL
#define KSEG2_BASE 0xC0000000UL
#define KSEG3_BASE 0xE0000000UL
#define KVM_KSEG0_BASE 0x40000000UL
#define KVM_KSEG2_BASE 0x60000000UL
if (kvm_enabled()) {
/* KVM T&E adds guest kernel segments in useg */
if (real_address >= KVM_KSEG0_BASE) {
if (real_address < KVM_KSEG2_BASE) {
/* kseg0 */
address += KSEG0_BASE - KVM_KSEG0_BASE;
} else if (real_address <= USEG_LIMIT) {
/* kseg2/3 */
address += KSEG2_BASE - KVM_KSEG2_BASE;
}
}
}
if (address <= USEG_LIMIT) {
/* useg */
if (env->CP0_Status & (1 << CP0St_ERL)) {
*physical = address & 0xFFFFFFFF;
*prot = PAGE_READ | PAGE_WRITE;
} else {
ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
}
#if defined(TARGET_MIPS64)
} else if (address < 0x4000000000000000ULL) {
/* xuseg */
if (UX && address <= (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) {
ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
} else {
ret = TLBRET_BADADDR;
}
} else if (address < 0x8000000000000000ULL) {
/* xsseg */
if ((supervisor_mode || kernel_mode) &&
SX && address <= (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {
ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
} else {
ret = TLBRET_BADADDR;
}
} else if (address < 0xC000000000000000ULL) {
/* xkphys */
if (kernel_mode && KX &&
(address & 0x07FFFFFFFFFFFFFFULL) <= env->PAMask) {
*physical = address & env->PAMask;
*prot = PAGE_READ | PAGE_WRITE;
} else {
ret = TLBRET_BADADDR;
}
} else if (address < 0xFFFFFFFF80000000ULL) {
/* xkseg */
if (kernel_mode && KX &&
address <= (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) {
ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
} else {
ret = TLBRET_BADADDR;
}
#endif
} else if (address < (int32_t)KSEG1_BASE) {
/* kseg0 */
if (kernel_mode) {
*physical = address - (int32_t)KSEG0_BASE;
*prot = PAGE_READ | PAGE_WRITE;
} else {
ret = TLBRET_BADADDR;
}
} else if (address < (int32_t)KSEG2_BASE) {
/* kseg1 */
if (kernel_mode) {
*physical = address - (int32_t)KSEG1_BASE;
*prot = PAGE_READ | PAGE_WRITE;
} else {
ret = TLBRET_BADADDR;
}
} else if (address < (int32_t)KSEG3_BASE) {
/* sseg (kseg2) */
if (supervisor_mode || kernel_mode) {
ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
} else {
ret = TLBRET_BADADDR;
}
} else {
/* kseg3 */
/* XXX: debug segment is not emulated */
if (kernel_mode) {
ret = env->tlb->map_address(env, physical, prot, real_address, rw, access_type);
} else {
ret = TLBRET_BADADDR;
}
}
return ret;
}
| 4,501 |
FFmpeg | 979bea13003ef489d95d2538ac2fb1c26c6f103b | 0 | static int rv30_decode_mb_info(RV34DecContext *r)
{
static const int rv30_p_types[6] = { RV34_MB_SKIP, RV34_MB_P_16x16, RV34_MB_P_8x8, -1, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
static const int rv30_b_types[6] = { RV34_MB_SKIP, RV34_MB_B_DIRECT, RV34_MB_B_FORWARD, RV34_MB_B_BACKWARD, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
MpegEncContext *s = &r->s;
GetBitContext *gb = &s->gb;
int code = svq3_get_ue_golomb(gb);
if(code > 11){
av_log(s->avctx, AV_LOG_ERROR, "Incorrect MB type code\n");
return -1;
}
if(code > 5){
av_log(s->avctx, AV_LOG_ERROR, "dquant needed\n");
code -= 6;
}
if(s->pict_type != AV_PICTURE_TYPE_B)
return rv30_p_types[code];
else
return rv30_b_types[code];
}
| 4,502 |
qemu | 375092332eeaa6e47561ce47fd36144cdaf964d0 | 0 | static ssize_t test_block_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
Error **errp,
void *opaque)
{
Buffer *header = opaque;
g_assert_cmpint(buflen + offset, <=, header->capacity);
memcpy(header->buffer + offset, buf, buflen);
header->offset = offset + buflen;
return buflen;
}
| 4,503 |
qemu | 32bafa8fdd098d52fbf1102d5a5e48d29398c0aa | 0 | int net_init_vde(const NetClientOptions *opts, const char *name,
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
const NetdevVdeOptions *vde;
assert(opts->type == NET_CLIENT_OPTIONS_KIND_VDE);
vde = opts->u.vde;
/* missing optional values have been initialized to "all bits zero" */
if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group,
vde->has_mode ? vde->mode : 0700) == -1) {
return -1;
}
return 0;
}
| 4,504 |
qemu | 973945804d95878375b487c0c5c9b2556c5e4543 | 0 | static void tcx_rstip_writel(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
TCXState *s = opaque;
int i;
uint32_t col;
if (!(addr & 4)) {
s->tmpblit = val;
} else {
addr = (addr >> 3) & 0xfffff;
col = cpu_to_be32(s->tmpblit);
if (s->depth == 24) {
for (i = 0; i < 32; i++) {
if (val & 0x80000000) {
s->vram[addr + i] = s->tmpblit;
s->vram24[addr + i] = col;
s->cplane[addr + i] = col;
}
val <<= 1;
}
} else {
for (i = 0; i < 32; i++) {
if (val & 0x80000000) {
s->vram[addr + i] = s->tmpblit;
}
val <<= 1;
}
}
memory_region_set_dirty(&s->vram_mem, addr, 32);
}
}
| 4,505 |
qemu | c3109ba1b109f84929abbfe0462d910d5aa8617c | 0 | static int load_flat_file(struct linux_binprm * bprm,
struct lib_info *libinfo, int id, abi_ulong *extra_stack)
{
struct flat_hdr * hdr;
abi_ulong textpos = 0, datapos = 0;
abi_long result;
abi_ulong realdatastart = 0;
abi_ulong text_len, data_len, bss_len, stack_len, flags;
abi_ulong memp = 0; /* for finding the brk area */
abi_ulong extra;
abi_ulong reloc = 0, rp;
int i, rev, relocs = 0;
abi_ulong fpos;
abi_ulong start_code, end_code;
abi_ulong indx_len;
hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */
text_len = ntohl(hdr->data_start);
data_len = ntohl(hdr->data_end) - ntohl(hdr->data_start);
bss_len = ntohl(hdr->bss_end) - ntohl(hdr->data_end);
stack_len = ntohl(hdr->stack_size);
if (extra_stack) {
stack_len += *extra_stack;
*extra_stack = stack_len;
}
relocs = ntohl(hdr->reloc_count);
flags = ntohl(hdr->flags);
rev = ntohl(hdr->rev);
DBG_FLT("BINFMT_FLAT: Loading file: %s\n", bprm->filename);
if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) {
fprintf(stderr, "BINFMT_FLAT: bad magic/rev (0x%x, need 0x%x)\n",
rev, (int) FLAT_VERSION);
return -ENOEXEC;
}
/* Don't allow old format executables to use shared libraries */
if (rev == OLD_FLAT_VERSION && id != 0) {
fprintf(stderr, "BINFMT_FLAT: shared libraries are not available\n");
return -ENOEXEC;
}
/*
* fix up the flags for the older format, there were all kinds
* of endian hacks, this only works for the simple cases
*/
if (rev == OLD_FLAT_VERSION && flat_old_ram_flag(flags))
flags = FLAT_FLAG_RAM;
#ifndef CONFIG_BINFMT_ZFLAT
if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) {
fprintf(stderr, "Support for ZFLAT executables is not enabled\n");
return -ENOEXEC;
}
#endif
/*
* calculate the extra space we need to map in
*/
extra = relocs * sizeof(abi_ulong);
if (extra < bss_len + stack_len)
extra = bss_len + stack_len;
/* Add space for library base pointers. Make sure this does not
misalign the doesn't misalign the data segment. */
indx_len = MAX_SHARED_LIBS * sizeof(abi_ulong);
indx_len = (indx_len + 15) & ~(abi_ulong)15;
/*
* there are a couple of cases here, the separate code/data
* case, and then the fully copied to RAM case which lumps
* it all together.
*/
if ((flags & (FLAT_FLAG_RAM|FLAT_FLAG_GZIP)) == 0) {
/*
* this should give us a ROM ptr, but if it doesn't we don't
* really care
*/
DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n");
textpos = target_mmap(0, text_len, PROT_READ|PROT_EXEC,
MAP_PRIVATE, bprm->fd, 0);
if (textpos == -1) {
fprintf(stderr, "Unable to mmap process text\n");
return -1;
}
realdatastart = target_mmap(0, data_len + extra + indx_len,
PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (realdatastart == -1) {
fprintf(stderr, "Unable to allocate RAM for process data\n");
return realdatastart;
}
datapos = realdatastart + indx_len;
DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n",
(int)(data_len + bss_len + stack_len), (int)datapos);
fpos = ntohl(hdr->data_start);
#ifdef CONFIG_BINFMT_ZFLAT
if (flags & FLAT_FLAG_GZDATA) {
result = decompress_exec(bprm, fpos, (char *) datapos,
data_len + (relocs * sizeof(abi_ulong)))
} else
#endif
{
result = target_pread(bprm->fd, datapos,
data_len + (relocs * sizeof(abi_ulong)),
fpos);
}
if (result < 0) {
fprintf(stderr, "Unable to read data+bss\n");
return result;
}
reloc = datapos + (ntohl(hdr->reloc_start) - text_len);
memp = realdatastart;
} else {
textpos = target_mmap(0, text_len + data_len + extra + indx_len,
PROT_READ | PROT_EXEC | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (textpos == -1 ) {
fprintf(stderr, "Unable to allocate RAM for process text/data\n");
return -1;
}
realdatastart = textpos + ntohl(hdr->data_start);
datapos = realdatastart + indx_len;
reloc = (textpos + ntohl(hdr->reloc_start) + indx_len);
memp = textpos;
#ifdef CONFIG_BINFMT_ZFLAT
#error code needs checking
/*
* load it all in and treat it like a RAM load from now on
*/
if (flags & FLAT_FLAG_GZIP) {
result = decompress_exec(bprm, sizeof (struct flat_hdr),
(((char *) textpos) + sizeof (struct flat_hdr)),
(text_len + data_len + (relocs * sizeof(unsigned long))
- sizeof (struct flat_hdr)),
0);
memmove((void *) datapos, (void *) realdatastart,
data_len + (relocs * sizeof(unsigned long)));
} else if (flags & FLAT_FLAG_GZDATA) {
fpos = 0;
result = bprm->file->f_op->read(bprm->file,
(char *) textpos, text_len, &fpos);
if (result < (unsigned long) -4096)
result = decompress_exec(bprm, text_len, (char *) datapos,
data_len + (relocs * sizeof(unsigned long)), 0);
}
else
#endif
{
result = target_pread(bprm->fd, textpos,
text_len, 0);
if (result >= 0) {
result = target_pread(bprm->fd, datapos,
data_len + (relocs * sizeof(abi_ulong)),
ntohl(hdr->data_start));
}
}
if (result < 0) {
fprintf(stderr, "Unable to read code+data+bss\n");
return result;
}
}
DBG_FLT("Mapping is 0x%x, Entry point is 0x%x, data_start is 0x%x\n",
(int)textpos, 0x00ffffff&ntohl(hdr->entry),
ntohl(hdr->data_start));
/* The main program needs a little extra setup in the task structure */
start_code = textpos + sizeof (struct flat_hdr);
end_code = textpos + text_len;
DBG_FLT("%s %s: TEXT=%x-%x DATA=%x-%x BSS=%x-%x\n",
id ? "Lib" : "Load", bprm->filename,
(int) start_code, (int) end_code,
(int) datapos,
(int) (datapos + data_len),
(int) (datapos + data_len),
(int) (((datapos + data_len + bss_len) + 3) & ~3));
text_len -= sizeof(struct flat_hdr); /* the real code len */
/* Store the current module values into the global library structure */
libinfo[id].start_code = start_code;
libinfo[id].start_data = datapos;
libinfo[id].end_data = datapos + data_len;
libinfo[id].start_brk = datapos + data_len + bss_len;
libinfo[id].text_len = text_len;
libinfo[id].loaded = 1;
libinfo[id].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos;
libinfo[id].build_date = ntohl(hdr->build_date);
/*
* We just load the allocations into some temporary memory to
* help simplify all this mumbo jumbo
*
* We've got two different sections of relocation entries.
* The first is the GOT which resides at the begining of the data segment
* and is terminated with a -1. This one can be relocated in place.
* The second is the extra relocation entries tacked after the image's
* data segment. These require a little more processing as the entry is
* really an offset into the image which contains an offset into the
* image.
*/
if (flags & FLAT_FLAG_GOTPIC) {
rp = datapos;
while (1) {
abi_ulong addr;
if (get_user_ual(addr, rp))
return -EFAULT;
if (addr == -1)
break;
if (addr) {
addr = calc_reloc(addr, libinfo, id, 0);
if (addr == RELOC_FAILED)
return -ENOEXEC;
if (put_user_ual(addr, rp))
return -EFAULT;
}
rp += sizeof(abi_ulong);
}
}
/*
* Now run through the relocation entries.
* We've got to be careful here as C++ produces relocatable zero
* entries in the constructor and destructor tables which are then
* tested for being not zero (which will always occur unless we're
* based from address zero). This causes an endless loop as __start
* is at zero. The solution used is to not relocate zero addresses.
* This has the negative side effect of not allowing a global data
* reference to be statically initialised to _stext (I've moved
* __start to address 4 so that is okay).
*/
if (rev > OLD_FLAT_VERSION) {
for (i = 0; i < relocs; i++) {
abi_ulong addr, relval;
/* Get the address of the pointer to be
relocated (of course, the address has to be
relocated first). */
if (get_user_ual(relval, reloc + i * sizeof(abi_ulong)))
return -EFAULT;
addr = flat_get_relocate_addr(relval);
rp = calc_reloc(addr, libinfo, id, 1);
if (rp == RELOC_FAILED)
return -ENOEXEC;
/* Get the pointer's value. */
if (get_user_ual(addr, rp))
return -EFAULT;
if (addr != 0) {
/*
* Do the relocation. PIC relocs in the data section are
* already in target order
*/
#ifndef TARGET_WORDS_BIGENDIAN
if ((flags & FLAT_FLAG_GOTPIC) == 0)
addr = bswap32(addr);
#endif
addr = calc_reloc(addr, libinfo, id, 0);
if (addr == RELOC_FAILED)
return -ENOEXEC;
/* Write back the relocated pointer. */
if (put_user_ual(addr, rp))
return -EFAULT;
}
}
} else {
for (i = 0; i < relocs; i++) {
abi_ulong relval;
if (get_user_ual(relval, reloc + i * sizeof(abi_ulong)))
return -EFAULT;
old_reloc(&libinfo[0], relval);
}
}
/* zero the BSS. */
memset((void *)((unsigned long)datapos + data_len), 0, bss_len);
return 0;
}
| 4,506 |
qemu | bec1631100323fac0900aea71043d5c4e22fc2fa | 0 | static void tcg_out_bc(TCGContext *s, int bc, int label_index)
{
TCGLabel *l = &s->labels[label_index];
if (l->has_value) {
tcg_out32(s, bc | reloc_pc14_val(s->code_ptr, l->u.value_ptr));
} else {
tcg_out_reloc(s, s->code_ptr, R_PPC_REL14, label_index, 0);
tcg_out_bc_noaddr(s, bc);
}
}
| 4,507 |
qemu | 9f14b0add1dcdbfa2ee61051d068211fb0a1fcc9 | 0 | static void rng_egd_free_request(RngRequest *req)
{
g_free(req->data);
g_free(req);
}
| 4,508 |
qemu | a011898d25b8a26a311d56dfe37e8d3a4374ec65 | 0 | static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
uint64_t image_size, VHDXImageType type,
bool use_zero_blocks, uint64_t file_offset,
uint32_t length)
{
int ret = 0;
uint64_t data_file_offset;
uint64_t total_sectors = 0;
uint64_t sector_num = 0;
uint64_t unused;
int block_state;
VHDXSectorInfo sinfo;
assert(s->bat == NULL);
/* this gives a data start after BAT/bitmap entries, and well
* past any metadata entries (with a 4 MB buffer for future
* expansion */
data_file_offset = file_offset + length + 5 * MiB;
total_sectors = image_size >> s->logical_sector_size_bits;
if (type == VHDX_TYPE_DYNAMIC) {
/* All zeroes, so we can just extend the file - the end of the BAT
* is the furthest thing we have written yet */
ret = bdrv_truncate(bs, data_file_offset);
if (ret < 0) {
goto exit;
}
} else if (type == VHDX_TYPE_FIXED) {
ret = bdrv_truncate(bs, data_file_offset + image_size);
if (ret < 0) {
goto exit;
}
} else {
ret = -ENOTSUP;
goto exit;
}
if (type == VHDX_TYPE_FIXED ||
use_zero_blocks ||
bdrv_has_zero_init(bs) == 0) {
/* for a fixed file, the default BAT entry is not zero */
s->bat = g_try_malloc0(length);
if (length && s->bat != NULL) {
ret = -ENOMEM;
goto exit;
}
block_state = type == VHDX_TYPE_FIXED ? PAYLOAD_BLOCK_FULLY_PRESENT :
PAYLOAD_BLOCK_NOT_PRESENT;
block_state = use_zero_blocks ? PAYLOAD_BLOCK_ZERO : block_state;
/* fill the BAT by emulating sector writes of sectors_per_block size */
while (sector_num < total_sectors) {
vhdx_block_translate(s, sector_num, s->sectors_per_block, &sinfo);
sinfo.file_offset = data_file_offset +
(sector_num << s->logical_sector_size_bits);
sinfo.file_offset = ROUND_UP(sinfo.file_offset, MiB);
vhdx_update_bat_table_entry(bs, s, &sinfo, &unused, &unused,
block_state);
cpu_to_le64s(&s->bat[sinfo.bat_idx]);
sector_num += s->sectors_per_block;
}
ret = bdrv_pwrite(bs, file_offset, s->bat, length);
if (ret < 0) {
goto exit;
}
}
exit:
g_free(s->bat);
return ret;
}
| 4,509 |
qemu | aed6efb90cc43faf45f1e40425646c55d37a340f | 0 | int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset)
{
struct kvm_signal_mask *sigmask;
int r;
if (!sigset) {
return kvm_vcpu_ioctl(cpu, KVM_SET_SIGNAL_MASK, NULL);
}
sigmask = g_malloc(sizeof(*sigmask) + sizeof(*sigset));
sigmask->len = 8;
memcpy(sigmask->sigset, sigset, sizeof(*sigset));
r = kvm_vcpu_ioctl(cpu, KVM_SET_SIGNAL_MASK, sigmask);
g_free(sigmask);
return r;
}
| 4,510 |
FFmpeg | e701cd96c2d5dc034e7615967d208db3d953e111 | 0 | unsigned avutil_version(void)
{
av_assert0(AV_PIX_FMT_VDA_VLD == 81); //check if the pix fmt enum has not had anything inserted or removed by mistake
av_assert0(AV_SAMPLE_FMT_DBLP == 9);
av_assert0(AVMEDIA_TYPE_ATTACHMENT == 4);
av_assert0(AV_PICTURE_TYPE_BI == 7);
av_assert0(LIBAVUTIL_VERSION_MICRO >= 100);
av_assert0(HAVE_MMX2 == HAVE_MMXEXT);
if (av_sat_dadd32(1, 2) != 5) {
av_log(NULL, AV_LOG_FATAL, "Libavutil has been build with a broken binutils, please upgrade binutils and rebuild\n");
abort();
}
ff_check_pixfmt_descriptors();
return LIBAVUTIL_VERSION_INT;
}
| 4,512 |
FFmpeg | 281bde27894f994d0982ab9283f15d6073ae352c | 0 | static int udp_open(URLContext *h, const char *uri, int flags)
{
char hostname[1024], localaddr[1024] = "";
int port, udp_fd = -1, tmp, bind_ret = -1;
UDPContext *s = h->priv_data;
int is_output;
const char *p;
char buf[256];
struct sockaddr_storage my_addr;
int len;
int reuse_specified = 0;
h->is_streamed = 1;
h->max_packet_size = 1472;
is_output = !(flags & AVIO_FLAG_READ);
s->ttl = 16;
s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
s->circular_buffer_size = 7*188*4096;
p = strchr(uri, '?');
if (p) {
if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) {
char *endptr = NULL;
s->reuse_socket = strtol(buf, &endptr, 10);
/* assume if no digits were found it is a request to enable it */
if (buf == endptr)
s->reuse_socket = 1;
reuse_specified = 1;
}
if (av_find_info_tag(buf, sizeof(buf), "overrun_nonfatal", p)) {
char *endptr = NULL;
s->overrun_nonfatal = strtol(buf, &endptr, 10);
/* assume if no digits were found it is a request to enable it */
if (buf == endptr)
s->overrun_nonfatal = 1;
}
if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
s->ttl = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
s->local_port = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
h->max_packet_size = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
s->buffer_size = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
s->is_connected = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "fifo_size", p)) {
s->circular_buffer_size = strtol(buf, NULL, 10)*188;
}
if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
av_strlcpy(localaddr, buf, sizeof(localaddr));
}
}
/* fill the dest addr */
av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
/* XXX: fix av_url_split */
if (hostname[0] == '\0' || hostname[0] == '?') {
/* only accepts null hostname if input */
if (!(flags & AVIO_FLAG_READ))
goto fail;
} else {
if (ff_udp_set_remote_url(h, uri) < 0)
goto fail;
}
if ((s->is_multicast || !s->local_port) && (h->flags & AVIO_FLAG_READ))
s->local_port = port;
udp_fd = udp_socket_create(s, &my_addr, &len, localaddr);
if (udp_fd < 0)
goto fail;
/* Follow the requested reuse option, unless it's multicast in which
* case enable reuse unless explicitly disabled.
*/
if (s->reuse_socket || (s->is_multicast && !reuse_specified)) {
s->reuse_socket = 1;
if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
goto fail;
}
/* If multicast, try binding the multicast address first, to avoid
* receiving UDP packets from other sources aimed at the same UDP
* port. This fails on windows. This makes sending to the same address
* using sendto() fail, so only do it if we're opened in read-only mode. */
if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE)) {
bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);
}
/* bind to the local address if not multicast or if the multicast
* bind failed */
/* the bind is needed to give a port to the socket now */
if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) {
av_log(h, AV_LOG_ERROR, "bind failed: %s\n", strerror(errno));
goto fail;
}
len = sizeof(my_addr);
getsockname(udp_fd, (struct sockaddr *)&my_addr, &len);
s->local_port = udp_port(&my_addr, len);
if (s->is_multicast) {
if (h->flags & AVIO_FLAG_WRITE) {
/* output */
if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
goto fail;
}
if (h->flags & AVIO_FLAG_READ) {
/* input */
if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0)
goto fail;
}
}
if (is_output) {
/* limit the tx buf size to limit latency */
tmp = s->buffer_size;
if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
av_log(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno));
goto fail;
}
} else {
/* set udp recv buffer size to the largest possible udp packet size to
* avoid losing data on OSes that set this too low by default. */
tmp = s->buffer_size;
if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
av_log(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno));
}
/* make the socket non-blocking */
ff_socket_nonblock(udp_fd, 1);
}
if (s->is_connected) {
if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) {
av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno));
goto fail;
}
}
s->udp_fd = udp_fd;
#if HAVE_PTHREADS
if (!is_output && s->circular_buffer_size) {
int ret;
/* start the task going */
s->fifo = av_fifo_alloc(s->circular_buffer_size);
ret = pthread_mutex_init(&s->mutex, NULL);
if (ret != 0) {
av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));
goto fail;
}
ret = pthread_cond_init(&s->cond, NULL);
if (ret != 0) {
av_log(h, AV_LOG_ERROR, "pthread_cond_init failed : %s\n", strerror(ret));
goto cond_fail;
}
ret = pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h);
if (ret != 0) {
av_log(h, AV_LOG_ERROR, "pthread_create failed : %s\n", strerror(ret));
goto thread_fail;
}
s->thread_started = 1;
}
#endif
return 0;
#if HAVE_PTHREADS
thread_fail:
pthread_cond_destroy(&s->cond);
cond_fail:
pthread_mutex_destroy(&s->mutex);
#endif
fail:
if (udp_fd >= 0)
closesocket(udp_fd);
av_fifo_free(s->fifo);
return AVERROR(EIO);
}
| 4,513 |
FFmpeg | 919f3554387e043bdfe10c6369356d1104882183 | 1 | static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt) {
const uint8_t *buf = avpkt->data;
TXDContext * const s = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p = &s->picture;
unsigned int version, w, h, d3d_format, depth, stride, mipmap_count, flags;
unsigned int y, v;
uint8_t *ptr;
const uint8_t *cur = buf;
const uint32_t *palette = (const uint32_t *)(cur + 88);
uint32_t *pal;
version = AV_RL32(cur);
d3d_format = AV_RL32(cur+76);
w = AV_RL16(cur+80);
h = AV_RL16(cur+82);
depth = AV_RL8 (cur+84);
mipmap_count = AV_RL8 (cur+85);
flags = AV_RL8 (cur+87);
cur += 92;
if (version < 8 || version > 9) {
av_log(avctx, AV_LOG_ERROR, "texture data version %i is unsupported\n",
version);
return -1;
}
if (depth == 8) {
avctx->pix_fmt = PIX_FMT_PAL8;
cur += 1024;
} else if (depth == 16 || depth == 32)
avctx->pix_fmt = PIX_FMT_RGB32;
else {
av_log(avctx, AV_LOG_ERROR, "depth of %i is unsupported\n", depth);
return -1;
}
if (p->data[0])
avctx->release_buffer(avctx, p);
if (av_image_check_size(w, h, 0, avctx))
return -1;
if (w != avctx->width || h != avctx->height)
avcodec_set_dimensions(avctx, w, h);
if (avctx->get_buffer(avctx, p) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
p->pict_type = AV_PICTURE_TYPE_I;
ptr = p->data[0];
stride = p->linesize[0];
if (depth == 8) {
pal = (uint32_t *) p->data[1];
for (y=0; y<256; y++) {
v = AV_RB32(palette+y);
pal[y] = (v>>8) + (v<<24);
}
for (y=0; y<h; y++) {
memcpy(ptr, cur, w);
ptr += stride;
cur += w;
}
} else if (depth == 16) {
switch (d3d_format) {
case 0:
if (!(flags & 1))
goto unsupported;
case FF_S3TC_DXT1:
ff_decode_dxt1(cur, ptr, w, h, stride);
break;
case FF_S3TC_DXT3:
ff_decode_dxt3(cur, ptr, w, h, stride);
break;
default:
goto unsupported;
}
} else if (depth == 32) {
switch (d3d_format) {
case 0x15:
case 0x16:
for (y=0; y<h; y++) {
memcpy(ptr, cur, w*4);
ptr += stride;
cur += w*4;
}
break;
default:
goto unsupported;
}
}
for (; mipmap_count > 1; mipmap_count--)
cur += AV_RL32(cur) + 4;
*picture = s->picture;
*data_size = sizeof(AVPicture);
return cur - buf;
unsupported:
av_log(avctx, AV_LOG_ERROR, "unsupported d3d format (%08x)\n", d3d_format);
return -1;
}
| 4,515 |
qemu | a8f2e5c8fffbaf7fbd4f0efc8efbeebade78008f | 1 | void virtio_scsi_dataplane_start(VirtIOSCSI *s)
{
int i;
int rc;
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
if (s->dataplane_started ||
s->dataplane_starting ||
s->dataplane_fenced ||
s->ctx != iothread_get_aio_context(vs->conf.iothread)) {
return;
}
s->dataplane_starting = true;
/* Set up guest notifier (irq) */
rc = k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, true);
if (rc != 0) {
fprintf(stderr, "virtio-scsi: Failed to set guest notifiers (%d), "
"ensure -enable-kvm is set\n", rc);
goto fail_guest_notifiers;
}
aio_context_acquire(s->ctx);
rc = virtio_scsi_vring_init(s, vs->ctrl_vq, 0);
if (rc) {
goto fail_vrings;
}
rc = virtio_scsi_vring_init(s, vs->event_vq, 1);
if (rc) {
goto fail_vrings;
}
for (i = 0; i < vs->conf.num_queues; i++) {
rc = virtio_scsi_vring_init(s, vs->cmd_vqs[i], i + 2);
if (rc) {
goto fail_vrings;
}
}
s->dataplane_starting = false;
s->dataplane_started = true;
aio_context_release(s->ctx);
return;
fail_vrings:
virtio_scsi_clear_aio(s);
aio_context_release(s->ctx);
for (i = 0; i < vs->conf.num_queues + 2; i++) {
k->set_host_notifier(qbus->parent, i, false);
}
k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);
fail_guest_notifiers:
s->dataplane_fenced = true;
s->dataplane_starting = false;
s->dataplane_started = true;
}
| 4,516 |
qemu | c2d76497b6eafcaedc806e07804e7bed55a98a0b | 1 | int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
BlockDriver *drv)
{
int ret;
char tmp_filename[PATH_MAX];
if (flags & BDRV_O_SNAPSHOT) {
BlockDriverState *bs1;
int64_t total_size;
int is_protocol = 0;
BlockDriver *bdrv_qcow2;
QEMUOptionParameter *options;
char backing_filename[PATH_MAX];
/* if snapshot, we create a temporary backing file and open it
instead of opening 'filename' directly */
/* if there is a backing file, use it */
bs1 = bdrv_new("");
ret = bdrv_open(bs1, filename, 0, drv);
if (ret < 0) {
bdrv_delete(bs1);
return ret;
}
total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK;
if (bs1->drv && bs1->drv->protocol_name)
is_protocol = 1;
bdrv_delete(bs1);
get_tmp_filename(tmp_filename, sizeof(tmp_filename));
/* Real path is meaningless for protocols */
if (is_protocol)
snprintf(backing_filename, sizeof(backing_filename),
"%s", filename);
else if (!realpath(filename, backing_filename))
return -errno;
bdrv_qcow2 = bdrv_find_format("qcow2");
options = parse_option_parameters("", bdrv_qcow2->create_options, NULL);
set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size);
set_option_parameter(options, BLOCK_OPT_BACKING_FILE, backing_filename);
if (drv) {
set_option_parameter(options, BLOCK_OPT_BACKING_FMT,
drv->format_name);
}
ret = bdrv_create(bdrv_qcow2, tmp_filename, options);
free_option_parameters(options);
if (ret < 0) {
return ret;
}
filename = tmp_filename;
drv = bdrv_qcow2;
bs->is_temporary = 1;
}
/* Find the right image format driver */
if (!drv) {
ret = find_image_format(filename, &drv);
}
if (!drv) {
goto unlink_and_fail;
}
/* Open the image */
ret = bdrv_open_common(bs, filename, flags, drv);
if (ret < 0) {
goto unlink_and_fail;
}
/* If there is a backing file, use it */
if ((flags & BDRV_O_NO_BACKING) == 0 && bs->backing_file[0] != '\0') {
char backing_filename[PATH_MAX];
int back_flags;
BlockDriver *back_drv = NULL;
bs->backing_hd = bdrv_new("");
bdrv_get_full_backing_filename(bs, backing_filename,
sizeof(backing_filename));
if (bs->backing_format[0] != '\0') {
back_drv = bdrv_find_format(bs->backing_format);
}
/* backing files always opened read-only */
back_flags =
flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
ret = bdrv_open(bs->backing_hd, backing_filename, back_flags, back_drv);
if (ret < 0) {
bdrv_close(bs);
return ret;
}
if (bs->is_temporary) {
bs->backing_hd->keep_read_only = !(flags & BDRV_O_RDWR);
} else {
/* base image inherits from "parent" */
bs->backing_hd->keep_read_only = bs->keep_read_only;
}
}
if (!bdrv_key_required(bs)) {
bdrv_dev_change_media_cb(bs, true);
}
/* throttling disk I/O limits */
if (bs->io_limits_enabled) {
bdrv_io_limits_enable(bs);
}
return 0;
unlink_and_fail:
if (bs->is_temporary) {
unlink(filename);
}
return ret;
}
| 4,517 |
qemu | 5935ee072d6fbcdf28ff6132ba6d8c3a1356bb0a | 1 | void helper_booke206_tlbwe(void)
{
uint32_t tlbncfg, tlbn;
ppcmas_tlb_t *tlb;
uint32_t size_tlb, size_ps;
switch (env->spr[SPR_BOOKE_MAS0] & MAS0_WQ_MASK) {
case MAS0_WQ_ALWAYS:
/* good to go, write that entry */
break;
case MAS0_WQ_COND:
/* XXX check if reserved */
if (0) {
return;
break;
case MAS0_WQ_CLR_RSRV:
/* XXX clear entry */
return;
default:
/* no idea what to do */
return;
if (((env->spr[SPR_BOOKE_MAS0] & MAS0_ATSEL) == MAS0_ATSEL_LRAT) &&
!msr_gs) {
/* XXX we don't support direct LRAT setting yet */
fprintf(stderr, "cpu: don't support LRAT setting yet\n");
return;
tlbn = (env->spr[SPR_BOOKE_MAS0] & MAS0_TLBSEL_MASK) >> MAS0_TLBSEL_SHIFT;
tlbncfg = env->spr[SPR_BOOKE_TLB0CFG + tlbn];
tlb = booke206_cur_tlb(env);
if (msr_gs) {
cpu_abort(env, "missing HV implementation\n");
tlb->mas7_3 = ((uint64_t)env->spr[SPR_BOOKE_MAS7] << 32) |
env->spr[SPR_BOOKE_MAS3];
tlb->mas1 = env->spr[SPR_BOOKE_MAS1];
/* XXX needs to change when supporting 64-bit e500 */
tlb->mas2 = env->spr[SPR_BOOKE_MAS2] & 0xffffffff;
if (!(tlbncfg & TLBnCFG_IPROT)) {
/* no IPROT supported by TLB */
tlb->mas1 &= ~MAS1_IPROT;
if (booke206_tlb_to_page_size(env, tlb) == TARGET_PAGE_SIZE) {
tlb_flush_page(env, tlb->mas2 & MAS2_EPN_MASK);
} else {
tlb_flush(env, 1); | 4,518 |
qemu | ad5afd07b628cd0610ea322ad60b5ad03aa250c8 | 1 | static void s390_qemu_cpu_model_initfn(Object *obj)
{
} | 4,520 |
FFmpeg | 6f3d2fb18bb6225c27e22a95846c42f2093dc3b7 | 0 | static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
{
AVFilterContext *ctx = inlink->dst;
TileContext *tile = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
if (tile->current)
return 0;
outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
outlink->w, outlink->h);
avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
outlink->out_buf->video->w = outlink->w;
outlink->out_buf->video->h = outlink->h;
/* fill surface once for margin/padding */
if (tile->margin || tile->padding)
ff_fill_rectangle(&tile->draw, &tile->blank,
outlink->out_buf->data, outlink->out_buf->linesize,
0, 0, outlink->w, outlink->h);
return 0;
}
| 4,523 |
FFmpeg | 931da6a5e9dd54563fe5d4d30b7bd4d0a0218c87 | 0 | static int v4l2_read_header(AVFormatContext *ctx)
{
struct video_data *s = ctx->priv_data;
AVStream *st;
int res = 0;
uint32_t desired_format;
enum AVCodecID codec_id = AV_CODEC_ID_NONE;
enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
struct v4l2_input input = { 0 };
st = avformat_new_stream(ctx, NULL);
if (!st)
return AVERROR(ENOMEM);
#if CONFIG_LIBV4L2
/* silence libv4l2 logging. if fopen() fails v4l2_log_file will be NULL
and errors will get sent to stderr */
if (s->use_libv4l2)
v4l2_log_file = fopen("/dev/null", "w");
#endif
s->fd = device_open(ctx);
if (s->fd < 0)
return s->fd;
if (s->channel != -1) {
/* set video input */
av_log(ctx, AV_LOG_DEBUG, "Selecting input_channel: %d\n", s->channel);
if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &s->channel) < 0) {
res = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_S_INPUT): %s\n", av_err2str(res));
goto fail;
}
} else {
/* get current video input */
if (v4l2_ioctl(s->fd, VIDIOC_G_INPUT, &s->channel) < 0) {
res = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_G_INPUT): %s\n", av_err2str(res));
goto fail;
}
}
/* enum input */
input.index = s->channel;
if (v4l2_ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
res = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMINPUT): %s\n", av_err2str(res));
goto fail;
}
s->std_id = input.std;
av_log(ctx, AV_LOG_DEBUG, "Current input_channel: %d, input_name: %s, input_std: %"PRIx64"\n",
s->channel, input.name, (uint64_t)input.std);
if (s->list_format) {
list_formats(ctx, s->list_format);
res = AVERROR_EXIT;
goto fail;
}
if (s->list_standard) {
list_standards(ctx);
res = AVERROR_EXIT;
goto fail;
}
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
if ((res = v4l2_set_parameters(ctx)) < 0)
goto fail;
if (s->pixel_format) {
AVCodec *codec = avcodec_find_decoder_by_name(s->pixel_format);
if (codec)
ctx->video_codec_id = codec->id;
pix_fmt = av_get_pix_fmt(s->pixel_format);
if (pix_fmt == AV_PIX_FMT_NONE && !codec) {
av_log(ctx, AV_LOG_ERROR, "No such input format: %s.\n",
s->pixel_format);
res = AVERROR(EINVAL);
goto fail;
}
}
if (!s->width && !s->height) {
struct v4l2_format fmt = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE };
av_log(ctx, AV_LOG_VERBOSE,
"Querying the device for the current frame size\n");
if (v4l2_ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
res = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", av_err2str(res));
goto fail;
}
s->width = fmt.fmt.pix.width;
s->height = fmt.fmt.pix.height;
av_log(ctx, AV_LOG_VERBOSE,
"Setting frame size to %dx%d\n", s->width, s->height);
}
res = device_try_init(ctx, pix_fmt, &s->width, &s->height, &desired_format, &codec_id);
if (res < 0)
goto fail;
/* If no pixel_format was specified, the codec_id was not known up
* until now. Set video_codec_id in the context, as codec_id will
* not be available outside this function
*/
if (codec_id != AV_CODEC_ID_NONE && ctx->video_codec_id == AV_CODEC_ID_NONE)
ctx->video_codec_id = codec_id;
if ((res = av_image_check_size(s->width, s->height, 0, ctx)) < 0)
goto fail;
s->frame_format = desired_format;
st->codec->pix_fmt = avpriv_fmt_v4l2ff(desired_format, codec_id);
s->frame_size =
avpicture_get_size(st->codec->pix_fmt, s->width, s->height);
if ((res = mmap_init(ctx)) ||
(res = mmap_start(ctx)) < 0)
goto fail;
s->top_field_first = first_field(s);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = codec_id;
if (codec_id == AV_CODEC_ID_RAWVIDEO)
st->codec->codec_tag =
avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
else if (codec_id == AV_CODEC_ID_H264) {
st->need_parsing = AVSTREAM_PARSE_HEADERS;
}
if (desired_format == V4L2_PIX_FMT_YVU420)
st->codec->codec_tag = MKTAG('Y', 'V', '1', '2');
else if (desired_format == V4L2_PIX_FMT_YVU410)
st->codec->codec_tag = MKTAG('Y', 'V', 'U', '9');
st->codec->width = s->width;
st->codec->height = s->height;
if (st->avg_frame_rate.den)
st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
return 0;
fail:
v4l2_close(s->fd);
return res;
}
| 4,526 |
FFmpeg | 8c55ff393340998faae887dfac19e7ef128e1e58 | 0 | static int output_frame(H264Context *h, AVFrame *dst, Picture *srcp)
{
AVFrame *src = &srcp->f;
int i;
int ret = av_frame_ref(dst, src);
if (ret < 0)
return ret;
av_dict_set(&dst->metadata, "stereo_mode", ff_h264_sei_stereo_mode(h), 0);
if (!srcp->crop)
return 0;
for (i = 0; i < 3; i++) {
int hshift = (i > 0) ? h->chroma_x_shift : 0;
int vshift = (i > 0) ? h->chroma_y_shift : 0;
int off = ((srcp->crop_left >> hshift) << h->pixel_shift) +
(srcp->crop_top >> vshift) * dst->linesize[i];
dst->data[i] += off;
}
return 0;
}
| 4,527 |
FFmpeg | 0c1959b056f6ccaa2eee2c824352ba93c8e36d52 | 0 | static int flac_write_header(struct AVFormatContext *s)
{
int ret;
AVCodecContext *codec = s->streams[0]->codec;
FlacMuxerContext *c = s->priv_data;
if (!c->write_header)
return 0;
ret = ff_flac_write_header(s->pb, codec, 0);
if (ret)
return ret;
ret = flac_write_block_comment(s->pb, &s->metadata, 0,
codec->flags & CODEC_FLAG_BITEXACT);
if (ret)
return ret;
/* The command line flac encoder defaults to placing a seekpoint
* every 10s. So one might add padding to allow that later
* but there seems to be no simple way to get the duration here.
* So let's try the flac default of 8192 bytes */
flac_write_block_padding(s->pb, 8192, 1);
return ret;
}
| 4,528 |
FFmpeg | a1335149fd610b16459d9281b611282cac51c950 | 0 | int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
{
int opaque_alloc = 0;
int ret;
q->param.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
q->param.AsyncDepth = q->async_depth;
q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
(sizeof(AVPacket) + sizeof(mfxSyncPoint) + sizeof(mfxBitstream*)));
if (!q->async_fifo)
return AVERROR(ENOMEM);
if (avctx->hwaccel_context) {
AVQSVContext *qsv = avctx->hwaccel_context;
q->session = qsv->session;
q->param.IOPattern = qsv->iopattern;
opaque_alloc = qsv->opaque_alloc;
}
if (!q->session) {
ret = ff_qsv_init_internal_session(avctx, &q->internal_session,
q->load_plugins);
if (ret < 0)
return ret;
q->session = q->internal_session;
}
ret = init_video_param(avctx, q);
if (ret < 0)
return ret;
ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error querying the encoding parameters\n");
return ff_qsv_error(ret);
}
if (opaque_alloc) {
ret = qsv_init_opaque_alloc(avctx, q);
if (ret < 0)
return ret;
}
if (avctx->hwaccel_context) {
AVQSVContext *qsv = avctx->hwaccel_context;
int i, j;
q->extparam = av_mallocz_array(qsv->nb_ext_buffers + q->nb_extparam_internal,
sizeof(*q->extparam));
if (!q->extparam)
return AVERROR(ENOMEM);
q->param.ExtParam = q->extparam;
for (i = 0; i < qsv->nb_ext_buffers; i++)
q->param.ExtParam[i] = qsv->ext_buffers[i];
q->param.NumExtParam = qsv->nb_ext_buffers;
for (i = 0; i < q->nb_extparam_internal; i++) {
for (j = 0; j < qsv->nb_ext_buffers; j++) {
if (qsv->ext_buffers[j]->BufferId == q->extparam_internal[i]->BufferId)
break;
}
if (j < qsv->nb_ext_buffers)
continue;
q->param.ExtParam[q->param.NumExtParam++] = q->extparam_internal[i];
}
} else {
q->param.ExtParam = q->extparam_internal;
q->param.NumExtParam = q->nb_extparam_internal;
}
ret = MFXVideoENCODE_Init(q->session, &q->param);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n");
return ff_qsv_error(ret);
}
ret = qsv_retrieve_enc_params(avctx, q);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error retrieving encoding parameters.\n");
return ret;
}
q->avctx = avctx;
return 0;
}
| 4,529 |
qemu | 88affa1c77c9019f3450f851495997897bd14e40 | 1 | void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const char *fmt, ...))
{
unsigned int i;
for (i = 0; i < TRACE_BUF_LEN; i++) {
TraceRecord record;
if (!get_trace_record(i, &record)) {
continue;
}
stream_printf(stream, "Event %" PRIu64 " : %" PRIx64 " %" PRIx64
" %" PRIx64 " %" PRIx64 " %" PRIx64 " %" PRIx64 "\n",
record.event, record.x1, record.x2,
record.x3, record.x4, record.x5,
record.x6);
}
}
| 4,531 |
FFmpeg | 993092dcd3fb7ec84fdd1cd3b28a3973740b22bf | 0 | static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) {
GetBitContext *gb=&vc->gb;
uint_fast16_t i,j,k;
vc->floor_count=get_bits(gb, 6)+1;
vc->floors=av_mallocz(vc->floor_count * sizeof(vorbis_floor));
for (i=0;i<vc->floor_count;++i) {
vorbis_floor *floor_setup=&vc->floors[i];
floor_setup->floor_type=get_bits(gb, 16);
AV_DEBUG(" %d. floor type %d \n", i, floor_setup->floor_type);
if (floor_setup->floor_type==1) {
uint_fast8_t maximum_class=0;
uint_fast8_t rangebits;
uint_fast16_t floor1_values=2;
floor_setup->decode=vorbis_floor1_decode;
floor_setup->data.t1.partitions=get_bits(gb, 5);
AV_DEBUG(" %d.floor: %d partitions \n", i, floor_setup->data.t1.partitions);
for(j=0;j<floor_setup->data.t1.partitions;++j) {
floor_setup->data.t1.partition_class[j]=get_bits(gb, 4);
if (floor_setup->data.t1.partition_class[j]>maximum_class) maximum_class=floor_setup->data.t1.partition_class[j];
AV_DEBUG(" %d. floor %d partition class %d \n", i, j, floor_setup->data.t1.partition_class[j]);
}
AV_DEBUG(" maximum class %d \n", maximum_class);
floor_setup->data.t1.maximum_class=maximum_class;
for(j=0;j<=maximum_class;++j) {
floor_setup->data.t1.class_dimensions[j]=get_bits(gb, 3)+1;
floor_setup->data.t1.class_subclasses[j]=get_bits(gb, 2);
AV_DEBUG(" %d floor %d class dim: %d subclasses %d \n", i, j, floor_setup->data.t1.class_dimensions[j], floor_setup->data.t1.class_subclasses[j]);
if (floor_setup->data.t1.class_subclasses[j]) {
floor_setup->data.t1.class_masterbook[j]=get_bits(gb, 8);
AV_DEBUG(" masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]);
}
for(k=0;k<(1<<floor_setup->data.t1.class_subclasses[j]);++k) {
floor_setup->data.t1.subclass_books[j][k]=(int16_t)get_bits(gb, 8)-1;
AV_DEBUG(" book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]);
}
}
floor_setup->data.t1.multiplier=get_bits(gb, 2)+1;
floor_setup->data.t1.x_list_dim=2;
for(j=0;j<floor_setup->data.t1.partitions;++j) {
floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];
}
floor_setup->data.t1.list=av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(vorbis_floor1_entry));
rangebits=get_bits(gb, 4);
floor_setup->data.t1.list[0].x = 0;
floor_setup->data.t1.list[1].x = (1<<rangebits);
for(j=0;j<floor_setup->data.t1.partitions;++j) {
for(k=0;k<floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) {
floor_setup->data.t1.list[floor1_values].x=get_bits(gb, rangebits);
AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x);
}
}
// Precalculate order of x coordinates - needed for decode
ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim);
}
else if(floor_setup->floor_type==0) {
uint_fast8_t max_codebook_dim=0;
floor_setup->decode=vorbis_floor0_decode;
floor_setup->data.t0.order=get_bits(gb, 8);
floor_setup->data.t0.rate=get_bits(gb, 16);
floor_setup->data.t0.bark_map_size=get_bits(gb, 16);
floor_setup->data.t0.amplitude_bits=get_bits(gb, 6);
/* zero would result in a div by zero later *
* 2^0 - 1 == 0 */
if (floor_setup->data.t0.amplitude_bits == 0) {
av_log(vc->avccontext, AV_LOG_ERROR,
"Floor 0 amplitude bits is 0.\n");
return 1;
}
floor_setup->data.t0.amplitude_offset=get_bits(gb, 8);
floor_setup->data.t0.num_books=get_bits(gb, 4)+1;
/* allocate mem for booklist */
floor_setup->data.t0.book_list=
av_malloc(floor_setup->data.t0.num_books);
if(!floor_setup->data.t0.book_list) { return 1; }
/* read book indexes */
{
int idx;
uint_fast8_t book_idx;
for (idx=0;idx<floor_setup->data.t0.num_books;++idx) {
book_idx=get_bits(gb, 8);
if (book_idx>=vc->codebook_count)
return 1;
floor_setup->data.t0.book_list[idx]=book_idx;
if (vc->codebooks[book_idx].dimensions > max_codebook_dim)
max_codebook_dim=vc->codebooks[book_idx].dimensions;
}
}
create_map( vc, i );
/* allocate mem for lsp coefficients */
{
/* codebook dim is for padding if codebook dim doesn't *
* divide order+1 then we need to read more data */
floor_setup->data.t0.lsp=
av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim)
* sizeof(float));
if(!floor_setup->data.t0.lsp) { return 1; }
}
#ifdef V_DEBUG /* debug output parsed headers */
AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order);
AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate);
AV_DEBUG("floor0 bark map size: %u\n",
floor_setup->data.t0.bark_map_size);
AV_DEBUG("floor0 amplitude bits: %u\n",
floor_setup->data.t0.amplitude_bits);
AV_DEBUG("floor0 amplitude offset: %u\n",
floor_setup->data.t0.amplitude_offset);
AV_DEBUG("floor0 number of books: %u\n",
floor_setup->data.t0.num_books);
AV_DEBUG("floor0 book list pointer: %p\n",
floor_setup->data.t0.book_list);
{
int idx;
for (idx=0;idx<floor_setup->data.t0.num_books;++idx) {
AV_DEBUG( " Book %d: %u\n",
idx+1,
floor_setup->data.t0.book_list[idx] );
}
}
#endif
}
else {
av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n");
return 1;
}
}
return 0;
}
| 4,532 |
qemu | 9fac18f03a9040b67ec38e14d3e1ed34db9c7e06 | 1 | void qemu_anon_ram_free(void *ptr, size_t size)
{
trace_qemu_anon_ram_free(ptr, size);
if (ptr) {
munmap(ptr, size);
}
}
| 4,533 |
qemu | ca5a2a4b12bd44762a5106c9352eafd878bbd52f | 1 | void qemu_run_all_timers(void)
{
/* rearm timer, if not periodic */
if (alarm_timer->expired) {
alarm_timer->expired = 0;
qemu_rearm_alarm_timer(alarm_timer);
}
alarm_timer->pending = 0;
/* vm time timers */
if (vm_running) {
qemu_run_timers(vm_clock);
}
qemu_run_timers(rt_clock);
qemu_run_timers(host_clock);
}
| 4,534 |
qemu | c8057f951d64de93bfd01569c0a725baa9f94372 | 1 | static void mips_jazz_init(MemoryRegion *address_space,
MemoryRegion *address_space_io,
ram_addr_t ram_size,
const char *cpu_model,
enum jazz_model_e jazz_model)
{
char *filename;
int bios_size, n;
MIPSCPU *cpu;
CPUMIPSState *env;
qemu_irq *rc4030, *i8259;
rc4030_dma *dmas;
void* rc4030_opaque;
MemoryRegion *rtc = g_new(MemoryRegion, 1);
MemoryRegion *i8042 = g_new(MemoryRegion, 1);
MemoryRegion *dma_dummy = g_new(MemoryRegion, 1);
NICInfo *nd;
DeviceState *dev;
SysBusDevice *sysbus;
ISABus *isa_bus;
ISADevice *pit;
DriveInfo *fds[MAX_FD];
qemu_irq esp_reset, dma_enable;
qemu_irq *cpu_exit_irq;
MemoryRegion *ram = g_new(MemoryRegion, 1);
MemoryRegion *bios = g_new(MemoryRegion, 1);
MemoryRegion *bios2 = g_new(MemoryRegion, 1);
/* init CPUs */
if (cpu_model == NULL) {
#ifdef TARGET_MIPS64
cpu_model = "R4000";
#else
/* FIXME: All wrong, this maybe should be R3000 for the older JAZZs. */
cpu_model = "24Kf";
#endif
}
cpu = cpu_mips_init(cpu_model);
if (cpu == NULL) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
env = &cpu->env;
qemu_register_reset(main_cpu_reset, cpu);
/* allocate RAM */
memory_region_init_ram(ram, "mips_jazz.ram", ram_size);
vmstate_register_ram_global(ram);
memory_region_add_subregion(address_space, 0, ram);
memory_region_init_ram(bios, "mips_jazz.bios", MAGNUM_BIOS_SIZE);
vmstate_register_ram_global(bios);
memory_region_set_readonly(bios, true);
memory_region_init_alias(bios2, "mips_jazz.bios", bios,
0, MAGNUM_BIOS_SIZE);
memory_region_add_subregion(address_space, 0x1fc00000LL, bios);
memory_region_add_subregion(address_space, 0xfff00000LL, bios2);
/* load the BIOS image. */
if (bios_name == NULL)
bios_name = BIOS_FILENAME;
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
if (filename) {
bios_size = load_image_targphys(filename, 0xfff00000LL,
MAGNUM_BIOS_SIZE);
g_free(filename);
} else {
bios_size = -1;
}
if (bios_size < 0 || bios_size > MAGNUM_BIOS_SIZE) {
fprintf(stderr, "qemu: Could not load MIPS bios '%s'\n",
bios_name);
exit(1);
}
/* Init CPU internal devices */
cpu_mips_irq_init_cpu(env);
cpu_mips_clock_init(env);
/* Chipset */
rc4030_opaque = rc4030_init(env->irq[6], env->irq[3], &rc4030, &dmas,
address_space);
memory_region_init_io(dma_dummy, &dma_dummy_ops, NULL, "dummy_dma", 0x1000);
memory_region_add_subregion(address_space, 0x8000d000, dma_dummy);
/* ISA devices */
isa_bus = isa_bus_new(NULL, address_space_io);
i8259 = i8259_init(isa_bus, env->irq[4]);
isa_bus_irqs(isa_bus, i8259);
cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
DMA_init(0, cpu_exit_irq);
pit = pit_init(isa_bus, 0x40, 0, NULL);
pcspk_init(isa_bus, pit);
/* ISA IO space at 0x90000000 */
isa_mmio_init(0x90000000, 0x01000000);
isa_mem_base = 0x11000000;
/* Video card */
switch (jazz_model) {
case JAZZ_MAGNUM:
dev = qdev_create(NULL, "sysbus-g364");
qdev_init_nofail(dev);
sysbus = sysbus_from_qdev(dev);
sysbus_mmio_map(sysbus, 0, 0x60080000);
sysbus_mmio_map(sysbus, 1, 0x40000000);
sysbus_connect_irq(sysbus, 0, rc4030[3]);
{
/* Simple ROM, so user doesn't have to provide one */
MemoryRegion *rom_mr = g_new(MemoryRegion, 1);
memory_region_init_ram(rom_mr, "g364fb.rom", 0x80000);
vmstate_register_ram_global(rom_mr);
memory_region_set_readonly(rom_mr, true);
uint8_t *rom = memory_region_get_ram_ptr(rom_mr);
memory_region_add_subregion(address_space, 0x60000000, rom_mr);
rom[0] = 0x10; /* Mips G364 */
}
break;
case JAZZ_PICA61:
isa_vga_mm_init(0x40000000, 0x60000000, 0, get_system_memory());
break;
default:
break;
}
/* Network controller */
for (n = 0; n < nb_nics; n++) {
nd = &nd_table[n];
if (!nd->model)
nd->model = g_strdup("dp83932");
if (strcmp(nd->model, "dp83932") == 0) {
dp83932_init(nd, 0x80001000, 2, get_system_memory(), rc4030[4],
rc4030_opaque, rc4030_dma_memory_rw);
break;
} else if (strcmp(nd->model, "?") == 0) {
fprintf(stderr, "qemu: Supported NICs: dp83932\n");
exit(1);
} else {
fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model);
exit(1);
}
}
/* SCSI adapter */
esp_init(0x80002000, 0,
rc4030_dma_read, rc4030_dma_write, dmas[0],
rc4030[5], &esp_reset, &dma_enable);
/* Floppy */
if (drive_get_max_bus(IF_FLOPPY) >= MAX_FD) {
fprintf(stderr, "qemu: too many floppy drives\n");
exit(1);
}
for (n = 0; n < MAX_FD; n++) {
fds[n] = drive_get(IF_FLOPPY, 0, n);
}
fdctrl_init_sysbus(rc4030[1], 0, 0x80003000, fds);
/* Real time clock */
rtc_init(isa_bus, 1980, NULL);
memory_region_init_io(rtc, &rtc_ops, NULL, "rtc", 0x1000);
memory_region_add_subregion(address_space, 0x80004000, rtc);
/* Keyboard (i8042) */
i8042_mm_init(rc4030[6], rc4030[7], i8042, 0x1000, 0x1);
memory_region_add_subregion(address_space, 0x80005000, i8042);
/* Serial ports */
if (serial_hds[0]) {
serial_mm_init(address_space, 0x80006000, 0, rc4030[8], 8000000/16,
serial_hds[0], DEVICE_NATIVE_ENDIAN);
}
if (serial_hds[1]) {
serial_mm_init(address_space, 0x80007000, 0, rc4030[9], 8000000/16,
serial_hds[1], DEVICE_NATIVE_ENDIAN);
}
/* Parallel port */
if (parallel_hds[0])
parallel_mm_init(address_space, 0x80008000, 0, rc4030[0],
parallel_hds[0]);
/* Sound card */
/* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */
audio_init(isa_bus, NULL);
/* NVRAM */
dev = qdev_create(NULL, "ds1225y");
qdev_init_nofail(dev);
sysbus = sysbus_from_qdev(dev);
sysbus_mmio_map(sysbus, 0, 0x80009000);
/* LED indicator */
sysbus_create_simple("jazz-led", 0x8000f000, NULL);
}
| 4,535 |
qemu | 60fe637bf0e4d7989e21e50f52526444765c63b4 | 1 | static int qemu_rdma_close(void *opaque)
{
DPRINTF("Shutting down connection.\n");
QEMUFileRDMA *r = opaque;
if (r->rdma) {
qemu_rdma_cleanup(r->rdma);
g_free(r->rdma);
}
g_free(r);
return 0;
}
| 4,536 |
FFmpeg | c3da9f506038aea306dd1b9ce48db94ca251a08d | 1 | static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], int total_gain){
int v, bsize, ch, coef_nb_bits, parse_exponents;
float mdct_norm;
int nb_coefs[MAX_CHANNELS];
static const int fixed_exp[25]={20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20};
//FIXME remove duplication relative to decoder
if (s->use_variable_block_len) {
assert(0); //FIXME not implemented
}else{
/* fixed block len */
s->next_block_len_bits = s->frame_len_bits;
s->prev_block_len_bits = s->frame_len_bits;
s->block_len_bits = s->frame_len_bits;
}
s->block_len = 1 << s->block_len_bits;
// assert((s->block_pos + s->block_len) <= s->frame_len);
bsize = s->frame_len_bits - s->block_len_bits;
//FIXME factor
v = s->coefs_end[bsize] - s->coefs_start;
for(ch = 0; ch < s->nb_channels; ch++)
nb_coefs[ch] = v;
{
int n4 = s->block_len / 2;
mdct_norm = 1.0 / (float)n4;
if (s->version == 1) {
mdct_norm *= sqrt(n4);
}
}
if (s->nb_channels == 2) {
put_bits(&s->pb, 1, !!s->ms_stereo);
}
for(ch = 0; ch < s->nb_channels; ch++) {
s->channel_coded[ch] = 1; //FIXME only set channel_coded when needed, instead of always
if (s->channel_coded[ch]) {
init_exp(s, ch, fixed_exp);
}
}
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
WMACoef *coefs1;
float *coefs, *exponents, mult;
int i, n;
coefs1 = s->coefs1[ch];
exponents = s->exponents[ch];
mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
mult *= mdct_norm;
coefs = src_coefs[ch];
if (s->use_noise_coding && 0) {
assert(0); //FIXME not implemented
} else {
coefs += s->coefs_start;
n = nb_coefs[ch];
for(i = 0;i < n; i++){
double t= *coefs++ / (exponents[i] * mult);
if(t<-32768 || t>32767)
return -1;
coefs1[i] = lrint(t);
}
}
}
}
v = 0;
for(ch = 0; ch < s->nb_channels; ch++) {
int a = s->channel_coded[ch];
put_bits(&s->pb, 1, a);
v |= a;
}
if (!v)
return 1;
for(v= total_gain-1; v>=127; v-= 127)
put_bits(&s->pb, 7, 127);
put_bits(&s->pb, 7, v);
coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);
if (s->use_noise_coding) {
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
int i, n;
n = s->exponent_high_sizes[bsize];
for(i=0;i<n;i++) {
put_bits(&s->pb, 1, s->high_band_coded[ch][i]= 0);
if (0)
nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
}
}
}
}
parse_exponents = 1;
if (s->block_len_bits != s->frame_len_bits) {
put_bits(&s->pb, 1, parse_exponents);
}
if (parse_exponents) {
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
if (s->use_exp_vlc) {
encode_exp_vlc(s, ch, fixed_exp);
} else {
assert(0); //FIXME not implemented
// encode_exp_lsp(s, ch);
}
}
}
} else {
assert(0); //FIXME not implemented
}
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
int run, tindex;
WMACoef *ptr, *eptr;
tindex = (ch == 1 && s->ms_stereo);
ptr = &s->coefs1[ch][0];
eptr = ptr + nb_coefs[ch];
run=0;
for(;ptr < eptr; ptr++){
if(*ptr){
int level= *ptr;
int abs_level= FFABS(level);
int code= 0;
if(abs_level <= s->coef_vlcs[tindex]->max_level){
if(run < s->coef_vlcs[tindex]->levels[abs_level-1])
code= run + s->int_table[tindex][abs_level-1];
}
assert(code < s->coef_vlcs[tindex]->n);
put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[code], s->coef_vlcs[tindex]->huffcodes[code]);
if(code == 0){
if(1<<coef_nb_bits <= abs_level)
return -1;
//Workaround minor rounding differences for the regression tests, FIXME we should find and replace the problematic float by fixpoint for reg tests
if(abs_level == 0x71B && (s->avctx->flags & CODEC_FLAG_BITEXACT)) abs_level=0x71A;
put_bits(&s->pb, coef_nb_bits, abs_level);
put_bits(&s->pb, s->frame_len_bits, run);
}
put_bits(&s->pb, 1, level < 0); //FIXME the sign is fliped somewhere
run=0;
}else{
run++;
}
}
if(run)
put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]);
}
if (s->version == 1 && s->nb_channels >= 2) {
avpriv_align_put_bits(&s->pb);
}
}
return 0;
}
| 4,537 |
qemu | 9c7d64eb2a47033c9697fb4a5a540af1aa3915ab | 1 | static void check(int a, int b, bool expected)
{
struct qht_stats stats;
int i;
for (i = a; i < b; i++) {
void *p;
uint32_t hash;
int32_t val;
val = i;
hash = i;
p = qht_lookup(&ht, is_equal, &val, hash);
g_assert_true(!!p == expected);
}
rcu_read_unlock();
qht_statistics_init(&ht, &stats);
if (stats.used_head_buckets) {
g_assert_cmpfloat(qdist_avg(&stats.chain), >=, 1.0);
}
g_assert_cmpuint(stats.head_buckets, >, 0);
qht_statistics_destroy(&stats);
} | 4,538 |
qemu | 32bafa8fdd098d52fbf1102d5a5e48d29398c0aa | 0 | int net_init_netmap(const NetClientOptions *opts,
const char *name, NetClientState *peer, Error **errp)
{
const NetdevNetmapOptions *netmap_opts = opts->u.netmap;
struct nm_desc *nmd;
NetClientState *nc;
Error *err = NULL;
NetmapState *s;
nmd = netmap_open(netmap_opts, &err);
if (err) {
error_propagate(errp, err);
return -1;
}
/* Create the object. */
nc = qemu_new_net_client(&net_netmap_info, peer, "netmap", name);
s = DO_UPCAST(NetmapState, nc, nc);
s->nmd = nmd;
s->tx = NETMAP_TXRING(nmd->nifp, 0);
s->rx = NETMAP_RXRING(nmd->nifp, 0);
s->vnet_hdr_len = 0;
pstrcpy(s->ifname, sizeof(s->ifname), netmap_opts->ifname);
netmap_read_poll(s, true); /* Initially only poll for reads. */
return 0;
}
| 4,541 |
qemu | 3dc6f8693694a649a9c83f1e2746565b47683923 | 0 | static void pc_init1(MachineState *machine,
const char *host_type, const char *pci_type)
{
PCMachineState *pcms = PC_MACHINE(machine);
PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
MemoryRegion *system_memory = get_system_memory();
MemoryRegion *system_io = get_system_io();
int i;
PCIBus *pci_bus;
ISABus *isa_bus;
PCII440FXState *i440fx_state;
int piix3_devfn = -1;
qemu_irq *i8259;
qemu_irq smi_irq;
GSIState *gsi_state;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
BusState *idebus[MAX_IDE_BUS];
ISADevice *rtc_state;
MemoryRegion *ram_memory;
MemoryRegion *pci_memory;
MemoryRegion *rom_memory;
ram_addr_t lowmem;
/*
* Calculate ram split, for memory below and above 4G. It's a bit
* complicated for backward compatibility reasons ...
*
* - Traditional split is 3.5G (lowmem = 0xe0000000). This is the
* default value for max_ram_below_4g now.
*
* - Then, to gigabyte align the memory, we move the split to 3G
* (lowmem = 0xc0000000). But only in case we have to split in
* the first place, i.e. ram_size is larger than (traditional)
* lowmem. And for new machine types (gigabyte_align = true)
* only, for live migration compatibility reasons.
*
* - Next the max-ram-below-4g option was added, which allowed to
* reduce lowmem to a smaller value, to allow a larger PCI I/O
* window below 4G. qemu doesn't enforce gigabyte alignment here,
* but prints a warning.
*
* - Finally max-ram-below-4g got updated to also allow raising lowmem,
* so legacy non-PAE guests can get as much memory as possible in
* the 32bit address space below 4G.
*
* - Note that Xen has its own ram setp code in xen_ram_init(),
* called via xen_hvm_init().
*
* Examples:
* qemu -M pc-1.7 -m 4G (old default) -> 3584M low, 512M high
* qemu -M pc -m 4G (new default) -> 3072M low, 1024M high
* qemu -M pc,max-ram-below-4g=2G -m 4G -> 2048M low, 2048M high
* qemu -M pc,max-ram-below-4g=4G -m 3968M -> 3968M low (=4G-128M)
*/
if (xen_enabled()) {
xen_hvm_init(pcms, &ram_memory);
} else {
if (!pcms->max_ram_below_4g) {
pcms->max_ram_below_4g = 0xe0000000; /* default: 3.5G */
}
lowmem = pcms->max_ram_below_4g;
if (machine->ram_size >= pcms->max_ram_below_4g) {
if (pcmc->gigabyte_align) {
if (lowmem > 0xc0000000) {
lowmem = 0xc0000000;
}
if (lowmem & ((1ULL << 30) - 1)) {
error_report("Warning: Large machine and max_ram_below_4g "
"(%" PRIu64 ") not a multiple of 1G; "
"possible bad performance.",
pcms->max_ram_below_4g);
}
}
}
if (machine->ram_size >= lowmem) {
pcms->above_4g_mem_size = machine->ram_size - lowmem;
pcms->below_4g_mem_size = lowmem;
} else {
pcms->above_4g_mem_size = 0;
pcms->below_4g_mem_size = machine->ram_size;
}
}
pc_cpus_init(pcms);
if (kvm_enabled() && pcmc->kvmclock_enabled) {
kvmclock_create();
}
if (pcmc->pci_enabled) {
pci_memory = g_new(MemoryRegion, 1);
memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
rom_memory = pci_memory;
} else {
pci_memory = NULL;
rom_memory = system_memory;
}
pc_guest_info_init(pcms);
if (pcmc->smbios_defaults) {
MachineClass *mc = MACHINE_GET_CLASS(machine);
/* These values are guest ABI, do not change */
smbios_set_defaults("QEMU", "Standard PC (i440FX + PIIX, 1996)",
mc->name, pcmc->smbios_legacy_mode,
pcmc->smbios_uuid_encoded,
SMBIOS_ENTRY_POINT_21);
}
/* allocate ram and load rom/bios */
if (!xen_enabled()) {
pc_memory_init(pcms, system_memory,
rom_memory, &ram_memory);
} else if (machine->kernel_filename != NULL) {
/* For xen HVM direct kernel boot, load linux here */
xen_load_linux(pcms);
}
gsi_state = g_malloc0(sizeof(*gsi_state));
if (kvm_ioapic_in_kernel()) {
kvm_pc_setup_irq_routing(pcmc->pci_enabled);
pcms->gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
GSI_NUM_PINS);
} else {
pcms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
}
if (pcmc->pci_enabled) {
pci_bus = i440fx_init(host_type,
pci_type,
&i440fx_state, &piix3_devfn, &isa_bus, pcms->gsi,
system_memory, system_io, machine->ram_size,
pcms->below_4g_mem_size,
pcms->above_4g_mem_size,
pci_memory, ram_memory);
pcms->bus = pci_bus;
} else {
pci_bus = NULL;
i440fx_state = NULL;
isa_bus = isa_bus_new(NULL, get_system_memory(), system_io,
&error_abort);
no_hpet = 1;
}
isa_bus_irqs(isa_bus, pcms->gsi);
if (kvm_pic_in_kernel()) {
i8259 = kvm_i8259_init(isa_bus);
} else if (xen_enabled()) {
i8259 = xen_interrupt_controller_init();
} else {
i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq());
}
for (i = 0; i < ISA_NUM_IRQS; i++) {
gsi_state->i8259_irq[i] = i8259[i];
}
g_free(i8259);
if (pcmc->pci_enabled) {
ioapic_init_gsi(gsi_state, "i440fx");
}
pc_register_ferr_irq(pcms->gsi[13]);
pc_vga_init(isa_bus, pcmc->pci_enabled ? pci_bus : NULL);
assert(pcms->vmport != ON_OFF_AUTO__MAX);
if (pcms->vmport == ON_OFF_AUTO_AUTO) {
pcms->vmport = xen_enabled() ? ON_OFF_AUTO_OFF : ON_OFF_AUTO_ON;
}
/* init basic PC hardware */
pc_basic_device_init(isa_bus, pcms->gsi, &rtc_state, true,
(pcms->vmport != ON_OFF_AUTO_ON), pcms->pit, 0x4);
pc_nic_init(isa_bus, pci_bus);
ide_drive_get(hd, ARRAY_SIZE(hd));
if (pcmc->pci_enabled) {
PCIDevice *dev;
if (xen_enabled()) {
dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
} else {
dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
}
idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
} else {
for(i = 0; i < MAX_IDE_BUS; i++) {
ISADevice *dev;
char busname[] = "ide.0";
dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
ide_irq[i],
hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
/*
* The ide bus name is ide.0 for the first bus and ide.1 for the
* second one.
*/
busname[4] = '0' + i;
idebus[i] = qdev_get_child_bus(DEVICE(dev), busname);
}
}
pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
if (pcmc->pci_enabled && machine_usb(machine)) {
pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
}
if (pcmc->pci_enabled && acpi_enabled) {
DeviceState *piix4_pm;
I2CBus *smbus;
smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
/* TODO: Populate SPD eeprom data. */
smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
pcms->gsi[9], smi_irq,
pc_machine_is_smm_enabled(pcms),
&piix4_pm);
smbus_eeprom_init(smbus, 8, NULL, 0);
object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
TYPE_HOTPLUG_HANDLER,
(Object **)&pcms->acpi_dev,
object_property_allow_set_link,
OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
object_property_set_link(OBJECT(machine), OBJECT(piix4_pm),
PC_MACHINE_ACPI_DEVICE_PROP, &error_abort);
}
if (pcmc->pci_enabled) {
pc_pci_device_init(pci_bus);
}
if (pcms->acpi_nvdimm_state.is_enabled) {
nvdimm_init_acpi_state(&pcms->acpi_nvdimm_state, system_io,
pcms->fw_cfg, OBJECT(pcms));
}
}
| 4,542 |
FFmpeg | ffcc82219cef0928bed2d558b19ef6ea35634130 | 0 | int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
const uint8_t *name, uint8_t *dst, int dst_size)
{
int namelen = strlen(name);
int len;
while (*data != AMF_DATA_TYPE_OBJECT && data < data_end) {
len = ff_amf_tag_size(data, data_end);
if (len < 0)
len = data_end - data;
data += len;
}
if (data_end - data < 3)
return -1;
data++;
for (;;) {
int size = bytestream_get_be16(&data);
if (!size)
break;
if (size < 0 || size >= data_end - data)
return -1;
data += size;
if (size == namelen && !memcmp(data-size, name, namelen)) {
switch (*data++) {
case AMF_DATA_TYPE_NUMBER:
snprintf(dst, dst_size, "%g", av_int2double(AV_RB64(data)));
break;
case AMF_DATA_TYPE_BOOL:
snprintf(dst, dst_size, "%s", *data ? "true" : "false");
break;
case AMF_DATA_TYPE_STRING:
len = bytestream_get_be16(&data);
av_strlcpy(dst, data, FFMIN(len+1, dst_size));
break;
default:
return -1;
}
return 0;
}
len = ff_amf_tag_size(data, data_end);
if (len < 0 || len >= data_end - data)
return -1;
data += len;
}
return -1;
}
| 4,543 |
qemu | 54421cb17bc744bad15f2b1adb4adefdaea83c10 | 0 | static int raw_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVRawState *s = bs->opaque;
int access_flags, create_flags;
DWORD overlapped;
s->type = FTYPE_FILE;
if ((flags & BDRV_O_ACCESS) == O_RDWR) {
access_flags = GENERIC_READ | GENERIC_WRITE;
} else {
access_flags = GENERIC_READ;
}
if (flags & BDRV_O_CREAT) {
create_flags = CREATE_ALWAYS;
} else {
create_flags = OPEN_EXISTING;
}
#ifdef QEMU_TOOL
overlapped = FILE_ATTRIBUTE_NORMAL;
#else
overlapped = FILE_FLAG_OVERLAPPED;
#endif
s->hfile = CreateFile(filename, access_flags,
FILE_SHARE_READ, NULL,
create_flags, overlapped, NULL);
if (s->hfile == INVALID_HANDLE_VALUE)
return -1;
return 0;
}
| 4,544 |
Subsets and Splits