Skip to content

Commit e2219f0

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 e7d6cef commit e2219f0

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
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 logger.o error.o syscall.o task.o main.o
20+
KERNEL_OBJS := timer.o mqueue.o pipe.o semaphore.o mutex.o logger.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: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,31 @@ typedef struct {
6363
* DECLARE_MEMPOOL_FROM_SYMBOLS uses token concatenation to construct
6464
* linker symbol names automatically.
6565
*/
66-
#define DECLARE_MEMPOOL(name_, start_, end_, flags_, tag_) \
67-
{ \
68-
.name = (name_), \
69-
.start = (uintptr_t)(start_), \
70-
.end = (uintptr_t)(end_), \
71-
.flags = (flags_), \
72-
.tag = (tag_), \
66+
#define DECLARE_MEMPOOL(name_, start_, end_, flags_, tag_) \
67+
{ \
68+
.name = (name_), .start = (uintptr_t) (start_), \
69+
.end = (uintptr_t) (end_), .flags = (flags_), .tag = (tag_), \
7370
}
7471

75-
#define DECLARE_MEMPOOL_FROM_SYMBOLS(name_, sym_base_, flags_, tag_) \
76-
DECLARE_MEMPOOL((name_), &(sym_base_##_start), &(sym_base_##_end), (flags_), (tag_))
72+
#define DECLARE_MEMPOOL_FROM_SYMBOLS(name_, sym_base_, flags_, tag_) \
73+
DECLARE_MEMPOOL((name_), &(sym_base_##_start), &(sym_base_##_end), \
74+
(flags_), (tag_))
75+
76+
/* Flexpage Management Functions */
77+
78+
/* Creates and initializes a new flexpage.
79+
* @base : Physical base address
80+
* @size : Size in bytes
81+
* @rwx : Permission bits
82+
* @priority : Eviction priority
83+
* Returns pointer to created flexpage, or NULL on failure.
84+
*/
85+
fpage_t *mo_fpage_create(uint32_t base,
86+
uint32_t size,
87+
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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,
14+
uint32_t size,
15+
uint32_t rwx,
16+
uint32_t priority)
17+
{
18+
fpage_t *fpage = malloc(sizeof(fpage_t));
19+
if (!fpage)
20+
return NULL;
21+
22+
/* Initialize all fields */
23+
fpage->as_next = NULL;
24+
fpage->map_next = NULL;
25+
fpage->pmp_next = NULL;
26+
fpage->base = base;
27+
fpage->size = size;
28+
fpage->rwx = rwx;
29+
fpage->pmp_id = 0; /* Not loaded into PMP initially */
30+
fpage->flags = 0; /* No flags set initially */
31+
fpage->priority = priority;
32+
fpage->used = 0; /* Not in use initially */
33+
34+
return fpage;
35+
}
36+
37+
/* Destroys a flexpage */
38+
void mo_fpage_destroy(fpage_t *fpage)
39+
{
40+
if (!fpage)
41+
return;
42+
43+
free(fpage);
44+
}

0 commit comments

Comments
 (0)