oscall 0.1.1

Low-level cross-platform interface to operating system services: files, memory mapping, networking and more, with no libc on Linux
Documentation
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
name: CI

on:
  push:
    # wip/** branches are work in progress pushed to be tested on the
    # platforms that cannot be tested locally (macOS, Windows, wasmtime)
    # before it lands; the jobs scripts/check.sh covers are skipped there.
    branches: [master, "wip/**"]
  pull_request:

# A newer push to the same branch (or PR) supersedes this run: cancel the
# older one instead of queueing every intermediate commit.
concurrency:
  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
  # Not on master: with frequent pushes no full run would ever finish.
  cancel-in-progress: ${{ github.ref_name != 'master' }}

permissions:
  contents: read

# Every job skips release-plz's pull request: it only changes the version and
# the changelog, of commits that were tested when they reached master, and
# its runs would compete for the macOS runners.

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # Every operating system on the runners' own architecture.
    name: Test & lint (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest # Linux x86_64
          - ubuntu-24.04-arm # Linux aarch64
          - macos-latest # macOS aarch64
          - macos-15-intel # macOS x86_64
          - windows-latest # Windows x86_64
          - windows-11-arm # Windows aarch64
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Cache
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.os }}

      - name: Format
        if: matrix.os == 'ubuntu-latest' # formatting is platform-independent
        run: cargo fmt --all --check

      - name: Clippy (all features, warnings denied)
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Clippy (no_std, warnings denied)
        run: cargo clippy --all-targets --no-default-features -- -D warnings

      # io_uring works on the Linux runners: its tests must not all skip
      # there unnoticed (tests/io_linux.rs).
      - name: Test (all features)
        run: cargo test --all-features
        env:
          OSCALL_REQUIRE_IO_URING: ${{ runner.os == 'Linux' && '1' || '' }}

      - name: Test (no_std)
        run: cargo test --no-default-features
        env:
          OSCALL_REQUIRE_IO_URING: ${{ runner.os == 'Linux' && '1' || '' }}

  cross:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    # The architectures the runners don't have natively. Linux tests are
    # static musl binaries linked with rust-lld (no cross toolchain needed);
    # foreign ones run under qemu-user through binfmt_misc.
    name: Test (${{ matrix.name || matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
          # 32-bit x86 runs natively on x86_64.
          - { os: ubuntu-latest, target: i686-unknown-linux-musl }
          - { os: ubuntu-24.04-arm, target: aarch64-unknown-linux-musl }
          # 32-bit ARM twice. Under qemu-user, which is what most people
          # who run such a program on another machine have; and natively
          # on the arm64 runner, whose processor and kernel run 32-bit
          # programs (measured: Neoverse-N2, CONFIG_COMPAT): there the
          # system calls are the kernel's own, `clone3` included, which
          # qemu-user does not have.
          - { os: ubuntu-latest, target: armv7-unknown-linux-musleabihf, qemu: arm }
          - os: ubuntu-24.04-arm
            target: armv7-unknown-linux-musleabihf
            name: armv7-unknown-linux-musleabihf, on an aarch64 kernel
          - { os: ubuntu-latest, target: riscv64gc-unknown-linux-musl, qemu: riscv64 }
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Cache
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      - name: Set up qemu-user
        if: matrix.qemu
        uses: docker/setup-qemu-action@v3
        with:
          platforms: ${{ matrix.qemu }}

      - name: Link static musl binaries with rust-lld
        if: runner.os == 'Linux'
        run: |
          target_env=$(tr 'a-z-' 'A-Z_' <<<"${{ matrix.target }}")
          echo "CARGO_TARGET_${target_env}_LINKER=rust-lld" >> "$GITHUB_ENV"
          # Not every musl target is static and self-contained by default.
          echo "CARGO_TARGET_${target_env}_RUSTFLAGS=-C target-feature=+crt-static -C link-self-contained=yes" >> "$GITHUB_ENV"

      # Doc-tests are skipped: the static linking flags do not reach rustdoc,
      # and the native jobs run them.
      # Natively io_uring works and its tests must not skip; qemu-user does
      # not have it.
      - name: Test (all features)
        run: cargo test --lib --tests --all-features --target ${{ matrix.target }}
        env:
          OSCALL_REQUIRE_IO_URING: ${{ !matrix.qemu && '1' || '' }}

      - name: Test (no_std)
        run: cargo test --lib --tests --no-default-features --target ${{ matrix.target }}
        env:
          OSCALL_REQUIRE_IO_URING: ${{ !matrix.qemu && '1' || '' }}

  fullrust:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    # Libc-free static binaries built with fullrust
    # (https://github.com/KarpelesLab/fullrust), where target_os = "fullrust"
    # and cfg(unix) is false. aarch64 and armv7 run under the image's qemu-user.
    name: fullrust (${{ matrix.target }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-fullrust
          - aarch64-unknown-linux-fullrust
          - i686-unknown-linux-fullrust
          - armv7-unknown-linux-fullrusteabihf
    steps:
      - uses: actions/checkout@v7

      # Doc-tests are skipped: the fullrust toolchain ships no rustdoc.
      - name: Test (all features)
        uses: KarpelesLab/fullrust@master
        with:
          command: test
          target: ${{ matrix.target }}
          no-ecosystem: true
          args: --lib --tests --all-features

      - name: Test (no_std)
        uses: KarpelesLab/fullrust@master
        with:
          command: test
          target: ${{ matrix.target }}
          no-ecosystem: true
          args: --lib --tests --no-default-features

  privileged:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # What the other jobs cannot do for want of privilege, in a container
    # that has it all (root with every capability, namespaces, a cgroup
    # hierarchy to write, no system call filter): a child created in a
    # cgroup, with `clone3` and without, what root alone may do with
    # namespaces, identities, capabilities and mounts. There, a test that
    # skips fails. x86_64 and i686 (musl and fullrust) on one runner,
    # aarch64 and armv7 on the other. scripts/check.sh runs the same
    # script, but not on aarch64: the job is not skipped on wip/** branches.
    name: Privileged container (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            targets: x86_64-unknown-linux-musl, i686-unknown-linux-musl
          - os: ubuntu-24.04-arm
            targets: aarch64-unknown-linux-musl, armv7-unknown-linux-musleabihf
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.targets }}

      - name: Cache
        uses: Swatinem/rust-cache@v2
        with:
          key: privileged-${{ matrix.os }}

      - name: Test in a privileged container
        run: scripts/privileged.sh

  vm:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # The same tests on a kernel of the architecture itself, in a virtual
    # machine (qemu-system): the only place where riscv64 and riscv32 have
    # `clone3`, namespaces, cgroups and system call filters, which
    # qemu-user does not emulate; and 32-bit ARM on a 32-bit kernel. The
    # job builds a kernel (kept in a cache) and depends on kernel.org, on
    # Debian's qemu and, for riscv32, on nightly: it reports, and does not
    # block.
    name: Virtual machine (${{ matrix.arch }})
    runs-on: ubuntu-latest
    continue-on-error: true
    strategy:
      fail-fast: false
      matrix:
        include:
          - { arch: riscv64, toolchain: stable, target: riscv64gc-unknown-linux-musl }
          - { arch: arm, toolchain: stable, target: armv7-unknown-linux-musleabihf }
          # Tier 3: a nightly toolchain builds `std` (scripts/riscv32.sh).
          - { arch: riscv32, toolchain: nightly, components: rust-src }
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
          targets: ${{ matrix.target }}
          components: ${{ matrix.components }}

      - name: Cache the kernel
        uses: actions/cache@v6
        with:
          path: |
            target/vm/kernel-${{ matrix.arch }}
            target/vm/kernel-${{ matrix.arch }}.stamp
          key: vm-kernel-${{ matrix.arch }}-${{ hashFiles('scripts/vm.sh') }}

      - name: Test in a virtual machine
        env:
          OSCALL_NIGHTLY: ${{ matrix.toolchain == 'nightly' && 'nightly' || '' }}
        run: scripts/vm.sh ${{ matrix.arch }}

  windows-x86:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # 32-bit x86 runs natively on the x86_64 Windows runner.
    name: Test (i686-pc-windows-msvc)
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: i686-pc-windows-msvc

      - name: Cache
        uses: Swatinem/rust-cache@v2

      - name: Test (all features)
        run: cargo test --all-features --target i686-pc-windows-msvc

      - name: Test (no_std)
        run: cargo test --no-default-features --target i686-pc-windows-msvc

  wasm:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # WASI preview 1 runs under wasmtime, with the crate directory preopened
    # and a variable in its environment, which is otherwise empty there.
    # The other WebAssembly targets are type-checked and linted only:
    # wasm32-unknown-unknown has no system interface to test.
    name: WebAssembly
    runs-on: ubuntu-latest
    env:
      CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime run --dir=. --env OSCALL_TEST_ENV=wasi
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
          targets: wasm32-wasip1, wasm32-wasip2, wasm32-unknown-unknown

      - name: Install wasmtime
        uses: bytecodealliance/actions/wasmtime/setup@v1

      - name: Cache
        uses: Swatinem/rust-cache@v2

      - name: Test on WASI (all features)
        run: cargo test --all-features --target wasm32-wasip1

      - name: Test on WASI (no_std)
        run: cargo test --no-default-features --target wasm32-wasip1

      - name: Clippy (wasm32-wasip2)
        run: cargo clippy --all-targets --all-features --target wasm32-wasip2 -- -D warnings

      - name: Clippy (wasm32-unknown-unknown, all features)
        run: cargo clippy --lib --all-features --target wasm32-unknown-unknown -- -D warnings

      - name: Clippy (wasm32-unknown-unknown, no_std)
        run: cargo clippy --lib --no-default-features --target wasm32-unknown-unknown -- -D warnings

  check:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    # Targets with no runner and no emulator here: type-check and lint only.
    name: Check (${{ matrix.target }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        target:
          - riscv64gc-unknown-linux-gnu
          - armv7-unknown-linux-gnueabihf
          - arm-unknown-linux-gnueabihf
          - i686-unknown-linux-gnu
          - x86_64-pc-windows-gnu
          - aarch64-pc-windows-gnullvm
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
          targets: ${{ matrix.target }}

      - name: Clippy (all features, warnings denied)
        run: cargo clippy --all-targets --all-features --target ${{ matrix.target }} -- -D warnings

  riscv32:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # 32-bit RISC-V Linux is tier 3: Rust ships no standard library for it,
    # so everything here builds one with a nightly toolchain (-Zbuild-std).
    # Nightly lints and nightly `std` change under it: the job reports, and
    # does not block.
    name: riscv32 Linux (nightly, qemu)
    runs-on: ubuntu-latest
    continue-on-error: true
    env:
      FREESTANDING_FLAGS: -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=static
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust nightly
        uses: dtolnay/rust-toolchain@nightly
        with:
          components: clippy, rust-src

      # Not the runner's own qemu-user (8.2), which does not emulate the
      # socket timeouts of 64-bit time on a 32-bit target, and
      # docker/setup-qemu-action has no riscv32: Debian's static build of
      # qemu 10.
      - name: Install qemu-riscv32
        run: |
          docker run --rm -v "$RUNNER_TEMP":/out debian:trixie-slim sh -ec '
            apt-get update -qq
            apt-get install -y -qq --no-install-recommends qemu-user-static
            cp /usr/bin/qemu-riscv32-static /out/qemu-riscv32'
          sudo install "$RUNNER_TEMP/qemu-riscv32" /usr/local/bin/qemu-riscv32
          qemu-riscv32 --version

      - name: Clippy (all features, warnings denied)
        run: cargo clippy -Zbuild-std --all-targets --all-features --target riscv32gc-unknown-linux-gnu -- -D warnings

      - name: Clippy (no_std, warnings denied)
        run: cargo clippy -Zbuild-std --all-targets --no-default-features --target riscv32gc-unknown-linux-gnu -- -D warnings

      # No libc and no `std`: the Linux backend alone, natively first.
      - name: Freestanding program (x86_64)
        working-directory: tests/freestanding
        env:
          RUSTFLAGS: ${{ env.FREESTANDING_FLAGS }}
        run: cargo run --target x86_64-unknown-linux-gnu -- "$RUNNER_TEMP"

      - name: Freestanding program (riscv32)
        working-directory: tests/freestanding
        env:
          RUSTFLAGS: ${{ env.FREESTANDING_FLAGS }}
          CARGO_TARGET_RISCV32GC_UNKNOWN_LINUX_GNU_RUNNER: qemu-riscv32
        run: cargo run -Zbuild-std=core --target riscv32gc-unknown-linux-gnu -- "$RUNNER_TEMP"

      # The whole test-suite, as static musl binaries; the script builds musl.
      - name: Test (both feature sets)
        env:
          OSCALL_NIGHTLY: nightly
        run: scripts/riscv32.sh

  msrv:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    name: MSRV (1.95)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust 1.95
        uses: dtolnay/rust-toolchain@1.95

      - name: Check
        run: cargo check --all-targets --all-features