diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3efba0..9c1faec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -281,27 +281,32 @@ jobs: run: | set -euo pipefail cd examples/std - mcpp build --target x86_64-uefi - EFI=$(find target -name "std.efi" | head -1) - rm -f std.img - mkfs.vfat -C -n OKSTD std.img 65536 > /dev/null - printf '@echo -off\r\nfs0:\r\nstd.efi --shell "a b" c "two words here"\r\n' > startup.nsh - mcopy -i std.img "$EFI" ::/std.efi - mcopy -i std.img startup.nsh ::/startup.nsh - set +e - timeout 180 qemu-system-x86_64 -machine q35 -m 1024 -nographic -no-reboot \ - -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \ - -drive if=virtio,format=raw,file=std.img -device virtio-rng-pci \ - -device isa-debug-exit,iobase=0xf4,iosize=0x04 -net none < /dev/null > std.log 2>&1 - status=$? - set -e - tr -d '\000' < std.log | sed 's/\x1b\[[0-9;]*[A-Za-z]//g' | grep -v '^Press ESC' | tail -30 - if grep -qi "secure randomness" std.log; then - echo "::error::the C library's allocator found no secure random source"; exit 1 - fi - grep -q "all held" std.log - [ "$status" -eq 85 ] || { echo "::error::QEMU ended with $status, not 85 (42 << 1 | 1)"; exit 1; } - mtype -i std.img ::/okstd/written.txt | tr -d '\r' | grep -qx "written through the C library" + # Both profiles (0.11.2): the release profile replaced a loop over a UTF-16 name by the + # C library's `wcslen', and the dev profile showed nothing of it. + for profile in "" "--release"; do + rm -rf target + mcpp build $profile --target x86_64-uefi + EFI=$(find target -name "std.efi" | head -1) + rm -f std.img + mkfs.vfat -C -n OKSTD std.img 65536 > /dev/null + printf '@echo -off\r\nfs0:\r\nstd.efi --shell "a b" c "two words here"\r\n' > startup.nsh + mcopy -i std.img "$EFI" ::/std.efi + mcopy -i std.img startup.nsh ::/startup.nsh + set +e + timeout 180 qemu-system-x86_64 -machine q35 -m 1024 -nographic -no-reboot \ + -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \ + -drive if=virtio,format=raw,file=std.img -device virtio-rng-pci \ + -device isa-debug-exit,iobase=0xf4,iosize=0x04 -net none < /dev/null > std.log 2>&1 + status=$? + set -e + tr -d '\000' < std.log | sed 's/\x1b\[[0-9;]*[A-Za-z]//g' | grep -v '^Press ESC' | tail -30 + if grep -qi "secure randomness" std.log; then + echo "::error::the C library's allocator found no secure random source"; exit 1 + fi + grep -q "all held" std.log + [ "$status" -eq 85 ] || { echo "::error::QEMU ended with $status, not 85 (42 << 1 | 1)"; exit 1; } + mtype -i std.img ::/okstd/written.txt | tr -d '\r' | grep -qx "written through the C library" + done # --------------------------------------------------------------------------- # The cross-compilation is performed FROM three systems, not only from Linux. diff --git a/README.md b/README.md index ee04997..ffb0ceb 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,12 @@ or closes a part in which they do not, `^` takes the next character as it is. 0.10.0 divided the load options at spaces alone, so `"a b"` arrived as two arguments with their quotes. Firmware that gave none gives one empty name. +From 0.11.2 the implementation is compiled with `-fno-builtin`. On the release +profile the compiler replaced the loop that measures a UTF-16 name by a call of +`wcslen`, which the C library above defines for a `wchar_t` of thirty-two bits: +a listing gave `f2.` for `f2.txt`, and the firmware refused a rename +(`EFI_ACCESS_DENIED`). The C library example runs on both profiles in CI. + From 0.11.1 the arguments after the name are divided from the load options where the Shell started the program too. The Shell of edk2 9.2.4 was measured to hand over a shortened argument where it has ten or more characters and a run of three diff --git a/examples/std/src/main.cpp b/examples/std/src/main.cpp index 3456c24..ab7bac5 100644 --- a/examples/std/src/main.cpp +++ b/examples/std/src/main.cpp @@ -42,6 +42,19 @@ int main(int argc, char** argv) { check(line == "written through the C library", "a file is written and read back"); check(fs::file_size("/okstd/written.txt") == 30, "its size"); + // A listing gives whole names and a file is renamed (0.11.2): both measure a UTF-16 name, and + // on the release profile the measuring loop was replaced by the C library's `wcslen'. + { std::ofstream note("/okstd/note.txt"); note << "n\n"; } + std::error_code ec; + fs::rename("/okstd/note.txt", "/okstd/moved-note.txt", ec); + check(!ec, "a file is renamed beneath a directory"); + std::vector beneath; + for (const auto& e : fs::directory_iterator("/okstd")) beneath.push_back(lower(e.path().filename().string())); + std::ranges::sort(beneath); + std::println(" beneath okstd: {}", beneath); + check(beneath == std::vector{"moved-note.txt", "written.txt"}, "a listing gives each name whole, with its extension"); + fs::remove("/okstd/moved-note.txt", ec); + std::random_device rd; const auto a = rd(), b = rd(), c = rd(); check(!(a == b && b == c), "std::random_device draws on the firmware's source"); diff --git a/mcpp.toml b/mcpp.toml index 6868f86..c96fd79 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -15,7 +15,7 @@ [package] namespace = "mcpplibs" name = "openkal-uefi" -version = "0.11.1" +version = "0.11.2" description = "An implementation of openkal on UEFI Boot Services, for applications the firmware loads before an operating system exists" license = "Apache-2.0" @@ -55,10 +55,18 @@ standalone = { defines = ["OKUEFI_STANDALONE"] } # this implementation defines `__chkstk', which a frame larger than a page otherwise calls (a name # of openkal.fs is converted in a buffer of 2 KiB on the stack). The example's board states it for # the whole program; a row that does not still links this implementation. +# +# No loop is replaced by a call (0.11.2), which is what `-fno-builtin' is for. The row's compiler +# reads `wchar_t' as sixteen bits and replaces a loop that measures a UTF-16 name by a call of +# `wcslen'; the C library above this implementation is built with a `wchar_t' of thirty-two bits, +# and its `wcslen' answered another length. Measured on the release profile: a listing gave +# `f2.' for `f2.txt', and a rename, whose new name is measured the same way, was refused by the +# firmware (EFI_ACCESS_DENIED). The dev profile does not optimise the loop and showed neither. [build] flags = [ { glob = "src/**", cxxflags = ["-fno-exceptions", "-fno-rtti", "-fno-stack-protector", "-fno-asynchronous-unwind-tables", - "-mno-stack-arg-probe"] }, + "-mno-stack-arg-probe", + "-fno-builtin"] }, ]