Skip to content

Commit 5b66e64

Browse files
committed
Implement flexpage lifecycle management
Adds creation and destruction functions for flexpages, which are software abstractions representing contiguous physical memory regions with hardware-enforced protection attributes. These primitives will be used by higher-level memory space management to construct per-task memory views for PMP-based isolation. Function naming follows kernel conventions to reflect that these operations manage abstract memory protection objects rather than just memory allocation.
1 parent bd7cc70 commit 5b66e64

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ include arch/$(ARCH)/build.mk
1717
INC_DIRS += -I $(SRC_DIR)/include \
1818
-I $(SRC_DIR)/include/lib
1919

20-
KERNEL_OBJS := timer.o mqueue.o pipe.o semaphore.o mutex.o error.o syscall.o task.o main.o
20+
KERNEL_OBJS := timer.o mqueue.o pipe.o semaphore.o mutex.o error.o syscall.o task.o memprot.o main.o
2121
KERNEL_OBJS := $(addprefix $(BUILD_KERNEL_DIR)/,$(KERNEL_OBJS))
2222
deps += $(KERNEL_OBJS:%.o=%.o.d)
2323

include/sys/memprot.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
struct fpage;
1515
struct as;
1616

17-
/* Flex Page
17+
/* Flexpage
1818
*
1919
* Contiguous physical memory region with hardware-enforced protection.
2020
* Supports arbitrary base addresses and sizes without alignment constraints.
@@ -39,7 +39,7 @@ typedef struct fpage {
3939
*/
4040
typedef struct memspace {
4141
uint32_t as_id; /* Address space identifier */
42-
struct fpage *first; /* Head of flex page list */
42+
struct fpage *first; /* Head of flexpage list */
4343
struct fpage *pmp_first; /* Head of PMP-loaded list */
4444
struct fpage *pmp_stack; /* Stack regions */
4545
uint32_t shared; /* Shared flag */
@@ -74,3 +74,20 @@ typedef struct {
7474

7575
#define DECLARE_MEMPOOL_FROM_SYMBOLS(name_, sym_base_, flags_, tag_) \
7676
DECLARE_MEMPOOL((name_), &(sym_base_##_start), &(sym_base_##_end), (flags_), (tag_))
77+
78+
/* Flexpage Management Functions */
79+
80+
/* Creates and initializes a new flexpage.
81+
* @base : Physical base address
82+
* @size : Size in bytes
83+
* @rwx : Permission bits
84+
* @priority : Eviction priority
85+
* Returns pointer to created flexpage, or NULL on failure.
86+
*/
87+
fpage_t *mo_fpage_create(uint32_t base, uint32_t size, uint32_t rwx,
88+
uint32_t priority);
89+
90+
/* Destroys a flexpage.
91+
* @fpage : Pointer to flexpage to destroy
92+
*/
93+
void mo_fpage_destroy(fpage_t *fpage);

kernel/memprot.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Memory Protection Management
2+
*
3+
* Provides allocation and management functions for flexpages, which are
4+
* software abstractions representing contiguous physical memory regions with
5+
* hardware-enforced protection attributes.
6+
*/
7+
8+
#include <lib/libc.h>
9+
#include <lib/malloc.h>
10+
#include <sys/memprot.h>
11+
12+
/* Creates and initializes a flexpage */
13+
fpage_t *mo_fpage_create(uint32_t base, uint32_t size, uint32_t rwx,
14+
uint32_t priority)
15+
{
16+
fpage_t *fpage = malloc(sizeof(fpage_t));
17+
if (!fpage)
18+
return NULL;
19+
20+
/* Initialize all fields */
21+
fpage->as_next = NULL;
22+
fpage->map_next = NULL;
23+
fpage->pmp_next = NULL;
24+
fpage->base = base;
25+
fpage->size = size;
26+
fpage->rwx = rwx;
27+
fpage->pmp_id = 0; /* Not loaded into PMP initially */
28+
fpage->flags = 0; /* No flags set initially */
29+
fpage->priority = priority;
30+
fpage->used = 0; /* Not in use initially */
31+
32+
return fpage;
33+
}
34+
35+
/* Destroys a flexpage */
36+
void mo_fpage_destroy(fpage_t *fpage)
37+
{
38+
if (!fpage)
39+
return;
40+
41+
free(fpage);
42+
}

0 commit comments

Comments
 (0)