1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*
* include/free_list.h
*
* Free list management routines for liballoc
* CISC 301 -- Operating Systems, Project 3
*
* Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu>
*
* Distributed under the Modified BSD License
*
*/
#ifndef H_LIBALLOC_FREELIST
#define H_LIBALLOC_FREELIST
#include <stdlib.h>
#include "alloc_header.h"
#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.
*
* 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);
/*
* 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.
*
* 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);
#endif
|