1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
// plat -- the platform layer: one module per OS with the same functions [src/plat]
//
// process: entry point (calls the app's jfgui_main), args(), arg_value(name), exit(code),
// std_start() (feature std: the start of a program with std, from its fn main),
// write_stdout / write_stderr, time_us(), sleep_ms(ms), date()
// environment: env(name) (= getenv), setenv(name, Some / None), config_dir(), temp_dir(), cwd()
// folders: user_dir(DIR_DOCUMENTS ..) (desktop, documents, downloads, pictures, music,
// videos: Known Folders / XDG user dirs), log_dir() (dirs.rs)
// files: read_file(path), write_file(path, data) (native: exclusive sibling + rename),
// File::open(path, FO_*) / open_temp(dir) -> read_at / write_at / size / sync,
// file_exists(path) (0 / 1 file / 2 dir), mkdir (with parents), delete, rename,
// trash (into the recycle bin / freedesktop trash; trash.rs),
// file_exists_checked(path) (Some(0) missing, None error), FileLock::acquire(path),
// AtomicFile::create(path) -> write_at / commit (write_file in pieces),
// dir_list(path, f(name, is_dir, size_lo)) -- checked against the app's
// permissions first (guarded.rs); a refused path behaves like a missing one
// policy: the app's permissions (apps/NAME/PERMISSIONS): install, the fs / process /
// url / plugin / print checks, grants for the user's files (policy.rs)
// boot: the app's name, app:// and its manifest at start-up (rt::main! through
// rt::boot; ui::main! calls the parts itself) (boot.rs)
// vfs: "scheme://path" names in every file function: app:// (the bundled assets),
// config:// data:// cache:// logs:// (the app's folders), documents:// and the
// other user folders, mem://, mounted providers
// (MemFs, DirFs, Overlay, Sub, Bundle); data_dir(), cache_dir() (vfs.rs);
// display_name(path); Android content:// (ContentFs, DocHost) (content.rs);
// persistent_name(path): a chosen file's name that lasts across restarts (Flatpak's
// documents portal: linux_docs.rs)
// secret: secret_set / secret_get / secret_delete / secret_available: passwords, tokens and
// keys in the system's store (Credential Manager + DPAPI, Secret Service; needs
// `secrets` in the manifest) (secret.rs)
// instance: claim(app) -> Primary / Forwarded / Alone, take() -> requests of later starts
// (the app's single instance; pipe / abstract socket per user) (instance.rs)
// spell: sys_spell_find / sys_spell_languages, SysSpeller (check, suggest): the system's
// spell checker (Windows ISpellChecker; elsewhere none) (spell.rs)
// tray: tray_set / tray_remove (the symbol in the notification area, its menu), notify /
// notify_close (system notifications), tray_take() -> events (tray.rs)
// power: inhibit(reason, INHIBIT_SUSPEND | INHIBIT_IDLE) -> Option<Inhibit> (no standby /
// screen saver while the guard lives), inhibited() (power.rs)
// autostart: autostart_set(on, args) / autostart_get() / autostart_entry() (Run key, XDG
// autostart, Background portal, MSIX StartupTask; needs `autostart` in the manifest)
// (autostart.rs)
// pkg: packaged() (MSIX, Flatpak, AppImage, Snap or a plain program), msix_updates (App
// Installer), FlatpakMonitor / flatpak_spawn_latest (the Flatpak portal),
// restart_appimage (pkg.rs)
// taskbar: taskbar_progress / taskbar_badge / taskbar_tasks (the taskbar button: progress,
// overlay / count, jump list; ITaskbarList3, Unity LauncherEntry), app_user_model_id
// / set_app_user_model_id (Windows: the app's explicit id) (taskbar.rs)
// assoc: assoc_register / assoc_conflicts / assoc_unregister: the app's PACKAGE file types
// and URL schemes for this program without a setup (HKCU\Software\Classes; .desktop,
// shared-mime-info, mimeapps.list), file_uri_path (assoc.rs)
// recent: recent_add / recent_list / recent_remove / recent_clear: the system's recent files
// (SHAddToRecentDocs and the jump list; recently-used.xbel) (recent.rs)
// audio: Stream (open / open_fill, write, start / pause / stop, volume, latency, the default
// device followed), play / play_file (WAV, Ogg Vorbis), sound(SOUND_*): the system's
// sounds (WASAPI, PulseAudio protocol, WebAudio, AAudio) (audio.rs)
// screen: monitors() (rect, work area, dpi, refresh, primary; SET_MONITORS), pick_start (a
// pixel's colour anywhere), capture_start (pictures of the screen) (screen.rs)
// hotkey: hotkey_register / hotkey_unregister / hotkey_take: global shortcuts (RegisterHotKey,
// XGrabKey, the GlobalShortcuts portal) (hotkey.rs)
// threads: thread_spawn(stack, f) -> Thread (join), thread_yield(), Sem (post / wait),
// wake() (any thread: E_WAKE on the UI thread), wait_events(deadline, on_event)
// (headless), cpu_count(), mem_total()
// pool: thr_init / thr_count / thr_shutdown / thr_self, parallel_for, Job (pool.rs)
// task: async execution: Executor (ui() in the event loop, new() / block_on), Task,
// spawn_blocking (a pool for blocking work), sleep, CancelToken, Progress, join /
// select (task.rs)
// aio: files without blocking: read_file / write_file / copy_file with progress and
// cancellation, Reader / Writer chunk by chunk (AtomicFile underneath) (aio.rs)
// sync: Mutex, Condvar, RwLock, channel (futex / WaitOnAddress) (sync.rs)
// rand: fill_random, random_bytes, random_u64 (the OS CSPRNG) (rand.rs)
// net: TcpListener, TcpStream, UdpSocket, SocketAddr, resolve (net.rs)
// fs: stat / lstat / read_dir / links / set_times / free_space /
// write_file_private / local_zone_id (fs.rs)
// cpu: cpu_features() (CPU_*), cpu_brand() (cpu.rs)
// crash: crash_hook(Some(f)): f(&CrashInfo) before exit code 3 -- hardware faults (VEH /
// signals, the stderr line of ASMLIB) and panics; crash_test() crashes on purpose
// windows: the window-indexed API of the assembly (win_create / win_show / win_present /
// wait ..., popups, clipboard, drops, pen, cursors; consts.rs, evq.rs, pwin0.rs)
// dnd: drag and drop between programs: DragData (files, text, URLs, HTML, image),
// the drop target hook, the pending drop, drag_start (dragging out) (dnd.rs)
// (plat-shared) print(job) + page layout / PDF writer (print.rs; win_print.rs,
// linux_print.rs), plugin libraries lib_open / lib_sym / lib_close / lib_seg and
// the crash guard guard_call / guard_run / guard_tag (plib.rs; win_lib.rs,
// linux_elfload.rs, linux_guard.rs), monitor_icc / monitor_key (icc.rs), the
// portal's file dialog / OpenURI / Print (linux_portal.rs)
// (jxl-module) the loadable JPEG XL writer module: jxlenc_set_path / jxlenc_ready /
// jxlenc_encode (modhost.rs; the records in modabi.rs)
//
// The layer knows events, pixel rows, files and threads only -- no UI, no gfx. One of the
// four crates that may contain `unsafe` (rt, simd, plat, plugin); nothing unsafe leaves it.
extern crate std;
extern crate alloc;
/// Owned native child processes with pipes and process-tree lifetime management.
/// Mutex, Condvar, RwLock and bounded channels for worker threads.
/// TCP and UDP sockets (IPv4 / IPv6) with timeouts, numeric names.
/// Metadata, directory listings, links, times, free space, owner-only files, the local zone.
/// Running as a system service (Windows service control manager, systemd units).
/// Changes below folders as they happen (continuous data protection).
/// The operating system's trusted certificate authorities (TLS clients of public servers).
pub use *;
use String;
pub use exit; pub use ;
// a program with std (feature std): its exit and the symbol its fn main calls
pub use ;
pub use std_start;
// the library's version (the root Cargo.toml, docs/VERSIONING.md); the app's own: rt::app_version!()
pub use ;
pub use *;
/// The app's permissions (apps/NAME/PERMISSIONS) and their checks.
/// OS sandbox derived from the manifest: Landlock + seccomp (Linux), mitigation policies (Windows).
/// What build_rs.py builds into a program (name, assets, manifest), set up at start-up.
/// One file namespace: app://, config://, data://, cache://, mem:// and mounted providers.
pub use display_name;
/// The documents of other apps as files: Android's content:// names (the name logic on all
/// platforms, tested with a host in memory).
/// Passwords, tokens and keys in the system's secret store (Credential Manager, Secret Service).
/// One running instance per app and user; later starts hand over their arguments.
/// The system's spell checker (Windows ISpellChecker); Hunspell files are the spell crate's.
/// The app's symbol in the notification area and system notifications.
/// Keeping the computer awake: no standby, no screen saver while a guard lives.
pub use ;
/// Android: while `on`, the back key reaches the app as Esc (a page of the app goes back, a popup
/// closes; `UIC_ESCAPE` when nothing took it) instead of ending the activity. Elsewhere nothing:
/// there Esc is a key of its own
/// Android: the runtime ended (ui.quit): the activity goes and its process with it, a new start
/// needs a new runtime. Elsewhere nothing: there the main loop ends the program
/// (ui touch.rs) the host's main pointer is a finger at the start (Android; a phone's browser:
/// `pointer: coarse`; a Windows tablet in slate posture): no scroll bars from the first frame on; the
/// next pointer event decides again
/// (ui touch.rs) a text field got the focus through a finger (show) or lost it: the on-screen keyboard
/// of window w. Windows: InputPane; Wayland: text-input follows the focus by itself (the compositor's
/// keyboard); elsewhere the host's job (Android, the browser) or nothing there is to ask (X11)
/// (ui touch.rs) a finger's gesture reached a widget (a tap, a drag), or it did not (a scroll):
/// Android asks after the finger lifted whether the keyboard has to follow
/// (ui touch.rs) a finger rested long enough: the host's feedback (Android: performLongClick)
/// where a window the user moves may be (x, y; w its width; screen the area's size; dpi for the
/// margin): the title bar stays on the screen, at least 48 DIP of the window at each side
/// Starting the app when the user logs in (Run key, XDG autostart, Background portal, an MSIX
/// package's StartupTask).
/// The package the program runs from (MSIX, Flatpak, AppImage, Snap) and what its package
/// system offers for updates (App Installer, the Flatpak portal).
// the few WinRT calls (StartupTask, Package) through raw COM
pub use ;
/// The app's taskbar / dock button: progress, a badge, the jump list's tasks.
/// The app's file types and URL schemes registered without a setup (developer builds).
/// The system's list of recently used files (jump lists, recently-used.xbel).
pub use ;
/// Sound output: streams, short sounds from memory or files, the system's own sounds.
/// The monitors, a pixel's colour anywhere on the screen, pictures of the screen.
pub use ;
/// Global keyboard shortcuts: chords that reach the app while another program has the keyboard.
pub use ;
// what the desktop integration shares on Linux (the session-bus link, the .desktop id)
// the damage regions of the X11 / Wayland presents
// the log: levels, a ring for crash reports, stderr, a rotating file
pub use *;
// the accessibility tree for screen readers (AT-SPI2, UI Automation)
// the system settings the UI follows (theme, accent, contrast, motion, text scale, timing)
pub use ;
// the user's languages and regional format (BCP 47 tags)
pub use ;
pub use *;
// the user's folders (documents, downloads, pictures ...) and the folder of logs
pub use *;
// moving files to the trash instead of deleting them
pub use *;
/// Async execution: executors in the event loop and for block_on, a pool for blocking work,
/// timers, cancellation, progress, joins.
/// Files without blocking the caller: chunked reads, atomic writes and copies with progress and
/// cancellation.
pub use *;
pub use *;
pub use *;
// a managed program on the runtime another application ships; values of HKLM
pub use *;
pub use *;
/// Host-driven boundary shared by browser workers and the native Android adapter.
pub use *;
// drag and drop between programs (the shared part; win_dnd.rs, linux_x11_dnd.rs, linux_wl_clip.rs)
pub use *;
// clipboard_platform: reusable rich clipboard framing.
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// plat-shared: printing (print.rs + win_print.rs / linux_print.rs), plugin libraries and the
// crash guard (plib.rs + win_lib.rs / linux_elfload.rs, linux_guard.rs)
pub use *;
pub use *;
// jxl-module: loadable modules, the host side (the JPEG XL writer jxlenc; modhost.rs, modabi.rs)
pub use *;
/// one platform event (the EV_* record): type, button, modifiers, window index (0 = the
/// main window), position (px; E_RESIZE: size), data
/// the pixels to present: rows of 32-bit B, G, R, x
// ---- files
pub const FO_READ: u32 = 0; // existing file, read only
pub const FO_WRITE: u32 = 1; // create or truncate, read + write
pub const FO_RW: u32 = 2; // open or create (contents kept), read + write
/// a date and time (date(): Windows local time, Linux UTC)
/// The name under which a file the user chose stays reachable after a restart, for a list of
/// recent files or a session (ui.recent_add keeps this one). A document of Flatpak's
/// documents portal (`$XDG_RUNTIME_DIR/doc/ID/NAME`) is asked for its lasting form
/// (`Documents.Add`, persistent; linux_docs.rs): `<mount>/<ID>/<NAME>` of the portal's answer.
/// Where the portal reaches the real file that is a lasting document of it; for a document
/// of its own mount the portal answers that document's own ID, so inside the sandbox the name
/// stays as the dialog gave it (the portal's file dialog makes lasting documents, "Open with"
/// session ones). Every other name comes back unchanged: Android keeps the grant of a
/// `content://` document and the browser the handle of a `/handles/` file when the user
/// chooses it, and OS paths need nothing. The name must be readable under the app's
/// permissions.
/// The answer of a system file dialog that answers later (file_dialog -> FD_PENDING: only
/// Android's picker and the browser's; web.rs): None while it is open, then once (1 chosen /
/// 0 not, index, path).
/// the argument after `name` on the command line (argument 0, the program, is skipped) [arg_value]
/// the library's options that take a value (`--size 800x600`): a program whose plain
/// arguments are files skips the value after these
pub const VALUE_OPTS: & = &;
// ---- crashes (docs/modules/CRASH.md)
pub use ;
/// f(&CrashInfo) runs in the crash handler, after the stderr line, before exit code 3; also
/// for panics (CK_PANIC) [plat_crash_hook]
/// a deliberate crash for tests: `mov eax, 16` (5 bytes), then a 4-byte write to address 0x10
/// -- the faulting instruction is at crash_test + 5
pub extern "C" !
/// (plat-win) crash_test called from a known place (call rel32): the return address
/// crash_test_caller + 5 must be among CrashInfo::frames (plattest's call chain check)
pub extern "C" !
/// Deliberate trap for browser runtime diagnostics.
pub extern "C" !
/// Deliberate trap through the compatibility caller API.
pub extern "C" !
/// Deliberate termination on Android, where no hardware exception translator is installed.
pub extern "C" !
/// Compatibility caller for the Android diagnostic termination.
pub extern "C" !