project
stringclasses
2 values
commit_id
stringlengths
40
40
target
int64
0
1
func
stringlengths
26
142k
idx
int64
0
27.3k
qemu
ec50dd4634ae06091e61f42b7ba975f9ed510ad0
1
RockerSwitch *qmp_query_rocker(const char *name, Error **errp) { RockerSwitch *rocker = g_malloc0(sizeof(*rocker)); Rocker *r; r = rocker_find(name); if (!r) { error_set(errp, ERROR_CLASS_GENERIC_ERROR, "rocker %s not found", name); return NULL; } rocker->name = g_strdup(r->name); rocker->id = r->switch_id; rocker->ports = r->fp_ports; return rocker; }
4,807
FFmpeg
3176217c60ca7828712985092d9102d331ea4f3d
0
static int init_dimensions(H264Context *h) { int width = h->width - (h->sps.crop_right + h->sps.crop_left); int height = h->height - (h->sps.crop_top + h->sps.crop_bottom); /* handle container cropping */ if (FFALIGN(h->avctx->width, 16) == FFALIGN(width, 16) && FFALIGN(h->avctx->height, 16) == FFALIGN(height, 16)) { width = h->avctx->width; height = h->avctx->height; } if (width <= 0 || height <= 0) { av_log(h->avctx, AV_LOG_ERROR, "Invalid cropped dimensions: %dx%d.\n", width, height); if (h->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; av_log(h->avctx, AV_LOG_WARNING, "Ignoring cropping information.\n"); h->sps.crop_bottom = h->sps.crop_top = h->sps.crop_right = h->sps.crop_left = h->sps.crop = 0; width = h->width; height = h->height; } h->avctx->coded_width = h->width; h->avctx->coded_height = h->height; h->avctx->width = width; h->avctx->height = height; return 0; }
4,808
FFmpeg
ae7a4a1594e3624f7c844dec44266d2dc74a6be2
1
static inline CopyRet copy_frame(AVCodecContext *avctx, BC_DTS_PROC_OUT *output, void *data, int *data_size, uint8_t second_field) { BC_STATUS ret; BC_DTS_STATUS decoder_status; uint8_t is_paff; uint8_t next_frame_same; uint8_t interlaced; CHDContext *priv = avctx->priv_data; int64_t pkt_pts = AV_NOPTS_VALUE; uint8_t pic_type = 0; uint8_t bottom_field = (output->PicInfo.flags & VDEC_FLAG_BOTTOMFIELD) == VDEC_FLAG_BOTTOMFIELD; uint8_t bottom_first = !!(output->PicInfo.flags & VDEC_FLAG_BOTTOM_FIRST); int width = output->PicInfo.width; int height = output->PicInfo.height; int bwidth; uint8_t *src = output->Ybuff; int sStride; uint8_t *dst; int dStride; if (output->PicInfo.timeStamp != 0) { OpaqueList *node = opaque_list_pop(priv, output->PicInfo.timeStamp); if (node) { pkt_pts = node->reordered_opaque; pic_type = node->pic_type; av_free(node); } else { /* * We will encounter a situation where a timestamp cannot be * popped if a second field is being returned. In this case, * each field has the same timestamp and the first one will * cause it to be popped. To keep subsequent calculations * simple, pic_type should be set a FIELD value - doesn't * matter which, but I chose BOTTOM. */ pic_type = PICT_BOTTOM_FIELD; } av_log(avctx, AV_LOG_VERBOSE, "output \"pts\": %"PRIu64"\n", output->PicInfo.timeStamp); av_log(avctx, AV_LOG_VERBOSE, "output picture type %d\n", pic_type); } ret = DtsGetDriverStatus(priv->dev, &decoder_status); if (ret != BC_STS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed: %u\n", ret); return RET_ERROR; } is_paff = ASSUME_PAFF_OVER_MBAFF || !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC); next_frame_same = output->PicInfo.picture_number == (decoder_status.picNumFlags & ~0x40000000); interlaced = ((output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) && is_paff) || next_frame_same || bottom_field || second_field; av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: next_frame_same: %u | %u | %u\n", next_frame_same, output->PicInfo.picture_number, decoder_status.picNumFlags & ~0x40000000); if (priv->pic.data[0] && !priv->need_second_field) avctx->release_buffer(avctx, &priv->pic); priv->need_second_field = interlaced && !priv->need_second_field; priv->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if (!priv->pic.data[0]) { if (avctx->get_buffer(avctx, &priv->pic) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return RET_ERROR; } } bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0); if (priv->is_70012) { int pStride; if (width <= 720) pStride = 720; else if (width <= 1280) pStride = 1280; else if (width <= 1080) pStride = 1080; sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0); } else { sStride = bwidth; } dStride = priv->pic.linesize[0]; dst = priv->pic.data[0]; av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n"); if (interlaced) { int dY = 0; int sY = 0; height /= 2; if (bottom_field) { av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n"); dY = 1; } else { av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n"); dY = 0; } for (sY = 0; sY < height; dY++, sY++) { memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth); dY++; } } else { av_image_copy_plane(dst, dStride, src, sStride, bwidth, height); } priv->pic.interlaced_frame = interlaced; if (interlaced) priv->pic.top_field_first = !bottom_first; priv->pic.pkt_pts = pkt_pts; if (!priv->need_second_field) { *data_size = sizeof(AVFrame); *(AVFrame *)data = priv->pic; } if (ASSUME_TWO_INPUTS_ONE_OUTPUT && output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) { av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n"); return RET_SKIP_NEXT_COPY; } /* * Testing has shown that in all cases where we don't want to return the * full frame immediately, VDEC_FLAG_UNKNOWN_SRC is set. */ return priv->need_second_field && !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ? RET_COPY_NEXT_FIELD : RET_OK; }
4,809
FFmpeg
2a5ac99e6e06078713f684fee2466c91f677b303
0
static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) { X11GrabContext *s = s1->priv_data; Display *dpy = s->dpy; XImage *image = s->image; int x_off = s->x_off; int y_off = s->y_off; int follow_mouse = s->follow_mouse; int screen; Window root; int64_t curtime, delay; struct timespec ts; /* Calculate the time of the next frame */ s->time_frame += INT64_C(1000000); /* wait based on the frame rate */ for (;;) { curtime = av_gettime(); delay = s->time_frame * av_q2d(s->time_base) - curtime; if (delay <= 0) { if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) s->time_frame += INT64_C(1000000); break; } ts.tv_sec = delay / 1000000; ts.tv_nsec = (delay % 1000000) * 1000; nanosleep(&ts, NULL); } av_init_packet(pkt); pkt->data = image->data; pkt->size = s->frame_size; pkt->pts = curtime; screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); if (follow_mouse) { int screen_w, screen_h; int pointer_x, pointer_y, _; Window w; screen_w = DisplayWidth(dpy, screen); screen_h = DisplayHeight(dpy, screen); XQueryPointer(dpy, root, &w, &w, &pointer_x, &pointer_y, &_, &_, &_); if (follow_mouse == -1) { // follow the mouse, put it at center of grabbing region x_off += pointer_x - s->width / 2 - x_off; y_off += pointer_y - s->height / 2 - y_off; } else { // follow the mouse, but only move the grabbing region when mouse // reaches within certain pixels to the edge. if (pointer_x > x_off + s->width - follow_mouse) x_off += pointer_x - (x_off + s->width - follow_mouse); else if (pointer_x < x_off + follow_mouse) x_off -= (x_off + follow_mouse) - pointer_x; if (pointer_y > y_off + s->height - follow_mouse) y_off += pointer_y - (y_off + s->height - follow_mouse); else if (pointer_y < y_off + follow_mouse) y_off -= (y_off + follow_mouse) - pointer_y; } // adjust grabbing region position if it goes out of screen. s->x_off = x_off = FFMIN(FFMAX(x_off, 0), screen_w - s->width); s->y_off = y_off = FFMIN(FFMAX(y_off, 0), screen_h - s->height); if (s->show_region && s->region_win) XMoveWindow(dpy, s->region_win, s->x_off - REGION_WIN_BORDER, s->y_off - REGION_WIN_BORDER); } if (s->show_region) { if (s->region_win) { XEvent evt = { .type = NoEventMask }; // Clean up the events, and do the initial draw or redraw. while (XCheckMaskEvent(dpy, ExposureMask | StructureNotifyMask, &evt)) ; if (evt.type) x11grab_draw_region_win(s); } else { x11grab_region_win_init(s); } } if (s->use_shm) { if (!XShmGetImage(dpy, root, image, x_off, y_off, AllPlanes)) av_log(s1, AV_LOG_INFO, "XShmGetImage() failed\n"); } else { if (!xget_zpixmap(dpy, root, image, x_off, y_off)) av_log(s1, AV_LOG_INFO, "XGetZPixmap() failed\n"); } if (s->draw_mouse) paint_mouse_pointer(image, s); return s->frame_size; }
4,810
qemu
579967bea69bf1b32faee13ff76b19ba641a2618
1
void usb_ep_combine_input_packets(USBEndpoint *ep) { USBPacket *p, *u, *next, *prev = NULL, *first = NULL; USBPort *port = ep->dev->port; int ret; assert(ep->pipeline); assert(ep->pid == USB_TOKEN_IN); QTAILQ_FOREACH_SAFE(p, &ep->queue, queue, next) { /* Empty the queue on a halt */ if (ep->halted) { p->result = USB_RET_REMOVE_FROM_QUEUE; port->ops->complete(port, p); continue; } /* Skip packets already submitted to the device */ if (p->state == USB_PACKET_ASYNC) { prev = p; continue; } usb_packet_check_state(p, USB_PACKET_QUEUED); /* * If the previous (combined) packet has the short_not_ok flag set * stop, as we must not submit packets to the device after a transfer * ending with short_not_ok packet. */ if (prev && prev->short_not_ok) { break; } if (first) { if (first->combined == NULL) { USBCombinedPacket *combined = g_new0(USBCombinedPacket, 1); combined->first = first; QTAILQ_INIT(&combined->packets); qemu_iovec_init(&combined->iov, 2); usb_combined_packet_add(combined, first); } usb_combined_packet_add(first->combined, p); } else { first = p; } /* Is this packet the last one of a (combined) transfer? */ if ((p->iov.size % ep->max_packet_size) != 0 || !p->short_not_ok || next == NULL) { ret = usb_device_handle_data(ep->dev, first); assert(ret == USB_RET_ASYNC); if (first->combined) { QTAILQ_FOREACH(u, &first->combined->packets, combined_entry) { usb_packet_set_state(u, USB_PACKET_ASYNC); } } else { usb_packet_set_state(first, USB_PACKET_ASYNC); } first = NULL; prev = p; } } }
4,811
qemu
07c114bbf389c09c99fd451b0b0fddf88962f512
1
static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d, hwaddr addr, bool resolve_subpage) { MemoryRegionSection *section = atomic_read(&d->mru_section); subpage_t *subpage; bool update; if (section && section != &d->map.sections[PHYS_SECTION_UNASSIGNED] && section_covers_addr(section, addr)) { update = false; } else { section = phys_page_find(d, addr); update = true; } if (resolve_subpage && section->mr->subpage) { subpage = container_of(section->mr, subpage_t, iomem); section = &d->map.sections[subpage->sub_section[SUBPAGE_IDX(addr)]]; } if (update) { atomic_set(&d->mru_section, section); } return section; }
4,812
FFmpeg
fdbc544d29176ba69d67dd879df4696f0a19052e
1
static int asf_read_generic_value(AVFormatContext *s, uint8_t *name, uint16_t name_len, int type, AVDictionary **met) { AVIOContext *pb = s->pb; uint64_t value; char buf[32]; switch (type) { case ASF_BOOL: value = avio_rl32(pb); break; case ASF_DWORD: value = avio_rl32(pb); break; case ASF_QWORD: value = avio_rl64(pb); break; case ASF_WORD: value = avio_rl16(pb); break; default: av_freep(&name); return AVERROR_INVALIDDATA; } snprintf(buf, sizeof(buf), "%"PRIu64, value); if (av_dict_set(met, name, buf, 0) < 0) av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n"); return 0; }
4,813
qemu
410cbafebc7168a278a23c856b4f5ff276ef1c85
1
int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { QemuOpts *opts; int res; opts = qemu_opts_from_qdict(&qemu_netdev_opts, qdict); if (!opts) { return -1; res = net_client_init(mon, opts, 1); return res;
4,814
qemu
2bf3aa85f08186b8162b76e7e8efe5b5a44306a6
1
static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, uint8_t *p) { int pages = -1; if (is_zero_range(p, TARGET_PAGE_SIZE)) { rs->zero_pages++; rs->bytes_transferred += save_page_header(rs, block, offset | RAM_SAVE_FLAG_COMPRESS); qemu_put_byte(rs->f, 0); rs->bytes_transferred += 1; pages = 1; } return pages; }
4,817
FFmpeg
229843aa359ae0c9519977d7fa952688db63f559
0
static int movie_push_frame(AVFilterContext *ctx, unsigned out_id) { MovieContext *movie = ctx->priv; AVPacket *pkt = &movie->pkt; enum AVMediaType frame_type; MovieStream *st; int ret, got_frame = 0, pkt_out_id; AVFilterLink *outlink; AVFrame *frame; if (!pkt->size) { if (movie->eof) { if (movie->st[out_id].done) { if (movie->loop_count != 1) { ret = rewind_file(ctx); if (ret < 0) return ret; movie->loop_count -= movie->loop_count > 1; av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n"); return 0; /* retry */ } return AVERROR_EOF; } pkt->stream_index = movie->st[out_id].st->index; /* packet is already ready for flushing */ } else { ret = av_read_frame(movie->format_ctx, &movie->pkt0); if (ret < 0) { av_init_packet(&movie->pkt0); /* ready for flushing */ *pkt = movie->pkt0; if (ret == AVERROR_EOF) { movie->eof = 1; return 0; /* start flushing */ } return ret; } *pkt = movie->pkt0; } } pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 : movie->out_index[pkt->stream_index]; if (pkt_out_id < 0) { av_free_packet(&movie->pkt0); pkt->size = 0; /* ready for next run */ pkt->data = NULL; return 0; } st = &movie->st[pkt_out_id]; outlink = ctx->outputs[pkt_out_id]; frame = av_frame_alloc(); if (!frame) return AVERROR(ENOMEM); frame_type = st->st->codec->codec_type; switch (frame_type) { case AVMEDIA_TYPE_VIDEO: ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt); break; case AVMEDIA_TYPE_AUDIO: ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt); break; default: ret = AVERROR(ENOSYS); break; } if (ret < 0) { av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret)); av_frame_free(&frame); av_free_packet(&movie->pkt0); movie->pkt.size = 0; movie->pkt.data = NULL; return 0; } if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) ret = pkt->size; pkt->data += ret; pkt->size -= ret; if (pkt->size <= 0) { av_free_packet(&movie->pkt0); pkt->size = 0; /* ready for next run */ pkt->data = NULL; } if (!got_frame) { if (!ret) st->done = 1; av_frame_free(&frame); return 0; } frame->pts = av_frame_get_best_effort_timestamp(frame); av_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name, describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink)); if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (frame->format != outlink->format) { av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n", av_get_pix_fmt_name(outlink->format), av_get_pix_fmt_name(frame->format) ); av_frame_free(&frame); return 0; } } ret = ff_filter_frame(outlink, frame); if (ret < 0) return ret; return pkt_out_id == out_id; }
4,819
FFmpeg
90540c2d5ace46a1e9789c75fde0b1f7dbb12a9b
1
static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; const uint8_t *mm_end; uint16_t *d = (uint16_t *)dst; end = s + src_size; __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); __asm__ volatile( "movq %0, %%mm7 \n\t" "movq %1, %%mm6 \n\t" ::"m"(red_15mask),"m"(green_15mask)); mm_end = end - 15; while (s < mm_end) { __asm__ volatile( PREFETCH" 32%1 \n\t" "movd %1, %%mm0 \n\t" "movd 3%1, %%mm3 \n\t" "punpckldq 6%1, %%mm0 \n\t" "punpckldq 9%1, %%mm3 \n\t" "movq %%mm0, %%mm1 \n\t" "movq %%mm0, %%mm2 \n\t" "movq %%mm3, %%mm4 \n\t" "movq %%mm3, %%mm5 \n\t" "psllq $7, %%mm0 \n\t" "psllq $7, %%mm3 \n\t" "pand %%mm7, %%mm0 \n\t" "pand %%mm7, %%mm3 \n\t" "psrlq $6, %%mm1 \n\t" "psrlq $6, %%mm4 \n\t" "pand %%mm6, %%mm1 \n\t" "pand %%mm6, %%mm4 \n\t" "psrlq $19, %%mm2 \n\t" "psrlq $19, %%mm5 \n\t" "pand %2, %%mm2 \n\t" "pand %2, %%mm5 \n\t" "por %%mm1, %%mm0 \n\t" "por %%mm4, %%mm3 \n\t" "por %%mm2, %%mm0 \n\t" "por %%mm5, %%mm3 \n\t" "psllq $16, %%mm3 \n\t" "por %%mm3, %%mm0 \n\t" MOVNTQ" %%mm0, %0 \n\t" :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); d += 4; s += 12; } __asm__ volatile(SFENCE:::"memory"); __asm__ volatile(EMMS:::"memory"); while (s < end) { const int r = *s++; const int g = *s++; const int b = *s++; *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); } }
4,820
FFmpeg
3176217c60ca7828712985092d9102d331ea4f3d
0
static int decode_picture_timing(H264Context *h) { if (h->sps.nal_hrd_parameters_present_flag || h->sps.vcl_hrd_parameters_present_flag) { h->sei_cpb_removal_delay = get_bits(&h->gb, h->sps.cpb_removal_delay_length); h->sei_dpb_output_delay = get_bits(&h->gb, h->sps.dpb_output_delay_length); } if (h->sps.pic_struct_present_flag) { unsigned int i, num_clock_ts; h->sei_pic_struct = get_bits(&h->gb, 4); h->sei_ct_type = 0; if (h->sei_pic_struct > SEI_PIC_STRUCT_FRAME_TRIPLING) return AVERROR_INVALIDDATA; num_clock_ts = sei_num_clock_ts_table[h->sei_pic_struct]; for (i = 0; i < num_clock_ts; i++) { if (get_bits(&h->gb, 1)) { /* clock_timestamp_flag */ unsigned int full_timestamp_flag; h->sei_ct_type |= 1 << get_bits(&h->gb, 2); skip_bits(&h->gb, 1); /* nuit_field_based_flag */ skip_bits(&h->gb, 5); /* counting_type */ full_timestamp_flag = get_bits(&h->gb, 1); skip_bits(&h->gb, 1); /* discontinuity_flag */ skip_bits(&h->gb, 1); /* cnt_dropped_flag */ skip_bits(&h->gb, 8); /* n_frames */ if (full_timestamp_flag) { skip_bits(&h->gb, 6); /* seconds_value 0..59 */ skip_bits(&h->gb, 6); /* minutes_value 0..59 */ skip_bits(&h->gb, 5); /* hours_value 0..23 */ } else { if (get_bits(&h->gb, 1)) { /* seconds_flag */ skip_bits(&h->gb, 6); /* seconds_value range 0..59 */ if (get_bits(&h->gb, 1)) { /* minutes_flag */ skip_bits(&h->gb, 6); /* minutes_value 0..59 */ if (get_bits(&h->gb, 1)) /* hours_flag */ skip_bits(&h->gb, 5); /* hours_value 0..23 */ } } } if (h->sps.time_offset_length > 0) skip_bits(&h->gb, h->sps.time_offset_length); /* time_offset */ } } if (h->avctx->debug & FF_DEBUG_PICT_INFO) av_log(h->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); } return 0; }
4,821
FFmpeg
229843aa359ae0c9519977d7fa952688db63f559
0
static int ftp_close(URLContext *h) { FTPContext *s = h->priv_data; av_dlog(h, "ftp protocol close\n"); ftp_close_both_connections(s); av_freep(&s->user); av_freep(&s->password); av_freep(&s->hostname); av_freep(&s->path); av_freep(&s->features); return 0; }
4,822
FFmpeg
a8dbe9514f865f6a8efb304a720025cb1ef9ae3f
0
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap) { AVFormatContext *ic = NULL; int err; char buf[PROBE_BUF_SIZE]; AVProbeData probe_data, *pd = &probe_data; ic = av_mallocz(sizeof(AVFormatContext)); if (!ic) { err = AVERROR_NOMEM; goto fail; } pstrcpy(ic->filename, sizeof(ic->filename), filename); pd->filename = ic->filename; pd->buf = buf; pd->buf_size = 0; if (!fmt) { /* guess format if no file can be opened */ fmt = probe_input_format(pd, 0); } /* if no file needed do not try to open one */ if (!fmt || !(fmt->flags & AVFMT_NOFILE)) { if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) { err = AVERROR_IO; goto fail; } if (buf_size > 0) { url_setbufsize(&ic->pb, buf_size); } /* read probe data */ pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE); url_fseek(&ic->pb, 0, SEEK_SET); } /* guess file format */ if (!fmt) { fmt = probe_input_format(pd, 1); } /* if still no format found, error */ if (!fmt) { err = AVERROR_NOFMT; goto fail; } ic->iformat = fmt; /* allocate private data */ ic->priv_data = av_mallocz(fmt->priv_data_size); if (!ic->priv_data) { err = AVERROR_NOMEM; goto fail; } /* check filename in case of an image number is expected */ if (ic->iformat->flags & AVFMT_NEEDNUMBER) { if (filename_number_test(ic->filename) < 0) { err = AVERROR_NUMEXPECTED; goto fail1; } } err = ic->iformat->read_header(ic, ap); if (err < 0) goto fail1; *ic_ptr = ic; return 0; fail1: if (!(fmt->flags & AVFMT_NOFILE)) { url_fclose(&ic->pb); } fail: if (ic) { av_free(ic->priv_data); } av_free(ic); *ic_ptr = NULL; return err; }
4,823
qemu
e7b9bc3e89152f14f426fa4d150d2a6ca02583c1
0
static int dec_21154_pci_host_init(PCIDevice *d) { /* PCI2PCI bridge same values as PearPC - check this */ pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC); pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154); pci_set_byte(d->config + PCI_REVISION_ID, 0x02); pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI); return 0; }
4,824
FFmpeg
eff2399f240db76b713b694508cdc8be175ab9fd
0
static void guess_mv(MpegEncContext *s) { uint8_t *fixed = av_malloc(s->mb_stride * s->mb_height); #define MV_FROZEN 3 #define MV_CHANGED 2 #define MV_UNCHANGED 1 const int mb_stride = s->mb_stride; const int mb_width = s->mb_width; const int mb_height = s->mb_height; int i, depth, num_avail; int mb_x, mb_y, mot_step, mot_stride; set_mv_strides(s, &mot_step, &mot_stride); num_avail = 0; for (i = 0; i < s->mb_num; i++) { const int mb_xy = s->mb_index2xy[i]; int f = 0; int error = s->error_status_table[mb_xy]; if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) f = MV_FROZEN; // intra // FIXME check if (!(error & ER_MV_ERROR)) f = MV_FROZEN; // inter with undamaged MV fixed[mb_xy] = f; if (f == MV_FROZEN) num_avail++; else if(s->last_picture.f.data[0] && s->last_picture.f.motion_val[0]){ const int mb_y= mb_xy / s->mb_stride; const int mb_x= mb_xy % s->mb_stride; const int mot_index= (mb_x + mb_y*mot_stride) * mot_step; s->current_picture.f.motion_val[0][mot_index][0]= s->last_picture.f.motion_val[0][mot_index][0]; s->current_picture.f.motion_val[0][mot_index][1]= s->last_picture.f.motion_val[0][mot_index][1]; s->current_picture.f.ref_index[0][4*mb_xy] = s->last_picture.f.ref_index[0][4*mb_xy]; } } if ((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width / 2) { for (mb_y = 0; mb_y < s->mb_height; mb_y++) { s->mb_x = 0; s->mb_y = mb_y; ff_init_block_index(s); for (mb_x = 0; mb_x < s->mb_width; mb_x++) { const int mb_xy = mb_x + mb_y * s->mb_stride; ff_update_block_index(s); if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) continue; if (!(s->error_status_table[mb_xy] & ER_MV_ERROR)) continue; s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD; s->mb_intra = 0; s->mv_type = MV_TYPE_16X16; s->mb_skipped = 0; s->dsp.clear_blocks(s->block[0]); s->mb_x = mb_x; s->mb_y = mb_y; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; decode_mb(s, 0); } } goto end; } for (depth = 0; ; depth++) { int changed, pass, none_left; none_left = 1; changed = 1; for (pass = 0; (changed || pass < 2) && pass < 10; pass++) { int mb_x, mb_y; int score_sum = 0; changed = 0; for (mb_y = 0; mb_y < s->mb_height; mb_y++) { s->mb_x = 0; s->mb_y = mb_y; ff_init_block_index(s); for (mb_x = 0; mb_x < s->mb_width; mb_x++) { const int mb_xy = mb_x + mb_y * s->mb_stride; int mv_predictor[8][2] = { { 0 } }; int ref[8] = { 0 }; int pred_count = 0; int j; int best_score = 256 * 256 * 256 * 64; int best_pred = 0; const int mot_index = (mb_x + mb_y * mot_stride) * mot_step; int prev_x, prev_y, prev_ref; ff_update_block_index(s); if ((mb_x ^ mb_y ^ pass) & 1) continue; if (fixed[mb_xy] == MV_FROZEN) continue; assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy])); assert(s->last_picture_ptr && s->last_picture_ptr->f.data[0]); j = 0; if (mb_x > 0 && fixed[mb_xy - 1] == MV_FROZEN) j = 1; if (mb_x + 1 < mb_width && fixed[mb_xy + 1] == MV_FROZEN) j = 1; if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_FROZEN) j = 1; if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_FROZEN) j = 1; if (j == 0) continue; j = 0; if (mb_x > 0 && fixed[mb_xy - 1 ] == MV_CHANGED) j = 1; if (mb_x + 1 < mb_width && fixed[mb_xy + 1 ] == MV_CHANGED) j = 1; if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_CHANGED) j = 1; if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_CHANGED) j = 1; if (j == 0 && pass > 1) continue; none_left = 0; if (mb_x > 0 && fixed[mb_xy - 1]) { mv_predictor[pred_count][0] = s->current_picture.f.motion_val[0][mot_index - mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index - mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy - 1)]; pred_count++; } if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) { mv_predictor[pred_count][0] = s->current_picture.f.motion_val[0][mot_index + mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index + mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy + 1)]; pred_count++; } if (mb_y > 0 && fixed[mb_xy - mb_stride]) { mv_predictor[pred_count][0] = s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy - s->mb_stride)]; pred_count++; } if (mb_y + 1<mb_height && fixed[mb_xy + mb_stride]) { mv_predictor[pred_count][0] = s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy + s->mb_stride)]; pred_count++; } if (pred_count == 0) continue; if (pred_count > 1) { int sum_x = 0, sum_y = 0, sum_r = 0; int max_x, max_y, min_x, min_y, max_r, min_r; for (j = 0; j < pred_count; j++) { sum_x += mv_predictor[j][0]; sum_y += mv_predictor[j][1]; sum_r += ref[j]; if (j && ref[j] != ref[j - 1]) goto skip_mean_and_median; } /* mean */ mv_predictor[pred_count][0] = sum_x / j; mv_predictor[pred_count][1] = sum_y / j; ref[pred_count] = sum_r / j; /* median */ if (pred_count >= 3) { min_y = min_x = min_r = 99999; max_y = max_x = max_r = -99999; } else { min_x = min_y = max_x = max_y = min_r = max_r = 0; } for (j = 0; j < pred_count; j++) { max_x = FFMAX(max_x, mv_predictor[j][0]); max_y = FFMAX(max_y, mv_predictor[j][1]); max_r = FFMAX(max_r, ref[j]); min_x = FFMIN(min_x, mv_predictor[j][0]); min_y = FFMIN(min_y, mv_predictor[j][1]); min_r = FFMIN(min_r, ref[j]); } mv_predictor[pred_count + 1][0] = sum_x - max_x - min_x; mv_predictor[pred_count + 1][1] = sum_y - max_y - min_y; ref[pred_count + 1] = sum_r - max_r - min_r; if (pred_count == 4) { mv_predictor[pred_count + 1][0] /= 2; mv_predictor[pred_count + 1][1] /= 2; ref[pred_count + 1] /= 2; } pred_count += 2; } skip_mean_and_median: /* zero MV */ pred_count++; if (!fixed[mb_xy] && 0) { if (s->avctx->codec_id == CODEC_ID_H264) { // FIXME } else { ff_thread_await_progress(&s->last_picture_ptr->f, mb_y, 0); } if (!s->last_picture.f.motion_val[0] || !s->last_picture.f.ref_index[0]) goto skip_last_mv; prev_x = s->last_picture.f.motion_val[0][mot_index][0]; prev_y = s->last_picture.f.motion_val[0][mot_index][1]; prev_ref = s->last_picture.f.ref_index[0][4 * mb_xy]; } else { prev_x = s->current_picture.f.motion_val[0][mot_index][0]; prev_y = s->current_picture.f.motion_val[0][mot_index][1]; prev_ref = s->current_picture.f.ref_index[0][4 * mb_xy]; } /* last MV */ mv_predictor[pred_count][0] = prev_x; mv_predictor[pred_count][1] = prev_y; ref[pred_count] = prev_ref; pred_count++; skip_last_mv: s->mv_dir = MV_DIR_FORWARD; s->mb_intra = 0; s->mv_type = MV_TYPE_16X16; s->mb_skipped = 0; s->dsp.clear_blocks(s->block[0]); s->mb_x = mb_x; s->mb_y = mb_y; for (j = 0; j < pred_count; j++) { int score = 0; uint8_t *src = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; s->current_picture.f.motion_val[0][mot_index][0] = s->mv[0][0][0] = mv_predictor[j][0]; s->current_picture.f.motion_val[0][mot_index][1] = s->mv[0][0][1] = mv_predictor[j][1]; // predictor intra or otherwise not available if (ref[j] < 0) continue; decode_mb(s, ref[j]); if (mb_x > 0 && fixed[mb_xy - 1]) { int k; for (k = 0; k < 16; k++) score += FFABS(src[k * s->linesize - 1] - src[k * s->linesize]); } if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) { int k; for (k = 0; k < 16; k++) score += FFABS(src[k * s->linesize + 15] - src[k * s->linesize + 16]); } if (mb_y > 0 && fixed[mb_xy - mb_stride]) { int k; for (k = 0; k < 16; k++) score += FFABS(src[k - s->linesize] - src[k]); } if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride]) { int k; for (k = 0; k < 16; k++) score += FFABS(src[k + s->linesize * 15] - src[k + s->linesize * 16]); } if (score <= best_score) { // <= will favor the last MV best_score = score; best_pred = j; } } score_sum += best_score; s->mv[0][0][0] = mv_predictor[best_pred][0]; s->mv[0][0][1] = mv_predictor[best_pred][1]; for (i = 0; i < mot_step; i++) for (j = 0; j < mot_step; j++) { s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0]; s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1]; } decode_mb(s, ref[best_pred]); if (s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y) { fixed[mb_xy] = MV_CHANGED; changed++; } else fixed[mb_xy] = MV_UNCHANGED; } } // printf(".%d/%d", changed, score_sum); fflush(stdout); } if (none_left) goto end; for (i = 0; i < s->mb_num; i++) { int mb_xy = s->mb_index2xy[i]; if (fixed[mb_xy]) fixed[mb_xy] = MV_FROZEN; } // printf(":"); fflush(stdout); } end: av_free(fixed); }
4,825
qemu
1ffc266539d443f83d5eb487593be50ef496f09e
0
static void audio_reset_timer (AudioState *s) { if (audio_is_timer_needed ()) { timer_mod (s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + conf.period.ticks); } else { timer_del (s->ts); } }
4,826
qemu
2b584959ed300ddff4acba0d7554becad5f274fd
0
int bdrv_get_translation_hint(BlockDriverState *bs) { return bs->translation; }
4,827
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
static int omap_validate_emifs_addr(struct omap_mpu_state_s *s, target_phys_addr_t addr) { return range_covers_byte(OMAP_EMIFS_BASE, OMAP_EMIFF_BASE - OMAP_EMIFS_BASE, addr); }
4,828
qemu
3b098d56979d2f7fd707c5be85555d114353a28d
0
StringOutputVisitor *string_output_visitor_new(bool human) { StringOutputVisitor *v; v = g_malloc0(sizeof(*v)); v->string = g_string_new(NULL); v->human = human; v->visitor.type = VISITOR_OUTPUT; v->visitor.type_int64 = print_type_int64; v->visitor.type_uint64 = print_type_uint64; v->visitor.type_size = print_type_size; v->visitor.type_bool = print_type_bool; v->visitor.type_str = print_type_str; v->visitor.type_number = print_type_number; v->visitor.start_list = start_list; v->visitor.next_list = next_list; v->visitor.end_list = end_list; v->visitor.free = string_output_free; return v; }
4,829
qemu
568c73a4783cd981e9aa6de4f15dcda7829643ad
0
int qemu_input_key_value_to_number(const KeyValue *value) { if (value->kind == KEY_VALUE_KIND_QCODE) { return qcode_to_number[value->qcode]; } else { assert(value->kind == KEY_VALUE_KIND_NUMBER); return value->number; } }
4,831
qemu
2399d4e7cec22ecf1c51062d2ebfd45220dbaace
0
uint64_t HELPER(paired_cmpxchg64_be)(CPUARMState *env, uint64_t addr, uint64_t new_lo, uint64_t new_hi) { uintptr_t ra = GETPC(); Int128 oldv, cmpv, newv; bool success; cmpv = int128_make128(env->exclusive_val, env->exclusive_high); newv = int128_make128(new_lo, new_hi); if (parallel_cpus) { #ifndef CONFIG_ATOMIC128 cpu_loop_exit_atomic(ENV_GET_CPU(env), ra); #else int mem_idx = cpu_mmu_index(env, false); TCGMemOpIdx oi = make_memop_idx(MO_BEQ | MO_ALIGN_16, mem_idx); oldv = helper_atomic_cmpxchgo_be_mmu(env, addr, cmpv, newv, oi, ra); success = int128_eq(oldv, cmpv); #endif } else { uint64_t o0, o1; #ifdef CONFIG_USER_ONLY /* ??? Enforce alignment. */ uint64_t *haddr = g2h(addr); o1 = ldq_be_p(haddr + 0); o0 = ldq_be_p(haddr + 1); oldv = int128_make128(o0, o1); success = int128_eq(oldv, cmpv); if (success) { stq_be_p(haddr + 0, int128_gethi(newv)); stq_be_p(haddr + 1, int128_getlo(newv)); } #else int mem_idx = cpu_mmu_index(env, false); TCGMemOpIdx oi0 = make_memop_idx(MO_BEQ | MO_ALIGN_16, mem_idx); TCGMemOpIdx oi1 = make_memop_idx(MO_BEQ, mem_idx); o1 = helper_be_ldq_mmu(env, addr + 0, oi0, ra); o0 = helper_be_ldq_mmu(env, addr + 8, oi1, ra); oldv = int128_make128(o0, o1); success = int128_eq(oldv, cmpv); if (success) { helper_be_stq_mmu(env, addr + 0, int128_gethi(newv), oi1, ra); helper_be_stq_mmu(env, addr + 8, int128_getlo(newv), oi1, ra); } #endif } return !success; }
4,833
qemu
e91171e30235ae99ab8060988aa3c9536692bba8
0
void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload) { /* * Artificially limit timeout rate to something * achievable under QEMU. Otherwise, QEMU spends all * its time generating timer interrupts, and there * is no forward progress. * About ten microseconds is the fastest that really works * on the current generation of host machines. */ if (!use_icount && limit * s->period < 10000 && s->period) { limit = 10000 / s->period; } s->limit = limit; if (reload) s->delta = limit; if (s->enabled && reload) { s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); ptimer_reload(s); } }
4,834
FFmpeg
f20b67173ca6a05b8c3dee02dad3b7243b96292b
0
static inline void conv_to_int32(int32_t *loc, float *samples, int num, float norm) { int i; for (i = 0; i < num; i++) loc[i] = ceilf((samples[i]/norm)*INT32_MAX); }
4,836
FFmpeg
d1adad3cca407f493c3637e20ecd4f7124e69212
0
static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst, long dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { #if ARCH_X86 #if COMPILE_TEMPLATE_MMX2 int32_t *filterPos = c->hChrFilterPos; int16_t *filter = c->hChrFilter; int canMMX2BeUsed = c->canMMX2BeUsed; void *mmx2FilterCode= c->chrMmx2FilterCode; int i; #if defined(PIC) DECLARE_ALIGNED(8, uint64_t, ebxsave); #endif if (canMMX2BeUsed) { __asm__ volatile( #if defined(PIC) "mov %%"REG_b", %6 \n\t" #endif "pxor %%mm7, %%mm7 \n\t" "mov %0, %%"REG_c" \n\t" "mov %1, %%"REG_D" \n\t" "mov %2, %%"REG_d" \n\t" "mov %3, %%"REG_b" \n\t" "xor %%"REG_a", %%"REG_a" \n\t" // i PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE "xor %%"REG_a", %%"REG_a" \n\t" // i "mov %5, %%"REG_c" \n\t" // src "mov %1, %%"REG_D" \n\t" // buf1 "add $"AV_STRINGIFY(VOF)", %%"REG_D" \n\t" PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE #if defined(PIC) "mov %6, %%"REG_b" \n\t" #endif :: "m" (src1), "m" (dst), "m" (filter), "m" (filterPos), "m" (mmx2FilterCode), "m" (src2) #if defined(PIC) ,"m" (ebxsave) #endif : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D #if !defined(PIC) ,"%"REG_b #endif ); for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { //printf("%d %d %d\n", dstWidth, i, srcW); dst[i] = src1[srcW-1]*128; dst[i+VOFW] = src2[srcW-1]*128; } } else { #endif /* COMPILE_TEMPLATE_MMX2 */ x86_reg xInc_shr16 = (x86_reg) (xInc >> 16); uint16_t xInc_mask = xInc & 0xffff; x86_reg dstWidth_reg = dstWidth; __asm__ volatile( "xor %%"REG_a", %%"REG_a" \n\t" // i "xor %%"REG_d", %%"REG_d" \n\t" // xx "xorl %%ecx, %%ecx \n\t" // xalpha ".p2align 4 \n\t" "1: \n\t" "mov %0, %%"REG_S" \n\t" "movzbl (%%"REG_S", %%"REG_d"), %%edi \n\t" //src[xx] "movzbl 1(%%"REG_S", %%"REG_d"), %%esi \n\t" //src[xx+1] FAST_BILINEAR_X86 "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" "movzbl (%5, %%"REG_d"), %%edi \n\t" //src[xx] "movzbl 1(%5, %%"REG_d"), %%esi \n\t" //src[xx+1] FAST_BILINEAR_X86 "movw %%si, "AV_STRINGIFY(VOF)"(%%"REG_D", %%"REG_a", 2) \n\t" "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry "add $1, %%"REG_a" \n\t" "cmp %2, %%"REG_a" \n\t" " jb 1b \n\t" /* GCC 3.3 makes MPlayer crash on IA-32 machines when using "g" operand here, which is needed to support GCC 4.0. */ #if ARCH_X86_64 && AV_GCC_VERSION_AT_LEAST(3,4) :: "m" (src1), "m" (dst), "g" (dstWidth_reg), "m" (xInc_shr16), "m" (xInc_mask), #else :: "m" (src1), "m" (dst), "m" (dstWidth_reg), "m" (xInc_shr16), "m" (xInc_mask), #endif "r" (src2) : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" ); #if COMPILE_TEMPLATE_MMX2 } //if MMX2 can't be used #endif #else int i; unsigned int xpos=0; for (i=0;i<dstWidth;i++) { register unsigned int xx=xpos>>16; register unsigned int xalpha=(xpos&0xFFFF)>>9; dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha); dst[i+VOFW]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha); /* slower dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha; dst[i+VOFW]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha; */ xpos+=xInc; } #endif /* ARCH_X86 */ }
4,837
qemu
f06b2031a31cdd3acf6f61a977e505b8c6b58f73
0
static void ga_channel_listen_close(GAChannel *c) { g_assert(c->method == GA_CHANNEL_UNIX_LISTEN); g_assert(c->listen_channel); g_io_channel_shutdown(c->listen_channel, true, NULL); g_io_channel_unref(c->listen_channel); c->listen_channel = NULL; }
4,838
qemu
758e8e38eb582e3dc87fd55a1d234c25108a7b7f
0
static int v9fs_do_setuid(V9fsState *s, uid_t uid) { return s->ops->setuid(&s->ctx, uid); }
4,839
qemu
c1076c3e13a86140cc2ba29866512df8460cc7c2
0
static void vgafb_update_display(void *opaque) { MilkymistVgafbState *s = opaque; SysBusDevice *sbd; DisplaySurface *surface = qemu_console_surface(s->con); int first = 0; int last = 0; drawfn fn; if (!vgafb_enabled(s)) { return; } sbd = SYS_BUS_DEVICE(s); int dest_width = s->regs[R_HRES]; switch (surface_bits_per_pixel(surface)) { case 0: return; case 8: fn = draw_line_8; break; case 15: fn = draw_line_15; dest_width *= 2; break; case 16: fn = draw_line_16; dest_width *= 2; break; case 24: fn = draw_line_24; dest_width *= 3; break; case 32: fn = draw_line_32; dest_width *= 4; break; default: hw_error("milkymist_vgafb: bad color depth\n"); break; } framebuffer_update_display(surface, sysbus_address_space(sbd), s->regs[R_BASEADDRESS] + s->fb_offset, s->regs[R_HRES], s->regs[R_VRES], s->regs[R_HRES] * 2, dest_width, 0, s->invalidate, fn, NULL, &first, &last); if (first >= 0) { dpy_gfx_update(s->con, 0, first, s->regs[R_HRES], last - first + 1); } s->invalidate = 0; }
4,840
qemu
8543243c29a60f102d7a3d98027b46bc8cdac421
0
static void mainstone_common_init(int ram_size, int vga_ram_size, DisplayState *ds, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model, enum mainstone_model_e model, int arm_id) { uint32_t mainstone_ram = 0x04000000; uint32_t mainstone_rom = 0x00800000; struct pxa2xx_state_s *cpu; qemu_irq *mst_irq; int index; if (!cpu_model) cpu_model = "pxa270-c5"; /* Setup CPU & memory */ if (ram_size < mainstone_ram + mainstone_rom + PXA2XX_INTERNAL_SIZE) { fprintf(stderr, "This platform requires %i bytes of memory\n", mainstone_ram + mainstone_rom + PXA2XX_INTERNAL_SIZE); exit(1); } cpu = pxa270_init(mainstone_ram, ds, cpu_model); cpu_register_physical_memory(0, mainstone_rom, qemu_ram_alloc(mainstone_rom) | IO_MEM_ROM); /* Setup initial (reset) machine state */ cpu->env->regs[15] = PXA2XX_SDRAM_BASE; /* There are two 32MiB flash devices on the board */ index = drive_get_index(IF_PFLASH, 0, 0); if (index == -1) { fprintf(stderr, "Two flash images must be given with the " "'pflash' parameter\n"); exit(1); } if (!pflash_register(MST_FLASH_0, mainstone_ram + PXA2XX_INTERNAL_SIZE, drives_table[index].bdrv, 256 * 1024, 128, 4, 0, 0, 0, 0)) { fprintf(stderr, "qemu: Error registering flash memory.\n"); exit(1); } index = drive_get_index(IF_PFLASH, 0, 1); if (index == -1) { fprintf(stderr, "Two flash images must be given with the " "'pflash' parameter\n"); exit(1); } if (!pflash_register(MST_FLASH_1, mainstone_ram + PXA2XX_INTERNAL_SIZE, drives_table[index].bdrv, 256 * 1024, 128, 4, 0, 0, 0, 0)) { fprintf(stderr, "qemu: Error registering flash memory.\n"); exit(1); } mst_irq = mst_irq_init(cpu, MST_FPGA_PHYS, PXA2XX_PIC_GPIO_0); /* MMC/SD host */ pxa2xx_mmci_handlers(cpu->mmc, mst_irq[MMC_IRQ], mst_irq[MMC_IRQ]); smc91c111_init(&nd_table[0], MST_ETH_PHYS, mst_irq[ETHERNET_IRQ]); arm_load_kernel(cpu->env, mainstone_ram, kernel_filename, kernel_cmdline, initrd_filename, arm_id, PXA2XX_SDRAM_BASE); }
4,841
qemu
fc89efe693278c79273f3bbf6b581e8a749c85b0
0
uint32_t HELPER(xc)(CPUS390XState *env, uint32_t l, uint64_t dest, uint64_t src) { int i; unsigned char x; uint32_t cc = 0; HELPER_LOG("%s l %d dest %" PRIx64 " src %" PRIx64 "\n", __func__, l, dest, src); #ifndef CONFIG_USER_ONLY /* xor with itself is the same as memset(0) */ if ((l > 32) && (src == dest) && (src & TARGET_PAGE_MASK) == ((src + l) & TARGET_PAGE_MASK)) { mvc_fast_memset(env, l + 1, dest, 0); return 0; } #else if (src == dest) { memset(g2h(dest), 0, l + 1); return 0; } #endif for (i = 0; i <= l; i++) { x = cpu_ldub_data(env, dest + i) ^ cpu_ldub_data(env, src + i); if (x) { cc = 1; } cpu_stb_data(env, dest + i, x); } return cc; }
4,843
qemu
4daf62594d13dfca2ce3a74dd3bddee5f54d7127
0
static int xen_pt_pci_config_access_check(PCIDevice *d, uint32_t addr, int len) { /* check offset range */ if (addr >= 0xFF) { XEN_PT_ERR(d, "Failed to access register with offset exceeding 0xFF. " "(addr: 0x%02x, len: %d)\n", addr, len); return -1; } /* check read size */ if ((len != 1) && (len != 2) && (len != 4)) { XEN_PT_ERR(d, "Failed to access register with invalid access length. " "(addr: 0x%02x, len: %d)\n", addr, len); return -1; } /* check offset alignment */ if (addr & (len - 1)) { XEN_PT_ERR(d, "Failed to access register with invalid access size " "alignment. (addr: 0x%02x, len: %d)\n", addr, len); return -1; } return 0; }
4,844
qemu
2c1885adcf0312da80c7317b09f9adad97fa0fc6
0
static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num) { BDRVDMGState *s = bs->opaque; if(!is_sector_in_chunk(s,s->current_chunk,sector_num)) { int ret; uint32_t chunk = search_chunk(s,sector_num); if(chunk>=s->n_chunks) return -1; s->current_chunk = s->n_chunks; switch(s->types[chunk]) { case 0x80000005: { /* zlib compressed */ int i; /* we need to buffer, because only the chunk as whole can be * inflated. */ i=0; do { ret = bdrv_pread(bs->file, s->offsets[chunk] + i, s->compressed_chunk+i, s->lengths[chunk]-i); if(ret<0 && errno==EINTR) ret=0; i+=ret; } while(ret>=0 && ret+i<s->lengths[chunk]); if (ret != s->lengths[chunk]) return -1; s->zstream.next_in = s->compressed_chunk; s->zstream.avail_in = s->lengths[chunk]; s->zstream.next_out = s->uncompressed_chunk; s->zstream.avail_out = 512*s->sectorcounts[chunk]; ret = inflateReset(&s->zstream); if(ret != Z_OK) return -1; ret = inflate(&s->zstream, Z_FINISH); if(ret != Z_STREAM_END || s->zstream.total_out != 512*s->sectorcounts[chunk]) return -1; break; } case 1: /* copy */ ret = bdrv_pread(bs->file, s->offsets[chunk], s->uncompressed_chunk, s->lengths[chunk]); if (ret != s->lengths[chunk]) return -1; break; case 2: /* zero */ memset(s->uncompressed_chunk, 0, 512*s->sectorcounts[chunk]); break; } s->current_chunk = chunk; } return 0; }
4,845
qemu
64607d088132abdb25bf30d93e97d0c8df7b364c
0
void object_property_add_child(Object *obj, const char *name, Object *child, Error **errp) { Error *local_err = NULL; gchar *type; type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child))); object_property_add(obj, name, type, object_get_child_property, NULL, object_finalize_child_property, child, &local_err); if (local_err) { error_propagate(errp, local_err); goto out; } object_ref(child); g_assert(child->parent == NULL); child->parent = obj; out: g_free(type); }
4,846
qemu
65ed2ed90d9d81fd4b639029be850ea5651f919f
1
void tlb_fill(CPUState *cs, target_ulong addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { bool ret; uint32_t fsr = 0; ARMMMUFaultInfo fi = {}; ret = arm_tlb_fill(cs, addr, access_type, mmu_idx, &fsr, &fi); if (unlikely(ret)) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; uint32_t syn, exc; unsigned int target_el; bool same_el; if (retaddr) { /* now we have a real cpu fault */ cpu_restore_state(cs, retaddr); } target_el = exception_target_el(env); if (fi.stage2) { target_el = 2; env->cp15.hpfar_el2 = extract64(fi.s2addr, 12, 47) << 4; } same_el = arm_current_el(env) == target_el; /* AArch64 syndrome does not have an LPAE bit */ syn = fsr & ~(1 << 9); /* For insn and data aborts we assume there is no instruction syndrome * information; this is always true for exceptions reported to EL1. */ if (access_type == MMU_INST_FETCH) { syn = syn_insn_abort(same_el, 0, fi.s1ptw, syn); exc = EXCP_PREFETCH_ABORT; } else { syn = merge_syn_data_abort(env->exception.syndrome, target_el, same_el, fi.s1ptw, access_type == MMU_DATA_STORE, syn); if (access_type == MMU_DATA_STORE && arm_feature(env, ARM_FEATURE_V6)) { fsr |= (1 << 11); } exc = EXCP_DATA_ABORT; } env->exception.vaddress = addr; env->exception.fsr = fsr; raise_exception(env, exc, syn, target_el); } }
4,850
FFmpeg
1f1207145a0f2d26e5e3525bea6cc417a3ec39cf
1
static inline FFAMediaCodec *codec_create(int method, const char *arg) { int ret = -1; JNIEnv *env = NULL; FFAMediaCodec *codec = NULL; jstring jarg = NULL; jobject object = NULL; jmethodID create_id = NULL; codec = av_mallocz(sizeof(FFAMediaCodec)); if (!codec) { return NULL; codec->class = &amediacodec_class; env = ff_jni_get_env(codec); if (!env) { av_freep(&codec); return NULL; if (ff_jni_init_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec) < 0) { goto fail; jarg = ff_jni_utf_chars_to_jstring(env, arg, codec); if (!jarg) { goto fail; switch (method) { case CREATE_CODEC_BY_NAME: create_id = codec->jfields.create_by_codec_name_id; break; case CREATE_DECODER_BY_TYPE: create_id = codec->jfields.create_decoder_by_type_id; break; case CREATE_ENCODER_BY_TYPE: create_id = codec->jfields.create_encoder_by_type_id; break; default: av_assert0(0); object = (*env)->CallStaticObjectMethod(env, codec->jfields.mediacodec_class, create_id, jarg); if (ff_jni_exception_check(env, 1, codec) < 0) { goto fail; codec->object = (*env)->NewGlobalRef(env, object); if (!codec->object) { goto fail; if (codec_init_static_fields(codec) < 0) { goto fail; if (codec->jfields.get_input_buffer_id && codec->jfields.get_output_buffer_id) { codec->has_get_i_o_buffer = 1; ret = 0; fail: if (jarg) { (*env)->DeleteLocalRef(env, jarg); if (object) { (*env)->DeleteLocalRef(env, object); if (ret < 0) { ff_jni_reset_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec); av_freep(&codec); return codec;
4,851
FFmpeg
b8ed15d6378f00e158c72c526fa0fce17da77361
1
static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size) { if (buf_size < 13) return AVERROR_INVALIDDATA; if (memcmp(buf, "FLV", 3)) return AVERROR_INVALIDDATA; buf += 13; buf_size -= 13; while (buf_size >= 11 + 4) { int type = buf[0]; int size = AV_RB24(&buf[1]) + 11 + 4; if (size > buf_size) return AVERROR_INVALIDDATA; if (type == 8 || type == 9) { if (os->nb_extra_packets > FF_ARRAY_ELEMS(os->extra_packets)) return AVERROR_INVALIDDATA; os->extra_packet_sizes[os->nb_extra_packets] = size; os->extra_packets[os->nb_extra_packets] = av_malloc(size); if (!os->extra_packets[os->nb_extra_packets]) return AVERROR(ENOMEM); memcpy(os->extra_packets[os->nb_extra_packets], buf, size); os->nb_extra_packets++; } else if (type == 0x12) { if (os->metadata) return AVERROR_INVALIDDATA; os->metadata_size = size - 11 - 4; os->metadata = av_malloc(os->metadata_size); if (!os->metadata) return AVERROR(ENOMEM); memcpy(os->metadata, buf + 11, os->metadata_size); } buf += size; buf_size -= size; } if (!os->metadata) return AVERROR_INVALIDDATA; return 0; }
4,852
qemu
d0bce760e04b1658a3b4ac95be2839ae20fd86db
1
static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr, const uint8_t *buf, uint16_t len) { OMAPI2C *s = (OMAPI2C *)i2c; uint16_t data; omap_i2c_set_slave_addr(s, addr); data = len; memwrite(s->addr + OMAP_I2C_CNT, &data, 2); data = OMAP_I2C_CON_I2C_EN | OMAP_I2C_CON_TRX | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT | OMAP_I2C_CON_STP; memwrite(s->addr + OMAP_I2C_CON, &data, 2); memread(s->addr + OMAP_I2C_CON, &data, 2); g_assert((data & OMAP_I2C_CON_STP) != 0); memread(s->addr + OMAP_I2C_STAT, &data, 2); g_assert((data & OMAP_I2C_STAT_NACK) == 0); while (len > 1) { memread(s->addr + OMAP_I2C_STAT, &data, 2); g_assert((data & OMAP_I2C_STAT_XRDY) != 0); memwrite(s->addr + OMAP_I2C_DATA, buf, 2); buf = (uint8_t *)buf + 2; len -= 2; } if (len == 1) { memread(s->addr + OMAP_I2C_STAT, &data, 2); g_assert((data & OMAP_I2C_STAT_XRDY) != 0); memwrite(s->addr + OMAP_I2C_DATA, buf, 1); } memread(s->addr + OMAP_I2C_CON, &data, 2); g_assert((data & OMAP_I2C_CON_STP) == 0); }
4,853
qemu
ce3bc112cdb1d462e2d52eaa17a7314e7f3af504
1
static void mps2_common_init(MachineState *machine) { MPS2MachineState *mms = MPS2_MACHINE(machine); MPS2MachineClass *mmc = MPS2_MACHINE_GET_CLASS(machine); MemoryRegion *system_memory = get_system_memory(); DeviceState *armv7m, *sccdev; if (!machine->cpu_model) { machine->cpu_model = mmc->cpu_model; } if (strcmp(machine->cpu_model, mmc->cpu_model) != 0) { error_report("This board can only be used with CPU %s", mmc->cpu_model); exit(1); } /* The FPGA images have an odd combination of different RAMs, * because in hardware they are different implementations and * connected to different buses, giving varying performance/size * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily * call the 16MB our "system memory", as it's the largest lump. * * Common to both boards: * 0x21000000..0x21ffffff : PSRAM (16MB) * AN385 only: * 0x00000000 .. 0x003fffff : ZBT SSRAM1 * 0x00400000 .. 0x007fffff : mirror of ZBT SSRAM1 * 0x20000000 .. 0x203fffff : ZBT SSRAM 2&3 * 0x20400000 .. 0x207fffff : mirror of ZBT SSRAM 2&3 * 0x01000000 .. 0x01003fff : block RAM (16K) * 0x01004000 .. 0x01007fff : mirror of above * 0x01008000 .. 0x0100bfff : mirror of above * 0x0100c000 .. 0x0100ffff : mirror of above * AN511 only: * 0x00000000 .. 0x0003ffff : FPGA block RAM * 0x00400000 .. 0x007fffff : ZBT SSRAM1 * 0x20000000 .. 0x2001ffff : SRAM * 0x20400000 .. 0x207fffff : ZBT SSRAM 2&3 * * The AN385 has a feature where the lowest 16K can be mapped * either to the bottom of the ZBT SSRAM1 or to the block RAM. * This is of no use for QEMU so we don't implement it (as if * zbt_boot_ctrl is always zero). */ memory_region_allocate_system_memory(&mms->psram, NULL, "mps.ram", 0x1000000); memory_region_add_subregion(system_memory, 0x21000000, &mms->psram); switch (mmc->fpga_type) { case FPGA_AN385: make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000); make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000); make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000); make_ram_alias(&mms->ssram23_m, "mps.ssram23_m", &mms->ssram23, 0x20400000); make_ram(&mms->blockram, "mps.blockram", 0x01000000, 0x4000); make_ram_alias(&mms->blockram_m1, "mps.blockram_m1", &mms->blockram, 0x01004000); make_ram_alias(&mms->blockram_m2, "mps.blockram_m2", &mms->blockram, 0x01008000); make_ram_alias(&mms->blockram_m3, "mps.blockram_m3", &mms->blockram, 0x0100c000); break; case FPGA_AN511: make_ram(&mms->blockram, "mps.blockram", 0x0, 0x40000); make_ram(&mms->ssram1, "mps.ssram1", 0x00400000, 0x00800000); make_ram(&mms->sram, "mps.sram", 0x20000000, 0x20000); make_ram(&mms->ssram23, "mps.ssram23", 0x20400000, 0x400000); break; default: g_assert_not_reached(); } object_initialize(&mms->armv7m, sizeof(mms->armv7m), TYPE_ARMV7M); armv7m = DEVICE(&mms->armv7m); qdev_set_parent_bus(armv7m, sysbus_get_default()); switch (mmc->fpga_type) { case FPGA_AN385: qdev_prop_set_uint32(armv7m, "num-irq", 32); break; case FPGA_AN511: qdev_prop_set_uint32(armv7m, "num-irq", 64); break; default: g_assert_not_reached(); } qdev_prop_set_string(armv7m, "cpu-model", machine->cpu_model); object_property_set_link(OBJECT(&mms->armv7m), OBJECT(system_memory), "memory", &error_abort); object_property_set_bool(OBJECT(&mms->armv7m), true, "realized", &error_fatal); create_unimplemented_device("zbtsmram mirror", 0x00400000, 0x00400000); create_unimplemented_device("RESERVED 1", 0x00800000, 0x00800000); create_unimplemented_device("Block RAM", 0x01000000, 0x00010000); create_unimplemented_device("RESERVED 2", 0x01010000, 0x1EFF0000); create_unimplemented_device("RESERVED 3", 0x20800000, 0x00800000); create_unimplemented_device("PSRAM", 0x21000000, 0x01000000); /* These three ranges all cover multiple devices; we may implement * some of them below (in which case the real device takes precedence * over the unimplemented-region mapping). */ create_unimplemented_device("CMSDK APB peripheral region @0x40000000", 0x40000000, 0x00010000); create_unimplemented_device("CMSDK peripheral region @0x40010000", 0x40010000, 0x00010000); create_unimplemented_device("Extra peripheral region @0x40020000", 0x40020000, 0x00010000); create_unimplemented_device("RESERVED 4", 0x40030000, 0x001D0000); create_unimplemented_device("VGA", 0x41000000, 0x0200000); switch (mmc->fpga_type) { case FPGA_AN385: { /* The overflow IRQs for UARTs 0, 1 and 2 are ORed together. * Overflow for UARTs 4 and 5 doesn't trigger any interrupt. */ Object *orgate; DeviceState *orgate_dev; int i; orgate = object_new(TYPE_OR_IRQ); object_property_set_int(orgate, 6, "num-lines", &error_fatal); object_property_set_bool(orgate, true, "realized", &error_fatal); orgate_dev = DEVICE(orgate); qdev_connect_gpio_out(orgate_dev, 0, qdev_get_gpio_in(armv7m, 12)); for (i = 0; i < 5; i++) { static const hwaddr uartbase[] = {0x40004000, 0x40005000, 0x40006000, 0x40007000, 0x40009000}; Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL; /* RX irq number; TX irq is always one greater */ static const int uartirq[] = {0, 2, 4, 18, 20}; qemu_irq txovrint = NULL, rxovrint = NULL; if (i < 3) { txovrint = qdev_get_gpio_in(orgate_dev, i * 2); rxovrint = qdev_get_gpio_in(orgate_dev, i * 2 + 1); } cmsdk_apb_uart_create(uartbase[i], qdev_get_gpio_in(armv7m, uartirq[i] + 1), qdev_get_gpio_in(armv7m, uartirq[i]), txovrint, rxovrint, NULL, uartchr, SYSCLK_FRQ); } break; } case FPGA_AN511: { /* The overflow IRQs for all UARTs are ORed together. * Tx and Rx IRQs for each UART are ORed together. */ Object *orgate; DeviceState *orgate_dev; int i; orgate = object_new(TYPE_OR_IRQ); object_property_set_int(orgate, 10, "num-lines", &error_fatal); object_property_set_bool(orgate, true, "realized", &error_fatal); orgate_dev = DEVICE(orgate); qdev_connect_gpio_out(orgate_dev, 0, qdev_get_gpio_in(armv7m, 12)); for (i = 0; i < 5; i++) { /* system irq numbers for the combined tx/rx for each UART */ static const int uart_txrx_irqno[] = {0, 2, 45, 46, 56}; static const hwaddr uartbase[] = {0x40004000, 0x40005000, 0x4002c000, 0x4002d000, 0x4002e000}; Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL; Object *txrx_orgate; DeviceState *txrx_orgate_dev; txrx_orgate = object_new(TYPE_OR_IRQ); object_property_set_int(txrx_orgate, 2, "num-lines", &error_fatal); object_property_set_bool(txrx_orgate, true, "realized", &error_fatal); txrx_orgate_dev = DEVICE(txrx_orgate); qdev_connect_gpio_out(txrx_orgate_dev, 0, qdev_get_gpio_in(armv7m, uart_txrx_irqno[i])); cmsdk_apb_uart_create(uartbase[i], qdev_get_gpio_in(txrx_orgate_dev, 0), qdev_get_gpio_in(txrx_orgate_dev, 1), qdev_get_gpio_in(orgate_dev, 0), qdev_get_gpio_in(orgate_dev, 1), NULL, uartchr, SYSCLK_FRQ); } break; } default: g_assert_not_reached(); } cmsdk_apb_timer_create(0x40000000, qdev_get_gpio_in(armv7m, 8), SYSCLK_FRQ); cmsdk_apb_timer_create(0x40001000, qdev_get_gpio_in(armv7m, 9), SYSCLK_FRQ); object_initialize(&mms->scc, sizeof(mms->scc), TYPE_MPS2_SCC); sccdev = DEVICE(&mms->scc); qdev_set_parent_bus(sccdev, sysbus_get_default()); qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2); qdev_prop_set_uint32(sccdev, "scc-aid", 0x02000008); qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id); object_property_set_bool(OBJECT(&mms->scc), true, "realized", &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(sccdev), 0, 0x4002f000); /* In hardware this is a LAN9220; the LAN9118 is software compatible * except that it doesn't support the checksum-offload feature. */ lan9118_init(&nd_table[0], 0x40200000, qdev_get_gpio_in(armv7m, mmc->fpga_type == FPGA_AN385 ? 13 : 47)); system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000); }
4,854
FFmpeg
369a12082635bb6655412dd4407759caf48d48c9
1
static int xbm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { AVFrame *p = data; const uint8_t *end, *ptr = avpkt->data; uint8_t *dst; int ret, linesize, i, j; end = avpkt->data + avpkt->size; while (!avctx->width || !avctx->height) { char name[256]; int number, len; ptr += strcspn(ptr, "#"); if (sscanf(ptr, "#define %256s %u", name, &number) != 2) { av_log(avctx, AV_LOG_ERROR, "Unexpected preprocessor directive\n"); return AVERROR_INVALIDDATA; } len = strlen(name); if ((len > 6) && !avctx->height && !memcmp(name + len - 7, "_height", 7)) { avctx->height = number; } else if ((len > 5) && !avctx->width && !memcmp(name + len - 6, "_width", 6)) { avctx->width = number; } else { av_log(avctx, AV_LOG_ERROR, "Unknown define '%s'\n", name); return AVERROR_INVALIDDATA; } ptr += strcspn(ptr, "\n\r") + 1; } if ((ret = ff_get_buffer(avctx, p, 0)) < 0) return ret; // goto start of image data ptr += strcspn(ptr, "{") + 1; linesize = (avctx->width + 7) / 8; for (i = 0; i < avctx->height; i++) { dst = p->data[0] + i * p->linesize[0]; for (j = 0; j < linesize; j++) { uint8_t val; ptr += strcspn(ptr, "x") + 1; if (ptr < end && av_isxdigit(*ptr)) { val = convert(*ptr); ptr++; if (av_isxdigit(*ptr)) val = (val << 4) + convert(*ptr); *dst++ = ff_reverse[val]; } else { av_log(avctx, AV_LOG_ERROR, "Unexpected data at '%.8s'\n", ptr); return AVERROR_INVALIDDATA; } } } p->key_frame = 1; p->pict_type = AV_PICTURE_TYPE_I; *got_frame = 1; return avpkt->size; }
4,855
qemu
800675f11742b6080e40d17b8d5f35d3a5fc5724
1
int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) { MIPSCPU *cpu = MIPS_CPU(cs); CPUMIPSState *env = &cpu->env; target_ulong tmp; tmp = ldtul_p(mem_buf); if (n < 32) { env->active_tc.gpr[n] = tmp; return sizeof(target_ulong); } if (env->CP0_Config1 & (1 << CP0C1_FP) && n >= 38 && n < 73) { if (n < 70) { if (env->CP0_Status & (1 << CP0St_FR)) { env->active_fpu.fpr[n - 38].d = tmp; } else { env->active_fpu.fpr[n - 38].w[FP_ENDIAN_IDX] = tmp; } } switch (n) { case 70: env->active_fpu.fcr31 = tmp & 0xFF83FFFF; /* set rounding mode */ RESTORE_ROUNDING_MODE; break; case 71: env->active_fpu.fcr0 = tmp; break; } return sizeof(target_ulong); } switch (n) { case 32: env->CP0_Status = tmp; break; case 33: env->active_tc.LO[0] = tmp; break; case 34: env->active_tc.HI[0] = tmp; break; case 35: env->CP0_BadVAddr = tmp; break; case 36: env->CP0_Cause = tmp; break; case 37: env->active_tc.PC = tmp & ~(target_ulong)1; if (tmp & 1) { env->hflags |= MIPS_HFLAG_M16; } else { env->hflags &= ~(MIPS_HFLAG_M16); } break; case 72: /* fp, ignored */ break; default: if (n > 89) { return 0; } /* Other registers are readonly. Ignore writes. */ break; } return sizeof(target_ulong); }
4,856
FFmpeg
e3694478a98bc2cd702b3b3f0bfb19a100da737e
1
static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) { int i; char header[MAX_FRAME_HEADER+1]; int ret; int64_t off = avio_tell(s->pb); for (i = 0; i < MAX_FRAME_HEADER; i++) { header[i] = avio_r8(s->pb); if (header[i] == '\n') { header[i + 1] = 0; break; } } if (s->pb->error) return s->pb->error; else if (s->pb->eof_reached) return AVERROR_EOF; else if (i == MAX_FRAME_HEADER) return AVERROR_INVALIDDATA; if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return AVERROR_INVALIDDATA; ret = av_get_packet(s->pb, pkt, s->packet_size - Y4M_FRAME_MAGIC_LEN); if (ret < 0) return ret; else if (ret != s->packet_size - Y4M_FRAME_MAGIC_LEN) return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO); pkt->stream_index = 0; pkt->pts = (off - s->internal->data_offset) / s->packet_size; pkt->duration = 1; return 0; }
4,857
qemu
72902672dc2ed6281cdb205259c1d52ecf01f6b2
1
uint64_t HELPER(neon_add_saturate_u64)(uint64_t src1, uint64_t src2) { uint64_t res; res = src1 + src2; if (res < src1) { env->QF = 1; res = ~(uint64_t)0; } return res; }
4,858
qemu
ec5fd402645fd4f03d89dcd5840b0e8542549e82
1
static void load_linux(PCMachineState *pcms, FWCfgState *fw_cfg) { uint16_t protocol; int setup_size, kernel_size, initrd_size = 0, cmdline_size; uint32_t initrd_max; uint8_t header[8192], *setup, *kernel, *initrd_data; hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0; FILE *f; char *vmode; MachineState *machine = MACHINE(pcms); const char *kernel_filename = machine->kernel_filename; const char *initrd_filename = machine->initrd_filename; const char *kernel_cmdline = machine->kernel_cmdline; /* Align to 16 bytes as a paranoia measure */ cmdline_size = (strlen(kernel_cmdline)+16) & ~15; /* load the kernel header */ f = fopen(kernel_filename, "rb"); if (!f || !(kernel_size = get_file_size(f)) || fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != MIN(ARRAY_SIZE(header), kernel_size)) { fprintf(stderr, "qemu: could not load kernel '%s': %s\n", kernel_filename, strerror(errno)); /* kernel protocol version */ #if 0 fprintf(stderr, "header magic: %#x\n", ldl_p(header+0x202)); #endif if (ldl_p(header+0x202) == 0x53726448) { protocol = lduw_p(header+0x206); } else { /* This looks like a multiboot kernel. If it is, let's stop treating it like a Linux kernel. */ if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename, kernel_cmdline, kernel_size, header)) { return; protocol = 0; if (protocol < 0x200 || !(header[0x211] & 0x01)) { /* Low kernel */ real_addr = 0x90000; cmdline_addr = 0x9a000 - cmdline_size; prot_addr = 0x10000; } else if (protocol < 0x202) { /* High but ancient kernel */ real_addr = 0x90000; cmdline_addr = 0x9a000 - cmdline_size; prot_addr = 0x100000; } else { /* High and recent kernel */ real_addr = 0x10000; cmdline_addr = 0x20000; prot_addr = 0x100000; #if 0 fprintf(stderr, "qemu: real_addr = 0x" TARGET_FMT_plx "\n" "qemu: cmdline_addr = 0x" TARGET_FMT_plx "\n" "qemu: prot_addr = 0x" TARGET_FMT_plx "\n", real_addr, cmdline_addr, prot_addr); #endif /* highest address for loading the initrd */ if (protocol >= 0x203) { initrd_max = ldl_p(header+0x22c); } else { initrd_max = 0x37ffffff; if (initrd_max >= pcms->below_4g_mem_size - acpi_data_size) { initrd_max = pcms->below_4g_mem_size - acpi_data_size - 1; fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr); fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1); fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); if (protocol >= 0x202) { stl_p(header+0x228, cmdline_addr); } else { stw_p(header+0x20, 0xA33F); stw_p(header+0x22, cmdline_addr-real_addr); /* handle vga= parameter */ vmode = strstr(kernel_cmdline, "vga="); if (vmode) { unsigned int video_mode; /* skip "vga=" */ vmode += 4; if (!strncmp(vmode, "normal", 6)) { video_mode = 0xffff; } else if (!strncmp(vmode, "ext", 3)) { video_mode = 0xfffe; } else if (!strncmp(vmode, "ask", 3)) { video_mode = 0xfffd; } else { video_mode = strtol(vmode, NULL, 0); stw_p(header+0x1fa, video_mode); /* loader type */ /* High nybble = B reserved for QEMU; low nybble is revision number. If this code is substantially changed, you may want to consider incrementing the revision. */ if (protocol >= 0x200) { header[0x210] = 0xB0; /* heap */ if (protocol >= 0x201) { header[0x211] |= 0x80; /* CAN_USE_HEAP */ stw_p(header+0x224, cmdline_addr-real_addr-0x200); /* load initrd */ if (initrd_filename) { if (protocol < 0x200) { fprintf(stderr, "qemu: linux kernel too old to load a ram disk\n"); initrd_size = get_image_size(initrd_filename); if (initrd_size < 0) { fprintf(stderr, "qemu: error reading initrd %s: %s\n", initrd_filename, strerror(errno)); initrd_addr = (initrd_max-initrd_size) & ~4095; initrd_data = g_malloc(initrd_size); load_image(initrd_filename, initrd_data); fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size); stl_p(header+0x218, initrd_addr); stl_p(header+0x21c, initrd_size); /* load kernel and setup */ setup_size = header[0x1f1]; if (setup_size == 0) { setup_size = 4; setup_size = (setup_size+1)*512; kernel_size -= setup_size; setup = g_malloc(setup_size); kernel = g_malloc(kernel_size); fseek(f, 0, SEEK_SET); if (fread(setup, 1, setup_size, f) != setup_size) { fprintf(stderr, "fread() failed\n"); if (fread(kernel, 1, kernel_size, f) != kernel_size) { fprintf(stderr, "fread() failed\n"); fclose(f); memcpy(setup, header, MIN(sizeof(header), setup_size)); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size); fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr); fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size); fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size); option_rom[nb_option_roms].name = "linuxboot.bin"; option_rom[nb_option_roms].bootindex = 0; nb_option_roms++;
4,859
qemu
f3a06403b82c7f036564e4caf18b52ce6885fcfb
1
void ga_command_state_add(GACommandState *cs, void (*init)(void), void (*cleanup)(void)) { GACommandGroup *cg = g_malloc0(sizeof(GACommandGroup)); cg->init = init; cg->cleanup = cleanup; cs->groups = g_slist_append(cs->groups, cg); }
4,860
FFmpeg
ce9e31655e5b8f8db3bb4f13f436fc836062a514
1
static void new_pes_packet(PESContext *pes, AVPacket *pkt) { av_init_packet(pkt); pkt->destruct = av_destruct_packet; pkt->data = pes->buffer; pkt->size = pes->data_index; memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); // Separate out the AC3 substream from an HDMV combined TrueHD/AC3 PID if (pes->sub_st && pes->stream_type == 0x83 && pes->extended_stream_id == 0x76) pkt->stream_index = pes->sub_st->index; else pkt->stream_index = pes->st->index; pkt->pts = pes->pts; pkt->dts = pes->dts; /* store position of first TS packet of this PES packet */ pkt->pos = pes->ts_packet_pos; /* reset pts values */ pes->pts = AV_NOPTS_VALUE; pes->dts = AV_NOPTS_VALUE; pes->buffer = NULL; pes->data_index = 0; }
4,862
FFmpeg
b12d92efd6c0d48665383a9baecc13e7ebbd8a22
1
static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size) { const unsigned char *data_end = data + data_size; GetBitContext gb; int flags, i, j, x, y, op; unsigned char c[3]; unsigned char *dst; uint32_t *palette; flags = *data++; if (flags & 1) { palette = (uint32_t *)seq->frame.data[1]; if (data_end - data < 256 * 3) return AVERROR_INVALIDDATA; for (i = 0; i < 256; i++) { for (j = 0; j < 3; j++, data++) c[j] = (*data << 2) | (*data >> 4); palette[i] = 0xFF << 24 | AV_RB24(c); } seq->frame.palette_has_changed = 1; } if (flags & 2) { if (data_end - data < 128) return AVERROR_INVALIDDATA; init_get_bits(&gb, data, 128 * 8); data += 128; for (y = 0; y < 128; y += 8) for (x = 0; x < 256; x += 8) { dst = &seq->frame.data[0][y * seq->frame.linesize[0] + x]; op = get_bits(&gb, 2); switch (op) { case 1: data = seq_decode_op1(seq, data, data_end, dst); break; case 2: data = seq_decode_op2(seq, data, data_end, dst); break; case 3: data = seq_decode_op3(seq, data, data_end, dst); break; } if (!data) return AVERROR_INVALIDDATA; } } return 0; }
4,863
qemu
d9123d09f711bf1b855de2b5a907d4c85f46d6c3
1
QTestState *qtest_init_without_qmp_handshake(const char *extra_args) { QTestState *s; int sock, qmpsock, i; gchar *socket_path; gchar *qmp_socket_path; gchar *command; const char *qemu_binary; qemu_binary = getenv("QTEST_QEMU_BINARY"); g_assert(qemu_binary != NULL); s = g_malloc(sizeof(*s)); socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid()); qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid()); sock = init_socket(socket_path); qmpsock = init_socket(qmp_socket_path); qtest_add_abrt_handler(kill_qemu_hook_func, s); s->qemu_pid = fork(); if (s->qemu_pid == 0) { setenv("QEMU_AUDIO_DRV", "none", true); command = g_strdup_printf("exec %s " "-qtest unix:%s,nowait " "-qtest-log %s " "-qmp unix:%s,nowait " "-machine accel=qtest " "-display none " "%s", qemu_binary, socket_path, getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null", qmp_socket_path, extra_args ?: ""); execlp("/bin/sh", "sh", "-c", command, NULL); exit(1); } s->fd = socket_accept(sock); if (s->fd >= 0) { s->qmp_fd = socket_accept(qmpsock); } g_free(socket_path); g_free(qmp_socket_path); g_assert(s->fd >= 0 && s->qmp_fd >= 0); s->rx = g_string_new(""); for (i = 0; i < MAX_IRQ; i++) { s->irq_level[i] = false; } if (getenv("QTEST_STOP")) { kill(s->qemu_pid, SIGSTOP); } /* ask endianness of the target */ s->big_endian = qtest_query_target_endianness(s); return s; }
4,864
FFmpeg
2da0d70d5eebe42f9fcd27ee554419ebe2a5da06
1
static inline void RENAME(yuv2packed2)(SwsContext *c, uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { int yalpha1=yalpha^4095; int uvalpha1=uvalpha^4095; int i; #if 0 //isn't used if(flags&SWS_FULL_CHR_H_INT) { switch(dstFormat) { #ifdef HAVE_MMX case PIX_FMT_RGB32: asm volatile( FULL_YSCALEYUV2RGB "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 "movq %%mm3, %%mm1 \n\t" "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 MOVNTQ(%%mm3, (%4, %%REGa, 4)) MOVNTQ(%%mm1, 8(%4, %%REGa, 4)) "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" ((long)dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a ); break; case PIX_FMT_BGR24: asm volatile( FULL_YSCALEYUV2RGB // lsb ... msb "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 "movq %%mm3, %%mm1 \n\t" "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 "movq %%mm3, %%mm2 \n\t" // BGR0BGR0 "psrlq $8, %%mm3 \n\t" // GR0BGR00 "pand "MANGLE(bm00000111)", %%mm2\n\t" // BGR00000 "pand "MANGLE(bm11111000)", %%mm3\n\t" // 000BGR00 "por %%mm2, %%mm3 \n\t" // BGRBGR00 "movq %%mm1, %%mm2 \n\t" "psllq $48, %%mm1 \n\t" // 000000BG "por %%mm1, %%mm3 \n\t" // BGRBGRBG "movq %%mm2, %%mm1 \n\t" // BGR0BGR0 "psrld $16, %%mm2 \n\t" // R000R000 "psrlq $24, %%mm1 \n\t" // 0BGR0000 "por %%mm2, %%mm1 \n\t" // RBGRR000 "mov %4, %%"REG_b" \n\t" "add %%"REG_a", %%"REG_b" \n\t" #ifdef HAVE_MMX2 //FIXME Alignment "movntq %%mm3, (%%"REG_b", %%"REG_a", 2)\n\t" "movntq %%mm1, 8(%%"REG_b", %%"REG_a", 2)\n\t" #else "movd %%mm3, (%%"REG_b", %%"REG_a", 2) \n\t" "psrlq $32, %%mm3 \n\t" "movd %%mm3, 4(%%"REG_b", %%"REG_a", 2) \n\t" "movd %%mm1, 8(%%"REG_b", %%"REG_a", 2) \n\t" #endif "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a, "%"REG_b ); break; case PIX_FMT_BGR555: asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP "paddusb "MANGLE(g5Dither)", %%mm1\n\t" "paddusb "MANGLE(r5Dither)", %%mm0\n\t" "paddusb "MANGLE(b5Dither)", %%mm3\n\t" #endif "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R "psrlw $3, %%mm3 \n\t" "psllw $2, %%mm1 \n\t" "psllw $7, %%mm0 \n\t" "pand "MANGLE(g15Mask)", %%mm1 \n\t" "pand "MANGLE(r15Mask)", %%mm0 \n\t" "por %%mm3, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%4, %%REGa, 2)) "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a ); break; case PIX_FMT_BGR565: asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP "paddusb "MANGLE(g6Dither)", %%mm1\n\t" "paddusb "MANGLE(r5Dither)", %%mm0\n\t" "paddusb "MANGLE(b5Dither)", %%mm3\n\t" #endif "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R "psrlw $3, %%mm3 \n\t" "psllw $3, %%mm1 \n\t" "psllw $8, %%mm0 \n\t" "pand "MANGLE(g16Mask)", %%mm1 \n\t" "pand "MANGLE(r16Mask)", %%mm0 \n\t" "por %%mm3, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%4, %%REGa, 2)) "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a ); break; #endif case PIX_FMT_BGR32: #ifndef HAVE_MMX case PIX_FMT_RGB32: #endif if(dstFormat==PIX_FMT_RGB32) { int i; #ifdef WORDS_BIGENDIAN dest++; #endif for(i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; dest+= 4; } } else if(dstFormat==PIX_FMT_BGR24) { int i; for(i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; dest+= 3; } } else if(dstFormat==PIX_FMT_BGR565) { int i; for(i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); ((uint16_t*)dest)[i] = clip_table16b[(Y + yuvtab_40cf[U]) >>13] | clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | clip_table16r[(Y + yuvtab_3343[V]) >>13]; } } else if(dstFormat==PIX_FMT_BGR555) { int i; for(i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); ((uint16_t*)dest)[i] = clip_table15b[(Y + yuvtab_40cf[U]) >>13] | clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | clip_table15r[(Y + yuvtab_3343[V]) >>13]; } } }//FULL_UV_IPOL else { #endif // if 0 #ifdef HAVE_MMX switch(c->dstFormat) { //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( case PIX_FMT_RGB32: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) WRITEBGR32(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_BGR24: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) WRITEBGR24(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_BGR555: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2\n\t" "paddusb "MANGLE(g5Dither)", %%mm4\n\t" "paddusb "MANGLE(r5Dither)", %%mm5\n\t" #endif WRITEBGR15(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_BGR565: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2\n\t" "paddusb "MANGLE(g6Dither)", %%mm4\n\t" "paddusb "MANGLE(r5Dither)", %%mm5\n\t" #endif WRITEBGR16(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_YUYV422: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2PACKED(%%REGBP, %5) WRITEYUY2(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; default: break; } #endif //HAVE_MMX YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C) }
4,865
FFmpeg
33d6f90e3e0241939ea0be9ca9e1f335942081c8
0
static int http_parse_request(HTTPContext *c) { const char *p; char *p1; enum RedirType redir_type; char cmd[32]; char info[1024], filename[1024]; char url[1024], *q; char protocol[32]; char msg[1024]; const char *mime_type; FFServerStream *stream; int i; char ratebuf[32]; const char *useragent = 0; p = c->buffer; get_word(cmd, sizeof(cmd), &p); av_strlcpy(c->method, cmd, sizeof(c->method)); if (!strcmp(cmd, "GET")) c->post = 0; else if (!strcmp(cmd, "POST")) c->post = 1; else return -1; get_word(url, sizeof(url), &p); av_strlcpy(c->url, url, sizeof(c->url)); get_word(protocol, sizeof(protocol), (const char **)&p); if (strcmp(protocol, "HTTP/1.0") && strcmp(protocol, "HTTP/1.1")) return -1; av_strlcpy(c->protocol, protocol, sizeof(c->protocol)); if (config.debug) http_log("%s - - New connection: %s %s\n", inet_ntoa(c->from_addr.sin_addr), cmd, url); /* find the filename and the optional info string in the request */ p1 = strchr(url, '?'); if (p1) { av_strlcpy(info, p1, sizeof(info)); *p1 = '\0'; } else info[0] = '\0'; av_strlcpy(filename, url + ((*url == '/') ? 1 : 0), sizeof(filename)-1); for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (av_strncasecmp(p, "User-Agent:", 11) == 0) { useragent = p + 11; if (*useragent && *useragent != '\n' && av_isspace(*useragent)) useragent++; break; } p = strchr(p, '\n'); if (!p) break; p++; } redir_type = REDIR_NONE; if (av_match_ext(filename, "asx")) { redir_type = REDIR_ASX; filename[strlen(filename)-1] = 'f'; } else if (av_match_ext(filename, "asf") && (!useragent || av_strncasecmp(useragent, "NSPlayer", 8) != 0)) { /* if this isn't WMP or lookalike, return the redirector file */ redir_type = REDIR_ASF; } else if (av_match_ext(filename, "rpm,ram")) { redir_type = REDIR_RAM; strcpy(filename + strlen(filename)-2, "m"); } else if (av_match_ext(filename, "rtsp")) { redir_type = REDIR_RTSP; compute_real_filename(filename, sizeof(filename) - 1); } else if (av_match_ext(filename, "sdp")) { redir_type = REDIR_SDP; compute_real_filename(filename, sizeof(filename) - 1); } // "redirect" / request to index.html if (!strlen(filename)) av_strlcpy(filename, "index.html", sizeof(filename) - 1); stream = config.first_stream; while (stream) { if (!strcmp(stream->filename, filename) && validate_acl(stream, c)) break; stream = stream->next; } if (!stream) { snprintf(msg, sizeof(msg), "File '%s' not found", url); http_log("File '%s' not found\n", url); goto send_error; } c->stream = stream; memcpy(c->feed_streams, stream->feed_streams, sizeof(c->feed_streams)); memset(c->switch_feed_streams, -1, sizeof(c->switch_feed_streams)); if (stream->stream_type == STREAM_TYPE_REDIRECT) { c->http_error = 301; q = c->buffer; snprintf(q, c->buffer_size, "HTTP/1.0 301 Moved\r\n" "Location: %s\r\n" "Content-type: text/html\r\n" "\r\n" "<html><head><title>Moved</title></head><body>\r\n" "You should be <a href=\"%s\">redirected</a>.\r\n" "</body></html>\r\n", stream->feed_filename, stream->feed_filename); q += strlen(q); /* prepare output buffer */ c->buffer_ptr = c->buffer; c->buffer_end = q; c->state = HTTPSTATE_SEND_HEADER; return 0; } /* If this is WMP, get the rate information */ if (extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) { if (modify_current_stream(c, ratebuf)) { for (i = 0; i < FF_ARRAY_ELEMS(c->feed_streams); i++) { if (c->switch_feed_streams[i] >= 0) c->switch_feed_streams[i] = -1; } } } if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE) current_bandwidth += stream->bandwidth; /* If already streaming this feed, do not let start another feeder. */ if (stream->feed_opened) { snprintf(msg, sizeof(msg), "This feed is already being received."); http_log("Feed '%s' already being received\n", stream->feed_filename); goto send_error; } if (c->post == 0 && config.max_bandwidth < current_bandwidth) { c->http_error = 503; q = c->buffer; snprintf(q, c->buffer_size, "HTTP/1.0 503 Server too busy\r\n" "Content-type: text/html\r\n" "\r\n" "<html><head><title>Too busy</title></head><body>\r\n" "<p>The server is too busy to serve your request at this time.</p>\r\n" "<p>The bandwidth being served (including your stream) is %"PRIu64"kbit/sec, " "and this exceeds the limit of %"PRIu64"kbit/sec.</p>\r\n" "</body></html>\r\n", current_bandwidth, config.max_bandwidth); q += strlen(q); /* prepare output buffer */ c->buffer_ptr = c->buffer; c->buffer_end = q; c->state = HTTPSTATE_SEND_HEADER; return 0; } if (redir_type != REDIR_NONE) { const char *hostinfo = 0; for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (av_strncasecmp(p, "Host:", 5) == 0) { hostinfo = p + 5; break; } p = strchr(p, '\n'); if (!p) break; p++; } if (hostinfo) { char *eoh; char hostbuf[260]; while (av_isspace(*hostinfo)) hostinfo++; eoh = strchr(hostinfo, '\n'); if (eoh) { if (eoh[-1] == '\r') eoh--; if (eoh - hostinfo < sizeof(hostbuf) - 1) { memcpy(hostbuf, hostinfo, eoh - hostinfo); hostbuf[eoh - hostinfo] = 0; c->http_error = 200; q = c->buffer; switch(redir_type) { case REDIR_ASX: snprintf(q, c->buffer_size, "HTTP/1.0 200 ASX Follows\r\n" "Content-type: video/x-ms-asf\r\n" "\r\n" "<ASX Version=\"3\">\r\n" //"<!-- Autogenerated by ffserver -->\r\n" "<ENTRY><REF HREF=\"http://%s/%s%s\"/></ENTRY>\r\n" "</ASX>\r\n", hostbuf, filename, info); q += strlen(q); break; case REDIR_RAM: snprintf(q, c->buffer_size, "HTTP/1.0 200 RAM Follows\r\n" "Content-type: audio/x-pn-realaudio\r\n" "\r\n" "# Autogenerated by ffserver\r\n" "http://%s/%s%s\r\n", hostbuf, filename, info); q += strlen(q); break; case REDIR_ASF: snprintf(q, c->buffer_size, "HTTP/1.0 200 ASF Redirect follows\r\n" "Content-type: video/x-ms-asf\r\n" "\r\n" "[Reference]\r\n" "Ref1=http://%s/%s%s\r\n", hostbuf, filename, info); q += strlen(q); break; case REDIR_RTSP: { char hostname[256], *p; /* extract only hostname */ av_strlcpy(hostname, hostbuf, sizeof(hostname)); p = strrchr(hostname, ':'); if (p) *p = '\0'; snprintf(q, c->buffer_size, "HTTP/1.0 200 RTSP Redirect follows\r\n" /* XXX: incorrect MIME type ? */ "Content-type: application/x-rtsp\r\n" "\r\n" "rtsp://%s:%d/%s\r\n", hostname, ntohs(config.rtsp_addr.sin_port), filename); q += strlen(q); } break; case REDIR_SDP: { uint8_t *sdp_data; int sdp_data_size; socklen_t len; struct sockaddr_in my_addr; snprintf(q, c->buffer_size, "HTTP/1.0 200 OK\r\n" "Content-type: application/sdp\r\n" "\r\n"); q += strlen(q); len = sizeof(my_addr); /* XXX: Should probably fail? */ if (getsockname(c->fd, (struct sockaddr *)&my_addr, &len)) http_log("getsockname() failed\n"); /* XXX: should use a dynamic buffer */ sdp_data_size = prepare_sdp_description(stream, &sdp_data, my_addr.sin_addr); if (sdp_data_size > 0) { memcpy(q, sdp_data, sdp_data_size); q += sdp_data_size; *q = '\0'; av_free(sdp_data); } } break; default: abort(); break; } /* prepare output buffer */ c->buffer_ptr = c->buffer; c->buffer_end = q; c->state = HTTPSTATE_SEND_HEADER; return 0; } } } snprintf(msg, sizeof(msg), "ASX/RAM file not handled"); goto send_error; } stream->conns_served++; /* XXX: add there authenticate and IP match */ if (c->post) { /* if post, it means a feed is being sent */ if (!stream->is_feed) { /* However it might be a status report from WMP! Let us log the * data as it might come handy one day. */ const char *logline = 0; int client_id = 0; for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (av_strncasecmp(p, "Pragma: log-line=", 17) == 0) { logline = p; break; } if (av_strncasecmp(p, "Pragma: client-id=", 18) == 0) client_id = strtol(p + 18, 0, 10); p = strchr(p, '\n'); if (!p) break; p++; } if (logline) { char *eol = strchr(logline, '\n'); logline += 17; if (eol) { if (eol[-1] == '\r') eol--; http_log("%.*s\n", (int) (eol - logline), logline); c->suppress_log = 1; } } #ifdef DEBUG http_log("\nGot request:\n%s\n", c->buffer); #endif if (client_id && extract_rates(ratebuf, sizeof(ratebuf), c->buffer)) { HTTPContext *wmpc; /* Now we have to find the client_id */ for (wmpc = first_http_ctx; wmpc; wmpc = wmpc->next) { if (wmpc->wmp_client_id == client_id) break; } if (wmpc && modify_current_stream(wmpc, ratebuf)) wmpc->switch_pending = 1; } snprintf(msg, sizeof(msg), "POST command not handled"); c->stream = 0; goto send_error; } if (http_start_receive_data(c) < 0) { snprintf(msg, sizeof(msg), "could not open feed"); goto send_error; } c->http_error = 0; c->state = HTTPSTATE_RECEIVE_DATA; return 0; } #ifdef DEBUG if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0) http_log("\nGot request:\n%s\n", c->buffer); #endif if (c->stream->stream_type == STREAM_TYPE_STATUS) goto send_status; /* open input stream */ if (open_input_stream(c, info) < 0) { snprintf(msg, sizeof(msg), "Input stream corresponding to '%s' not found", url); goto send_error; } /* prepare HTTP header */ c->buffer[0] = 0; av_strlcatf(c->buffer, c->buffer_size, "HTTP/1.0 200 OK\r\n"); mime_type = c->stream->fmt->mime_type; if (!mime_type) mime_type = "application/x-octet-stream"; av_strlcatf(c->buffer, c->buffer_size, "Pragma: no-cache\r\n"); /* for asf, we need extra headers */ if (!strcmp(c->stream->fmt->name,"asf_stream")) { /* Need to allocate a client id */ c->wmp_client_id = av_lfg_get(&random_state); av_strlcatf(c->buffer, c->buffer_size, "Server: Cougar 4.1.0.3923\r\nCache-Control: no-cache\r\nPragma: client-id=%d\r\nPragma: features=\"broadcast\"\r\n", c->wmp_client_id); } av_strlcatf(c->buffer, c->buffer_size, "Content-Type: %s\r\n", mime_type); av_strlcatf(c->buffer, c->buffer_size, "\r\n"); q = c->buffer + strlen(c->buffer); /* prepare output buffer */ c->http_error = 0; c->buffer_ptr = c->buffer; c->buffer_end = q; c->state = HTTPSTATE_SEND_HEADER; return 0; send_error: c->http_error = 404; q = c->buffer; htmlstrip(msg); snprintf(q, c->buffer_size, "HTTP/1.0 404 Not Found\r\n" "Content-type: text/html\r\n" "\r\n" "<html>\n" "<head><title>404 Not Found</title></head>\n" "<body>%s</body>\n" "</html>\n", msg); q += strlen(q); /* prepare output buffer */ c->buffer_ptr = c->buffer; c->buffer_end = q; c->state = HTTPSTATE_SEND_HEADER; return 0; send_status: compute_status(c); c->http_error = 200; /* horrible : we use this value to avoid going to the send data state */ c->state = HTTPSTATE_SEND_HEADER; return 0; }
4,866
qemu
60fe637bf0e4d7989e21e50f52526444765c63b4
1
static int get_bitmap(QEMUFile *f, void *pv, size_t size) { unsigned long *bmp = pv; int i, idx = 0; for (i = 0; i < BITS_TO_U64S(size); i++) { uint64_t w = qemu_get_be64(f); bmp[idx++] = w; if (sizeof(unsigned long) == 4 && idx < BITS_TO_LONGS(size)) { bmp[idx++] = w >> 32; } } return 0; }
4,867
qemu
016d2e1dfa21b64a524d3629fdd317d4c25bc3b8
1
long do_sigreturn(CPUM68KState *env) { struct target_sigframe *frame; abi_ulong frame_addr = env->aregs[7] - 4; target_sigset_t target_set; sigset_t set; int d0, i; if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; /* set blocked signals */ if (__get_user(target_set.sig[0], &frame->sc.sc_mask)) goto badframe; for(i = 1; i < TARGET_NSIG_WORDS; i++) { if (__get_user(target_set.sig[i], &frame->extramask[i - 1])) goto badframe; } target_to_host_sigset_internal(&set, &target_set); do_sigprocmask(SIG_SETMASK, &set, NULL); /* restore registers */ if (restore_sigcontext(env, &frame->sc, &d0)) goto badframe; unlock_user_struct(frame, frame_addr, 0); return d0; badframe: unlock_user_struct(frame, frame_addr, 0); force_sig(TARGET_SIGSEGV); return 0; }
4,868
qemu
ad0ebb91cd8b5fdc4a583b03645677771f420a46
1
static int vscsi_send_adapter_info(VSCSIState *s, vscsi_req *req) { struct viosrp_adapter_info *sinfo; struct mad_adapter_info_data info; int rc; sinfo = &req->iu.mad.adapter_info; #if 0 /* What for ? */ rc = spapr_tce_dma_read(&s->vdev, be64_to_cpu(sinfo->buffer), &info, be16_to_cpu(sinfo->common.length)); if (rc) { fprintf(stderr, "vscsi_send_adapter_info: DMA read failure !\n"); } #endif memset(&info, 0, sizeof(info)); strcpy(info.srp_version, SRP_VERSION); strncpy(info.partition_name, "qemu", sizeof("qemu")); info.partition_number = cpu_to_be32(0); info.mad_version = cpu_to_be32(1); info.os_type = cpu_to_be32(2); info.port_max_txu[0] = cpu_to_be32(VSCSI_MAX_SECTORS << 9); rc = spapr_tce_dma_write(&s->vdev, be64_to_cpu(sinfo->buffer), &info, be16_to_cpu(sinfo->common.length)); if (rc) { fprintf(stderr, "vscsi_send_adapter_info: DMA write failure !\n"); } sinfo->common.status = rc ? cpu_to_be32(1) : 0; return vscsi_send_iu(s, req, sizeof(*sinfo), VIOSRP_MAD_FORMAT); }
4,869
qemu
c489780203f9b22aca5539ec7589b7140bdc951f
1
static void qmp_input_type_null(Visitor *v, const char *name, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, true); if (qobject_type(qobj) != QTYPE_QNULL) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "null");
4,870
qemu
4b3fc37788fe5a9c6ec0c43863c78604db40cbb3
1
static void gen_spr_970_lpar(CPUPPCState *env) { /* Logical partitionning */ /* PPC970: HID4 is effectively the LPCR */ spr_register(env, SPR_970_HID4, "HID4", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); }
4,871
qemu
f293709c6af7a65a9bcec09cdba7a60183657a3e
1
static inline void *alloc_code_gen_buffer(void) { void *buf = static_code_gen_buffer; #ifdef __mips__ if (cross_256mb(buf, tcg_ctx.code_gen_buffer_size)) { buf = split_cross_256mb(buf, tcg_ctx.code_gen_buffer_size); } #endif map_exec(buf, tcg_ctx.code_gen_buffer_size); return buf; }
4,872
qemu
b1fe60cd3525871a4c593ad8c2b39b89c19c00d0
1
static void intel_hda_update_int_sts(IntelHDAState *d) { uint32_t sts = 0; uint32_t i; /* update controller status */ if (d->rirb_sts & ICH6_RBSTS_IRQ) { sts |= (1 << 30); } if (d->rirb_sts & ICH6_RBSTS_OVERRUN) { sts |= (1 << 30); } if (d->state_sts & d->wake_en) { sts |= (1 << 30); } /* update stream status */ for (i = 0; i < 8; i++) { /* buffer completion interrupt */ if (d->st[i].ctl & (1 << 26)) { sts |= (1 << i); } } /* update global status */ if (sts & d->int_ctl) { sts |= (1 << 31); } d->int_sts = sts; }
4,875
qemu
f0aa7a8b2d518c54430e4382309281b93e51981a
1
static void do_loadvm(Monitor *mon, const QDict *qdict) { int saved_vm_running = vm_running; const char *name = qdict_get_str(qdict, "name"); vm_stop(0); if (load_vmstate(name) >= 0 && saved_vm_running) vm_start(); }
4,877
FFmpeg
68caef9d48c4f1540b1b3181ebe7062a3417c62a
1
static av_always_inline void mc_chroma_scaled(VP9Context *s, vp9_scaled_mc_func smc, vp9_mc_func (*mc)[2], uint8_t *dst_u, uint8_t *dst_v, ptrdiff_t dst_stride, const uint8_t *ref_u, ptrdiff_t src_stride_u, const uint8_t *ref_v, ptrdiff_t src_stride_v, ThreadFrame *ref_frame, ptrdiff_t y, ptrdiff_t x, const VP56mv *in_mv, int px, int py, int pw, int ph, int bw, int bh, int w, int h, int bytesperpixel, const uint16_t *scale, const uint8_t *step) { if (s->s.frames[CUR_FRAME].tf.f->width == ref_frame->f->width && s->s.frames[CUR_FRAME].tf.f->height == ref_frame->f->height) { mc_chroma_unscaled(s, mc, dst_u, dst_v, dst_stride, ref_u, src_stride_u, ref_v, src_stride_v, ref_frame, y, x, in_mv, bw, bh, w, h, bytesperpixel); } else { int mx, my; int refbw_m1, refbh_m1; int th; VP56mv mv; if (s->ss_h) { // BUG https://code.google.com/p/webm/issues/detail?id=820 mv.x = av_clip(in_mv->x, -(x + pw - px + 4) * 16, (s->cols * 4 - x + px + 3) * 16); mx = scale_mv(mv.x, 0) + (scale_mv(x * 16, 0) & ~15) + (scale_mv(x * 32, 0) & 15); } else { mv.x = av_clip(in_mv->x, -(x + pw - px + 4) * 8, (s->cols * 8 - x + px + 3) * 8); mx = scale_mv(mv.x * 2, 0) + scale_mv(x * 16, 0); } if (s->ss_v) { // BUG https://code.google.com/p/webm/issues/detail?id=820 mv.y = av_clip(in_mv->y, -(y + ph - py + 4) * 16, (s->rows * 4 - y + py + 3) * 16); my = scale_mv(mv.y, 1) + (scale_mv(y * 16, 1) & ~15) + (scale_mv(y * 32, 1) & 15); } else { mv.y = av_clip(in_mv->y, -(y + ph - py + 4) * 8, (s->rows * 8 - y + py + 3) * 8); my = scale_mv(mv.y * 2, 1) + scale_mv(y * 16, 1); } #undef scale_mv y = my >> 4; x = mx >> 4; ref_u += y * src_stride_u + x * bytesperpixel; ref_v += y * src_stride_v + x * bytesperpixel; mx &= 15; my &= 15; refbw_m1 = ((bw - 1) * step[0] + mx) >> 4; refbh_m1 = ((bh - 1) * step[1] + my) >> 4; // FIXME bilinear filter only needs 0/1 pixels, not 3/4 // we use +7 because the last 7 pixels of each sbrow can be changed in // the longest loopfilter of the next sbrow th = (y + refbh_m1 + 4 + 7) >> (6 - s->ss_v); ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0); if (x < 3 || y < 3 || x + 4 >= w - refbw_m1 || y + 4 >= h - refbh_m1) { s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ref_u - 3 * src_stride_u - 3 * bytesperpixel, 288, src_stride_u, refbw_m1 + 8, refbh_m1 + 8, x - 3, y - 3, w, h); ref_u = s->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel; smc(dst_u, dst_stride, ref_u, 288, bh, mx, my, step[0], step[1]); s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ref_v - 3 * src_stride_v - 3 * bytesperpixel, 288, src_stride_v, refbw_m1 + 8, refbh_m1 + 8, x - 3, y - 3, w, h); ref_v = s->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel; smc(dst_v, dst_stride, ref_v, 288, bh, mx, my, step[0], step[1]); } else { smc(dst_u, dst_stride, ref_u, src_stride_u, bh, mx, my, step[0], step[1]); smc(dst_v, dst_stride, ref_v, src_stride_v, bh, mx, my, step[0], step[1]); } } }
4,878
qemu
7d1b0095bff7157e856d1d0e6c4295641ced2752
1
static void gen_add_carry(TCGv dest, TCGv t0, TCGv t1) { TCGv tmp; tcg_gen_add_i32(dest, t0, t1); tmp = load_cpu_field(CF); tcg_gen_add_i32(dest, dest, tmp); dead_tmp(tmp); }
4,880
FFmpeg
efddf2c09aed7400c73ecf327f86a4d0452b94b5
1
static int compat_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt) { AVCodecInternal *avci = avctx->internal; int ret; av_assert0(avci->compat_decode_consumed == 0); *got_frame = 0; avci->compat_decode = 1; if (avci->compat_decode_partial_size > 0 && avci->compat_decode_partial_size != pkt->size) { av_log(avctx, AV_LOG_ERROR, "Got unexpected packet size after a partial decode\n"); ret = AVERROR(EINVAL); goto finish; } if (!avci->compat_decode_partial_size) { ret = avcodec_send_packet(avctx, pkt); if (ret == AVERROR_EOF) ret = 0; else if (ret == AVERROR(EAGAIN)) { /* we fully drain all the output in each decode call, so this should not * ever happen */ ret = AVERROR_BUG; goto finish; } else if (ret < 0) goto finish; } while (ret >= 0) { ret = avcodec_receive_frame(avctx, frame); if (ret < 0) { if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) ret = 0; goto finish; } if (frame != avci->compat_decode_frame) { if (!avctx->refcounted_frames) { ret = unrefcount_frame(avci, frame); if (ret < 0) goto finish; } *got_frame = 1; frame = avci->compat_decode_frame; } else { if (!avci->compat_decode_warned) { av_log(avctx, AV_LOG_WARNING, "The deprecated avcodec_decode_* " "API cannot return all the frames for this decoder. " "Some frames will be dropped. Update your code to the " "new decoding API to fix this.\n"); avci->compat_decode_warned = 1; } } if (avci->draining || (!avctx->codec->bsfs && avci->compat_decode_consumed < pkt->size)) break; } finish: if (ret == 0) { /* if there are any bsfs then assume full packet is always consumed */ if (avctx->codec->bsfs) ret = pkt->size; else ret = FFMIN(avci->compat_decode_consumed, pkt->size); } avci->compat_decode_consumed = 0; avci->compat_decode_partial_size = (ret >= 0) ? pkt->size - ret : 0; return ret; }
4,881
qemu
53593e90d13264dc88b3281ddf75ceaa641df05a
1
static void gen_wsr_debugcause(DisasContext *dc, uint32_t sr, TCGv_i32 v) { }
4,882
FFmpeg
1b00600319506a9bd81b114d2b374051dc1a29a6
1
static int jp2_find_codestream(Jpeg2000DecoderContext *s) { uint32_t atom_size, atom, atom_end; int search_range = 10; while (search_range && bytestream2_get_bytes_left(&s->g) >= 8) { atom_size = bytestream2_get_be32u(&s->g); atom = bytestream2_get_be32u(&s->g); atom_end = bytestream2_tell(&s->g) + atom_size - 8; if (atom == JP2_CODESTREAM) return 1; if (bytestream2_get_bytes_left(&s->g) < atom_size || atom_end < atom_size) return 0; if (atom == JP2_HEADER && atom_size >= 16) { uint32_t atom2_size, atom2, atom2_end; do { atom2_size = bytestream2_get_be32u(&s->g); atom2 = bytestream2_get_be32u(&s->g); atom2_end = bytestream2_tell(&s->g) + atom2_size - 8; if (atom2_size < 8 || atom2_end > atom_end || atom2_end < atom2_size) break; atom2_size -= 8; if (atom2 == JP2_CODESTREAM) { return 1; } else if (atom2 == MKBETAG('c','o','l','r') && atom2_size >= 7) { int method = bytestream2_get_byteu(&s->g); bytestream2_skipu(&s->g, 2); if (method == 1) { s->colour_space = bytestream2_get_be32u(&s->g); } else if (atom2 == MKBETAG('p','c','l','r') && atom2_size >= 6) { int i, size, colour_count, colour_channels, colour_depth[3]; uint32_t r, g, b; colour_count = bytestream2_get_be16u(&s->g); colour_channels = bytestream2_get_byteu(&s->g); // FIXME: Do not ignore channel_sign colour_depth[0] = (bytestream2_get_byteu(&s->g) & 0x7f) + 1; colour_depth[1] = (bytestream2_get_byteu(&s->g) & 0x7f) + 1; colour_depth[2] = (bytestream2_get_byteu(&s->g) & 0x7f) + 1; size = (colour_depth[0] + 7 >> 3) * colour_count + (colour_depth[1] + 7 >> 3) * colour_count + (colour_depth[2] + 7 >> 3) * colour_count; if (colour_count > 256 || colour_channels != 3 || colour_depth[0] > 16 || colour_depth[1] > 16 || colour_depth[2] > 16 || atom2_size < size) { avpriv_request_sample(s->avctx, "Unknown palette"); s->pal8 = 1; for (i = 0; i < colour_count; i++) { if (colour_depth[0] <= 8) { r = bytestream2_get_byteu(&s->g) << 8 - colour_depth[0]; r |= r >> colour_depth[0]; } else { r = bytestream2_get_be16u(&s->g) >> colour_depth[0] - 8; if (colour_depth[1] <= 8) { g = bytestream2_get_byteu(&s->g) << 8 - colour_depth[1]; r |= r >> colour_depth[1]; } else { g = bytestream2_get_be16u(&s->g) >> colour_depth[1] - 8; if (colour_depth[2] <= 8) { b = bytestream2_get_byteu(&s->g) << 8 - colour_depth[2]; r |= r >> colour_depth[2]; } else { b = bytestream2_get_be16u(&s->g) >> colour_depth[2] - 8; s->palette[i] = 0xffu << 24 | r << 16 | g << 8 | b; } else if (atom2 == MKBETAG('c','d','e','f') && atom2_size >= 2) { int n = bytestream2_get_be16u(&s->g); for (; n>0; n--) { int cn = bytestream2_get_be16(&s->g); int av_unused typ = bytestream2_get_be16(&s->g); int asoc = bytestream2_get_be16(&s->g); if (cn < 4 && asoc < 4) s->cdef[cn] = asoc; } else if (atom2 == MKBETAG('r','e','s',' ') && atom2_size >= 18) { int64_t vnum, vden, hnum, hden, vexp, hexp; uint32_t resx; bytestream2_skip(&s->g, 4); resx = bytestream2_get_be32u(&s->g); if (resx != MKBETAG('r','e','s','c') && resx != MKBETAG('r','e','s','d')) { vnum = bytestream2_get_be16u(&s->g); vden = bytestream2_get_be16u(&s->g); hnum = bytestream2_get_be16u(&s->g); hden = bytestream2_get_be16u(&s->g); vexp = bytestream2_get_byteu(&s->g); hexp = bytestream2_get_byteu(&s->g); if (vexp > hexp) { vexp -= hexp; hexp = 0; } else { hexp -= vexp; vexp = 0; if ( INT64_MAX / (hnum * vden) > pow(10, hexp) && INT64_MAX / (vnum * hden) > pow(10, vexp)) av_reduce(&s->sar.den, &s->sar.num, hnum * vden * pow(10, hexp), vnum * hden * pow(10, vexp), INT32_MAX); } while (atom_end - atom2_end >= 8); } else { search_range--; bytestream2_seek(&s->g, atom_end, SEEK_SET); return 0;
4,883
qemu
3dc6f8693694a649a9c83f1e2746565b47683923
0
static void i440fx_realize(PCIDevice *dev, Error **errp) { dev->config[I440FX_SMRAM] = 0x02; if (object_property_get_bool(qdev_get_machine(), "iommu", NULL)) { error_report("warning: i440fx doesn't support emulated iommu"); } }
4,884
FFmpeg
7e7e59409294af9caa63808e56c5cc824c98b4fc
0
static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b) { return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6)); }
4,885
qemu
0b5a24454fc551f0294fe93821e8c643214a55f5
0
static void coroutine_fn bdrv_co_do_rw(void *opaque) { BlockAIOCBCoroutine *acb = opaque; BlockDriverState *bs = acb->common.bs; if (!acb->is_write) { acb->req.error = bdrv_co_do_readv(bs, acb->req.sector, acb->req.nb_sectors, acb->req.qiov, acb->req.flags); } else { acb->req.error = bdrv_co_do_writev(bs, acb->req.sector, acb->req.nb_sectors, acb->req.qiov, acb->req.flags); } acb->bh = aio_bh_new(bdrv_get_aio_context(bs), bdrv_co_em_bh, acb); qemu_bh_schedule(acb->bh); }
4,887
qemu
20a544c7dc2428e8816ed4a87af732884e885f2d
0
static int xen_add_to_physmap(XenIOState *state, hwaddr start_addr, ram_addr_t size, MemoryRegion *mr, hwaddr offset_within_region) { unsigned long i = 0; int rc = 0; XenPhysmap *physmap = NULL; hwaddr pfn, start_gpfn; hwaddr phys_offset = memory_region_get_ram_addr(mr); char path[80], value[17]; const char *mr_name; if (get_physmapping(state, start_addr, size)) { return 0; } if (size <= 0) { return -1; } /* Xen can only handle a single dirty log region for now and we want * the linear framebuffer to be that region. * Avoid tracking any regions that is not videoram and avoid tracking * the legacy vga region. */ if (mr == framebuffer && start_addr > 0xbffff) { goto go_physmap; } return -1; go_physmap: DPRINTF("mapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx"\n", start_addr, start_addr + size); pfn = phys_offset >> TARGET_PAGE_BITS; start_gpfn = start_addr >> TARGET_PAGE_BITS; for (i = 0; i < size >> TARGET_PAGE_BITS; i++) { unsigned long idx = pfn + i; xen_pfn_t gpfn = start_gpfn + i; rc = xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE_gmfn, idx, gpfn); if (rc) { DPRINTF("add_to_physmap MFN %"PRI_xen_pfn" to PFN %" PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc, errno); return -rc; } } mr_name = memory_region_name(mr); physmap = g_malloc(sizeof (XenPhysmap)); physmap->start_addr = start_addr; physmap->size = size; physmap->name = mr_name; physmap->phys_offset = phys_offset; QLIST_INSERT_HEAD(&state->physmap, physmap, list); xc_domain_pin_memory_cacheattr(xen_xc, xen_domid, start_addr >> TARGET_PAGE_BITS, (start_addr + size - 1) >> TARGET_PAGE_BITS, XEN_DOMCTL_MEM_CACHEATTR_WB); snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", xen_domid, (uint64_t)phys_offset); snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)start_addr); if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { return -1; } snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", xen_domid, (uint64_t)phys_offset); snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)size); if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { return -1; } if (mr_name) { snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", xen_domid, (uint64_t)phys_offset); if (!xs_write(state->xenstore, 0, path, mr_name, strlen(mr_name))) { return -1; } } return 0; }
4,888
qemu
1ea879e5580f63414693655fcf0328559cdce138
0
static int fmod_init_in (HWVoiceIn *hw, audsettings_t *as) { int bits16, mode; FMODVoiceIn *fmd = (FMODVoiceIn *) hw; audsettings_t obt_as = *as; if (conf.broken_adc) { return -1; } mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0); fmd->fmod_sample = FSOUND_Sample_Alloc ( FSOUND_FREE, /* index */ conf.nb_samples, /* length */ mode, /* mode */ as->freq, /* freq */ 255, /* volume */ 128, /* pan */ 255 /* priority */ ); if (!fmd->fmod_sample) { fmod_logerr2 ("ADC", "Failed to allocate FMOD sample\n"); return -1; } /* FMOD always operates on little endian frames? */ obt_as.endianness = 0; audio_pcm_init_info (&hw->info, &obt_as); bits16 = (mode & FSOUND_16BITS) != 0; hw->samples = conf.nb_samples; return 0; }
4,889
qemu
ca9567e23454ca94e3911710da4e953ad049b40f
0
static void monitor_control_event(void *opaque, int event) { if (event == CHR_EVENT_OPENED) { QObject *data; Monitor *mon = opaque; json_message_parser_init(&mon->mc->parser, handle_qmp_command); data = qobject_from_jsonf("{ 'QMP': { 'capabilities': [] } }"); assert(data != NULL); monitor_json_emitter(mon, data); qobject_decref(data); } }
4,890
qemu
3e300fa6ad4ee19b16339c25773dec8df0bfb982
0
static void pmac_ide_transfer_cb(void *opaque, int ret) { DBDMA_io *io = opaque; MACIOIDEState *m = io->opaque; IDEState *s = idebus_active_if(&m->bus); int n = 0; int64_t sector_num; int unaligned; if (ret < 0) { MACIO_DPRINTF("DMA error\n"); m->aiocb = NULL; qemu_sglist_destroy(&s->sg); ide_dma_error(s); io->remainder_len = 0; goto done; } if (!m->dma_active) { MACIO_DPRINTF("waiting for data (%#x - %#x - %x)\n", s->nsector, io->len, s->status); /* data not ready yet, wait for the channel to get restarted */ io->processing = false; return; } sector_num = ide_get_sector(s); MACIO_DPRINTF("io_buffer_size = %#x\n", s->io_buffer_size); if (s->io_buffer_size > 0) { m->aiocb = NULL; qemu_sglist_destroy(&s->sg); n = (s->io_buffer_size + 0x1ff) >> 9; sector_num += n; ide_set_sector(s, sector_num); s->nsector -= n; } MACIO_DPRINTF("remainder: %d io->len: %d nsector: %d " "sector_num: %" PRId64 "\n", io->remainder_len, io->len, s->nsector, sector_num); if (io->remainder_len && io->len) { /* guest wants the rest of its previous transfer */ int remainder_len = MIN(io->remainder_len, io->len); uint8_t *p = &io->remainder[0x200 - remainder_len]; MACIO_DPRINTF("copying remainder %d bytes at %#" HWADDR_PRIx "\n", remainder_len, io->addr); switch (s->dma_cmd) { case IDE_DMA_READ: cpu_physical_memory_write(io->addr, p, remainder_len); break; case IDE_DMA_WRITE: cpu_physical_memory_read(io->addr, p, remainder_len); bdrv_write(s->bs, sector_num - 1, io->remainder, 1); break; case IDE_DMA_TRIM: break; } io->addr += remainder_len; io->len -= remainder_len; io->remainder_len -= remainder_len; } if (s->nsector == 0 && !io->remainder_len) { MACIO_DPRINTF("end of transfer\n"); s->status = READY_STAT | SEEK_STAT; ide_set_irq(s->bus); m->dma_active = false; } if (io->len == 0) { MACIO_DPRINTF("end of DMA\n"); goto done; } /* launch next transfer */ s->io_buffer_index = 0; s->io_buffer_size = MIN(io->len, s->nsector * 512); /* handle unaligned accesses first, get them over with and only do the remaining bulk transfer using our async DMA helpers */ unaligned = io->len & 0x1ff; if (unaligned) { int nsector = io->len >> 9; MACIO_DPRINTF("precopying unaligned %d bytes to %#" HWADDR_PRIx "\n", unaligned, io->addr + io->len - unaligned); switch (s->dma_cmd) { case IDE_DMA_READ: bdrv_read(s->bs, sector_num + nsector, io->remainder, 1); cpu_physical_memory_write(io->addr + io->len - unaligned, io->remainder, unaligned); break; case IDE_DMA_WRITE: /* cache the contents in our io struct */ cpu_physical_memory_read(io->addr + io->len - unaligned, io->remainder, unaligned); break; case IDE_DMA_TRIM: break; } io->len -= unaligned; } MACIO_DPRINTF("io->len = %#x\n", io->len); qemu_sglist_init(&s->sg, DEVICE(m), io->len / MACIO_PAGE_SIZE + 1, &address_space_memory); qemu_sglist_add(&s->sg, io->addr, io->len); io->addr += io->len + unaligned; io->remainder_len = (0x200 - unaligned) & 0x1ff; MACIO_DPRINTF("set remainder to: %d\n", io->remainder_len); /* We would read no data from the block layer, thus not get a callback. Just fake completion manually. */ if (!io->len) { pmac_ide_transfer_cb(opaque, 0); return; } io->len = 0; MACIO_DPRINTF("sector_num=%" PRId64 " n=%d, nsector=%d, cmd_cmd=%d\n", sector_num, n, s->nsector, s->dma_cmd); switch (s->dma_cmd) { case IDE_DMA_READ: m->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num, pmac_ide_transfer_cb, io); break; case IDE_DMA_WRITE: m->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num, pmac_ide_transfer_cb, io); break; case IDE_DMA_TRIM: m->aiocb = dma_bdrv_io(s->bs, &s->sg, sector_num, ide_issue_trim, pmac_ide_transfer_cb, io, DMA_DIRECTION_TO_DEVICE); break; } return; done: if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) { bdrv_acct_done(s->bs, &s->acct); } io->dma_end(io); }
4,894
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
static uint64_t bmdma_read(void *opaque, target_phys_addr_t addr, unsigned size) { BMDMAState *bm = opaque; PCIIDEState *pci_dev = bm->pci_dev; uint32_t val; if (size != 1) { return ((uint64_t)1 << (size * 8)) - 1; } switch(addr & 3) { case 0: val = bm->cmd; break; case 1: val = pci_dev->dev.config[MRDMODE]; break; case 2: val = bm->status; break; case 3: if (bm == &pci_dev->bmdma[0]) { val = pci_dev->dev.config[UDIDETCR0]; } else { val = pci_dev->dev.config[UDIDETCR1]; } break; default: val = 0xff; break; } #ifdef DEBUG_IDE printf("bmdma: readb 0x%02x : 0x%02x\n", addr, val); #endif return val; }
4,895
qemu
6fc76aa9adc1c8896a97059f12a1e5e6c1820c64
0
static void hash32_bat_size(CPUPPCState *env, target_ulong *blp, int *validp, target_ulong batu, target_ulong batl) { target_ulong bl; int valid; bl = (batu & BATU32_BL) << 15; valid = 0; if (((msr_pr == 0) && (batu & BATU32_VS)) || ((msr_pr != 0) && (batu & BATU32_VP))) { valid = 1; } *blp = bl; *validp = valid; }
4,897
qemu
7cfbd386b92e93fbfae033b9ac89a20d1fe72573
0
static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, abi_ulong parent_tidptr, target_ulong newtls, abi_ulong child_tidptr) { CPUState *cpu = ENV_GET_CPU(env); int ret; TaskState *ts; CPUState *new_cpu; CPUArchState *new_env; unsigned int nptl_flags; sigset_t sigmask; /* Emulate vfork() with fork() */ if (flags & CLONE_VFORK) flags &= ~(CLONE_VFORK | CLONE_VM); if (flags & CLONE_VM) { TaskState *parent_ts = (TaskState *)cpu->opaque; new_thread_info info; pthread_attr_t attr; ts = g_new0(TaskState, 1); init_task_state(ts); /* we create a new CPU instance. */ new_env = cpu_copy(env); /* Init regs that differ from the parent. */ cpu_clone_regs(new_env, newsp); new_cpu = ENV_GET_CPU(new_env); new_cpu->opaque = ts; ts->bprm = parent_ts->bprm; ts->info = parent_ts->info; ts->signal_mask = parent_ts->signal_mask; nptl_flags = flags; flags &= ~CLONE_NPTL_FLAGS2; if (nptl_flags & CLONE_CHILD_CLEARTID) { ts->child_tidptr = child_tidptr; } if (nptl_flags & CLONE_SETTLS) cpu_set_tls (new_env, newtls); /* Grab a mutex so that thread setup appears atomic. */ pthread_mutex_lock(&clone_lock); memset(&info, 0, sizeof(info)); pthread_mutex_init(&info.mutex, NULL); pthread_mutex_lock(&info.mutex); pthread_cond_init(&info.cond, NULL); info.env = new_env; if (nptl_flags & CLONE_CHILD_SETTID) info.child_tidptr = child_tidptr; if (nptl_flags & CLONE_PARENT_SETTID) info.parent_tidptr = parent_tidptr; ret = pthread_attr_init(&attr); ret = pthread_attr_setstacksize(&attr, NEW_STACK_SIZE); ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); /* It is not safe to deliver signals until the child has finished initializing, so temporarily block all signals. */ sigfillset(&sigmask); sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); ret = pthread_create(&info.thread, &attr, clone_func, &info); /* TODO: Free new CPU state if thread creation failed. */ sigprocmask(SIG_SETMASK, &info.sigmask, NULL); pthread_attr_destroy(&attr); if (ret == 0) { /* Wait for the child to initialize. */ pthread_cond_wait(&info.cond, &info.mutex); ret = info.tid; if (flags & CLONE_PARENT_SETTID) put_user_u32(ret, parent_tidptr); } else { ret = -1; } pthread_mutex_unlock(&info.mutex); pthread_cond_destroy(&info.cond); pthread_mutex_destroy(&info.mutex); pthread_mutex_unlock(&clone_lock); } else { /* if no CLONE_VM, we consider it is a fork */ if ((flags & ~(CSIGNAL | CLONE_NPTL_FLAGS2)) != 0) { return -TARGET_EINVAL; } if (block_signals()) { return -TARGET_ERESTARTSYS; } fork_start(); ret = fork(); if (ret == 0) { /* Child Process. */ rcu_after_fork(); cpu_clone_regs(env, newsp); fork_end(1); /* There is a race condition here. The parent process could theoretically read the TID in the child process before the child tid is set. This would require using either ptrace (not implemented) or having *_tidptr to point at a shared memory mapping. We can't repeat the spinlock hack used above because the child process gets its own copy of the lock. */ if (flags & CLONE_CHILD_SETTID) put_user_u32(gettid(), child_tidptr); if (flags & CLONE_PARENT_SETTID) put_user_u32(gettid(), parent_tidptr); ts = (TaskState *)cpu->opaque; if (flags & CLONE_SETTLS) cpu_set_tls (env, newtls); if (flags & CLONE_CHILD_CLEARTID) ts->child_tidptr = child_tidptr; } else { fork_end(0); } } return ret; }
4,898
qemu
0c16c056a4f9dec18fdd56feec82a5db9ff3c15e
0
static void test_hash_digest(void) { size_t i; g_assert(qcrypto_init(NULL) == 0); for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) { int ret; char *digest; size_t digestsize; digestsize = qcrypto_hash_digest_len(i); g_assert_cmpint(digestsize * 2, ==, strlen(expected_outputs[i])); ret = qcrypto_hash_digest(i, INPUT_TEXT, strlen(INPUT_TEXT), &digest, NULL); g_assert(ret == 0); g_assert(g_str_equal(digest, expected_outputs[i])); g_free(digest); } }
4,900
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
static uint32_t pci_apb_ioreadw (void *opaque, target_phys_addr_t addr) { uint32_t val; val = bswap16(cpu_inw(addr & IOPORTS_MASK)); return val; }
4,901
qemu
d6f2ea22a05b429ba83248b80a625b6fe1d927f3
0
static void destroy_l2_mapping(PhysPageEntry *lp, unsigned level) { unsigned i; PhysPageEntry *p = lp->u.node; if (!p) { return; } for (i = 0; i < L2_SIZE; ++i) { if (level > 0) { destroy_l2_mapping(&p[i], level - 1); } else { destroy_page_desc(p[i].u.leaf); } } g_free(p); lp->u.node = NULL; }
4,902
qemu
494a8ebe713055d3946183f4b395f85a18b43e9e
0
static void prstat_to_stat(struct stat *stbuf, ProxyStat *prstat) { memset(stbuf, 0, sizeof(*stbuf)); stbuf->st_dev = prstat->st_dev; stbuf->st_ino = prstat->st_ino; stbuf->st_nlink = prstat->st_nlink; stbuf->st_mode = prstat->st_mode; stbuf->st_uid = prstat->st_uid; stbuf->st_gid = prstat->st_gid; stbuf->st_rdev = prstat->st_rdev; stbuf->st_size = prstat->st_size; stbuf->st_blksize = prstat->st_blksize; stbuf->st_blocks = prstat->st_blocks; stbuf->st_atim.tv_sec = prstat->st_atim_sec; stbuf->st_atim.tv_nsec = prstat->st_atim_nsec; stbuf->st_mtime = prstat->st_mtim_sec; stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec; stbuf->st_ctime = prstat->st_ctim_sec; stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec; }
4,904
qemu
96b1a8bb55f1aeb72a943d1001841ff8b0687059
0
S390CPU *cpu_s390x_init(const char *cpu_model) { S390CPU *cpu; cpu = S390_CPU(object_new(TYPE_S390_CPU)); object_property_set_bool(OBJECT(cpu), true, "realized", NULL); return cpu; }
4,905
qemu
fd56e0612b6454a282fa6a953fdb09281a98c589
0
void pci_unregister_vga(PCIDevice *pci_dev) { if (!pci_dev->has_vga) { return; } memory_region_del_subregion(pci_dev->bus->address_space_mem, pci_dev->vga_regions[QEMU_PCI_VGA_MEM]); memory_region_del_subregion(pci_dev->bus->address_space_io, pci_dev->vga_regions[QEMU_PCI_VGA_IO_LO]); memory_region_del_subregion(pci_dev->bus->address_space_io, pci_dev->vga_regions[QEMU_PCI_VGA_IO_HI]); pci_dev->has_vga = false; }
4,906
FFmpeg
6b657ac7889738b9ab38924cca4e7c418f6fbc38
0
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; C93DecoderContext * const c93 = avctx->priv_data; AVFrame * const newpic = &c93->pictures[c93->currentpic]; AVFrame * const oldpic = &c93->pictures[c93->currentpic^1]; GetByteContext gb; uint8_t *out; int stride, ret, i, x, y, b, bt = 0; c93->currentpic ^= 1; if ((ret = ff_reget_buffer(avctx, newpic)) < 0) return ret; stride = newpic->linesize[0]; bytestream2_init(&gb, buf, buf_size); b = bytestream2_get_byte(&gb); if (b & C93_FIRST_FRAME) { newpic->pict_type = AV_PICTURE_TYPE_I; newpic->key_frame = 1; } else { newpic->pict_type = AV_PICTURE_TYPE_P; newpic->key_frame = 0; } for (y = 0; y < HEIGHT; y += 8) { out = newpic->data[0] + y * stride; for (x = 0; x < WIDTH; x += 8) { uint8_t *copy_from = oldpic->data[0]; unsigned int offset, j; uint8_t cols[4], grps[4]; C93BlockType block_type; if (!bt) bt = bytestream2_get_byte(&gb); block_type= bt & 0x0F; switch (block_type) { case C93_8X8_FROM_PREV: offset = bytestream2_get_le16(&gb); if ((ret = copy_block(avctx, out, copy_from, offset, 8, stride)) < 0) return ret; break; case C93_4X4_FROM_CURR: copy_from = newpic->data[0]; case C93_4X4_FROM_PREV: for (j = 0; j < 8; j += 4) { for (i = 0; i < 8; i += 4) { offset = bytestream2_get_le16(&gb); if ((ret = copy_block(avctx, &out[j*stride+i], copy_from, offset, 4, stride)) < 0) return ret; } } break; case C93_8X8_2COLOR: bytestream2_get_buffer(&gb, cols, 2); for (i = 0; i < 8; i++) { draw_n_color(out + i*stride, stride, 8, 1, 1, cols, NULL, bytestream2_get_byte(&gb)); } break; case C93_4X4_2COLOR: case C93_4X4_4COLOR: case C93_4X4_4COLOR_GRP: for (j = 0; j < 8; j += 4) { for (i = 0; i < 8; i += 4) { if (block_type == C93_4X4_2COLOR) { bytestream2_get_buffer(&gb, cols, 2); draw_n_color(out + i + j*stride, stride, 4, 4, 1, cols, NULL, bytestream2_get_le16(&gb)); } else if (block_type == C93_4X4_4COLOR) { bytestream2_get_buffer(&gb, cols, 4); draw_n_color(out + i + j*stride, stride, 4, 4, 2, cols, NULL, bytestream2_get_le32(&gb)); } else { bytestream2_get_buffer(&gb, grps, 4); draw_n_color(out + i + j*stride, stride, 4, 4, 1, cols, grps, bytestream2_get_le16(&gb)); } } } break; case C93_NOOP: break; case C93_8X8_INTRA: for (j = 0; j < 8; j++) bytestream2_get_buffer(&gb, out + j*stride, 8); break; default: av_log(avctx, AV_LOG_ERROR, "unexpected type %x at %dx%d\n", block_type, x, y); return AVERROR_INVALIDDATA; } bt >>= 4; out += 8; } } if (b & C93_HAS_PALETTE) { uint32_t *palette = (uint32_t *) newpic->data[1]; for (i = 0; i < 256; i++) { palette[i] = 0xFFU << 24 | bytestream2_get_be24(&gb); } newpic->palette_has_changed = 1; } else { if (oldpic->data[1]) memcpy(newpic->data[1], oldpic->data[1], 256 * 4); } if ((ret = av_frame_ref(data, newpic)) < 0) return ret; *got_frame = 1; return buf_size; }
4,907
qemu
2a7e6857cd3178d705a49c4adde2f3af26ed3ae1
0
VncInfo2List *qmp_query_vnc_servers(Error **errp) { VncInfo2List *item, *prev = NULL; VncInfo2 *info; VncDisplay *vd; DeviceState *dev; QTAILQ_FOREACH(vd, &vnc_displays, next) { info = g_new0(VncInfo2, 1); info->id = g_strdup(vd->id); info->clients = qmp_query_client_list(vd); qmp_query_auth(vd, info); if (vd->dcl.con) { dev = DEVICE(object_property_get_link(OBJECT(vd->dcl.con), "device", NULL)); info->has_display = true; info->display = g_strdup(dev->id); } if (vd->lsock != NULL) { info->server = qmp_query_server_entry( vd->lsock, false, info->server); } if (vd->lwebsock != NULL) { info->server = qmp_query_server_entry( vd->lwebsock, true, info->server); } item = g_new0(VncInfo2List, 1); item->value = info; item->next = prev; prev = item; } return prev; }
4,908
qemu
a8170e5e97ad17ca169c64ba87ae2f53850dab4c
0
pic_read(void *opaque, target_phys_addr_t addr, unsigned int size) { struct etrax_pic *fs = opaque; uint32_t rval; rval = fs->regs[addr >> 2]; D(printf("%s %x=%x\n", __func__, addr, rval)); return rval; }
4,910
qemu
aa92d6c4609e174fc6884e4b7b87367fac33cbe9
0
static int coroutine_fn nfs_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *iov) { NFSClient *client = bs->opaque; NFSRPC task; char *buf = NULL; nfs_co_init_task(client, &task); buf = g_try_malloc(nb_sectors * BDRV_SECTOR_SIZE); if (nb_sectors && buf == NULL) { return -ENOMEM; } qemu_iovec_to_buf(iov, 0, buf, nb_sectors * BDRV_SECTOR_SIZE); if (nfs_pwrite_async(client->context, client->fh, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE, buf, nfs_co_generic_cb, &task) != 0) { g_free(buf); return -ENOMEM; } while (!task.complete) { nfs_set_events(client); qemu_coroutine_yield(); } g_free(buf); if (task.ret != nb_sectors * BDRV_SECTOR_SIZE) { return task.ret < 0 ? task.ret : -EIO; } return 0; }
4,911
qemu
6f1de6b70d857d5e316ae6fd908f52818b827b08
0
static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond, void *opaque) { CadenceUARTState *s = opaque; int ret; /* instant drain the fifo when there's no back-end */ if (!s->chr) { s->tx_count = 0; return FALSE; } if (!s->tx_count) { return FALSE; } ret = qemu_chr_fe_write(s->chr, s->tx_fifo, s->tx_count); s->tx_count -= ret; memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_count); if (s->tx_count) { int r = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, cadence_uart_xmit, s); assert(r); } uart_update_status(s); return FALSE; }
4,912
qemu
0ed6dc1a982fd029557a17fda7606d679a6ebb28
0
void error_set_field(Error *err, const char *field, const char *value) { QDict *dict = qdict_get_qdict(err->obj, "data"); return qdict_put(dict, field, qstring_from_str(value)); }
4,914
qemu
33577b47c64435fcc2a1bc01c7e82534256f1fc3
0
static void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque, void *opaque2, uint64_t id) { assert(event_kind < REPLAY_ASYNC_COUNT); if (!replay_file || replay_mode == REPLAY_MODE_NONE || !events_enabled) { Event e; e.event_kind = event_kind; e.opaque = opaque; e.opaque2 = opaque2; e.id = id; replay_run_event(&e); return; } Event *event = g_malloc0(sizeof(Event)); event->event_kind = event_kind; event->opaque = opaque; event->opaque2 = opaque2; event->id = id; replay_mutex_lock(); QTAILQ_INSERT_TAIL(&events_list, event, events); replay_mutex_unlock(); }
4,915
qemu
3dc6f8693694a649a9c83f1e2746565b47683923
0
static void unsafe_flush_warning(BDRVSSHState *s, const char *what) { if (!s->unsafe_flush_warning) { error_report("warning: ssh server %s does not support fsync", s->inet->host); if (what) { error_report("to support fsync, you need %s", what); } s->unsafe_flush_warning = true; } }
4,917
FFmpeg
3051e7fa712dfe2136f19b7157211453895f2a3c
0
static int hls_slice_header(HEVCContext *s) { GetBitContext *gb = &s->HEVClc->gb; SliceHeader *sh = &s->sh; int i, j, ret; // Coded parameters sh->first_slice_in_pic_flag = get_bits1(gb); if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) { s->seq_decode = (s->seq_decode + 1) & 0xff; s->max_ra = INT_MAX; if (IS_IDR(s)) ff_hevc_clear_refs(s); } sh->no_output_of_prior_pics_flag = 0; if (IS_IRAP(s)) sh->no_output_of_prior_pics_flag = get_bits1(gb); sh->pps_id = get_ue_golomb_long(gb); if (sh->pps_id >= MAX_PPS_COUNT || !s->pps_list[sh->pps_id]) { av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id); return AVERROR_INVALIDDATA; } if (!sh->first_slice_in_pic_flag && s->pps != (HEVCPPS*)s->pps_list[sh->pps_id]->data) { av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); return AVERROR_INVALIDDATA; } s->pps = (HEVCPPS*)s->pps_list[sh->pps_id]->data; if (s->nal_unit_type == NAL_CRA_NUT && s->last_eos == 1) sh->no_output_of_prior_pics_flag = 1; if (s->sps != (HEVCSPS*)s->sps_list[s->pps->sps_id]->data) { const HEVCSPS* last_sps = s->sps; s->sps = (HEVCSPS*)s->sps_list[s->pps->sps_id]->data; if (last_sps && IS_IRAP(s) && s->nal_unit_type != NAL_CRA_NUT) { if (s->sps->width != last_sps->width || s->sps->height != last_sps->height || s->sps->temporal_layer[s->sps->max_sub_layers - 1].max_dec_pic_buffering != last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering) sh->no_output_of_prior_pics_flag = 0; } ff_hevc_clear_refs(s); ret = set_sps(s, s->sps, AV_PIX_FMT_NONE); if (ret < 0) return ret; s->seq_decode = (s->seq_decode + 1) & 0xff; s->max_ra = INT_MAX; } sh->dependent_slice_segment_flag = 0; if (!sh->first_slice_in_pic_flag) { int slice_address_length; if (s->pps->dependent_slice_segments_enabled_flag) sh->dependent_slice_segment_flag = get_bits1(gb); slice_address_length = av_ceil_log2(s->sps->ctb_width * s->sps->ctb_height); sh->slice_segment_addr = get_bits(gb, slice_address_length); if (sh->slice_segment_addr >= s->sps->ctb_width * s->sps->ctb_height) { av_log(s->avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n", sh->slice_segment_addr); return AVERROR_INVALIDDATA; } if (!sh->dependent_slice_segment_flag) { sh->slice_addr = sh->slice_segment_addr; s->slice_idx++; } } else { sh->slice_segment_addr = sh->slice_addr = 0; s->slice_idx = 0; s->slice_initialized = 0; } if (!sh->dependent_slice_segment_flag) { s->slice_initialized = 0; for (i = 0; i < s->pps->num_extra_slice_header_bits; i++) skip_bits(gb, 1); // slice_reserved_undetermined_flag[] sh->slice_type = get_ue_golomb_long(gb); if (!(sh->slice_type == I_SLICE || sh->slice_type == P_SLICE || sh->slice_type == B_SLICE)) { av_log(s->avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", sh->slice_type); return AVERROR_INVALIDDATA; } if (IS_IRAP(s) && sh->slice_type != I_SLICE) { av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n"); return AVERROR_INVALIDDATA; } // when flag is not present, picture is inferred to be output sh->pic_output_flag = 1; if (s->pps->output_flag_present_flag) sh->pic_output_flag = get_bits1(gb); if (s->sps->separate_colour_plane_flag) sh->colour_plane_id = get_bits(gb, 2); if (!IS_IDR(s)) { int poc; sh->pic_order_cnt_lsb = get_bits(gb, s->sps->log2_max_poc_lsb); poc = ff_hevc_compute_poc(s, sh->pic_order_cnt_lsb); if (!sh->first_slice_in_pic_flag && poc != s->poc) { av_log(s->avctx, AV_LOG_WARNING, "Ignoring POC change between slices: %d -> %d\n", s->poc, poc); if (s->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; poc = s->poc; } s->poc = poc; sh->short_term_ref_pic_set_sps_flag = get_bits1(gb); if (!sh->short_term_ref_pic_set_sps_flag) { int pos = get_bits_left(gb); ret = ff_hevc_decode_short_term_rps(s, &sh->slice_rps, s->sps, 1); if (ret < 0) return ret; sh->short_term_ref_pic_set_size = pos - get_bits_left(gb); sh->short_term_rps = &sh->slice_rps; } else { int numbits, rps_idx; if (!s->sps->nb_st_rps) { av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n"); return AVERROR_INVALIDDATA; } numbits = av_ceil_log2(s->sps->nb_st_rps); rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0; sh->short_term_rps = &s->sps->st_rps[rps_idx]; } ret = decode_lt_rps(s, &sh->long_term_rps, gb); if (ret < 0) { av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n"); if (s->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } if (s->sps->sps_temporal_mvp_enabled_flag) sh->slice_temporal_mvp_enabled_flag = get_bits1(gb); else sh->slice_temporal_mvp_enabled_flag = 0; } else { s->sh.short_term_rps = NULL; s->poc = 0; } /* 8.3.1 */ if (s->temporal_id == 0 && s->nal_unit_type != NAL_TRAIL_N && s->nal_unit_type != NAL_TSA_N && s->nal_unit_type != NAL_STSA_N && s->nal_unit_type != NAL_RADL_N && s->nal_unit_type != NAL_RADL_R && s->nal_unit_type != NAL_RASL_N && s->nal_unit_type != NAL_RASL_R) s->pocTid0 = s->poc; if (s->sps->sao_enabled) { sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb); if (s->sps->chroma_format_idc) { sh->slice_sample_adaptive_offset_flag[1] = sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb); } } else { sh->slice_sample_adaptive_offset_flag[0] = 0; sh->slice_sample_adaptive_offset_flag[1] = 0; sh->slice_sample_adaptive_offset_flag[2] = 0; } sh->nb_refs[L0] = sh->nb_refs[L1] = 0; if (sh->slice_type == P_SLICE || sh->slice_type == B_SLICE) { int nb_refs; sh->nb_refs[L0] = s->pps->num_ref_idx_l0_default_active; if (sh->slice_type == B_SLICE) sh->nb_refs[L1] = s->pps->num_ref_idx_l1_default_active; if (get_bits1(gb)) { // num_ref_idx_active_override_flag sh->nb_refs[L0] = get_ue_golomb_long(gb) + 1; if (sh->slice_type == B_SLICE) sh->nb_refs[L1] = get_ue_golomb_long(gb) + 1; } if (sh->nb_refs[L0] > MAX_REFS || sh->nb_refs[L1] > MAX_REFS) { av_log(s->avctx, AV_LOG_ERROR, "Too many refs: %d/%d.\n", sh->nb_refs[L0], sh->nb_refs[L1]); return AVERROR_INVALIDDATA; } sh->rpl_modification_flag[0] = 0; sh->rpl_modification_flag[1] = 0; nb_refs = ff_hevc_frame_nb_refs(s); if (!nb_refs) { av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n"); return AVERROR_INVALIDDATA; } if (s->pps->lists_modification_present_flag && nb_refs > 1) { sh->rpl_modification_flag[0] = get_bits1(gb); if (sh->rpl_modification_flag[0]) { for (i = 0; i < sh->nb_refs[L0]; i++) sh->list_entry_lx[0][i] = get_bits(gb, av_ceil_log2(nb_refs)); } if (sh->slice_type == B_SLICE) { sh->rpl_modification_flag[1] = get_bits1(gb); if (sh->rpl_modification_flag[1] == 1) for (i = 0; i < sh->nb_refs[L1]; i++) sh->list_entry_lx[1][i] = get_bits(gb, av_ceil_log2(nb_refs)); } } if (sh->slice_type == B_SLICE) sh->mvd_l1_zero_flag = get_bits1(gb); if (s->pps->cabac_init_present_flag) sh->cabac_init_flag = get_bits1(gb); else sh->cabac_init_flag = 0; sh->collocated_ref_idx = 0; if (sh->slice_temporal_mvp_enabled_flag) { sh->collocated_list = L0; if (sh->slice_type == B_SLICE) sh->collocated_list = !get_bits1(gb); if (sh->nb_refs[sh->collocated_list] > 1) { sh->collocated_ref_idx = get_ue_golomb_long(gb); if (sh->collocated_ref_idx >= sh->nb_refs[sh->collocated_list]) { av_log(s->avctx, AV_LOG_ERROR, "Invalid collocated_ref_idx: %d.\n", sh->collocated_ref_idx); return AVERROR_INVALIDDATA; } } } if ((s->pps->weighted_pred_flag && sh->slice_type == P_SLICE) || (s->pps->weighted_bipred_flag && sh->slice_type == B_SLICE)) { pred_weight_table(s, gb); } sh->max_num_merge_cand = 5 - get_ue_golomb_long(gb); if (sh->max_num_merge_cand < 1 || sh->max_num_merge_cand > 5) { av_log(s->avctx, AV_LOG_ERROR, "Invalid number of merging MVP candidates: %d.\n", sh->max_num_merge_cand); return AVERROR_INVALIDDATA; } } sh->slice_qp_delta = get_se_golomb(gb); if (s->pps->pic_slice_level_chroma_qp_offsets_present_flag) { sh->slice_cb_qp_offset = get_se_golomb(gb); sh->slice_cr_qp_offset = get_se_golomb(gb); } else { sh->slice_cb_qp_offset = 0; sh->slice_cr_qp_offset = 0; } if (s->pps->chroma_qp_offset_list_enabled_flag) sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb); else sh->cu_chroma_qp_offset_enabled_flag = 0; if (s->pps->deblocking_filter_control_present_flag) { int deblocking_filter_override_flag = 0; if (s->pps->deblocking_filter_override_enabled_flag) deblocking_filter_override_flag = get_bits1(gb); if (deblocking_filter_override_flag) { sh->disable_deblocking_filter_flag = get_bits1(gb); if (!sh->disable_deblocking_filter_flag) { sh->beta_offset = get_se_golomb(gb) * 2; sh->tc_offset = get_se_golomb(gb) * 2; } } else { sh->disable_deblocking_filter_flag = s->pps->disable_dbf; sh->beta_offset = s->pps->beta_offset; sh->tc_offset = s->pps->tc_offset; } } else { sh->disable_deblocking_filter_flag = 0; sh->beta_offset = 0; sh->tc_offset = 0; } if (s->pps->seq_loop_filter_across_slices_enabled_flag && (sh->slice_sample_adaptive_offset_flag[0] || sh->slice_sample_adaptive_offset_flag[1] || !sh->disable_deblocking_filter_flag)) { sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb); } else { sh->slice_loop_filter_across_slices_enabled_flag = s->pps->seq_loop_filter_across_slices_enabled_flag; } } else if (!s->slice_initialized) { av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n"); return AVERROR_INVALIDDATA; } sh->num_entry_point_offsets = 0; if (s->pps->tiles_enabled_flag || s->pps->entropy_coding_sync_enabled_flag) { unsigned num_entry_point_offsets = get_ue_golomb_long(gb); // It would be possible to bound this tighter but this here is simpler if (sh->num_entry_point_offsets > get_bits_left(gb)) { av_log(s->avctx, AV_LOG_ERROR, "num_entry_point_offsets %d is invalid\n", num_entry_point_offsets); return AVERROR_INVALIDDATA; } sh->num_entry_point_offsets = num_entry_point_offsets; if (sh->num_entry_point_offsets > 0) { int offset_len = get_ue_golomb_long(gb) + 1; if (offset_len < 1 || offset_len > 32) { sh->num_entry_point_offsets = 0; av_log(s->avctx, AV_LOG_ERROR, "offset_len %d is invalid\n", offset_len); return AVERROR_INVALIDDATA; } av_freep(&sh->entry_point_offset); av_freep(&sh->offset); av_freep(&sh->size); sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); sh->offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); sh->size = av_malloc_array(sh->num_entry_point_offsets, sizeof(int)); if (!sh->entry_point_offset || !sh->offset || !sh->size) { sh->num_entry_point_offsets = 0; av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n"); return AVERROR(ENOMEM); } for (i = 0; i < sh->num_entry_point_offsets; i++) { unsigned val = get_bits_long(gb, offset_len); sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size } if (s->threads_number > 1 && (s->pps->num_tile_rows > 1 || s->pps->num_tile_columns > 1)) { s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here s->threads_number = 1; } else s->enable_parallel_tiles = 0; } else s->enable_parallel_tiles = 0; } if (s->pps->slice_header_extension_present_flag) { unsigned int length = get_ue_golomb_long(gb); if (length*8LL > get_bits_left(gb)) { av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n"); return AVERROR_INVALIDDATA; } for (i = 0; i < length; i++) skip_bits(gb, 8); // slice_header_extension_data_byte } // Inferred parameters sh->slice_qp = 26U + s->pps->pic_init_qp_minus26 + sh->slice_qp_delta; if (sh->slice_qp > 51 || sh->slice_qp < -s->sps->qp_bd_offset) { av_log(s->avctx, AV_LOG_ERROR, "The slice_qp %d is outside the valid range " "[%d, 51].\n", sh->slice_qp, -s->sps->qp_bd_offset); return AVERROR_INVALIDDATA; } sh->slice_ctb_addr_rs = sh->slice_segment_addr; if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) { av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n"); return AVERROR_INVALIDDATA; } if (get_bits_left(gb) < 0) { av_log(s->avctx, AV_LOG_ERROR, "Overread slice header by %d bits\n", -get_bits_left(gb)); return AVERROR_INVALIDDATA; } s->HEVClc->first_qp_group = !s->sh.dependent_slice_segment_flag; if (!s->pps->cu_qp_delta_enabled_flag) s->HEVClc->qp_y = s->sh.slice_qp; s->slice_initialized = 1; s->HEVClc->tu.cu_qp_offset_cb = 0; s->HEVClc->tu.cu_qp_offset_cr = 0; return 0; }
4,918
FFmpeg
992b03183819553a73b4f870a710ef500b4eb6d0
0
static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color) { int x, y, fr, f; sx = av_clip(sx, 0, w - 1); sy = av_clip(sy, 0, h - 1); ex = av_clip(ex, 0, w - 1); ey = av_clip(ey, 0, h - 1); buf[sy * stride + sx] += color; if (FFABS(ex - sx) > FFABS(ey - sy)) { if (sx > ex) { FFSWAP(int, sx, ex); FFSWAP(int, sy, ey); } buf += sx + sy * stride; ex -= sx; f = ((ey - sy) << 16) / ex; for (x = 0; x = ex; x++) { y = (x * f) >> 16; fr = (x * f) & 0xFFFF; buf[y * stride + x] += (color * (0x10000 - fr)) >> 16; buf[(y + 1) * stride + x] += (color * fr ) >> 16; } } else { if (sy > ey) { FFSWAP(int, sx, ex); FFSWAP(int, sy, ey); } buf += sx + sy * stride; ey -= sy; if (ey) f = ((ex - sx) << 16) / ey; else f = 0; for (y = 0; y = ey; y++) { x = (y * f) >> 16; fr = (y * f) & 0xFFFF; buf[y * stride + x] += (color * (0x10000 - fr)) >> 16; buf[y * stride + x + 1] += (color * fr ) >> 16; } } }
4,919
qemu
61007b316cd71ee7333ff7a0a749a8949527575f
0
static int bdrv_prwv_co(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags) { Coroutine *co; RwCo rwco = { .bs = bs, .offset = offset, .qiov = qiov, .is_write = is_write, .ret = NOT_DONE, .flags = flags, }; /** * In sync call context, when the vcpu is blocked, this throttling timer * will not fire; so the I/O throttling function has to be disabled here * if it has been enabled. */ if (bs->io_limits_enabled) { fprintf(stderr, "Disabling I/O throttling on '%s' due " "to synchronous I/O.\n", bdrv_get_device_name(bs)); bdrv_io_limits_disable(bs); } if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_rw_co_entry(&rwco); } else { AioContext *aio_context = bdrv_get_aio_context(bs); co = qemu_coroutine_create(bdrv_rw_co_entry); qemu_coroutine_enter(co, &rwco); while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); } } return rwco.ret; }
4,920
qemu
a89f364ae8740dfc31b321eed9ee454e996dc3c1
0
static uint64_t omap_mcbsp_read(void *opaque, hwaddr addr, unsigned size) { struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) opaque; int offset = addr & OMAP_MPUI_REG_MASK; uint16_t ret; if (size != 2) { return omap_badwidth_read16(opaque, addr); } switch (offset) { case 0x00: /* DRR2 */ if (((s->rcr[0] >> 5) & 7) < 3) /* RWDLEN1 */ return 0x0000; /* Fall through. */ case 0x02: /* DRR1 */ if (s->rx_req < 2) { printf("%s: Rx FIFO underrun\n", __FUNCTION__); omap_mcbsp_rx_done(s); } else { s->tx_req -= 2; if (s->codec && s->codec->in.len >= 2) { ret = s->codec->in.fifo[s->codec->in.start ++] << 8; ret |= s->codec->in.fifo[s->codec->in.start ++]; s->codec->in.len -= 2; } else ret = 0x0000; if (!s->tx_req) omap_mcbsp_rx_done(s); return ret; } return 0x0000; case 0x04: /* DXR2 */ case 0x06: /* DXR1 */ return 0x0000; case 0x08: /* SPCR2 */ return s->spcr[1]; case 0x0a: /* SPCR1 */ return s->spcr[0]; case 0x0c: /* RCR2 */ return s->rcr[1]; case 0x0e: /* RCR1 */ return s->rcr[0]; case 0x10: /* XCR2 */ return s->xcr[1]; case 0x12: /* XCR1 */ return s->xcr[0]; case 0x14: /* SRGR2 */ return s->srgr[1]; case 0x16: /* SRGR1 */ return s->srgr[0]; case 0x18: /* MCR2 */ return s->mcr[1]; case 0x1a: /* MCR1 */ return s->mcr[0]; case 0x1c: /* RCERA */ return s->rcer[0]; case 0x1e: /* RCERB */ return s->rcer[1]; case 0x20: /* XCERA */ return s->xcer[0]; case 0x22: /* XCERB */ return s->xcer[1]; case 0x24: /* PCR0 */ return s->pcr; case 0x26: /* RCERC */ return s->rcer[2]; case 0x28: /* RCERD */ return s->rcer[3]; case 0x2a: /* XCERC */ return s->xcer[2]; case 0x2c: /* XCERD */ return s->xcer[3]; case 0x2e: /* RCERE */ return s->rcer[4]; case 0x30: /* RCERF */ return s->rcer[5]; case 0x32: /* XCERE */ return s->xcer[4]; case 0x34: /* XCERF */ return s->xcer[5]; case 0x36: /* RCERG */ return s->rcer[6]; case 0x38: /* RCERH */ return s->rcer[7]; case 0x3a: /* XCERG */ return s->xcer[6]; case 0x3c: /* XCERH */ return s->xcer[7]; } OMAP_BAD_REG(addr); return 0; }
4,921
qemu
621ff94d5074d88253a5818c6b9c4db718fbfc65
0
static void check_suspend_mode(GuestSuspendMode mode, Error **errp) { SYSTEM_POWER_CAPABILITIES sys_pwr_caps; Error *local_err = NULL; ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps)); if (!GetPwrCapabilities(&sys_pwr_caps)) { error_setg(&local_err, QERR_QGA_COMMAND_FAILED, "failed to determine guest suspend capabilities"); goto out; } switch (mode) { case GUEST_SUSPEND_MODE_DISK: if (!sys_pwr_caps.SystemS4) { error_setg(&local_err, QERR_QGA_COMMAND_FAILED, "suspend-to-disk not supported by OS"); } break; case GUEST_SUSPEND_MODE_RAM: if (!sys_pwr_caps.SystemS3) { error_setg(&local_err, QERR_QGA_COMMAND_FAILED, "suspend-to-ram not supported by OS"); } break; default: error_setg(&local_err, QERR_INVALID_PARAMETER_VALUE, "mode", "GuestSuspendMode"); } out: if (local_err) { error_propagate(errp, local_err); } }
4,922
FFmpeg
9b595e86e342e0e39c5ddf9020286cae258b9965
0
av_cold static int lavfi_read_header(AVFormatContext *avctx) { LavfiContext *lavfi = avctx->priv_data; AVFilterInOut *input_links = NULL, *output_links = NULL, *inout; AVFilter *buffersink, *abuffersink; int *pix_fmts = create_all_formats(AV_PIX_FMT_NB); enum AVMediaType type; int ret = 0, i, n; #define FAIL(ERR) { ret = ERR; goto end; } if (!pix_fmts) FAIL(AVERROR(ENOMEM)); avfilter_register_all(); buffersink = avfilter_get_by_name("buffersink"); abuffersink = avfilter_get_by_name("abuffersink"); if (lavfi->graph_filename && lavfi->graph_str) { av_log(avctx, AV_LOG_ERROR, "Only one of the graph or graph_file options must be specified\n"); FAIL(AVERROR(EINVAL)); } if (lavfi->graph_filename) { uint8_t *file_buf, *graph_buf; size_t file_bufsize; ret = av_file_map(lavfi->graph_filename, &file_buf, &file_bufsize, 0, avctx); if (ret < 0) goto end; /* create a 0-terminated string based on the read file */ graph_buf = av_malloc(file_bufsize + 1); if (!graph_buf) { av_file_unmap(file_buf, file_bufsize); FAIL(AVERROR(ENOMEM)); } memcpy(graph_buf, file_buf, file_bufsize); graph_buf[file_bufsize] = 0; av_file_unmap(file_buf, file_bufsize); lavfi->graph_str = graph_buf; } if (!lavfi->graph_str) lavfi->graph_str = av_strdup(avctx->filename); /* parse the graph, create a stream for each open output */ if (!(lavfi->graph = avfilter_graph_alloc())) FAIL(AVERROR(ENOMEM)); if ((ret = avfilter_graph_parse(lavfi->graph, lavfi->graph_str, &input_links, &output_links, avctx)) < 0) FAIL(ret); if (input_links) { av_log(avctx, AV_LOG_ERROR, "Open inputs in the filtergraph are not acceptable\n"); FAIL(AVERROR(EINVAL)); } /* count the outputs */ for (n = 0, inout = output_links; inout; n++, inout = inout->next); if (!(lavfi->sink_stream_map = av_malloc(sizeof(int) * n))) FAIL(AVERROR(ENOMEM)); if (!(lavfi->sink_eof = av_mallocz(sizeof(int) * n))) FAIL(AVERROR(ENOMEM)); if (!(lavfi->stream_sink_map = av_malloc(sizeof(int) * n))) FAIL(AVERROR(ENOMEM)); for (i = 0; i < n; i++) lavfi->stream_sink_map[i] = -1; /* parse the output link names - they need to be of the form out0, out1, ... * create a mapping between them and the streams */ for (i = 0, inout = output_links; inout; i++, inout = inout->next) { int stream_idx; if (!strcmp(inout->name, "out")) stream_idx = 0; else if (sscanf(inout->name, "out%d\n", &stream_idx) != 1) { av_log(avctx, AV_LOG_ERROR, "Invalid outpad name '%s'\n", inout->name); FAIL(AVERROR(EINVAL)); } if ((unsigned)stream_idx >= n) { av_log(avctx, AV_LOG_ERROR, "Invalid index was specified in output '%s', " "must be a non-negative value < %d\n", inout->name, n); FAIL(AVERROR(EINVAL)); } /* is an audio or video output? */ type = inout->filter_ctx->output_pads[inout->pad_idx].type; if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) { av_log(avctx, AV_LOG_ERROR, "Output '%s' is not a video or audio output, not yet supported\n", inout->name); FAIL(AVERROR(EINVAL)); } if (lavfi->stream_sink_map[stream_idx] != -1) { av_log(avctx, AV_LOG_ERROR, "An output with stream index %d was already specified\n", stream_idx); FAIL(AVERROR(EINVAL)); } lavfi->sink_stream_map[i] = stream_idx; lavfi->stream_sink_map[stream_idx] = i; } /* for each open output create a corresponding stream */ for (i = 0, inout = output_links; inout; i++, inout = inout->next) { AVStream *st; if (!(st = avformat_new_stream(avctx, NULL))) FAIL(AVERROR(ENOMEM)); st->id = i; } /* create a sink for each output and connect them to the graph */ lavfi->sinks = av_malloc(sizeof(AVFilterContext *) * avctx->nb_streams); if (!lavfi->sinks) FAIL(AVERROR(ENOMEM)); for (i = 0, inout = output_links; inout; i++, inout = inout->next) { AVFilterContext *sink; type = inout->filter_ctx->output_pads[inout->pad_idx].type; if (type == AVMEDIA_TYPE_VIDEO && ! buffersink || type == AVMEDIA_TYPE_AUDIO && ! abuffersink) { av_log(avctx, AV_LOG_ERROR, "Missing required buffersink filter, aborting.\n"); FAIL(AVERROR_FILTER_NOT_FOUND); } if (type == AVMEDIA_TYPE_VIDEO) { ret = avfilter_graph_create_filter(&sink, buffersink, inout->name, NULL, NULL, lavfi->graph); av_opt_set_int_list(sink, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN); if (ret < 0) goto end; } else if (type == AVMEDIA_TYPE_AUDIO) { enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL, -1 }; ret = avfilter_graph_create_filter(&sink, abuffersink, inout->name, NULL, NULL, lavfi->graph); av_opt_set_int_list(sink, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN); if (ret < 0) goto end; } lavfi->sinks[i] = sink; if ((ret = avfilter_link(inout->filter_ctx, inout->pad_idx, sink, 0)) < 0) FAIL(ret); } /* configure the graph */ if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0) FAIL(ret); if (lavfi->dump_graph) { char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph); fputs(dump, stderr); fflush(stderr); av_free(dump); } /* fill each stream with the information in the corresponding sink */ for (i = 0; i < avctx->nb_streams; i++) { AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0]; AVStream *st = avctx->streams[i]; st->codec->codec_type = link->type; avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den); if (link->type == AVMEDIA_TYPE_VIDEO) { st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; st->codec->pix_fmt = link->format; st->codec->time_base = link->time_base; st->codec->width = link->w; st->codec->height = link->h; st ->sample_aspect_ratio = st->codec->sample_aspect_ratio = link->sample_aspect_ratio; avctx->probesize = FFMAX(avctx->probesize, link->w * link->h * av_get_padded_bits_per_pixel(av_pix_fmt_desc_get(link->format)) * 30); } else if (link->type == AVMEDIA_TYPE_AUDIO) { st->codec->codec_id = av_get_pcm_codec(link->format, -1); st->codec->channels = av_get_channel_layout_nb_channels(link->channel_layout); st->codec->sample_fmt = link->format; st->codec->sample_rate = link->sample_rate; st->codec->time_base = link->time_base; st->codec->channel_layout = link->channel_layout; if (st->codec->codec_id == AV_CODEC_ID_NONE) av_log(avctx, AV_LOG_ERROR, "Could not find PCM codec for sample format %s.\n", av_get_sample_fmt_name(link->format)); } } if (!(lavfi->decoded_frame = av_frame_alloc())) FAIL(AVERROR(ENOMEM)); end: av_free(pix_fmts); avfilter_inout_free(&input_links); avfilter_inout_free(&output_links); if (ret < 0) lavfi_read_close(avctx); return ret; }
4,923
qemu
514e73ecebc0aeadef218e91e36ee42b3d145c93
0
int do_balloon(Monitor *mon, const QDict *params, MonitorCompletion cb, void *opaque) { int ret; if (kvm_enabled() && !kvm_has_sync_mmu()) { qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); return -1; } ret = qemu_balloon(qdict_get_int(params, "value")); if (ret == 0) { qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); return -1; } cb(opaque, NULL); return 0; }
4,925
FFmpeg
831a999ddaf89ad3bb31bfcf4201463098444539
0
static av_cold int movie_init(AVFilterContext *ctx, const char *args) { MovieContext *movie = ctx->priv; AVInputFormat *iformat = NULL; int64_t timestamp; int nb_streams, ret, i; char default_streams[16], *stream_specs, *spec, *cursor; char name[16]; AVStream *st; movie->class = &movie_class; av_opt_set_defaults(movie); if (args) movie->file_name = av_get_token(&args, ":"); if (!movie->file_name || !*movie->file_name) { av_log(ctx, AV_LOG_ERROR, "No filename provided!\n"); return AVERROR(EINVAL); } if (*args++ == ':' && (ret = av_set_options_string(movie, args, "=", ":")) < 0) return ret; movie->seek_point = movie->seek_point_d * 1000000 + 0.5; stream_specs = movie->stream_specs; if (!stream_specs) { snprintf(default_streams, sizeof(default_streams), "d%c%d", !strcmp(ctx->filter->name, "amovie") ? 'a' : 'v', movie->stream_index); stream_specs = default_streams; } for (cursor = stream_specs, nb_streams = 1; *cursor; cursor++) if (*cursor == '+') nb_streams++; if (movie->loop_count != 1 && nb_streams != 1) { av_log(ctx, AV_LOG_ERROR, "Loop with several streams is currently unsupported\n"); return AVERROR_PATCHWELCOME; } av_register_all(); // Try to find the movie format (container) iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL; movie->format_ctx = NULL; if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) { av_log(ctx, AV_LOG_ERROR, "Failed to avformat_open_input '%s'\n", movie->file_name); return ret; } if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0) av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n"); // if seeking requested, we execute it if (movie->seek_point > 0) { timestamp = movie->seek_point; // add the stream start time, should it exist if (movie->format_ctx->start_time != AV_NOPTS_VALUE) { if (timestamp > INT64_MAX - movie->format_ctx->start_time) { av_log(ctx, AV_LOG_ERROR, "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n", movie->file_name, movie->format_ctx->start_time, movie->seek_point); return AVERROR(EINVAL); } timestamp += movie->format_ctx->start_time; } if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) { av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n", movie->file_name, timestamp); return ret; } } for (i = 0; i < movie->format_ctx->nb_streams; i++) movie->format_ctx->streams[i]->discard = AVDISCARD_ALL; movie->st = av_calloc(nb_streams, sizeof(*movie->st)); if (!movie->st) return AVERROR(ENOMEM); for (i = 0; i < nb_streams; i++) { spec = av_strtok(stream_specs, "+", &cursor); if (!spec) return AVERROR_BUG; stream_specs = NULL; /* for next strtok */ st = find_stream(ctx, movie->format_ctx, spec); if (!st) return AVERROR(EINVAL); st->discard = AVDISCARD_DEFAULT; movie->st[i].st = st; movie->max_stream_index = FFMAX(movie->max_stream_index, st->index); } if (av_strtok(NULL, "+", &cursor)) return AVERROR_BUG; movie->out_index = av_calloc(movie->max_stream_index + 1, sizeof(*movie->out_index)); if (!movie->out_index) return AVERROR(ENOMEM); for (i = 0; i <= movie->max_stream_index; i++) movie->out_index[i] = -1; for (i = 0; i < nb_streams; i++) movie->out_index[movie->st[i].st->index] = i; for (i = 0; i < nb_streams; i++) { AVFilterPad pad = { 0 }; snprintf(name, sizeof(name), "out%d", i); pad.type = movie->st[i].st->codec->codec_type; pad.name = av_strdup(name); pad.config_props = movie_config_output_props; pad.request_frame = movie_request_frame; ff_insert_outpad(ctx, i, &pad); ret = open_stream(ctx, &movie->st[i]); if (ret < 0) return ret; if ( movie->st[i].st->codec->codec->type == AVMEDIA_TYPE_AUDIO && !movie->st[i].st->codec->channel_layout) { ret = guess_channel_layout(&movie->st[i], i, ctx); if (ret < 0) return ret; } } if (!(movie->frame = avcodec_alloc_frame()) ) { av_log(log, AV_LOG_ERROR, "Failed to alloc frame\n"); return AVERROR(ENOMEM); } av_log(ctx, AV_LOG_VERBOSE, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n", movie->seek_point, movie->format_name, movie->file_name, movie->stream_index); return 0; }
4,926
qemu
b40acf99bef69fa8ab0f9092ff162fde945eec12
0
void cpu_outl(pio_addr_t addr, uint32_t val) { LOG_IOPORT("outl: %04"FMT_pioaddr" %08"PRIx32"\n", addr, val); trace_cpu_out(addr, val); ioport_write(2, addr, val); }
4,927
qemu
9307c4c1d93939db9b04117b654253af5113dc21
0
static void do_loadvm(int argc, const char **argv) { if (argc != 2) { help_cmd(argv[0]); return; } if (qemu_loadvm(argv[1]) < 0) term_printf("I/O error when loading VM from '%s'\n", argv[1]); }
4,928
qemu
cf081fca4e3cc02a309659b571ab0c5b225ea4cf
0
static void vmdk_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVVmdkState *s = bs->opaque; int i; for (i = 0; i < s->num_extents; i++) { if (!s->extents[i].flat) { bs->bl.write_zeroes_alignment = MAX(bs->bl.write_zeroes_alignment, s->extents[i].cluster_sectors); } } }
4,929
qemu
4be746345f13e99e468c60acbd3a355e8183e3ce
0
static int handle_cmd(AHCIState *s, int port, int slot) { IDEState *ide_state; uint32_t opts; uint64_t tbl_addr; AHCICmdHdr *cmd; uint8_t *cmd_fis; dma_addr_t cmd_len; if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) { /* Engine currently busy, try again later */ DPRINTF(port, "engine busy\n"); return -1; } cmd = &((AHCICmdHdr *)s->dev[port].lst)[slot]; if (!s->dev[port].lst) { DPRINTF(port, "error: lst not given but cmd handled"); return -1; } /* remember current slot handle for later */ s->dev[port].cur_cmd = cmd; opts = le32_to_cpu(cmd->opts); tbl_addr = le64_to_cpu(cmd->tbl_addr); cmd_len = 0x80; cmd_fis = dma_memory_map(s->as, tbl_addr, &cmd_len, DMA_DIRECTION_FROM_DEVICE); if (!cmd_fis) { DPRINTF(port, "error: guest passed us an invalid cmd fis\n"); return -1; } /* The device we are working for */ ide_state = &s->dev[port].port.ifs[0]; if (!ide_state->bs) { DPRINTF(port, "error: guest accessed unused port"); goto out; } debug_print_fis(cmd_fis, 0x90); //debug_print_fis(cmd_fis, (opts & AHCI_CMD_HDR_CMD_FIS_LEN) * 4); switch (cmd_fis[0]) { case SATA_FIS_TYPE_REGISTER_H2D: break; default: DPRINTF(port, "unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x " "cmd_fis[2]=%02x\n", cmd_fis[0], cmd_fis[1], cmd_fis[2]); goto out; break; } switch (cmd_fis[1]) { case SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER: break; case 0: break; default: DPRINTF(port, "unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x " "cmd_fis[2]=%02x\n", cmd_fis[0], cmd_fis[1], cmd_fis[2]); goto out; break; } switch (s->dev[port].port_state) { case STATE_RUN: if (cmd_fis[15] & ATA_SRST) { s->dev[port].port_state = STATE_RESET; } break; case STATE_RESET: if (!(cmd_fis[15] & ATA_SRST)) { ahci_reset_port(s, port); } break; } if (cmd_fis[1] == SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER) { /* Check for NCQ command */ if ((cmd_fis[2] == READ_FPDMA_QUEUED) || (cmd_fis[2] == WRITE_FPDMA_QUEUED)) { process_ncq_command(s, port, cmd_fis, slot); goto out; } /* Decompose the FIS */ ide_state->nsector = (int64_t)((cmd_fis[13] << 8) | cmd_fis[12]); ide_state->feature = cmd_fis[3]; if (!ide_state->nsector) { ide_state->nsector = 256; } if (ide_state->drive_kind != IDE_CD) { /* * We set the sector depending on the sector defined in the FIS. * Unfortunately, the spec isn't exactly obvious on this one. * * Apparently LBA48 commands set fis bytes 10,9,8,6,5,4 to the * 48 bit sector number. ATA_CMD_READ_DMA_EXT is an example for * such a command. * * Non-LBA48 commands however use 7[lower 4 bits],6,5,4 to define a * 28-bit sector number. ATA_CMD_READ_DMA is an example for such * a command. * * Since the spec doesn't explicitly state what each field should * do, I simply assume non-used fields as reserved and OR everything * together, independent of the command. */ ide_set_sector(ide_state, ((uint64_t)cmd_fis[10] << 40) | ((uint64_t)cmd_fis[9] << 32) /* This is used for LBA48 commands */ | ((uint64_t)cmd_fis[8] << 24) /* This is used for non-LBA48 commands */ | ((uint64_t)(cmd_fis[7] & 0xf) << 24) | ((uint64_t)cmd_fis[6] << 16) | ((uint64_t)cmd_fis[5] << 8) | cmd_fis[4]); } /* Copy the ACMD field (ATAPI packet, if any) from the AHCI command * table to ide_state->io_buffer */ if (opts & AHCI_CMD_ATAPI) { memcpy(ide_state->io_buffer, &cmd_fis[AHCI_COMMAND_TABLE_ACMD], 0x10); ide_state->lcyl = 0x14; ide_state->hcyl = 0xeb; debug_print_fis(ide_state->io_buffer, 0x10); ide_state->feature = IDE_FEATURE_DMA; s->dev[port].done_atapi_packet = false; /* XXX send PIO setup FIS */ } ide_state->error = 0; /* Reset transferred byte counter */ cmd->status = 0; /* We're ready to process the command in FIS byte 2. */ ide_exec_cmd(&s->dev[port].port, cmd_fis[2]); } out: dma_memory_unmap(s->as, cmd_fis, cmd_len, DMA_DIRECTION_FROM_DEVICE, cmd_len); if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) { /* async command, complete later */ s->dev[port].busy_slot = slot; return -1; } /* done handling the command */ return 0; }
4,931
qemu
e1f7b4812eab992de46c98b3726745afb042a7f0
0
static void virtio_rng_process(VirtIORNG *vrng) { size_t size; if (!is_guest_ready(vrng)) { return; } size = get_request_size(vrng->vq); size = MIN(vrng->quota_remaining, size); if (size) { rng_backend_request_entropy(vrng->rng, size, chr_read, vrng); } }
4,932
qemu
c471ad0e9bd46ca5f5c9c796e727230e043a091d
0
static int vhost_verify_ring_part_mapping(void *part, uint64_t part_addr, uint64_t part_size, uint64_t start_addr, uint64_t size) { hwaddr l; void *p; int r = 0; if (!ranges_overlap(start_addr, size, part_addr, part_size)) { return 0; } l = part_size; p = cpu_physical_memory_map(part_addr, &l, 1); if (!p || l != part_size) { r = -ENOMEM; } if (p != part) { r = -EBUSY; } cpu_physical_memory_unmap(p, l, 0, 0); return r; }
4,933