FUCK2
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#ifndef UTSM_LINUX_COMPAT_H
|
||||
#define UTSM_LINUX_COMPAT_H
|
||||
|
||||
/* linux_compat.h — Deshab Linux 程序兼容层服务接口。
|
||||
*
|
||||
* 依赖 UTSM+Linux 双内核架构:Linux guest 作为 daemon 在 VMX guest 中
|
||||
* park-and-resume 驻留。UTSM 侧的 linux_compat_service 通过 IPC 共享内存
|
||||
* 向 Linux daemon 发送 exec 请求,并 vmresume 唤醒 guest 执行。
|
||||
*
|
||||
* 执行流程:
|
||||
* 1. shell.elf / cmd.elf 通过 boot context 获取 linux_compat_service 指针
|
||||
* 2. 调用 exec(path, argc, argv, ...) 写 IPC 请求到 utsm_to_linux ring
|
||||
* 3. exec() 调用 linux_resume() → vmresume → Linux daemon fork+exec
|
||||
* 4. daemon 通过 linux_to_utsm ring 回传 stdout/stderr/exit,然后 HLT park
|
||||
* 5. exec() 从 ring 读取输出,返回给调用方
|
||||
*
|
||||
* 服务指针通过 dsk_boot_context.reserved[5] 暴露给 DSK 用户态(shell/cmd/desktop)。
|
||||
*/
|
||||
|
||||
#include <utsm/types.h>
|
||||
|
||||
#define LINUX_COMPAT_MAGIC 0x4C4E58434F4D5000ULL /* "LNXCOMP\0" */
|
||||
|
||||
/* Linux 兼容层服务表 — 通过 boot context reserved[5] 传递 */
|
||||
typedef struct linux_compat_service {
|
||||
u64 magic; /* LINUX_COMPAT_MAGIC */
|
||||
|
||||
/* 查询 Linux 兼容层是否可用(Linux guest 已 park 且 IPC 就绪)。
|
||||
* 返回 1 可用,0 不可用。 */
|
||||
int (*is_available)(void);
|
||||
|
||||
/* 执行一个 Linux 程序。
|
||||
* path : 程序路径(如 "/bin/ls"),NUL-terminated
|
||||
* argc/argv : 参数向量(argv[0] 通常为程序名)
|
||||
* stdout_buf : 接收 stdout 的缓冲区(可为 NULL,此时丢弃 stdout)
|
||||
* stdout_cap : stdout_buf 容量(字节)
|
||||
* stdout_len : 输出实际写入的字节数(可为 NULL)
|
||||
* exit_code : 输出进程退出码(可为 NULL)
|
||||
* 返回 0 成功,负值失败(-1=服务不可用, -2=IPC 发送失败,
|
||||
* -3=linux_resume 失败, -4=超时无响应)。 */
|
||||
int (*exec)(const char *path, int argc, const char *const *argv,
|
||||
char *stdout_buf, u64 stdout_cap, u64 *stdout_len,
|
||||
u64 *exit_code);
|
||||
|
||||
/* 查询 Linux guest 状态字符串(调试用),写入 buf,返回字符串长度。 */
|
||||
int (*status)(char *buf, u64 cap);
|
||||
} linux_compat_service;
|
||||
|
||||
/* 获取全局 Linux 兼容层服务实例指针(UTSM 内部使用,
|
||||
* 外部通过 boot context reserved[5] 获取)。 */
|
||||
const linux_compat_service *linux_compat_get_service(void);
|
||||
|
||||
/* 初始化 Linux 兼容层服务(在 linux_launch 成功后调用)。 */
|
||||
void linux_compat_init(void);
|
||||
|
||||
#endif /* UTSM_LINUX_COMPAT_H */
|
||||
@@ -162,9 +162,12 @@ const struct linux_guest_info *linux_get_guest_info(void);
|
||||
* Returns 0 on successful guest termination, negative on error. */
|
||||
int linux_launch(void);
|
||||
|
||||
/* Default Linux command line (can be overridden). */
|
||||
/* Default Linux command line (can be overridden).
|
||||
* nohlt: prevent kernel idle loop from using HLT — only the exec daemon's
|
||||
* explicit ioctl(PARK) HLT should trigger VM-Exit park, so that
|
||||
* linux_launch() returns only after the daemon is ready. */
|
||||
#define LINUX_DEFAULT_CMDLINE \
|
||||
"console=ttyS0,115200 earlyprintk=serial nokaslr " \
|
||||
"no_timer_check loglevel=7"
|
||||
"no_timer_check loglevel=7 nohlt idle=poll"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef UTSM_LINUX_RESUME_H
|
||||
#define UTSM_LINUX_RESUME_H
|
||||
|
||||
#include <utsm/types.h>
|
||||
|
||||
/* linux_resume.h — Linux guest park-and-resume 唤醒接口。
|
||||
*
|
||||
* linux_launch() 启动 Linux guest 后,guest daemon 完成 init 并 HLT 驻留(park)。
|
||||
* linux_resume() 通过 vmresume 唤醒 guest,daemon 处理 IPC 请求后再次 HLT park,
|
||||
* 控制权返回 host。
|
||||
*
|
||||
* 典型流程:
|
||||
* 1. shell 调用 linux_compat_service->exec(path, argc, argv)
|
||||
* 2. exec() 写 IPC 请求到 utsm_to_linux ring
|
||||
* 3. exec() 调用 linux_resume() → vmresume → guest daemon 读取请求 → fork+exec
|
||||
* 4. daemon 写输出到 linux_to_utsm ring → HLT park → linux_resume() 返回
|
||||
* 5. exec() 从 ring 读取输出,返回给 shell
|
||||
*/
|
||||
|
||||
/* 唤醒已 park 的 Linux guest。
|
||||
* 前置条件:g_guest_parked == 1(linux_launch 已完成且 guest 已 HLT)。
|
||||
* 返回 0 成功(guest 再次 park),负值失败。 */
|
||||
int linux_resume(void);
|
||||
|
||||
/* 查询 Linux guest 是否已 park 就绪。 */
|
||||
int linux_is_parked(void);
|
||||
|
||||
#endif /* UTSM_LINUX_RESUME_H */
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef UTSM_PE_H
|
||||
#define UTSM_PE_H
|
||||
|
||||
/* pe.h — Deshab PE/EXE 兼容层公共接口。
|
||||
*
|
||||
* UTSM 内置 PE32+(64位)与 PE32(32位)加载器:
|
||||
* - PE32+:解析 → 映射节区 → 基址重定位 → import 解析(Windows API shim)→ Ring0 原生执行
|
||||
* - PE32 :解析 → 映射节区 → 基址重定位 → import 解析 → x86-32 解释器执行
|
||||
*
|
||||
* pe_service 通过 dsk_boot_context.reserved[4] 暴露给 DSK/cmd.elf,
|
||||
* 同地址空间 Ring0 直接调用。
|
||||
*/
|
||||
|
||||
#include <utsm/types.h>
|
||||
|
||||
#define PE_SERVICE_MAGIC 0x5045535643200000ULL /* "PESVC\0\0" */
|
||||
|
||||
/* PE 加载结果 */
|
||||
typedef struct pe_image_info {
|
||||
u64 image_base; /* 实际加载基址(kmem_alloc_aligned 返回) */
|
||||
u64 image_size; /* 映射后总大小(SizeOfImage) */
|
||||
u64 entry_point; /* 绝对入口地址 = image_base + AddressOfEntryPoint */
|
||||
int is_pe32_plus; /* 1=PE32+ 64位原生执行, 0=PE32 32位解释执行 */
|
||||
int load_ok; /* 1=加载成功 */
|
||||
} pe_image_info;
|
||||
|
||||
/* PE 服务表 — 通过 boot context reserved[4] 传递 */
|
||||
typedef struct pe_service {
|
||||
u64 magic; /* PE_SERVICE_MAGIC */
|
||||
/* 加载 PE 到内存(不执行)。返回 0 成功,info 填充。 */
|
||||
int (*load)(const void *pe_data, u64 size, pe_image_info *out);
|
||||
/* 加载并执行 PE。cmdline = 命令行字符串(GetCommandLineA 返回值)。
|
||||
* 返回 0 成功,*exit_code 为进程退出码。 */
|
||||
int (*run)(const void *pe_data, u64 size, const char *cmdline, u64 *exit_code);
|
||||
/* 释放 pe_load 分配的镜像内存。 */
|
||||
void (*unload)(pe_image_info *info);
|
||||
} pe_service;
|
||||
|
||||
/* 获取全局 PE 服务实例指针(UTSM 内部使用,外部通过 boot context 获取) */
|
||||
const pe_service *pe_get_service(void);
|
||||
|
||||
#endif /* UTSM_PE_H */
|
||||
@@ -42,6 +42,30 @@ struct vmexit_guest_regs {
|
||||
* Non-static: shared between vmm.c, vmexit.c, hypercall.c, and vmexit_asm.S. */
|
||||
extern volatile struct vmexit_guest_regs g_guest_regs;
|
||||
|
||||
/* ===== Linux guest park-and-resume 状态 =====
|
||||
*
|
||||
* g_linux_guest_active: 1 = 当前运行的 guest 是 Linux guest。
|
||||
* handle_hlt 检查此标志:Linux guest HLT 时 park(推进 RIP,exit-to-host),
|
||||
* self-test guest HLT 时 terminate。
|
||||
* g_guest_parked: 1 = Linux guest 已 HLT 驻留,可被 linux_resume() 唤醒。
|
||||
* linux_compat_service 通过此标志判断 guest 是否就绪。 */
|
||||
extern volatile int g_linux_guest_active;
|
||||
extern volatile int g_guest_parked;
|
||||
|
||||
/* ===== VM-Exit host 恢复点(vmm.c 定义,vmm.c / linux_boot.c / linux_resume.c 共用) =====
|
||||
*
|
||||
* g_saved_host_rsp: vmlaunch/vmresume 前保存的 host RSP。VM-Exit 处理器
|
||||
* 终止 guest 时恢复此 RSP 并 jmp 到 g_saved_return_rip。
|
||||
* g_saved_return_rip: vmlaunch/vmresume 后的返回地址(post_guest / post_resume 标签)。
|
||||
* g_guest_terminated: 1 = guest 已终止(不再 vmresume)。dispatch 返回 0 时置位。
|
||||
* g_last_exit_reason: 最近一次 VM-Exit 的 reason(vmexit_asm.S 路径写入)。
|
||||
*
|
||||
* 这些符号必须是非 static 全局变量,因为 vmexit_asm.S 通过 RIP 相对寻址引用。 */
|
||||
extern volatile u64 g_saved_host_rsp;
|
||||
extern volatile u64 g_saved_return_rip;
|
||||
extern volatile int g_guest_terminated;
|
||||
extern volatile u64 g_last_exit_reason;
|
||||
|
||||
/* ===== VMM API ===== */
|
||||
|
||||
/* 初始化 VMM:VMX root 模式 + EPT 表 + 分配 VMCS。
|
||||
|
||||
Reference in New Issue
Block a user