plat/modabi.rs#
Source: lib/plat/modabi.rs
modabi -- the ABI of loadable modules (jxl-module): the records the host (modhost.rs) and a
module (the module runtime modules/modrt, which has a copy of this file) exchange
[jxl-module: no asm]
A module is a no_std cdylib linked against nothing (no imports; built and checked as
build_rs.py's sections jxl-module and "loader checks" say) that exports exactly one function
<name>_module(host: *const HostTable) -> *const ModTable rt::plugin_abi!
(`jxlenc_module` for the JPEG XL writer). The host keeps the module loaded for the rest of
the process; the module keeps the HostTable pointer. Null = the module refuses the host
(another MOD_VERSION). Every function pointer has the plugin ABI (rt::plugin_abi!: win64 on
x86-64, also on Linux; C elsewhere), so the records are the same on Windows and Linux.
Memory: the module's global allocator is the host's (HostTable::alloc / free = the host's
GlobalAlloc with the same Layout), so blocks move between both sides as Vec<u8> raw parts
(JxlReq::rgba to the module, JxlRes to the host) without a copy.
Threads: parallel_for runs item(ctx, index, job) on the host's worker pool (and the calling
thread); thr_count / thr_self are the pool's, so per-thread arrays of the module work as in
the host. A panic of the module ends in HostTable::panic: the host's normal crash report
(stderr "panic: jxlenc: ...", the crash hook, exit code 3); a fault inside the module code
goes to the host's crash handlers like any other.
Version 1. Layouts are asserted below.
/// ModTable::magic ("MODM" little endian)
MOD_MAGIC: u32 = 0x4D44_4F4D
/// the ABI version of this file
MOD_VERSION: u32 = 1
/// ModTable::kind of the JPEG XL writer
MOD_JXLENC: u32 = 1
/// JxlReq::blobs: which of the blobs are present (None vs Some)
JXB_ICC: u32 = 1
JXB_EXIF: u32 = 2
JXB_XMP: u32 = 4
/// JxlReq::test: crash tests of the module (plat::jxlenc_*: jfgui_JXLENC_TEST=panic / fault)
JXT_PANIC: u32 = 1
JXT_FAULT: u32 = 2
type ItemFn = rt::plugin_abi!(fn(ctx: *const c_void, index: usize, job: *const c_void))one item of a parallel loop: item(ctx, index, job)struct HostTablethe host's functions (the module keeps the pointer)size: u32-- size_of::<HostTable>()version: u32-- MOD_VERSIONcpu: u32-- the host's rt::cpu::features() (--simd sse2: 0, the module then uses SSE2 too)threads: u32-- workers of the host's poolalloc: rt::plugin_abi!(fn(size: usize, align: usize, zeroed: u32) -> *mut u8)-- a block ofsizebytes aligned toalignfrom the host's allocator (zeroed != 0: cleared), null when out of memoryfree: rt::plugin_abi!(fn(p: *mut u8, size: usize, align: usize))-- free a block of alloc with its size and alignmentparallel_for: rt::plugin_abi!(fn(count: usize, ctx: *const c_void, item: ItemFn) -> u32)-- item(ctx, i, job) for i in 0..count on the pool; 0 = done, 1 = cancelledjob_cancel: rt::plugin_abi!(fn(job: *const c_void))-- job.cancel() of the job an item gotjob_cancelled: rt::plugin_abi!(fn(job: *const c_void) -> u32)-- job.cancelled()thr_count: rt::plugin_abi!(fn() -> u32)-- the pool's thr_count() / thr_self()thr_self: rt::plugin_abi!(fn() -> usize)yield_now: rt::plugin_abi!(fn())-- give the time slice away (spin locks)log: rt::plugin_abi!(fn(msg: *const u8, len: usize))-- one line on stderr ("<module>: msg")panic: rt::plugin_abi!(fn(msg: *const u8, len: usize) -> !)-- a panic of the module (UTF-8 message): the host's crash report, exit code 3
struct ModTablewhat a module offerssize: u32-- size_of::<ModTable>()version: u32-- MOD_VERSIONmagic: u32-- MOD_MAGICkind: u32-- MOD_JXLENCjxl_encode: rt::plugin_abi!(fn(req: *const JxlReq, res: *mut JxlRes) -> i32)-- the JPEG XL writer: 0 and res filled, or ERR_* (res empty)
struct JxlReqa JPEG XL encode: the samples of img_jxl::writer::image_of and the writer's optionssize: u32-- size_of::<JxlReq>()w: u32h: u32gray: u32-- Px::grayalpha: u32-- Px::alphaeffort: u32quality: u32flags: u32-- IO_FLAGSblobs: u32-- JXB_*: which blobs are presenttest: u32-- JXT_* (0)rgba: *mut u8-- Px::rgba (R, G, B, A per pixel) as Vec raw parts: the module owns it from now onrgba_len: usizergba_cap: usizeicc: *const u8icc_len: usizeexif: *const u8exif_len: usizexmp: *const u8xmp_len: usizecancel: *const u32-- the cancel flag (an AtomicU32), null = none
struct JxlResthe file the writer made, as Vec raw parts (the host owns it from now on)data: *mut u8len: usizecap: usize