From db7277df5ed4a0951698697b62afa823c3ba0d72 Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sun, 2 Nov 2025 13:23:50 -0500 Subject: Intial commit: No free list management yet --- include/alloc.h | 38 ++++++++++++++++++++++++++++++++++++++ include/constants.h | 18 ++++++++++++++++++ include/free_list.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 include/alloc.h create mode 100644 include/constants.h create mode 100644 include/free_list.h (limited to 'include') diff --git a/include/alloc.h b/include/alloc.h new file mode 100644 index 0000000..cdbdb37 --- /dev/null +++ b/include/alloc.h @@ -0,0 +1,38 @@ +/* + * include/alloc.h + * + * Primary header for liballoc API + * CISC 301 -- Operating Systems, Project 3 + * + * Copyright (C) 2025 Douglas B. Rumbaugh + * + * Distributed under the Modified BSD License + * + */ +#ifndef H_LIBALLOC +#define H_LIBALLOC + +#include +#include +#include + +#include "constants.h" +#include "free_list.h" + +/* + * Returns a pointer to a new region of memory of the specified + * size, or NULL if no memory is available. + */ +void *allocate(size_t); + +/* + * Release a block of memory previous allocated using allocate(). If the + * input pointer was not returned by allocate(), then the behavior of + * this function is undefined. + * + * Accessing a pointer that has been previous passed to this function is + * undefined behavior. + */ +void release(void *); + +#endif diff --git a/include/constants.h b/include/constants.h new file mode 100644 index 0000000..7d88060 --- /dev/null +++ b/include/constants.h @@ -0,0 +1,18 @@ +/* + * include/constants.h + * + * Configuration constant values for liballoc + * CISC 301 -- Operating Systems, Project 3 + * + * Copyright (C) 2025 Douglas B. Rumbaugh + * + * Distributed under the Modified BSD License + * + */ +#ifndef H_LIBALLOC_CONST +#define H_LIBALLOC_CONST + +#define MAGIC_NUMBER 0x123456789 +#define ALIGNMENT 16 + +#endif diff --git a/include/free_list.h b/include/free_list.h new file mode 100644 index 0000000..887167b --- /dev/null +++ b/include/free_list.h @@ -0,0 +1,52 @@ +/* + * include/free_list.h + * + * Free list management routines for liballoc + * CISC 301 -- Operating Systems, Project 3 + * + * Copyright (C) 2025 Douglas B. Rumbaugh + * + * Distributed under the Modified BSD License + * + */ +#ifndef H_LIBALLOC_FREELIST +#define H_LIBALLOC_FREELIST + +#include + +#include "constants.h" + +typedef struct free_nd { + size_t size; + struct free_nd *next; +} free_nd; + +/* + * Scans the specified free list for the first node with >= the + * specified size and returns a pointer to it. If no such node can + * be found, returns NULL. + */ +free_nd *fl_find_first_fit(free_nd *free_list, size_t size); + +/* + * Split the specified free list node based on the required size, while + * maintaining alignment, and update the free list accordingly. If the + * specified node cannot be split (e.g., it's an exact match for size + * within alignment restrictions), simply remove it from the list. + * + * 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); + +/* + * Scans the free list for adjacent nodes and merges them together + */ +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. + */ +void fl_add_node(free_nd *free_list, void *ptr); + +#endif -- cgit v1.2.3