From 04b57a756402e156953edfa2079d69b41db26e51 Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sun, 2 Nov 2025 15:39:43 -0500 Subject: Updated free list interface I realized my existing interface wouldn't work if the coalescing or adding of a new node replaced the head of the list, as there was no way to communicate that back to the caller. As a result, I've updated those interfaces to accept a pointer to the free list head pointer. This will let them change the free list head in alloc.c if necessary. --- include/alloc_header.h | 27 +++++++++++++++++++++++++++ include/free_list.h | 11 +++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 include/alloc_header.h (limited to 'include') diff --git a/include/alloc_header.h b/include/alloc_header.h new file mode 100644 index 0000000..bf4716c --- /dev/null +++ b/include/alloc_header.h @@ -0,0 +1,27 @@ +/* + * include/alloc_header.h + * + * liballoc memory block header type. + * CISC 301 -- Operating Systems, Project 3 + * + * Copyright (C) 2025 Douglas B. Rumbaugh + * + * Distributed under the Modified BSD License + * + */ +#ifndef H_LIBALLOC_HEADER +#define H_LIBALLOC_HEADER + +#include +#include + +#include "constants.h" + +typedef struct header { + size_t size; + size_t magic_number; +} header; + +static_assert(sizeof(header) % ALIGNMENT == 0, "Header improperly aligned"); + +#endif diff --git a/include/free_list.h b/include/free_list.h index 887167b..1993aa7 100644 --- a/include/free_list.h +++ b/include/free_list.h @@ -15,6 +15,7 @@ #include #include "constants.h" +#include "alloc_header.h" typedef struct free_nd { size_t size; @@ -34,9 +35,12 @@ free_nd *fl_find_first_fit(free_nd *free_list, size_t size); * specified node cannot be split (e.g., it's an exact match for size * within alignment restrictions), simply remove it from the list. * + * If the head of the free list is updated by this operation, the free + * list pointer passed as an argument will be updated to reflect this + * * Returns a pointer to the region of memory removed from the list. */ -void *fl_split_node(free_nd *free_list, free_nd *nd, size_t size); +void *fl_split_node(free_nd **free_list, free_nd *nd, size_t size); /* * Scans the free list for adjacent nodes and merges them together @@ -46,7 +50,10 @@ void fl_coalesce_nodes(free_nd *free_list); /* * Scans the free list for the correct location for the specified * pointer, and link it into the list at that point. + * + * If the head of the free list is updated by this operation, the free + * list pointer passed as an argument will be updated to reflect this */ -void fl_add_node(free_nd *free_list, void *ptr); +void fl_add_node(free_nd **free_list, void *ptr); #endif -- cgit v1.2.3