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
.envand resolvePINTOS_PATH. - Default host source tree is
ZhangZimo1308280/src/.
- Read
- Locate Allocation Sites
- Use
grepinZhangZimo1308280/src/formalloc (,calloc (,realloc (,palloc_get_page (,palloc_get_multiple (. - Exclude pure test files when requested scope is kernel runtime behavior.
- Use
- Classify by Allocation Granularity
- Page-granularity or page-table/frame related objects: prefer
palloc_*. - Sub-page dynamic objects:
malloc/freemay be appropriate. - Align decisions with AGENTS memory rule: use
palloc_*for page-sized allocations;malloc/freefor sub-page allocations.
- Page-granularity or page-table/frame related objects: prefer
- Audit Error Paths
- Verify allocation failure handling (
NULLchecks where failure is expected). - Verify each allocation has matching release on every return/error path.
- Verify allocation failure handling (
- Patch and Verify
- Apply minimal edits with
apply_patch. - Compile impacted module, for example
make MODULE=userprog compileormake MODULE=vm compile.
- Apply minimal edits with
Constraints
- Do not blanket-replace all
malloc/freewithpalloc_*; choose allocator by granularity and subsystem usage. - Do not modify
threads/malloc.callocator 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_ZEROwhen zeroed page memory is expected.malloc/freefor 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.cforpalloc_get_page (andmalloc (. - Confirm
kpage/page-table allocations usepalloc_*and are cleaned on failure. - Compile with
make MODULE=userprog compile.
Representative tool calls:
readon.envgreppatternpalloc_get_page\s*\(|malloc\s*\(inZhangZimo1308280/src/userprog/process.creadonZhangZimo1308280/src/userprog/process.capply_patchwhen neededbashcommandmake MODULE=userprog compile