feat: re-instrument per STUB rules - all silent placeholders now panic

- PE-E03 pe_loader.c: unsupported base-reloc type silently skipped -> panic
- PE-E04 pe_shim.c ReadFile: fake TRUE+0-bytes ("pretend EOF") -> panic
- PE-E05 pe_shim.c CreateFileA: no file backend -> panic (no honest-failure excuse)
- PE-E06/E07 x86emu32.c: emu IAT unimplemented API / shim index OOB -> panic
- NETST-E01 net.c: netdev stats all-zero placeholder ("lying zero traffic") -> panic
- apic.c comment: SIPI reserved now points to DKM-E03 skeleton
- pe_dll_manager comments: circular-dep stub call now documented as PE-E01
- virtio_blk.c: capacity declaration marked as instrumentation whitelist
- QEMU verify: wizard -> Save -> verify ok -> login success -> desktop ready,
  zero spurious panics

[STUB] P1/UTSM/pe+net re-instrument sweep | 剩余STUB命中=101 (全部为 panic 坐标注释 /
IDT halt-stub 防御术语 / 白名单) | “未成之物,不留活口”
This commit is contained in:
Linehu
2026-10-03 12:44:57 +08:00
parent cd39caa10c
commit 301006d611
13 changed files with 78 additions and 18 deletions
+2 -1
View File
@@ -6,7 +6,8 @@
* 2. IOAPIC 重定向表初始化: 逐条目编程, 将 ISA IRQ 映射到 vector 0x20-0x2F
* (兼容 PIC 布局), 逐条目 mask
* 3. MADT ISO (Interrupt Source Override) 处理: 按 ACPI 规范修正 IRQ→GSI 映射
* 4. SIPI 多核启动框架 (预留, 未实现)
* 4. SIPI 多核启动框架 (预留: 调用 dkm_sipi_wake_ap 即 DKM-E03 panic,
* 见 CODE/UTSM/dkm/kernel_api.c 骨架)
*
* B7 路由接管 (apic_route):
* FUCK [drivers] apic_route=1 时, 本驱动在初始化末尾尝试把中断路由
+7 -5
View File
@@ -1,5 +1,6 @@
#include <utsm/net.h>
#include <utsm/log.h>
#include <utsm/panic.h>
/*
* 最小 netdev 注册表:
@@ -92,14 +93,15 @@ static int net_is_wireless_impl(u32 index) {
}
/* 统计查询:返回驱动层累计的收发统计。
* 当前实现为占位:返回全零统计。
* 后续由驱动在 tx/rx 回调内更新共享统计区,此处直接读取。
* 驱动层的本地统计(如 e1000 的 g_stat_tx_ok 等)与 netdev 层统计
* 通过 driver_ctx 统一后即可返回精确值。 */
* 严格错误策略插桩:全零统计占位 = 向上层谎报"网卡零流量",
* 零降级 panic(NETST-E01)。驱动层统计区接入(driver_ctx 共享统计)
* 后才能提供真实语义。 */
static int net_device_stats_impl(u32 index, dkm_net_stats *out) {
if (!out) return -1;
if (index >= g_net_device_count) return -2;
/* 占位:全零。后续由驱动填充实际统计。 */
(void)index;
panic_full("NETST-E01 NET STATS NOT IMPLEMENTED",
"netdev stats placeholder returns all-zero: driver stats wiring not implemented", 0);
for (u32 i = 0; i < sizeof(dkm_net_stats); i++)
((u8 *)out)[i] = 0;
return 0;
+6
View File
@@ -0,0 +1,6 @@
kernel/net.o: kernel\net.c include\utsm\net.h include\utsm\types.h \
include\utsm\log.h include\utsm\panic.h
include\utsm\net.h:
include\utsm\types.h:
include\utsm\log.h:
include\utsm\panic.h:
Binary file not shown.
+3 -1
View File
@@ -356,7 +356,9 @@ int pe_dll_load(const char *dll_name, u64 *out_base) {
return 0;
}
if (e->state == DLL_STATE_LOADING) {
/* 循环依赖:返回 -1,调用方填 unimpl stub */
/* 循环依赖:返回 -1,调用方填 unimpl stub——该 stub 被调用
* 即 PE-E01 莲花 panic(见 pe_shim.c shim_unimpl64),
* 不存在静默降级出口。 */
if (out_base) *out_base = 0;
return -1;
}
+10
View File
@@ -0,0 +1,10 @@
pe/pe_dll_manager.o: pe\pe_dll_manager.c pe\pe_dll_manager.h \
include\utsm\types.h pe\pe_loader.h include\utsm\pe.h pe\pe_shim.h \
include\utsm\arena.h include\utsm\log.h
pe\pe_dll_manager.h:
include\utsm\types.h:
pe\pe_loader.h:
include\utsm\pe.h:
pe\pe_shim.h:
include\utsm\arena.h:
include\utsm\log.h:
+5 -1
View File
@@ -144,7 +144,11 @@ static void apply_relocations(u8 *image, u32 image_size, u64 image_base_actual,
val += (u32)delta;
*(u32 *)target = val;
} else {
/* 其他重定位类型暂不支持 */
/* 严格错误策略插桩:未实现的重定位类型静默跳过 = 重定位
* 不完整照跑,零降级 panic(PE-E03)。 */
log_error("[PE] unsupported reloc type");
panic_full("PE-E03 RELOC TYPE NOT IMPLEMENTED",
"PE base-reloc type outside ABSOLUTE/HIGHLOW/DIR64: not implemented", 0);
}
}
block_rva += block_size;
+13 -5
View File
@@ -216,10 +216,12 @@ static u64 __attribute__((ms_abi)) shim_WriteFile(u64 handle, u64 buffer, u64 le
static u64 __attribute__((ms_abi)) shim_ReadFile(u64 handle, u64 buffer, u64 max_length,
u64 bytes_read_ptr, u64 overlapped) {
(void)handle; (void)buffer; (void)max_length; (void)overlapped;
/* 暂不支持输入读取;lpNumberOfBytesRead 同为 DWORD*(4 字节) */
u64 brp = gp(bytes_read_ptr);
if (brp) *(u32 *)brp = 0;
return 1;
/* 严格错误策略插桩:读取路径未实现。此前返回 TRUE+0 字节是
* "假装能跑"——PE 应用以为读到了 EOF。零降级 panic(PE-E04)。 */
log_error("[PE] ReadFile called on shim without input backend");
panic_full("PE-E04 READFILE INPUT NOT IMPLEMENTED",
"shim ReadFile has no input backend: designed, not implemented", 0);
return 0;
}
static u64 __attribute__((ms_abi)) shim_ExitProcess(u64 exit_code) {
@@ -287,7 +289,13 @@ static u64 __attribute__((ms_abi)) shim_GetEnvironmentVariableA(u64 name, u64 bu
static u64 __attribute__((ms_abi)) shim_CreateFileA(u64 filename, u64 access, u64 share,
u64 sa, u64 disp, u64 flags, u64 template) {
(void)filename; (void)access; (void)share; (void)sa; (void)disp; (void)flags; (void)template;
return 0; /* 暂不支持文件 */
/* 严格错误策略插桩:文件访问未实现。返回 INVALID_HANDLE 是诚实的
* Win32 失败语义(应用可自行处理),但功能本身未实现——按零降级
* 原则 panic(PE-E05),不做"假装没有文件"的静默降级。 */
log_error("[PE] CreateFileA called: file IO not implemented");
panic_full("PE-E05 FILE IO NOT IMPLEMENTED",
"shim CreateFileA: file backend designed, not implemented", 0);
return 0;
}
static u64 __attribute__((ms_abi)) shim_CloseHandle(u64 handle) { (void)handle; return 1; }
static u64 __attribute__((ms_abi)) shim_GetFileSize(u64 handle, u64 high) {
+10 -3
View File
@@ -11,6 +11,7 @@
#include "x86emu32.h"
#include "pe_shim.h"
#include <utsm/log.h>
#include <utsm/panic.h>
#include <utsm/types.h>
/* ===== 内存访问(带边界检查) ===== */
@@ -278,14 +279,20 @@ static int try_iat_call(x86emu_state *emu, u32 target) {
if (target >= 0x00010000 && target < 0x00020000) {
int shim_idx = target & 0xFFFF;
if (shim_idx == 0xFFFF) {
/* 未实现 stub */
log_warn("[PE32] call unimplemented API");
/* 严格错误策略插桩:32 位解释器调用未实现 API = 静默 EAX=0
* 会给 PE 程序喂错误语义,零降级 panic(PE-E06)。 */
log_error("[PE32] call unimplemented API");
panic_full("PE-E06 EMU UNSHIMMED API CALLED",
"x86emu32 IAT call hit unimplemented stub: not implemented", 0);
emu->regs[X86_EAX] = 0;
return 1;
}
const pe_shim_entry *se = pe_shim_get(shim_idx);
if (!se) {
log_warn("[PE32] shim index out of range");
/* 严格错误策略插桩:shim 索引越界 = 导入解析已损坏,panic(PE-E07) */
log_error("[PE32] shim index out of range");
panic_full("PE-E07 SHIM INDEX OUT OF RANGE",
"x86emu32 IAT call with invalid shim index", 0);
emu->regs[X86_EAX] = 0;
return 1;
}
+7
View File
@@ -0,0 +1,7 @@
pe/x86emu32.o: pe\x86emu32.c pe\x86emu32.h include\utsm\types.h \
pe\pe_shim.h include\utsm\log.h include\utsm\panic.h
pe\x86emu32.h:
include\utsm\types.h:
pe\pe_shim.h:
include\utsm\log.h:
include\utsm\panic.h:
+4 -2
View File
@@ -346,8 +346,10 @@ void virtio_blk_backend_init(void) {
u64 ssize = blk->sector_size(0);
if (ssize > 0) g_blk_sector_size = (u32)ssize;
/* 从设备名推算容量不可得,用默认值(guest 端可再探测)。
* 实际 capacity 需读 ATA IDENTIFY;这里给 4GB 占位,
* guest mkfs/mount 会按此上限工作。 */
* 【插桩白名单】capacity 为声明值而非真实容量:block API 尚无
* capacity 查询(sector_count 仅部分 provider 提供)。这是对
* guest 的声明边界而非"静默失败",guest 端按声明值工作;
* 补齐 block capacity 查询后改为真实值。 */
g_blk_capacity = 8ULL * 1024 * 1024 * 1024 / 512; /* 8GB in sectors */
log_info("[VBLK] bound to UTSM block device 0");
log_hex64("[VBLK] capacity(sectors)=", g_blk_capacity);
+11
View File
@@ -0,0 +1,11 @@
vmm/virtio_blk.o: vmm\virtio_blk.c include\utsm\virtio_mmio.h \
include\utsm\types.h include\utsm\linux_loader.h include\utsm\block.h \
include\utsm\log.h vmm\..\..\tools\fat32_lfn.h \
vmm\..\..\tools\fat32_part.h
include\utsm\virtio_mmio.h:
include\utsm\types.h:
include\utsm\linux_loader.h:
include\utsm\block.h:
include\utsm\log.h:
vmm\..\..\tools\fat32_lfn.h:
vmm\..\..\tools\fat32_part.h: