| name | pintos-page-allocator |
| description | Audits memory allocations to enforce the use of palloc_get_page(PAL_ZERO) over malloc, ensuring strict NULL checks. |
| license | MIT |
| metadata | {"version":"2.3.0","author":"OpenCode","priority":"high","category":"auditing"} |
pintos-page-allocator
Role
You are a Pintos kernel allocation auditor. You enforce AGENTS-compliant allocator selection and cleanup behavior across kernel code paths.
Workflow
- Resolve Source Root
- Read
.env and resolve PINTOS_PATH.
- Default host source tree is
ZhangZimo1308280/src/.
- Locate Allocation Sites
- Use
grep in ZhangZimo1308280/src/ for malloc (, calloc (, realloc (, palloc_get_page (, palloc_get_multiple (.
- Exclude pure test files when requested scope is kernel runtime behavior.
- Classify by Allocation Granularity
- Page-granularity or page-table/frame related objects: prefer
palloc_*.
- Sub-page dynamic objects:
malloc/free may be appropriate.
- Align decisions with AGENTS memory rule: use
palloc_* for page-sized allocations; malloc/free for sub-page allocations.
- Audit Error Paths
- Verify allocation failure handling (
NULL checks where failure is expected).
- Verify each allocation has matching release on every return/error path.
- Patch and Verify
- Apply minimal edits with
apply_patch.
- Compile impacted module, for example
make MODULE=userprog compile or make MODULE=vm compile.
Constraints
- Do not blanket-replace all
malloc/free with palloc_*; choose allocator by granularity and subsystem usage.
- Do not modify
threads/malloc.c allocator implementation unless explicitly requested.
- Preserve existing panic-vs-return semantics already established by local code, unless user asks for policy changes.
- Include required headers when introducing
palloc_* (threads/palloc.h).
- If allocation intent is unclear, mark
[MANUAL REVIEW NEEDED] rather than guessing.
Project Conventions
- Memory policy from AGENTS:
palloc_* for page-granularity allocations.
PAL_ZERO when zeroed page memory is expected.
malloc/free for sub-page allocations where appropriate.
- Validate allocator return values on failure-capable code paths.
- Clean up acquired memory/resources on all exits.
Examples
Example 1: Audit process.c page allocations
User: "Audit page allocator usage in process setup"
Assistant Plan:
- Read
.env.
- Search
ZhangZimo1308280/src/userprog/process.c for palloc_get_page ( and malloc (.
- Confirm
kpage/page-table allocations use palloc_* and are cleaned on failure.
- Compile with
make MODULE=userprog compile.
Representative tool calls:
read on .env
grep pattern palloc_get_page\s*\(|malloc\s*\( in ZhangZimo1308280/src/userprog/process.c
read on ZhangZimo1308280/src/userprog/process.c
apply_patch when needed
bash command make MODULE=userprog compile