Skip to content

Commit b560812

Browse files
committed
Extract stack allocator from easy_memory into standalone easy_stack library with test matrix and fuzzers
1 parent c85395e commit b560812

16 files changed

Lines changed: 2819 additions & 0 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Bug Report
3+
about: Report a crash, memory leak, or undefined behavior.
4+
title: '[BUG] '
5+
labels: 'bug'
6+
---
7+
8+
**Describe the bug**
9+
A clear and concise description of what the bug is.
10+
11+
**Environment:**
12+
- OS:[e.g. Ubuntu 22.04, Windows 11, Bare-Metal ESP32]
13+
- Compiler:[e.g. GCC 11, Clang 14, MSVC]
14+
- Architecture:[e.g. x86_64, aarch64, s390x, 32-bit/64-bit]
15+
- C Standard:[e.g. C99, C11, C17, GNU11]
16+
- Optimization Flags:[e.g. -O0, -O2, -O3, -Os, -Oz]
17+
- Safety Policy:[ESTACK_POLICY_DEFENSIVE or ESTACK_POLICY_CONTRACT]
18+
19+
**To Reproduce**
20+
Please provide a minimal C snippet that reproduces the crash, OR paste the `libFuzzer` crash dump below:

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Description
2+
<!-- Please briefly describe what this PR adds or fixes. -->
3+
4+
### Contribution Checklist
5+
- [ ] I have read the `CONTRIBUTING.md` file.
6+
- [ ] I added a new test in the `tests/` directory (if applicable).
7+
- [ ] I ran `make tests` and everything passes locally.
8+
- [ ] I ran the fuzzers (`make fuzz_core` or custom) locally for at least 5 minutes to ensure no regressions.
9+
- [ ] The code complies with C99/C11 standards and `ESTACK_NO_MALLOC` constraints.

.github/codecov.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Codecov configuration
2+
3+
coverage:
4+
ignore:
5+
- "tests/*" # Ignore all files within the tests/ directory
6+
- "fuzzers/*" # Ignore all files within the fuzzers/ directory
7+
8+
# Coverage status settings
9+
status:
10+
project:
11+
default:
12+
# Target coverage for the whole project
13+
target: 80%
14+
threshold: 0%
15+
patch:
16+
default:
17+
# Target coverage for the changes in a PR
18+
target: 80%
19+
# Do not allow coverage to decrease in PRs
20+
threshold: 0%

.github/docker/Dockerfile.test-env

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG BASE_IMAGE=ubuntu:latest
2+
FROM ${BASE_IMAGE}
3+
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
RUN apt-get update && \
7+
apt-get install -y --no-install-recommends \
8+
build-essential \
9+
gcc \
10+
make \
11+
valgrind \
12+
lcov \
13+
git \
14+
ca-certificates \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
WORKDIR /workspace

.github/workflows/docker-build.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: build-docker-images
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- '.github/docker/**'
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
strategy:
17+
matrix:
18+
include:
19+
- arch: s390x
20+
platform: linux/s390x
21+
base_img: s390x/ubuntu:latest
22+
tag_suffix: s390x
23+
- arch: arm32
24+
platform: linux/arm/v7
25+
base_img: arm32v7/ubuntu:latest
26+
tag_suffix: arm32
27+
28+
steps:
29+
- name: checkout
30+
uses: actions/checkout@v6
31+
32+
- name: setup-qemu
33+
uses: docker/setup-qemu-action@v4
34+
35+
- name: setup-docker-buildx
36+
uses: docker/setup-buildx-action@v4
37+
38+
- name: login-to-ghcr
39+
if: github.repository == 'EasyMem/easy_stack'
40+
uses: docker/login-action@v4
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: build-and-push-${{ matrix.arch }}
47+
uses: docker/build-push-action@v6
48+
with:
49+
context: .github/docker
50+
file: .github/docker/Dockerfile.test-env
51+
platforms: ${{ matrix.platform }}
52+
push: ${{ github.repository == 'EasyMem/easy_stack' }}
53+
build-args: BASE_IMAGE=${{ matrix.base_img }}
54+
tags: ghcr.io/easymem/easy_stack:${{ matrix.tag_suffix }}

.gitignore

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf
53+
54+
# Tests
55+
tests/stack_alloc_test_*
56+
57+
build_matrix
58+
59+
# Fuzzers
60+
fuzzers/*_fuzzer
61+
62+
# Coverage files
63+
*.gcno
64+
*.gcda
65+
*.info

CODE_OF_CONDUCT.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
gooderfreed@gmail.com.
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series
86+
of actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or
93+
permanent ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within
113+
the community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.0, available at
119+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120+
121+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122+
enforcement ladder](https://github.com/mozilla/diversity).
123+
124+
[homepage]: https://www.contributor-covenant.org
125+
126+
For answers to common questions about this code of conduct, see the FAQ at
127+
https://www.contributor-covenant.org/faq. Translations are available at
128+
https://www.contributor-covenant.org/translations.

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contributing to EasyMem
2+
3+
First of all, thank you for being here!
4+
5+
I've been on the other side: you spend your weekend optimizing someone else's messy codebase, making it 10x faster, only to be hit with a 10-page contribution guide full of bureaucratic rules, strict commit formats, and formatting nitpicks. You close the tab and walk away.
6+
7+
**I don't do that here.**
8+
9+
At EasyMem, code quality and performance speak louder than bureaucracy. If you have an idea, a bug fix, or a massive optimization, I want to see your code. We can figure out the formatting details later.
10+
11+
## The Golden Rules
12+
13+
To keep EasyMem true to its philosophy, there are only a few architectural rules I strictly follow:
14+
15+
1. **Header-Only (STB-style):** The core libraries must remain single-file headers. No `.c` files, no complex build systems required for the end-user.
16+
2. **Zero-Overhead Philosophy:** Performance is critical. Avoid adding internal locks, mutexes, or hidden allocations.
17+
3. **Bare-Metal Friendly:** I do not assume the existence of a `libc` heap unless explicitly allowed. The code must perfectly respect the `ESTACK_NO_MALLOC` macro.
18+
4. **16-bit, 32-bit, and 64-bit Support:** The code must compile and run correctly across all pointer sizes. Be careful with bitwise operations, shifts, and alignment mathematics. The CI will test this, but keep it in mind.
19+
20+
## The Workflow
21+
22+
If you want to add a feature or fix a bug, here is the ideal pipeline:
23+
24+
1. **Write the code.**
25+
2. **Add a test:** If you introduced a new feature or fixed an edge case, create a new test file in the `tests/` directory (name it `yourfeature_test.c`). The `Makefile` will automatically pick it up and generate the build targets for it—no need to edit the build scripts.
26+
3. **Run tests locally:**
27+
* Run `make tests`.
28+
* *(Note: `make tests_full` runs the exact same test suite, it just enables verbose debug output in the console. You can run `make` or `make list` to see all dynamically generated targets).*
29+
4. **Push to your fork and check CI:** The GitHub Actions workflow **must be green**. It automatically runs an aggressive matrix (Sanitizers, strict ARM alignment, Big Endian s390x, and 16-bit fallbacks). Let the robots do the heavy lifting.
30+
5. **Feed it to the Fuzzer:** Run the fuzzers locally for the standard 5 minutes each.
31+
* Just like tests, if you add a new `.c` file to the `fuzzers/` directory (name it `yourfeature_fuzzer.c`), the `Makefile` will automatically detect it. Check `make list` for your new `make fuzz_yourfeature` target.
32+
* *Tip: If you implemented new features or structural mechanics, please create a dedicated standalone fuzzer for it to test its specific boundary scenarios!*
33+
6. **Open the PR.**
34+
35+
*Don't worry about strict commit message formats (like `feat(core): ...`). Just write what you did in plain English.*
36+
37+
## Code Style
38+
* Try to match the surrounding code style.
39+
* If you add a new API function, please add a small comment explaining *what* it does and *why*.
40+
* If you implement a complex bit-manipulation hack, write a "WHY DOING THIS?" comment. I love reading about the physics of the code!
41+
42+
## Let's make C memory management *easy*.
43+
If you're unsure about an architectural decision, just open a Draft PR or an Issue, and we'll discuss it. I'm always open to new ideas.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 EasyMem
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)