|
1 | 1 | # yafl - Portable Fiber/Coroutine Library |
2 | 2 |
|
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | -[](https://codecov.io/gh/libplctag/yafl) |
24 | | - |
25 | | -A portable, low-level C11 fiber/coroutine library derived from Boost.Context, designed to replace the deprecated `ucontext` API. |
| 3 | +## Build Status |
| 4 | + |
| 5 | +| Platform | Status | |
| 6 | +| -------- | ------ | |
| 7 | +| x86_64-pc-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/x86_64-pc-linux-gnu.yml) | |
| 8 | +| aarch64-pc-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/aarch64-pc-linux-gnu.yml) | |
| 9 | +| x86_64-apple-darwin | [](https://github.com/libplctag/yafl/actions/workflows/x86_64-apple-darwin.yml) | |
| 10 | +| aarch64-apple-darwin | [](https://github.com/libplctag/yafl/actions/workflows/aarch64-apple-darwin.yml) | |
| 11 | +| x86_64-pc-windows-msvc | [](https://github.com/libplctag/yafl/actions/workflows/x86_64-pc-windows-msvc.yml) | |
| 12 | +| aarch64-pc-windows-msvc | [](https://github.com/libplctag/yafl/actions/workflows/aarch64-pc-windows-msvc.yml) | |
| 13 | +| x86_64-pc-windows-gnu | [](https://github.com/libplctag/yafl/actions/workflows/x86_64-pc-windows-gnu.yml) | |
| 14 | +| aarch64-pc-windows-gnu | [](https://github.com/libplctag/yafl/actions/workflows/aarch64-pc-windows-gnu.yml) | |
| 15 | +| x86_64-unknown-linux-android | [](https://github.com/libplctag/yafl/actions/workflows/x86_64-unknown-linux-android.yml) | |
| 16 | +| aarch64-apple-ios | [](https://github.com/libplctag/yafl/actions/workflows/aarch64-apple-ios.yml) | |
| 17 | +| arm-unknown-linux-gnueabihf | [](https://github.com/libplctag/yafl/actions/workflows/arm-unknown-linux-gnueabihf.yml) | |
| 18 | +| riscv64-unknown-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/riscv64-unknown-linux-gnu.yml) | |
| 19 | +| mipsel-unknown-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/mipsel-unknown-linux-gnu.yml) | |
| 20 | +| mips64el-unknown-linux-gnuabi64 | [](https://github.com/libplctag/yafl/actions/workflows/mips64el-unknown-linux-gnuabi64.yml) | |
| 21 | +| powerpc64le-unknown-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/powerpc64le-unknown-linux-gnu.yml) | |
| 22 | +| s390x-ibm-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/s390x-ibm-linux-gnu.yml) | |
| 23 | +| sparc64-unknown-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/sparc64-unknown-linux-gnu.yml) | |
| 24 | +| powerpc-unknown-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/powerpc-unknown-linux-gnu.yml) | |
| 25 | +| i386-unknown-linux-gnu | [](https://github.com/libplctag/yafl/actions/workflows/i386-unknown-linux-gnu.yml) | |
| 26 | + |
| 27 | +[](https://libplctag.github.io/libyafl/coverage/index.html) |
| 28 | + |
| 29 | +A portable, low-level C11 fiber/coroutine library derived from Boost.Context. |
| 30 | + |
| 31 | +## Why Another Fiber Library? |
| 32 | + |
| 33 | +I wanted to use coroutines/fibers for another project and searched on GitHub and elsewhere and did not find anything that was: |
| 34 | + |
| 35 | +- Portable across many OSes, architectures and compilers. Aiming for RTOS environments as well. |
| 36 | +- Every release tested across a matrix of architectures and operating systems and compilers. |
| 37 | +- Only C11 and assembly. |
| 38 | +- CMake build system or easy creation of CMake build configuration. |
| 39 | +- Minimal functionality. Just fibers. |
| 40 | +- Support for guard pages etc. on operating systems that support them and malloc on platforms that do not. |
| 41 | +- The ability to measure stack usage. This is critical for embedded projects. |
| 42 | +- No dependency on POSIX ucontext. |
| 43 | +- No other dependencies. |
| 44 | +- Appears to be maintained. |
| 45 | + |
| 46 | +Boost.Context is very close but aimed at C++ and in one case seems to require C++ code. However, the project has large set of assembly for a wide variety of processor architectures. I decided it would make a good test of using an LLM to wrap/refactor some code. |
| 47 | + |
| 48 | +The C code and documentation was mostly generated by Claude Code. The assembly is from the Boost.Context project and was written by humans. I have touched/edited almost every file at some point. |
26 | 49 |
|
27 | 50 | ## Features |
28 | 51 |
|
29 | 52 | - **Pure C11 implementation** - No C++ dependencies |
30 | 53 | - **Asymmetric coroutines (fibers)** - Simplified suspend/resume model |
31 | | -- **Guard pages** - Memory-efficient mmap-based stack with automatic overflow detection |
| 54 | +- **Guard pages** - Memory-efficient mmap-based stack with automatic overflow detection (crashing your program!) |
32 | 55 | - **Stack watermark checking** - Measure maximum stack usage |
33 | 56 | - **16-byte stack alignment** - ABI-compliant on x86_64 and ARM64 |
34 | 57 | - **Page-aware allocation** - Handles 4KB (Linux/Windows) and 16KB (macOS ARM) pages |
|
0 commit comments