Skip to content

Commit c84cbae

Browse files
committed
Implement flex page lifecycle management
Adds creation and destruction functions for flex pages, 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 319ba96 commit c84cbae

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
/* Flex Page Management Functions */
79+
80+
/* Creates and initializes a new flex page.
81+
* @base : Physical base address
82+
* @size : Size in bytes
83+
* @rwx : Permission bits
84+
* @priority : Eviction priority
85+
* Returns pointer to created flex page, 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 flex page.
91+
* @fpage : Pointer to flex page 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 flex pages, 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 flex page */
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 flex page */
36+
void mo_fpage_destroy(fpage_t *fpage)
37+
{
38+
if (!fpage)
39+
return;
40+
41+
free(fpage);
42+
}

0 commit comments

Comments
 (0)