Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def main():
print(f"\n {color('⚠ Some tools missing - will try anyway:', Colors.YELLOW)}")
for m in missing:
print(f" {m}")
print(f" {color('Not all modules will build. That\'s fine.', Colors.GRAY)}")
print(" " + color("Not all modules will build. That's fine.", Colors.GRAY))
else:
print(f" {color('✓ All prerequisites found', Colors.GREEN)}")

Expand Down
23 changes: 23 additions & 0 deletions diagnostic/build-2b54872c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"generated_at": "2026-06-23T04:05:10.650191+00:00",
"commit": "2b54872c",
"diagnostic_logd": null,
"diagnostic_logd_error": "191814fb92eb3c934cfb",
"chunked": false,
"chunk_size_bytes": null,
"password": null,
"decrypt_command": null,
"total_modules": 1,
"passed": 1,
"failed": 0,
"modules": [
{
"name": "frailbox",
"status": "PASS",
"elapsed_seconds": 0.557,
"artifact": "/Volumes/Soengkit\u786c\u76d8/Codex\u65b0\u9879\u76ee\u4e0e\u8f93\u51fa/2026-06-19_Agent Bounty Workbench/02_candidate_bounties/gautam-tentoftrials-buddy-4/repo/frailbox/frailbox",
"output": "gcc -Wall -Wextra -Wpedantic -std=c2x -O2 -g -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fPIE -Iinclude -MMD -MP -c src/arena.c -o build/src/arena.o\ngcc -Wall -Wextra -Wpedantic -std=c2x -O2 -g -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fPIE -Iinclude -MMD -MP -c src/buddy.c -o build/src/buddy.o\ngcc -Wall -Wextra -Wpedantic -std=c2x -O2 -g -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fPIE -Iinclude -MMD -MP -c src/logger.c -o build/src/logger.o\ngcc -Wall -Wextra -Wpedantic -std=c2x -O2 -g -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fPIE -Iinclude -MMD -MP -c src/sandbox.c -o build/src/sandbox.o\ngcc -Wall -Wextra -Wpedantic -std=c2x -O2 -g -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fPIE -Iinclude -MMD -MP -c main.c -o build/main.o\ngcc -Wall -Wextra -Wpedantic -std=c2x -O2 -g -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fPIE -Iinclude build/src/arena.o build/src/buddy.o build/src/logger.o build/src/sandbox.o build/main.o -o frailbox"
}
],
"pr_note": "Encrypted diagnostic logd artifact was not created; include this JSON report showing why. The encrypted .logd is the required diagnostic content for PR review; this JSON file is metadata. Maintainers may ask you to remove these diagnostic artifacts before merging."
}
18 changes: 15 additions & 3 deletions frailbox/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
CC = gcc
UNAME_S := $(shell uname -s)
CFLAGS = -Wall -Wextra -Wpedantic -std=c2x -O2 -g
CFLAGS += -D_FORTIFY_SOURCE=3
CFLAGS += -fstack-protector-strong
CFLAGS += -fPIE
LDFLAGS = -pie -z relro -z now
LDFLAGS =
ifeq ($(UNAME_S),Linux)
LDFLAGS += -pie -z relro -z now
endif

SRCDIR = src
INCDIR = include
Expand All @@ -14,8 +18,9 @@ OBJS = $(patsubst %.c, $(BUILDDIR)/%.o, $(SRCS))
DEPS = $(OBJS:.o=.d)

TARGET = frailbox
BUDDY_TEST = $(BUILDDIR)/test_buddy

.PHONY: all clean
.PHONY: all clean test-buddy

all: $(TARGET)

Expand All @@ -26,6 +31,10 @@ $(BUILDDIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -I$(INCDIR) -MMD -MP -c $< -o $@

$(BUDDY_TEST): tests/test_buddy.c $(SRCDIR)/buddy.c $(INCDIR)/buddy.h
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -I$(INCDIR) tests/test_buddy.c $(SRCDIR)/buddy.c -o $@ $(LDFLAGS)

-include $(DEPS)

clean:
Expand All @@ -37,7 +46,10 @@ distclean: clean
test: $(TARGET)
./$(TARGET) --sandbox-type seccomp --memory-limit 64 --verbose

test-buddy: $(BUDDY_TEST)
./$(BUDDY_TEST)

valgrind: $(TARGET)
valgrind --leak-check=full --show-leak-kinds=all ./$(TARGET)

.PHONY: all clean distclean test valgrind
.PHONY: all clean distclean test test-buddy valgrind
41 changes: 41 additions & 0 deletions frailbox/include/buddy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef FRAILBOX_BUDDY_H
#define FRAILBOX_BUDDY_H

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define BUDDY_MIN_BLOCK_SIZE 64u

typedef struct buddy_allocator buddy_allocator_t;

typedef struct buddy_stats {
size_t capacity_bytes;
size_t allocated_bytes;
size_t reserved_bytes;
size_t free_bytes;
size_t largest_free_block;
uint64_t allocation_count;
uint64_t deallocation_count;
uint64_t split_count;
uint64_t coalesce_count;
double fragmentation_ratio;
} buddy_stats_t;

buddy_allocator_t *buddy_create(size_t capacity_bytes);
void buddy_destroy(buddy_allocator_t *allocator);

void *buddy_alloc(buddy_allocator_t *allocator, size_t size);
void buddy_free(buddy_allocator_t *allocator, void *ptr);

buddy_stats_t buddy_stats(const buddy_allocator_t *allocator);
int buddy_contains(const buddy_allocator_t *allocator, const void *ptr);

#ifdef __cplusplus
}
#endif

#endif
9 changes: 7 additions & 2 deletions frailbox/src/arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ static arena_region_t *region_alloc(size_t size, uint32_t flags) {
int mmap_prot = PROT_READ | PROT_WRITE;

if (flags & ARENA_HUGE_PAGES) {
#ifdef MAP_HUGETLB
mmap_flags |= MAP_HUGETLB;
#else
return NULL;
#endif
}

void *addr = mmap(NULL, size, mmap_prot, mmap_flags, -1, 0);
Expand Down Expand Up @@ -175,8 +179,9 @@ size_t arena_total_capacity(const arena_t *arena) {
int arena_contains(const arena_t *arena, const void *ptr) {
arena_region_t *region = arena->regions;
while (region) {
if (ptr >= region->start &&
ptr < (char *)region->start + region->size) {
const char *byte_ptr = ptr;
if (byte_ptr >= (const char *)region->start &&
byte_ptr < (const char *)region->start + region->size) {
return 1;
}
region = region->next;
Expand Down
Loading