test/runtime/spin.rad 1.6 KiB raw
1
//! Scheduled runtime compilation and an independent window witness.
2
export mod cases;
3
export mod abi;
4
export mod sys;
5
6
/// Compile a package twice or record progress during another domain's load.
7
@default fn main(env: *abi::Env) {
8
    // The arguments Page holds the binary package capability, its byte count,
9
    // the shared progress Page capability, and the actor index selected by the
10
    // parent.
11
    let words = try! sys::pageWords(abi::Handle(env.args));
12
    let source = abi::Handle(words[0]);
13
    let length = words[1];
14
    let progress = try! sys::pageWordsMut(abi::Handle(words[2]));
15
    let actor = words[3] as u32;
16
    if actor == cases::WITNESS {
17
        assert progress[cases::RETRY_LOADER] == cases::STARTED;
18
        let mut busy = false;
19
        try sys::imageLoad(abi::Handle(0), source, 0, length) catch error {
20
            assert error == abi::Error::Busy;
21
            set busy = true;
22
        };
23
        assert busy;
24
        set progress[cases::WITNESS] = cases::STARTED;
25
        return;
26
    }
27
    set progress[actor] = cases::STARTED;
28
    let image = try sys::imageLoad(abi::Handle(0), source, 0, length) catch error {
29
        set progress[actor] = cases::LOAD_ERROR_BASE + error as u64;
30
        return;
31
    };
32
    let info = try! sys::queryImage(image);
33
    let repeated = try sys::imageLoad(abi::Handle(0), source, 0, length) catch error {
34
        set progress[actor] = cases::REPEAT_ERROR_BASE + error as u64;
35
        return;
36
    };
37
    assert (try! sys::queryImage(repeated)).id == info.id;
38
    set progress[cases::IMAGE_ID] = info.id;
39
    set progress[actor] = cases::COMPLETE;
40
}