From 566cbfb5d2e2319eb0da8efabe545f7342850abe Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 02:36:06 +0100 Subject: [PATCH] Boot signed Xlib, font encoding and Pixman libraries in Vinix --- tests/x11/README.md | 6 ++++ tests/x11/client.v | 83 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 tests/x11/client.v diff --git a/tests/x11/README.md b/tests/x11/README.md index af366b0..bee0a31 100644 --- a/tests/x11/README.md +++ b/tests/x11/README.md @@ -22,3 +22,9 @@ To reproduce it, supply the two original sidecars, per-architecture inventories ```sh v run tests/x11/release-elf.v "$release_assets" "$reference_apks" "$new_output" ``` + +## Signed packages in a Vinix guest + +The x86-64 client test booted Vinix with ten PGP-validated packages, including libX11, libfontenc and Pixman. `client.v` parsed a signed X geometry, mapped the Latin-9 euro character to Unicode and copied a one-pixel ARGB image through Pixman. All three checks passed. Its additional `--display` mode performs a pixmap readback against a running X server. + +The font test installed `mkfontscale` and both bitmap font packages by name. The cold install ran the pacman hook inside the target root and produced 766 owned file and link paths across twelve signed packages. Inside Vinix, `font-index.v` ran the installed hook’s command with the cursor font present, removed and restored. It verified the header count, the cursor entry and the fixed-font entry. Both QEMU runs used one vCPU and 384 MiB. Receipts and serial transcripts are under `~/.local/state/vinix/ports/musl-busybox-CqkBEA/xorg/worker/{x11-client-guest-04,font-index-guest-02}`. diff --git a/tests/x11/client.v b/tests/x11/client.v new file mode 100644 index 0000000..535f380 --- /dev/null +++ b/tests/x11/client.v @@ -0,0 +1,83 @@ +// With --display, also round-trip a pixel through the running X server. +module main + +import os + +#include +#include +#include +#include +#pkgconfig pixman-1 +#flag -lX11 +#flag -lfontenc + +fn C.XParseGeometry(&char, &int, &int, &u32, &u32) int +fn C.FontEncMapFind(&char, int, int, int, &char) voidptr +fn C.FontEncRecode(u32, voidptr) u32 +fn C.pixman_image_create_bits(u32, int, int, &u32, int) voidptr +fn C.pixman_image_composite32(int, voidptr, voidptr, voidptr, int, int, int, int, int, int, int, int) +fn C.pixman_image_unref(voidptr) int +fn C.XOpenDisplay(&char) voidptr +fn C.XDefaultScreen(voidptr) int +fn C.XRootWindow(voidptr, int) u64 +fn C.XDefaultDepth(voidptr, int) int +fn C.XWhitePixel(voidptr, int) u64 +fn C.XCreatePixmap(voidptr, u64, u32, u32, u32) u64 +fn C.XCreateGC(voidptr, u64, u64, voidptr) voidptr +fn C.XSetForeground(voidptr, voidptr, u64) int +fn C.XFillRectangle(voidptr, u64, voidptr, int, int, u32, u32) int +@[typedef] +struct C.XImage {} + +fn C.XGetImage(voidptr, u64, int, int, u32, u32, u64, int) &C.XImage +fn C.XGetPixel(&C.XImage, int, int) u64 +fn C.XDestroyImage(&C.XImage) int +fn C.XFreeGC(voidptr, voidptr) int +fn C.XFreePixmap(voidptr, u64) int +fn C.XCloseDisplay(voidptr) int + +fn display_pixel() { + display := C.XOpenDisplay(unsafe { nil }) + assert display != unsafe { nil } + defer { C.XCloseDisplay(display) } + screen := C.XDefaultScreen(display) + pixmap := C.XCreatePixmap(display, C.XRootWindow(display, screen), 1, 1, + u32(C.XDefaultDepth(display, screen))) + defer { C.XFreePixmap(display, pixmap) } + gc := C.XCreateGC(display, pixmap, 0, unsafe { nil }) + defer { C.XFreeGC(display, gc) } + white := C.XWhitePixel(display, screen) + C.XSetForeground(display, gc, white) + C.XFillRectangle(display, pixmap, gc, 0, 0, 1, 1) + image := C.XGetImage(display, pixmap, 0, 0, 1, 1, ~u64(0), C.ZPixmap) + assert image != unsafe { nil } + defer { C.XDestroyImage(image) } + assert C.XGetPixel(image, 0, 0) == white + println('X server pixmap round-trip passed.') +} + +fn main() { + zero := unsafe { C.malloc(0) } + assert zero != unsafe { nil } + unsafe { C.free(zero) } + mut x, mut y := 0, 0 + mut w, mut h := u32(0), u32(0) + assert C.XParseGeometry(c'=17x9-2+3', &x, &y, &w, &h) & C.XNegative != 0 + assert x == -2 && y == 3 && w == 17 && h == 9 + mapping := C.FontEncMapFind(c'iso8859-15', C.FONT_ENCODING_UNICODE, 0, 0, unsafe { nil }) + assert mapping != unsafe { nil } + assert C.FontEncRecode(0xa4, mapping) == 0x20ac + mut input := u32(0xff3388cc) + mut output := u32(0) + src := C.pixman_image_create_bits(C.PIXMAN_a8r8g8b8, 1, 1, &input, 4) + dst := C.pixman_image_create_bits(C.PIXMAN_a8r8g8b8, 1, 1, &output, 4) + assert src != unsafe { nil } && dst != unsafe { nil } + defer { C.pixman_image_unref(src) } + defer { C.pixman_image_unref(dst) } + C.pixman_image_composite32(C.PIXMAN_OP_SRC, src, unsafe { nil }, dst, 0, 0, 0, 0, 0, 0, 1, 1) + assert output == input + println('Xlib geometry, Latin-9 font mapping and Pixman pixel copy passed.') + if os.args[1..] == ['--display'] { + display_pixel() + } +} -- 2.56.1