Kernel: Map .rodata as read only instead of read-write

This commit is contained in:
Bananymous 2024-08-12 14:28:52 +03:00
parent 1bd7b86e60
commit f37e1c2229
4 changed files with 28 additions and 2 deletions

View File

@ -9,6 +9,9 @@ extern uint8_t g_kernel_end[];
extern uint8_t g_kernel_execute_start[]; extern uint8_t g_kernel_execute_start[];
extern uint8_t g_kernel_execute_end[]; extern uint8_t g_kernel_execute_end[];
extern uint8_t g_kernel_writable_start[];
extern uint8_t g_kernel_writable_end[];
extern uint8_t g_userspace_start[]; extern uint8_t g_userspace_start[];
extern uint8_t g_userspace_end[]; extern uint8_t g_userspace_end[];
@ -148,7 +151,7 @@ namespace Kernel
V2P(g_kernel_start), V2P(g_kernel_start),
(vaddr_t)g_kernel_start, (vaddr_t)g_kernel_start,
g_kernel_end - g_kernel_start, g_kernel_end - g_kernel_start,
Flags::ReadWrite | Flags::Present Flags::Present
); );
// Map executable kernel memory as executable // Map executable kernel memory as executable
@ -159,6 +162,14 @@ namespace Kernel
Flags::Execute | Flags::Present Flags::Execute | Flags::Present
); );
// Map writable kernel memory as writable
map_range_at(
V2P(g_kernel_writable_start),
(vaddr_t)g_kernel_writable_start,
g_kernel_writable_end - g_kernel_writable_start,
Flags::ReadWrite | Flags::Present
);
// Map userspace memory // Map userspace memory
map_range_at( map_range_at(
V2P(g_userspace_start), V2P(g_userspace_start),

View File

@ -34,12 +34,14 @@ SECTIONS
} }
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET) .data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
{ {
g_kernel_writable_start = .;
*(.data) *(.data)
} }
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET) .bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
{ {
*(COMMON) *(COMMON)
*(.bss) *(.bss)
g_kernel_writable_end = .;
} }
g_kernel_end = .; g_kernel_end = .;
} }

View File

@ -11,6 +11,9 @@ extern uint8_t g_kernel_end[];
extern uint8_t g_kernel_execute_start[]; extern uint8_t g_kernel_execute_start[];
extern uint8_t g_kernel_execute_end[]; extern uint8_t g_kernel_execute_end[];
extern uint8_t g_kernel_writable_start[];
extern uint8_t g_kernel_writable_end[];
extern uint8_t g_userspace_start[]; extern uint8_t g_userspace_start[];
extern uint8_t g_userspace_end[]; extern uint8_t g_userspace_end[];
@ -170,7 +173,7 @@ namespace Kernel
V2P(g_kernel_start), V2P(g_kernel_start),
(vaddr_t)g_kernel_start, (vaddr_t)g_kernel_start,
g_kernel_end - g_kernel_start, g_kernel_end - g_kernel_start,
Flags::ReadWrite | Flags::Present Flags::Present
); );
// Map executable kernel memory as executable // Map executable kernel memory as executable
@ -181,6 +184,14 @@ namespace Kernel
Flags::Execute | Flags::Present Flags::Execute | Flags::Present
); );
// Map writable kernel memory as writable
map_range_at(
V2P(g_kernel_writable_start),
(vaddr_t)g_kernel_writable_start,
g_kernel_writable_end - g_kernel_writable_start,
Flags::ReadWrite | Flags::Present
);
// Map userspace memory // Map userspace memory
map_range_at( map_range_at(
V2P(g_userspace_start), V2P(g_userspace_start),

View File

@ -34,12 +34,14 @@ SECTIONS
} }
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET) .data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
{ {
g_kernel_writable_start = .;
*(.data) *(.data)
} }
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET) .bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
{ {
*(COMMON) *(COMMON)
*(.bss) *(.bss)
g_kernel_writable_end = .;
} }
g_kernel_end = .; g_kernel_end = .;
} }