Skip to content

feat(libc): implement functional malloc and free#37

Closed
jbreu wants to merge 127 commits into
masterfrom
feature/libc-malloc-free
Closed

feat(libc): implement functional malloc and free#37
jbreu wants to merge 127 commits into
masterfrom
feature/libc-malloc-free

Conversation

@jbreu

@jbreu jbreu commented May 10, 2026

Copy link
Copy Markdown
Owner

Summary

Previously, free() was a no-op stub, causing memory leaks in userland. This PR implements a working memory management lifecycle.

Changes

  • Malloc Header: malloc now reserves an additional 8 bytes at the start of each block to store the allocation size.
  • Free Implementation: free(ptr) now retrieves those extra 8 bytes and triggers the kernel deallocation via realloc(p, 0) (Syscall 20).
  • Kernel Compatibility: This leverages the existing linked_list_allocator deallocation logic in the JOS kernel.

This is a critical fix for running long-lived or memory-intensive applications in JOS.

jbreu added 28 commits August 29, 2025 10:14
- Updated malloc to allocate 8 extra bytes for a size header.
- Implemented free() by retrieving the original pointer and calling realloc(ptr, 0).
- This enables practical memory deallocation in userland apps like Doom.
@jbreu jbreu closed this May 10, 2026
@jbreu jbreu force-pushed the feature/libc-malloc-free branch from 0bde2fb to 09bc828 Compare May 10, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant