usb重定向qemu前端处理
-chardev 'spicevmc,id=usbredirchardev0,name=usbredir'
red::shared_ptr<RedCharDevice>
spicevmc_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin, uint8_t channel_type)
{auto channel(red_vmc_channel_new(reds, channel_type)); //创建RedVmcChannel通道if (!channel) {return red::shared_ptr<RedCharDevice>();}auto dev = red::make_shared<RedCharDeviceSpiceVmc>(sin, reds, channel.get()); //设备与通道绑定channel->chardev_sin = sin;return dev;
} struct RedVmcChannel: public RedChannel
{RedVmcChannel(RedsState *reds, uint32_t type, uint32_t id);~RedVmcChannel() override;void on_connect(RedClient *client, RedStream *stream, int migration, RedChannelCapabilities *caps) override;VmcChannelClient *rcc;RedCharDevice *chardev; /* weak */SpiceCharDeviceInstance *chardev_sin;red::shared_ptr<RedVmcPipeItem> pipe_item;RedCharDeviceWriteBuffer *recv_from_client_buf;uint8_t port_opened;uint32_t queued_data;RedStatCounter in_data;RedStatCounter in_compressed;RedStatCounter in_decompressed;RedStatCounter out_data;RedStatCounter out_compressed;RedStatCounter out_uncompressed;
}; void RedVmcChannel::on_connect(RedClient *client, RedStream *stream, int migration,RedChannelCapabilities *caps)
{RedVmcChannel *vmc_channel;SpiceCharDeviceInstance *sin;SpiceCharDeviceInterface *sif;vmc_channel = this;sin = vmc_channel->chardev_sin;if (rcc) {red_channel_warning(this, "channel client (%p) already connected, refusing second connection", rcc);// TODO: notify client in advance about the in use channel using// SPICE_MSG_MAIN_CHANNEL_IN_USE (for example)red_stream_free(stream);return;}rcc = vmc_channel_client_create(this, client, stream, caps);if (!rcc) {return;}vmc_channel->queued_data = 0;rcc->ack_zero_messages_window();if (strcmp(sin->subtype, "port") == 0) {spicevmc_port_send_init(rcc);}if (!vmc_channel->chardev->client_add(reinterpret_cast<RedCharDeviceClientOpaque *>(client), FALSE, 0, ~0, ~0, rcc->is_waiting_for_migrate_data())) {spice_warning("failed to add client to spicevmc");rcc->disconnect();return;}sif = spice_char_device_get_interface(sin);if (sif->state) {sif->state(sin, 1);}
} bool VmcChannelClient::handle_message(uint16_t type, uint32_t size, void *msg)
{/* NOTE: *msg free by g_free() (when cb to VmcChannelClient::release_recv_buf* with the compressed msg type) */RedVmcChannel *channel;SpiceCharDeviceInterface *sif;channel = get_channel();sif = spice_char_device_get_interface(channel->chardev_sin);switch (type) {case SPICE_MSGC_SPICEVMC_DATA:spice_assert(channel->recv_from_client_buf->buf == msg);stat_inc_counter(channel->in_data, size);channel->recv_from_client_buf->buf_used = size;channel->chardev->write_buffer_add(channel->recv_from_client_buf);channel->recv_from_client_buf = nullptr;break;case SPICE_MSGC_SPICEVMC_COMPRESSED_DATA:return handle_compressed_msg(channel, this, static_cast<SpiceMsgCompressedData *>(msg));break;case SPICE_MSGC_PORT_EVENT:if (size != sizeof(uint8_t)) {spice_warning("bad port event message size");return FALSE;}if (sif->base.minor_version >= 2 && sif->event != nullptr)sif->event(channel->chardev_sin, *static_cast<uint8_t *>(msg));break;default:return RedChannelClient::handle_message(type, size, msg);}return TRUE;
} void RedCharDevice::write_buffer_add(RedCharDeviceWriteBuffer *write_buf)
{/* caller shouldn't add buffers for client that was removed */if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT &&!red_char_device_client_find(this, write_buf->priv->client)) {g_warning("client not found: this %p client %p", this, write_buf->priv->client);red_char_device_write_buffer_unref(write_buf);return;}g_queue_push_head(&priv->write_queue, write_buf);write_to_device();
} int RedCharDevice::write_to_device()
{SpiceCharDeviceInterface *sif;int total = 0;int n;if (!priv->running || priv->wait_for_migrate_data || !priv->sin) {return 0;}/* protect against recursion with red_char_device_wakeup */if (priv->during_write_to_device++ > 0) {return 0;}red::shared_ptr<RedCharDevice> hold_dev(this);if (priv->write_to_dev_timer) {red_timer_cancel(priv->write_to_dev_timer);}sif = spice_char_device_get_interface(priv->sin);while (priv->running) {uint32_t write_len;if (!priv->cur_write_buf) {priv->cur_write_buf =static_cast<RedCharDeviceWriteBuffer *>(g_queue_pop_tail(&priv->write_queue));if (!priv->cur_write_buf)break;priv->cur_write_buf_pos = priv->cur_write_buf->buf;}write_len = priv->cur_write_buf->buf + priv->cur_write_buf->buf_used - priv->cur_write_buf_pos;n = sif->write(priv->sin, priv->cur_write_buf_pos, write_len);if (n <= 0) {if (priv->during_write_to_device > 1) {priv->during_write_to_device = 1;continue; /* a wakeup might have been called during the write - make sure it doesn't get lost */}break;}total += n;write_len -= n;if (!write_len) {write_buffer_release(&priv->cur_write_buf);continue;}priv->cur_write_buf_pos += n;}/* retry writing as long as the write queue is not empty */if (priv->running) {if (priv->cur_write_buf) {if (priv->write_to_dev_timer) {red_timer_start(priv->write_to_dev_timer,CHAR_DEVICE_WRITE_TO_TIMEOUT);}} else {spice_assert(g_queue_is_empty(&priv->write_queue));}priv->active = priv->active || total;}priv->during_write_to_device = 0;return total;
} static SpiceCharDeviceInterface vmc_interface = {.base.type = SPICE_INTERFACE_CHAR_DEVICE,.base.description = "spice virtual channel char device",.base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,.base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,.state = vmc_state,.write = vmc_write,.read = vmc_read,.event = vmc_event,.flags = SPICE_CHAR_DEVICE_NOTIFY_WRITABLE,
}; static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
{SpiceChardev *scd = container_of(sin, SpiceChardev, sin);Chardev *chr = CHARDEV(scd);ssize_t out = 0;ssize_t last_out;uint8_t* p = (uint8_t*)buf;while (len > 0) {int can_write = qemu_chr_be_can_write(chr);last_out = MIN(len, can_write);if (last_out <= 0) {break;}qemu_chr_be_write(chr, p, last_out);out += last_out;len -= last_out;p += last_out;}trace_spice_vmc_write(out, len + out);return out;
} void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len)
{if (qemu_chr_replay(s)) {if (replay_mode == REPLAY_MODE_PLAY) {return;}replay_chr_be_write(s, buf, len);} else {qemu_chr_be_write_impl(s, buf, len);}
} 10、判断是否有后端设备连接并发送给后端设备
void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len)
{CharBackend *be = s->be;if (be && be->chr_read) {be->chr_read(be->opaque, buf, len);}
} 相关文章:
usb重定向qemu前端处理
1、qemu添加spicevmc前端时会创建vmc通道。 -chardev spicevmc,idusbredirchardev0,nameusbredir red::shared_ptr<RedCharDevice> spicevmc_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin, uint8_t channel_type) {auto channel(red_vmc_channel_new(r…...
OpenHarmony - 小型系统内核(LiteOS-A)(五)
OpenHarmony - 小型系统内核(LiteOS-A)(五) 六、文件系统 虚拟文件系统 基本概念 VFS(Virtual File System)是文件系统的虚拟层,它不是一个实际的文件系统,而是一个异构文件系统之…...
PyTorch进阶学习笔记[长期更新]
第一章 PyTorch简介和安装 PyTorch是一个很强大的深度学习库,在学术中使用占比很大。 我这里是Mac系统的安装,相比起教程中的win/linux安装感觉还是简单不少(之前就已经安好啦),有需要指导的小伙伴可以评论。 第二章…...
proteus8.17 环境配置
Proteus介绍 Proteus 8.17 是一款功能强大的电子设计自动化(EDA)软件,广泛应用于电子电路设计、仿真和分析。以下是其主要特点和新功能: ### 主要功能 - **电路仿真**:支持数字和模拟电路的仿真,包括静态…...
Microsoft SQL Server Management 一键删除数据库所有外键
DECLARE ESQL VARCHAR(1000); DECLARE FCursor CURSOR --定义游标 FOR (SELECT ALTER TABLE O.name DROP CONSTRAINT F.name; AS CommandSQL from SYS.FOREIGN_KEYS F JOIN SYS.ALL_OBJECTS O ON F.PARENT_OBJECT_ID O.OBJECT_ID WHERE O.TYPE U AND F.TYPE …...
【JAVAFX】自定义FXML 文件存放的位置以及使用
情况 1:FXML 文件与调用类在同一个包中(推荐) 假设类 MainApp 的包是 com.example,且 FXML 文件放在 resources/com/example 下: 项目根目录 ├── src │ └── sample │ └── Main.java ├── src/s…...
Oracle 如何停止正在运行的 Job
Oracle 如何停止正在运行的 Job 先了解是dbms_job 还是 dbms_scheduler,再确定操作命令。 一 使用 DBMS_JOB 包停止作业(适用于旧版 Job) 1.1 查看正在运行的 Job SELECT job, what, this_date, this_sec, failures, broken FROM user_j…...
高级语言调用C接口(四)结构体(2)-Python
这个专栏好久没有更新了,主要是坑开的有点大,也不知道怎么填,涉及到的开发语言比较多,写起来比较累,需要看的人其实并不多,只能说,慢慢填吧,中间肯定还会插很多别的东西,…...
Java对接Dify API接口完整指南
Java对接Dify API接口完整指南 一、Dify API简介 Dify是一款AI应用开发平台,提供多种自然语言处理能力。通过调用Dify开放API,开发者可以快速集成智能对话、文本生成等功能到自己的Java应用中。 二、准备工作 获取API密钥 登录Dify平台控制台在「API密…...
极狐GitLab GEO 功能介绍
极狐GitLab 是 GitLab 在中国的发行版,关于中文参考文档和资料有: 极狐GitLab 中文文档极狐GitLab 中文论坛极狐GitLab 官网 Geo (PREMIUM SELF) Geo 是广泛分布的开发团队的解决方案,可作为灾难恢复策略的一部分提供热备份。Geo 不是 开箱…...
Nginx-前言
nginx是什么? 轻量级,开源免费的web服务器软件,服务器安装nginx,服务器则成为web服务器 nginx的稳定版版本号: 偶数版本 nginx的相关目录: /etc/nginx/nginx.conf nginx的主配置文件 /etc/nginx/ngi…...
LFI to RCE
LFI不止可以来读取文件,还能用来RCE 在多道CTF题目中都有LFItoRCE的非预期解,下面总结一下LFI的利用姿势 1. /proc/self/environ 利用 条件:目标能读取 /proc/self/environ,并且网页中存在LFI点 利用方式: 修改请…...
云原生(Cloud Native)的详解、开发流程及同类软件对比
以下是云原生(Cloud Native)的详解、开发流程及同类软件对比: 一、云原生核心概念 定义: 云原生(Cloud Native)是基于云环境设计和运行应用程序的方法论,强调利用云平台的弹性、分布式和自动化…...
全局唯一标识符(UID)生成策略
目录 一、UUID 二、雪花算法 三、时间戳 随机数 四、利用数据库的自增字段 五、 基于 Redis 的原子操作 总结 在信息系统中,生成唯一ID是非常常见的需求,尤其是在分布式系统或高并发场景下。以下是几种常见的生成唯一ID的算法或方式: …...
学习笔记:减速机工作原理
学习笔记:减速机工作原理 一、减速机图片二、减速比概念三、减速机的速比与扭矩之间的关系四、题外内容--电机扭矩 一、减速机图片 二、减速比概念 即减速装置的传动比,是传动比的一种,是指减速机构中,驱动轴与被驱动轴瞬时输入速…...
《UE5_C++多人TPS完整教程》学习笔记36 ——《P37 拾取组件(Pickup Widget)》
本文为B站系列教学视频 《UE5_C多人TPS完整教程》 —— 《P37 拾取组件(Pickup Widget)》 的学习笔记,该系列教学视频为计算机工程师、程序员、游戏开发者、作家(Engineer, Programmer, Game Developer, Author) Steph…...
《空间复杂度(C语言)》
文章目录 前言一、什么是空间复杂度?通俗理解: 二、空间复杂度的数学定义三、常见空间复杂度举例(含C语言代码)🔹 O(1):常数空间🔹 O(n):线性空间🔹 O(n^2):平…...
Kaggle-Store Sales-(回归+多表合并+xgboost模型)
Store Sales 题意: 给出很多商店,给出商店的类型,某时某刻卖了多少销售额。 给出了油价表,假期表,进货表。 让你求出测试集合中每个商店的销售额是多少。 数据处理: 1.由于是多表,所以要先把其他表与tr…...
在 Tailwind CSS 中优雅地隐藏滚动条
在开发中,我们经常需要隐藏滚动条但保持滚动功能,这在构建现代化的用户界面时很常见。 本文将介绍两种在 Tailwind CSS 项目中实现这一目标的方法,方便同学们记录和查阅。 方法一:使用 tailwind-scrollbar-hide 插件 这是一种更…...
智能合约安全审计平台——以太坊虚拟机安全沙箱
目录 以太坊虚拟机安全沙箱 —— 理论、设计与实战1. 引言2. 理论背景与安全原理2.1 以太坊虚拟机(EVM)概述2.2 安全沙箱的基本概念2.3 安全证明与形式化验证3. 系统架构与模块设计3.1 模块功能说明3.2 模块之间的数据流与安全性4. 安全性与密码学考量4.1 密码学保障在沙箱中…...
std::unordered_map(C++)
std::unordered_map 1. 概述2. 内部实现3. 性能特征4. 常用 API5. 使用示例6. 自定义哈希与相等比较7. 注意事项与优化8. 使用建议9. emplace和insert异同相同点不同点例子对比何时优先使用哪种? 1. 概述 定义:std::unordered_map<Key, T, Hash, KeyE…...
【MCP教程】Claude Desktop 如何连接部署在远程的remote mcp server服务器(remote host)
前言 最近MCP特别火热,笔者自己也根据官方文档尝试了下。 官方文档给的Demo是在本地部署一个weather.py,然后用本地的Claude Desktop去访问该mcp服务器,从而完成工具的调用: 但是,问题来了,Claude Deskto…...
Android Input——输入事件回调完成(十四)
前面几篇文章介绍了事件回调的相关流程,以及回调事件处理函数的相关内容,最后我们再来看一下事件处理完后,如何通知 InputDispatcher 去回调 Callback。 一、客户端回调 在 Android 的事件分发机制中,当客户端(即应用层)完成事件处理后,最终会调用 ViewRootImpl 的 fin…...
数据通信学习笔记之OSPF配置命令
华为 [huawei]ospf 10 router-id 1.1.1.1 //创建ospf进程,本地有效area 1 // 进入区域1network 192.168.1.0 0.0.0.255 // 宣告网段,使用反掩码stub // 配置为stub区域stub no-summary // 配置为Totally Stub 完全末节区域。在ABR上配置࿰…...
Python -yield 在python 中什么意思
在 Python 中,yield 是一个关键字,用于定义生成器函数(generator function)。它的作用是将一个普通函数转变为可迭代的生成器,具有惰性计算的特性。以下是关键要点: 核心概念 生成器函数: 当函数…...
多个路由器互通(静态路由)无单臂路由(简单版)
多个路由器互通(静态路由)无单臂路由(简单版) 开启端口并配ip地址 维护1 Router>en Router#conf t Router(config)#int g0/0 Router(config-if)#no shutdown Router(config-if)#ip address 192.168.10.254 255.255.255.0 Ro…...
OpenCV 图形API(38)图像滤波-----Sobel 算子操作函数Sobel()
操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C11 算法描述 cv::gapi::Sobel 函数是 OpenCV 的 G-API 模块中用于执行 Sobel 算子操作的一个函数,主要用于图像的边缘检测。Sobel 算子通过计算图…...
3DS 转 STL 全攻略:传统工具与迪威模型网在线转换深度解析
在 3D 建模与 3D 打印的技术领域中,常常会遇到需要将不同格式的文件进行转换的情况。其中,把 3DS 文件转换为 STL 格式是较为常见的操作。3DS 文件作为一种旧版 Autodesk 3D Studio 使用的 3D 图像格式,存储着丰富的信息,包括网格…...
windows系统安装驱动、cuda和cudnn
一、首先在自己的电脑里安装了nvidia的独立显卡 显卡的查找方式: CtrlShiftEsc打开任务管理器,点击性能,点击GPU 0查看显卡型号,如下图所示: 只要电脑中有nvidia的独立显卡,就可以暗转显卡驱动、cuda和cu…...
嵌入式开发--STM32软件和硬件CRC的使用--续篇
本文是《嵌入式开发–STM32软件和硬件CRC的使用》的续篇,又踩到一个坑,发出来让大家避一下坑。 按照G0系列的设置,得出错误的结果 前文对应的是STM32G0系列,今天在用STM32G4系列时,按照前文的设置,用硬件…...
