Files
metal2vulkan/docs
Anees Iqbal 3a7568d5b4 A device can be made to open no dynamic library's file; only regular files are read
A pipeline creation loads, for each install name its stage's libraries name, the file that name
names (dynamic_library.rs, `stage_with_dependencies`), and `new_dynamic_library_with_url` and a
binary archive's descriptor read the file they name. Where the library bytes come from another
party (a guest's metallib in a virtual GPU), its install names name any host path: `/dev/zero` grew
`read_to_end` until the process ran out of memory, a FIFO blocked the creating thread for ever,
opening a device file could act on the device, and any host file that parses as a dynamic metallib
linked into the pipeline.

- `DeviceOptions::load_no_dynamic_library_file` (and `RawDevice`'s), off by default: the device
  opens no file a library's install names name and refuses `new_dynamic_library_with_url`
  (`DynamicLibraryError::NoFileLoading`, new). A creation links only the libraries its function
  descriptors give (`libraries.preloaded`, `libraries.loaded` by install name); an install name
  `loaded` lacks loads nothing, so a creation whose import survives specialization fails
  `Compile(NeedsInput(DynamicLibrary))`, as Metal's does for a file it cannot load.
- Without the switch, every such read goes through `container::read_file`: a regular file alone,
  looked at before it is opened, opened `O_NONBLOCK | O_NOCTTY` and looked at again through the
  handle, read once no further than its length when opened, a length the process cannot hold
  refused rather than allocated. A FIFO, device or directory loads nothing as an install name and
  is `InvalidFile` for `new_dynamic_library_with_url` and a binary archive.

The stage_with_dependencies call sites (compute, render, mesh, tile creation) pass the device.
Docs: the field's and variant's doc comments, the runtime README's options table, docs/API.md's
accepted differences. api_signatures.tsv blessed (two fields, one variant); docs/REFUSALS.md
regenerates unchanged.

Tests, each failing without the change (a control commit neutralizing the gate and the
regular-file read, run once):
- tests::binary_archive::a_path_of_no_regular_file_is_no_archive_and_is_not_waited_on (CPU):
  a FIFO and /dev/zero are InvalidFile, each read bounded at 30 s.
- runtime_lane::dynamic_libraries::an_install_name_of_no_regular_file_loads_nothing_and_waits_on_nothing
  (lavapipe): a FIFO's and /dev/zero's install names load nothing, the creation is refused
  NeedsInput(DynamicLibrary), new_dynamic_library_with_url is InvalidFile, each bounded at 60 s.
- runtime_lane::dynamic_libraries::a_device_that_loads_no_file_links_only_the_libraries_it_is_given
  (lavapipe): with the switch, a client linked against A's real file is refused, A preloaded or
  not; given A in `libraries.loaded` it links A's values; new_dynamic_library_with_url is refused.
2026-11-12 07:02:06 -08:00
..